@zero2webmaster/starter-kit 0.40.1 → 0.41.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.40.1 | **Framework:** 2.19.0
3
+ **Version:** 0.41.0 | **Framework:** 2.19.0
4
4
 
5
5
  > Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.
6
6
 
@@ -135,4 +135,4 @@ Inquiries: kerry@zero2webmaster.com.
135
135
  ---
136
136
 
137
137
  *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.*
138
- *Version: 0.40.1 | Last Updated: 2026-10-16*
138
+ *Version: 0.41.0 | Last Updated: 2026-10-17*
@@ -65,7 +65,7 @@ const SPECS = {
65
65
  "and the fingerprint we stamp is the one upstream publishes",
66
66
  },
67
67
  templates: {
68
- repo: "cursor-project-templates",
68
+ repo: "agent-framework",
69
69
  relPath: "Resources/CAPTURE_LEARNINGS_BLOCK.md",
70
70
  localCandidates: () => [
71
71
  join(homedir(), "Desktop/Zero2Webmaster/AI/Templates/Resources/CAPTURE_LEARNINGS_BLOCK.md"),
@@ -24,6 +24,13 @@ export declare const INVENTORY_CONFLICT_KEY = "slug";
24
24
  * project is scaffolded FROM, which is the criterion above stated almost
25
25
  * literally, and its authoring sibling `cursor-project-templates` was already
26
26
  * in the set. Reversible in one `UPDATE` plus this line if Kerry disagrees.
27
+ *
28
+ * **Two members RENAMED 2026-10-17 (Kerry's rename plan, steps 1 and 2):**
29
+ * `cursor-project-templates` → `agent-framework` and `z2w-templates` →
30
+ * `starter-kit-templates`. Same nine projects, new slugs; the old ones are in
31
+ * each row's `former_slugs`. The constraint was swapped in the same
32
+ * transaction as the two row UPDATEs, so no moment existed where an
33
+ * `ecosystem` row held a slug the constraint did not list.
27
34
  */
28
35
  export declare const ECOSYSTEM_PROJECTS: readonly string[];
29
36
  /**
package/dist/inventory.js CHANGED
@@ -54,17 +54,24 @@ export const INVENTORY_CONFLICT_KEY = "slug";
54
54
  * project is scaffolded FROM, which is the criterion above stated almost
55
55
  * literally, and its authoring sibling `cursor-project-templates` was already
56
56
  * in the set. Reversible in one `UPDATE` plus this line if Kerry disagrees.
57
+ *
58
+ * **Two members RENAMED 2026-10-17 (Kerry's rename plan, steps 1 and 2):**
59
+ * `cursor-project-templates` → `agent-framework` and `z2w-templates` →
60
+ * `starter-kit-templates`. Same nine projects, new slugs; the old ones are in
61
+ * each row's `former_slugs`. The constraint was swapped in the same
62
+ * transaction as the two row UPDATEs, so no moment existed where an
63
+ * `ecosystem` row held a slug the constraint did not list.
57
64
  */
58
65
  export const ECOSYSTEM_PROJECTS = [
66
+ "agent-framework",
59
67
  "audit-engine",
60
- "cursor-project-templates",
61
68
  "kuma-watchdog",
69
+ "starter-kit-templates",
62
70
  "z2w-agent-command-center",
63
71
  "z2w-agent-coordination",
64
72
  "z2w-observability-bridge",
65
73
  "z2w-skill-vault",
66
74
  "z2w-starter-kit",
67
- "z2w-templates",
68
75
  ];
69
76
  /**
70
77
  * The `ecosystem_role` a given slug must hold, derived from the closed set.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The in-app user guide MECHANISM, emitted into every `nextjs` scaffold.
3
+ *
4
+ * Kerry ruled 2026-10-12 (relayed by `z2w-agent-coordination`): every scaffolded
5
+ * app emits it, internal tools included. That settles the question this project
6
+ * put to `grantor` on 2026-09-19 (emit always, or only when the scaffold knows
7
+ * the app has outside users) in favour of always.
8
+ *
9
+ * What is emitted is the mechanism, never content. A guide documents what people
10
+ * could not FIND, which no scaffolder can know, so `GUIDE_SECTIONS` starts EMPTY
11
+ * and the page says so plainly. The model is `grantor`'s guide (the first one in
12
+ * the portfolio that was a page rather than an emailed document) reduced to the
13
+ * parts that are true of any app:
14
+ *
15
+ * - `lib/guide.ts` — the guide as typed DATA, a hand-set review date, a pure
16
+ * age function that fails closed, and the "What's new" change log (Kerry,
17
+ * 2026-10-12, via `audit-engine`).
18
+ * - `app/guide/page.tsx`, `app/guide/whats-new/page.tsx` — the two pages.
19
+ * - `test/guide.test.ts` — walks `app/` in BOTH directions and fails when the
20
+ * guide goes unread for more than 35 days.
21
+ *
22
+ * 🔴 ESCAPING: these are template literals emitted as consumer source, the one
23
+ * place this repo has shipped code that did not parse while every check here was
24
+ * green (2026-08-17). The emitted code therefore contains NO backticks and NO
25
+ * dollar-brace sequences at all; strings are built with `+`. Keep it that way,
26
+ * and verify any change by running the scaffold's own `vitest` and `next build`.
27
+ *
28
+ * 🔴 AUDIENCE: these files also reach external customers. Do not name private
29
+ * skills, the bulletin, or people in them; the audience gate scans for it.
30
+ */
31
+ export declare const GUIDE_MODULE_TEMPLATE = "/**\n * THE USER GUIDE, as data. Rendered at /guide.\n *\n * WHAT GOES IN IT: the things people TRIED to do here and could not find, in the\n * order a new user meets them. Not a tour of the navigation. A feature list\n * documents what was built; it cannot document what people looked for and missed,\n * and that second list is the whole reason anyone opens a guide.\n *\n * Where that list comes from, best first:\n * 1. A recording of somebody using the app while talking (a demo, a meeting,\n * a support call).\n * 2. \"X is missing\" reports where X already existed.\n * 3. Questions you have answered by hand more than once.\n * 4. Last: the route list, only to check no whole screen was forgotten.\n *\n * Every \"note\" you write is ALSO a design defect. Write the entry, fix the\n * screen so it explains itself, then delete the entry.\n *\n * If writing a section makes the guide contradict itself, the APP is\n * contradicting itself. Fix the app, not the sentence.\n *\n * Shape: one section per TASK, titled as the task (\"Invite a team member\"), at\n * most seven numbered steps (eight means it is two sections). Every in-app\n * destination goes in a step's href, so test/guide.test.ts can tell you when a\n * renamed page leaves the guide pointing at nothing.\n *\n * PURE: no database, no session, no next/* imports, so it is tested directly.\n */\n\n/**\n * WHEN A PERSON LAST READ THIS GUIDE AGAINST THE RUNNING APP. Printed atop /guide.\n *\n * HAND-SET ON PURPOSE. Never derive it from the file's modified time, the git\n * log or the build. A derived date answers \"was this file touched?\", which a\n * typo fix satisfies; the reader is asking \"has anybody checked this is still\n * true?\". A build that stamps today onto an unread page makes a guide that is\n * confidently, freshly wrong, which is worse than one admitting it is old.\n *\n * Move it only after reading the whole guide beside the app and fixing what\n * drifted. test/guide.test.ts fails when it is more than\n * GUIDE_REVIEW_INTERVAL_DAYS old.\n */\nexport const GUIDE_REVIEWED_ON = \"{{date}}\";\n\n/** How long the guide may go unread before the test suite fails. */\nexport const GUIDE_REVIEW_INTERVAL_DAYS = 35;\n\n/**\n * A YYYY-MM-DD string as UTC milliseconds, or NaN if it is not a real date.\n *\n * The round trip is the important part: Date.parse(\"2026-02-31\") does NOT fail,\n * it silently returns March 3. A typo in a date would then pass as a different,\n * real date, so the parsed value must print back as exactly the string given.\n */\nexport function parseGuideDate(isoDate: string): number {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(isoDate)) return Number.NaN;\n const t = Date.parse(isoDate + \"T00:00:00Z\");\n if (!Number.isFinite(t) || new Date(t).toISOString().slice(0, 10) !== isoDate) return Number.NaN;\n return t;\n}\n\n/**\n * Whole days between the last review and \"now\". Pure, so a test can pass any\n * date. An invalid date returns Infinity, so it FAILS the staleness test\n * instead of passing it.\n */\nexport function guideAgeInDays(now: Date, reviewedOn: string = GUIDE_REVIEWED_ON): number {\n const reviewed = parseGuideDate(reviewedOn);\n if (!Number.isFinite(reviewed)) return Number.POSITIVE_INFINITY;\n return Math.floor((now.getTime() - reviewed) / 86_400_000);\n}\n\n/**\n * \"everyone\" = anyone who can open the app. \"admin\" = administrators only.\n * Admin sections are NOT shown to other readers at all: a guide that explains\n * things you may not do is a guide people stop reading.\n */\nexport type GuideAudience = \"everyone\" | \"admin\";\n\nexport interface GuideStep {\n /** One instruction, one sentence. */\n text: string;\n /** A real in-app path (\"/settings\"). The test checks it exists under app/. */\n href?: string;\n /** The link's words. Required whenever href is set. */\n linkLabel?: string;\n}\n\nexport interface GuideSection {\n /** The anchor (/guide#this-id). Keep it stable: people send these links. */\n id: string;\n /** The task, in the reader's words. */\n title: string;\n /** When you would come here, in one line. */\n lead: string;\n audience: GuideAudience;\n steps: readonly GuideStep[];\n /** The thing people miss, written from somebody actually missing it. */\n note?: string;\n}\n\n/**\n * Empty until somebody who did not build this app has used it and got stuck.\n * The first section is usually \"What you do here, start to finish\".\n */\nexport const GUIDE_SECTIONS: readonly GuideSection[] = [];\n\n/** The sections a reader may see. Unknown means not an admin. */\nexport function guideSectionsFor(\n viewer: { isAdmin: boolean },\n sections: readonly GuideSection[] = GUIDE_SECTIONS,\n): GuideSection[] {\n return sections.filter((s) => s.audience === \"everyone\" || viewer.isAdmin);\n}\n\n/**\n * WHAT'S NEW: one plain-language line per change a USER would notice, newest\n * first. Not a developer changelog (that is CHANGELOG.md): no version numbers,\n * no refactors, no fixes nobody saw. \"You can now export the member list\" is an\n * entry; \"upgraded the database driver\" is not.\n */\nexport interface WhatsNewEntry {\n /** YYYY-MM-DD, the day users could first see it. */\n date: string;\n text: string;\n audience: GuideAudience;\n}\n\nexport const WHATS_NEW: readonly WhatsNewEntry[] = [];\n\n/** How far back the guide's \"Recent changes\" box looks. */\nexport const RECENT_CHANGES_DAYS = 31;\n\n/** Entries a reader may see, newest first. */\nexport function whatsNewFor(\n viewer: { isAdmin: boolean },\n entries: readonly WhatsNewEntry[] = WHATS_NEW,\n): WhatsNewEntry[] {\n return entries\n .filter((e) => e.audience === \"everyone\" || viewer.isAdmin)\n .slice()\n .sort((a, b) => (a.date < b.date ? 1 : a.date > b.date ? -1 : 0));\n}\n\n/** The entries from the last RECENT_CHANGES_DAYS days, as of \"now\". */\nexport function recentChanges(\n viewer: { isAdmin: boolean },\n now: Date,\n entries: readonly WhatsNewEntry[] = WHATS_NEW,\n): WhatsNewEntry[] {\n return whatsNewFor(viewer, entries).filter((e) => {\n const age = guideAgeInDays(now, e.date);\n return age >= 0 && age <= RECENT_CHANGES_DAYS;\n });\n}\n\n/**\n * A YYYY-MM-DD date for people to read, in UTC. Formatting a bare date in the\n * reader's own time zone shows the PREVIOUS day anywhere west of Greenwich.\n */\nexport function formatGuideDate(isoDate: string): string {\n const t = parseGuideDate(isoDate);\n if (!Number.isFinite(t)) return isoDate;\n return new Intl.DateTimeFormat(\"en-US\", {\n year: \"numeric\",\n month: \"long\",\n day: \"numeric\",\n timeZone: \"UTC\",\n }).format(new Date(t));\n}\n";
32
+ export declare const GUIDE_PAGE_TEMPLATE = "// The user guide. Content lives in lib/guide.ts; this file only renders it.\n//\n// \u26A0\uFE0F WHO IS READING: until this app has sign-in, every reader is treated as a\n// non-admin, so \"admin\" sections are never shown. When you add auth, replace\n// VIEWER with the signed-in user, and make sure a signed-out reader who opens a\n// /guide link is sent back to the guide after logging in, not to the dashboard.\n//\n// \u26A0\uFE0F noindex: a guide describes how the app works inside. It is for the people\n// you send the link to, not for search engines.\n\nimport Link from \"next/link\";\nimport type { Metadata } from \"next\";\nimport { pageMetadata } from \"@/lib/seo/page-metadata\";\nimport {\n GUIDE_REVIEWED_ON,\n formatGuideDate,\n guideSectionsFor,\n recentChanges,\n} from \"@/lib/guide\";\n\nexport const metadata: Metadata = {\n ...pageMetadata({\n title: \"User guide\",\n description: \"Step-by-step help for the things people look for in {{slug}}.\",\n path: \"/guide\",\n }),\n robots: { index: false, follow: false },\n};\n\n// Rebuilt daily so \"Recent changes\" means the last month as of today, not as\n// of the last deploy.\nexport const revalidate = 86400;\n\nconst VIEWER = { isAdmin: false };\n\nexport default function GuidePage() {\n const sections = guideSectionsFor(VIEWER);\n const recent = recentChanges(VIEWER, new Date());\n\n return (\n <main style={{ maxWidth: \"820px\", margin: \"0 auto\", padding: \"2rem 1rem\", fontSize: \"1.125rem\", lineHeight: 1.6 }}>\n <h1>How to use {{brand_name}}</h1>\n <p>\n <strong>Last checked against the app:</strong> {formatGuideDate(GUIDE_REVIEWED_ON)}\n </p>\n\n {recent.length > 0 ? (\n <section aria-labelledby=\"recent-changes\" style={{ border: \"2px solid {{primary_color}}\", borderRadius: \"8px\", padding: \"1rem 1.25rem\", margin: \"1.5rem 0\" }}>\n <h2 id=\"recent-changes\" style={{ marginTop: 0 }}>Recent changes</h2>\n <ul>\n {recent.map((e) => (\n <li key={e.date + e.text}>\n <strong>{formatGuideDate(e.date)}:</strong> {e.text}\n </li>\n ))}\n </ul>\n <p style={{ marginBottom: 0 }}>\n <Link href=\"/guide/whats-new\">Everything that has changed</Link>\n </p>\n </section>\n ) : (\n <p>\n <Link href=\"/guide/whats-new\">What&apos;s new</Link>\n </p>\n )}\n\n {sections.length === 0 ? (\n <p>\n This guide has no sections yet. If something here was hard to find,\n tell the team which page you were on and what you were looking for.\n That is exactly what this page is written from.\n </p>\n ) : (\n <>\n <nav aria-label=\"Guide contents\">\n <ol style={{ columns: 2, columnGap: \"2rem\", paddingLeft: \"1.25rem\" }}>\n {sections.map((s) => (\n <li key={s.id}>\n <a href={\"#\" + s.id}>{s.title}</a>\n </li>\n ))}\n </ol>\n </nav>\n {sections.map((s) => (\n <section key={s.id} id={s.id} aria-labelledby={s.id + \"-title\"} style={{ marginTop: \"2.5rem\" }}>\n <h2 id={s.id + \"-title\"}>{s.title}</h2>\n <p>{s.lead}</p>\n <ol>\n {s.steps.map((step, i) => (\n <li key={i}>\n {step.text}\n {step.href ? (\n <>\n {\" \"}\n <Link href={step.href}>{step.linkLabel}</Link>\n </>\n ) : null}\n </li>\n ))}\n </ol>\n {s.note ? (\n <p role=\"note\" style={{ borderLeft: \"4px solid {{accent_color}}\", background: \"#fff8e1\", color: \"#1a1a1a\", padding: \"0.75rem 1rem\" }}>\n <strong>Worth knowing:</strong> {s.note}\n </p>\n ) : null}\n </section>\n ))}\n </>\n )}\n </main>\n );\n}\n";
33
+ export declare const WHATS_NEW_PAGE_TEMPLATE = "// \"What's new\": the user-facing change log. Entries live in lib/guide.ts\n// (WHATS_NEW). Same viewer rule and noindex as app/guide/page.tsx.\n\nimport Link from \"next/link\";\nimport type { Metadata } from \"next\";\nimport { pageMetadata } from \"@/lib/seo/page-metadata\";\nimport { formatGuideDate, whatsNewFor } from \"@/lib/guide\";\n\nexport const metadata: Metadata = {\n ...pageMetadata({\n title: \"What's new\",\n description: \"Changes to {{slug}} that you would notice, newest first.\",\n path: \"/guide/whats-new\",\n }),\n robots: { index: false, follow: false },\n};\n\nconst VIEWER = { isAdmin: false };\n\nexport default function WhatsNewPage() {\n const entries = whatsNewFor(VIEWER);\n return (\n <main style={{ maxWidth: \"820px\", margin: \"0 auto\", padding: \"2rem 1rem\", fontSize: \"1.125rem\", lineHeight: 1.6 }}>\n <h1>What&apos;s new</h1>\n <p>\n <Link href=\"/guide\">Back to the guide</Link>\n </p>\n {entries.length === 0 ? (\n <p>Nothing yet. Changes you would notice will be listed here, newest first.</p>\n ) : (\n <ul>\n {entries.map((e) => (\n <li key={e.date + e.text}>\n <strong>{formatGuideDate(e.date)}:</strong> {e.text}\n </li>\n ))}\n </ul>\n )}\n </main>\n );\n}\n";
34
+ export declare const GUIDE_TEST_TEMPLATE = "/**\n * THE GUIDE MUST NOT ROT, and guide rot is silent: a renamed page does not\n * throw or look wrong in review. The guide just starts lying to the one reader\n * least able to tell, somebody sent the link because they do not know the app.\n *\n * So these checks run in BOTH directions: every page the guide names must exist\n * under app/, AND every page under app/ must be explained in the guide or listed\n * in DELIBERATELY_UNEXPLAINED with a reason a person wrote.\n */\nimport { describe, it, expect } from \"vitest\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport { join, dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport {\n GUIDE_REVIEWED_ON,\n GUIDE_REVIEW_INTERVAL_DAYS,\n GUIDE_SECTIONS,\n RECENT_CHANGES_DAYS,\n WHATS_NEW,\n formatGuideDate,\n guideAgeInDays,\n guideSectionsFor,\n recentChanges,\n whatsNewFor,\n type GuideSection,\n type WhatsNewEntry,\n} from \"@/lib/guide\";\n\nconst APP_DIR = join(dirname(fileURLToPath(import.meta.url)), \"..\", \"app\");\n\n/**\n * Every page path under app/, read from the directory. Route groups \"(x)\"\n * collapse away; private \"_x\" and parallel \"@x\" folders are skipped.\n */\nfunction allPagePaths(dir: string = APP_DIR, prefix = \"\"): string[] {\n const out: string[] = [];\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry);\n if (statSync(full).isDirectory()) {\n if (entry.startsWith(\"_\") || entry.startsWith(\"@\")) continue;\n const isGroup = entry.startsWith(\"(\") && entry.endsWith(\")\");\n out.push(...allPagePaths(full, isGroup ? prefix : prefix + \"/\" + entry));\n } else if (/^page\\.(tsx|ts|jsx|js|mdx)$/.test(entry)) {\n out.push(prefix === \"\" ? \"/\" : prefix);\n }\n }\n return out;\n}\n\nconst PAGES = new Set(allPagePaths());\n\n/**\n * Pages the guide deliberately does not explain, each with its reason. Adding a\n * line here is a decision, which is the point: \"the guide skips it\" must be a\n * sentence somebody wrote, never something that happened by omission.\n *\n * Some exclusions are disclosure decisions. Naming a screen that only a few\n * people can open, in a guide sent to many, tells the many that it exists.\n */\nconst DELIBERATELY_UNEXPLAINED: Record<string, string> = {\n \"/guide\": \"It is the guide.\",\n \"/guide/whats-new\": \"Linked from the top of the guide; it explains itself.\",\n \"/\": \"The scaffold's placeholder home page. When it becomes a real screen, explain it in a guide section and delete this line.\",\n};\n\n/** Dynamic routes (\"/items/[id]\") cannot be linked to as written. */\nconst isDynamic = (path: string) => path.includes(\"[\");\n\ndescribe(\"the guide's destinations are real\", () => {\n it(\"actually read the app directory\", () => {\n // An empty walk is not a pass.\n expect(PAGES.has(\"/\")).toBe(true);\n expect(PAGES.has(\"/guide\")).toBe(true);\n expect(PAGES.has(\"/guide/whats-new\")).toBe(true);\n });\n\n it(\"links only to pages that exist under app/\", () => {\n const bad: string[] = [];\n for (const section of GUIDE_SECTIONS) {\n for (const step of section.steps) {\n if (step.href && !PAGES.has(step.href.split(\"#\")[0])) bad.push(section.id + \": \" + step.href);\n }\n }\n expect(bad, \"The guide links to pages that do not exist: \" + bad.join(\", \")).toEqual([]);\n });\n\n it(\"gives every link words to click\", () => {\n for (const section of GUIDE_SECTIONS) {\n for (const step of section.steps) {\n if (step.href) expect(step.linkLabel, section.id + \" has a link with no label\").toBeTruthy();\n }\n }\n });\n\n it(\"explains every page, or says why it does not\", () => {\n const mentioned = new Set(\n GUIDE_SECTIONS.flatMap((s) => s.steps.map((st) => (st.href ?? \"\").split(\"#\")[0]).filter(Boolean)),\n );\n const unexplained = [...PAGES]\n .filter((p) => !isDynamic(p))\n .filter((p) => !mentioned.has(p) && !(p in DELIBERATELY_UNEXPLAINED));\n expect(\n unexplained,\n \"These pages are in the app but nowhere in the guide. Explain them in lib/guide.ts, \" +\n \"or add them to DELIBERATELY_UNEXPLAINED in this file with a reason: \" +\n unexplained.join(\", \"),\n ).toEqual([]);\n });\n\n it(\"keeps no exclusion for a page that no longer exists\", () => {\n const stale = Object.keys(DELIBERATELY_UNEXPLAINED).filter((p) => !PAGES.has(p));\n expect(stale, \"Remove these from DELIBERATELY_UNEXPLAINED: \" + stale.join(\", \")).toEqual([]);\n });\n});\n\ndescribe(\"the guide's structure\", () => {\n it(\"has unique, stable anchors, because people send these links\", () => {\n const ids = GUIDE_SECTIONS.map((s) => s.id);\n expect(new Set(ids).size).toBe(ids.length);\n for (const id of ids) expect(id).toMatch(/^[a-z][a-z0-9-]*$/);\n });\n\n it(\"keeps every section between one and seven steps\", () => {\n for (const s of GUIDE_SECTIONS) {\n expect(s.steps.length, s.id + \" has no steps\").toBeGreaterThan(0);\n expect(s.steps.length, s.id + \" has \" + s.steps.length + \" steps; split it in two\").toBeLessThanOrEqual(7);\n }\n });\n\n it(\"shows admin sections to admins only\", () => {\n const sample: GuideSection[] = [\n { id: \"a\", title: \"A\", lead: \"a\", audience: \"everyone\", steps: [{ text: \"x\" }] },\n { id: \"b\", title: \"B\", lead: \"b\", audience: \"admin\", steps: [{ text: \"y\" }] },\n ];\n expect(guideSectionsFor({ isAdmin: false }, sample).map((s) => s.id)).toEqual([\"a\"]);\n expect(guideSectionsFor({ isAdmin: true }, sample).map((s) => s.id)).toEqual([\"a\", \"b\"]);\n });\n});\n\ndescribe(\"what's new\", () => {\n it(\"dates every entry as a real YYYY-MM-DD that is not in the future\", () => {\n const now = new Date();\n for (const e of WHATS_NEW) {\n expect(Number.isFinite(guideAgeInDays(now, e.date)), e.date + \" is not a valid date\").toBe(true);\n expect(guideAgeInDays(now, e.date), e.date + \" is in the future\").toBeGreaterThanOrEqual(0);\n expect(e.text.trim().length, \"an entry dated \" + e.date + \" has no text\").toBeGreaterThan(0);\n }\n });\n\n it(\"lists newest first, hides admin entries from everyone else, and keeps only the last month in Recent changes\", () => {\n const sample: WhatsNewEntry[] = [\n { date: \"2026-01-01\", text: \"old\", audience: \"everyone\" },\n { date: \"2026-03-10\", text: \"admin only\", audience: \"admin\" },\n { date: \"2026-03-20\", text: \"new\", audience: \"everyone\" },\n ];\n expect(whatsNewFor({ isAdmin: false }, sample).map((e) => e.text)).toEqual([\"new\", \"old\"]);\n expect(whatsNewFor({ isAdmin: true }, sample).map((e) => e.text)).toEqual([\"new\", \"admin only\", \"old\"]);\n const now = new Date(\"2026-03-25T12:00:00Z\");\n expect(recentChanges({ isAdmin: true }, now, sample).map((e) => e.text)).toEqual([\"new\", \"admin only\"]);\n expect(RECENT_CHANGES_DAYS).toBeGreaterThanOrEqual(28);\n });\n});\n\ndescribe(\"the review date\", () => {\n it(\"prints dates in UTC, so nobody west of Greenwich sees the day before\", () => {\n expect(formatGuideDate(\"2026-03-01\")).toBe(\"March 1, 2026\");\n });\n\n it(\"can fail: a stale date, a future 'now' and a malformed date all read as old\", () => {\n // A staleness check that cannot fail is a comment. These prove it can.\n expect(guideAgeInDays(new Date(\"2026-03-01T00:00:00Z\"), \"2026-01-01\")).toBe(59);\n expect(guideAgeInDays(new Date(), \"not-a-date\")).toBe(Number.POSITIVE_INFINITY);\n expect(guideAgeInDays(new Date(), \"2026-02-31\")).toBe(Number.POSITIVE_INFINITY);\n });\n\n it(\"has been read against the app within the last \" + GUIDE_REVIEW_INTERVAL_DAYS + \" days\", () => {\n const age = guideAgeInDays(new Date());\n const what =\n GUIDE_SECTIONS.length === 0\n ? \"The guide is still EMPTY. If anyone besides the people who built this app uses it, \" +\n \"write the first section from what they could not find, then set GUIDE_REVIEWED_ON. \"\n : \"Open /guide beside the running app, read it top to bottom, fix what has drifted, \" +\n \"and only THEN set GUIDE_REVIEWED_ON. \";\n expect(\n age,\n \"The user guide was last checked \" + age + \" days ago (\" + GUIDE_REVIEWED_ON + \"). \" + what +\n \"Moving the date without doing the reading is worse than leaving it stale: it makes \" +\n \"a guide that is wrong and says it was just checked.\",\n ).toBeLessThanOrEqual(GUIDE_REVIEW_INTERVAL_DAYS);\n });\n});\n";
@@ -0,0 +1,548 @@
1
+ /**
2
+ * The in-app user guide MECHANISM, emitted into every `nextjs` scaffold.
3
+ *
4
+ * Kerry ruled 2026-10-12 (relayed by `z2w-agent-coordination`): every scaffolded
5
+ * app emits it, internal tools included. That settles the question this project
6
+ * put to `grantor` on 2026-09-19 (emit always, or only when the scaffold knows
7
+ * the app has outside users) in favour of always.
8
+ *
9
+ * What is emitted is the mechanism, never content. A guide documents what people
10
+ * could not FIND, which no scaffolder can know, so `GUIDE_SECTIONS` starts EMPTY
11
+ * and the page says so plainly. The model is `grantor`'s guide (the first one in
12
+ * the portfolio that was a page rather than an emailed document) reduced to the
13
+ * parts that are true of any app:
14
+ *
15
+ * - `lib/guide.ts` — the guide as typed DATA, a hand-set review date, a pure
16
+ * age function that fails closed, and the "What's new" change log (Kerry,
17
+ * 2026-10-12, via `audit-engine`).
18
+ * - `app/guide/page.tsx`, `app/guide/whats-new/page.tsx` — the two pages.
19
+ * - `test/guide.test.ts` — walks `app/` in BOTH directions and fails when the
20
+ * guide goes unread for more than 35 days.
21
+ *
22
+ * 🔴 ESCAPING: these are template literals emitted as consumer source, the one
23
+ * place this repo has shipped code that did not parse while every check here was
24
+ * green (2026-08-17). The emitted code therefore contains NO backticks and NO
25
+ * dollar-brace sequences at all; strings are built with `+`. Keep it that way,
26
+ * and verify any change by running the scaffold's own `vitest` and `next build`.
27
+ *
28
+ * 🔴 AUDIENCE: these files also reach external customers. Do not name private
29
+ * skills, the bulletin, or people in them; the audience gate scans for it.
30
+ */
31
+ export const GUIDE_MODULE_TEMPLATE = `/**
32
+ * THE USER GUIDE, as data. Rendered at /guide.
33
+ *
34
+ * WHAT GOES IN IT: the things people TRIED to do here and could not find, in the
35
+ * order a new user meets them. Not a tour of the navigation. A feature list
36
+ * documents what was built; it cannot document what people looked for and missed,
37
+ * and that second list is the whole reason anyone opens a guide.
38
+ *
39
+ * Where that list comes from, best first:
40
+ * 1. A recording of somebody using the app while talking (a demo, a meeting,
41
+ * a support call).
42
+ * 2. "X is missing" reports where X already existed.
43
+ * 3. Questions you have answered by hand more than once.
44
+ * 4. Last: the route list, only to check no whole screen was forgotten.
45
+ *
46
+ * Every "note" you write is ALSO a design defect. Write the entry, fix the
47
+ * screen so it explains itself, then delete the entry.
48
+ *
49
+ * If writing a section makes the guide contradict itself, the APP is
50
+ * contradicting itself. Fix the app, not the sentence.
51
+ *
52
+ * Shape: one section per TASK, titled as the task ("Invite a team member"), at
53
+ * most seven numbered steps (eight means it is two sections). Every in-app
54
+ * destination goes in a step's href, so test/guide.test.ts can tell you when a
55
+ * renamed page leaves the guide pointing at nothing.
56
+ *
57
+ * PURE: no database, no session, no next/* imports, so it is tested directly.
58
+ */
59
+
60
+ /**
61
+ * WHEN A PERSON LAST READ THIS GUIDE AGAINST THE RUNNING APP. Printed atop /guide.
62
+ *
63
+ * HAND-SET ON PURPOSE. Never derive it from the file's modified time, the git
64
+ * log or the build. A derived date answers "was this file touched?", which a
65
+ * typo fix satisfies; the reader is asking "has anybody checked this is still
66
+ * true?". A build that stamps today onto an unread page makes a guide that is
67
+ * confidently, freshly wrong, which is worse than one admitting it is old.
68
+ *
69
+ * Move it only after reading the whole guide beside the app and fixing what
70
+ * drifted. test/guide.test.ts fails when it is more than
71
+ * GUIDE_REVIEW_INTERVAL_DAYS old.
72
+ */
73
+ export const GUIDE_REVIEWED_ON = "{{date}}";
74
+
75
+ /** How long the guide may go unread before the test suite fails. */
76
+ export const GUIDE_REVIEW_INTERVAL_DAYS = 35;
77
+
78
+ /**
79
+ * A YYYY-MM-DD string as UTC milliseconds, or NaN if it is not a real date.
80
+ *
81
+ * The round trip is the important part: Date.parse("2026-02-31") does NOT fail,
82
+ * it silently returns March 3. A typo in a date would then pass as a different,
83
+ * real date, so the parsed value must print back as exactly the string given.
84
+ */
85
+ export function parseGuideDate(isoDate: string): number {
86
+ if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(isoDate)) return Number.NaN;
87
+ const t = Date.parse(isoDate + "T00:00:00Z");
88
+ if (!Number.isFinite(t) || new Date(t).toISOString().slice(0, 10) !== isoDate) return Number.NaN;
89
+ return t;
90
+ }
91
+
92
+ /**
93
+ * Whole days between the last review and "now". Pure, so a test can pass any
94
+ * date. An invalid date returns Infinity, so it FAILS the staleness test
95
+ * instead of passing it.
96
+ */
97
+ export function guideAgeInDays(now: Date, reviewedOn: string = GUIDE_REVIEWED_ON): number {
98
+ const reviewed = parseGuideDate(reviewedOn);
99
+ if (!Number.isFinite(reviewed)) return Number.POSITIVE_INFINITY;
100
+ return Math.floor((now.getTime() - reviewed) / 86_400_000);
101
+ }
102
+
103
+ /**
104
+ * "everyone" = anyone who can open the app. "admin" = administrators only.
105
+ * Admin sections are NOT shown to other readers at all: a guide that explains
106
+ * things you may not do is a guide people stop reading.
107
+ */
108
+ export type GuideAudience = "everyone" | "admin";
109
+
110
+ export interface GuideStep {
111
+ /** One instruction, one sentence. */
112
+ text: string;
113
+ /** A real in-app path ("/settings"). The test checks it exists under app/. */
114
+ href?: string;
115
+ /** The link's words. Required whenever href is set. */
116
+ linkLabel?: string;
117
+ }
118
+
119
+ export interface GuideSection {
120
+ /** The anchor (/guide#this-id). Keep it stable: people send these links. */
121
+ id: string;
122
+ /** The task, in the reader's words. */
123
+ title: string;
124
+ /** When you would come here, in one line. */
125
+ lead: string;
126
+ audience: GuideAudience;
127
+ steps: readonly GuideStep[];
128
+ /** The thing people miss, written from somebody actually missing it. */
129
+ note?: string;
130
+ }
131
+
132
+ /**
133
+ * Empty until somebody who did not build this app has used it and got stuck.
134
+ * The first section is usually "What you do here, start to finish".
135
+ */
136
+ export const GUIDE_SECTIONS: readonly GuideSection[] = [];
137
+
138
+ /** The sections a reader may see. Unknown means not an admin. */
139
+ export function guideSectionsFor(
140
+ viewer: { isAdmin: boolean },
141
+ sections: readonly GuideSection[] = GUIDE_SECTIONS,
142
+ ): GuideSection[] {
143
+ return sections.filter((s) => s.audience === "everyone" || viewer.isAdmin);
144
+ }
145
+
146
+ /**
147
+ * WHAT'S NEW: one plain-language line per change a USER would notice, newest
148
+ * first. Not a developer changelog (that is CHANGELOG.md): no version numbers,
149
+ * no refactors, no fixes nobody saw. "You can now export the member list" is an
150
+ * entry; "upgraded the database driver" is not.
151
+ */
152
+ export interface WhatsNewEntry {
153
+ /** YYYY-MM-DD, the day users could first see it. */
154
+ date: string;
155
+ text: string;
156
+ audience: GuideAudience;
157
+ }
158
+
159
+ export const WHATS_NEW: readonly WhatsNewEntry[] = [];
160
+
161
+ /** How far back the guide's "Recent changes" box looks. */
162
+ export const RECENT_CHANGES_DAYS = 31;
163
+
164
+ /** Entries a reader may see, newest first. */
165
+ export function whatsNewFor(
166
+ viewer: { isAdmin: boolean },
167
+ entries: readonly WhatsNewEntry[] = WHATS_NEW,
168
+ ): WhatsNewEntry[] {
169
+ return entries
170
+ .filter((e) => e.audience === "everyone" || viewer.isAdmin)
171
+ .slice()
172
+ .sort((a, b) => (a.date < b.date ? 1 : a.date > b.date ? -1 : 0));
173
+ }
174
+
175
+ /** The entries from the last RECENT_CHANGES_DAYS days, as of "now". */
176
+ export function recentChanges(
177
+ viewer: { isAdmin: boolean },
178
+ now: Date,
179
+ entries: readonly WhatsNewEntry[] = WHATS_NEW,
180
+ ): WhatsNewEntry[] {
181
+ return whatsNewFor(viewer, entries).filter((e) => {
182
+ const age = guideAgeInDays(now, e.date);
183
+ return age >= 0 && age <= RECENT_CHANGES_DAYS;
184
+ });
185
+ }
186
+
187
+ /**
188
+ * A YYYY-MM-DD date for people to read, in UTC. Formatting a bare date in the
189
+ * reader's own time zone shows the PREVIOUS day anywhere west of Greenwich.
190
+ */
191
+ export function formatGuideDate(isoDate: string): string {
192
+ const t = parseGuideDate(isoDate);
193
+ if (!Number.isFinite(t)) return isoDate;
194
+ return new Intl.DateTimeFormat("en-US", {
195
+ year: "numeric",
196
+ month: "long",
197
+ day: "numeric",
198
+ timeZone: "UTC",
199
+ }).format(new Date(t));
200
+ }
201
+ `;
202
+ export const GUIDE_PAGE_TEMPLATE = `// The user guide. Content lives in lib/guide.ts; this file only renders it.
203
+ //
204
+ // ⚠️ WHO IS READING: until this app has sign-in, every reader is treated as a
205
+ // non-admin, so "admin" sections are never shown. When you add auth, replace
206
+ // VIEWER with the signed-in user, and make sure a signed-out reader who opens a
207
+ // /guide link is sent back to the guide after logging in, not to the dashboard.
208
+ //
209
+ // ⚠️ noindex: a guide describes how the app works inside. It is for the people
210
+ // you send the link to, not for search engines.
211
+
212
+ import Link from "next/link";
213
+ import type { Metadata } from "next";
214
+ import { pageMetadata } from "@/lib/seo/page-metadata";
215
+ import {
216
+ GUIDE_REVIEWED_ON,
217
+ formatGuideDate,
218
+ guideSectionsFor,
219
+ recentChanges,
220
+ } from "@/lib/guide";
221
+
222
+ export const metadata: Metadata = {
223
+ ...pageMetadata({
224
+ title: "User guide",
225
+ description: "Step-by-step help for the things people look for in {{slug}}.",
226
+ path: "/guide",
227
+ }),
228
+ robots: { index: false, follow: false },
229
+ };
230
+
231
+ // Rebuilt daily so "Recent changes" means the last month as of today, not as
232
+ // of the last deploy.
233
+ export const revalidate = 86400;
234
+
235
+ const VIEWER = { isAdmin: false };
236
+
237
+ export default function GuidePage() {
238
+ const sections = guideSectionsFor(VIEWER);
239
+ const recent = recentChanges(VIEWER, new Date());
240
+
241
+ return (
242
+ <main style={{ maxWidth: "820px", margin: "0 auto", padding: "2rem 1rem", fontSize: "1.125rem", lineHeight: 1.6 }}>
243
+ <h1>How to use {{brand_name}}</h1>
244
+ <p>
245
+ <strong>Last checked against the app:</strong> {formatGuideDate(GUIDE_REVIEWED_ON)}
246
+ </p>
247
+
248
+ {recent.length > 0 ? (
249
+ <section aria-labelledby="recent-changes" style={{ border: "2px solid {{primary_color}}", borderRadius: "8px", padding: "1rem 1.25rem", margin: "1.5rem 0" }}>
250
+ <h2 id="recent-changes" style={{ marginTop: 0 }}>Recent changes</h2>
251
+ <ul>
252
+ {recent.map((e) => (
253
+ <li key={e.date + e.text}>
254
+ <strong>{formatGuideDate(e.date)}:</strong> {e.text}
255
+ </li>
256
+ ))}
257
+ </ul>
258
+ <p style={{ marginBottom: 0 }}>
259
+ <Link href="/guide/whats-new">Everything that has changed</Link>
260
+ </p>
261
+ </section>
262
+ ) : (
263
+ <p>
264
+ <Link href="/guide/whats-new">What&apos;s new</Link>
265
+ </p>
266
+ )}
267
+
268
+ {sections.length === 0 ? (
269
+ <p>
270
+ This guide has no sections yet. If something here was hard to find,
271
+ tell the team which page you were on and what you were looking for.
272
+ That is exactly what this page is written from.
273
+ </p>
274
+ ) : (
275
+ <>
276
+ <nav aria-label="Guide contents">
277
+ <ol style={{ columns: 2, columnGap: "2rem", paddingLeft: "1.25rem" }}>
278
+ {sections.map((s) => (
279
+ <li key={s.id}>
280
+ <a href={"#" + s.id}>{s.title}</a>
281
+ </li>
282
+ ))}
283
+ </ol>
284
+ </nav>
285
+ {sections.map((s) => (
286
+ <section key={s.id} id={s.id} aria-labelledby={s.id + "-title"} style={{ marginTop: "2.5rem" }}>
287
+ <h2 id={s.id + "-title"}>{s.title}</h2>
288
+ <p>{s.lead}</p>
289
+ <ol>
290
+ {s.steps.map((step, i) => (
291
+ <li key={i}>
292
+ {step.text}
293
+ {step.href ? (
294
+ <>
295
+ {" "}
296
+ <Link href={step.href}>{step.linkLabel}</Link>
297
+ </>
298
+ ) : null}
299
+ </li>
300
+ ))}
301
+ </ol>
302
+ {s.note ? (
303
+ <p role="note" style={{ borderLeft: "4px solid {{accent_color}}", background: "#fff8e1", color: "#1a1a1a", padding: "0.75rem 1rem" }}>
304
+ <strong>Worth knowing:</strong> {s.note}
305
+ </p>
306
+ ) : null}
307
+ </section>
308
+ ))}
309
+ </>
310
+ )}
311
+ </main>
312
+ );
313
+ }
314
+ `;
315
+ export const WHATS_NEW_PAGE_TEMPLATE = `// "What's new": the user-facing change log. Entries live in lib/guide.ts
316
+ // (WHATS_NEW). Same viewer rule and noindex as app/guide/page.tsx.
317
+
318
+ import Link from "next/link";
319
+ import type { Metadata } from "next";
320
+ import { pageMetadata } from "@/lib/seo/page-metadata";
321
+ import { formatGuideDate, whatsNewFor } from "@/lib/guide";
322
+
323
+ export const metadata: Metadata = {
324
+ ...pageMetadata({
325
+ title: "What's new",
326
+ description: "Changes to {{slug}} that you would notice, newest first.",
327
+ path: "/guide/whats-new",
328
+ }),
329
+ robots: { index: false, follow: false },
330
+ };
331
+
332
+ const VIEWER = { isAdmin: false };
333
+
334
+ export default function WhatsNewPage() {
335
+ const entries = whatsNewFor(VIEWER);
336
+ return (
337
+ <main style={{ maxWidth: "820px", margin: "0 auto", padding: "2rem 1rem", fontSize: "1.125rem", lineHeight: 1.6 }}>
338
+ <h1>What&apos;s new</h1>
339
+ <p>
340
+ <Link href="/guide">Back to the guide</Link>
341
+ </p>
342
+ {entries.length === 0 ? (
343
+ <p>Nothing yet. Changes you would notice will be listed here, newest first.</p>
344
+ ) : (
345
+ <ul>
346
+ {entries.map((e) => (
347
+ <li key={e.date + e.text}>
348
+ <strong>{formatGuideDate(e.date)}:</strong> {e.text}
349
+ </li>
350
+ ))}
351
+ </ul>
352
+ )}
353
+ </main>
354
+ );
355
+ }
356
+ `;
357
+ export const GUIDE_TEST_TEMPLATE = `/**
358
+ * THE GUIDE MUST NOT ROT, and guide rot is silent: a renamed page does not
359
+ * throw or look wrong in review. The guide just starts lying to the one reader
360
+ * least able to tell, somebody sent the link because they do not know the app.
361
+ *
362
+ * So these checks run in BOTH directions: every page the guide names must exist
363
+ * under app/, AND every page under app/ must be explained in the guide or listed
364
+ * in DELIBERATELY_UNEXPLAINED with a reason a person wrote.
365
+ */
366
+ import { describe, it, expect } from "vitest";
367
+ import { readdirSync, statSync } from "node:fs";
368
+ import { join, dirname } from "node:path";
369
+ import { fileURLToPath } from "node:url";
370
+ import {
371
+ GUIDE_REVIEWED_ON,
372
+ GUIDE_REVIEW_INTERVAL_DAYS,
373
+ GUIDE_SECTIONS,
374
+ RECENT_CHANGES_DAYS,
375
+ WHATS_NEW,
376
+ formatGuideDate,
377
+ guideAgeInDays,
378
+ guideSectionsFor,
379
+ recentChanges,
380
+ whatsNewFor,
381
+ type GuideSection,
382
+ type WhatsNewEntry,
383
+ } from "@/lib/guide";
384
+
385
+ const APP_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "app");
386
+
387
+ /**
388
+ * Every page path under app/, read from the directory. Route groups "(x)"
389
+ * collapse away; private "_x" and parallel "@x" folders are skipped.
390
+ */
391
+ function allPagePaths(dir: string = APP_DIR, prefix = ""): string[] {
392
+ const out: string[] = [];
393
+ for (const entry of readdirSync(dir)) {
394
+ const full = join(dir, entry);
395
+ if (statSync(full).isDirectory()) {
396
+ if (entry.startsWith("_") || entry.startsWith("@")) continue;
397
+ const isGroup = entry.startsWith("(") && entry.endsWith(")");
398
+ out.push(...allPagePaths(full, isGroup ? prefix : prefix + "/" + entry));
399
+ } else if (/^page\\.(tsx|ts|jsx|js|mdx)$/.test(entry)) {
400
+ out.push(prefix === "" ? "/" : prefix);
401
+ }
402
+ }
403
+ return out;
404
+ }
405
+
406
+ const PAGES = new Set(allPagePaths());
407
+
408
+ /**
409
+ * Pages the guide deliberately does not explain, each with its reason. Adding a
410
+ * line here is a decision, which is the point: "the guide skips it" must be a
411
+ * sentence somebody wrote, never something that happened by omission.
412
+ *
413
+ * Some exclusions are disclosure decisions. Naming a screen that only a few
414
+ * people can open, in a guide sent to many, tells the many that it exists.
415
+ */
416
+ const DELIBERATELY_UNEXPLAINED: Record<string, string> = {
417
+ "/guide": "It is the guide.",
418
+ "/guide/whats-new": "Linked from the top of the guide; it explains itself.",
419
+ "/": "The scaffold's placeholder home page. When it becomes a real screen, explain it in a guide section and delete this line.",
420
+ };
421
+
422
+ /** Dynamic routes ("/items/[id]") cannot be linked to as written. */
423
+ const isDynamic = (path: string) => path.includes("[");
424
+
425
+ describe("the guide's destinations are real", () => {
426
+ it("actually read the app directory", () => {
427
+ // An empty walk is not a pass.
428
+ expect(PAGES.has("/")).toBe(true);
429
+ expect(PAGES.has("/guide")).toBe(true);
430
+ expect(PAGES.has("/guide/whats-new")).toBe(true);
431
+ });
432
+
433
+ it("links only to pages that exist under app/", () => {
434
+ const bad: string[] = [];
435
+ for (const section of GUIDE_SECTIONS) {
436
+ for (const step of section.steps) {
437
+ if (step.href && !PAGES.has(step.href.split("#")[0])) bad.push(section.id + ": " + step.href);
438
+ }
439
+ }
440
+ expect(bad, "The guide links to pages that do not exist: " + bad.join(", ")).toEqual([]);
441
+ });
442
+
443
+ it("gives every link words to click", () => {
444
+ for (const section of GUIDE_SECTIONS) {
445
+ for (const step of section.steps) {
446
+ if (step.href) expect(step.linkLabel, section.id + " has a link with no label").toBeTruthy();
447
+ }
448
+ }
449
+ });
450
+
451
+ it("explains every page, or says why it does not", () => {
452
+ const mentioned = new Set(
453
+ GUIDE_SECTIONS.flatMap((s) => s.steps.map((st) => (st.href ?? "").split("#")[0]).filter(Boolean)),
454
+ );
455
+ const unexplained = [...PAGES]
456
+ .filter((p) => !isDynamic(p))
457
+ .filter((p) => !mentioned.has(p) && !(p in DELIBERATELY_UNEXPLAINED));
458
+ expect(
459
+ unexplained,
460
+ "These pages are in the app but nowhere in the guide. Explain them in lib/guide.ts, " +
461
+ "or add them to DELIBERATELY_UNEXPLAINED in this file with a reason: " +
462
+ unexplained.join(", "),
463
+ ).toEqual([]);
464
+ });
465
+
466
+ it("keeps no exclusion for a page that no longer exists", () => {
467
+ const stale = Object.keys(DELIBERATELY_UNEXPLAINED).filter((p) => !PAGES.has(p));
468
+ expect(stale, "Remove these from DELIBERATELY_UNEXPLAINED: " + stale.join(", ")).toEqual([]);
469
+ });
470
+ });
471
+
472
+ describe("the guide's structure", () => {
473
+ it("has unique, stable anchors, because people send these links", () => {
474
+ const ids = GUIDE_SECTIONS.map((s) => s.id);
475
+ expect(new Set(ids).size).toBe(ids.length);
476
+ for (const id of ids) expect(id).toMatch(/^[a-z][a-z0-9-]*$/);
477
+ });
478
+
479
+ it("keeps every section between one and seven steps", () => {
480
+ for (const s of GUIDE_SECTIONS) {
481
+ expect(s.steps.length, s.id + " has no steps").toBeGreaterThan(0);
482
+ expect(s.steps.length, s.id + " has " + s.steps.length + " steps; split it in two").toBeLessThanOrEqual(7);
483
+ }
484
+ });
485
+
486
+ it("shows admin sections to admins only", () => {
487
+ const sample: GuideSection[] = [
488
+ { id: "a", title: "A", lead: "a", audience: "everyone", steps: [{ text: "x" }] },
489
+ { id: "b", title: "B", lead: "b", audience: "admin", steps: [{ text: "y" }] },
490
+ ];
491
+ expect(guideSectionsFor({ isAdmin: false }, sample).map((s) => s.id)).toEqual(["a"]);
492
+ expect(guideSectionsFor({ isAdmin: true }, sample).map((s) => s.id)).toEqual(["a", "b"]);
493
+ });
494
+ });
495
+
496
+ describe("what's new", () => {
497
+ it("dates every entry as a real YYYY-MM-DD that is not in the future", () => {
498
+ const now = new Date();
499
+ for (const e of WHATS_NEW) {
500
+ expect(Number.isFinite(guideAgeInDays(now, e.date)), e.date + " is not a valid date").toBe(true);
501
+ expect(guideAgeInDays(now, e.date), e.date + " is in the future").toBeGreaterThanOrEqual(0);
502
+ expect(e.text.trim().length, "an entry dated " + e.date + " has no text").toBeGreaterThan(0);
503
+ }
504
+ });
505
+
506
+ it("lists newest first, hides admin entries from everyone else, and keeps only the last month in Recent changes", () => {
507
+ const sample: WhatsNewEntry[] = [
508
+ { date: "2026-01-01", text: "old", audience: "everyone" },
509
+ { date: "2026-03-10", text: "admin only", audience: "admin" },
510
+ { date: "2026-03-20", text: "new", audience: "everyone" },
511
+ ];
512
+ expect(whatsNewFor({ isAdmin: false }, sample).map((e) => e.text)).toEqual(["new", "old"]);
513
+ expect(whatsNewFor({ isAdmin: true }, sample).map((e) => e.text)).toEqual(["new", "admin only", "old"]);
514
+ const now = new Date("2026-03-25T12:00:00Z");
515
+ expect(recentChanges({ isAdmin: true }, now, sample).map((e) => e.text)).toEqual(["new", "admin only"]);
516
+ expect(RECENT_CHANGES_DAYS).toBeGreaterThanOrEqual(28);
517
+ });
518
+ });
519
+
520
+ describe("the review date", () => {
521
+ it("prints dates in UTC, so nobody west of Greenwich sees the day before", () => {
522
+ expect(formatGuideDate("2026-03-01")).toBe("March 1, 2026");
523
+ });
524
+
525
+ it("can fail: a stale date, a future 'now' and a malformed date all read as old", () => {
526
+ // A staleness check that cannot fail is a comment. These prove it can.
527
+ expect(guideAgeInDays(new Date("2026-03-01T00:00:00Z"), "2026-01-01")).toBe(59);
528
+ expect(guideAgeInDays(new Date(), "not-a-date")).toBe(Number.POSITIVE_INFINITY);
529
+ expect(guideAgeInDays(new Date(), "2026-02-31")).toBe(Number.POSITIVE_INFINITY);
530
+ });
531
+
532
+ it("has been read against the app within the last " + GUIDE_REVIEW_INTERVAL_DAYS + " days", () => {
533
+ const age = guideAgeInDays(new Date());
534
+ const what =
535
+ GUIDE_SECTIONS.length === 0
536
+ ? "The guide is still EMPTY. If anyone besides the people who built this app uses it, " +
537
+ "write the first section from what they could not find, then set GUIDE_REVIEWED_ON. "
538
+ : "Open /guide beside the running app, read it top to bottom, fix what has drifted, " +
539
+ "and only THEN set GUIDE_REVIEWED_ON. ";
540
+ expect(
541
+ age,
542
+ "The user guide was last checked " + age + " days ago (" + GUIDE_REVIEWED_ON + "). " + what +
543
+ "Moving the date without doing the reading is worse than leaving it stale: it makes " +
544
+ "a guide that is wrong and says it was just checked.",
545
+ ).toBeLessThanOrEqual(GUIDE_REVIEW_INTERVAL_DAYS);
546
+ });
547
+ });
548
+ `;
@@ -46,6 +46,7 @@
46
46
  // allowlist stub in `.env.example`. This CLI emits no auth code, so it plants the
47
47
  // seam + the pointer at [[z2w-magic-link-auth]] §0 rule 2b rather than a check —
48
48
  // see CANONICAL_HOSTS_ENV_BLOCK for why that is the honest half.
49
+ import { GUIDE_MODULE_TEMPLATE, GUIDE_PAGE_TEMPLATE, GUIDE_TEST_TEMPLATE, WHATS_NEW_PAGE_TEMPLATE, } from "./nextjs-guide.js";
49
50
  import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, accessibleOn, contrastRatio, readableInkOn, resolveBrandSpec, SENTRY_DEPS, NEON_DRIVER_DEP, sub, } from "./common.js";
50
51
  const NARRATIVE = `## What this is
51
52
 
@@ -89,6 +90,8 @@ The components carry **no** \`"use client"\` on purpose, so a Server Component c
89
90
  **Before launch:** run the SEO baseline pre-launch audit from CLAUDE.md.
90
91
 
91
92
  **Health endpoint:** \`/api/health\` is DB-free per [[neon-postgres]].
93
+
94
+ **User guide (wired in, empty on purpose):** \`/guide\` renders \`lib/guide.ts\`, and \`/guide/whats-new\` lists changes a user would notice. Write a section only from what somebody who did not build this app tried to do and could not find; never as a tour of the menus. \`test/guide.test.ts\` fails when the guide links to a page that no longer exists, when a page is neither explained nor excluded with a reason, and when \`GUIDE_REVIEWED_ON\` is more than 35 days old. Move that date only after reading the guide beside the running app.
92
95
  `;
93
96
  const PACKAGE_JSON_TEMPLATE = `{
94
97
  "name": "{{slug}}",
@@ -5670,6 +5673,16 @@ export function scaffoldNextjs(inputs, opts) {
5670
5673
  content: sub(pwa ? withPwaWiring(APP_LAYOUT_TEMPLATE) : APP_LAYOUT_TEMPLATE, inputs, opts, spec),
5671
5674
  },
5672
5675
  { path: "app/page.tsx", content: sub(APP_PAGE_TEMPLATE, inputs, opts, spec) },
5676
+ // The in-app user guide MECHANISM (Kerry, 2026-10-12: always, internal tools
5677
+ // included). Content cannot be scaffolded, so the sections start empty; see
5678
+ // ./nextjs-guide.ts for what each file is and why the date is hand-set.
5679
+ { path: "lib/guide.ts", content: sub(GUIDE_MODULE_TEMPLATE, inputs, opts, spec) },
5680
+ { path: "app/guide/page.tsx", content: sub(GUIDE_PAGE_TEMPLATE, inputs, opts, spec) },
5681
+ {
5682
+ path: "app/guide/whats-new/page.tsx",
5683
+ content: sub(WHATS_NEW_PAGE_TEMPLATE, inputs, opts, spec),
5684
+ },
5685
+ { path: "test/guide.test.ts", content: sub(GUIDE_TEST_TEMPLATE, inputs, opts, spec) },
5673
5686
  { path: "lib/analytics/utm.ts", content: sub(ANALYTICS_UTM_TEMPLATE, inputs, opts, spec) },
5674
5687
  {
5675
5688
  path: "lib/analytics/Analytics.tsx",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero2webmaster/starter-kit",
3
- "version": "0.40.1",
3
+ "version": "0.41.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",