@vesviet/agent-skills 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/INDEX.md +5 -5
  2. package/README.md +1 -1
  3. package/VERSION +1 -1
  4. package/adapters/antigravity/a2a-config.template.yaml +1 -1
  5. package/adapters/antigravity/role-skill-index.json +12 -12
  6. package/adapters/claude/CLAUDE_ADAPTER.md +1 -1
  7. package/adapters/cursor/README.md +185 -185
  8. package/bin/agent-skills.mjs +17 -14
  9. package/core/contracts/README.md +1 -1
  10. package/core/contracts/schemas/api-contract-spec.json +191 -191
  11. package/core/contracts/schemas/data-pipeline-spec.json +1 -1
  12. package/core/contracts/schemas/design-tokens-spec.json +19 -0
  13. package/core/contracts/schemas/feature-ticket.json +1293 -1293
  14. package/core/contracts/schemas/pull-request-spec.json +338 -338
  15. package/core/contracts/schemas/references/detailed/01-solution-and-governance.md +19 -19
  16. package/core/contracts/schemas/references/detailed/02-engineering-delivery.md +93 -93
  17. package/core/contracts/schemas/references/detailed/04-finance-accounting-and-compliance.md +54 -54
  18. package/core/contracts/schemas/references/detailed/05-design-and-content.md +92 -92
  19. package/core/contracts/schemas/references/detailed/06-seo-and-publishing.md +48 -48
  20. package/core/contracts/schemas/references/detailed/07-a2a-protocol.md +85 -85
  21. package/core/contracts/schemas/security-audit.json +143 -12
  22. package/core/contracts/schemas/system-design-spec.json +9 -1
  23. package/core/contracts/schemas/test-report.json +530 -530
  24. package/core/contracts/schemas/ux-flow-spec.json +66 -0
  25. package/core/roles/ai-systems-engineer.md +31 -18
  26. package/core/roles/aws-engineer.md +33 -29
  27. package/core/roles/backend-developer.md +6 -4
  28. package/core/roles/content-manager.md +7 -7
  29. package/core/roles/data-engineer.md +39 -36
  30. package/core/roles/qa-engineer.md +18 -18
  31. package/core/roles/references/ai-systems-engineer-review-checklist.md +11 -3
  32. package/core/roles/references/aws-engineer-review-checklist.md +29 -16
  33. package/core/roles/references/business-analyst-responsibilities.md +207 -207
  34. package/core/roles/references/content-manager-governance-standards.md +2 -2
  35. package/core/roles/references/content-manager-review-checklist.md +7 -1
  36. package/core/roles/references/data-engineer-review-checklist.md +11 -3
  37. package/core/roles/references/frontend-developer-responsibilities.md +275 -275
  38. package/core/roles/references/qa-engineer-review-checklist.md +10 -5
  39. package/core/roles/references/security-engineer-review-checklist.md +8 -0
  40. package/core/roles/references/solution-architect-review-checklist.md +6 -1
  41. package/core/roles/references/system-engineer-review-checklist.md +11 -0
  42. package/core/roles/references/ui-ux-designer-review-checklist.md +12 -0
  43. package/core/roles/security-engineer.md +35 -5
  44. package/core/roles/solution-architect.md +7 -7
  45. package/core/roles/system-engineer.md +470 -465
  46. package/core/roles/ui-ux-designer.md +17 -3
  47. package/core/skills/agent/agent-memory-compaction/references/anchored-schema-and-compaction-algorithms.md +141 -141
  48. package/core/skills/agent/architect-mcp-server/SKILL.md +3 -3
  49. package/core/skills/agent/decompose-agentic-system/SKILL.md +1 -1
  50. package/core/skills/ai/deploy-vllm-inference/SKILL.md +14 -14
  51. package/core/skills/ai-agent/agent-evaluation/SKILL.md +5 -0
  52. package/core/skills/ai-agent/context-optimization/SKILL.md +9 -0
  53. package/core/skills/backend/add-api-endpoint/SKILL.md +1 -0
  54. package/core/skills/backend/add-event-handler/SKILL.md +1 -0
  55. package/core/skills/backend/add-service-client/SKILL.md +1 -0
  56. package/core/skills/backend/build-mcp-server/SKILL.md +101 -100
  57. package/core/skills/backend/implement-auth/SKILL.md +1 -0
  58. package/core/skills/backend/implement-structured-outputs/SKILL.md +95 -94
  59. package/core/skills/backend/optimize-postgres/SKILL.md +1 -0
  60. package/core/skills/backend/scaffold-new-service/SKILL.md +1 -0
  61. package/core/skills/business/elicit-requirements/SKILL.md +102 -102
  62. package/core/skills/business/elicit-requirements/references/elicitation-techniques-and-babok-criteria.md +60 -60
  63. package/core/skills/business/trace-requirements-impact/SKILL.md +97 -97
  64. package/core/skills/business/trace-requirements-impact/references/rtm-graph-and-prioritization-models.md +109 -109
  65. package/core/skills/business/write-use-cases/SKILL.md +106 -106
  66. package/core/skills/business/write-use-cases/references/cockburn-scoping-and-13-field-template.md +135 -135
  67. package/core/skills/content/audit-content/SKILL.md +3 -2
  68. package/core/skills/content/audit-content/references/information-gain-rubric.md +1 -1
  69. package/core/skills/content/design-content-strategy/SKILL.md +6 -5
  70. package/core/skills/content/design-content-strategy/references/information-gain-and-decay-triage.md +2 -2
  71. package/core/skills/content/optimize-seo/SKILL.md +6 -5
  72. package/core/skills/content/optimize-seo/references/geo-ai-citation-playbook.md +2 -2
  73. package/core/skills/content/optimize-seo/references/process-and-checklist.md +1 -1
  74. package/core/skills/content/repurpose-content/SKILL.md +4 -3
  75. package/core/skills/content/write-article/SKILL.md +6 -5
  76. package/core/skills/content/write-copy/SKILL.md +3 -2
  77. package/core/skills/document/pptx/SKILL.md +1 -0
  78. package/core/skills/document/pptx/scripts/add_slide.py +0 -0
  79. package/core/skills/document/pptx/scripts/clean.py +0 -0
  80. package/core/skills/document/pptx/scripts/thumbnail.py +0 -0
  81. package/core/skills/document/xlsx/scripts/recalc.py +0 -0
  82. package/core/skills/documentation/write-documentation/SKILL.md +143 -143
  83. package/core/skills/documentation/write-tech-radar/SKILL.md +149 -149
  84. package/core/skills/foundation/accessibility-review/SKILL.md +160 -160
  85. package/core/skills/foundation/design-review/SKILL.md +11 -1
  86. package/core/skills/foundation/design-ux-flow/SKILL.md +13 -1
  87. package/core/skills/foundation/performance-profiling/SKILL.md +3 -1
  88. package/core/skills/foundation/release-notes/SKILL.md +192 -192
  89. package/core/skills/foundation/webapp-server-runner/scripts/with_server.py +0 -0
  90. package/core/skills/foundation/write-product-brief/SKILL.md +160 -160
  91. package/core/skills/foundation/write-tests/SKILL.md +11 -10
  92. package/core/skills/frontend/anti-ui-slop-finish-gate/SKILL.md +5 -0
  93. package/core/skills/frontend/design-md-specification/SKILL.md +1 -0
  94. package/core/skills/frontend/design-system-engineering/SKILL.md +4 -2
  95. package/core/skills/meetings-analysis/analyze-business-requirements/SKILL.md +1 -1
  96. package/core/skills/platform/add-telemetry-instrumentation/SKILL.md +2 -1
  97. package/core/skills/platform/aws-infrastructure/SKILL.md +12 -11
  98. package/core/skills/platform/cloudflare-email-service/SKILL.md +166 -166
  99. package/core/skills/platform/cloudflare-email-service/references/routing.md +199 -199
  100. package/core/skills/platform/debug-runtime-platform/SKILL.md +1 -0
  101. package/core/skills/platform/debug-workers-edge/SKILL.md +111 -111
  102. package/core/skills/platform/sandbox-sdk/SKILL.md +183 -183
  103. package/core/skills/platform/setup-gpu-finops/SKILL.md +111 -107
  104. package/core/skills/platform/setup-llm-gateway/SKILL.md +110 -108
  105. package/core/skills/platform/supply-chain-security/SKILL.md +1 -0
  106. package/core/skills/platform/system-design/SKILL.md +7 -0
  107. package/core/skills/platform/turnstile-spin/SKILL.md +118 -118
  108. package/core/skills/platform/turnstile-spin/scripts/auth-probe.sh +0 -0
  109. package/core/skills/platform/turnstile-spin/scripts/fetch-secret.sh +0 -0
  110. package/core/skills/platform/turnstile-spin/scripts/persist-skill.sh +0 -0
  111. package/core/skills/platform/turnstile-spin/scripts/validate.sh +0 -0
  112. package/core/skills/platform/turnstile-spin/scripts/widget-create.sh +0 -0
  113. package/core/skills/platform/turnstile-spin/scripts/worker-deploy.sh +0 -0
  114. package/core/skills/platform/turnstile-spin/templates/worker/src/index.ts +199 -199
  115. package/core/skills/platform/turnstile-spin/templates/worker/wrangler.toml +31 -31
  116. package/core/skills/platform/web-perf/SKILL.md +151 -151
  117. package/core/skills/platform/workers-best-practices/references/rules.md +463 -463
  118. package/core/skills/product/build-story-map/SKILL.md +104 -104
  119. package/core/skills/product/build-story-map/references/story-mapping-and-cpm-scheduling.md +101 -101
  120. package/core/skills/product/define-product-strategy/SKILL.md +105 -105
  121. package/core/skills/product/define-product-strategy/references/strategy-frameworks-and-pr-faq.md +142 -142
  122. package/core/skills/product/model-saas-metrics/SKILL.md +104 -104
  123. package/core/skills/product/model-saas-metrics/references/saas-unit-economics-and-pricing.md +110 -110
  124. package/core/skills/product/prioritize-roadmap/SKILL.md +106 -106
  125. package/core/skills/product/prioritize-roadmap/references/prioritization-scoring-and-kill-criteria.md +105 -105
  126. package/core/skills/repo-ops/commit-code/SKILL.md +190 -190
  127. package/core/skills/repo-ops/commit-code/references/multi-repo-and-deployment.md +21 -21
  128. package/core/skills/repo-ops/navigate-service/SKILL.md +199 -199
  129. package/core/skills/repo-ops/review-code/references/process-and-format.md +100 -100
  130. package/core/skills/repo-ops/review-service/SKILL.md +186 -186
  131. package/core/skills/repo-ops/troubleshoot-service/SKILL.md +127 -127
  132. package/core/skills/repo-ops/troubleshoot-service/references/failure-modes-and-security.md +22 -22
  133. package/core/skills/repo-ops/troubleshoot-service/references/suggested-process.md +110 -110
  134. package/core/skills/security-data/build-data-pipeline/SKILL.md +15 -14
  135. package/core/skills/security-data/build-data-pipeline/references/producer-contracts-and-lakehouse.md +5 -5
  136. package/core/skills/security-data/database-maintenance/SKILL.md +1 -0
  137. package/core/skills/security-data/database-maintenance/references/relational-and-vector-maintenance.md +5 -5
  138. package/core/skills/security-data/manage-secrets/SKILL.md +3 -0
  139. package/core/skills/security-data/optimize-olap-database/SKILL.md +14 -13
  140. package/core/skills/security-data/optimize-olap-database/references/olap-database-guide.md +2 -2
  141. package/core/skills/security-data/prompt-injection-defense/SKILL.md +3 -0
  142. package/core/skills/security-data/query-analytical-engine/SKILL.md +8 -7
  143. package/core/skills/security-data/query-analytical-engine/references/analytical-query-guide.md +3 -3
  144. package/core/skills/security-data/security-audit/SKILL.md +126 -119
  145. package/core/workflows/add-new-feature.md +212 -212
  146. package/core/workflows/agent-a2a-delegation.md +142 -142
  147. package/core/workflows/bug-fix.md +147 -147
  148. package/core/workflows/build-deploy.md +208 -208
  149. package/core/workflows/code-review.md +137 -137
  150. package/core/workflows/curriculum-delivery.md +1 -1
  151. package/core/workflows/dependency-upgrade.md +193 -193
  152. package/core/workflows/feature-delivery.md +149 -149
  153. package/core/workflows/hotfix-production.md +172 -172
  154. package/core/workflows/qa-validation.md +231 -231
  155. package/core/workflows/refactoring.md +154 -154
  156. package/core/workflows/revert-deployment.md +147 -147
  157. package/core/workflows/security-incident-response.md +191 -191
  158. package/core/workflows/seo-content-lifecycle.md +91 -91
  159. package/core/workflows/service-review-release.md +223 -223
  160. package/core/workflows/setup-new-service.md +214 -214
  161. package/core/workflows/tech-repo-review.md +245 -245
  162. package/core/workflows/troubleshooting.md +241 -241
  163. package/overlays/astro-cloudflare/README.md +93 -93
  164. package/overlays/data-analyst-stack/README.md +109 -109
  165. package/overlays/data-analyst-stack/rules/metric-dashboard-templates.md +135 -135
  166. package/overlays/data-analyst-stack/rules/stack-conventions.md +80 -80
  167. package/overlays/ecommerce-microservices/README.md +65 -65
  168. package/overlays/go-microservices/README.md +78 -78
  169. package/overlays/go-microservices/rules/go-conventions.md +223 -223
  170. package/overlays/laravel-filament/README.md +90 -90
  171. package/overlays/laravel-filament/rules/laravel-conventions.md +220 -220
  172. package/overlays/laravel-filament/skills/develop-laravel-feature/SKILL.md +141 -141
  173. package/overlays/laravel-filament/workflows/deploy-laravel.md +133 -133
  174. package/overlays/obj-configurator/rules/obj-project-rules.md +111 -111
  175. package/overlays/obj-configurator/skills/develop-obj-feature/SKILL.md +71 -71
  176. package/overlays/r3f-stack/README.md +89 -89
  177. package/overlays/r3f-stack/rules/stub.md +43 -43
  178. package/overlays/r3f-stack/skills/debug-3d-scene/SKILL.md +166 -166
  179. package/overlays/r3f-stack/skills/integrate-r3f-three-legacy/SKILL.md +159 -159
  180. package/overlays/r3f-stack/skills/optimize-3d-assets/SKILL.md +128 -128
  181. package/overlays/seo-publishing/rules/site-mix-and-cannibalization.md +52 -52
  182. package/overlays/ui-design-system/rules/handoff-conventions.md +73 -73
  183. package/package.json +2 -2
  184. package/core/README.md +0 -53
