@zero2webmaster/starter-kit 0.30.0 → 0.31.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.30.0 | **Framework:** 2.19.0
3
+ **Version:** 0.31.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.30.0 | Last Updated: 2026-09-11*
138
+ *Version: 0.31.0 | Last Updated: 2026-09-18*
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The three CROSS-REPO sources this repo's drift guards read — and the switch
3
+ * that decides whether their ABSENCE is allowed to be silent.
4
+ *
5
+ * WHY THIS FILE EXISTS
6
+ * --------------------
7
+ * Six of this suite's tests compare something this CLI emits against the
8
+ * canonical text it claims to mirror. All three canonical texts live in OTHER
9
+ * private repos, so until 2026-09-13 every one of those tests was written as
10
+ * `it.skipIf(!existsSync(pathOnKerrysLaptop))`.
11
+ *
12
+ * That was correct when nothing else could reach them, and it became the
13
+ * problem the moment CI existed: the coordination-pointer conformance byte-diff
14
+ * — built in v0.30.0 *after* the emitted pointer had drifted to a 62%-similar
15
+ * paraphrase that four fingerprint bumps missed — ran on exactly one machine,
16
+ * and it was the machine CI exists to stop trusting.
17
+ *
18
+ * THE PART THAT IS NOT ABOUT CREDENTIALS
19
+ * --------------------------------------
20
+ * Granting CI read access to those repos is necessary and not sufficient. A
21
+ * skip reads as green, so if the token lapses, the checkout silently fails, or
22
+ * a file is renamed upstream, the guards return to not running and NOTHING GOES
23
+ * RED. We would be paying for a credential with no guarantee it is still in
24
+ * use — which is [[zero-is-not-a-pass]] wearing a purchase order.
25
+ *
26
+ * So absence is configurable, and the two audiences get opposite defaults:
27
+ *
28
+ * - a contributor's laptop (no env var): missing source => SKIP, as before.
29
+ * - CI (`Z2W_REQUIRE_DRIFT_SOURCES=1`): missing source => HARD FAILURE.
30
+ *
31
+ * RESOLUTION IS REPORTED, NOT JUST PERFORMED
32
+ * ------------------------------------------
33
+ * Each source is found by walking a list of candidate paths, and taking the
34
+ * first that exists is selection by POSITION, not by evidence — a named trap in
35
+ * [[zero-is-not-a-pass]]. The stale bulletin clone that sat 215 commits behind
36
+ * while a guard reported a shrinking gap was exactly this. So every resolution
37
+ * carries WHICH candidate won and WHY, and the suite prints it.
38
+ */
39
+ export type DriftSourceName = "coordination" | "templates" | "skill";
40
+ /** Where CI drops the sibling checkouts. Overridable so the layout is not magic. */
41
+ export declare const driftSourcesDir: () => string;
42
+ /**
43
+ * `1` means a missing source is a FAILURE, not a skip. CI sets it; laptops
44
+ * don't. Deliberately an opt-IN to strictness rather than an opt-out: a
45
+ * contributor who has none of these repos must still be able to run the suite.
46
+ */
47
+ export declare const driftSourcesRequired: () => boolean;
48
+ export interface ResolvedDriftSource {
49
+ readonly name: DriftSourceName;
50
+ readonly repo: string;
51
+ readonly guards: string;
52
+ /** The file, if it was found anywhere. */
53
+ readonly path?: string;
54
+ /** WHICH candidate won. Never infer this from `path` — say it. */
55
+ readonly origin: "ci-checkout" | "local" | "absent";
56
+ /** Everything looked at, in order, so a wrong answer is diagnosable. */
57
+ readonly candidatesTried: readonly string[];
58
+ }
59
+ /** Find one source. Never throws — callers decide what absence means. */
60
+ export declare const resolveDriftSource: (name: DriftSourceName) => ResolvedDriftSource;
61
+ /**
62
+ * The `skipIf` condition. Skip ONLY when the source is missing AND nobody has
63
+ * declared it mandatory. Under `Z2W_REQUIRE_DRIFT_SOURCES=1` this returns false
64
+ * even with no file, so the test RUNS and `demandDriftSource` fails it loudly.
65
+ */
66
+ export declare const skipUnlessRequired: (source: ResolvedDriftSource) => boolean;
67
+ /** The path, or a failure that says exactly what is missing and how to supply it. */
68
+ export declare const demandDriftSource: (source: ResolvedDriftSource) => string;
69
+ /**
70
+ * A one-line, always-visible statement of what was (or was not) measured.
71
+ * A silent skip is how a blind guard hides, so every source prints either way.
72
+ */
73
+ export declare const describeDriftSource: (source: ResolvedDriftSource) => string;
74
+ /**
75
+ * The ref to compare a source checkout against when asking "is this copy
76
+ * current?".
77
+ *
78
+ * Three shapes have to work: a laptop clone (has `origin/main`), an
79
+ * `actions/checkout` of another repo (has a remote-tracking ref, but the branch
80
+ * name is the repo's default and not necessarily `main`), and anything else.
81
+ * Returns undefined rather than guessing — the caller must treat "cannot
82
+ * determine" as a failure, never as a clean result.
83
+ */
84
+ export declare const upstreamRefFor: (repoDir: string) => string | undefined;
85
+ /**
86
+ * The canonical text of a file, READ FROM THE UPSTREAM REF rather than from a
87
+ * working tree.
88
+ *
89
+ * 🔴 WHY THIS EXISTS (2026-09-18). The conformance guards used to read
90
+ * `AGENT_PROTOCOL.md` off the working tree of the shared bulletin clone, and
91
+ * fail when that tree differed from `origin/main` with the remedy
92
+ * `git -C <repo> pull --ff-only`. Both halves are wrong, and they are wrong in
93
+ * a way that compounds:
94
+ *
95
+ * 1. **Nothing ever pulls that clone, by design.** Since 2026-08-29 every
96
+ * session takes a linked WORKTREE from it and works there; the shared tree
97
+ * itself carries a `pre-commit` guard that REFUSES commits and is left
98
+ * alone on purpose. Measured today it was **79 commits behind origin/main**
99
+ * and dirty with three other sessions' in-flight files.
100
+ * 2. **So the guard's remedy instructs an action the coordination protocol
101
+ * forbids** — `agent-workspace.sh` prints "do not pull it, do not commit
102
+ * it" about that exact directory. A guard whose only fix is a prohibited
103
+ * command is a guard that will be muted, and muting it restores the blind
104
+ * spot it was built to close.
105
+ *
106
+ * Reading the ref removes the dependency on any checkout's currency: the
107
+ * baseline is whatever `origin/main` holds, fetched at the moment we ask. That
108
+ * is strictly stronger than "the working tree happens to match", which is all
109
+ * the old test could assert.
110
+ *
111
+ * It THROWS rather than falling back to the working file. A fallback here would
112
+ * silently restore the stale-canon comparison this replaces, and the whole
113
+ * point of the drift-sources rework is that an unverifiable baseline must never
114
+ * render as a clean one ([[zero-is-not-a-pass]]).
115
+ */
116
+ export interface CanonicalRead {
117
+ /** The file's contents at `ref`. */
118
+ readonly text: string;
119
+ /** Which ref was treated as upstream — say it, never infer it. */
120
+ readonly ref: string;
121
+ /** The commit the text was read from, short form. */
122
+ readonly sha: string;
123
+ /**
124
+ * How the ref we read got to be the ref we read. Three states, not a boolean:
125
+ * a fetch we CHOSE not to run and a fetch that FAILED are different facts, and
126
+ * collapsing them into `false` would report a CI run — where skipping is
127
+ * correct and deliberate — as "the remote was unreachable". That is the
128
+ * [[zero-is-not-a-pass]] shape applied to our own telemetry.
129
+ */
130
+ readonly refreshed: "fetched" | "skipped" | "unreachable";
131
+ }
132
+ export interface ReadCanonicalOptions {
133
+ /**
134
+ * Refresh the ref from the remote before reading it. Default true.
135
+ *
136
+ * 🔴 Pass `false` for a CI checkout. `actions/checkout` provisions the repo at
137
+ * run start, so its ref is current by construction and a fetch buys nothing —
138
+ * but it COSTS, and on 2026-09-18 that cost was a red build: the fetch ran
139
+ * past vitest's 5 s per-test budget on the runner while finishing instantly on
140
+ * the laptop. Local green, CI red, for a network call that was pure overhead.
141
+ */
142
+ readonly fetch?: boolean;
143
+ }
144
+ export declare const readCanonicalFile: (repoDir: string, relPath: string, options?: ReadCanonicalOptions) => CanonicalRead;
@@ -0,0 +1,204 @@
1
+ /**
2
+ * The three CROSS-REPO sources this repo's drift guards read — and the switch
3
+ * that decides whether their ABSENCE is allowed to be silent.
4
+ *
5
+ * WHY THIS FILE EXISTS
6
+ * --------------------
7
+ * Six of this suite's tests compare something this CLI emits against the
8
+ * canonical text it claims to mirror. All three canonical texts live in OTHER
9
+ * private repos, so until 2026-09-13 every one of those tests was written as
10
+ * `it.skipIf(!existsSync(pathOnKerrysLaptop))`.
11
+ *
12
+ * That was correct when nothing else could reach them, and it became the
13
+ * problem the moment CI existed: the coordination-pointer conformance byte-diff
14
+ * — built in v0.30.0 *after* the emitted pointer had drifted to a 62%-similar
15
+ * paraphrase that four fingerprint bumps missed — ran on exactly one machine,
16
+ * and it was the machine CI exists to stop trusting.
17
+ *
18
+ * THE PART THAT IS NOT ABOUT CREDENTIALS
19
+ * --------------------------------------
20
+ * Granting CI read access to those repos is necessary and not sufficient. A
21
+ * skip reads as green, so if the token lapses, the checkout silently fails, or
22
+ * a file is renamed upstream, the guards return to not running and NOTHING GOES
23
+ * RED. We would be paying for a credential with no guarantee it is still in
24
+ * use — which is [[zero-is-not-a-pass]] wearing a purchase order.
25
+ *
26
+ * So absence is configurable, and the two audiences get opposite defaults:
27
+ *
28
+ * - a contributor's laptop (no env var): missing source => SKIP, as before.
29
+ * - CI (`Z2W_REQUIRE_DRIFT_SOURCES=1`): missing source => HARD FAILURE.
30
+ *
31
+ * RESOLUTION IS REPORTED, NOT JUST PERFORMED
32
+ * ------------------------------------------
33
+ * Each source is found by walking a list of candidate paths, and taking the
34
+ * first that exists is selection by POSITION, not by evidence — a named trap in
35
+ * [[zero-is-not-a-pass]]. The stale bulletin clone that sat 215 commits behind
36
+ * while a guard reported a shrinking gap was exactly this. So every resolution
37
+ * carries WHICH candidate won and WHY, and the suite prints it.
38
+ */
39
+ import { execFileSync } from "node:child_process";
40
+ import { existsSync } from "node:fs";
41
+ import { homedir } from "node:os";
42
+ import { isAbsolute, join, resolve } from "node:path";
43
+ /** Where CI drops the sibling checkouts. Overridable so the layout is not magic. */
44
+ export const driftSourcesDir = () => {
45
+ const dir = process.env.Z2W_DRIFT_SOURCES_DIR ?? ".drift-sources";
46
+ return isAbsolute(dir) ? dir : resolve(process.cwd(), dir);
47
+ };
48
+ /**
49
+ * `1` means a missing source is a FAILURE, not a skip. CI sets it; laptops
50
+ * don't. Deliberately an opt-IN to strictness rather than an opt-out: a
51
+ * contributor who has none of these repos must still be able to run the suite.
52
+ */
53
+ export const driftSourcesRequired = () => process.env.Z2W_REQUIRE_DRIFT_SOURCES === "1";
54
+ const SPECS = {
55
+ coordination: {
56
+ repo: "z2w-agent-coordination",
57
+ relPath: "AGENT_PROTOCOL.md",
58
+ localCandidates: () => [
59
+ // Since 2026-08-29 these are ONE clone (the Desktop path is a symlink),
60
+ // but both spellings are kept so a machine that predates that still works.
61
+ join(homedir(), "Desktop/Zero2Webmaster/AI/Cursor Projects/z2w-agent-coordination/AGENT_PROTOCOL.md"),
62
+ join(homedir(), ".cache/z2w-coordination/AGENT_PROTOCOL.md"),
63
+ ],
64
+ guards: "the emitted Agent Coordination pointer is upstream's steps 1 + 1b VERBATIM, " +
65
+ "and the fingerprint we stamp is the one upstream publishes",
66
+ },
67
+ templates: {
68
+ repo: "cursor-project-templates",
69
+ relPath: "Resources/CAPTURE_LEARNINGS_BLOCK.md",
70
+ localCandidates: () => [
71
+ join(homedir(), "Desktop/Zero2Webmaster/AI/Templates/Resources/CAPTURE_LEARNINGS_BLOCK.md"),
72
+ ],
73
+ guards: "the emitted Capture Learnings block is byte-identical to the canonical source",
74
+ },
75
+ skill: {
76
+ repo: "z2w-skill-vault",
77
+ relPath: "instantiate-z2w-project/references/standards-block.md",
78
+ localCandidates: () => [
79
+ // On the laptop this resolves through the Vault's sync.sh symlink.
80
+ join(homedir(), ".claude/skills/instantiate-z2w-project/references/standards-block.md"),
81
+ join(homedir(), "Desktop/Zero2Webmaster/AI/Skill Vault/instantiate-z2w-project/references/standards-block.md"),
82
+ ],
83
+ guards: "OP #2 reverse mirror — no standard exists in the skill that this CLI fails to emit",
84
+ },
85
+ };
86
+ /** Find one source. Never throws — callers decide what absence means. */
87
+ export const resolveDriftSource = (name) => {
88
+ const spec = SPECS[name];
89
+ const ciPath = join(driftSourcesDir(), spec.repo, spec.relPath);
90
+ const localCandidates = spec.localCandidates();
91
+ const candidatesTried = [ciPath, ...localCandidates];
92
+ // CI's explicitly provisioned checkout outranks whatever is ambiently lying
93
+ // around, so a runner can never accidentally measure a developer's stale copy.
94
+ if (existsSync(ciPath)) {
95
+ return { name, repo: spec.repo, guards: spec.guards, path: ciPath, origin: "ci-checkout", candidatesTried };
96
+ }
97
+ const local = localCandidates.find((p) => existsSync(p));
98
+ if (local) {
99
+ return { name, repo: spec.repo, guards: spec.guards, path: local, origin: "local", candidatesTried };
100
+ }
101
+ return { name, repo: spec.repo, guards: spec.guards, origin: "absent", candidatesTried };
102
+ };
103
+ /**
104
+ * The `skipIf` condition. Skip ONLY when the source is missing AND nobody has
105
+ * declared it mandatory. Under `Z2W_REQUIRE_DRIFT_SOURCES=1` this returns false
106
+ * even with no file, so the test RUNS and `demandDriftSource` fails it loudly.
107
+ */
108
+ export const skipUnlessRequired = (source) => !source.path && !driftSourcesRequired();
109
+ /** The path, or a failure that says exactly what is missing and how to supply it. */
110
+ export const demandDriftSource = (source) => {
111
+ if (source.path)
112
+ return source.path;
113
+ const spec = SPECS[source.name];
114
+ throw new Error(`Drift source "${source.name}" is REQUIRED here and was not found.\n` +
115
+ ` What stops being checked: ${source.guards}.\n` +
116
+ ` Expected: zero2webmaster/${spec.repo} -> ${spec.relPath}\n` +
117
+ ` Looked in, in order:\n${source.candidatesTried.map((p) => ` - ${p}`).join("\n")}\n` +
118
+ ` On a runner this means the checkout did not happen: the app token is missing or\n` +
119
+ ` expired, the App is not installed on ${spec.repo}, or the file moved upstream.\n` +
120
+ ` This is deliberately a FAILURE and not a skip — see src/drift-sources.ts.`);
121
+ };
122
+ /**
123
+ * A one-line, always-visible statement of what was (or was not) measured.
124
+ * A silent skip is how a blind guard hides, so every source prints either way.
125
+ */
126
+ export const describeDriftSource = (source) => source.path
127
+ ? `[drift source: ${source.name}] using ${source.origin} copy at ${source.path}`
128
+ : `[drift source: ${source.name}] ABSENT — not measured. This is NOT a pass.`;
129
+ /**
130
+ * The ref to compare a source checkout against when asking "is this copy
131
+ * current?".
132
+ *
133
+ * Three shapes have to work: a laptop clone (has `origin/main`), an
134
+ * `actions/checkout` of another repo (has a remote-tracking ref, but the branch
135
+ * name is the repo's default and not necessarily `main`), and anything else.
136
+ * Returns undefined rather than guessing — the caller must treat "cannot
137
+ * determine" as a failure, never as a clean result.
138
+ */
139
+ export const upstreamRefFor = (repoDir) => {
140
+ const git = (args) => {
141
+ try {
142
+ return execFileSync("git", args, { cwd: repoDir, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
143
+ }
144
+ catch {
145
+ return undefined;
146
+ }
147
+ };
148
+ // `origin/HEAD` is the honest answer when it exists: it names the default
149
+ // branch rather than assuming one.
150
+ const head = git(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"]);
151
+ if (head)
152
+ return head;
153
+ for (const ref of ["origin/main", "origin/master"]) {
154
+ if (git(["rev-parse", "--verify", "--quiet", ref]))
155
+ return ref;
156
+ }
157
+ // Last resort: ask the remote directly. A shallow CI checkout still answers.
158
+ if (git(["fetch", "--depth=1", "--quiet", "origin", "HEAD"]) !== undefined) {
159
+ if (git(["rev-parse", "--verify", "--quiet", "FETCH_HEAD"]))
160
+ return "FETCH_HEAD";
161
+ }
162
+ return undefined;
163
+ };
164
+ export const readCanonicalFile = (repoDir, relPath, options = {}) => {
165
+ const git = (args) => execFileSync("git", args, {
166
+ cwd: repoDir,
167
+ encoding: "utf8",
168
+ stdio: ["ignore", "pipe", "pipe"],
169
+ timeout: 15_000,
170
+ // Never let git stop and ask for a password. Without this a credential-less
171
+ // fetch BLOCKS instead of failing, which reads as a hang rather than as the
172
+ // recoverable "remote unreachable" this function is designed to tolerate.
173
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "echo" },
174
+ });
175
+ // Best-effort refresh. A failure here is NOT fatal — an offline laptop and a
176
+ // CI runner that just checked the repo out both have a usable ref already —
177
+ // but whether it happened is reported rather than assumed.
178
+ let refreshed = "skipped";
179
+ if (options.fetch !== false) {
180
+ try {
181
+ git(["fetch", "--quiet", "origin"]);
182
+ refreshed = "fetched";
183
+ }
184
+ catch {
185
+ refreshed = "unreachable";
186
+ }
187
+ }
188
+ const ref = upstreamRefFor(repoDir);
189
+ if (!ref) {
190
+ throw new Error(`cannot determine the upstream ref for ${repoDir}, so there is no baseline to compare ` +
191
+ `against. Failing on purpose: an unverifiable baseline is not a clean one.`);
192
+ }
193
+ let text;
194
+ try {
195
+ text = git(["show", `${ref}:${relPath}`]);
196
+ }
197
+ catch (err) {
198
+ throw new Error(`cannot read ${relPath} at ${ref} in ${repoDir} (${err.message}). ` +
199
+ `Failing on purpose rather than falling back to the working tree, which is ` +
200
+ `${refreshed === "fetched" ? "" : "possibly "}stale and which nothing is allowed to pull.`);
201
+ }
202
+ const sha = git(["rev-parse", "--short", ref]).trim();
203
+ return { text, ref, sha, refreshed };
204
+ };
@@ -78,7 +78,7 @@ export interface StandardsResolution {
78
78
  * family — the safe default for anything else with `has_web_ui=true`.
79
79
  */
80
80
  export declare function fathomEnvVarFor(projectType: ProjectType): string;
81
- export declare const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.33";
81
+ export declare const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.34";
82
82
  /**
83
83
  * The canonical **Capture Learnings** block, emitted VERBATIM into every
84
84
  * scaffolded `CLAUDE.md`.
package/dist/standards.js CHANGED
@@ -475,7 +475,7 @@ const NEON_CAREFUL_BODY = `### Neon-careful (Neon Postgres)
475
475
  // Two consecutive handoffs compared this constant against the DOCUMENT version
476
476
  // and reported a "15-version gap" that did not exist — the real gap was 4. Read
477
477
  // the `<!-- ... canonical-block vX.Y.Z -->` comment, never the `**Version:**` line.
478
- export const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.33";
478
+ export const CANONICAL_COORDINATION_BLOCK_VERSION = "v0.1.34";
479
479
  /**
480
480
  * The canonical **Capture Learnings** block, emitted VERBATIM into every
481
481
  * scaffolded `CLAUDE.md`.
@@ -606,6 +606,7 @@ This project participates in the Z2W cross-project coordination bulletin.
606
606
  - **Private repo only.** The bulletin must remain \`--visibility private\`.
607
607
  - **Never edit another project's file directly.** Cross-project signaling goes through \`[→ {their-project}]\` prefixes in the target's \`## Open questions\` section.
608
608
  - **Append-only within sections.** Trimming expired entries is a separate operation flagged in the commit message.
609
+ - **A worktree isolates your INDEX and WORKING TREE, and nothing else.** \`config\`, remotes, refs, hooks and the \`stash\` stack all belong to the REPOSITORY and are shared with the shared clone and every other worktree. So a throwaway worktree is not a disposable repo: \`git remote remove\`, \`git config\`, \`git branch -D\`, \`git stash\` and \`git gc\` reach the whole repository from inside it — one session disarmed a repo's \`origin\` this way (2026-09-18) and nothing in its output looked wrong. When you are finished, REMOVE the worktree; never tidy it with a command that writes to config, remotes, refs or the stash. And never move in-flight edits with \`git stash\` — \`refs/stash\` is one stack per repository, so a bare \`git stash pop\` takes whoever stashed last. Copy the files instead, or take your worktree at session START so there is nothing to move. [[shared-clone-concurrency]]
609
610
 
610
611
  Reference the protocol's conventions by NAME, never by §-number — the numbering renumbers upstream, and step 1b gives you the live text anyway.
611
612
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zero2webmaster/starter-kit",
3
- "version": "0.30.0",
3
+ "version": "0.31.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",