شعار Cloudflare Workers Author

Cloudflare Workers Author

المجتمع
d-padmanabhan
cloudflare-workers-author

Workflow for building production-grade Cloudflare Workers in TypeScript - bootstrap, bindings and storage choice, routing (Hono + RPC via WorkerEntrypoint), testing with @cloudflare/vitest-plugin, gradual deployments, and common pitfalls. Use when adding a new Worker, adding endpoints to an existing Worker, choosing between KV / R2 / D1 / Durable Objects / Hyperdrive, setting up testing, configuring deployment, or reviewing a Worker PR.

نظرة عامة

الناشرd-padmanabhan
المستودعagent-engineering-handbook
اسم المهارةcloudflare-workers-author
النجوم
20
التفريعات
3
الملفات المرفقة
7
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 7

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها d-padmanabhan على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Cloudflare Workers Author في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/d-padmanabhan/agent-engineering-handbook/tree/main/skills/cloudflare-workers-author
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/d-padmanabhan/agent-engineering-handbook.git /tmp/agent-engineering-handbook
mkdir -p .claude/skills
cp -r /tmp/agent-engineering-handbook/skills/cloudflare-workers-author .claude/skills/cloudflare-workers-author
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Cloudflare Workers Author في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Cloudflare Workers Author تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Cloudflare Workers Author بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Cloudflare Workers Author

Companion rule: 401-cloudflare-workers.mdc (file-scoped to wrangler.{jsonc,toml,json} and common Worker entry-point names). The rule is the gate (non-negotiables); this skill is the workflow (how to actually build the Worker).

Voice: opinionated. Cloudflare Workers is a small, fast platform with a specific runtime model. Most production incidents come from treating it like a generic Node.js server (top-level await, mutable module state, unbounded loops, secrets in logs, public-URL Worker-to-Worker calls). The workflow below prevents those.


When to invoke this skill

Invoke when:

  • The user asks to build a new Cloudflare Worker, Durable Object, Workflow, Queue consumer, Cron Trigger, Email Worker, or Pages Function.
  • The user is adding routes / endpoints to an existing Worker.
  • The user asks "should I use KV / D1 / R2 / DO / Hyperdrive for this?" (the bindings-and-storage decision matrix is the answer).
  • The user is setting up testing for a Worker.
  • The user is configuring deployment (gradual rollouts, OIDC for GitHub Actions, secret rotation).
  • A PR review touches wrangler.jsonc, a Worker entry-point file, or a binding configuration.

Do NOT invoke for:

  • Cloudflare Pages static-site work (not Worker authoring). See cloud-platforms/references/cloudflare.md § Pages.
  • WAF rule authoring (use cloudflare-waf-author skill instead).
  • Generic JavaScript / TypeScript code that happens to be imported by a Worker - delegate to the typescript-javascript skill.

Pre-step: classify what you're building

Each Worker type has a different entry-point shape and different bindings emphasis. Ask the user which one if unclear - the wrong entry-point shape is a wrong-handler-signature bug that won't surface until deploy time.

TypeEntry pointMost common bindings
Default-export HTTP Workerexport default { async fetch(req, env, ctx) {...} } satisfies ExportedHandler<Env>KV, D1, R2, AI, Service Bindings
Named-entrypoint (RPC target)export default class extends WorkerEntrypoint { async myMethod() {...} }Same, called via Service Binding from another Worker
Durable Objectexport class Room extends DurableObject {...} + a default fetch handler that routes to DODO storage + KV / R2 for cold data
Workflowexport class MyWorkflow extends WorkflowEntrypoint { async run(event, step) {...} }KV, D1, R2, Service Bindings, AI
Queue consumerexport default { async queue(batch, env, ctx) {...} }D1, R2, Service Bindings, AI
Cron Triggerexport default { async scheduled(event, env, ctx) {...} }KV, D1, R2, Service Bindings
Email Workerexport default { async email(message, env, ctx) {...} }R2 for attachments, D1 for logs
Pages Functionexport const onRequest: PagesFunction<Env> = async (ctx) => {...} (in functions/[[path]].ts)KV, D1, R2 (subset of full Worker bindings)

The six-step workflow

Step 1 - Bootstrap the project

