@zero2webmaster/starter-kit 0.22.0 → 0.24.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # z2w-starter-kit
2
2
 
3
- **Version:** 0.22.0 | **Framework:** 2.19.0
3
+ **Version:** 0.24.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,9 @@ The Claude Code skill at `~/.claude/skills/instantiate-z2w-project/SKILL.md` and
83
83
 
84
84
  ## Status
85
85
 
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.
86
+ - **v0.24.0 (current)** makes contrast a measured property of a PAIR rather than a taste call about a swatch. Every `nextjs` scaffold now emits `lib/a11y/contrast.ts` and `test/contrast.test.ts`, a table of **SURFACE x TEXT-ROLE x THRESHOLD** rows measured against the stylesheet the project actually ships — thirteen pairs across six surfaces, with `--brand-ink` measured four separate times because it is painted on four different backgrounds. The candidate came from `static-sites` and its lesson is one line: *contrast is per-surface, not per-palette* — a validator that checks each swatch against white passes cleanly while shipping unreadable text, because the swatch is rendered on the tint panel three components down. **Writing that check found two real defects in this scaffold's own CSS, both invisible to every brand preset.** The keyboard focus ring was painted in `--brand-primary`, which measures 2.03:1 on white in Z2W green and 1.40:1 in Z2W gold — so focusing a field made its boundary *less* visible than at rest, in Zero2Webmaster's and Save The Frogs' own colors. And `readableInkOn()` picked the better of near-black and white without checking that the winner cleared anything, which put a 4.41:1 glyph on any mid-tone brand fill. Fixed with a derived `--brand-focus` (same hue, darkened only as far as 3:1 requires) and an escalation to pure black, which provably clears 4.5:1 on every possible background. **Verified by running the scaffold's own vitest, plus four canaries that each reproduce a defect on demand** — including the one that matters most: an ink that stays green on white and fails at 4.06:1 on the code tint.
87
+ - **v0.23.0** makes every scaffolded web app defend its own head. `audit-engine` measured 26 reachable Z2W surfaces on 2026-08-20: **22 carried none of the five baseline security headers**, while `leaderboard` carried five of five — so this was a lift from a passing in-house implementation rather than a design exercise. Every `nextjs` scaffold now emits `lib/security-headers.mjs`, applied to every route by a new `async headers()` in **both** `next.config.mjs` variants, and `cf-pages` goes from two of five to five of five. **The CSP is assembled from the origins the scaffold actually loads**, each gated on the input that ships the feature: Fathom unconditionally, Turnstile in `script-src` *and* `frame-src` when the project takes cards (the widget is an iframe, so allowing only the script leaves an uncompletable card path), Sentry in `connect-src` alone when observability is on. **It ships enforcing rather than Report-Only** — a considered deviation from the retrofit-oriented rule, reasoned in the emitted comments, because a scaffold has no live traffic to break and a header that blocks nothing is just a note asking someone to finish later. Alongside it, `lib/json-ld.ts` closes the `JSON.stringify`-into-a-`<script>` sink: not because the scaffold's own JSON-LD was exploitable (it holds a brand name and an env URL) but because the Pro-SEO extension's *documented example* fed a post title — database content — straight into it, which is the exact stored XSS found live in `z2w-social`. **A scaffold's examples are copied more often than its code is read.** Verified on the artifact: real `next build`, all six headers `curl`-confirmed on a home page, a child page and an API route, and headless Chrome reporting zero CSP violations — with a positive control proving the detector fires.
88
+ - **v0.22.0** 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
89
  - **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
90
  - **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
91
  - **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.
@@ -130,4 +132,4 @@ Inquiries: kerry@zero2webmaster.com.
130
132
  ---
131
133
 
132
134
  *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.*
