@zero2webmaster/starter-kit 0.2.0 → 0.3.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.
- package/README.md +14 -15
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/brief.d.ts +2 -2
- package/dist/brief.js +11 -4
- package/dist/cli.js +290 -17
- package/dist/confirm.d.ts +16 -4
- package/dist/confirm.js +66 -32
- package/dist/index.d.ts +195 -3
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.d.ts +97 -0
- package/dist/license.js +474 -0
- package/dist/parse-brief.d.ts +45 -1
- package/dist/parse-brief.js +349 -21
- package/dist/scaffolders/common.d.ts +42 -1
- package/dist/scaffolders/common.js +753 -30
- package/dist/scaffolders/index.d.ts +1 -0
- package/dist/scaffolders/index.js +3 -0
- package/dist/scaffolders/library.js +26 -2
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +254 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.d.ts +11 -0
- package/dist/scaffolders/pro-seo-extension.js +782 -0
- package/dist/scaffolders/python-service.js +10 -2
- package/dist/scaffolders/wp-plugin.js +8 -8
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +164 -5
- package/dist/substitute.d.ts +22 -3
- package/dist/substitute.js +19 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +31 -13
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +32 -0
- package/dist/with-init.js +171 -0
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +13 -6
- package/dist/writer.js +119 -21
- package/package.json +2 -1
|
@@ -31,11 +31,11 @@ const README_TEMPLATE = `# {{slug}}
|
|
|
31
31
|
|
|
32
32
|
## Overview
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
{{overview}}
|
|
35
35
|
|
|
36
36
|
## Quick start
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
{{quick_start}}
|
|
39
39
|
|
|
40
40
|
## License
|
|
41
41
|
|
|
@@ -45,6 +45,94 @@ Proprietary — © {{year}} {{author}}, Zero2Webmaster. All rights reserved.
|
|
|
45
45
|
|
|
46
46
|
*Scaffolded {{date}} via [[instantiate-z2w-project]] v1 — mirrored by \`@zero2webmaster/starter-kit\`.*
|
|
47
47
|
`;
|
|
48
|
+
/**
|
|
49
|
+
* Per-type Quick-start block for the README. Mirrors the "Quick start for
|
|
50
|
+
* contributors" command sequence each per-type scaffolder puts in CLAUDE.md,
|
|
51
|
+
* so the README (the file a first-time reader opens) isn't a `[fill in]` stub
|
|
52
|
+
* (2026-06-03 dogfood + z2w-member-match 2026-06-11 findings).
|
|
53
|
+
*/
|
|
54
|
+
function quickStartFor(inputs) {
|
|
55
|
+
const slugUnder = inputs.slug.replace(/-/g, "_");
|
|
56
|
+
switch (inputs.projectType) {
|
|
57
|
+
case "wp-plugin":
|
|
58
|
+
return [
|
|
59
|
+
"```bash",
|
|
60
|
+
"# Symlink (or copy) the plugin folder into a Local by Flywheel site:",
|
|
61
|
+
`# wp-content/plugins/${inputs.slug}`,
|
|
62
|
+
"# See [[symlink-safety]] before symlinking — WP Admin Delete follows symlinks.",
|
|
63
|
+
"composer install # only if the plugin uses Composer; otherwise skip",
|
|
64
|
+
"```",
|
|
65
|
+
"",
|
|
66
|
+
"Then activate via **WP Admin → Plugins**.",
|
|
67
|
+
].join("\n");
|
|
68
|
+
case "cf-worker":
|
|
69
|
+
return [
|
|
70
|
+
"```bash",
|
|
71
|
+
"npm install",
|
|
72
|
+
"npm run dev # local wrangler dev server",
|
|
73
|
+
"npm run deploy # wrangler deploy",
|
|
74
|
+
"```",
|
|
75
|
+
].join("\n");
|
|
76
|
+
case "cf-pages":
|
|
77
|
+
return [
|
|
78
|
+
"```bash",
|
|
79
|
+
"npm install",
|
|
80
|
+
"npm run dev # local dev server",
|
|
81
|
+
"npm run build # production build (deploys via Cloudflare Pages)",
|
|
82
|
+
"```",
|
|
83
|
+
].join("\n");
|
|
84
|
+
case "nextjs":
|
|
85
|
+
return [
|
|
86
|
+
"```bash",
|
|
87
|
+
"npm install",
|
|
88
|
+
"# .env.local was scaffolded for you — fill in the values it lists",
|
|
89
|
+
"npm run dev # http://localhost:3000",
|
|
90
|
+
"npm run build && npm start # production build",
|
|
91
|
+
"```",
|
|
92
|
+
].join("\n");
|
|
93
|
+
case "python-service":
|
|
94
|
+
return [
|
|
95
|
+
"```bash",
|
|
96
|
+
"python3 -m venv .venv",
|
|
97
|
+
"source .venv/bin/activate",
|
|
98
|
+
"pip install -e .[dev] # or: pip install -r requirements.txt",
|
|
99
|
+
`uvicorn ${slugUnder}.main:app --reload`,
|
|
100
|
+
"```",
|
|
101
|
+
].join("\n");
|
|
102
|
+
case "node-service":
|
|
103
|
+
return [
|
|
104
|
+
"```bash",
|
|
105
|
+
"npm install",
|
|
106
|
+
"# .env was scaffolded for you — fill in the values it lists",
|
|
107
|
+
"npm run dev # local server (tsx watch) on http://localhost:8080",
|
|
108
|
+
"npm test # vitest",
|
|
109
|
+
"npm run build # compile to dist/",
|
|
110
|
+
"npm start # node dist/index.js (what the container runs)",
|
|
111
|
+
"```",
|
|
112
|
+
].join("\n");
|
|
113
|
+
case "library":
|
|
114
|
+
return [
|
|
115
|
+
"```bash",
|
|
116
|
+
"npm install",
|
|
117
|
+
"npm test",
|
|
118
|
+
"npm run build",
|
|
119
|
+
"```",
|
|
120
|
+
].join("\n");
|
|
121
|
+
case "protocol-repo":
|
|
122
|
+
return "This is a documentation / protocol repository — there is no build step. Read the files in repository order.";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* README Overview paragraph. Prefers the brief's Purpose section (verbatim)
|
|
127
|
+
* when scaffolding from a pasted brief; otherwise falls back to the one-line
|
|
128
|
+
* description plus a fill-in nudge.
|
|
129
|
+
*/
|
|
130
|
+
function readmeOverview(inputs) {
|
|
131
|
+
const purpose = inputs.briefSections?.purpose?.trim();
|
|
132
|
+
if (purpose && purpose.length > 0)
|
|
133
|
+
return purpose;
|
|
134
|
+
return `${inputs.description}\n\n_(Expand this overview after scaffold.)_`;
|
|
135
|
+
}
|
|
48
136
|
const TROUBLESHOOTING_TEMPLATE = `# Troubleshooting
|
|
49
137
|
|
|
50
138
|
Living document for {{slug}}. Add an entry whenever a problem takes >15 minutes to solve.
|
|
@@ -79,6 +167,110 @@ Format: [Semantic Versioning](https://semver.org/).
|
|
|
79
167
|
- Initial scaffold via \`@zero2webmaster/starter-kit\` (mirrors [[instantiate-z2w-project]]).
|
|
80
168
|
- Brand: {{brand_name}}.
|
|
81
169
|
`;
|
|
170
|
+
// Emitted by default for every project type (always-on standard, like the
|
|
171
|
+
// Skill Vault / text-size standards). Per Kerry's 2026-06-18 directive: every
|
|
172
|
+
// coding project with any likelihood of being sold or licensed should carry a
|
|
173
|
+
// marketing plan, kept up to date and tracked as a first-class artifact. The
|
|
174
|
+
// stub has an explicit N/A path for internal-only projects so it never becomes
|
|
175
|
+
// dead boilerplate. The high-level state mirrors to the project inventory's
|
|
176
|
+
// `marketing_plan` field (the at-a-glance status the command center reads).
|
|
177
|
+
const MARKETING_TEMPLATE = `# Marketing Plan — {{slug}}
|
|
178
|
+
|
|
179
|
+
> A first-class, tracked artifact for every Z2W project. Per the standing
|
|
180
|
+
> Zero2Webmaster rule (2026-06-18): every coding project with any likelihood of
|
|
181
|
+
> being sold or licensed should carry a marketing plan, kept up to date here.
|
|
182
|
+
|
|
183
|
+
**Project:** {{slug}}
|
|
184
|
+
**Status:** Stub — fill this in, or mark **N/A (internal-only, not sold/licensed)** and say why.
|
|
185
|
+
**Last Updated:** {{date}}
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Is this project sold or licensed?
|
|
190
|
+
|
|
191
|
+
- [ ] **Yes** — complete the sections below.
|
|
192
|
+
- [ ] **No / internal-only** — mark N/A here and you can delete the rest: ______________
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Positioning
|
|
197
|
+
|
|
198
|
+
- **What it is (one sentence):** {{description}}
|
|
199
|
+
- **Ideal end user:**
|
|
200
|
+
- **Where it fits among competitors:**
|
|
201
|
+
- **Primary value proposition:**
|
|
202
|
+
|
|
203
|
+
## Pricing & packaging
|
|
204
|
+
|
|
205
|
+
- **Model:** (one-time / subscription / freemium / …)
|
|
206
|
+
- **Price points:**
|
|
207
|
+
|
|
208
|
+
## Distribution & discovery
|
|
209
|
+
|
|
210
|
+
- **Where buyers find it:**
|
|
211
|
+
- **Launch channels:**
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Status tracking
|
|
216
|
+
|
|
217
|
+
Mirror the high-level state to the project inventory's \`marketing_plan\` field
|
|
218
|
+
(\`None\` / \`Stub\` / \`Drafted\` / \`Active\`). This file is the detail; the
|
|
219
|
+
inventory is the at-a-glance status the command center reads.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
*Scaffolded {{date}} via [[instantiate-z2w-project]] — mirrored by \`@zero2webmaster/starter-kit\`.*
|
|
224
|
+
`;
|
|
225
|
+
// Emitted by default for every project type (always-on standard). Per Kerry's
|
|
226
|
+
// 2026-06-18 directive: each project should keep a living document stating what
|
|
227
|
+
// parts need backups, which are actually backed up, how, and when each was last
|
|
228
|
+
// verified (code → GitHub, Neon → nightly dumps to R2, Backblaze B2 → R2, …).
|
|
229
|
+
// The high-level state mirrors to the project inventory's `backup_plan` field so
|
|
230
|
+
// the command center can surface each project's backup status / last-completed.
|
|
231
|
+
const BACKUPS_TEMPLATE = `# Backup Plan — {{slug}}
|
|
232
|
+
|
|
233
|
+
> A first-class, tracked artifact for every Z2W project. State here what parts
|
|
234
|
+
> of this project need backups, which are actually backed up, how, and when each
|
|
235
|
+
> was last verified. Keep it up to date.
|
|
236
|
+
|
|
237
|
+
**Project:** {{slug}}
|
|
238
|
+
**Status:** Stub — fill in each surface below (or mark N/A).
|
|
239
|
+
**Last Updated:** {{date}}
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Backup surfaces
|
|
244
|
+
|
|
245
|
+
For each surface: whether it needs a backup, whether one exists, the
|
|
246
|
+
method/destination, the cadence, and when it was last verified.
|
|
247
|
+
|
|
248
|
+
| Surface | Needs backup? | Backed up? | Method / destination | Cadence | Last verified |
|
|
249
|
+
|---|---|---|---|---|---|
|
|
250
|
+
| Source code | Yes | | GitHub (\`{{github_org}}/{{slug}}\`) | on push | |
|
|
251
|
+
| Database (e.g. Neon Postgres) | | | nightly \`pg_dump\` → R2 / Backblaze | | |
|
|
252
|
+
| Object storage (e.g. Backblaze B2) | | | mirror → Cloudflare R2 | | |
|
|
253
|
+
| Secrets / env vars | | | (where are they recoverable from?) | | |
|
|
254
|
+
| Other (config, DNS, …) | | | | | |
|
|
255
|
+
|
|
256
|
+
## Restore test
|
|
257
|
+
|
|
258
|
+
A backup you have never restored from is a hope, not a backup. Note the last
|
|
259
|
+
time a restore was actually exercised:
|
|
260
|
+
|
|
261
|
+
- **Last restore drill:** ______________
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Status tracking
|
|
266
|
+
|
|
267
|
+
Mirror the high-level state to the project inventory's \`backup_plan\` field. The
|
|
268
|
+
command center can then surface each project's backup status / last-completed.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
*Scaffolded {{date}} via [[instantiate-z2w-project]] — mirrored by \`@zero2webmaster/starter-kit\`.*
|
|
273
|
+
`;
|
|
82
274
|
const ROADMAP_TEMPLATE = `# Project Roadmap
|
|
83
275
|
|
|
84
276
|
**Project:** {{slug}}
|
|
@@ -168,7 +360,7 @@ const STATUS_TEMPLATE = `# Project Status
|
|
|
168
360
|
|
|
169
361
|
*This status file provides quick context for resuming work after breaks. Keep it concise and action-oriented.*
|
|
170
362
|
`;
|
|
171
|
-
const
|
|
363
|
+
const HANDOFF_HEAD = `# Session Handoff Document
|
|
172
364
|
|
|
173
365
|
**Project:** {{slug}}
|
|
174
366
|
**Session Date:** {{date}}
|
|
@@ -185,25 +377,12 @@ Initial scaffold complete. No application code yet.
|
|
|
185
377
|
|
|
186
378
|
## 📚 Reading Order for Next Agent
|
|
187
379
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
3. **[ROADMAP.md](ROADMAP.md)** — atomic steps to v{{version}}
|
|
191
|
-
4. **[CLAUDE.md](CLAUDE.md)** — operating rules
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
## 🚀 Starting Prompt for Next Session
|
|
196
|
-
|
|
197
|
-
\`\`\`
|
|
198
|
-
I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, then begin
|
|
199
|
-
ROADMAP Step 1.
|
|
200
|
-
\`\`\`
|
|
201
|
-
|
|
380
|
+
`;
|
|
381
|
+
const HANDOFF_TAIL = `
|
|
202
382
|
---
|
|
203
383
|
|
|
204
384
|
**Handoff Status:** ✅ CLEAN
|
|
205
|
-
**Ready for Next Session:** ✅ YES
|
|
206
|
-
`;
|
|
385
|
+
**Ready for Next Session:** ✅ YES`;
|
|
207
386
|
const CURSORIGNORE_TEMPLATE = `# Files Cursor should ignore (per project type).
|
|
208
387
|
.DS_Store
|
|
209
388
|
.tmp/
|
|
@@ -308,13 +487,91 @@ ${AGENTS_BODY_MARKER}
|
|
|
308
487
|
};
|
|
309
488
|
}
|
|
310
489
|
export function commonReadme(inputs, opts, spec) {
|
|
311
|
-
|
|
490
|
+
// sub() fills the standard tokens; {{overview}} + {{quick_start}} are unknown
|
|
491
|
+
// to the substitution map, so they survive to be filled here (the values are
|
|
492
|
+
// free text that may contain `$`, so use replacer functions).
|
|
493
|
+
const content = sub(README_TEMPLATE, inputs, opts, spec)
|
|
494
|
+
.replace("{{overview}}", () => readmeOverview(inputs))
|
|
495
|
+
.replace("{{quick_start}}", () => quickStartFor(inputs));
|
|
496
|
+
return { path: "README.md", content };
|
|
312
497
|
}
|
|
498
|
+
const ROADMAP_HEADER_TEMPLATE = `# Project Roadmap
|
|
499
|
+
|
|
500
|
+
**Project:** {{slug}}
|
|
501
|
+
**Goal:** {{description}}
|
|
502
|
+
**Created:** {{date}}
|
|
503
|
+
**Last Updated:** {{date}}
|
|
504
|
+
|
|
505
|
+
---
|
|
506
|
+
|
|
507
|
+
## Overview
|
|
508
|
+
|
|
509
|
+
This roadmap breaks the v{{version}} ship into atomic, testable steps. Each step should be completable in a single focused chat session.
|
|
510
|
+
|
|
511
|
+
The sections below were lifted from the project brief used to scaffold {{slug}}. Refine the brief's planning notes into concrete, verifiable steps as the project takes shape.
|
|
512
|
+
`;
|
|
513
|
+
const ROADMAP_PLACEHOLDER_STEPS = `## Step 1: First milestone (placeholder)
|
|
514
|
+
|
|
515
|
+
**Goal:** Replace this with your first concrete deliverable.
|
|
516
|
+
|
|
517
|
+
**Tasks:**
|
|
518
|
+
- [ ] [Task 1]
|
|
519
|
+
|
|
520
|
+
**Verification:**
|
|
521
|
+
- [ ] [How will you know it's done?]
|
|
522
|
+
|
|
523
|
+
**Status:** 📋 Pending
|
|
524
|
+
`;
|
|
525
|
+
const ROADMAP_FOOTER = `## Status Indicators
|
|
526
|
+
|
|
527
|
+
- 📋 **Pending** - Not started yet
|
|
528
|
+
- ⏳ **In Progress** - Currently working on
|
|
529
|
+
- ✅ **Complete** - Verified and working
|
|
530
|
+
- 🚫 **Blocked** - Cannot proceed (see STATUS.md for details)
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
*This roadmap is a living document. Update it as the project evolves.*
|
|
535
|
+
`;
|
|
536
|
+
/** Brief context sections rendered under "## Project context (from brief)". */
|
|
537
|
+
const ROADMAP_CONTEXT_FIELDS = [
|
|
538
|
+
["purpose", "Purpose"],
|
|
539
|
+
["keyApis", "Key APIs"],
|
|
540
|
+
["dataSources", "Data sources"],
|
|
541
|
+
["expectedOutputs", "Expected outputs"],
|
|
542
|
+
["edgeCases", "Edge cases"],
|
|
543
|
+
];
|
|
313
544
|
export function commonRoadmap(inputs, opts, spec) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
545
|
+
const sections = inputs.briefSections;
|
|
546
|
+
// No brief (wizard / --input path): emit the placeholder template verbatim.
|
|
547
|
+
if (sections === undefined) {
|
|
548
|
+
return {
|
|
549
|
+
path: "ROADMAP.md",
|
|
550
|
+
content: sub(ROADMAP_TEMPLATE, inputs, opts, spec),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
// Brief path: flow the brief's planning sections into ROADMAP.md per
|
|
554
|
+
// [[instantiate-z2w-project]] SKILL Step 1a.4.
|
|
555
|
+
const parts = [sub(ROADMAP_HEADER_TEMPLATE, inputs, opts, spec)];
|
|
556
|
+
const contextChunks = [];
|
|
557
|
+
for (const [field, label] of ROADMAP_CONTEXT_FIELDS) {
|
|
558
|
+
const body = sections[field]?.trim();
|
|
559
|
+
if (body)
|
|
560
|
+
contextChunks.push(`### ${label}\n\n${body}`);
|
|
561
|
+
}
|
|
562
|
+
if (contextChunks.length > 0) {
|
|
563
|
+
parts.push(`---\n\n## Project context (from brief)\n\n${contextChunks.join("\n\n")}\n`);
|
|
564
|
+
}
|
|
565
|
+
const roadmapBody = sections.roadmap?.trim();
|
|
566
|
+
parts.push(roadmapBody
|
|
567
|
+
? `---\n\n## Roadmap (from brief)\n\n${roadmapBody}\n`
|
|
568
|
+
: `---\n\n${ROADMAP_PLACEHOLDER_STEPS}`);
|
|
569
|
+
const future = sections.futureImprovements?.trim();
|
|
570
|
+
if (future) {
|
|
571
|
+
parts.push(`---\n\n## Future improvements (from brief)\n\n${future}\n`);
|
|
572
|
+
}
|
|
573
|
+
parts.push(`---\n\n${ROADMAP_FOOTER}`);
|
|
574
|
+
return { path: "ROADMAP.md", content: parts.join("\n") };
|
|
318
575
|
}
|
|
319
576
|
export function commonStatus(inputs, opts, spec) {
|
|
320
577
|
return {
|
|
@@ -323,9 +580,81 @@ export function commonStatus(inputs, opts, spec) {
|
|
|
323
580
|
};
|
|
324
581
|
}
|
|
325
582
|
export function commonHandoff(inputs, opts, spec) {
|
|
583
|
+
// Did we capture (and persist) a brief? If so it is written verbatim to
|
|
584
|
+
// directives/PROJECT_BRIEF.md and belongs in the reading order. Is the
|
|
585
|
+
// roadmap concrete, or just placeholder prose? Both drive the starting
|
|
586
|
+
// prompt so the next agent is NEVER pointed at a "begin ROADMAP Step 1"
|
|
587
|
+
// that doesn't exist yet (the second half of the 2026-06-28 silent-miss).
|
|
588
|
+
const hasBrief = (inputs.instantiationPrompt ?? "").trim().length > 0;
|
|
589
|
+
const roadmapConcrete = (inputs.briefSections?.roadmap ?? "").trim().length > 0;
|
|
590
|
+
const readingOrder = [
|
|
591
|
+
"1. **This file (HANDOFF.md)** — current state",
|
|
592
|
+
"2. **[STATUS.md](STATUS.md)** — decisions, next actions, recent updates",
|
|
593
|
+
"3. **[ROADMAP.md](ROADMAP.md)** — atomic steps to v{{version}}",
|
|
594
|
+
];
|
|
595
|
+
if (hasBrief) {
|
|
596
|
+
readingOrder.push("4. **[directives/PROJECT_BRIEF.md](directives/PROJECT_BRIEF.md)** — the full instantiation brief (frozen charter)", "5. **[CLAUDE.md](CLAUDE.md)** — operating rules");
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
readingOrder.push("4. **[CLAUDE.md](CLAUDE.md)** — operating rules");
|
|
600
|
+
}
|
|
601
|
+
let startingPrompt;
|
|
602
|
+
if (hasBrief && roadmapConcrete) {
|
|
603
|
+
startingPrompt =
|
|
604
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, and\n" +
|
|
605
|
+
"directives/PROJECT_BRIEF.md (the full brief). ROADMAP.md was seeded from the\n" +
|
|
606
|
+
"brief's plan — turn it into concrete, verifiable steps, then begin Step 1.";
|
|
607
|
+
}
|
|
608
|
+
else if (hasBrief) {
|
|
609
|
+
startingPrompt =
|
|
610
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md, and\n" +
|
|
611
|
+
"directives/PROJECT_BRIEF.md (the full brief). ROADMAP.md has no concrete steps\n" +
|
|
612
|
+
"yet — derive the first milestone from the brief, then begin Step 1.";
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
startingPrompt =
|
|
616
|
+
"I'm picking up {{slug}}. Read HANDOFF.md, STATUS.md, ROADMAP.md. ROADMAP.md is\n" +
|
|
617
|
+
"a placeholder — define the first concrete milestone, then begin Step 1.";
|
|
618
|
+
}
|
|
619
|
+
const body = HANDOFF_HEAD +
|
|
620
|
+
readingOrder.join("\n") +
|
|
621
|
+
"\n\n---\n\n## 🚀 Starting Prompt for Next Session\n\n```\n" +
|
|
622
|
+
startingPrompt +
|
|
623
|
+
"\n```\n" +
|
|
624
|
+
HANDOFF_TAIL +
|
|
625
|
+
"\n";
|
|
326
626
|
return {
|
|
327
627
|
path: "HANDOFF.md",
|
|
328
|
-
content: sub(
|
|
628
|
+
content: sub(body, inputs, opts, spec),
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
const PROJECT_BRIEF_HEADER = `# Project Brief — {{slug}} (frozen instantiation charter)
|
|
632
|
+
|
|
633
|
+
> This is the verbatim brief {{slug}} was scaffolded from on {{date}}, captured here
|
|
634
|
+
> so the repo is self-contained — the next agent can read the full spec without
|
|
635
|
+
> leaving the repository. It is a **frozen historical charter**: do NOT edit it to
|
|
636
|
+
> track ongoing work. The living plan is [ROADMAP.md](../ROADMAP.md); current state
|
|
637
|
+
> is [STATUS.md](../STATUS.md).
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
`;
|
|
642
|
+
/**
|
|
643
|
+
* Persist the verbatim instantiation brief into the repo at
|
|
644
|
+
* directives/PROJECT_BRIEF.md. Returns null for the wizard / `--input` paths
|
|
645
|
+
* that carry no brief text (nothing to persist). The body is the raw brief and
|
|
646
|
+
* is intentionally NOT run through the placeholder substituter, so a brief that
|
|
647
|
+
* happens to contain `{{token}}`-looking text is preserved exactly (only
|
|
648
|
+
* CLAUDE.md is validated for leftover markers — see writer.ts).
|
|
649
|
+
*/
|
|
650
|
+
export function commonProjectBrief(inputs, opts, spec) {
|
|
651
|
+
const brief = (inputs.instantiationPrompt ?? "").trim();
|
|
652
|
+
if (brief.length === 0)
|
|
653
|
+
return null;
|
|
654
|
+
const header = sub(PROJECT_BRIEF_HEADER, inputs, opts, spec);
|
|
655
|
+
return {
|
|
656
|
+
path: "directives/PROJECT_BRIEF.md",
|
|
657
|
+
content: `${header}${brief}\n`,
|
|
329
658
|
};
|
|
330
659
|
}
|
|
331
660
|
export function commonTroubleshooting(inputs, opts, spec) {
|
|
@@ -340,6 +669,18 @@ export function commonChangelog(inputs, opts, spec) {
|
|
|
340
669
|
content: sub(CHANGELOG_TEMPLATE, inputs, opts, spec),
|
|
341
670
|
};
|
|
342
671
|
}
|
|
672
|
+
export function commonMarketing(inputs, opts, spec) {
|
|
673
|
+
return {
|
|
674
|
+
path: "marketing.md",
|
|
675
|
+
content: sub(MARKETING_TEMPLATE, inputs, opts, spec),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
export function commonBackups(inputs, opts, spec) {
|
|
679
|
+
return {
|
|
680
|
+
path: "BACKUPS.md",
|
|
681
|
+
content: sub(BACKUPS_TEMPLATE, inputs, opts, spec),
|
|
682
|
+
};
|
|
683
|
+
}
|
|
343
684
|
export function commonVersion() {
|
|
344
685
|
return { path: "VERSION", content: "0.1.0\n" };
|
|
345
686
|
}
|
|
@@ -352,14 +693,46 @@ export function commonDirective(inputs, opts, spec) {
|
|
|
352
693
|
content: sub(DIRECTIVE_TEMPLATE, inputs, opts, spec),
|
|
353
694
|
};
|
|
354
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* Trailing block appended to every `.gitignore` regardless of project type.
|
|
698
|
+
*
|
|
699
|
+
* Two entries that MUST be present from line one of any Z2W repo:
|
|
700
|
+
* - `.tmp/` — the Z2W scratch/intermediates convention; can hold tokens
|
|
701
|
+
* (dev-server logs with magic-link URLs, etc.).
|
|
702
|
+
* - `.specstory/` — SpecStory chat transcripts. These archive *pasted* values
|
|
703
|
+
* from past sessions; in the field they have contained live
|
|
704
|
+
* DATABASE_URLs (with password) and API keys. A fresh repo's
|
|
705
|
+
* first `git add -A` silently stages them otherwise.
|
|
706
|
+
* - `.cursorindexingignore` — Cursor auto-creates this to manage its own
|
|
707
|
+
* index. Without ignoring it, a freshly-scaffolded repo opens
|
|
708
|
+
* to a dirty tree with one mystery untracked file, and the
|
|
709
|
+
* first-session agent has to stop and ask what to do with it
|
|
710
|
+
* (contact-registry, 2026-07-12). Ignoring it gives every
|
|
711
|
+
* generated tree a clean `git status` — every file either
|
|
712
|
+
* tracked or ignored, nothing present-but-untracked.
|
|
713
|
+
*
|
|
714
|
+
* Per the 2026-06-11 z2w-member-match near-miss (live DATABASE_URL +
|
|
715
|
+
* RESEND_API_KEY staged on a fresh repo) and matching asks from
|
|
716
|
+
* videomigrator-dashboard (2026-06-07). Centralized here so no per-type body
|
|
717
|
+
* can ever omit it.
|
|
718
|
+
*/
|
|
719
|
+
const GITIGNORE_SECRET_SCRATCH_BLOCK = `
|
|
720
|
+
# Scratch / intermediates (Z2W convention) — never commit
|
|
721
|
+
.tmp/
|
|
722
|
+
# SpecStory chat transcripts — local only; can contain pasted secrets
|
|
723
|
+
.specstory/
|
|
724
|
+
# Cursor's own index-management file — local, auto-created; keeps git status clean
|
|
725
|
+
.cursorindexingignore
|
|
726
|
+
`;
|
|
355
727
|
/**
|
|
356
728
|
* Per-type `.gitignore` body. Sources: skill's "Inline mini-templates"
|
|
357
|
-
* section. Each variant is the verbatim block from there
|
|
729
|
+
* section. Each variant is the verbatim block from there, plus the shared
|
|
730
|
+
* `GITIGNORE_SECRET_SCRATCH_BLOCK` appended to every type (so `.tmp/` and
|
|
731
|
+
* `.specstory/` are guaranteed present — see that constant's doc comment).
|
|
358
732
|
*/
|
|
359
733
|
export function gitignoreFor(projectType) {
|
|
360
734
|
const base = {
|
|
361
735
|
"wp-plugin": `.DS_Store
|
|
362
|
-
.tmp/
|
|
363
736
|
*.zip
|
|
364
737
|
node_modules/
|
|
365
738
|
vendor/
|
|
@@ -399,6 +772,13 @@ venv/
|
|
|
399
772
|
dist/
|
|
400
773
|
build/
|
|
401
774
|
*.egg-info/
|
|
775
|
+
`,
|
|
776
|
+
"node-service": `.DS_Store
|
|
777
|
+
node_modules/
|
|
778
|
+
dist/
|
|
779
|
+
.env
|
|
780
|
+
.env.local
|
|
781
|
+
*.log
|
|
402
782
|
`,
|
|
403
783
|
library: `.DS_Store
|
|
404
784
|
node_modules/
|
|
@@ -406,12 +786,43 @@ dist/
|
|
|
406
786
|
.env
|
|
407
787
|
`,
|
|
408
788
|
"protocol-repo": `.DS_Store
|
|
409
|
-
.tmp/
|
|
410
789
|
.env
|
|
411
790
|
node_modules/
|
|
412
791
|
`,
|
|
413
792
|
}[projectType];
|
|
414
|
-
return { path: ".gitignore", content: base };
|
|
793
|
+
return { path: ".gitignore", content: base + GITIGNORE_SECRET_SCRATCH_BLOCK };
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Derive a gitignored local env file (`.env.local` for nextjs, `.env` for
|
|
797
|
+
* python-service) from an already-substituted `.env.example` body. Keeps every
|
|
798
|
+
* key and its inline doc comments, clears assigned values so the user fills
|
|
799
|
+
* real ones, and swaps the example banner for a local-file banner. Emitted
|
|
800
|
+
* alongside `.env.example` so a fresh clone has the local file ready to fill
|
|
801
|
+
* rather than requiring a manual `cp .env.example .env.local` — closes the
|
|
802
|
+
* z2w-agent-command-center 2026-06-01 Open question.
|
|
803
|
+
*/
|
|
804
|
+
export function localEnvFrom(exampleContent, filename, slug) {
|
|
805
|
+
const lines = exampleContent.split("\n");
|
|
806
|
+
// Drop the leading banner block (consecutive comment lines + blank lines at
|
|
807
|
+
// the top) — the per-key doc comments further down are kept verbatim.
|
|
808
|
+
let start = 0;
|
|
809
|
+
while (start < lines.length && lines[start].startsWith("#"))
|
|
810
|
+
start++;
|
|
811
|
+
while (start < lines.length && lines[start].trim() === "")
|
|
812
|
+
start++;
|
|
813
|
+
const body = lines
|
|
814
|
+
.slice(start)
|
|
815
|
+
.map((line) => {
|
|
816
|
+
const m = /^(\s*)([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line);
|
|
817
|
+
return m ? `${m[1]}${m[2]}=` : line;
|
|
818
|
+
})
|
|
819
|
+
.join("\n");
|
|
820
|
+
// Project name FIRST on line 1 (Kerry's standing rule 2026-07-01): two env
|
|
821
|
+
// files open side-by-side are easy to confuse, so the slug must lead — the
|
|
822
|
+
// filename alone ("# .env — …") doesn't say WHICH project's .env it is.
|
|
823
|
+
const banner = `# ${slug} — ${filename} (local environment values; gitignored, never committed).\n` +
|
|
824
|
+
`# Generated from .env.example at scaffold time; fill in real values below.\n\n`;
|
|
825
|
+
return banner + body;
|
|
415
826
|
}
|
|
416
827
|
/**
|
|
417
828
|
* Common base files every scaffolded project gets — CLAUDE.md, README.md,
|
|
@@ -424,7 +835,7 @@ node_modules/
|
|
|
424
835
|
*/
|
|
425
836
|
export function commonBaseFiles(inputs, opts, perTypeNarrative) {
|
|
426
837
|
const spec = resolveBrandSpec(inputs);
|
|
427
|
-
|
|
838
|
+
const files = [
|
|
428
839
|
buildClaudeMd(inputs, opts, spec, perTypeNarrative),
|
|
429
840
|
commonReadme(inputs, opts, spec),
|
|
430
841
|
commonRoadmap(inputs, opts, spec),
|
|
@@ -432,9 +843,321 @@ export function commonBaseFiles(inputs, opts, perTypeNarrative) {
|
|
|
432
843
|
commonHandoff(inputs, opts, spec),
|
|
433
844
|
commonTroubleshooting(inputs, opts, spec),
|
|
434
845
|
commonChangelog(inputs, opts, spec),
|
|
846
|
+
commonMarketing(inputs, opts, spec),
|
|
847
|
+
commonBackups(inputs, opts, spec),
|
|
435
848
|
commonVersion(),
|
|
436
849
|
commonCursorignore(),
|
|
437
850
|
gitignoreFor(inputs.projectType),
|
|
438
851
|
commonDirective(inputs, opts, spec),
|
|
439
852
|
];
|
|
853
|
+
// Persist the verbatim brief into the repo (when one was captured) so the
|
|
854
|
+
// project is self-contained — see commonProjectBrief.
|
|
855
|
+
const briefFile = commonProjectBrief(inputs, opts, spec);
|
|
856
|
+
if (briefFile)
|
|
857
|
+
files.push(briefFile);
|
|
858
|
+
return files;
|
|
859
|
+
}
|
|
860
|
+
/* ─────────────────────────── Email wiring (opt-in) ─────────────────────────
|
|
861
|
+
*
|
|
862
|
+
* Emitted by the `nextjs` and `node-service` scaffolders when
|
|
863
|
+
* `inputs.sendsEmail === true` (per the 2026-06-28 email-default decision —
|
|
864
|
+
* event-engine, on Kerry's steer). A provider-router mailer with a stable
|
|
865
|
+
* `sendEmail()` signature: default provider Amazon SES, Resend as a one-env-var
|
|
866
|
+
* swappable alternative (`EMAIL_PROVIDER=resend`). SES is the default because
|
|
867
|
+
* the Z2W stacks already run authenticated SES in production (zero new vendor).
|
|
868
|
+
* See [[email-service-router]].
|
|
869
|
+
*
|
|
870
|
+
* The mailer body has NO {{tokens}} and NO relative imports, so it is
|
|
871
|
+
* byte-identical across the two types — only the file PATH differs (nextjs uses
|
|
872
|
+
* `lib/…` under the `@/*` alias; node-service uses `src/lib/…`). */
|
|
873
|
+
/** npm deps the mailer requires; merged into the scaffolded package.json. */
|
|
874
|
+
export const EMAIL_DEPS = {
|
|
875
|
+
"@aws-sdk/client-ses": "^3.1075.0",
|
|
876
|
+
resend: "^6.16.0",
|
|
877
|
+
};
|
|
878
|
+
const EMAIL_MAILER_BODY = `// Transactional / auth email — provider router. Default provider: Amazon SES;
|
|
879
|
+
// Resend is a swappable alternative selected with EMAIL_PROVIDER=resend.
|
|
880
|
+
//
|
|
881
|
+
// SERVER-SIDE ONLY. Never import this from client/browser code — it reads secret
|
|
882
|
+
// credentials from process.env and pulls in the AWS/Resend SDKs.
|
|
883
|
+
//
|
|
884
|
+
// Why SES is the default ([[email-service-router]], 2026-06-28): when a stack
|
|
885
|
+
// already runs authenticated SES in production (SAVE THE FROGS! / Bansuri Bliss /
|
|
886
|
+
// Zero2Webmaster all do), SES is zero new vendor, no domain warmup, and cheap at
|
|
887
|
+
// burst volume — past Resend Free's 100/day · 3k/mo cap, which is shared across
|
|
888
|
+
// the whole Z2W portfolio. Resend stays wired for a non-developer tenant who
|
|
889
|
+
// wants the easier DX: set EMAIL_PROVIDER=resend + RESEND_API_KEY + RESEND_FROM,
|
|
890
|
+
// no code change. Do NOT add a fifth mail vendor (SendGrid/Mailgun/Postmark/…) —
|
|
891
|
+
// [[email-service-router]] sanctions exactly these.
|
|
892
|
+
//
|
|
893
|
+
// The sendEmail() signature is provider-agnostic, so call sites (magic links,
|
|
894
|
+
// confirmations, notifications) never change when a deployment flips providers.
|
|
895
|
+
//
|
|
896
|
+
// Hard rules from the skills, enforced for BOTH providers:
|
|
897
|
+
// 1. Construct the client LAZILY — never validate creds at module import, or a
|
|
898
|
+
// build that collects env at build time (e.g. \`next build\`) dies with creds
|
|
899
|
+
// absent. (per [[portable-stack]] §15)
|
|
900
|
+
// 2. On Vercel/Lambda, SES creds use a custom SES_ prefix and are passed
|
|
901
|
+
// EXPLICITLY — Vercel injects its own AWS_* that would shadow the default
|
|
902
|
+
// credential chain. (skill caveat — see directives/email-setup.md)
|
|
903
|
+
// 3. Neither SDK is trusted to throw on a rejected send — we surface failures.
|
|
904
|
+
// 4. Unconfigured (no creds) -> logged NO-OP { sent:false }, never throws, so a
|
|
905
|
+
// sign-in / registration can't fail just because mail isn't wired yet.
|
|
906
|
+
|
|
907
|
+
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
|
|
908
|
+
import { Resend } from "resend";
|
|
909
|
+
|
|
910
|
+
export interface SendEmailParams {
|
|
911
|
+
to: string;
|
|
912
|
+
subject: string;
|
|
913
|
+
text: string;
|
|
914
|
+
html?: string;
|
|
915
|
+
/** Per-deployment override; defaults to the provider's configured FROM. Never noreply@. */
|
|
916
|
+
from?: string;
|
|
917
|
+
replyTo?: string;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
export interface SendEmailResult {
|
|
921
|
+
sent: boolean;
|
|
922
|
+
/** Why a send was skipped (no creds / no from) — for logs, not user display. */
|
|
923
|
+
skippedReason?: string;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
export type EmailProvider = "ses" | "resend";
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Resolve the active provider from env. Pure + exported for testing. Defaults to
|
|
930
|
+
* SES; any value other than "resend" (including unset) -> SES.
|
|
931
|
+
*/
|
|
932
|
+
export function selectProvider(
|
|
933
|
+
value: string | undefined = process.env.EMAIL_PROVIDER,
|
|
934
|
+
): EmailProvider {
|
|
935
|
+
return value?.trim().toLowerCase() === "resend" ? "resend" : "ses";
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/* ───────────────────────────── SES ───────────────────────────── */
|
|
939
|
+
|
|
940
|
+
let _ses: SESClient | undefined;
|
|
941
|
+
|
|
942
|
+
function sesClient(): SESClient | null {
|
|
943
|
+
const region = process.env.SES_REGION;
|
|
944
|
+
const accessKeyId = process.env.SES_ACCESS_KEY_ID;
|
|
945
|
+
const secretAccessKey = process.env.SES_SECRET_ACCESS_KEY;
|
|
946
|
+
if (!region || !accessKeyId || !secretAccessKey) return null;
|
|
947
|
+
if (!_ses) {
|
|
948
|
+
// Pass creds EXPLICITLY — do NOT rely on the default chain. Vercel functions
|
|
949
|
+
// run on Lambda, which injects its own AWS_* env that would shadow ours.
|
|
950
|
+
_ses = new SESClient({
|
|
951
|
+
region,
|
|
952
|
+
credentials: { accessKeyId, secretAccessKey },
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
return _ses;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
async function sendViaSes(params: SendEmailParams): Promise<SendEmailResult> {
|
|
959
|
+
const ses = sesClient();
|
|
960
|
+
if (!ses) {
|
|
961
|
+
return {
|
|
962
|
+
sent: false,
|
|
963
|
+
skippedReason:
|
|
964
|
+
"SES creds not set (SES_REGION/SES_ACCESS_KEY_ID/SES_SECRET_ACCESS_KEY)",
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
const from = params.from ?? process.env.AWS_SES_FROM;
|
|
968
|
+
if (!from) {
|
|
969
|
+
return { sent: false, skippedReason: "no from address (AWS_SES_FROM unset)" };
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
await ses.send(
|
|
973
|
+
new SendEmailCommand({
|
|
974
|
+
Source: from,
|
|
975
|
+
Destination: { ToAddresses: [params.to] },
|
|
976
|
+
ReplyToAddresses: params.replyTo ? [params.replyTo] : undefined,
|
|
977
|
+
Message: {
|
|
978
|
+
Subject: { Data: params.subject, Charset: "UTF-8" },
|
|
979
|
+
Body: {
|
|
980
|
+
// Always send a text part — HTML-only is penalized by spam filters.
|
|
981
|
+
Text: { Data: params.text, Charset: "UTF-8" },
|
|
982
|
+
...(params.html
|
|
983
|
+
? { Html: { Data: params.html, Charset: "UTF-8" } }
|
|
984
|
+
: {}),
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
}),
|
|
988
|
+
);
|
|
989
|
+
// SendEmailCommand rejects (throws) on a hard failure; a resolved promise means
|
|
990
|
+
// SES accepted the message for delivery.
|
|
991
|
+
return { sent: true };
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/* ───────────────────────────── Resend ───────────────────────────── */
|
|
995
|
+
|
|
996
|
+
let _resend: Resend | undefined;
|
|
997
|
+
|
|
998
|
+
function resendClient(): Resend | null {
|
|
999
|
+
const key = process.env.RESEND_API_KEY;
|
|
1000
|
+
if (!key) return null;
|
|
1001
|
+
if (!_resend) _resend = new Resend(key);
|
|
1002
|
+
return _resend;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
async function sendViaResend(params: SendEmailParams): Promise<SendEmailResult> {
|
|
1006
|
+
const resend = resendClient();
|
|
1007
|
+
if (!resend) {
|
|
1008
|
+
return { sent: false, skippedReason: "RESEND_API_KEY not set" };
|
|
1009
|
+
}
|
|
1010
|
+
const from = params.from ?? process.env.RESEND_FROM;
|
|
1011
|
+
if (!from) {
|
|
1012
|
+
return { sent: false, skippedReason: "no from address (RESEND_FROM unset)" };
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
const { error } = await resend.emails.send({
|
|
1016
|
+
from,
|
|
1017
|
+
to: params.to,
|
|
1018
|
+
subject: params.subject,
|
|
1019
|
+
text: params.text, // always send a text part — HTML-only is penalized
|
|
1020
|
+
html: params.html,
|
|
1021
|
+
replyTo: params.replyTo,
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// The Resend SDK resolves successfully even on a rejected send — the reason is
|
|
1025
|
+
// in \`error\`. Surfacing it is our responsibility.
|
|
1026
|
+
if (error) {
|
|
1027
|
+
throw new Error(\`Resend rejected the send: \${error.name}: \${error.message}\`);
|
|
1028
|
+
}
|
|
1029
|
+
return { sent: true };
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/* ───────────────────────────── public API ───────────────────────────── */
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Send one transactional email via the active provider. Returns
|
|
1036
|
+
* { sent: false, skippedReason } instead of throwing when mail is unconfigured,
|
|
1037
|
+
* so callers can proceed; throws only when a configured send is actually rejected.
|
|
1038
|
+
*/
|
|
1039
|
+
export async function sendEmail(
|
|
1040
|
+
params: SendEmailParams,
|
|
1041
|
+
): Promise<SendEmailResult> {
|
|
1042
|
+
return selectProvider() === "resend"
|
|
1043
|
+
? sendViaResend(params)
|
|
1044
|
+
: sendViaSes(params);
|
|
1045
|
+
}
|
|
1046
|
+
`;
|
|
1047
|
+
// Unit test for the mailer — only emitted for node-service (which scaffolds a
|
|
1048
|
+
// vitest runner). The relative import carries a .js extension for NodeNext.
|
|
1049
|
+
const EMAIL_MAILER_TEST_BODY = `import { describe, expect, it } from "vitest";
|
|
1050
|
+
|
|
1051
|
+
import { selectProvider } from "./mailer.js";
|
|
1052
|
+
|
|
1053
|
+
describe("selectProvider", () => {
|
|
1054
|
+
it("defaults to SES when unset", () => {
|
|
1055
|
+
expect(selectProvider(undefined)).toBe("ses");
|
|
1056
|
+
expect(selectProvider("")).toBe("ses");
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
it("selects resend only on an explicit 'resend' (case-insensitive)", () => {
|
|
1060
|
+
expect(selectProvider("resend")).toBe("resend");
|
|
1061
|
+
expect(selectProvider("Resend")).toBe("resend");
|
|
1062
|
+
expect(selectProvider(" RESEND ")).toBe("resend");
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
it("any other value (including unsanctioned vendors) falls back to SES", () => {
|
|
1066
|
+
expect(selectProvider("ses")).toBe("ses");
|
|
1067
|
+
expect(selectProvider("sendgrid")).toBe("ses");
|
|
1068
|
+
expect(selectProvider("mailgun")).toBe("ses");
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
`;
|
|
1072
|
+
/**
|
|
1073
|
+
* The env-var block appended to a scaffolded `.env.example` when the project
|
|
1074
|
+
* sends email. Both providers' vars are stubbed so switching is a one-line env
|
|
1075
|
+
* change with no code edit.
|
|
1076
|
+
*/
|
|
1077
|
+
export const EMAIL_ENV_BLOCK = `
|
|
1078
|
+
# ── Transactional / auth email (lib/email/mailer.ts) ────────────────────────
|
|
1079
|
+
# Provider router. Default: Amazon SES. Set to "resend" to use Resend instead —
|
|
1080
|
+
# no code change. See directives/email-setup.md + [[email-service-router]].
|
|
1081
|
+
EMAIL_PROVIDER=ses
|
|
1082
|
+
|
|
1083
|
+
# Amazon SES (default). Custom SES_ prefix + explicit creds is deliberate: on
|
|
1084
|
+
# Vercel/Lambda the platform injects its own AWS_* that would shadow the default
|
|
1085
|
+
# credential chain. SES_REGION MUST equal the region the sender domain is
|
|
1086
|
+
# verified in, or sends fail with "Email address is not verified".
|
|
1087
|
+
SES_REGION=
|
|
1088
|
+
SES_ACCESS_KEY_ID=
|
|
1089
|
+
SES_SECRET_ACCESS_KEY=
|
|
1090
|
+
# From address. A domain-verified identity can send from any local-part.
|
|
1091
|
+
# Format: "Brand Name <sender@yourdomain.com>". Never noreply@.
|
|
1092
|
+
AWS_SES_FROM=
|
|
1093
|
+
|
|
1094
|
+
# Resend (swappable alternative — only read when EMAIL_PROVIDER=resend).
|
|
1095
|
+
# RESEND_FROM must be on a Resend-verified domain.
|
|
1096
|
+
RESEND_API_KEY=
|
|
1097
|
+
RESEND_FROM=
|
|
1098
|
+
`;
|
|
1099
|
+
const EMAIL_SETUP_DIRECTIVE = `# Directive — Wire transactional / auth email for {{slug}}
|
|
1100
|
+
|
|
1101
|
+
**Decision (2026-06-28):** {{slug}} sends via **Amazon SES by default**, with
|
|
1102
|
+
Resend as a swappable alternative (\`EMAIL_PROVIDER=resend\`). SES is the default
|
|
1103
|
+
because the Z2W stacks already run authenticated SES in production — zero new
|
|
1104
|
+
vendor, no domain warmup, cheap at burst volume (past Resend Free's shared
|
|
1105
|
+
100/day · 3k/mo cap). Resend stays wired for a non-developer client who prefers
|
|
1106
|
+
the easier DX. See [[email-service-router]]; DO NOT add a fifth mail vendor.
|
|
1107
|
+
|
|
1108
|
+
Until the four \`SES_*\` vars are set, all sends are a **logged no-op**
|
|
1109
|
+
(\`{ sent: false }\`) — the app, dashboards, and login flow all work; only actual
|
|
1110
|
+
email delivery is deferred. This directive is the one-time setup to turn live
|
|
1111
|
+
email on. The \`sendEmail()\` call sites never change when you flip providers.
|
|
1112
|
+
|
|
1113
|
+
## What the operator does (AWS console + host env), one stage at a time
|
|
1114
|
+
|
|
1115
|
+
> Secrets go in the operator's OWN terminal / the AWS + host consoles — never
|
|
1116
|
+
> pasted into a chat/agent transcript ([[terminal-secret-hygiene]]).
|
|
1117
|
+
|
|
1118
|
+
1. **Verify the sender domain in the right region.** SES → *Verified identities*
|
|
1119
|
+
→ confirm your domain shows **Verified** with DKIM enabled. The identity is
|
|
1120
|
+
**region-scoped** — \`SES_REGION\` MUST equal that region.
|
|
1121
|
+
2. **Confirm production access (not sandbox).** SES → *Account dashboard*. In
|
|
1122
|
+
sandbox you can only send to verified recipients; request production access
|
|
1123
|
+
once if needed.
|
|
1124
|
+
3. **Create a send-only IAM key** allowing \`ses:SendEmail\` + \`ses:SendRawEmail\`
|
|
1125
|
+
only. These are IAM access keys (\`AKIA…\` + secret) for the SDK — NOT SMTP
|
|
1126
|
+
credentials.
|
|
1127
|
+
4. **Set the env vars** (see \`.env.example\`): \`EMAIL_PROVIDER=ses\`,
|
|
1128
|
+
\`SES_REGION\`, \`SES_ACCESS_KEY_ID\`, \`SES_SECRET_ACCESS_KEY\`, \`AWS_SES_FROM\`.
|
|
1129
|
+
On Vercel set them for Production + Preview.
|
|
1130
|
+
5. **Deploy, then smoke-test** with a real send to an allowlisted address; watch
|
|
1131
|
+
the logs for a \`skippedReason\` (creds still missing) vs. a clean send.
|
|
1132
|
+
|
|
1133
|
+
## To use Resend instead (a non-dev client)
|
|
1134
|
+
Set \`EMAIL_PROVIDER=resend\`, \`RESEND_API_KEY\`, and \`RESEND_FROM\` (from a
|
|
1135
|
+
Resend-verified domain). No code change.
|
|
1136
|
+
|
|
1137
|
+
## Uptime
|
|
1138
|
+
Point any uptime monitor at \`/health\` (DB-free), never a login or DB-touching
|
|
1139
|
+
URL ([[uptime-kuma-monitor]] / [[neon-postgres]]).
|
|
1140
|
+
`;
|
|
1141
|
+
/**
|
|
1142
|
+
* Build the email-wiring files for a scaffold that sends email. \`layout\`
|
|
1143
|
+
* selects the file paths + whether a vitest test is emitted:
|
|
1144
|
+
* - "nextjs" → \`lib/email/mailer.ts\` (imported via the \`@/*\` alias); no
|
|
1145
|
+
* test file (the nextjs scaffold ships no test runner).
|
|
1146
|
+
* - "node-service" → \`src/lib/email/mailer.ts\` + \`src/lib/email/mailer.test.ts\`
|
|
1147
|
+
* (vitest picks up \`src/**\/*.test.ts\`).
|
|
1148
|
+
* The directive is emitted for both.
|
|
1149
|
+
*/
|
|
1150
|
+
export function emailFiles(inputs, opts, spec, layout) {
|
|
1151
|
+
const dir = layout === "nextjs" ? "lib/email" : "src/lib/email";
|
|
1152
|
+
const files = [
|
|
1153
|
+
{ path: `${dir}/mailer.ts`, content: EMAIL_MAILER_BODY },
|
|
1154
|
+
{
|
|
1155
|
+
path: "directives/email-setup.md",
|
|
1156
|
+
content: sub(EMAIL_SETUP_DIRECTIVE, inputs, opts, spec),
|
|
1157
|
+
},
|
|
1158
|
+
];
|
|
1159
|
+
if (layout === "node-service") {
|
|
1160
|
+
files.push({ path: `${dir}/mailer.test.ts`, content: EMAIL_MAILER_TEST_BODY });
|
|
1161
|
+
}
|
|
1162
|
+
return files;
|
|
440
1163
|
}
|