If this is a new Worker (no existing wrangler.jsonc), follow references/project-bootstrap.md to get a minimal Module Workers project with:

  • wrangler.jsonc (the modern config format - JSONC with comments; recommended by Cloudflare since Wrangler v3.91.0)
  • package.json with wrangler, typescript, and a types script that runs wrangler types
  • tsconfig.json with strict mode, ESNext target, "types": [], and the generated worker-configuration.d.ts in include
  • src/worker.ts with the generated Env type (do not hand-author it) and satisfies ExportedHandler<Env>
  • .dev.vars in .gitignore; worker-configuration.d.ts generated by wrangler types

[!IMPORTANT] wrangler types now generates the Workers runtime types and supersedes @cloudflare/workers-types. Current Wrangler (4.9x+) prints this on every wrangler types run and tells you to uninstall @cloudflare/workers-types and remove it from tsconfig.json. The generated worker-configuration.d.ts provides both the global Env (from vars + declared secrets) and the runtime globals (Request, Response, ExecutionContext, ExportedHandler, etc.), pinned to your compatibility_date. So: no @cloudflare/workers-types dependency, "types": [] in tsconfig.json, and worker-configuration.d.ts in include. Declare expected secrets under secrets.required in wrangler.jsonc so they appear in the generated Env. Vars are typed as their literal values by default; run wrangler types --strict-vars=false to type them as string when a var's value varies by environment.

If the user already has a Worker, read their existing wrangler.jsonc before suggesting changes. Don't propose a fresh structure that conflicts with their conventions.

Step 2 - Choose bindings and storage

This is the most consequential design decision in any new Worker. Pick wrong and you'll be migrating data in six months. The full decision matrix is in references/bindings-and-storage.md; the headline:

NeedUseDon't use
Session / config / feature flag (small, eventually consistent, low write)KVD1, R2
Relational queries, transactions, joins (single-region, SQLite scale)D1KV
File / blob storage (any size; metadata + body)R2KV (25 MB value limit)
Strongly-consistent coordination (sessions, rate limits, websocket fan-out)Durable ObjectKV (eventually consistent), D1 (single-region, not strongly consistent across Workers)
Connection pooling to existing Postgres / MySQLHyperdriveDirect TCP (works but no pooling)
Job queues, dead-letter, batchingQueuesManual KV-based queue
LLM inferenceWorkers AI behind AI Gateway (cost cap + caching + observability)Direct provider API calls
Vector searchVectorizeKV with embedding lookups (no ANN index)

Document the choice in the PR description with the rejected alternatives and why.

Step 3 - Route requests

Pick a router based on complexity:

ComplexityChoiceWhy
1-3 routes, no middlewareNative URL + switchZero deps, smallest bundle
Many routes, middleware, typed envHono (de facto)Typed, fast, designed for edge runtimes, OpenAPI integration available
Worker-to-Worker calls onlyRPC via WorkerEntrypointNo HTTP overhead, typed arguments and return values, faster than HTTP service bindings
GraphQLGraphQL Yoga + HonoYoga has a Workers adapter

For Hono patterns (typed env via Hono<{ Bindings: Env, Variables: ... }>, middleware, error boundaries, OpenAPI) and RPC patterns (when to use, named entrypoints, lifecycle), see references/hono-patterns.md.

Step 4 - Test

The canonical testing path is @cloudflare/vitest-plugin v1+ with Vitest 4.1+. It runs tests inside the Workers runtime via Miniflare, with bindings mocked or real (your choice), HMR for fast reruns, and isolated per-test storage.

See references/testing-with-vitest-pool.md for setup details. The pattern:

  • vitest.config.ts registers the cloudflareTest() Vite plugin (exported from @cloudflare/vitest-plugin) inside a standard defineConfig from vitest/config, pointing at your wrangler.jsonc
  • tsconfig.json for tests includes "@cloudflare/vitest-plugin/types" in types (declares the cloudflare:test module)
  • Unit tests: import the handler, call worker.fetch(request, env, ctx) directly with mocked env
  • Integration tests: use SELF.fetch() from cloudflare:test (in-process) or auxiliary Workers (fresh isolate)

[!IMPORTANT] Cloudflare renamed @cloudflare/vitest-pool-workers to @cloudflare/vitest-plugin in v1. Migrate the dependency, package imports, and TypeScript types entry. The configuration API remains cloudflareTest({ wrangler: { configPath: "./wrangler.jsonc" } }) inside plugins in a vitest/config defineConfig; do not restore the removed defineWorkersConfig helper.