133
- *Version: 0.22.0 | Last Updated: 2026-08-20*
135
+ *Version: 0.24.0 | Last Updated: 2026-08-20*
@@ -166,9 +166,37 @@ const HEADERS_TEMPLATE = `# Cloudflare Pages headers for {{slug}}.
166
166
  # Production (live domain): no special header — sitemap + robots.txt govern.
167
167
  # Preview deploys (*.pages.dev): noindex.
168
168
 
169
+ # ── The five-header baseline ─────────────────────────────────────────────
170
+ # Measured by \`audit-engine\` on 2026-08-20: 22 of 26 reachable Z2W surfaces
171
+ # carried NONE of these. They are config-only and none of them can break
172
+ # rendering, so there is no reason for a new site to ship without them.
173
+ #
174
+ # X-Frame-Options is DENY here, not SAMEORIGIN. A brochure site has no reason
175
+ # to frame itself, and DENY is what pairs with \`frame-ancestors 'none'\` below
176
+ # — the two say the same thing to two generations of browser, and shipping one
177
+ # without the other is a silent downgrade on whichever half you dropped. If
178
+ # this site genuinely needs to be embedded, change BOTH.
179
+ #
180
+ # The CSP is ENFORCING rather than Report-Only, which is a deliberate
181
+ # deviation from [[web-security-headers]]. That skill's two-wave rule protects
182
+ # a LIVE app being retrofitted, where a wrong directive is an outage. This site
183
+ # has never been deployed and every origin below is one this scaffold actually
184
+ # emits: Fathom's script, and nothing else. \`'unsafe-inline'\` covers the inline
185
+ # <style> block and the inline JSON-LD block that index.html ships.
186
+ #
187
+ # 🔴 If you add an external script, font, style or beacon, the browser console
188
+ # names the directive that blocked it — add the origin here rather than
189
+ # deleting the policy. To debug a stubborn one, temporarily rename the header
190
+ # to Content-Security-Policy-Report-Only, reproduce, read the console, and put
191
+ # it back. Verify a deploy at https://securityheaders.com.
192
+
169
193
  /*
170
- X-Frame-Options: SAMEORIGIN
194
+ Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
195
+ X-Content-Type-Options: nosniff
196
+ X-Frame-Options: DENY
171
197
  Referrer-Policy: strict-origin-when-cross-origin
198
+ Permissions-Policy: camera=(), microphone=(), geolocation=(), interest-cohort=()
199
+ Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.usefathom.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' https://cdn.usefathom.com; form-action 'self'; frame-ancestors 'none'; base-uri 'self'; object-src 'none'
172
200
 
173
201
  https://*.pages.dev/*
174
202
  X-Robots-Tag: noindex, nofollow
@@ -33,7 +33,34 @@ export declare const INK_LIGHT = "#ffffff";
33
33
  * Deciding it at scaffold time from the actual hex is deterministic, testable,
34
34
  * and costs the emitted project nothing at runtime.
35
35
  */
36
- export declare function readableInkOn(background: string): string;
36
+ export declare function readableInkOn(background: string, minRatio?: number): string;
37
+ /** Pure black. Only reached when the softened {@link INK_DARK} falls short. */
38
+ export declare const PURE_BLACK = "#000000";
39
+ /** Expand `#rgb` to a lowercase `#rrggbb`, so emitted CSS is comparable. */
40
+ export declare function normalizeHex(hex: string): string;
41
+ /**
42
+ * The nearest shade or tint of `color` that clears `minRatio` against
43
+ * `surface`, or `color` itself when it already does.
44
+ *
45
+ * WHY THIS EXISTS, and it is a real defect this repo shipped rather than a
46
+ * hypothetical. The emitted `globals.css` painted the input FOCUS RING in
47
+ * `var(--brand-primary)`, on a white page. Measured against white: Z2W green
48
+ * `#82C92B` is 2.03:1, STF green `#72af43` is 2.65:1, Z2W gold `#FFD700` is
49
+ * 1.40:1 — all below the 3:1 that WCAG 2.1 SC 1.4.11 requires of the visual
50
+ * information that identifies a component's STATE. So every scaffold built in
51
+ * Zero2Webmaster's or Save The Frogs' own brand shipped a focus ring the
52
+ * keyboard user can barely find, and focusing a field made its boundary LESS
53
+ * visible than at rest (the resting `--field-border` is a measured 3.40:1).
54
+ *
55
+ * A brand color is the author's to choose, so the fix is not to override it —
56
+ * it is to derive a same-hue variant for the one role that has a threshold, and
57
+ * to leave `--brand-primary` alone for decorative fills.
58
+ *
59
+ * Steps in 1/200ths and takes whichever direction reaches the bar first, so the
60
+ * result is the smallest visible departure from the author's color. Ties go to
61
+ * the shade, which keeps more chroma than a tint does.
62
+ */
63
+ export declare function accessibleOn(color: string, surface: string, minRatio: number): string;
37
64
  export declare function buildClaudeMd(inputs: ScaffoldInputs, opts: ScaffolderOptions | undefined, spec: BrandPresetSpec, perTypeNarrative: string): ScaffoldFile;
38
65
  export declare function commonReadme(inputs: ScaffoldInputs, opts: ScaffolderOptions | undefined, spec: BrandPresetSpec): ScaffoldFile;
39
66
  export declare function commonRoadmap(inputs: ScaffoldInputs, opts: ScaffolderOptions | undefined, spec: BrandPresetSpec): ScaffoldFile;
@@ -64,10 +64,97 @@ export const INK_LIGHT = "#ffffff";
64
64
  * Deciding it at scaffold time from the actual hex is deterministic, testable,
65
65
  * and costs the emitted project nothing at runtime.
66
66
  */
