@zero2webmaster/starter-kit 0.19.1 → 0.22.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 +7 -4
- package/dist/audience.d.ts +108 -0
- package/dist/audience.js +132 -0
- package/dist/scaffolders/common.d.ts +1 -1
- package/dist/scaffolders/common.js +20 -12
- package/dist/scaffolders/nextjs.js +231 -14
- package/dist/scaffolders/node-service.js +10 -7
- package/dist/scaffolders/python-service.js +3 -2
- package/dist/standards.d.ts +28 -1
- package/dist/summary.js +45 -2
- package/dist/writer.d.ts +14 -0
- package/dist/writer.js +53 -7
- package/package.json +1 -1
- package/scripts/rollup-integrations.mjs +107 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# z2w-starter-kit
|
|
2
2
|
|
|
3
|
-
**Version:** 0.
|
|
3
|
+
**Version:** 0.22.0 | **Framework:** 2.19.0
|
|
4
4
|
|
|
5
5
|
> Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.
|
|
6
6
|
|
|
@@ -83,7 +83,10 @@ The Claude Code skill at `~/.claude/skills/instantiate-z2w-project/SKILL.md` and
|
|
|
83
83
|
|
|
84
84
|
## Status
|
|
85
85
|
|
|
86
|
-
- **v0.
|
|
86
|
+
- **v0.22.0 (current)** reshapes every emitted `.env.example` / `.env.local` so the line you came to fill in is the one you see. Kerry, 2026-08-16: the `# ── Database (Neon Postgres) ─────…` ruler *"is usually too long and therefore doesn't look like anything useful"*, and eighteen lines of explanation sat between the header and `DATABASE_URL=`. Headers are now a plain `# Database (Neon Postgres)`, and each block leads with its assignments and carries its prose directly underneath. **Per block rather than per file, which was Kerry's call between two readings of his own note** — collecting every variable at the top of the file would put the pooled-connection warning a screen away from the person about to paste the wrong connection string, and that warning only works where it is read. **Not a trim: every explanatory sentence survives, reworded and moved**, and there is a control test that unwraps the comment prose and asserts the load-bearing warnings are all still present, because a layout change is exactly where a paragraph goes missing unnoticed. Verified by loading the emitted file with Node's real dotenv parser — all 13 variables read back — not by grepping the template.
|
|
87
|
+
- **v0.21.0** makes the external audience gate say what actually went wrong. Its refusal named exactly one cause — *"a heading was probably renamed upstream"* — for a state that has two, and `project-creator`, the only consumer that resolves Templates from a version-**pinned** package rather than from Kerry's disk, hits the other one every time: at AGENTS v2.15.0 the `## Keeping This Framework Current` section simply did not exist yet, so every outside-brand scaffold refused in their production while they hunted a rename that never happened. Each gated section now declares the Templates version that first shipped it, the gate derives a minimum from those declarations, and the error distinguishes **version skew** (upgrade Templates) from **unexplained** (fix the section list). The throw is deliberately not softened. Same release: the standards decision log is now gate-aware — a standard whose whole section the gate removed reports `removed-by-audience-gate` instead of `inserted-inline`, because the old log let a preview UI tell an outside customer it had "Skill Vault awareness" in a file that no longer mentioned it; and a new `privateReferences` finding separates a surviving line that *instructs* the reader into the private Skill Vault from one that merely points at a missing section — one hit at Templates v2.18.0 and zero at v2.19.0, which removed that sentence upstream during the same session, demoting the finding into the milder dangling-reference class rather than making the check inert. No emitted file changes by a byte.
|
|
88
|
+
- **v0.20.0** emits `lib/csv-export.ts` and an enforcing `test/csv-export.test.ts` into **every** Next.js scaffold, with no capability flag. A CSV cell beginning `=`, `+`, `-` or `@` is evaluated as a formula by Excel and Google Sheets, so an unguarded export is code execution on the machine of whoever opens it — arriving through a file the app itself told them to download. A survey of 53 Z2W repos found 1 pass and 12 fail, and all 12 grew their export months after the project was scaffolded, which is why this one ships unconditionally rather than behind a flag: "this app will export CSV" is not knowable at scaffold time the way "this app takes cards" is. The emitted test greps for any file serving `text/csv` that skips the helper, so the guard survives the next person who adds an export. Same release: `scripts/rollup-integrations.mjs` now reads markdown tables and `**We CONSUME:**` headings, recovering 18 real dependency edges the ecosystem map had been missing, with none lost.
|
|
89
|
+
- **v0.19.1** emits a `:disabled` rule for **buttons** in `app/globals.css`, so a disabled button still looks disabled after the author gives buttons a brand fill. The scaffold ships no button styling of its own, so today the browser's grey rendering still applies — the trap opens on the author's first `background`/`color`, which overrides that grey and leaves `:disabled` a state with no appearance: the button looks pressable, the click does nothing, and the user concludes the app is broken. A sibling Z2W app shipped exactly that across ~50 screens behind a clean typecheck, a green build and 1,051 passing tests, because it is a rendered-pixel property no unit test holds. Includes the `:hover` cancel people forget — a `filter: brightness()` hover happily re-brightens a dimmed button at the moment the user is deciding to click. Verified on real pixels via CDP with `:hover` forced, and canary-verified by stripping the rule from a live scaffold.
|
|
87
90
|
- **v0.19.0** emits the **PWA baseline** for `nextjs` projects with a web UI — `public/manifest.json`, `public/icon.svg`, `public/sw.js` and `components/ServiceWorker.tsx`, wired into `app/layout.tsx` — so a scaffolded app installs on a phone. Three decisions run against the original design note and are documented in place: `app/icon.svg` is NOT emitted (a static icon file in that segment would silently retire the generated `app/icon.tsx` favicon), `theme_color` comes from the brand primary so it agrees with the layout's `viewport.themeColor`, and the glyph is a path rather than text because no font is guaranteed where the OS rasterises an icon. The service worker is network-first, never caches `/api/`, and evicts only its own cache prefix — that last clause fixed a real defect found by **executing** the emitted worker in tests rather than grepping it: an origin-wide sweep meant one Z2W app's deploy wiped a neighbouring app's offline cache under `/path` routing.
|
|
88
91
|
- **v0.18.4** points the writer's cross-cutting placeholder check at EVERY emitted file. It had run against `CLAUDE.md` alone since Step 6 — one of the ~42 files a Next.js scaffold emits — so `sentry.shared.ts` shipped a literal `{{project_name}}`, a key that has never existed in the substitution map. Found by dogfooding a real scaffold, not by the suite. A per-project-type sweep now covers all eight types.
|
|
89
92
|
- **v0.18.3** makes every emitted `.gitignore` refuse a downloaded cloud service-account key. The Google Cloud console names a private key `<project-id>-<12 hex>.json`, which matched nothing in the scaffolded ignore file and, unlike a stray `.env.production`, carries no hint in its filename that it is a credential. Found when a live Gmail delegation key for two SAVE THE FROGS! mailboxes landed in a repo this CLI had emitted.
|
|
@@ -95,7 +98,7 @@ The Claude Code skill at `~/.claude/skills/instantiate-z2w-project/SKILL.md` and
|
|
|
95
98
|
- **v0.17.1** stops `scripts/rollup-integrations.mjs` counting its own `*-archive.md` spill files in the "Bulletin files scanned" denominator (72 -> 52), and STATES the exclusion rather than silently shrinking the number.
|
|
96
99
|
- **v0.17.0** makes the **Cloud-Run-vs-Fly.io host choice a standard** for `python-service` / `node-service` scaffolds, so a long-running service's platform is decided by one test — *does it need a persistent volume?* — rather than per project by whoever is in the chair. Cloud Run for stateless request/response that scales to zero with the database elsewhere; Fly.io for stateful always-on needing a disk that survives a restart, which Cloud Run structurally cannot hold. It is a ruling rather than a preference because `z2w-multi-lingual-api` costed it on a live service (~13 req/hr inside a $2/month budget, because Cloud Run genuinely idles at zero), and it carries the half a new project would not think to ask for: **do not re-litigate this as a migration** — every real incident there traced to Neon's CU-hour cap or to secret hygiene, both external to *both* platforms. Deliberately NOT inserted for `cf-worker` / `cf-pages` / `nextjs`, whose host the project type already settles.
|
|
97
100
|
- **v0.16.2** fixes `--strict` so it judges only what the invocation actually reconciled, unblocking `z2w-agent-coordination`'s Project Registry reconciler cron.
|
|
98
|
-
- **v0.15.1
|
|
101
|
+
- **v0.15.1** ships `scripts/rollup-integrations.mjs` **in the npm tarball**, which is the one thing standing between the Project Registry reconciler and a schedule. `z2w-agent-coordination` accepted this project's proposal to host it on a cron and built the workflow, then found neither delivery route worked: a checkout of this private repo needs a PAT that could read every private repo in the org, and although the package *is* published, the tarball shipped **no `scripts/` at all** — `files` listed `dist/**` + README + LICENSE and the reconciler matched none of those globs. *"It is published"* and *"the script is reachable"* were two different facts. A runner can now `npm i @zero2webmaster/starter-kit@latest` and get it with **zero credentials**. Guarded by `src/package-contents.test.ts`, which runs `npm pack --dry-run --json` and asserts on the **artifact** rather than the glob — nothing here could previously tell a shipped file from an unshipped one.
|
|
99
102
|
- **v0.15.0** deletes the embedded Agent Coordination block in favour of a **pointer**, because this CLI is an *emitter* and a stale copy here is minted into every new Z2W project. `z2w-agent-coordination` measured currency across the ecosystem on 2026-08-07 and found **0 of 37 files at canonical** — 34 stale, 3 frozen paraphrases — and named "delete the copy, keep a pointer" its preferred remedy; the block had grown 4,274 B → 34,515 B in ten weeks, so every bump re-asked ~21 projects for a bigger paste. Scaffolded `CLAUDE.md` files now carry heading + fingerprint + session-start steps 1 and 1b (read the live block; it wins) + the Hard rules, and drop ~24 KB of auto-loaded context each. **The Hard rules stay embedded on purpose** — a leaked secret or an overwritten neighbour is irreversible, so those must hold even when the clone is unreachable. The old byte-diff guard was replaced rather than dropped (pointer conformance + an anti-regrowth byte ceiling, both canary-verified), and a real defect in it was fixed: it read a local bulletin checkout without ever checking that the checkout was current, and that clone was **215 commits behind**, so it compared against stale canon while reporting a shrinking gap.
|
|
100
103
|
- **v0.14.0** makes card-path bot protection a scaffold standard, and fixes a defect that made **every** Next.js scaffold's server modules impossible to unit-test. A new `acceptsCards` input inserts a standard pointing at [[stripe-elements-confirm-path]] §8 for every project type that has a runtime request surface, and — for Next.js — emits the protected endpoint shape rather than a bare one: a Turnstile verifier whose verdict is five-valued and **fails open**, an abuse policy sized for card entry (30 per 10 minutes per source, no global cap) rather than copied from order submission, the browser widget with `appearance: "interaction-only"` and every failure callback wired, and an emitted test that greps the consuming project's own `app/` and fails the next card path added bare. The enumeration grep ships *with* the standard, because a rule that says "protect the card path" without saying how to enumerate card paths passes review and misses a route. Separately: `import "server-only"` is a build-time poison pill that made every server module in every scaffold fail to LOAD under vitest — while `next build`, `tsc --noEmit` and the emitted suite all passed — so scaffolds now emit a `server-only` test stub plus the `@/*` alias that mirrors `tsconfig.json`.
|
|
101
104
|
- **v0.9.5** gives the Project Registry a **write path for the events it describes**. `z2w-agent-command-center` reported two stale `production_status` rows and asked for a writer; investigating found two different causes wearing one face. `site-control`'s row would have been fixed by the reconciler that already exists — nothing ever ran it. `email-engine`'s row **could not** be fixed, because `scripts/rollup-integrations.mjs` allowed a backtick before the status value but not an asterisk, so every project that **bolded** its Live status parsed as null and vanished from the report — indistinguishable from a row already in sync. That was 3 of the 15 sections declaring a status (20%), two of which said LIVE. The parser now reads the forms agents actually write, and reports declared-but-unreadable separately from never-declared, at zero as well as non-zero. Six rows reconciled. Also: the `command_center` role (scoped to the two approval columns), a CHECK that makes `summary_state = 'approved'` unreachable without them, and `status_qualifier` for the projects that kept writing a sixth value into a five-value enum.
|
|
@@ -127,4 +130,4 @@ Inquiries: kerry@zero2webmaster.com.
|
|
|
127
130
|
---
|
|
128
131
|
|
|
129
132
|
*Scaffolded 2026-05-28 via the [[instantiate-z2w-project]] Claude Code skill v1; reconciled against the consolidated skill v1.1.0 (brief-first + Agent Coordination block) on 2026-05-29.*
|
|
130
|
-
*Version: 0.
|
|
133
|
+
*Version: 0.22.0 | Last Updated: 2026-08-20*
|
package/dist/audience.d.ts
CHANGED
|
@@ -71,7 +71,66 @@ export declare const EXTERNAL_DROPPED_SECTIONS: readonly {
|
|
|
71
71
|
* suite, whose fixture contained all six sections (2026-08-14).
|
|
72
72
|
*/
|
|
73
73
|
readonly conditionallyPresent?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The canonical AGENTS body version that FIRST shipped this heading, for
|
|
76
|
+
* sections sourced from Templates rather than generated by this CLI.
|
|
77
|
+
*
|
|
78
|
+
* 🔴 **This exists because "absent" had two causes and the error named only
|
|
79
|
+
* one of them.** `project-creator` resolves Templates from a version-PINNED
|
|
80
|
+
* package while this CLI resolves it from Kerry's disk, so this repo never
|
|
81
|
+
* sees version skew and its first real consumer sees nothing else. Pinned at
|
|
82
|
+
* AGENTS v2.15.0, `## Keeping This Framework Current` simply did not exist
|
|
83
|
+
* yet — the gate threw, said *"a heading was probably renamed upstream"*, and
|
|
84
|
+
* sent them hunting a rename that never happened while every outside-brand
|
|
85
|
+
* scaffold refused in their production (filed 2026-08-19).
|
|
86
|
+
*
|
|
87
|
+
* Omitted for sections this CLI itself emits (`Standards block`,
|
|
88
|
+
* `Capture Learnings`, `Agent Coordination`) — those are spliced in from
|
|
89
|
+
* `src/standards.ts` markers and are present at every Templates version, so
|
|
90
|
+
* for them "absent" really can only mean the gate stopped matching.
|
|
91
|
+
*
|
|
92
|
+
* The throw is deliberately NOT softened. A section missing because the
|
|
93
|
+
* Templates source predates it is genuinely safe — the doctrine is not in the
|
|
94
|
+
* document to leak — but "safe" is not the same as "supported", and shipping a
|
|
95
|
+
* customer scaffold from a Templates version this gate was never written
|
|
96
|
+
* against is a claim nobody verified. It still refuses; it just now refuses
|
|
97
|
+
* with the true cause and an actionable fix.
|
|
98
|
+
*/
|
|
99
|
+
readonly sinceTemplatesVersion?: string;
|
|
74
100
|
}[];
|
|
101
|
+
/**
|
|
102
|
+
* The lowest canonical AGENTS body version this gate can serve — the highest
|
|
103
|
+
* `sinceTemplatesVersion` among the sections it must drop.
|
|
104
|
+
*
|
|
105
|
+
* Derived, never hand-written: adding a section sourced from a newer Templates
|
|
106
|
+
* body raises this automatically, so the declared floor cannot drift from the
|
|
107
|
+
* list it describes.
|
|
108
|
+
*/
|
|
109
|
+
export declare const GATE_MIN_TEMPLATES_VERSION: string;
|
|
110
|
+
/** Why a section the gate must drop was not found in the document. */
|
|
111
|
+
export type NotFoundCause = "version-skew" | "unexplained";
|
|
112
|
+
/** A section the gate had to drop and could not find, with the likely cause. */
|
|
113
|
+
export interface UnfoundSection {
|
|
114
|
+
readonly heading: string;
|
|
115
|
+
/**
|
|
116
|
+
* `version-skew` — the Templates body in use predates the heading, so the
|
|
117
|
+
* section is legitimately absent and the fix is upgrading the Templates
|
|
118
|
+
* source. `unexplained` — the heading should be there, so it was renamed
|
|
119
|
+
* upstream or the body changed shape, and the fix is `EXTERNAL_DROPPED_SECTIONS`.
|
|
120
|
+
*/
|
|
121
|
+
readonly cause: NotFoundCause;
|
|
122
|
+
/** Present only for `version-skew`: the version that first shipped the heading. */
|
|
123
|
+
readonly sinceTemplatesVersion?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Classify each not-found heading against the resolved Templates version.
|
|
127
|
+
*
|
|
128
|
+
* `templatesVersion` is the `X.Y.Z` parsed off the canonical `AGENTS_v*.md`
|
|
129
|
+
* filename — the same value that fills `{{framework_version}}`. Pass `undefined`
|
|
130
|
+
* when it genuinely is not known; every finding then reads `unexplained`, which
|
|
131
|
+
* is the pre-existing behaviour and the safe direction to fail in.
|
|
132
|
+
*/
|
|
133
|
+
export declare function classifyUnfoundSections(notFound: readonly string[], templatesVersion: string | undefined): UnfoundSection[];
|
|
75
134
|
/** What {@link gateSectionsForAudience} did, so callers can report rather than guess. */
|
|
76
135
|
export interface AudienceGateResult {
|
|
77
136
|
/** The gated document. */
|
|
@@ -107,6 +166,37 @@ export interface AudienceGateResult {
|
|
|
107
166
|
/** 1-indexed line number in the GATED document. */
|
|
108
167
|
readonly line: number;
|
|
109
168
|
}[];
|
|
169
|
+
/**
|
|
170
|
+
* Surviving lines that INSTRUCT the reader to use a private Z2W resource.
|
|
171
|
+
*
|
|
172
|
+
* 🔴 **A different class from {@link danglingReferences}, and worse.** A
|
|
173
|
+
* dangling reference points at a section that is not there — the reader
|
|
174
|
+
* follows it, finds nothing, shrugs. A private reference tells them to *go do
|
|
175
|
+
* something* in a library they cannot open: `## Self-annealing loop` still
|
|
176
|
+
* says *"capture it in the Skill Vault"*, which is the same class as the
|
|
177
|
+
* private-bulletin-repo leak v0.16.0 fixed rather than mere disclosure.
|
|
178
|
+
* Naming a skill in passing is the accepted posture; instructing someone into
|
|
179
|
+
* the Vault is not. (Filed by `project-creator` 2026-08-19, who ranked this
|
|
180
|
+
* the one worth prioritising out of 12 residual files.)
|
|
181
|
+
*
|
|
182
|
+
* **Reported, never auto-edited**, for the same reason as the rest of this
|
|
183
|
+
* module: the sentence lives inside the canonical AGENTS body, and a body
|
|
184
|
+
* emitted with sentences quietly altered still carries a fingerprint claiming
|
|
185
|
+
* it is canonical. The durable fix is upstream in `cursor-project-templates`;
|
|
186
|
+
* this makes the residual visible instead of silent in the meantime.
|
|
187
|
+
*
|
|
188
|
+
* Measured on a real customer-shaped `nextjs` scaffold against Templates
|
|
189
|
+
* v2.18.0 (2026-08-20): **exactly one hit across all 42 emitted files**, so
|
|
190
|
+
* this does not cry wolf.
|
|
191
|
+
*/
|
|
192
|
+
readonly privateReferences: readonly {
|
|
193
|
+
/** The private resource named, e.g. `"Skill Vault"`. */
|
|
194
|
+
readonly resource: string;
|
|
195
|
+
/** 1-indexed line number in the GATED document. */
|
|
196
|
+
readonly line: number;
|
|
197
|
+
/** The surviving line, trimmed, so a consumer can show it without re-reading the file. */
|
|
198
|
+
readonly text: string;
|
|
199
|
+
}[];
|
|
110
200
|
}
|
|
111
201
|
/**
|
|
112
202
|
* Remove whole `## ` sections from an assembled `CLAUDE.md` for an external
|
|
@@ -121,6 +211,24 @@ export interface AudienceGateResult {
|
|
|
121
211
|
* `z2w-agent-coordination` hit in their own section tooling on 2026-08-13.
|
|
122
212
|
*/
|
|
123
213
|
export declare function gateSectionsForAudience(content: string, audience: Audience): AudienceGateResult;
|
|
214
|
+
/**
|
|
215
|
+
* Re-state the standards decision log against what the audience gate actually
|
|
216
|
+
* removed, so a consumer rendering that log cannot claim a standard is in a
|
|
217
|
+
* file the gate emptied of it.
|
|
218
|
+
*
|
|
219
|
+
* Driven by the gate's own `dropped` array rather than by `audience` — if the
|
|
220
|
+
* gate did not remove the section (an external scaffold with
|
|
221
|
+
* `participateInBulletin: false` never has an `## Agent Coordination` section
|
|
222
|
+
* to drop), the decision is left exactly as the resolver wrote it.
|
|
223
|
+
*
|
|
224
|
+
* Pure and total: returns a new array, never mutates, and is a no-op when
|
|
225
|
+
* `dropped` is empty — which is every `internal` scaffold.
|
|
226
|
+
*/
|
|
227
|
+
export declare function applyGateToDecisions<D extends {
|
|
228
|
+
key: string;
|
|
229
|
+
state: string;
|
|
230
|
+
reason: string;
|
|
231
|
+
}>(decisions: readonly D[], dropped: readonly string[]): D[];
|
|
124
232
|
/**
|
|
125
233
|
* Rewrite `[[skill-name]]` Vault pointers into plain text.
|
|
126
234
|
*
|
package/dist/audience.js
CHANGED
|
@@ -61,6 +61,8 @@ export const EXTERNAL_DROPPED_SECTIONS = [
|
|
|
61
61
|
{
|
|
62
62
|
heading: "Z2W Portfolio Standards",
|
|
63
63
|
why: "a pointer index into a private Skill Vault the reader cannot open",
|
|
64
|
+
// Folded into the general + WP bodies 2026-06-23 (FRAMEWORK_HISTORY #28).
|
|
65
|
+
sinceTemplatesVersion: "2.13.0",
|
|
64
66
|
},
|
|
65
67
|
{
|
|
66
68
|
heading: "Standards block",
|
|
@@ -73,10 +75,15 @@ export const EXTERNAL_DROPPED_SECTIONS = [
|
|
|
73
75
|
{
|
|
74
76
|
heading: "Keeping This Framework Current",
|
|
75
77
|
why: "a fingerprint-currency table naming private Z2W repos, meaningless outside the ecosystem",
|
|
78
|
+
// Introduced by AGENTS v2.17.0 / WP v3.5.0 (Templates `2b33d45`). This is
|
|
79
|
+
// the entry that sets GATE_MIN_TEMPLATES_VERSION.
|
|
80
|
+
sinceTemplatesVersion: "2.17.0",
|
|
76
81
|
},
|
|
77
82
|
{
|
|
78
83
|
heading: "Common Name & Terminology Glossary",
|
|
79
84
|
why: "internal vocabulary and Z2W brand spellings; reseeded from the customer's own brandNameRule instead",
|
|
85
|
+
// Added by AGENTS v2.6.0 (Templates `8a34391`).
|
|
86
|
+
sinceTemplatesVersion: "2.6.0",
|
|
80
87
|
},
|
|
81
88
|
{
|
|
82
89
|
heading: "Agent Coordination",
|
|
@@ -86,6 +93,53 @@ export const EXTERNAL_DROPPED_SECTIONS = [
|
|
|
86
93
|
conditionallyPresent: true,
|
|
87
94
|
},
|
|
88
95
|
];
|
|
96
|
+
/**
|
|
97
|
+
* Compare two `X.Y.Z` strings numerically. Returns <0, 0, >0 like a comparator.
|
|
98
|
+
*
|
|
99
|
+
* Numeric per component, never lexicographic: `"2.9.0" > "2.17.0"` is true as
|
|
100
|
+
* strings and false as versions, and this gate's whole job hinges on getting
|
|
101
|
+
* that comparison right.
|
|
102
|
+
*/
|
|
103
|
+
function compareSemver(a, b) {
|
|
104
|
+
const pa = a.split(".").map((n) => Number.parseInt(n, 10));
|
|
105
|
+
const pb = b.split(".").map((n) => Number.parseInt(n, 10));
|
|
106
|
+
for (let i = 0; i < 3; i++) {
|
|
107
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
108
|
+
if (d !== 0)
|
|
109
|
+
return d;
|
|
110
|
+
}
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The lowest canonical AGENTS body version this gate can serve — the highest
|
|
115
|
+
* `sinceTemplatesVersion` among the sections it must drop.
|
|
116
|
+
*
|
|
117
|
+
* Derived, never hand-written: adding a section sourced from a newer Templates
|
|
118
|
+
* body raises this automatically, so the declared floor cannot drift from the
|
|
119
|
+
* list it describes.
|
|
120
|
+
*/
|
|
121
|
+
export const GATE_MIN_TEMPLATES_VERSION = EXTERNAL_DROPPED_SECTIONS.reduce((max, s) => s.sinceTemplatesVersion && compareSemver(s.sinceTemplatesVersion, max) > 0
|
|
122
|
+
? s.sinceTemplatesVersion
|
|
123
|
+
: max, "0.0.0");
|
|
124
|
+
/**
|
|
125
|
+
* Classify each not-found heading against the resolved Templates version.
|
|
126
|
+
*
|
|
127
|
+
* `templatesVersion` is the `X.Y.Z` parsed off the canonical `AGENTS_v*.md`
|
|
128
|
+
* filename — the same value that fills `{{framework_version}}`. Pass `undefined`
|
|
129
|
+
* when it genuinely is not known; every finding then reads `unexplained`, which
|
|
130
|
+
* is the pre-existing behaviour and the safe direction to fail in.
|
|
131
|
+
*/
|
|
132
|
+
export function classifyUnfoundSections(notFound, templatesVersion) {
|
|
133
|
+
return notFound.map((heading) => {
|
|
134
|
+
const since = EXTERNAL_DROPPED_SECTIONS.find((s) => s.heading === heading)?.sinceTemplatesVersion;
|
|
135
|
+
if (since !== undefined &&
|
|
136
|
+
templatesVersion !== undefined &&
|
|
137
|
+
compareSemver(templatesVersion, since) < 0) {
|
|
138
|
+
return { heading, cause: "version-skew", sinceTemplatesVersion: since };
|
|
139
|
+
}
|
|
140
|
+
return { heading, cause: "unexplained" };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
89
143
|
/** Normalise a `## ` heading line to its comparable text. */
|
|
90
144
|
function headingText(line) {
|
|
91
145
|
return line.replace(/^##\s+/, "").trim();
|
|
@@ -102,6 +156,26 @@ function matchesHeading(line, heading) {
|
|
|
102
156
|
const text = headingText(line);
|
|
103
157
|
return text === heading || text.startsWith(heading + " ") || text.startsWith(heading + " (");
|
|
104
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Private Z2W resources whose NAME surviving is disclosure (accepted) but whose
|
|
161
|
+
* appearance in an INSTRUCTION is a leak (reported).
|
|
162
|
+
*
|
|
163
|
+
* Deliberately a short, closed list of things an outside reader genuinely
|
|
164
|
+
* cannot reach. It is not a general secret-scanner — the emitted `.env.example`
|
|
165
|
+
* and the CSV guard both mention plenty of internal-sounding names that are
|
|
166
|
+
* simply names.
|
|
167
|
+
*/
|
|
168
|
+
const PRIVATE_RESOURCES = [
|
|
169
|
+
{ resource: "Skill Vault", re: /\bSkill Vault\b/ },
|
|
170
|
+
{ resource: "the coordination bulletin repo", re: /zero2webmaster\/z2w-agent-coordination/ },
|
|
171
|
+
{ resource: "the local skills symlink tree", re: /[~.]\/\.(claude|cursor)\/skills/ },
|
|
172
|
+
];
|
|
173
|
+
/**
|
|
174
|
+
* Verbs that turn a mention into an instruction. Without this the check fires on
|
|
175
|
+
* the `## Z2W Portfolio Standards` preamble's *"the canonical text lives in the
|
|
176
|
+
* Skill Vault"* — a statement of fact, and a section the gate drops anyway.
|
|
177
|
+
*/
|
|
178
|
+
const INSTRUCTION_RE = /\b(capture|add|extend|load|open|read|check|update|see|consult|follow|put|write|file|store) (it|them|this|the|a|an|your|into|in) /i;
|
|
105
179
|
/**
|
|
106
180
|
* Remove whole `## ` sections from an assembled `CLAUDE.md` for an external
|
|
107
181
|
* audience. A no-op for `internal`, byte-for-byte.
|
|
@@ -122,6 +196,7 @@ export function gateSectionsForAudience(content, audience) {
|
|
|
122
196
|
notFound: [],
|
|
123
197
|
bytesDropped: 0,
|
|
124
198
|
danglingReferences: [],
|
|
199
|
+
privateReferences: [],
|
|
125
200
|
};
|
|
126
201
|
}
|
|
127
202
|
const lines = content.split("\n");
|
|
@@ -180,14 +255,71 @@ export function gateSectionsForAudience(content, audience) {
|
|
|
180
255
|
}
|
|
181
256
|
}
|
|
182
257
|
}
|
|
258
|
+
// Scan what SURVIVED for INSTRUCTIONS into a private Z2W resource — a
|
|
259
|
+
// separate, worse class than a dangling reference (see `privateReferences`).
|
|
260
|
+
const privateReferences = [];
|
|
261
|
+
for (let i = 0; i < outLines.length; i++) {
|
|
262
|
+
const line = outLines[i];
|
|
263
|
+
if (!INSTRUCTION_RE.test(line))
|
|
264
|
+
continue;
|
|
265
|
+
for (const { resource, re } of PRIVATE_RESOURCES) {
|
|
266
|
+
if (re.test(line)) {
|
|
267
|
+
privateReferences.push({ resource, line: i + 1, text: line.trim() });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
183
271
|
return {
|
|
184
272
|
content: out,
|
|
185
273
|
dropped,
|
|
186
274
|
notFound,
|
|
187
275
|
bytesDropped: content.length - out.length,
|
|
188
276
|
danglingReferences,
|
|
277
|
+
privateReferences,
|
|
189
278
|
};
|
|
190
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* The `## ` section each standard's rendered text ends up inside.
|
|
282
|
+
*
|
|
283
|
+
* Mirrors `resolveStandards()`: `agent-coordination` is spliced into its own
|
|
284
|
+
* top-level section via a separate marker so it can carry the canonical
|
|
285
|
+
* fingerprint verbatim; every other standard lands inline in `## Standards
|
|
286
|
+
* block`. Two destinations, both of which the external gate drops.
|
|
287
|
+
*/
|
|
288
|
+
function sectionHoldingStandard(key) {
|
|
289
|
+
return key === "agent-coordination" ? "Agent Coordination" : "Standards block";
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Re-state the standards decision log against what the audience gate actually
|
|
293
|
+
* removed, so a consumer rendering that log cannot claim a standard is in a
|
|
294
|
+
* file the gate emptied of it.
|
|
295
|
+
*
|
|
296
|
+
* Driven by the gate's own `dropped` array rather than by `audience` — if the
|
|
297
|
+
* gate did not remove the section (an external scaffold with
|
|
298
|
+
* `participateInBulletin: false` never has an `## Agent Coordination` section
|
|
299
|
+
* to drop), the decision is left exactly as the resolver wrote it.
|
|
300
|
+
*
|
|
301
|
+
* Pure and total: returns a new array, never mutates, and is a no-op when
|
|
302
|
+
* `dropped` is empty — which is every `internal` scaffold.
|
|
303
|
+
*/
|
|
304
|
+
export function applyGateToDecisions(decisions, dropped) {
|
|
305
|
+
if (dropped.length === 0)
|
|
306
|
+
return [...decisions];
|
|
307
|
+
const droppedSet = new Set(dropped);
|
|
308
|
+
return decisions.map((d) => {
|
|
309
|
+
if (d.state !== "inserted-inline")
|
|
310
|
+
return { ...d };
|
|
311
|
+
const section = sectionHoldingStandard(d.key);
|
|
312
|
+
if (!droppedSet.has(section))
|
|
313
|
+
return { ...d };
|
|
314
|
+
return {
|
|
315
|
+
...d,
|
|
316
|
+
state: "removed-by-audience-gate",
|
|
317
|
+
reason: `${d.reason} — then removed: audience="external" drops the whole ` +
|
|
318
|
+
`\`## ${section}\` section, so this standard's text is NOT in the emitted CLAUDE.md.`,
|
|
319
|
+
removedFromSection: section,
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
}
|
|
191
323
|
/**
|
|
192
324
|
* Rewrite `[[skill-name]]` Vault pointers into plain text.
|
|
193
325
|
*
|
|
@@ -133,7 +133,7 @@ export declare const NEON_DRIVER_DEP: Readonly<Record<string, string>>;
|
|
|
133
133
|
* sends email. Both providers' vars are stubbed so switching is a one-line env
|
|
134
134
|
* change with no code edit.
|
|
135
135
|
*/
|
|
136
|
-
export declare const EMAIL_ENV_BLOCK = "\n#
|
|
136
|
+
export declare const EMAIL_ENV_BLOCK = "\n# Transactional / auth email\n\nEMAIL_PROVIDER=ses\nSES_REGION=\nSES_ACCESS_KEY_ID=\nSES_SECRET_ACCESS_KEY=\nAWS_SES_FROM=\n\n# Only read when EMAIL_PROVIDER=resend:\nRESEND_API_KEY=\nRESEND_FROM=\n\n# Wiring: lib/email/mailer.ts. Setup: directives/email-setup.md +\n# [[email-service-router]]. Until the four SES_ vars are set every send is a\n# logged no-op, so the app works and only delivery is deferred.\n#\n# EMAIL_PROVIDER \u2014 \"ses\" (default) or \"resend\". Switching is this one line; no\n# code change at any call site.\n#\n# SES_* \u2014 the custom prefix and the explicit credentials are deliberate. On\n# Vercel/Lambda the platform injects its own AWS_* vars, which would shadow the\n# default credential chain. SES_REGION MUST equal the region the sender domain\n# is verified in, or sends fail with \"Email address is not verified\".\n#\n# AWS_SES_FROM \u2014 a domain-verified identity can send from any local-part.\n# Format: \"Brand Name <sender@yourdomain.com>\". Never noreply@.\n#\n# RESEND_FROM \u2014 must be on a Resend-verified domain.\n";
|
|
137
137
|
/**
|
|
138
138
|
* Build the email-wiring files for a scaffold that sends email. \`layout\`
|
|
139
139
|
* selects the file paths + whether a vitest test is emitted:
|
|
@@ -1377,26 +1377,34 @@ describe("selectProvider", () => {
|
|
|
1377
1377
|
* change with no code edit.
|
|
1378
1378
|
*/
|
|
1379
1379
|
export const EMAIL_ENV_BLOCK = `
|
|
1380
|
-
#
|
|
1381
|
-
# Provider router. Default: Amazon SES. Set to "resend" to use Resend instead —
|
|
1382
|
-
# no code change. See directives/email-setup.md + [[email-service-router]].
|
|
1383
|
-
EMAIL_PROVIDER=ses
|
|
1380
|
+
# Transactional / auth email
|
|
1384
1381
|
|
|
1385
|
-
|
|
1386
|
-
# Vercel/Lambda the platform injects its own AWS_* that would shadow the default
|
|
1387
|
-
# credential chain. SES_REGION MUST equal the region the sender domain is
|
|
1388
|
-
# verified in, or sends fail with "Email address is not verified".
|
|
1382
|
+
EMAIL_PROVIDER=ses
|
|
1389
1383
|
SES_REGION=
|
|
1390
1384
|
SES_ACCESS_KEY_ID=
|
|
1391
1385
|
SES_SECRET_ACCESS_KEY=
|
|
1392
|
-
# From address. A domain-verified identity can send from any local-part.
|
|
1393
|
-
# Format: "Brand Name <sender@yourdomain.com>". Never noreply@.
|
|
1394
1386
|
AWS_SES_FROM=
|
|
1395
1387
|
|
|
1396
|
-
#
|
|
1397
|
-
# RESEND_FROM must be on a Resend-verified domain.
|
|
1388
|
+
# Only read when EMAIL_PROVIDER=resend:
|
|
1398
1389
|
RESEND_API_KEY=
|
|
1399
1390
|
RESEND_FROM=
|
|
1391
|
+
|
|
1392
|
+
# Wiring: lib/email/mailer.ts. Setup: directives/email-setup.md +
|
|
1393
|
+
# [[email-service-router]]. Until the four SES_ vars are set every send is a
|
|
1394
|
+
# logged no-op, so the app works and only delivery is deferred.
|
|
1395
|
+
#
|
|
1396
|
+
# EMAIL_PROVIDER — "ses" (default) or "resend". Switching is this one line; no
|
|
1397
|
+
# code change at any call site.
|
|
1398
|
+
#
|
|
1399
|
+
# SES_* — the custom prefix and the explicit credentials are deliberate. On
|
|
1400
|
+
# Vercel/Lambda the platform injects its own AWS_* vars, which would shadow the
|
|
1401
|
+
# default credential chain. SES_REGION MUST equal the region the sender domain
|
|
1402
|
+
# is verified in, or sends fail with "Email address is not verified".
|
|
1403
|
+
#
|
|
1404
|
+
# AWS_SES_FROM — a domain-verified identity can send from any local-part.
|
|
1405
|
+
# Format: "Brand Name <sender@yourdomain.com>". Never noreply@.
|
|
1406
|
+
#
|
|
1407
|
+
# RESEND_FROM — must be on a Resend-verified domain.
|
|
1400
1408
|
`;
|
|
1401
1409
|
const EMAIL_SETUP_DIRECTIVE = `# Directive — Wire transactional / auth email for {{slug}}
|
|
1402
1410
|
|
|
@@ -487,6 +487,207 @@ const TSCONFIG_TEMPLATE = `{
|
|
|
487
487
|
* costs bundle size) but the STATED CONSEQUENCE was wrong, so the emitted
|
|
488
488
|
* comment says what was actually measured. Reported back to grantor.
|
|
489
489
|
*/
|
|
490
|
+
/**
|
|
491
|
+
* CSV export, with the spreadsheet-formula guard built in.
|
|
492
|
+
*
|
|
493
|
+
* WHY THIS IS EMITTED UNCONDITIONALLY, and why that is the unusual choice here.
|
|
494
|
+
*
|
|
495
|
+
* `audit-engine` surveyed 53 repos on 2026-08-15 against clones refreshed to live
|
|
496
|
+
* HEAD and found CSV export to be the portfolio's weakest surface: **1 pass, 12
|
|
497
|
+
* fail**. Every one of `backup-engine`, `contest-management`, `file-server`,
|
|
498
|
+
* `grantor`, `z2w-admin-suite`, `z2w-ai-suite`, `z2w-board-suite`, `z2w-forms`,
|
|
499
|
+
* `z2w-multi-lingual`, `z2w-science-suite`, `z2w-seller-suite` and `audit-engine`
|
|
500
|
+
* itself writes untrusted text into a CSV with no leading-character guard.
|
|
501
|
+
* `z2w-member-match`'s `src/lib/csv-export.ts` is the single pass, and this file
|
|
502
|
+
* is that module, ported.
|
|
503
|
+
*
|
|
504
|
+
* Every other conditional standard this scaffolder emits gates on something
|
|
505
|
+
* knowable at scaffold time — `acceptsCards`, `sendsEmail`, `hasWebUi`. **"This
|
|
506
|
+
* app will export CSV" is not knowable at scaffold time**, and that is the whole
|
|
507
|
+
* argument: all 12 grew their export MONTHS after instantiation, which is exactly
|
|
508
|
+
* the moment someone reaches for `.join(",")` and nobody is thinking about
|
|
509
|
+
* spreadsheets. A flag would have protected none of them. It is 37 dependency-free
|
|
510
|
+
* lines, pure and DB-free, so the cost of shipping it to a project that never
|
|
511
|
+
* exports anything is a file nobody imports.
|
|
512
|
+
*
|
|
513
|
+
* The threat is not theoretical and is not XSS: a cell beginning `=`, `+`, `-` or
|
|
514
|
+
* `@` is evaluated as a FORMULA by Excel and Google Sheets when the file is opened,
|
|
515
|
+
* so `=cmd|'/c calc'!A1` in a name field is code execution on the admin's laptop,
|
|
516
|
+
* arriving through a file our own app told them to download. The guard fires on the
|
|
517
|
+
* LEADING character only, so `a=b`, `1-2` and `O'Brien` all survive byte-identical.
|
|
518
|
+
*/
|
|
519
|
+
const CSV_EXPORT_TEMPLATE = `/**
|
|
520
|
+
* CSV serialization for exports.
|
|
521
|
+
*
|
|
522
|
+
* Pure and DB-free so it can be unit-tested without a database, and so it can sit
|
|
523
|
+
* behind any route handler, server action or script that needs to hand a person a
|
|
524
|
+
* spreadsheet.
|
|
525
|
+
*
|
|
526
|
+
* ⚠️ THE LEADING-CHARACTER GUARD IS THE POINT — do not "simplify" it away.
|
|
527
|
+
* A field beginning \`=\`, \`+\`, \`-\` or \`@\` is interpreted by Excel and Google
|
|
528
|
+
* Sheets as a FORMULA, not as text. So a name recorded as \`=cmd|'/c calc'!A1\`
|
|
529
|
+
* becomes code execution on the machine of whoever opens the export — through a
|
|
530
|
+
* file this app told them to download. Prefixing with a single quote makes the
|
|
531
|
+
* spreadsheet treat the cell as text and is invisible in the rendered sheet.
|
|
532
|
+
*
|
|
533
|
+
* Anything a user, an importer or an upstream system of record put into your
|
|
534
|
+
* database is untrusted input for this purpose, which in practice is every column
|
|
535
|
+
* worth exporting.
|
|
536
|
+
*/
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Quote one CSV field per RFC 4180, with the spreadsheet-formula guard applied first.
|
|
540
|
+
*
|
|
541
|
+
* Order matters: the guard runs BEFORE quoting, so a field that needs both gets the
|
|
542
|
+
* apostrophe INSIDE the quotes where the spreadsheet will see it.
|
|
543
|
+
*/
|
|
544
|
+
export function csvField(value: unknown): string {
|
|
545
|
+
if (value === null || value === undefined) return "";
|
|
546
|
+
let s = String(value);
|
|
547
|
+
// Leading character only — "a=b", "1-2" and "O'Brien" must pass through untouched.
|
|
548
|
+
// Tab and carriage return are in the class because a leading one of either can
|
|
549
|
+
// still start a formula once the spreadsheet trims the cell.
|
|
550
|
+
if (/^[=+\\-@\\t\\r]/.test(s)) s = "'" + s;
|
|
551
|
+
if (/[",\\r\\n]/.test(s)) s = '"' + s.replace(/"/g, '""') + '"';
|
|
552
|
+
return s;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Serialize rows to a complete CSV document.
|
|
557
|
+
*
|
|
558
|
+
* Emits CRLF line endings and a trailing newline per RFC 4180, and a UTF-8 BOM so
|
|
559
|
+
* Excel on Windows renders non-ASCII names correctly instead of mojibake. The BOM
|
|
560
|
+
* is not decoration — without it, any name outside ASCII arrives visibly corrupted
|
|
561
|
+
* for the largest group of people who will ever open one of these files.
|
|
562
|
+
*/
|
|
563
|
+
export function toCsv(headers: string[], rows: unknown[][]): string {
|
|
564
|
+
const lines = [headers.map(csvField).join(",")];
|
|
565
|
+
for (const row of rows) lines.push(row.map(csvField).join(","));
|
|
566
|
+
return "\\uFEFF" + lines.join("\\r\\n") + "\\r\\n";
|
|
567
|
+
}
|
|
568
|
+
`;
|
|
569
|
+
/**
|
|
570
|
+
* The emitted enforcement half of the CSV standard.
|
|
571
|
+
*
|
|
572
|
+
* Same doctrine as the form-standards test: a helper that makes the right thing
|
|
573
|
+
* easy is not a guarantee — only a test fails the build on the NEXT export someone
|
|
574
|
+
* hand-rolls. `audit-engine` made this point about their own adoption in the same
|
|
575
|
+
* message: they added a test asserting the writer actually *calls* the guard,
|
|
576
|
+
* "a helper nobody calls is not a fix."
|
|
577
|
+
*
|
|
578
|
+
* So this file does two jobs, and the second is the load-bearing one:
|
|
579
|
+
* 1. behaviour — the guard fires where it should and, just as importantly, does
|
|
580
|
+
* NOT fire on `a=b` / `1-2` / `O'Brien`;
|
|
581
|
+
* 2. a source grep that fails when a route hands back `text/csv` without going
|
|
582
|
+
* through `csvField`. That is the check that catches the export written in
|
|
583
|
+
* six months by someone who never read this file.
|
|
584
|
+
*/
|
|
585
|
+
const CSV_EXPORT_TEST_TEMPLATE = `/**
|
|
586
|
+
* CSV export standard, enforced as tests rather than as a convention someone has
|
|
587
|
+
* to remember.
|
|
588
|
+
*
|
|
589
|
+
* The rule: **every value written into a CSV goes through \`csvField()\`.** A cell
|
|
590
|
+
* beginning \`=\`, \`+\`, \`-\` or \`@\` is a FORMULA to Excel and Google Sheets, so an
|
|
591
|
+
* unguarded export is code execution on the machine of whoever opens it.
|
|
592
|
+
*
|
|
593
|
+
* Measured across the {{brand_name}} portfolio on 2026-08-15: of 13 repos with a
|
|
594
|
+
* CSV writer, ONE had the guard. This test is here so this project stays that one.
|
|
595
|
+
*/
|
|
596
|
+
import { describe, it, expect } from "vitest";
|
|
597
|
+
import { readFileSync, readdirSync, existsSync } from "node:fs";
|
|
598
|
+
import { join, dirname } from "node:path";
|
|
599
|
+
import { fileURLToPath } from "node:url";
|
|
600
|
+
import { csvField, toCsv } from "../lib/csv-export";
|
|
601
|
+
|
|
602
|
+
// NOT \`__dirname\` — this package is "type": "module", where it is undefined.
|
|
603
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
604
|
+
|
|
605
|
+
/** Every .ts/.tsx file under the project's own source directories. */
|
|
606
|
+
function sourceFiles(dir: string): string[] {
|
|
607
|
+
const abs = join(ROOT, dir);
|
|
608
|
+
if (!existsSync(abs)) return [];
|
|
609
|
+
const out: string[] = [];
|
|
610
|
+
for (const e of readdirSync(abs, { withFileTypes: true })) {
|
|
611
|
+
if (e.name === "node_modules" || e.name.startsWith(".")) continue;
|
|
612
|
+
const rel = join(dir, e.name);
|
|
613
|
+
if (e.isDirectory()) out.push(...sourceFiles(rel));
|
|
614
|
+
else if (/\\.tsx?$/.test(e.name)) out.push(rel);
|
|
615
|
+
}
|
|
616
|
+
return out;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const SOURCES = [...sourceFiles("app"), ...sourceFiles("lib"), ...sourceFiles("components")];
|
|
620
|
+
const read = (f: string) => readFileSync(join(ROOT, f), "utf8");
|
|
621
|
+
|
|
622
|
+
describe("csvField: the spreadsheet-formula guard", () => {
|
|
623
|
+
it("prefixes the four formula-starting characters", () => {
|
|
624
|
+
for (const dangerous of ["=1+1", "+1", "-1", "@SUM(A1)", "=cmd|'/c calc'!A1"]) {
|
|
625
|
+
expect(csvField(dangerous)).toBe("'" + dangerous);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it("🔴 CONTROL — leaves ordinary text that merely CONTAINS those characters alone", () => {
|
|
630
|
+
// The guard is on the LEADING character. A rule that fired anywhere would
|
|
631
|
+
// corrupt real data — and a corrupted export is a silent bug, because nobody
|
|
632
|
+
// diffs a spreadsheet against the database.
|
|
633
|
+
for (const fine of ["a=b", "1-2", "O'Brien", "x@y.com", "Smith, Jr."]) {
|
|
634
|
+
expect(csvField(fine).replace(/^"|"$/g, "").replace(/""/g, '"')).toBe(fine);
|
|
635
|
+
expect(csvField(fine).startsWith("'")).toBe(false);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it("quotes and doubles per RFC 4180", () => {
|
|
640
|
+
expect(csvField('say "hi"')).toBe('"say ""hi"""');
|
|
641
|
+
expect(csvField("a,b")).toBe('"a,b"');
|
|
642
|
+
expect(csvField("line1\\nline2")).toBe('"line1\\nline2"');
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it("empty and nullish become an empty field, never the string 'null'", () => {
|
|
646
|
+
expect(csvField(null)).toBe("");
|
|
647
|
+
expect(csvField(undefined)).toBe("");
|
|
648
|
+
expect(csvField("")).toBe("");
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
it("a guarded field that ALSO needs quoting gets the apostrophe inside the quotes", () => {
|
|
652
|
+
// Order matters. Quote-then-guard would put the apostrophe outside, where the
|
|
653
|
+
// spreadsheet never sees it, and the cell evaluates as a formula anyway.
|
|
654
|
+
expect(csvField("=A1,B1")).toBe(\`"'=A1,B1"\`);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
describe("toCsv: the document", () => {
|
|
659
|
+
it("emits a UTF-8 BOM so Excel on Windows does not mojibake non-ASCII names", () => {
|
|
660
|
+
expect(toCsv(["name"], [["Ana Muñoz"]]).charCodeAt(0)).toBe(0xfeff);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("emits CRLF line endings and a trailing newline", () => {
|
|
664
|
+
expect(toCsv(["a", "b"], [[1, 2]])).toBe("\\uFEFFa,b\\r\\n1,2\\r\\n");
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it("guards the HEADERS too, not only the rows", () => {
|
|
668
|
+
// Headers are user-controlled whenever a report lets someone pick columns.
|
|
669
|
+
expect(toCsv(["=evil"], [])).toContain("'=evil");
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
describe("nothing hand-rolls a CSV around the guard", () => {
|
|
674
|
+
it("actually has source files to check", () => {
|
|
675
|
+
// An empty list would make the grep below vacuously green.
|
|
676
|
+
expect(SOURCES.length).toBeGreaterThan(0);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it("every file that serves text/csv imports csvField or toCsv", () => {
|
|
680
|
+
// This is the check that matters in six months. \`lib/csv-export.ts\` makes the
|
|
681
|
+
// right thing easy; only this makes the wrong thing fail the build.
|
|
682
|
+
const offenders = SOURCES.filter((f) => {
|
|
683
|
+
const src = read(f);
|
|
684
|
+
if (!/text\\/csv/.test(src)) return false;
|
|
685
|
+
return !/\\b(csvField|toCsv)\\b/.test(src);
|
|
686
|
+
});
|
|
687
|
+
expect(offenders).toEqual([]);
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
`;
|
|
490
691
|
const FORM_BITS_TEMPLATE = `/**
|
|
491
692
|
* Shared form primitives that encode the {{brand_name}} form standards.
|
|
492
693
|
*
|
|
@@ -1914,9 +2115,11 @@ describe("card-path bot protection", () => {
|
|
|
1914
2115
|
* lifted with thanks; each is a mistake a first-timer makes exactly once.
|
|
1915
2116
|
*/
|
|
1916
2117
|
const NEON_DB_ENV_BLOCK = `
|
|
1917
|
-
#
|
|
1918
|
-
|
|
1919
|
-
|
|
2118
|
+
# Database (Neon Postgres)
|
|
2119
|
+
|
|
2120
|
+
DATABASE_URL=postgresql://user:pass@host-pooler.region.aws.neon.tech/dbname?sslmode=require
|
|
2121
|
+
|
|
2122
|
+
# Copy from https://console.neon.tech/ → your project → Connection Details.
|
|
1920
2123
|
#
|
|
1921
2124
|
# Use the POOLED connection string (the host contains \`-pooler\`). A serverless
|
|
1922
2125
|
# app opens a connection per invocation; the direct endpoint runs out.
|
|
@@ -1931,10 +2134,13 @@ const NEON_DB_ENV_BLOCK = `
|
|
|
1931
2134
|
# \`/api/health\` must never touch the database (per [[neon-postgres]] — routine
|
|
1932
2135
|
# probes burn the Free tier's 100 CU-hour quota and defeat scale-to-zero). The
|
|
1933
2136
|
# scaffolded health route is DB-free; keep it that way.
|
|
1934
|
-
DATABASE_URL=postgresql://user:pass@host-pooler.region.aws.neon.tech/dbname?sslmode=require
|
|
1935
2137
|
`;
|
|
1936
2138
|
const CARD_PATH_ENV_BLOCK = `
|
|
1937
|
-
#
|
|
2139
|
+
# Card-path bot protection (Cloudflare Turnstile)
|
|
2140
|
+
|
|
2141
|
+
NEXT_PUBLIC_TURNSTILE_SITE_KEY=
|
|
2142
|
+
TURNSTILE_SECRET_KEY=
|
|
2143
|
+
|
|
1938
2144
|
# Create a widget: https://dash.cloudflare.com/?to=/:account/turnstile
|
|
1939
2145
|
#
|
|
1940
2146
|
# Set BOTH or NEITHER. A half-configured pair is worse than neither — the widget
|
|
@@ -1943,8 +2149,6 @@ const CARD_PATH_ENV_BLOCK = `
|
|
|
1943
2149
|
#
|
|
1944
2150
|
# Cloudflare's always-passes / always-blocks TEST keys are the right thing to use
|
|
1945
2151
|
# in development: https://developers.cloudflare.com/turnstile/troubleshooting/testing/
|
|
1946
|
-
NEXT_PUBLIC_TURNSTILE_SITE_KEY=
|
|
1947
|
-
TURNSTILE_SECRET_KEY=
|
|
1948
2152
|
`;
|
|
1949
2153
|
/**
|
|
1950
2154
|
* Vitest config for the scaffolded project.
|
|
@@ -3208,13 +3412,15 @@ Per Z2W standing org requirement 2026-05-30. Run before adding a new page AND be
|
|
|
3208
3412
|
const ENV_EXAMPLE_TEMPLATE = `# {{slug}} — example environment variables.
|
|
3209
3413
|
# Copy to \`.env.local\` and fill in real values.
|
|
3210
3414
|
|
|
3211
|
-
# Site URL (used by metadataBase + sitemap + robots).
|
|
3212
|
-
# In production, set this to your live domain.
|
|
3213
3415
|
NEXT_PUBLIC_SITE_URL=https://{{slug}}.example.com
|
|
3214
|
-
|
|
3215
|
-
# Fathom Analytics site ID (per [[fathom-analytics]] convention).
|
|
3216
|
-
# One Fathom site = one deployment.
|
|
3217
3416
|
NEXT_PUBLIC_FATHOM_SITE_ID=
|
|
3417
|
+
|
|
3418
|
+
# NEXT_PUBLIC_SITE_URL — used by metadataBase + sitemap + robots. In production
|
|
3419
|
+
# set this to your live domain; leaving the placeholder publishes example.com
|
|
3420
|
+
# URLs in your sitemap on the first deploy.
|
|
3421
|
+
#
|
|
3422
|
+
# NEXT_PUBLIC_FATHOM_SITE_ID — per [[fathom-analytics]]. One Fathom site = one
|
|
3423
|
+
# deployment.
|
|
3218
3424
|
`;
|
|
3219
3425
|
/**
|
|
3220
3426
|
* The `CANONICAL_HOSTS` allowlist seam.
|
|
@@ -3231,7 +3437,10 @@ NEXT_PUBLIC_FATHOM_SITE_ID=
|
|
|
3231
3437
|
* pointer at the recipe, in the file the next agent actually opens.
|
|
3232
3438
|
*/
|
|
3233
3439
|
const CANONICAL_HOSTS_ENV_BLOCK = `
|
|
3234
|
-
#
|
|
3440
|
+
# Canonical host allowlist
|
|
3441
|
+
|
|
3442
|
+
CANONICAL_HOSTS=
|
|
3443
|
+
|
|
3235
3444
|
# Comma-separated list of the hostnames this deployment legitimately answers on.
|
|
3236
3445
|
# Normalize to lowercase when you parse it.
|
|
3237
3446
|
#
|
|
@@ -3249,7 +3458,6 @@ const CANONICAL_HOSTS_ENV_BLOCK = `
|
|
|
3249
3458
|
# NODE_ENV !== "production" so preview deployments and localhost keep working.
|
|
3250
3459
|
#
|
|
3251
3460
|
# Copy-paste recipe + the isKnownHost() helper: [[z2w-magic-link-auth]] §0 rule 2b.
|
|
3252
|
-
CANONICAL_HOSTS=
|
|
3253
3461
|
`;
|
|
3254
3462
|
/**
|
|
3255
3463
|
* Merge the email SDK deps into an already-substituted package.json string.
|
|
@@ -3345,6 +3553,15 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
3345
3553
|
path: "test/form-standards.test.ts",
|
|
3346
3554
|
content: sub(FORM_STANDARDS_TEST_TEMPLATE, inputs, opts, spec),
|
|
3347
3555
|
},
|
|
3556
|
+
// UNCONDITIONAL, unlike every other conditional standard here — see the note
|
|
3557
|
+
// above CSV_EXPORT_TEMPLATE. "This app will export CSV" is not knowable at
|
|
3558
|
+
// scaffold time, and all 12 repos that failed the 2026-08-15 survey grew their
|
|
3559
|
+
// export months after instantiation. A flag would have protected none of them.
|
|
3560
|
+
{ path: "lib/csv-export.ts", content: sub(CSV_EXPORT_TEMPLATE, inputs, opts, spec) },
|
|
3561
|
+
{
|
|
3562
|
+
path: "test/csv-export.test.ts",
|
|
3563
|
+
content: sub(CSV_EXPORT_TEST_TEMPLATE, inputs, opts, spec),
|
|
3564
|
+
},
|
|
3348
3565
|
...(hasObservability
|
|
3349
3566
|
? [
|
|
3350
3567
|
{
|
|
@@ -224,21 +224,24 @@ dist
|
|
|
224
224
|
`;
|
|
225
225
|
function buildEnvExample(usesNeon, sendsEmail) {
|
|
226
226
|
const dbLine = usesNeon
|
|
227
|
-
?
|
|
228
|
-
|
|
229
|
-
DATABASE_URL
|
|
227
|
+
? `DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
|
|
228
|
+
|
|
229
|
+
# DATABASE_URL — required. Per [[neon-postgres]], use the POOLED URL and keep
|
|
230
|
+
# /health DB-free so the compute scales to zero.
|
|
230
231
|
`
|
|
231
|
-
: `#
|
|
232
|
+
: `# DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
|
|
233
|
+
|
|
234
|
+
# DATABASE_URL — only if this service uses a database. For Neon Postgres, use
|
|
232
235
|
# the pooled connection string per [[neon-postgres]].
|
|
233
|
-
# DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
|
|
234
236
|
`;
|
|
235
237
|
return `# {{slug}} — example environment variables.
|
|
236
238
|
# Copy to \`.env\` (gitignored) and fill in real values. Do NOT commit \`.env\`.
|
|
237
239
|
|
|
238
|
-
# Port the service listens on. Cloud Run overrides this at runtime; 8080 is the
|
|
239
|
-
# Cloud Run default and a sensible local default.
|
|
240
240
|
PORT=8080
|
|
241
241
|
|
|
242
|
+
# PORT — Cloud Run overrides this at runtime; 8080 is the Cloud Run default and
|
|
243
|
+
# a sensible local default.
|
|
244
|
+
|
|
242
245
|
${dbLine}${sendsEmail ? EMAIL_ENV_BLOCK : ""}`;
|
|
243
246
|
}
|
|
244
247
|
const DRIZZLE_CONFIG_TEMPLATE = `import { defineConfig } from "drizzle-kit";
|
|
@@ -111,9 +111,10 @@ def test_health_returns_ok(client: TestClient) -> None:
|
|
|
111
111
|
const ENV_EXAMPLE_TEMPLATE = `# {{slug}} — example environment variables.
|
|
112
112
|
# Copy to \`.env\` and fill in real values. Do NOT commit \`.env\`.
|
|
113
113
|
|
|
114
|
-
# Database URL (only if db_strategy is non-none). For Neon Postgres, use the
|
|
115
|
-
# pooled connection string per [[neon-postgres]].
|
|
116
114
|
# DATABASE_URL=postgresql://user:pass@host/db
|
|
115
|
+
|
|
116
|
+
# DATABASE_URL — only if db_strategy is non-none. For Neon Postgres, use the
|
|
117
|
+
# pooled connection string per [[neon-postgres]].
|
|
117
118
|
`;
|
|
118
119
|
export function scaffoldPythonService(inputs, opts) {
|
|
119
120
|
const spec = resolveBrandSpec(inputs);
|
package/dist/standards.d.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import type { ProjectType, ScaffoldInputs } from "./index.js";
|
|
2
2
|
import { type SubstitutionOptions } from "./substitute.js";
|
|
3
3
|
export type StandardKey = "skill-vault" | "portable-stack" | "fathom" | "uptime-kuma" | "sentry" | "service-hosting" | "neon-careful" | "temp-files" | "agent-coordination" | "seo-baseline" | "email-service" | "moderation" | "card-path-bot-protection" | "text-size" | "test-count";
|
|
4
|
-
export type StandardDecisionState = "inserted-inline" | "skipped-not-applicable"
|
|
4
|
+
export type StandardDecisionState = "inserted-inline" | "skipped-not-applicable"
|
|
5
|
+
/**
|
|
6
|
+
* Applicable, rendered — and then removed again, because the audience gate
|
|
7
|
+
* dropped the whole `## ` section it lives in for `audience: "external"`.
|
|
8
|
+
*
|
|
9
|
+
* 🔴 **A third state, rather than leaving it `inserted-inline`, because the
|
|
10
|
+
* two-state version made a consumer's UI tell a customer something false.**
|
|
11
|
+
* `resolveStandards()` is a pure function that runs BEFORE the gate, so its
|
|
12
|
+
* verdict is "this standard applies and was rendered into the body" — true
|
|
13
|
+
* when written and still true. The gate then removes the section holding it.
|
|
14
|
+
* Neither half is individually wrong, which is exactly why no unit test
|
|
15
|
+
* caught it: `project-creator`'s preview screen reported an outside customer
|
|
16
|
+
* *"Skill Vault awareness"* — a standard whose entire content is "there is a
|
|
17
|
+
* private Z2W skill library at this path" — for a `CLAUDE.md` that no longer
|
|
18
|
+
* mentions it (filed 2026-08-19).
|
|
19
|
+
*
|
|
20
|
+
* Set by the writer from the gate's ACTUAL `dropped` list, never recomputed
|
|
21
|
+
* from the audience — a second derivation of the same fact is a second thing
|
|
22
|
+
* to drift.
|
|
23
|
+
*/
|
|
24
|
+
| "removed-by-audience-gate";
|
|
5
25
|
export interface StandardDecision {
|
|
6
26
|
key: StandardKey;
|
|
7
27
|
title: string;
|
|
8
28
|
state: StandardDecisionState;
|
|
9
29
|
/** Why the conditional matched (or didn't). */
|
|
10
30
|
reason: string;
|
|
31
|
+
/**
|
|
32
|
+
* For `removed-by-audience-gate` only: the `## ` heading the gate dropped
|
|
33
|
+
* that took this standard's text with it. Named rather than implied, so a
|
|
34
|
+
* consumer can say *which* section went and does not have to know the
|
|
35
|
+
* standards→section mapping to render an honest log.
|
|
36
|
+
*/
|
|
37
|
+
removedFromSection?: string;
|
|
11
38
|
}
|
|
12
39
|
export interface ResolveStandardsOptions extends SubstitutionOptions {
|
|
13
40
|
/**
|
package/dist/summary.js
CHANGED
|
@@ -61,8 +61,21 @@ function installCommandFor(projectType) {
|
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* True iff the standard APPLIED to this project — which is the question the
|
|
66
|
+
* next-actions checklist is asking, and it is NOT the same question as "is its
|
|
67
|
+
* prose in the emitted CLAUDE.md".
|
|
68
|
+
*
|
|
69
|
+
* 🔴 `removed-by-audience-gate` counts as applied, deliberately. The gate drops
|
|
70
|
+
* DOCTRINE from `CLAUDE.md`; it does not touch the emitted CODE. An external
|
|
71
|
+
* Fathom-enabled scaffold still ships the Fathom wiring, so the customer still
|
|
72
|
+
* has to create a Fathom site and set `NEXT_PUBLIC_FATHOM_SITE_ID` — dropping
|
|
73
|
+
* that next-action because the explanatory section went would hand them an app
|
|
74
|
+
* with a dangling env var and no instruction anywhere to fill it.
|
|
75
|
+
*/
|
|
64
76
|
function isDecisionInserted(decisions, key) {
|
|
65
|
-
return decisions.some((d) => d.key === key &&
|
|
77
|
+
return decisions.some((d) => d.key === key &&
|
|
78
|
+
(d.state === "inserted-inline" || d.state === "removed-by-audience-gate"));
|
|
66
79
|
}
|
|
67
80
|
function buildNextActions(inputs, result, repoAutoCreated) {
|
|
68
81
|
const actions = [];
|
|
@@ -152,6 +165,30 @@ function renderInsertedSection(chalk, result) {
|
|
|
152
165
|
}
|
|
153
166
|
return lines.join("\n");
|
|
154
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Standards that applied and were then removed with their host section by the
|
|
170
|
+
* external audience gate.
|
|
171
|
+
*
|
|
172
|
+
* Rendered as its own group rather than folded into either neighbour: they are
|
|
173
|
+
* not "inserted" (the text is not in the file) and they are not "skipped" (they
|
|
174
|
+
* DID apply, and their next-actions still stand). Collapsing them into either
|
|
175
|
+
* one is the false claim this section exists to stop — silence would be the
|
|
176
|
+
* same bug in the other direction, so the group prints whenever it is non-empty.
|
|
177
|
+
*/
|
|
178
|
+
function renderGatedSection(chalk, result) {
|
|
179
|
+
const gated = result.decisions.filter((d) => d.state === "removed-by-audience-gate");
|
|
180
|
+
if (gated.length === 0)
|
|
181
|
+
return null;
|
|
182
|
+
const heading = chalk.hex(Z2W_GREEN).bold;
|
|
183
|
+
const lines = [heading("Standards applied but NOT written to CLAUDE.md:")];
|
|
184
|
+
lines.push(` audience="external" drops the section(s) these live in, so the emitted CLAUDE.md does not describe them.`);
|
|
185
|
+
lines.push(` The emitted CODE is unaffected — the next actions below still apply.`);
|
|
186
|
+
for (const d of gated) {
|
|
187
|
+
const from = d.removedFromSection ? ` (was in \`## ${d.removedFromSection}\`)` : "";
|
|
188
|
+
lines.push(` - ${d.title}${from}`);
|
|
189
|
+
}
|
|
190
|
+
return lines.join("\n");
|
|
191
|
+
}
|
|
155
192
|
function renderSkippedSection(chalk, result) {
|
|
156
193
|
const heading = chalk.hex(Z2W_GREEN).bold;
|
|
157
194
|
const skipped = result.decisions.filter((d) => d.state === "skipped-not-applicable");
|
|
@@ -229,8 +266,14 @@ export function renderSummary(inputs, result, opts = {}) {
|
|
|
229
266
|
const sections = [
|
|
230
267
|
renderBanner(chalk, inputs, result),
|
|
231
268
|
renderInsertedSection(chalk, result),
|
|
232
|
-
renderSkippedSection(chalk, result),
|
|
233
269
|
];
|
|
270
|
+
// Between "inserted" and "skipped", because that is where a reader scanning
|
|
271
|
+
// for "what happened to standard X" looks — and the whole point of the group
|
|
272
|
+
// is that it is neither of its neighbours.
|
|
273
|
+
const gated = renderGatedSection(chalk, result);
|
|
274
|
+
if (gated !== null)
|
|
275
|
+
sections.push(gated);
|
|
276
|
+
sections.push(renderSkippedSection(chalk, result));
|
|
234
277
|
const promotions = renderPromotionsSection(chalk, result);
|
|
235
278
|
if (promotions !== null)
|
|
236
279
|
sections.push(promotions);
|
package/dist/writer.d.ts
CHANGED
|
@@ -83,6 +83,20 @@ export interface AudienceGateReport {
|
|
|
83
83
|
readonly heading: string;
|
|
84
84
|
readonly line: number;
|
|
85
85
|
}[];
|
|
86
|
+
/**
|
|
87
|
+
* Surviving lines that INSTRUCT the reader into a private Z2W resource — a
|
|
88
|
+
* worse class than a dangling reference, because the reader is being told to
|
|
89
|
+
* go do something in a library they cannot open. See
|
|
90
|
+
* `AudienceGateResult.privateReferences` in src/audience.ts for the full note.
|
|
91
|
+
*
|
|
92
|
+
* Reported, never auto-edited: the sentence lives inside the canonical AGENTS
|
|
93
|
+
* body, and the durable fix is upstream in `cursor-project-templates`.
|
|
94
|
+
*/
|
|
95
|
+
readonly privateReferences: readonly {
|
|
96
|
+
readonly resource: string;
|
|
97
|
+
readonly line: number;
|
|
98
|
+
readonly text: string;
|
|
99
|
+
}[];
|
|
86
100
|
}
|
|
87
101
|
export declare class WriterError extends Error {
|
|
88
102
|
constructor(message: string);
|
package/dist/writer.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { promises as fs } from "node:fs";
|
|
24
24
|
import * as path from "node:path";
|
|
25
25
|
import fsExtra from "fs-extra";
|
|
26
|
-
import { EXTERNAL_DROPPED_SECTIONS, gateSectionsForAudience, resolveAudience, stripVaultPointers, } from "./audience.js";
|
|
26
|
+
import { applyGateToDecisions, classifyUnfoundSections, EXTERNAL_DROPPED_SECTIONS, GATE_MIN_TEMPLATES_VERSION, gateSectionsForAudience, resolveAudience, stripVaultPointers, } from "./audience.js";
|
|
27
27
|
import { AGENT_COORDINATION_BLOCK_MARKER, AGENTS_BODY_MARKER, STANDARDS_BLOCK_MARKER, } from "./scaffolders/common.js";
|
|
28
28
|
import { buildProSeoExtension, proSeoApplies, } from "./scaffolders/pro-seo-extension.js";
|
|
29
29
|
import { scaffoldByType } from "./scaffolders/index.js";
|
|
@@ -250,12 +250,37 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
250
250
|
// no-silent-zero shape this repo has now hit three times. If a heading is
|
|
251
251
|
// renamed upstream the section is still being emitted, and the customer
|
|
252
252
|
// scaffold ships the doctrine while every signal reports success.
|
|
253
|
+
//
|
|
254
|
+
// 🔴 But "absent" has TWO causes, and until 2026-08-20 this message named
|
|
255
|
+
// only one of them. A version-PINNED Templates consumer (`project-creator`)
|
|
256
|
+
// hits the other one every time: the heading did not exist yet. Classify
|
|
257
|
+
// against the resolved Templates version so the error names the real cause
|
|
258
|
+
// — a message that confidently states the wrong cause is worse than a vague
|
|
259
|
+
// one, because it is actionable in the wrong direction.
|
|
260
|
+
const unfound = classifyUnfoundSections(gate.notFound, frameworkVersion);
|
|
261
|
+
const skew = unfound.filter((u) => u.cause === "version-skew");
|
|
262
|
+
const unexplained = unfound.filter((u) => u.cause === "unexplained");
|
|
263
|
+
const detail = [];
|
|
264
|
+
if (skew.length > 0) {
|
|
265
|
+
detail.push(`VERSION SKEW — the Templates body in use is AGENTS v${frameworkVersion}, ` +
|
|
266
|
+
`which predates ${skew.length === 1 ? "this section" : "these sections"}: ` +
|
|
267
|
+
`${skew.map((u) => `"${u.heading}" (since v${u.sinceTemplatesVersion})`).join(", ")}. ` +
|
|
268
|
+
`Nothing is leaking — the section is not in the document to leak — but this ` +
|
|
269
|
+
`gate has never been verified against a body that old, so it refuses rather ` +
|
|
270
|
+
`than guesses. Fix: point the scaffold at Templates v${GATE_MIN_TEMPLATES_VERSION} ` +
|
|
271
|
+
`or newer (upgrade --templates-path, or republish the pinned @zero2webmaster/templates package).`);
|
|
272
|
+
}
|
|
273
|
+
if (unexplained.length > 0) {
|
|
274
|
+
detail.push(`UNEXPLAINED — ${unexplained.map((u) => `"${u.heading}"`).join(", ")} ` +
|
|
275
|
+
`should be present at AGENTS v${frameworkVersion} and is not, so the heading ` +
|
|
276
|
+
`was renamed upstream or the body changed shape. The section is probably still ` +
|
|
277
|
+
`being emitted under a different name. Fix: update EXTERNAL_DROPPED_SECTIONS ` +
|
|
278
|
+
`in src/audience.ts to match.`);
|
|
279
|
+
}
|
|
253
280
|
throw new WriterError(`Audience gate could not find ${gate.notFound.length} of ` +
|
|
254
281
|
`${EXTERNAL_DROPPED_SECTIONS.length} section(s) it must drop for ` +
|
|
255
|
-
`audience="external"
|
|
256
|
-
`
|
|
257
|
-
`A heading was probably renamed upstream in Templates — update ` +
|
|
258
|
-
`EXTERNAL_DROPPED_SECTIONS in src/audience.ts to match.`);
|
|
282
|
+
`audience="external". Refusing to emit a customer scaffold that may ` +
|
|
283
|
+
`still contain them. ${detail.join(" ")}`);
|
|
259
284
|
}
|
|
260
285
|
if (audience === "external" && gate.danglingReferences.length > 0) {
|
|
261
286
|
// Report, never auto-edit — rewriting a sentence inside the canonical
|
|
@@ -273,6 +298,21 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
273
298
|
` Lines: ${gate.danglingReferences.map((d) => d.line).join(", ")} of ` +
|
|
274
299
|
`the emitted CLAUDE.md.\n`);
|
|
275
300
|
}
|
|
301
|
+
if (audience === "external" && gate.privateReferences.length > 0) {
|
|
302
|
+
// Louder than the dangling-reference warning above, and separate from it,
|
|
303
|
+
// because it is a different failure: the customer is being INSTRUCTED into
|
|
304
|
+
// a library they cannot open, not merely pointed at a missing section.
|
|
305
|
+
output.write(`\n🔴 audience="external": ${gate.privateReferences.length} surviving line(s) ` +
|
|
306
|
+
`instruct the reader to use a PRIVATE Z2W resource ` +
|
|
307
|
+
`(${[...new Set(gate.privateReferences.map((p) => p.resource))].join(", ")}).\n` +
|
|
308
|
+
` This is a leak, not a dangling reference — but the text is inside the ` +
|
|
309
|
+
`canonical framework body,\n` +
|
|
310
|
+
` which this CLI does not edit. The durable fix is upstream in ` +
|
|
311
|
+
`cursor-project-templates.\n` +
|
|
312
|
+
gate.privateReferences
|
|
313
|
+
.map((p) => ` line ${p.line}: ${p.text.slice(0, 120)}\n`)
|
|
314
|
+
.join(""));
|
|
315
|
+
}
|
|
276
316
|
// Capture the gate's findings for the RETURN VALUE as well as the terminal —
|
|
277
317
|
// see the `audienceGate` docblock. Built here rather than at the return site
|
|
278
318
|
// so it cannot drift from the `gate` that was actually applied.
|
|
@@ -281,8 +321,14 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
281
321
|
dropped: gate.dropped,
|
|
282
322
|
bytesDropped: gate.bytesDropped,
|
|
283
323
|
danglingReferences: gate.danglingReferences,
|
|
324
|
+
privateReferences: gate.privateReferences,
|
|
284
325
|
}
|
|
285
326
|
: undefined;
|
|
327
|
+
// Restate the decision log against what the gate REMOVED. Built here, from
|
|
328
|
+
// the same `gate` object that produced the emitted bytes, so the log and the
|
|
329
|
+
// file cannot disagree; used at BOTH return sites below (the dry-run branch
|
|
330
|
+
// is the one `previewScaffold()` takes, which is the consumer that hit this).
|
|
331
|
+
const gatedDecisions = applyGateToDecisions(resolution.decisions, gate.dropped);
|
|
286
332
|
claudeContent = stripVaultPointers(gate.content, audience);
|
|
287
333
|
checkNoUnfilledMarkers(claudeContent, "CLAUDE.md");
|
|
288
334
|
files[claudeIdx] = { path: claudeFile.path, content: claudeContent };
|
|
@@ -348,7 +394,7 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
348
394
|
output.write(`\n# End dry run — ${files.length} files, CLAUDE.md is ${claudeContent.length} bytes.\n`);
|
|
349
395
|
return {
|
|
350
396
|
filesWritten: files,
|
|
351
|
-
decisions:
|
|
397
|
+
decisions: gatedDecisions,
|
|
352
398
|
promotions,
|
|
353
399
|
targetPath: resolvedTarget,
|
|
354
400
|
dryRun: true,
|
|
@@ -370,7 +416,7 @@ export async function writeScaffold(inputs, targetPath, opts = {}) {
|
|
|
370
416
|
}
|
|
371
417
|
return {
|
|
372
418
|
filesWritten: files,
|
|
373
|
-
decisions:
|
|
419
|
+
decisions: gatedDecisions,
|
|
374
420
|
promotions,
|
|
375
421
|
targetPath: resolvedTarget,
|
|
376
422
|
dryRun: false,
|
package/package.json
CHANGED
|
@@ -251,12 +251,42 @@ function cleanSlug(raw) {
|
|
|
251
251
|
* But every project that adopted the section first wrote something else, and a parser
|
|
252
252
|
* that only accepts the canonical form reports ZERO matches — which looks exactly like
|
|
253
253
|
* "already in sync" (see `zeroEdges` handling in main(); 2026-07-25). So we also accept
|
|
254
|
-
* the
|
|
254
|
+
* the variants seen in the wild, while keeping the canonical form primary:
|
|
255
255
|
* - `file-server` — campaign cover images (bullet under a **Consumes** heading)
|
|
256
256
|
* - **consumes:** `a` (why), `b` (why), `c` (inline comma list)
|
|
257
|
+
* | `file-server` (85, Live) | uploads | note | (MARKDOWN TABLE row — 2026-08-17)
|
|
258
|
+
*
|
|
259
|
+
* TABLES (2026-08-17, filed by `z2w-agent-coordination`). Four of the six zero-edge
|
|
260
|
+
* sections on the live bulletin — `forms-engine`, `los-osititos`, `marketing-engine`,
|
|
261
|
+
* `support-desk` — put their edges in a markdown table, and every bullet branch below
|
|
262
|
+
* keys on `^\s*[-*]`, so a `|`-row was invisible and the ENTIRE table was skipped. That
|
|
263
|
+
* is ~20 real edges on `file-server`, `contact-registry`, `z2w-ai-engine` and `org-hq`
|
|
264
|
+
* that the registry never recorded, reported as "0 edges" rather than "unreadable".
|
|
265
|
+
*
|
|
266
|
+
* The table branch is deliberately no less conservative than the prose-bullet one: a
|
|
267
|
+
* first-column target is accepted only when it is a real registry slug or carries an
|
|
268
|
+
* explicit `:qualifier`. Two extra guards a bullet does not need:
|
|
269
|
+
* · DIRECTION. `**Consumed by:**` and a `| Direction |` column both mean PROVIDES, and
|
|
270
|
+
* provides is DERIVED from reverse `consumes`, never stored. `forms-engine` has a
|
|
271
|
+
* `**Consumes:**` table immediately followed by a `**Consumed by:**` table, so a
|
|
272
|
+
* parser that ignored direction would have written `site-control` and
|
|
273
|
+
* `contest-management` in backwards — worse than the miss it was fixing.
|
|
274
|
+
* · STRIKETHROUGH. `~~Airtable~~ | ~~consumes~~` in `los-osititos` is a RETIRED edge
|
|
275
|
+
* the agent struck out rather than deleted. A struck row is skipped whole.
|
|
257
276
|
*/
|
|
258
277
|
export function parseSection(section, knownSlugs = new Set()) {
|
|
259
|
-
const result = {
|
|
278
|
+
const result = {
|
|
279
|
+
liveStatus: null, statusDeclared: false, statusQualifier: null, asOf: null,
|
|
280
|
+
consumes: [],
|
|
281
|
+
// TRUE only when a LABELLED consumes line resolved to the §8.10 empty marker
|
|
282
|
+
// (`- consumes: (none — no Z2W edges)`). This is the "genuinely empty" signal that
|
|
283
|
+
// lets the caller stop reporting a deliberate zero as a parse failure — `main()`
|
|
284
|
+
// used to test the WHOLE SECTION for `/\(none/i`, which is true of any parenthetical
|
|
285
|
+
// beginning "none" anywhere in it, including one under **Provides**. That is the
|
|
286
|
+
// silent-zero rule failing one level up: it could neither see a deliberate empty
|
|
287
|
+
// CONSUMES declaration nor avoid being fooled by an unrelated one. [[zero-is-not-a-pass]]
|
|
288
|
+
declaredNoConsumes: false,
|
|
289
|
+
};
|
|
260
290
|
|
|
261
291
|
// The label is matched on its own, SEPARATELY from the value, so the caller can tell
|
|
262
292
|
// "declared but unreadable" (a defect) from "never declared" (a young project, and
|
|
@@ -304,9 +334,25 @@ export function parseSection(section, knownSlugs = new Set()) {
|
|
|
304
334
|
// Track which half of the section we're in, so a bare-slug bullet under **Provides**
|
|
305
335
|
// is never mistaken for a consumes edge (provides is DERIVED, never stored).
|
|
306
336
|
let inConsumes = false;
|
|
337
|
+
// Column index of a `| Direction |` header, when the current table has one. It OVERRIDES
|
|
338
|
+
// the heading state per row, because `los-osititos` puts both directions in ONE table.
|
|
339
|
+
let directionCol = -1;
|
|
340
|
+
// Direction inferred from a table's own header when no heading preceded it — see
|
|
341
|
+
// TABLE_CONSUMES_HEADERS. `marketing-engine` has no `**Consumes**` heading at all.
|
|
342
|
+
let tableConsumes = null;
|
|
343
|
+
|
|
307
344
|
for (const line of section.split("\n")) {
|
|
308
|
-
|
|
309
|
-
|
|
345
|
+
const heading = line.replace(/^[-*]\s*/, "");
|
|
346
|
+
// PROVIDES-side patterns are tested FIRST: `Consumed by` must not fall through to the
|
|
347
|
+
// consumes test, and `Consumes?\b` does not match it (no word boundary before `d`)
|
|
348
|
+
// only by luck — relying on that would be a trap for whoever loosens this next.
|
|
349
|
+
if (/^\s*\*{0,2}(?:We\s+)?(?:Consumed\s+by|Provides?|Provided\s+to|Used\s+by)\b/i.test(heading)) {
|
|
350
|
+
inConsumes = false; directionCol = -1; tableConsumes = null;
|
|
351
|
+
} else if (/^\s*\*{0,2}(?:We\s+)?Consumes?\b/i.test(heading)) {
|
|
352
|
+
// `We CONSUME:` is `file-server`'s form — the leading pronoun is why their section
|
|
353
|
+
// read zero, and `Consumes?` (optional s) is why the imperative "CONSUME" now lands.
|
|
354
|
+
inConsumes = true; directionCol = -1; tableConsumes = null;
|
|
355
|
+
}
|
|
310
356
|
|
|
311
357
|
// (a) canonical: `- consumes: slug — why` / (b) inline list: `- **consumes:** a, b, c`
|
|
312
358
|
const labelled = line.match(/^\s*[-*]\s*\*{0,2}consumes:?\*{0,2}:?\s*(.+)$/i);
|
|
@@ -314,6 +360,8 @@ export function parseSection(section, knownSlugs = new Set()) {
|
|
|
314
360
|
// Strip parentheticals BEFORE splitting: the per-edge "(why…)" notes contain
|
|
315
361
|
// commas of their own, and splitting first shreds every slug after the first.
|
|
316
362
|
// Also cut at "Later phases:" — those are aspirational, not current edges.
|
|
363
|
+
// The `(none…)` marker is read BEFORE that strip, since stripping erases it.
|
|
364
|
+
if (/^[`*_"'\s]*\((?:none|n\/a)\b/i.test(labelled[1])) result.declaredNoConsumes = true;
|
|
317
365
|
const body = labelled[1]
|
|
318
366
|
.replace(/\([^)]*\)/g, "")
|
|
319
367
|
.split(/\bLater phases?\b\s*:?/i)[0];
|
|
@@ -325,6 +373,40 @@ export function parseSection(section, knownSlugs = new Set()) {
|
|
|
325
373
|
continue;
|
|
326
374
|
}
|
|
327
375
|
|
|
376
|
+
// (d) MARKDOWN TABLE row. Same conservatism as the prose bullet in (c): the target is
|
|
377
|
+
// taken from the FIRST cell and accepted only if it is a known registry slug or
|
|
378
|
+
// carries a `:qualifier`, so a header cell ("Engine", "Depends on") and a non-Z2W
|
|
379
|
+
// vendor ("**Neon Postgres**", "**Murf AI**") both fall out on their own.
|
|
380
|
+
if (/^\s*\|/.test(line)) {
|
|
381
|
+
const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
382
|
+
// The `|---|:--:|` delimiter row carries no data and must not reset anything.
|
|
383
|
+
if (cells.every((c) => /^:?-{2,}:?$/.test(c) || c === "")) continue;
|
|
384
|
+
// A struck-through row is an edge the agent RETIRED in place rather than deleting.
|
|
385
|
+
if (cells.some((c) => /^~~.*~~$/.test(c))) continue;
|
|
386
|
+
|
|
387
|
+
const headerDir = cells.findIndex((c) => /^\**\s*directions?\s*\**$/i.test(c));
|
|
388
|
+
if (headerDir !== -1) { directionCol = headerDir; tableConsumes = null; continue; }
|
|
389
|
+
// A header row naming its own direction, for tables that follow no heading.
|
|
390
|
+
// Deliberately a CLOSED list, and deliberately not "Engine": `forms-engine` heads
|
|
391
|
+
// BOTH its `Consumes` and its `Consumed by` table with `| Engine |`, so that word
|
|
392
|
+
// carries no direction and guessing from it would invert half the edges.
|
|
393
|
+
if (/^\**\s*(?:depends\s+(?:on|upon)|consumes|dependenc(?:y|ies))\s*\**$/i.test(cells[0])) {
|
|
394
|
+
tableConsumes = true; continue;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const consumesHere = directionCol !== -1
|
|
398
|
+
? /^\**\s*consumes?\s*\**$/i.test(cells[directionCol] ?? "") // "consumed by" is NOT this
|
|
399
|
+
: (tableConsumes ?? inConsumes);
|
|
400
|
+
if (!consumesHere) continue;
|
|
401
|
+
|
|
402
|
+
const head = cells[0].split(/\s+[—–-]\s+/)[0].replace(/\([^)]*\)/g, "");
|
|
403
|
+
const slug = cleanSlug(head);
|
|
404
|
+
if (slug && (knownSlugs.has(slug.split(":")[0]) || slug.includes(":"))) {
|
|
405
|
+
result.consumes.push(slug);
|
|
406
|
+
}
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
|
|
328
410
|
// (c) prose bullet under the **Consumes** heading: "- `file-server` — why".
|
|
329
411
|
// CONSERVATIVE: an unlabelled bullet is inference, not a declaration, so accept it
|
|
330
412
|
// only when the target is a real registry slug or carries a `:qualifier` (a
|
|
@@ -539,6 +621,7 @@ async function main() {
|
|
|
539
621
|
let parsed = 0, skippedNoSection = 0, skippedUnknown = 0, changed = 0;
|
|
540
622
|
const plan = [];
|
|
541
623
|
const zeroEdges = [];
|
|
624
|
+
const declaredEmpty = []; // zero edges, DECLARED so via the §8.10 marker — legitimate
|
|
542
625
|
const unreadableStatus = []; // line present, value unreadable — a DEFECT
|
|
543
626
|
const noStatusLine = []; // no line at all — legitimate; skip and report
|
|
544
627
|
|
|
@@ -550,7 +633,7 @@ async function main() {
|
|
|
550
633
|
parsed++;
|
|
551
634
|
if (!known.has(slug)) { skippedUnknown++; console.warn(` ⚠ ${slug}: has ## Integrations but no registry row — skipped (never auto-inserted).`); continue; }
|
|
552
635
|
|
|
553
|
-
const { liveStatus, statusDeclared, statusQualifier, asOf, consumes } = parseSection(section, known);
|
|
636
|
+
const { liveStatus, statusDeclared, statusQualifier, asOf, consumes, declaredNoConsumes } = parseSection(section, known);
|
|
554
637
|
|
|
555
638
|
// NO SILENT ZERO, STATUS HALF (2026-08-02). The `zeroEdges` counter below has caught
|
|
556
639
|
// an inert EDGE pipeline since 2026-07-25; the STATUS field had no equivalent, so a
|
|
@@ -574,9 +657,22 @@ async function main() {
|
|
|
574
657
|
// declaration — either way it must NOT be reported the same as "already in sync."
|
|
575
658
|
// (2026-07-25: all 4 adopting projects wrote a non-canonical edge form, so the
|
|
576
659
|
// rollup printed "0 rows would change" for five days while the pipeline was inert.)
|
|
577
|
-
|
|
660
|
+
//
|
|
661
|
+
// "GENUINELY EMPTY" IS A DECLARATION, NOT A SUBSTRING (2026-08-17). The old test was
|
|
662
|
+
// `!/\(none/i.test(section)` — the whole section, so ANY parenthetical starting "none"
|
|
663
|
+
// suppressed the warning, including `- provides: (none yet)`, which says nothing about
|
|
664
|
+
// consumes. It could not do the job it was there for either: `kuma-watchdog` consumes
|
|
665
|
+
// only Uptime Kuma, Neon and Slack — no Z2W coupling BY DESIGN — and was reported as a
|
|
666
|
+
// parse failure every run, i.e. a false red under `--strict`. `declaredNoConsumes` is
|
|
667
|
+
// set only by a labelled CONSUMES line carrying the §8.10 empty marker, so the two
|
|
668
|
+
// cases the header's own NO SILENT ZERO rule conflates — "unreadable" and "deliberately
|
|
669
|
+
// empty" — are finally distinguishable. Absence is still never a value: a section that
|
|
670
|
+
// declares nothing at all remains a defect and still warns. [[zero-is-not-a-pass]]
|
|
671
|
+
if (consumes.length === 0 && !declaredNoConsumes) {
|
|
578
672
|
zeroEdges.push(slug);
|
|
579
|
-
console.warn(` ⚠ ${slug}: ## Integrations present but ZERO edges parsed — check the line form (expected \`- consumes: {slug} — {why}\`).`);
|
|
673
|
+
console.warn(` ⚠ ${slug}: ## Integrations present but ZERO edges parsed — check the line form (expected \`- consumes: {slug} — {why}\`, or \`- consumes: (none — no Z2W edges)\` if that is deliberate).`);
|
|
674
|
+
} else if (consumes.length === 0) {
|
|
675
|
+
declaredEmpty.push(slug);
|
|
580
676
|
}
|
|
581
677
|
|
|
582
678
|
const [current] = await sql`SELECT production_status, status_qualifier, consumes FROM projects WHERE slug = ${slug}`;
|
|
@@ -662,6 +758,10 @@ async function main() {
|
|
|
662
758
|
console.log(` ⚠ sections with ZERO edges parsed: ${zeroEdges.length} (${zeroEdges.join(", ")})`);
|
|
663
759
|
console.log(` A zero here is NOT "in sync" — it means the section's line form didn't match. Fix the bulletin or the parser.`);
|
|
664
760
|
}
|
|
761
|
+
// Printed unconditionally, at zero as well, for the same reason as the two below: this
|
|
762
|
+
// is the count of sections that were READ and found deliberately empty, and folding it
|
|
763
|
+
// into either "changed" or "zero edges" would re-create the ambiguity it resolves.
|
|
764
|
+
console.log(` ⓘ zero edges, DECLARED so (read, legitimate): ${declaredEmpty.length}${declaredEmpty.length ? ` (${declaredEmpty.join(", ")})` : ""}`);
|
|
665
765
|
// Report BOTH, always, even at zero — the count is the coverage number, and a silent
|
|
666
766
|
// absence is the thing this whole block exists to make impossible.
|
|
667
767
|
console.log(` ⚠ Live status declared but UNREADABLE: ${unreadableStatus.length}${unreadableStatus.length ? ` (${unreadableStatus.join(", ")})` : ""}`);
|