Reject in review: new tests using unstable_dev or the renamed @cloudflare/vitest-pool-workers package.

Step 5 - Deploy and roll out gradually

Workers supports two deployment models:

  • Standard deploy (wrangler deploy) - upload and immediately serve 100% from the new version. Fine for low-risk changes.
  • Gradual deployment (wrangler versions upload then wrangler versions deploy) - upload as a new version without serving traffic, split traffic between old and new, then promote to 100%. Required for production HTTP Workers serving customer traffic.

Headline commands:

bash
# Upload new version without deploying
wrangler versions upload

# Interactive split (prompts for percentages)
wrangler versions deploy

# Non-interactive: 90% old, 10% new
wrangler versions deploy <old-version-id>@90 <new-version-id>@10

# Promote to 100%
wrangler versions deploy <new-version-id>@100

Smoke-test a specific version in production via the Cloudflare-Workers-Version-Overrides request header (the version override applies even when its percentage is 0%).

For CI integration (OIDC trust for GitHub Actions instead of long-lived API tokens), secret rotation, and the canary-then-promote pattern, see references/deployment-and-versions.md.

Step 6 - Verify and ship

Before merge:

  • wrangler types regenerated; worker-configuration.d.ts matches wrangler.jsonc
  • tsc --noEmit clean
  • wrangler deploy --dry-run clean (catches binding misconfigurations)
  • @cloudflare/vitest-plugin tests pass
  • PR description names the rejected storage alternatives and why
  • PR description names the soak plan for the gradual rollout (e.g., "10% for 1h, then 50% for 1h, then 100%")
  • Reviewer checklist from 401-cloudflare-workers.mdc ticked

Self-check before submitting

The high-leverage subset of the 401-cloudflare-workers.mdc reviewer checklist:

  • Module Workers syntax (export default {...} or class extends WorkerEntrypoint); no addEventListener("fetch", ...)
  • Env interface imported from generated worker-configuration.d.ts; satisfies ExportedHandler<Env> on the default export
  • No secrets in console.log, error messages, response bodies, or thrown errors
  • All fire-and-forget async work wrapped in ctx.waitUntil()
  • Cloudflare resources declared as bindings (not env vars); Worker-to-Worker calls use Service Bindings + RPC (not public URLs)
  • Subrequest budget considered; loops use batching where the API supports it (D1 batch(), etc.)
  • No top-level await, no module-scope mutable state, no module-scope fetch()
  • compatibility_date set; compatibility_flags minimal and justified
  • wrangler.jsonc is source of truth; deployment from CI (not Dashboard "Edit code")
  • Tests use @cloudflare/vitest-plugin (not deprecated unstable_dev)

See references/common-pitfalls.md for the full list of failure modes observed across many Workers teams, organized by symptom (cold-start regressions, intermittent state pollution, secret leaks, subrequest budget exhaustion, deployment drift).


Related

  • 401-cloudflare-workers.mdc - the rule (file-scoped non-negotiables)
  • 400-cloudflare.mdc - broader Cloudflare platform playbook
  • 405-cloudflare-waf-rules.mdc - file-scoped WAF rule playbook
  • cloud-platforms skill - cross-cloud platform patterns
  • cloudflare-waf-author skill - WAF rule authoring workflow companion
  • skills/typescript-javascript - general TypeScript / JavaScript patterns

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Cloudflare Workers Author؟

Workflow for building production-grade Cloudflare Workers in TypeScript - bootstrap, bindings and storage choice, routing (Hono + RPC via WorkerEntrypoint), testing with @cloudflare/vitest-plugin, gradual deployments, and common pitfalls. Use when adding a new Worker, adding endpoints to an existing Worker, choosing between KV / R2 / D1 / Durable Objects / Hyperdrive, setting up testing, configuring deployment, or reviewing a Worker PR.

لماذا تستخدم Cloudflare Workers Author على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Cloudflare Workers Author عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Cloudflare Workers Author في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/d-padmanabhan/agent-engineering-handbook/tree/main/skills/cloudflare-workers-author. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Cloudflare Workers Author؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Cloudflare Workers Author؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Cloudflare Workers Author معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Cloudflare Workers Author مجانية؟

نعم. نشرها d-padmanabhan على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