67
- export function readableInkOn(background) {
68
- return contrastRatio(background, INK_DARK) >= contrastRatio(background, INK_LIGHT)
67
+ export function readableInkOn(background, minRatio = 4.5) {
68
+ const preferred = contrastRatio(background, INK_DARK) >= contrastRatio(background, INK_LIGHT)
69
69
  ? INK_DARK
70
70
  : INK_LIGHT;
71
+ if (contrastRatio(background, preferred) >= minRatio)
72
+ return preferred;
73
+ // Neither the soft near-black nor white clears the bar, which means the fill
74
+ // is MID-TONE — the case every current brand preset happens to avoid, so no
75
+ // test that only exercises the presets can see it. `#808080` scores 4.41:1
76
+ // against `#1a1a1a`, i.e. a 13px glyph that fails AA while looking perfectly
77
+ // deliberate. Escalate to PURE black, which buys back the ~0.9:1 that the
78
+ // softened near-black gives away for aesthetics.
79
+ //
80
+ // This always succeeds, and provably so: max(black, white) is minimised at
81
+ // the luminance where the two ratios cross, and there it is still 4.58:1. So
82
+ // the returned ink clears 4.5:1 against EVERY possible background.
83
+ return contrastRatio(background, PURE_BLACK) >= contrastRatio(background, INK_LIGHT)
84
+ ? PURE_BLACK
85
+ : INK_LIGHT;
86
+ }
87
+ /** Pure black. Only reached when the softened {@link INK_DARK} falls short. */
88
+ export const PURE_BLACK = "#000000";
89
+ /** Expand `#rgb` to a lowercase `#rrggbb`, so emitted CSS is comparable. */
90
+ export function normalizeHex(hex) {
91
+ const h = hex.trim().replace(/^#/, "").toLowerCase();
92
+ return "#" + (h.length === 3 ? h.split("").map((c) => c + c).join("") : h);
93
+ }
94
+ function channels(hex) {
95
+ const h = normalizeHex(hex).slice(1);
96
+ return [
97
+ parseInt(h.slice(0, 2), 16),
98
+ parseInt(h.slice(2, 4), 16),
99
+ parseInt(h.slice(4, 6), 16),
100
+ ];
101
+ }
102
+ /**
103
+ * Mix `hex` toward pure black (`toward = 0`) or pure white (`toward = 255`) by
104
+ * `amount` in 0..1. Both directions preserve HUE — a shade and a tint of the
105
+ * author's color, never a different color.
106
+ */
107
+ function mixToward(hex, toward, amount) {
108
+ const out = channels(hex).map((c) => Math.round(c + (toward - c) * amount));
109
+ return "#" + out.map((c) => c.toString(16).padStart(2, "0")).join("");
110
+ }
111
+ /**
112
+ * The nearest shade or tint of `color` that clears `minRatio` against
113
+ * `surface`, or `color` itself when it already does.
114
+ *
115
+ * WHY THIS EXISTS, and it is a real defect this repo shipped rather than a
116
+ * hypothetical. The emitted `globals.css` painted the input FOCUS RING in
117
+ * `var(--brand-primary)`, on a white page. Measured against white: Z2W green
118
+ * `#82C92B` is 2.03:1, STF green `#72af43` is 2.65:1, Z2W gold `#FFD700` is
119
+ * 1.40:1 — all below the 3:1 that WCAG 2.1 SC 1.4.11 requires of the visual
120
+ * information that identifies a component's STATE. So every scaffold built in
121
+ * Zero2Webmaster's or Save The Frogs' own brand shipped a focus ring the
122
+ * keyboard user can barely find, and focusing a field made its boundary LESS
123
+ * visible than at rest (the resting `--field-border` is a measured 3.40:1).
124
+ *
125
+ * A brand color is the author's to choose, so the fix is not to override it —
126
+ * it is to derive a same-hue variant for the one role that has a threshold, and
127
+ * to leave `--brand-primary` alone for decorative fills.
128
+ *
129
+ * Steps in 1/200ths and takes whichever direction reaches the bar first, so the
130
+ * result is the smallest visible departure from the author's color. Ties go to
131
+ * the shade, which keeps more chroma than a tint does.
132
+ */
133
+ export function accessibleOn(color, surface, minRatio) {
134
+ if (contrastRatio(color, surface) >= minRatio)
135
+ return normalizeHex(color);
136
+ const STEPS = 200;
137
+ let best = normalizeHex(color);
138
+ let bestRatio = contrastRatio(color, surface);
139
+ for (let i = 1; i <= STEPS; i++) {
140
+ const amount = i / STEPS;
141
+ for (const toward of [0, 255]) {
142
+ const candidate = mixToward(color, toward, amount);
143
+ const ratio = contrastRatio(candidate, surface);
144
+ if (ratio >= minRatio)
145
+ return candidate;
146
+ if (ratio > bestRatio) {
147
+ best = candidate;
148
+ bestRatio = ratio;
149
+ }
150
+ }
151
+ }
152
+ // Unreachable for any surface that is itself near-black or near-white, since
153
+ // one endpoint is then 21:1. Returning the best effort rather than throwing is
154
+ // deliberate: the emitted `test/contrast.test.ts` measures the VALUE that
155
+ // actually lands in the CSS, so a shortfall fails in the scaffolded project
156
+ // instead of being swallowed here.
157
+ return best;
71
158
  }
72
159
  const README_TEMPLATE = `# {{slug}}
73
160