@@ -1,199 +1,199 @@
1
- # Receiving & Routing Inbound Email
2
-
3
- Handle incoming emails sent to your domain via a Worker's `email()` handler. Forward, reply, reject, or parse emails programmatically.
4
-
5
- For full API details, see the [Email Routing docs](https://developers.cloudflare.com/email-service/api/route-emails/email-handler/).
6
-
7
- ## Email Handler
8
-
9
- Export an `email()` function from your Worker. No special wrangler binding needed — a routing rule connects incoming addresses to your Worker.
10
-
11
- ```typescript
12
- export default {
13
- async email(message, env, ctx): Promise<void> {
14
- console.log(`Email from ${message.from} to ${message.to}`);
15
- await message.forward("team@company.com");
16
- },
17
- } satisfies ExportedHandler<Env>;
18
- ```
19
-
20
- Set up routing rules in **Dashboard** > **Compute & AI** > **Email Service** > **Email Routing** > **Routing Rules**, or via `wrangler email routing rules create`.
21
-
22
- ## ForwardableEmailMessage
23
-
24
- The `message` parameter is a `ForwardableEmailMessage`. Run `npx wrangler types` to get the full type definition. Key properties and methods:
25
-
26
- - `message.from` / `message.to` — envelope addresses (SMTP MAIL FROM / RCPT TO). `message.from` is trustworthy; header addresses can be spoofed.
27
- - `message.headers` — `Headers` object (use `.get("subject")`, `.get("message-id")`, etc.)
28
- - `message.raw` — `ReadableStream<Uint8Array>` of raw MIME content. **Single use** — buffer before accessing.
29
- - `message.rawSize` — size in bytes
30
- - `message.setReject(reason)` — reject with a permanent SMTP error
31
- - `message.forward(rcptTo, headers?)` — forward to a verified destination
32
- - `message.reply(emailMessage)` — reply with an `EmailMessage` object
33
-
34
- ## Core Operations
35
-
36
- ### Forward
37
-
38
- ```typescript
39
- await message.forward("team@company.com");
40
-
41
- // With custom headers
42
- await message.forward("team@company.com", new Headers({
43
- "X-Original-Recipient": message.to,
44
- }));
45
- ```
46
-
47
- Destination must be verified first (Dashboard or `wrangler email routing addresses create`).
48
-
49
- ### Reject
50
-
51
- ```typescript
52
- message.setReject("Your message was blocked");
53
- ```
54
-
55
- ### Reply
56
-
57
- Using `env.EMAIL.send()` (recommended — no extra dependencies):
58
-
59
- ```typescript
60
- async email(message, env, ctx) {
61
- const subject = message.headers.get("subject") || "";
62
- await env.EMAIL.send({
63
- to: message.from,
64
- from: message.to,
65
- subject: `Re: ${subject}`,
66
- html: "<p>Thanks! We'll respond shortly.</p>",
67
- text: "Thanks! We'll respond shortly.",
68
- });
69
- await message.forward("team@company.com");
70
- }
71
- ```
72
-
73
- Using `message.reply()` with MIME (more control, requires `mimetext` + `nodejs_compat`):
74
-
75
- ```typescript
76
- import { EmailMessage } from "cloudflare:email";
77
- import { createMimeMessage } from "mimetext";
78
-
79
- async email(message, env, ctx) {
80
- const msg = createMimeMessage();
81
- const messageId = message.headers.get("Message-ID");
82
- if (messageId) msg.setHeader("In-Reply-To", messageId);
83
- msg.setSender({ name: "Support", addr: "support@yourdomain.com" });
84
- msg.setRecipient(message.from);
85
- msg.setSubject("Re: " + (message.headers.get("subject") || ""));
86
- msg.addMessage({ contentType: "text/plain", data: "Thanks for reaching out!" });
87
-
88
- await message.reply(new EmailMessage("support@yourdomain.com", message.from, msg.asRaw()));
89
- }
90
- ```
91
-
92
- ## Parsing Emails
93
-
94
- Use [postal-mime](https://www.npmjs.com/package/postal-mime) to parse raw MIME content:
95
-
96
- ```typescript
97
- import PostalMime from "postal-mime";
98
-
99
- async email(message, env, ctx) {
100
- const rawBuffer = await new Response(message.raw).arrayBuffer();
101
- const parsed = await PostalMime.parse(rawBuffer);
102
-
103
- console.log("Subject:", parsed.subject);
104
- console.log("Text:", parsed.text);
105
- console.log("Attachments:", parsed.attachments.length);
106
- }
107
- ```
108
-
109
- ## Store and Reply Later (Human-in-the-Loop)
110
-
111
- A common pattern is to store incoming emails in a Durable Object (SQLite) so a human or AI agent can review and reply later — rather than replying immediately in the `email()` handler. This enables support inboxes, approval workflows, and AI-drafted replies.
112
-
113
- ### Architecture
114
-
115
- ```
116
- Email Routing → email() handler → parse + store in DO → user reviews later → reply via send_email binding
117
- ```
118
-
119
- The `email()` handler stores the email and returns immediately. Replies happen later via a separate HTTP request or agent action.
120
-
121
- ### Receive and Store
122
-
123
- ```typescript
124
- import PostalMime from "postal-mime";
125
-
126
- export class MailboxDO extends DurableObject {
127
- async storeEmail(from: string, to: string, subject: string, body: string,
128
- messageId: string, inReplyTo: string | null) {
129
- this.ctx.storage.sql.exec(
130
- `INSERT INTO emails (sender, recipient, subject, body, message_id, in_reply_to, date, read)
131
- VALUES (?, ?, ?, ?, ?, ?, datetime('now'), 0)`,
132
- from, to, subject, body, messageId, inReplyTo
133
- );
134
- }
135
- }
136
-
137
- export default {
138
- async email(message, env, ctx) {
139
- const raw = await new Response(message.raw).arrayBuffer();
140
- const parsed = await PostalMime.parse(raw);
141
-
142
- const id = env.MAILBOX.idFromName(message.to);
143
- const stub = env.MAILBOX.get(id);
144
-
145
- await stub.storeEmail(
146
- message.from,
147
- message.to,
148
- parsed.subject || "(no subject)",
149
- parsed.text || parsed.html || "",
150
- message.headers.get("message-id") || "",
151
- message.headers.get("in-reply-to") || null,
152
- );
153
-
154
- // Optionally trigger an AI system to draft a reply (non-blocking)
155
- // ctx.waitUntil(notifyAgent(env, message.to, emailId));
156
- },
157
- } satisfies ExportedHandler<Env>;
158
- ```
159
-
160
- ### Reply Later
161
-
162
- When a user (or agent) decides to reply, build proper threading headers and send via the `send_email` binding:
163
-
164
- ```typescript
165
- // In an HTTP handler or system tool — not in the email() handler
166
- async function replyToStoredEmail(env: Env, original: StoredEmail, replyBody: string) {
167
- // Build threading headers (In-Reply-To + References per RFC 2822)
168
- const headers: Record<string, string> = {};
169
- if (original.messageId) {
170
- headers["In-Reply-To"] = original.messageId;
171
- headers["References"] = original.messageId;
172
- }
173
-
174
- await env.EMAIL.send({
175
- to: original.sender,
176
- from: original.recipient,
177
- subject: `Re: ${original.subject}`,
178
- text: replyBody,
179
- html: `<p>${replyBody}</p>`,
180
- headers,
181
- });
182
- }
183
- ```
184
-
185
- ### Key Design Points
186
-
187
- - **Buffer `message.raw` once**, parse with `postal-mime`, then store structured fields. Don't store the raw stream.
188
- - **Extract `Message-ID`, `In-Reply-To`, and `References`** headers during ingest for threading. Fall back to subject-based matching for emails without threading headers.
189
- - **Use Durable Object SQLite** for per-mailbox storage — each mailbox gets its own DO instance keyed by email address, providing natural isolation.
190
- - **Store attachments separately** in R2 (binary blobs), with metadata in SQLite.
191
- - **Defer heavy work** (AI drafting, notifications) via `ctx.waitUntil()` so the `email()` handler returns quickly.
192
- - **Never auto-send from the `email()` handler** in a human-in-the-loop flow. Store a draft, let the user review, then send via a separate action.
193
-
194
- ## Gotchas
195
-
196
- - **`message.raw` is single-use.** Buffer first: `const raw = await new Response(message.raw).arrayBuffer()`
197
- - **Destinations must be verified.** Forwarding to unverified addresses fails silently.
198
- - **Handler must act.** If your handler returns without consuming raw, forwarding, or rejecting, the email is dropped.
199
- - **DMARC/SPF for replies.** If sending replies, ensure your domain has proper SPF/DKIM records (auto-configured on domain onboarding).
1
+ # Receiving & Routing Inbound Email
2
+
3
+ Handle incoming emails sent to your domain via a Worker's `email()` handler. Forward, reply, reject, or parse emails programmatically.
4
+
5
+ For full API details, see the [Email Routing docs](https://developers.cloudflare.com/email-service/api/route-emails/email-handler/).
6
+
7
+ ## Email Handler
8
+
9
+ Export an `email()` function from your Worker. No special wrangler binding needed — a routing rule connects incoming addresses to your Worker.
10
+
11
+ ```typescript
12
+ export default {
13
+ async email(message, env, ctx): Promise<void> {
14
+ console.log(`Email from ${message.from} to ${message.to}`);
15
+ await message.forward("team@company.com");
16
+ },
17
+ } satisfies ExportedHandler<Env>;
18
+ ```
19
+
20
+ Set up routing rules in **Dashboard** > **Compute & AI** > **Email Service** > **Email Routing** > **Routing Rules**, or via `wrangler email routing rules create`.
21
+
22
+ ## ForwardableEmailMessage
23
+
24
+ The `message` parameter is a `ForwardableEmailMessage`. Run `npx wrangler types` to get the full type definition. Key properties and methods:
25
+
26
+ - `message.from` / `message.to` — envelope addresses (SMTP MAIL FROM / RCPT TO). `message.from` is trustworthy; header addresses can be spoofed.
27
+ - `message.headers` — `Headers` object (use `.get("subject")`, `.get("message-id")`, etc.)
28
+ - `message.raw` — `ReadableStream<Uint8Array>` of raw MIME content. **Single use** — buffer before accessing.
29
+ - `message.rawSize` — size in bytes
30
+ - `message.setReject(reason)` — reject with a permanent SMTP error
31
+ - `message.forward(rcptTo, headers?)` — forward to a verified destination
32
+ - `message.reply(emailMessage)` — reply with an `EmailMessage` object
33
+
34
+ ## Core Operations
35
+
36
+ ### Forward
37
+
38
+ ```typescript
39
+ await message.forward("team@company.com");
40
+
41
+ // With custom headers
42
+ await message.forward("team@company.com", new Headers({
43
+ "X-Original-Recipient": message.to,
44
+ }));
45
+ ```
46
+
47
+ Destination must be verified first (Dashboard or `wrangler email routing addresses create`).
48
+
49
+ ### Reject
50
+
51
+ ```typescript
52
+ message.setReject("Your message was blocked");
53
+ ```
54
+
55
+ ### Reply
56
+
57
+ Using `env.EMAIL.send()` (recommended — no extra dependencies):
58
+
59
+ ```typescript
60
+ async email(message, env, ctx) {
61
+ const subject = message.headers.get("subject") || "";
62
+ await env.EMAIL.send({
63
+ to: message.from,
64
+ from: message.to,
65
+ subject: `Re: ${subject}`,
66
+ html: "<p>Thanks! We'll respond shortly.</p>",
67
+ text: "Thanks! We'll respond shortly.",
68
+ });
69
+ await message.forward("team@company.com");
70
+ }
71
+ ```
72
+
73
+ Using `message.reply()` with MIME (more control, requires `mimetext` + `nodejs_compat`):
74
+
75
+ ```typescript
76
+ import { EmailMessage } from "cloudflare:email";
77
+ import { createMimeMessage } from "mimetext";
78
+
79
+ async email(message, env, ctx) {
80
+ const msg = createMimeMessage();
81
+ const messageId = message.headers.get("Message-ID");
82
+ if (messageId) msg.setHeader("In-Reply-To", messageId);
83
+ msg.setSender({ name: "Support", addr: "support@yourdomain.com" });
84
+ msg.setRecipient(message.from);
85
+ msg.setSubject("Re: " + (message.headers.get("subject") || ""));
86
+ msg.addMessage({ contentType: "text/plain", data: "Thanks for reaching out!" });
87
+
88
+ await message.reply(new EmailMessage("support@yourdomain.com", message.from, msg.asRaw()));
89
+ }
90
+ ```
91
+
92
+ ## Parsing Emails
93
+
94
+ Use [postal-mime](https://www.npmjs.com/package/postal-mime) to parse raw MIME content:
95
+
96
+ ```typescript
97
+ import PostalMime from "postal-mime";
98
+
99
+ async email(message, env, ctx) {
100
+ const rawBuffer = await new Response(message.raw).arrayBuffer();
101
+ const parsed = await PostalMime.parse(rawBuffer);
102
+
103
+ console.log("Subject:", parsed.subject);
104
+ console.log("Text:", parsed.text);
105
+ console.log("Attachments:", parsed.attachments.length);
106
+ }
107
+ ```
108
+
109
+ ## Store and Reply Later (Human-in-the-Loop)
110
+
111
+ A common pattern is to store incoming emails in a Durable Object (SQLite) so a human or AI agent can review and reply later — rather than replying immediately in the `email()` handler. This enables support inboxes, approval workflows, and AI-drafted replies.
112
+
113
+ ### Architecture
114
+
115
+ ```
116
+ Email Routing → email() handler → parse + store in DO → user reviews later → reply via send_email binding
117
+ ```
118
+
119
+ The `email()` handler stores the email and returns immediately. Replies happen later via a separate HTTP request or agent action.
120
+
121
+ ### Receive and Store
122
+
123
+ ```typescript
124
+ import PostalMime from "postal-mime";
125
+
126
+ export class MailboxDO extends DurableObject {
127
+ async storeEmail(from: string, to: string, subject: string, body: string,
128
+ messageId: string, inReplyTo: string | null) {
129
+ this.ctx.storage.sql.exec(
130
+ `INSERT INTO emails (sender, recipient, subject, body, message_id, in_reply_to, date, read)
131
+ VALUES (?, ?, ?, ?, ?, ?, datetime('now'), 0)`,
132
+ from, to, subject, body, messageId, inReplyTo
133
+ );
134
+ }
135
+ }
136
+
137
+ export default {
138
+ async email(message, env, ctx) {
139
+ const raw = await new Response(message.raw).arrayBuffer();
140
+ const parsed = await PostalMime.parse(raw);
141
+
142
+ const id = env.MAILBOX.idFromName(message.to);
143
+ const stub = env.MAILBOX.get(id);
144
+
145
+ await stub.storeEmail(
146
+ message.from,
147
+ message.to,
148
+ parsed.subject || "(no subject)",
149
+ parsed.text || parsed.html || "",
150
+ message.headers.get("message-id") || "",
151
+ message.headers.get("in-reply-to") || null,
152
+ );
153
+
154
+ // Optionally trigger an AI system to draft a reply (non-blocking)
155
+ // ctx.waitUntil(notifyAgent(env, message.to, emailId));
156
+ },
157
+ } satisfies ExportedHandler<Env>;
158
+ ```
159
+
160
+ ### Reply Later
161
+
162
+ When a user (or agent) decides to reply, build proper threading headers and send via the `send_email` binding:
163
+
164
+ ```typescript
165
+ // In an HTTP handler or system tool — not in the email() handler
166
+ async function replyToStoredEmail(env: Env, original: StoredEmail, replyBody: string) {
167
+ // Build threading headers (In-Reply-To + References per RFC 2822)
168
+ const headers: Record<string, string> = {};
169
+ if (original.messageId) {
170
+ headers["In-Reply-To"] = original.messageId;
171
+ headers["References"] = original.messageId;
172
+ }
173
+
174
+ await env.EMAIL.send({
175
+ to: original.sender,
176
+ from: original.recipient,
177
+ subject: `Re: ${original.subject}`,
178
+ text: replyBody,
179
+ html: `<p>${replyBody}</p>`,
180
+ headers,
181
+ });
182
+ }
183
+ ```
184
+
185
+ ### Key Design Points
186
+
187
+ - **Buffer `message.raw` once**, parse with `postal-mime`, then store structured fields. Don't store the raw stream.
188
+ - **Extract `Message-ID`, `In-Reply-To`, and `References`** headers during ingest for threading. Fall back to subject-based matching for emails without threading headers.
189
+ - **Use Durable Object SQLite** for per-mailbox storage — each mailbox gets its own DO instance keyed by email address, providing natural isolation.
190
+ - **Store attachments separately** in R2 (binary blobs), with metadata in SQLite.
191
+ - **Defer heavy work** (AI drafting, notifications) via `ctx.waitUntil()` so the `email()` handler returns quickly.
192
+ - **Never auto-send from the `email()` handler** in a human-in-the-loop flow. Store a draft, let the user review, then send via a separate action.
193
+
194
+ ## Gotchas
195
+
196
+ - **`message.raw` is single-use.** Buffer first: `const raw = await new Response(message.raw).arrayBuffer()`
197
+ - **Destinations must be verified.** Forwarding to unverified addresses fails silently.
198
+ - **Handler must act.** If your handler returns without consuming raw, forwarding, or rejecting, the email is dropped.
199
+ - **DMARC/SPF for replies.** If sending replies, ensure your domain has proper SPF/DKIM records (auto-configured on domain onboarding).
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: debug-runtime-platform
3
3
  description: Investigate deployment, environment, runtime, and rollout issues that are not purely application-code bugs. Use when the service behaves differently across environments or when deployment health is unclear.
4
+ version: 1.0.0
4
5
  allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, execute_command]
5
6
  ---
6
7
 
@@ -1,111 +1,111 @@
1
- ---
2
- name: debug-workers-edge
3
- description: Diagnose Cloudflare Pages and Workers failures at the edge — 5xx, binding errors, Wrangler deploy failures, DNS/cache issues, and context loss. Use when symptoms appear after deploy or only on Cloudflare runtime, not in local dev alone.
4
- allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, wrangler_deploy, execute_command]
5
- ---
6
-
7
- # Debug Workers Edge
8
-
9
- Use with the **Cloudflare Engineer** role for platform-layer failures. Escalate to `troubleshoot-service` when evidence points to application logic inside API handlers.
10
-
11
- ## When to Use
12
-
13
- - 5xx or binding errors on Cloudflare runtime
14
- - Wrangler deploy failures
15
- - DNS/cache issues only on edge
16
- - context loss after deploy
17
-
18
- ## Core Rules
19
-
20
- - compare local preview vs deployed behavior before changing production
21
- - read Workers/Pages logs and request IDs — do not guess from status codes alone
22
- - separate binding misconfiguration from application exceptions
23
- - prefer rollback or route disable for production incidents when blast radius is unclear
24
- - get approval for production DNS, cache purge, or binding deletes per policy
25
- - **WRANGLER-V4-REMOTE**: In Wrangler v4, `wrangler dev` defaults to local mode — use `--remote` flag explicitly to bind against real production D1/R2/KV resources; update any CI runbooks that assumed `--remote` as the default.
26
- - **WORKERS-OBSERVABILITY-DASHBOARD**: Use the Workers Observability dashboard for custom P99 CPU charts, JSON/CSV log export, and shareable trace URLs — requires `"observability": { "enabled": true }` in `wrangler.jsonc` to persist logs.
27
- - **OBSERVABILITY-BLOCK-REQUIRED**: `wrangler tail` does NOT persist logs without the `observability` block enabled in `wrangler.jsonc`. Add this block to all production Workers before any debugging session.
28
-
29
- ## Suggested Process
30
-
31
- ### 1. Capture Symptom
32
-
33
- Record:
34
-
35
- - URL, status code, environment (preview/production)
36
- - time of first failure vs last deploy
37
- - whether static assets vs API/Worker routes fail
38
-
39
- ### 2. Check Deploy And Config Drift
40
-
41
- Verify:
42
-
43
- - last successful deployment ID / commit
44
- - wrangler config vs dashboard bindings
45
- - secret presence (names only) in Dashboard vs `.dev.vars` locally
46
- - `nodejs_compat` and compatibility date issues
47
-
48
- ### 3. Isolate Layer
49
-
50
- | Signal | Likely layer |
51
- | ------ | ------------- |
52
- | Binding not found | Wrangler / env types |
53
- | 1101 / script error | Worker code — collaborate with dev |
54
- | SSL / DNS | dns_and_routing in edge spec |
55
- | Stale asset | cache rules or purge scope |
56
- | Turnstile failure | turnstile site keys / domains |
57
-
58
- ### 4. Apply Smallest Safe Fix
59
-
60
- Examples:
61
-
62
- - fix binding name or resource ID in repo
63
- - redeploy previous artifact
64
- - narrow cache purge (not whole zone without approval)
65
- - adjust route pattern
66
-
67
- ### 5. Verify And Document
68
-
69
- Run smoke_tests from edge-deployment-spec; update residual_risks for SRE/DevOps.
70
-
71
- ## Checklist
72
-
73
- - [ ] environment and route scope captured
74
- - [ ] deploy revision compared to failing window
75
- - [ ] bindings and secrets checked (names only in notes)
76
- - [ ] platform vs application layer decided
77
- - [ ] smallest safe fix applied
78
- - [ ] smoke tests pass after recovery
79
-
80
- ## Output Contracts
81
-
82
- When this skill is invoked as part of a coordinated multi-role delivery, emit:
83
-
84
- - **contracts/schemas/deployment-plan.json** — Required fields: infrastructure_changes[], config_updates[], and
85
- alidation_run. Set produced_by_role to the emitting developer role.
86
-
87
- Skip emission for solo refactor work where no downstream handoff is expected.
88
-
89
- ## Failure Modes
90
-
91
- - **Local-only assumption**: a fix is made locally and shipped without verifying on the deployed edge. Mitigation: always compare `wrangler dev --remote` against the deployed behavior before changing production.
92
- - **Status code guessing**: a 5xx is "fixed" based on the status alone without reading logs. Mitigation: read Workers Observability logs and request IDs first; never guess.
93
- - **Whole-zone cache purge**: a single-route cache issue triggers a full-zone purge. Mitigation: narrow the purge to the affected URL pattern; require approval for full-zone purges.
94
- - **Missing observability block**: `wrangler tail` is used to debug a production issue but logs are not persisted. Mitigation: require `"observability": { "enabled": true }` in `wrangler.jsonc` for all production Workers.
95
- - **Wrangler v4 default surprise**: a CI runbook assumes `wrangler dev` defaults to `--remote`; in v4 it defaults to local. Mitigation: pass `--remote` explicitly; update runbooks.
96
- - **Secret leaked in notes**: secret names (or values) are pasted into debug notes or chat. Mitigation: reference secrets by name only; never log values.
97
- - **Rollback skipped**: an incident is "fixed" without confirming the previous artifact is still available for rollback. Mitigation: verify the previous deployment ID is rollbackable before applying the new fix.
98
-
99
- ## Security Guardrails (OWASP ASI)
100
-
101
- - **ASI01 Goal Hijack**: a debug session may drift into changing application code outside the incident's scope. Mitigation: scope every debug change to the failing layer; open a separate task for unrelated fixes.
102
- - **ASI03 Identity & Privilege Abuse**: a debug command that requires elevated scopes (e.g., secret rotation, DNS update) must be approved; reject ad-hoc privilege escalation.
103
- - **ASI04 Supply Chain**: Wrangler CLI, observability agents, and edge config must be schema-validated against the expected manifest; treat unknown versions as untrusted.
104
- - **ASI07 Inter-Agent Communication**: the incident report is consumed by SRE and DevOps; emit a structured contract so each role can validate the remediation.
105
- - **ASI09 Human-Agent Trust Exploitation**: do not present a fix as "resolved" without a smoke test on the deployed edge; surface the residual risk honestly.
106
-
107
- ## Related Skills
108
-
109
- - **wrangler**: Wrangler CLI for deploying, developing, and managing Workers
110
- - **debug-runtime-platform**: Broader platform issues shared with DevOps/SRE
111
- - **troubleshoot-service**: Application-level API or Astro handler bugs
1
+ ---
2
+ name: debug-workers-edge
3
+ description: Diagnose Cloudflare Pages and Workers failures at the edge — 5xx, binding errors, Wrangler deploy failures, DNS/cache issues, and context loss. Use when symptoms appear after deploy or only on Cloudflare runtime, not in local dev alone.
4
+ allowed-tools: [read_file, write_file, edit_file, create_file, search_code, run_tests, run_linter, run_build, wrangler_deploy, execute_command]
5
+ ---
6
+
7
+ # Debug Workers Edge
8
+
9
+ Use with the **Cloudflare Engineer** role for platform-layer failures. Escalate to `troubleshoot-service` when evidence points to application logic inside API handlers.
10
+
11
+ ## When to Use
12
+
13
+ - 5xx or binding errors on Cloudflare runtime
14
+ - Wrangler deploy failures
15
+ - DNS/cache issues only on edge
16
+ - context loss after deploy
17
+
18
+ ## Core Rules
19
+
20
+ - compare local preview vs deployed behavior before changing production
21
+ - read Workers/Pages logs and request IDs — do not guess from status codes alone
22
+ - separate binding misconfiguration from application exceptions
23
+ - prefer rollback or route disable for production incidents when blast radius is unclear
24
+ - get approval for production DNS, cache purge, or binding deletes per policy
25
+ - **WRANGLER-V4-REMOTE**: In Wrangler v4, `wrangler dev` defaults to local mode — use `--remote` flag explicitly to bind against real production D1/R2/KV resources; update any CI runbooks that assumed `--remote` as the default.
26
+ - **WORKERS-OBSERVABILITY-DASHBOARD**: Use the Workers Observability dashboard for custom P99 CPU charts, JSON/CSV log export, and shareable trace URLs — requires `"observability": { "enabled": true }` in `wrangler.jsonc` to persist logs.
27
+ - **OBSERVABILITY-BLOCK-REQUIRED**: `wrangler tail` does NOT persist logs without the `observability` block enabled in `wrangler.jsonc`. Add this block to all production Workers before any debugging session.
28
+
29
+ ## Suggested Process
30
+
31
+ ### 1. Capture Symptom
32
+
33
+ Record:
34
+
35
+ - URL, status code, environment (preview/production)
36
+ - time of first failure vs last deploy
37
+ - whether static assets vs API/Worker routes fail
38
+
39
+ ### 2. Check Deploy And Config Drift
40
+
41
+ Verify:
42
+
43
+ - last successful deployment ID / commit
44
+ - wrangler config vs dashboard bindings
45
+ - secret presence (names only) in Dashboard vs `.dev.vars` locally
46
+ - `nodejs_compat` and compatibility date issues
47
+
48
+ ### 3. Isolate Layer
49
+
50
+ | Signal | Likely layer |
51
+ | ------ | ------------- |
52
+ | Binding not found | Wrangler / env types |
53
+ | 1101 / script error | Worker code — collaborate with dev |
54
+ | SSL / DNS | dns_and_routing in edge spec |
55
+ | Stale asset | cache rules or purge scope |
56
+ | Turnstile failure | turnstile site keys / domains |
57
+
58
+ ### 4. Apply Smallest Safe Fix
59
+
60
+ Examples:
61
+
62
+ - fix binding name or resource ID in repo
63
+ - redeploy previous artifact
64
+ - narrow cache purge (not whole zone without approval)
65
+ - adjust route pattern
66
+
67
+ ### 5. Verify And Document
68
+
69
+ Run smoke_tests from edge-deployment-spec; update residual_risks for SRE/DevOps.
70
+
71
+ ## Checklist
72
+
73
+ - [ ] environment and route scope captured
74
+ - [ ] deploy revision compared to failing window
75
+ - [ ] bindings and secrets checked (names only in notes)
76
+ - [ ] platform vs application layer decided
77
+ - [ ] smallest safe fix applied
78
+ - [ ] smoke tests pass after recovery
79
+
80
+ ## Output Contracts
81
+
82
+ When this skill is invoked as part of a coordinated multi-role delivery, emit:
83
+
84
+ - **contracts/schemas/deployment-plan.json** — Required fields: infrastructure_changes[], config_updates[], and
85
+ alidation_run. Set produced_by_role to the emitting developer role.
86
+
87
+ Skip emission for solo refactor work where no downstream handoff is expected.
88
+
89
+ ## Failure Modes
90
+
91
+ - **Local-only assumption**: a fix is made locally and shipped without verifying on the deployed edge. Mitigation: always compare `wrangler dev --remote` against the deployed behavior before changing production.
92
+ - **Status code guessing**: a 5xx is "fixed" based on the status alone without reading logs. Mitigation: read Workers Observability logs and request IDs first; never guess.
93
+ - **Whole-zone cache purge**: a single-route cache issue triggers a full-zone purge. Mitigation: narrow the purge to the affected URL pattern; require approval for full-zone purges.
94
+ - **Missing observability block**: `wrangler tail` is used to debug a production issue but logs are not persisted. Mitigation: require `"observability": { "enabled": true }` in `wrangler.jsonc` for all production Workers.
95
+ - **Wrangler v4 default surprise**: a CI runbook assumes `wrangler dev` defaults to `--remote`; in v4 it defaults to local. Mitigation: pass `--remote` explicitly; update runbooks.
96
+ - **Secret leaked in notes**: secret names (or values) are pasted into debug notes or chat. Mitigation: reference secrets by name only; never log values.
97
+ - **Rollback skipped**: an incident is "fixed" without confirming the previous artifact is still available for rollback. Mitigation: verify the previous deployment ID is rollbackable before applying the new fix.
98
+
99
+ ## Security Guardrails (OWASP ASI)
100
+
101
+ - **ASI01 Goal Hijack**: a debug session may drift into changing application code outside the incident's scope. Mitigation: scope every debug change to the failing layer; open a separate task for unrelated fixes.
102
+ - **ASI03 Identity & Privilege Abuse**: a debug command that requires elevated scopes (e.g., secret rotation, DNS update) must be approved; reject ad-hoc privilege escalation.
103
+ - **ASI04 Supply Chain**: Wrangler CLI, observability agents, and edge config must be schema-validated against the expected manifest; treat unknown versions as untrusted.
104
+ - **ASI07 Inter-Agent Communication**: the incident report is consumed by SRE and DevOps; emit a structured contract so each role can validate the remediation.
105
+ - **ASI09 Human-Agent Trust Exploitation**: do not present a fix as "resolved" without a smoke test on the deployed edge; surface the residual risk honestly.
106
+
107
+ ## Related Skills
108
+
109
+ - **wrangler**: Wrangler CLI for deploying, developing, and managing Workers
110
+ - **debug-runtime-platform**: Broader platform issues shared with DevOps/SRE
111
+ - **troubleshoot-service**: Application-level API or Astro handler bugs