@zero2webmaster/starter-kit 0.12.0 → 0.14.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.
@@ -1,6 +1,6 @@
1
1
  import type { ProjectType, ScaffoldInputs } from "./index.js";
2
2
  import { type SubstitutionOptions } from "./substitute.js";
3
- export type StandardKey = "skill-vault" | "portable-stack" | "fathom" | "uptime-kuma" | "sentry" | "neon-careful" | "agent-coordination" | "seo-baseline" | "email-service" | "moderation" | "text-size" | "test-count";
3
+ export type StandardKey = "skill-vault" | "portable-stack" | "fathom" | "uptime-kuma" | "sentry" | "neon-careful" | "temp-files" | "agent-coordination" | "seo-baseline" | "email-service" | "moderation" | "card-path-bot-protection" | "text-size" | "test-count";
4
4
  export type StandardDecisionState = "inserted-inline" | "skipped-not-applicable";
5
5
  export interface StandardDecision {
6
6
  key: StandardKey;
@@ -69,6 +69,20 @@ export declare const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.19";
69
69
  * Reported as an ACTION by `z2w-observability-bridge` (2026-07-27); closed here.
70
70
  */
71
71
  export declare const CAPTURE_LEARNINGS_BLOCK_VERSION = "v1.1.0";
72
+ /**
73
+ * The literal markdown heading each standard renders, keyed by `StandardKey`.
74
+ *
75
+ * Exists so a test can compare THIS CLI's standard set against the
76
+ * [[instantiate-z2w-project]] skill's `references/standards-block.md` in the
77
+ * skill → CLI direction. That direction had never been checked: OP #2's mirror
78
+ * habit propagates CLI changes INTO the skill, so a standard that existed only
79
+ * in the skill was invisible to every guard here. `temp-files` sat in that blind
80
+ * spot for months (found 2026-08-05) — the skill's Step 6 list named it, the
81
+ * reference file carried a full body for it, and `git log -S` proves this CLI
82
+ * never had it. Derived from `BODIES` rather than restated, so it cannot drift
83
+ * from what actually renders.
84
+ */
85
+ export declare function standardHeadings(): Record<StandardKey, string>;
72
86
  /**
73
87
  * Resolve which standards apply to `inputs` and render the standards markdown
74
88
  * body suitable for `.replace()`-ing into the `<!-- STANDARDS_BLOCK -->`
package/dist/standards.js CHANGED
@@ -51,10 +51,12 @@ const STANDARD_ORDER = [
51
51
  "uptime-kuma",
52
52
  "sentry",
53
53
  "neon-careful",
54
+ "temp-files",
54
55
  "agent-coordination",
55
56
  "seo-baseline",
56
57
  "email-service",
57
58
  "moderation",
59
+ "card-path-bot-protection",
58
60
  "text-size",
59
61
  "test-count",
60
62
  ];
@@ -65,10 +67,12 @@ const TITLES = {
65
67
  "uptime-kuma": "Uptime Kuma monitor",
66
68
  sentry: "Sentry runtime-error tracking (web app)",
67
69
  "neon-careful": "Neon-careful (Neon Postgres)",
70
+ "temp-files": "Project-scoped temp files (agent discipline)",
68
71
  "agent-coordination": "Agent Coordination (cross-project bulletin)",
69
72
  "seo-baseline": "SEO baseline (non-WP web UI)",
70
73
  "email-service": "Email service selection",
71
74
  moderation: "Moderation baseline (user-generated content)",
75
+ "card-path-bot-protection": "Card-path bot protection (accepts credit cards)",
72
76
  "text-size": "Text size (readability)",
73
77
  "test-count": "Test-count reporting (session end)",
74
78
  };
@@ -97,6 +101,12 @@ const NO_MODERATION_TYPES = [
97
101
  "library",
98
102
  "protocol-repo",
99
103
  ];
104
+ // Types with no runtime request surface, so no card-accepting endpoint can
105
+ // exist. Deliberately much SMALLER than the sets above: wp-plugin, cf-worker,
106
+ // cf-pages, node-service and python-service can all take a card, and the whole
107
+ // point of the standard is to reach the projects whose agents have not yet
108
+ // thought about payments. Only a CLI library and a spec repo are exempt.
109
+ const NO_CARD_PATH_TYPES = ["library", "protocol-repo"];
100
110
  function checkPortableStack(inputs) {
101
111
  if (inputs.projectType === "wp-plugin") {
102
112
  return {
@@ -233,6 +243,39 @@ function checkModeration(inputs) {
233
243
  reason: `hasUserContent=true on ${inputs.projectType} — two-layer moderation baseline per [[moderation-system]]`,
234
244
  };
235
245
  }
246
+ /**
247
+ * The card-path bot-protection standard applies on `acceptsCards`, and applies
248
+ * to EVERY project type — deliberately wider than the set this CLI can emit
249
+ * code for.
250
+ *
251
+ * A WordPress gateway and a Cloudflare Worker take cards too; `z2w-seller-suite`
252
+ * is the WP plugin whose retrofit produced the 2-of-3 measurement the body
253
+ * cites. Restricting the standard to `nextjs` (the only type whose protected
254
+ * shape we can scaffold) would mean the projects that most need to be told the
255
+ * rule are the ones never told it. The prose is the standard; the emitted code
256
+ * is a convenience `nextjs` happens to get.
257
+ *
258
+ * `library` and `protocol-repo` are excluded — no runtime request surface, so
259
+ * there is no endpoint to protect.
260
+ */
261
+ function checkCardPathBotProtection(inputs) {
262
+ if (!inputs.acceptsCards) {
263
+ return {
264
+ applies: false,
265
+ reason: "acceptsCards=false — no card-accepting endpoint to protect",
266
+ };
267
+ }
268
+ if (NO_CARD_PATH_TYPES.includes(inputs.projectType)) {
269
+ return {
270
+ applies: false,
271
+ reason: `${inputs.projectType} has no runtime request surface — no card path to protect`,
272
+ };
273
+ }
274
+ return {
275
+ applies: true,
276
+ reason: `acceptsCards=true on ${inputs.projectType} — bot check + own rate limit on every card path per [[stripe-elements-confirm-path]] §8`,
277
+ };
278
+ }
236
279
  function checkTextSize() {
237
280
  return { applies: true, reason: "Z2W standing org rule — applies to every project" };
238
281
  }
@@ -242,6 +285,20 @@ function checkTestCount() {
242
285
  reason: "Z2W standing org rule (2026-06-20) — every session reports its test count for the portfolio-wide tally",
243
286
  };
244
287
  }
288
+ /**
289
+ * Always-on. This is agent working discipline, not a stack choice: any project
290
+ * type can have an agent write a fixture or scratch script, so there is no
291
+ * project shape it fails to apply to (same footing as `text-size` and
292
+ * `test-count`). The scaffold already gitignores `.tmp/` via
293
+ * `GITIGNORE_SECRET_SCRATCH_BLOCK`, so the standard names a directory the
294
+ * emitted repo genuinely has.
295
+ */
296
+ function checkTempFiles() {
297
+ return {
298
+ applies: true,
299
+ reason: "Agent working discipline — applies to every project type regardless of stack",
300
+ };
301
+ }
245
302
  function checkSkillVault() {
246
303
  return {
247
304
  applies: true,
@@ -358,6 +415,27 @@ export const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.19";
358
415
  * Reported as an ACTION by `z2w-observability-bridge` (2026-07-27); closed here.
359
416
  */
360
417
  export const CAPTURE_LEARNINGS_BLOCK_VERSION = "v1.1.0";
418
+ /**
419
+ * Mirrored from the [[instantiate-z2w-project]] skill's
420
+ * `references/standards-block.md` per OP #2. **The skill had this standard and
421
+ * this CLI never did** — found 2026-08-05 by auditing the reference file against
422
+ * these bodies rather than against `SKILL.md`. `git log -S` confirms it was never
423
+ * here, so every CLI-scaffolded project has been missing it since the skill
424
+ * gained it, while every hand-scaffolded one has it. The gap was invisible
425
+ * because OP #2's mirror habit runs CLI → skill; nothing ever ran skill → CLI.
426
+ *
427
+ * One clause differs from the skill's wording deliberately, and the skill was
428
+ * updated to match: the skill said `.tmp/` is gitignored "by convention", but in
429
+ * a CLI-scaffolded repo it is gitignored by CONSTRUCTION (v0.5.4's
430
+ * `GITIGNORE_SECRET_SCRATCH_BLOCK`), which is a stronger and checkable promise.
431
+ */
432
+ const TEMP_FILES_BODY = `### Project-scoped temp files (agent discipline)
433
+
434
+ > **Temp files belong in this project's own \`.tmp/\`** — never in \`/tmp/\`, \`/private/tmp/\`, \`~/Desktop/\`, \`~/Downloads/\`, or anywhere else outside the project tree. Applies to any agent-created fixture, smoke-test dataset, scratch script, intermediate export, or scratchpad note. **\`.tmp/\` is already gitignored in this repo** (it ships in the scaffold's \`.gitignore\`), so writing there never accidentally commits. It also survives a reboot — macOS auto-cleans \`/tmp/\` — and it is discoverable in Finder under the project, which is the part that actually matters to a human operator.
435
+ >
436
+ > Acceptable exceptions, used sparingly and announced when taken: cross-project shared fixtures, a file some system process explicitly requires at \`/tmp/\`, and single-command ephemeral roundtrips via \`mktemp\`.
437
+ >
438
+ > **Why this is a standard and not a preference (discovered 2026-06-03):** a \`contest-management\` smoke-test fixture was written to \`/tmp/b22-smoke/\` by an earlier session. The operator could not find it during the browser-side upload step, because Finder hides \`/tmp\` by default and the reasonable place to look was inside the project being tested. Re-running mid-session meant recreating the fixture and moving it to \`<project>/.tmp/b22-smoke/\`. The default already existed; an agent skipping it costs operator time on every dogfood.`;
361
439
  const CAPTURE_LEARNINGS_BODY = `## Capture Learnings (session end)
362
440
 
363
441
  <!-- cursor-project-templates capture-learnings-block ${CAPTURE_LEARNINGS_BLOCK_VERSION} -->
@@ -549,6 +627,36 @@ const MODERATION_BODY = `### Moderation baseline (user-generated content)
549
627
  > 5. **Optional pre-publish gate.** For content with a \`draft → published\` lifecycle, an unresolved flag blocks publish — turning the AI scan into a mandatory pre-publication gate.
550
628
  >
551
629
  > **Cross-app note:** for a future shared moderation package, map the tenant key at the boundary (event-engine keys on \`org_id\`, z2w-social on \`tenant_id\` — same idea, rename where they meet). See [[moderation-system]] for the data model, the coalescing pattern, the entity-resolver seam, and the verification checklist. Companion skills: [[async-action-feedback]] (the Report button + dashboard feedback), [[neon-postgres]] (run the scan out-of-band so it doesn't pin compute), [[per-tenant-credential-vault]] (where the scan API key lives long-term).`;
630
+ const CARD_PATH_BOT_PROTECTION_BODY = `### Card-path bot protection (accepts credit cards)
631
+
632
+ > **This project will accept credit cards, so every card-accepting endpoint carries a bot check AND its own rate limit — from the first one, not from the first incident.** Load [[stripe-elements-confirm-path]] §8 before writing any payment code. Cloudflare Turnstile is the sanctioned bot mitigation for the Z2W stack; never Akismet. Kerry's directive, 2026-08-06: *"let's ensure that anywhere credit cards are accepted in our system we have turnstile enabled"* — explicitly widened by him beyond any one project.
633
+ >
634
+ > **First, ENUMERATE the card paths by grep — never by eye.** This is the step that gets skipped, and skipping it is what a passing review looks like:
635
+ >
636
+ > \`\`\`
637
+ > paymentIntents.create setupIntents.create
638
+ > confirmSetup( confirmPayment(
639
+ > /payment_intents /setup_intents
640
+ > \`\`\`
641
+ >
642
+ > For each hit, assert that **both** a bot check and a rate limit exist **in that handler**. Measured 2026-08-06: a Z2W WooCommerce gateway had \`verify_turnstile()\` and \`is_rate_limited()\` implemented and called in **exactly one of three** card-accepting paths. The two bare ones were authenticated, nonce'd and ownership-checked — **none of which limits volume.** Authentication answers *who*, not *how many*. And the save-a-card path is the one that gets forgotten: \`setupIntents.create\` validates a card **without charging it**, which is precisely the primitive card-testing wants, and it leaves no failed-charge trail to notice.
643
+ >
644
+ > **On Next.js, a page-level gate does not cover a Server Action.** A Server Action is a publicly addressable POST endpoint, invocable without ever loading its page, and a route-shaped scan cannot even see an actions file. Each exported action re-takes its own checks — [[server-actions-are-public-endpoints]].
645
+ >
646
+ > **The pass condition is NOT "has a captcha".** A visible challenge on a checkout or donation form costs real conversions, so an audit that rewards mere presence makes things worse. Require all four:
647
+ >
648
+ > 1. **Invisible unless needed** — \`appearance: "interaction-only"\`. A bare \`<div class="cf-turnstile">\` renders a visible widget to every buyer. (The standalone "Invisible" widget *type* is deprecated; Managed vs Non-interactive is a Cloudflare dashboard setting, not markup.)
649
+ > 2. **Legible failure** — wire the \`error\` / \`timeout\` / \`expired\` callbacks. Left unwired, the widget silently never mints a token and the user gets a baffling refusal at submit with nothing to act on. Report them where someone will see them (Sentry on a non-WP app; an admin-visible counter on a WordPress checkout — do not load a third-party SDK onto the page where card details are entered).
650
+ > 3. **A limit SIZED for card entry, and no global cap.** Do not copy the checkout's limit: a budget tuned for order submission blocks a customer legitimately retrying a mistyped card. The reference default is **30 per 10 minutes per source** — because thirty people giving over one wifi NAT at a fundraising dinner is a good night, not an attack, and a per-minute limit turns the moment the campaign works into a wall of 429s. **No site-wide ceiling on a giving path**: it converts going viral into an outage. (Opposite call to a magic-link limiter, where a global cap *is* right — every send costs money and no burst of them is ever good news.)
651
+ > 4. **🔴 Fail OPEN, with a verdict that is not a boolean.** A captcha-provider outage must never stop payments. Keep \`pass\` / \`fail\` / \`degraded\` / \`no-token\` / \`unconfigured\` distinct: a boolean silently collapses *"Cloudflare rejected this"* into *"we could not reach Cloudflare"*, and only the first is evidence of a bot ([[zero-is-not-a-pass]]). Pair a non-\`pass\` verdict with a **tighter budget**, not a refusal — a **missing** token throttles harder than a failed one, because "no token → allow" makes the check optional at the attacker's discretion while "no token → refuse" hands a Cloudflare outage the power to stop your checkout. Your own rotated or typo'd secret must degrade too: that is the most tempting place to fail closed and the most wrong, since your mistake would refuse every payment with a message blaming the customer.
652
+ >
653
+ > **🔴 Point 4 is the deliberate OPPOSITE of [[webhook-fail-closed]], and the two get conflated because they share the word "verify".** A webhook signature governs **inbound authenticity** — an unsigned request is provably not from Stripe, so fail **closed**. A bot check governs **friction on a human** — an unreachable third party is not evidence of abuse, so fail **open**. Same word, opposite correct answer. Write that reasoning next to the code, or someone will "fix" one into the other, and a payment path that fails closed on a Cloudflare blip is an outage you inflicted on yourself.
654
+ >
655
+ > **An in-memory rate limiter's real ceiling is \`limit × instances\`.** On a serverless host that is not good enough for a money path — card-testing fans out, which is exactly what defeats per-instance state. Back the limit with a shared store ([[z2w-magic-link-auth]] §8.6.1). The shared store must **also** fail open and loudly: a limiter outage must not become a payment outage, but the caller has to be able to tell "checked, under the limit" from "could not check."
656
+ >
657
+ > **Turnstile tokens are SINGLE-USE** — siteverify consumes them — so reset the widget after every attempt, or the customer's second try comes back \`timeout-or-duplicate\` and reads as a bot. Tokens also expire after ~5 minutes, which any customer reading a page before paying will cross: refresh on \`expired\`, don't fail at submit.
658
+ >
659
+ > *Reference implementation: \`z2w-crowdcommerce\` v0.7.0 (2026-08-06), which has the reasoning written next to the code. Standard settled 2026-08-07 with \`z2w-seller-suite\`, whose own retrofit supplied the 2-of-3 measurement above.*`;
552
660
  const TEXT_SIZE_BODY = `### Text size (always)
553
661
 
554
662
  > **Readability:** per Z2W standing org rule, all public-facing pages and documents use large, easy-to-read type. Body text 18px+ baseline; headings proportionally larger; line-height ≥ 1.5.`;
@@ -568,10 +676,12 @@ const BODIES = {
568
676
  "uptime-kuma": UPTIME_KUMA_BODY,
569
677
  sentry: SENTRY_BODY,
570
678
  "neon-careful": NEON_CAREFUL_BODY,
679
+ "temp-files": TEMP_FILES_BODY,
571
680
  "agent-coordination": AGENT_COORDINATION_BODY,
572
681
  "seo-baseline": SEO_BASELINE_BODY,
573
682
  "email-service": EMAIL_SERVICE_BODY,
574
683
  moderation: MODERATION_BODY,
684
+ "card-path-bot-protection": CARD_PATH_BOT_PROTECTION_BODY,
575
685
  "text-size": TEXT_SIZE_BODY,
576
686
  "test-count": TEST_COUNT_BODY,
577
687
  };
@@ -582,13 +692,35 @@ const APPLICABILITY = {
582
692
  "uptime-kuma": checkUptimeKuma,
583
693
  sentry: checkSentry,
584
694
  "neon-careful": checkNeonCareful,
695
+ "temp-files": checkTempFiles,
585
696
  "agent-coordination": checkAgentCoordination,
586
697
  "seo-baseline": checkSeoBaseline,
587
698
  "email-service": checkEmailService,
588
699
  moderation: checkModeration,
700
+ "card-path-bot-protection": checkCardPathBotProtection,
589
701
  "text-size": checkTextSize,
590
702
  "test-count": checkTestCount,
591
703
  };
704
+ /**
705
+ * The literal markdown heading each standard renders, keyed by `StandardKey`.
706
+ *
707
+ * Exists so a test can compare THIS CLI's standard set against the
708
+ * [[instantiate-z2w-project]] skill's `references/standards-block.md` in the
709
+ * skill → CLI direction. That direction had never been checked: OP #2's mirror
710
+ * habit propagates CLI changes INTO the skill, so a standard that existed only
711
+ * in the skill was invisible to every guard here. `temp-files` sat in that blind
712
+ * spot for months (found 2026-08-05) — the skill's Step 6 list named it, the
713
+ * reference file carried a full body for it, and `git log -S` proves this CLI
714
+ * never had it. Derived from `BODIES` rather than restated, so it cannot drift
715
+ * from what actually renders.
716
+ */
717
+ export function standardHeadings() {
718
+ const out = {};
719
+ for (const key of STANDARD_ORDER) {
720
+ out[key] = BODIES[key].split("\n")[0].trim();
721
+ }
722
+ return out;
723
+ }
592
724
  const PREAMBLE = `The following organization standards apply to {{slug}}. Each was selected at instantiation per the conditional rules in the [[instantiate-z2w-project]] skill (Step 6). See each standard's wiki-style link for the full discipline; the inline summaries below are the binding contract for this project.`;
593
725
  const NO_APPLICABLE_FALLBACK = `*(No conditional standards apply to this project.)*`;
594
726
  /**
package/dist/wizard.js CHANGED
@@ -156,6 +156,12 @@ export async function runWizard(opts) {
156
156
  ? "yes"
157
157
  : "no";
158
158
  const hasObservability = await askValidated(prompter, "8f. Wire Sentry runtime-error tracking (yes/no):", parseYesNo, observabilityDefault, out);
159
+ // Default NO. Unlike Sentry there is no type-based smart default worth
160
+ // guessing: "will this take a card" is a product decision the operator knows
161
+ // and the project type does not predict. Answering yes emits the protected
162
+ // card-path shape rather than leaving the first payment route bare — which is
163
+ // only cheap BEFORE the code exists ([[stripe-elements-confirm-path]] §8).
164
+ const acceptsCards = await askValidated(prompter, "8g. Will this project accept credit cards — checkout, donations, save-a-card (yes/no):", parseYesNo, "no", out);
159
165
  const result = {
160
166
  slug,
161
167
  description,
@@ -170,6 +176,7 @@ export async function runWizard(opts) {
170
176
  sendsEmail,
171
177
  hasUserContent,
172
178
  hasObservability,
179
+ acceptsCards,
173
180
  };
174
181
  if (customBrand) {
175
182
  result.customBrand = customBrand;
package/dist/writer.js CHANGED
@@ -427,6 +427,19 @@ export function parseScaffoldInputs(json) {
427
427
  }
428
428
  inputs.hostRoutedTenancy = obj["hostRoutedTenancy"];
429
429
  }
430
+ // Optional: whether this project will accept credit cards. Defaults to false.
431
+ // When true, the nextjs scaffolder emits the protected card-path shape
432
+ // (Turnstile verifier + an abuse policy sized for card entry + the widget +
433
+ // an enforcement test) instead of leaving the first payment route bare, and
434
+ // the standards resolver inserts the card-path bot-protection standard.
435
+ // Kerry's 2026-08-06 directive; four design decisions settled with
436
+ // z2w-seller-suite on 2026-08-07. See [[stripe-elements-confirm-path]] §8.
437
+ if (obj["acceptsCards"] !== undefined) {
438
+ if (typeof obj["acceptsCards"] !== "boolean") {
439
+ throw new WriterError(`--input field "acceptsCards" must be a boolean, got ${typeof obj["acceptsCards"]}.`);
440
+ }
441
+ inputs.acceptsCards = obj["acceptsCards"];
442
+ }
430
443
  // Optional: the verbatim instantiation prompt, recorded on the Airtable row.
431
444
  // The --input path has no brief to capture, so callers may supply it here;
432
445
  // when omitted, the Airtable write reminds the agent to add it by hand.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero2webmaster/starter-kit",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.",
5
5
  "author": {
6
6
  "name": "Dr. Kerry Kriger",