shapeup-sdlc 3.1.2 → 3.3.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.
Files changed (41) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +7 -6
  3. package/README.md +1 -1
  4. package/SECURITY.md +4 -1
  5. package/bin/init.mjs +3 -0
  6. package/commands/retro.md +19 -2
  7. package/commands/ship.md +5 -0
  8. package/hooks/dispatch-receipt.mjs +6 -3
  9. package/hooks/gate-intake.mjs +1 -1
  10. package/hooks/gate-zerowork.mjs +5 -2
  11. package/hooks/lib/decision.mjs +49 -6
  12. package/hooks/safety-spine.mjs +8 -5
  13. package/hooks/sandbox-guard.mjs +13 -6
  14. package/kernel/compile.mjs +112 -6
  15. package/kernel/harness.mjs +11 -5
  16. package/kernel/init/run.mjs +122 -6
  17. package/kernel/lib/breadboard.mjs +165 -0
  18. package/kernel/lib/paths.mjs +15 -3
  19. package/kernel/probe/owner.mjs +139 -0
  20. package/kernel/probe/resume.mjs +7 -1
  21. package/kernel/probe/stats.mjs +49 -2
  22. package/kernel/reduce/hill.mjs +12 -2
  23. package/kernel/verify/build.mjs +319 -0
  24. package/kernel/verify/spec.mjs +190 -2
  25. package/package.json +1 -1
  26. package/skills/ba-pitch-analyzer/SKILL.md +11 -5
  27. package/skills/ba-pitch-analyzer/assets/templates/_index.tmpl.md +2 -1
  28. package/skills/ba-pitch-analyzer/assets/templates/ux-behavior.tmpl.md +12 -2
  29. package/skills/ba-pitch-analyzer/references/doc-schemas.md +3 -0
  30. package/skills/ba-pitch-analyzer/references/ux-behavior-patterns.md +9 -0
  31. package/skills/coach/SKILL.md +232 -43
  32. package/skills/orient/SKILL.md +15 -5
  33. package/skills/qa-edge-hunter/SKILL.md +3 -2
  34. package/skills/scope-architect/SKILL.md +7 -0
  35. package/skills/scope-hammer/SKILL.md +13 -0
  36. package/skills/solution-architect/SKILL.md +7 -2
  37. package/skills/tech-lead/SKILL.md +7 -7
  38. package/skills/tech-lead/references/gates.md +69 -17
  39. package/skills/tech-lead/references/protocol.md +33 -8
  40. package/skills/tech-lead/schemas/domain.schema.json +180 -9
  41. package/skills/tech-lead/workflows/shapeup-run.js +54 -12
@@ -20,7 +20,7 @@
20
20
  // Usage: node `harness probe stats` [--cwd <dir>] [--metrics-dir <dir>] [--slug <slug>] [--format json|table]
21
21
 
22
22
  import { readFileSync, readdirSync, existsSync } from "node:fs";
23
- import { resolve, join } from "node:path";
23
+ import { resolve, join, relative, sep } from "node:path";
24
24
  import { validate } from "../verify/envelope.mjs";
25
25
  import { runArgs } from "../lib/argv.mjs";
26
26
  import { localDir, decisions as decisionsPath, metricsDir as metricsDirPath, SHARED } from "../lib/paths.mjs";
@@ -283,6 +283,49 @@ export function readDecisions(cwd) {
283
283
  } catch { return []; }
284
284
  }
285
285
 
286
+ /**
287
+ * Decision ledgers that landed OUTSIDE the project root — the trace a hook left when it filed
288
+ * under the shell's working directory instead of the project's.
289
+ *
290
+ * The hooks now resolve the root themselves, so a stray is either history from before that fix or
291
+ * evidence the resolver missed a layout; either way the rows in it are missing from the ledger
292
+ * `--hooks` reads, and a count that silently omits them is the inert-layer signature this report
293
+ * exists to expose. Bounded walk: depth-limited, skipping dependency and VCS directories.
294
+ *
295
+ * @param {string} cwd - Project root.
296
+ * @param {number} [maxDepth=8] - How deep to look.
297
+ * @returns {Array<{path:string, rows:number}>} Each stray ledger and its row count.
298
+ */
299
+ export function strayLedgers(cwd, maxDepth = 8) {
300
+ const SKIP = new Set(["node_modules", ".git", ".hg", ".svn", ".hvigor", ".idea", "dist", "build", "target", ".next", ".cache"]);
301
+ const out = [];
302
+ const home = decisionsPath(cwd);
303
+ /**
304
+ * Visit one directory level.
305
+ * @param {string} dir - Directory to scan.
306
+ * @param {number} depth - Its depth below `cwd`.
307
+ * @returns {void}
308
+ */
309
+ const walk = (dir, depth) => {
310
+ if (depth > maxDepth) return;
311
+ let entries;
312
+ try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
313
+ for (const e of entries) {
314
+ if (!e.isDirectory() || SKIP.has(e.name)) continue;
315
+ const sub = join(dir, e.name);
316
+ const candidate = decisionsPath(sub);
317
+ if (candidate !== home && existsSync(candidate)) {
318
+ let rows = 0;
319
+ try { rows = readFileSync(candidate, "utf8").split("\n").filter((l) => l.trim()).length; } catch { /* unreadable */ }
320
+ out.push({ path: relative(cwd, candidate).split(sep).join("/"), rows });
321
+ }
322
+ walk(sub, depth + 1);
323
+ }
324
+ };
325
+ walk(cwd, 1);
326
+ return out;
327
+ }
328
+
286
329
  /**
287
330
  * Render a StatsReport as a human-readable fixed-width table.
288
331
  * @param {object} report - A validated StatsReport (see {@link aggregate}).
@@ -382,6 +425,10 @@ function renderHooks(r) {
382
425
  lines.push("", "(zero rows: either no hook has run in this checkout, or the enforcement layer is inert —");
383
426
  lines.push(" and that distinction is exactly what this ledger exists to make.)");
384
427
  }
428
+ if (Array.isArray(r.stray_ledgers) && r.stray_ledgers.length) {
429
+ lines.push("", `stray ledgers: ${r.stray_ledgers.length} decisions.jsonl outside the project root — rows not counted above:`);
430
+ for (const s of r.stray_ledgers) lines.push(` ${s.path} (${s.rows} row(s))`);
431
+ }
385
432
  return lines.join("\n");
386
433
  }
387
434
 
@@ -403,7 +450,7 @@ export async function cli(rawArgv) {
403
450
  if (args.ratchet || args.hooks) {
404
451
  const out = {};
405
452
  if (args.ratchet) out.ratchet = ratchetReport(readAllTrials(cwd, args.slug ?? null));
406
- if (args.hooks) out.hooks = hooksReport(readDecisions(cwd));
453
+ if (args.hooks) out.hooks = { ...hooksReport(readDecisions(cwd)), stray_ledgers: strayLedgers(cwd) };
407
454
  if (format === "table") {
408
455
  const parts = [];
409
456
  if (out.ratchet) parts.push(renderRatchet(out.ratchet));
@@ -9,6 +9,7 @@ import { runArgs } from "../lib/argv.mjs";
9
9
  import { scopesDir, hillDir, verdictsDir, resultsDir, discoveryLedger } from "../lib/paths.mjs";
10
10
  import { readAllContracts, SCOPE_CONTRACT } from "../lib/contract.mjs";
11
11
  import { evalVerdict } from "../probe/eval.mjs";
12
+ import { redBuildRounds } from "../verify/build.mjs";
12
13
 
13
14
  /**
14
15
  * Derive and write the hill phase for all scopes mechanically based on T0, T1, and ledger facts.
@@ -16,7 +17,7 @@ import { evalVerdict } from "../probe/eval.mjs";
16
17
  * The derived phase follows these progression rules (facts move dots, not authors):
17
18
  * - UPHILL_UNKNOWN: open unknowns > 0 in the ledger for this scope
18
19
  * - UPHILL_SOLVED: unknowns 0, no T0-green yet
19
- * - DOWNHILL_EXECUTION: ≥1 T0-green; T1/seesaw pending
20
+ * - DOWNHILL_EXECUTION: ≥1 T0-green in a round whose build gate is not red; T1/seesaw pending
20
21
  * - FINISHED: T1 PASS ∧ seesaw green
21
22
  *
22
23
  * @param {string} cwd - The project root directory.
@@ -52,6 +53,15 @@ export function deriveHill(cwd, slug) {
52
53
  }
53
54
 
54
55
  // 2. T0 facts per scope: has it achieved a green overall verdict? was seesaw also green?
56
+ //
57
+ // MINUS THE ROUNDS WHOSE BUILD GATE IS RED. A T0 verdict is one scope's fixtures inside its own
58
+ // substrate; the round build gate (`verify build`) is the feature's build and launch. Measured on
59
+ // a live run, all fourteen committed shards read DOWNHILL_EXECUTION off T0 verdicts from rounds in
60
+ // which the app never compiled and never launched — the dashboard showed a feature going downhill
61
+ // that had not started. A green fixture in a round the gate failed is not evidence the scope
62
+ // works; it is evidence the fixture does not test the build. No gate artifact at all leaves every
63
+ // verdict counting exactly as before.
64
+ const redRounds = redBuildRounds(cwd, slug);
55
65
  const t0Facts = {};
56
66
  if (existsSync(vDir)) {
57
67
  for (const f of readdirSync(vDir)) {
@@ -59,7 +69,7 @@ export function deriveHill(cwd, slug) {
59
69
  try {
60
70
  const b = JSON.parse(readFileSync(join(vDir, f), "utf8"));
61
71
  if (!t0Facts[b.scope_id]) t0Facts[b.scope_id] = { hasGreen: false, seesawGreen: false };
62
- if (b.overall === "green") {
72
+ if (b.overall === "green" && !redRounds.has(Number(b.round))) {
63
73
  t0Facts[b.scope_id].hasGreen = true;
64
74
  // Read the REAL seesaw result off the verdict artifact (`t0.mjs`'s `writeArtifact()`
65
75
  // already persists the full `{ran, pass, scopes_checked, failing}` object), rather than
@@ -0,0 +1,319 @@
1
+ #!/usr/bin/env node
2
+ // The round build gate — does the FEATURE build and launch, before the judge is asked about it.
3
+ //
4
+ // WHY A GATE ABOVE T0. A T0 verdict is one scope's fixtures, run inside that scope's substrate, and
5
+ // the fixtures are the scope-architect's to write. Nothing in that layer proves the feature as a
6
+ // whole compiles or starts. Measured on a live mobile run: every one of 30 T0 trials went green on
7
+ // its first try — the fixtures were TypeScript stand-ins, structural greps and a test-suite wrapper
8
+ // that never compiled its sources — while the ledger's own `run_cmd` failed, and once the compiler
9
+ // could actually reach the new files it reported 58 errors. Three rounds of EVAL then graded a
10
+ // blank screen: nothing in the loop had ever installed or launched the app. The hill shards, derived
11
+ // from those T0 verdicts, all read DOWNHILL_EXECUTION.
12
+ //
13
+ // Two lessons, and this gate is both:
14
+ //
15
+ // 1. A green exit code from the build is not proof the feature compiled. Some toolchains compile
16
+ // only what is reachable from an entry point, so a scope's files can sit outside the compiled
17
+ // set and the build stays green. The exit code is the necessary half; `build_probe` is where a
18
+ // project asserts the other half (the artifact covers what the run wrote), in whatever way its
19
+ // toolchain makes possible.
20
+ // 2. Nothing else in the loop launches the app. `launch_probe` is where a project installs, starts
21
+ // and asserts a first screen. For the mobile archetype its absence is called out every round,
22
+ // because "on-device install unverified" was an L0 risk with no owner for three rounds.
23
+ //
24
+ // WHAT RUNS, in order, each stopping the rest on failure: the ledger's `run_cmd` (the build),
25
+ // then the profile's `build_probe`, then its `launch_probe`. All three are commands the tech lead
26
+ // pinned at GATE L0 — this script invents none of them, and a run that declares none of them gets
27
+ // exit 3 and no artifact, which every reader treats as "no gate declared" rather than as green.
28
+ //
29
+ // THE RED GATE IS THE NEXT ROUND'S BUG LIST. `harness compile` reads the latest gate artifact for
30
+ // the previous round and addresses each failing step to the scopes whose substrate contains the
31
+ // files the output names (unowned → every scope, marked), exactly as it does for an EVAL verdict.
32
+ // `reduce hill` reads the same artifact: a T0-green verdict from a round whose gate is red moves no
33
+ // scope downhill. Both are the same file, written once here — zero LLM tokens, same as T0.
34
+ //
35
+ // Usage:
36
+ // node "${CLAUDE_PLUGIN_ROOT}/kernel/harness.mjs" verify build --slug <slug> --round N [--cwd <dir>]
37
+ //
38
+ // Exit code: 0 = green, 1 = red, 2 = bad argv, 3 = nothing declared (no run_cmd, no probes).
39
+
40
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync } from "node:fs";
41
+ import { join, resolve } from "node:path";
42
+ import { spawnSync } from "node:child_process";
43
+ import { createHash } from "node:crypto";
44
+ import { runArgs, isMain } from "../lib/argv.mjs";
45
+ import { harnessRun, projectProfile, roundBuildDir, localRoot, runIdFromRoot } from "../lib/paths.mjs";
46
+ import { readContract, readAllContracts, PROJECT_PROFILE, SCOPE_CONTRACT, splitFrontmatter } from "../lib/contract.mjs";
47
+ import { scopesDir } from "../lib/paths.mjs";
48
+ import { digest } from "../probe/digest.mjs";
49
+
50
+ /** The three steps, in the order they run. */
51
+ export const STEPS = ["run_cmd", "build_probe", "launch_probe"];
52
+
53
+ /** Archetypes whose product cannot be judged without being launched on a device or simulator. */
54
+ export const LAUNCH_REQUIRED_ARCHETYPES = new Set(["mobile"]);
55
+
56
+ const TAIL_BYTES = 8 * 1024;
57
+ const tail = (s) => (s || "").length > TAIL_BYTES ? (s || "").slice(-TAIL_BYTES) : (s || "");
58
+
59
+ /**
60
+ * The commands this gate runs for a feature, read from the artifacts that declare them.
61
+ *
62
+ * `run_cmd` comes from the run ledger's frontmatter (`harness-run.md`, written at GATE L0 and
63
+ * already what every EVAL order carries); the two probes come from the committed project profile.
64
+ * Nothing is inferred: an absent field is an absent step.
65
+ *
66
+ * @param {string} cwd - Project root.
67
+ * @param {string} slug - Feature slug.
68
+ * @returns {{archetype:(string|null), steps:Array<{kind:string, cmd:string}>, warnings:string[]}}
69
+ * The declared steps in run order, the profile's archetype, and the warnings a reader should
70
+ * see — currently one: a launch-required archetype with no `launch_probe`.
71
+ */
72
+ export function declaredSteps(cwd, slug) {
73
+ const warnings = [];
74
+ let runCmd = null;
75
+ try {
76
+ const hr = splitFrontmatter(readFileSync(harnessRun(cwd, slug), "utf8")).meta || {};
77
+ runCmd = typeof hr.run_cmd === "string" && hr.run_cmd.trim() ? hr.run_cmd.trim() : null;
78
+ } catch { /* no ledger — no run_cmd */ }
79
+
80
+ let profile = null;
81
+ const pp = projectProfile(cwd, slug);
82
+ if (existsSync(pp)) profile = readContract(pp, PROJECT_PROFILE)?.contract || null;
83
+ const archetype = typeof profile?.archetype === "string" ? profile.archetype : null;
84
+ const pick = (k) => (typeof profile?.[k] === "string" && profile[k].trim() ? profile[k].trim() : null);
85
+
86
+ const steps = [];
87
+ if (runCmd) { steps.push({ kind: "run_cmd", cmd: runCmd }); warnings.push(...fixtureCoverageWarnings(cwd, slug, runCmd)); }
88
+ else warnings.push("the run ledger declares no run_cmd — the build itself is not part of this gate");
89
+ const buildProbe = pick("build_probe");
90
+ if (buildProbe) steps.push({ kind: "build_probe", cmd: buildProbe });
91
+ const launchProbe = pick("launch_probe");
92
+ if (launchProbe) steps.push({ kind: "launch_probe", cmd: launchProbe });
93
+ else if (archetype && LAUNCH_REQUIRED_ARCHETYPES.has(archetype)) {
94
+ warnings.push(`archetype ${archetype} declares no launch_probe in project-profile.md — nothing in the loop ` +
95
+ `launches the app, so a blank first screen survives every round. Give the install/launch risk an owner: ` +
96
+ `a command that installs the built artifact, starts it, asserts the first screen and fails on fatal logs.`);
97
+ }
98
+ return { archetype, steps, warnings };
99
+ }
100
+
101
+ /**
102
+ * The executable a run command actually invokes — its basename, past any `cd …&&`, `env`, or
103
+ * `VAR=value` prefix. `cd app && DEVECO_SDK_HOME=/x /tools/hvigor/bin/hvigorw assembleHap` → `hvigorw`.
104
+ * @param {string} runCmd - The ledger's run command.
105
+ * @returns {(string|null)} The tool's basename, or null when none can be read.
106
+ */
107
+ export function buildTool(runCmd) {
108
+ const segments = String(runCmd || "").split(/&&|;|\|\|/).map((s) => s.trim()).filter(Boolean);
109
+ for (const seg of segments) {
110
+ const tokens = seg.split(/\s+/).filter((t) => t && !/^[A-Za-z_][A-Za-z0-9_]*=/.test(t) && t !== "env" && t !== "cd");
111
+ if (seg.startsWith("cd ")) continue;
112
+ if (!tokens.length) continue;
113
+ const base = tokens[0].split(/[\\/]/).pop();
114
+ if (base) return base;
115
+ }
116
+ return null;
117
+ }
118
+
119
+ /**
120
+ * Scopes whose fixtures never invoke the build tool `run_cmd` names — ADVISORY.
121
+ *
122
+ * A T0 layer can be entirely green on a feature that does not compile when every fixture is a
123
+ * grep or a stand-in compiler (measured: 13 of 15 fixtures on one run). The harness cannot know
124
+ * what a project's fixtures should run, but it can see when none of a scope's fixture commands
125
+ * mention the tool the ledger builds with, and say so beside the gate's verdict. A warning, not a
126
+ * failure: a library scope with no compiled surface is a legitimate reason for the mismatch.
127
+ *
128
+ * @param {string} cwd - Project root.
129
+ * @param {string} slug - Feature slug.
130
+ * @param {(string|null)} runCmd - The ledger's run command.
131
+ * @returns {string[]} One warning per scope whose fixtures name the tool nowhere.
132
+ */
133
+ export function fixtureCoverageWarnings(cwd, slug, runCmd) {
134
+ const tool = buildTool(runCmd);
135
+ if (!tool) return [];
136
+ const out = [];
137
+ let contracts = [];
138
+ try { contracts = readAllContracts(scopesDir(cwd, slug), SCOPE_CONTRACT).map((x) => x.contract); } catch { return []; }
139
+ for (const c of contracts) {
140
+ const fixtures = Array.isArray(c.e2e_verification_fixtures) ? c.e2e_verification_fixtures : [];
141
+ if (!fixtures.length || fixtures.some((f) => String(f).includes(tool))) continue;
142
+ out.push(`scope ${c.scope_id}: none of its ${fixtures.length} fixture(s) invoke ${tool} (the ledger's build tool) — ` +
143
+ `its T0 green is not evidence the scope compiles; only this gate's run_cmd is.`);
144
+ }
145
+ return out;
146
+ }
147
+
148
+ /**
149
+ * Run one gate command and capture its outcome (10-minute timeout), output tails kept for the digest.
150
+ * @param {{kind:string, cmd:string}} step - The step to run.
151
+ * @param {string} cwd - Working directory.
152
+ * @returns {object} `{kind, cmd, exit, pass, stdout_tail, stderr_tail, error?}`.
153
+ */
154
+ export function runStep(step, cwd) {
155
+ const r = spawnSync(step.cmd, { shell: true, cwd, encoding: "utf8", timeout: 10 * 60 * 1000 });
156
+ const error = r.error ? String(r.error.message || r.error) : null;
157
+ return {
158
+ kind: step.kind, cmd: step.cmd,
159
+ exit: r.status ?? 1, pass: r.status === 0,
160
+ stdout_tail: tail(r.stdout), stderr_tail: tail(r.stderr),
161
+ ...(error ? { error } : {}),
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Run the declared steps in order, stopping at the first failure — a probe over a build that did
167
+ * not complete answers nothing, and would only bury the real error under a second one.
168
+ *
169
+ * @param {Array<{kind:string, cmd:string}>} steps - From {@link declaredSteps}.
170
+ * @param {string} cwd - Working directory.
171
+ * @returns {{overall:("green"|"red"), steps:Array<object>}} Every declared step, the ones not
172
+ * reached marked `skipped: true`.
173
+ */
174
+ export function runGate(steps, cwd) {
175
+ const out = [];
176
+ let failed = false;
177
+ for (const step of steps) {
178
+ if (failed) { out.push({ kind: step.kind, cmd: step.cmd, skipped: true }); continue; }
179
+ const r = runStep(step, cwd);
180
+ out.push(r);
181
+ if (!r.pass) failed = true;
182
+ }
183
+ return { overall: failed ? "red" : "green", steps: out };
184
+ }
185
+
186
+ /**
187
+ * Every gate artifact for a round, oldest first.
188
+ * @param {string} cwd - Project root.
189
+ * @param {string} slug - Feature slug.
190
+ * @param {number} round - Round number.
191
+ * @returns {Array<{path:string, trial:number, body:object}>} Parsed artifacts; unreadable ones skipped.
192
+ */
193
+ export function roundBuildArtifacts(cwd, slug, round) {
194
+ const dir = roundBuildDir(cwd, slug);
195
+ let files;
196
+ try { files = readdirSync(dir); } catch { return []; }
197
+ const out = [];
198
+ for (const f of files) {
199
+ const m = f.match(/^r(\d+)-t(\d+)\.json$/);
200
+ if (!m || Number(m[1]) !== Number(round)) continue;
201
+ try { out.push({ path: join(dir, f), trial: Number(m[2]), body: JSON.parse(readFileSync(join(dir, f), "utf8")) }); }
202
+ catch { /* skip */ }
203
+ }
204
+ return out.sort((a, b) => a.trial - b.trial);
205
+ }
206
+
207
+ /**
208
+ * The gate's latest word on a round — the artifact readers branch on.
209
+ *
210
+ * Latest, because the gate may run again after a hand fix between launches, and the run must act on
211
+ * the current state of the build, not the first one recorded. Every earlier artifact stays on disk.
212
+ *
213
+ * @param {string} cwd - Project root.
214
+ * @param {string} slug - Feature slug.
215
+ * @param {number} round - Round number.
216
+ * @returns {(object|null)} The latest artifact body, or null when the gate never ran for this round.
217
+ */
218
+ export function latestRoundBuild(cwd, slug, round) {
219
+ const all = roundBuildArtifacts(cwd, slug, round);
220
+ return all.length ? all[all.length - 1].body : null;
221
+ }
222
+
223
+ /**
224
+ * The rounds whose latest gate artifact is red — the set `reduce hill` subtracts from.
225
+ * @param {string} cwd - Project root.
226
+ * @param {string} slug - Feature slug.
227
+ * @returns {Set<number>} Round numbers; empty when the gate never ran (non-regression: every
228
+ * T0 verdict then counts exactly as it did before the gate existed).
229
+ */
230
+ export function redBuildRounds(cwd, slug) {
231
+ const latest = new Map();
232
+ let files;
233
+ try { files = readdirSync(roundBuildDir(cwd, slug)); } catch { return new Set(); }
234
+ for (const f of files) {
235
+ const m = f.match(/^r(\d+)-t(\d+)\.json$/);
236
+ if (!m) continue;
237
+ const round = Number(m[1]), trial = Number(m[2]);
238
+ if (!latest.has(round) || latest.get(round).trial < trial) latest.set(round, { trial, file: f });
239
+ }
240
+ const red = new Set();
241
+ for (const [round, { file }] of latest) {
242
+ try {
243
+ if (JSON.parse(readFileSync(join(roundBuildDir(cwd, slug), file), "utf8")).overall === "red") red.add(round);
244
+ } catch { /* unreadable → not proven red */ }
245
+ }
246
+ return red;
247
+ }
248
+
249
+ /**
250
+ * Write the gate artifact immutably (`wx`, next ordinal on collision — the T0 convention).
251
+ * @param {string} cwd - Project root.
252
+ * @param {string} slug - Feature slug.
253
+ * @param {number} round - Round number.
254
+ * @param {object} body - Artifact fields.
255
+ * @returns {{path:string, sha256:string, trial:number}} Where it landed and its digest.
256
+ */
257
+ export function writeRoundBuild(cwd, slug, round, body) {
258
+ const dir = roundBuildDir(cwd, slug);
259
+ mkdirSync(dir, { recursive: true });
260
+ const existing = roundBuildArtifacts(cwd, slug, round);
261
+ for (let trial = (existing.length ? existing[existing.length - 1].trial : 0) + 1; ; trial++) {
262
+ const path = join(dir, `r${round}-t${trial}.json`);
263
+ const text = JSON.stringify({ schema_version: 1, round, trial, at: new Date().toISOString(), ...body }, null, 2);
264
+ try {
265
+ writeFileSync(path, text, { flag: "wx" });
266
+ return { path, sha256: createHash("sha256").update(text).digest("hex"), trial };
267
+ } catch (e) { if (e.code !== "EEXIST") throw e; }
268
+ }
269
+ }
270
+
271
+ export const ARGV_SPEC = {
272
+ usage: "harness.mjs verify build --slug <slug> --round <N> [--cwd <dir>]",
273
+ _: { arity: 0, max: 0, name: "(no positional operands)" },
274
+ slug: { type: "str", required: true },
275
+ round: { type: "int", min: 1, required: true },
276
+ cwd: { type: "path" },
277
+ };
278
+
279
+ /**
280
+ * Run the round build gate and write its artifact.
281
+ *
282
+ * @param {string[]} rawArgv - The subcommand's own arguments (harness.mjs strips the verb words).
283
+ * @returns {Promise<void>} Exits 0 green, 1 red, 3 nothing declared, 2 bad argv.
284
+ */
285
+ export async function cli(rawArgv) {
286
+ const args = runArgs(ARGV_SPEC, rawArgv);
287
+ const cwd = resolve(args.cwd || process.cwd());
288
+ const { slug, round } = args;
289
+ const { archetype, steps, warnings } = declaredSteps(cwd, slug);
290
+ for (const w of warnings) console.error(`build-gate: ${w}`);
291
+
292
+ if (steps.length === 0) {
293
+ console.log(JSON.stringify({ round, overall: "skipped", steps: [], warnings,
294
+ reason: "nothing declared — no run_cmd in the run ledger, no build_probe or launch_probe in project-profile.md" }, null, 2));
295
+ process.exit(3);
296
+ }
297
+
298
+ const gate = runGate(steps, cwd);
299
+ const failing = gate.steps.filter((s) => !s.skipped && !s.pass);
300
+ const discovered = failing.flatMap((s) => digest(`${s.stdout_tail}\n${s.stderr_tail}`));
301
+ const runId = runIdFromRoot(localRoot(cwd, slug));
302
+ const { path, sha256, trial } = writeRoundBuild(cwd, slug, round, {
303
+ ...(runId ? { run_id: runId } : {}),
304
+ archetype,
305
+ overall: gate.overall,
306
+ steps: gate.steps,
307
+ warnings,
308
+ discovered_tasks: discovered.slice(0, 16),
309
+ });
310
+
311
+ console.log(JSON.stringify({
312
+ path, sha256, trial, round, overall: gate.overall, warnings,
313
+ steps: gate.steps.map((s) => (s.skipped ? { kind: s.kind, skipped: true } : { kind: s.kind, exit: s.exit, pass: s.pass })),
314
+ ...(failing.length ? { failed_step: failing[0].kind, stderr_tail: failing[0].stderr_tail.slice(-1200) } : {}),
315
+ }, null, 2));
316
+ process.exit(gate.overall === "green" ? 0 : 1);
317
+ }
318
+
319
+ if (isMain(import.meta.url)) cli(process.argv.slice(2));
@@ -42,6 +42,16 @@
42
42
  // Edge-cases heading with real content under it) but no usecases/UC-*.md declares
43
43
  // a single [INV-NN] anywhere — a criteria-count check can't tell a healthy small
44
44
  // tree from one that silently derived nothing from the pitch
45
+ // BREADBOARD-PLACE (red) a breadboard Place that owns UI affordances has no ux-behavior.md
46
+ // `## Screen: … (P#)` section and is not under `## Deferred Places`
47
+ // BREADBOARD-UI (red) a UI affordance (U#) not cited inside the screen section of any Place the
48
+ // breadboard puts it in. CITING IS NOT PLACING: a U# specified under another Place's
49
+ // screen passes a presence check and is exactly the defect this rule exists for
50
+ // BREADBOARD-TRACE (warn) N#/S# cited nowhere in the spec, V# slices no scope board records,
51
+ // U# the spec places that no manifest entry names as its `source`
52
+ // BREADBOARD-UNPARSED (warn) a staged breadboard this reader finds no ids in — a layout it
53
+ // cannot read must never become a hard stop
54
+ // All four are silent when the run has no breadboard (staged, or inline in the intake).
45
55
  //
46
56
  // Zero dependencies (glob matcher inlined from hooks/sandbox-guard.mjs). Judgment stays in the skill
47
57
  // (gap severity, lens choice); this script only reports facts.
@@ -56,6 +66,8 @@ import { runArgs } from "../lib/argv.mjs";
56
66
  import { LOCAL } from "../lib/paths.mjs";
57
67
  import { specDir, scopesDir, tasksDir, intake, sharedRoot, requirements } from "../lib/paths.mjs";
58
68
  import { readAllContracts, unreadableReason, ucId, scopePartitionConflicts, SCOPE_CONTRACT } from "../lib/contract.mjs";
69
+ import { breadboard as stagedBreadboard } from "../lib/paths.mjs";
70
+ import { parseBreadboard, hasBreadboardTables, idCounts } from "../lib/breadboard.mjs";
59
71
 
60
72
  // Inlined from hooks/sandbox-guard.mjs so this skill ships self-contained (a skill's scripts
61
73
  // must not reach outside its own folder — channels that copy only skills/ would dangle).
@@ -494,12 +506,169 @@ export function lintStructure({ specDir, tasks, intakeContent = "" }) {
494
506
  return findings;
495
507
  }
496
508
 
509
+ /** Every Place id inside a heading's parentheses — `## Screen: Sheet (P2)`, `(P1, P3)`. */
510
+ const PLACE_IN_PARENS = /\(([^)]*)\)/g;
511
+ const PLACE_ID = /\bP\d+(?:\.\d+)*\b/g;
512
+
513
+ /**
514
+ * Cut ux-behavior.md into the screen sections a breadboard's Places are checked against.
515
+ *
516
+ * A section runs from its `Screen:` heading to the next heading at the same level or higher, so
517
+ * a screen's `### States` table and behavior rules belong to it. Its Places are the P# ids in the
518
+ * heading's parentheses; a screen with none is kept (its citations are still "somewhere") but can
519
+ * place nothing.
520
+ *
521
+ * @param {string} uxText - ux-behavior.md, verbatim ("" when absent).
522
+ * @returns {{screens: {heading: string, places: string[], body: string}[], deferred: Set<string>}}
523
+ * The screen sections, and the Place ids listed first-cell under `## Deferred Places`.
524
+ */
525
+ export function uxScreens(uxText) {
526
+ const lines = String(uxText ?? "").split(/\r?\n/);
527
+ const screens = [];
528
+ const deferred = new Set();
529
+ let cur = null; // { level, heading, places, body[] } for a screen, or { level, deferred: true }
530
+ for (const line of lines) {
531
+ const h = line.match(/^(#{1,6})\s+(.*)$/);
532
+ if (h) {
533
+ const level = h[1].length;
534
+ if (cur && level <= cur.level) cur = null;
535
+ if (!cur) {
536
+ const text = h[2].trim();
537
+ if (/^screen\s*:/i.test(text)) {
538
+ const places = [...text.matchAll(PLACE_IN_PARENS)].flatMap((m) => m[1].match(PLACE_ID) ?? []);
539
+ cur = { level, heading: text, places, body: [] };
540
+ screens.push(cur);
541
+ continue;
542
+ }
543
+ if (/^deferred places\b/i.test(text)) { cur = { level, deferred: true }; continue; }
544
+ }
545
+ }
546
+ if (!cur) continue;
547
+ if (cur.deferred) {
548
+ const row = line.match(/^\s*\|\s*([^|]*)\|/);
549
+ const id = row ? row[1].replace(/[*`\[\]]/g, "").match(/^\s*(P\d+(?:\.\d+)*)\b/) : null;
550
+ if (id) deferred.add(id[1]);
551
+ } else cur.body.push(line);
552
+ }
553
+ return {
554
+ screens: screens.map((s) => ({ heading: s.heading, places: s.places, body: s.body.join("\n") })),
555
+ deferred,
556
+ };
557
+ }
558
+
559
+ /**
560
+ * Lint the spec against the pitch's breadboard: every Place with UI affordances has a screen, and
561
+ * every UI affordance is specified on a screen of a Place the breadboard puts it in.
562
+ *
563
+ * PLACEMENT, NOT CITATION. The loss this exists for did not drop a new sheet's affordances — they
564
+ * were all in the spec, inside the composer's state table. What was lost was the Place. A rule that
565
+ * only asks "is U2 cited?" passes that spec; this one asks "is U2 cited under P2?". It checks WHICH
566
+ * screen, never where on the screen: layout inside a Place stays the designer's.
567
+ *
568
+ * Absent breadboard ⇒ zero findings, the same "absent artifact ⇒ arm skipped" rule INV-FLOOR and
569
+ * SCOPE-COVERS follow — every pre-breadboard spec and every run without one is untouched.
570
+ *
571
+ * @param {object} input - What to lint (destructured).
572
+ * @param {string} input.uxText - ux-behavior.md, verbatim ("" when absent).
573
+ * @param {string} input.specText - Every markdown file under the spec tree, concatenated.
574
+ * @param {Array<object>} [input.scopes] - Parsed scope contracts ([] before MAP SCOPES).
575
+ * @param {(string|null)} [input.scopeSummaryText] - scope-summary.md, or null when absent.
576
+ * @param {(string|null)} [input.scopeBoardText] - scope-board.md, or null when absent — the scope
577
+ * architect's own write surface, where it records which scopes deliver each slice.
578
+ * @param {(string|null)} input.bbText - The breadboard, or null when the run has none.
579
+ * @returns {Array<{rule:string, level:("red"|"warn"), detail:string}>} Findings; [] when clean or
580
+ * when there is no breadboard.
581
+ */
582
+ export function lintBreadboard({ uxText = "", specText = "", scopes = [], scopeSummaryText = null, scopeBoardText = null, bbText = null }) {
583
+ if (!bbText) return [];
584
+ const findings = [];
585
+ const bb = parseBreadboard(bbText);
586
+ const counts = idCounts(bb);
587
+ if (Object.values(counts).every((n) => n === 0)) {
588
+ findings.push({ rule: "BREADBOARD-UNPARSED", level: "warn", detail: "the run has a breadboard but no P#/U#/N#/S#/V# ids could be read from its tables — placement was not checked. A `#` or `ID` first column holding the id, and a `Place` column on affordance rows, is the layout this reads" });
589
+ return findings;
590
+ }
591
+
592
+ const { screens, deferred } = uxScreens(uxText);
593
+ /**
594
+ * A Place as a finding names it — id and breadboard name.
595
+ * @param {string} p - Place id.
596
+ * @returns {string} e.g. `P2 Payment Sheet`.
597
+ */
598
+ const name = (p) => {
599
+ const n = bb.places.find((x) => x.id === p)?.name;
600
+ return n ? `${p} ${n}` : p;
601
+ };
602
+ /**
603
+ * Does the text cite this exact id — `U2` but not `U21` or `U2a`?
604
+ * @param {string} text - Markdown to search.
605
+ * @param {string} id - A breadboard id.
606
+ * @returns {boolean} True when the id appears as a whole word.
607
+ */
608
+ const cites = (text, id) => new RegExp(`\\b${id.replace(/\./g, "\\.")}\\b`).test(text);
609
+
610
+ // BREADBOARD-PLACE — a Place with something to place needs a screen of its own.
611
+ const owners = new Map(); // Place → the U# it owns
612
+ for (const u of bb.ui) for (const p of u.places) (owners.get(p) ?? owners.set(p, []).get(p)).push(u.id);
613
+ for (const [p, us] of owners) {
614
+ if (deferred.has(p)) continue;
615
+ if (screens.some((s) => s.places.includes(p))) continue;
616
+ findings.push({ rule: "BREADBOARD-PLACE", level: "red", detail: `${name(p)} owns ${us.join(", ")} but ux-behavior.md has no "## Screen: … (${p})" section — add the screen or defer the Place under "## Deferred Places"; never fold it into another screen` });
617
+ }
618
+
619
+ // BREADBOARD-UI — each U# is specified on a screen of a Place the breadboard puts it in.
620
+ const unplaceable = [];
621
+ for (const u of bb.ui) {
622
+ if (!u.places.length) { unplaceable.push(u.id); continue; }
623
+ const live = u.places.filter((p) => !deferred.has(p));
624
+ if (!live.length) continue;
625
+ if (screens.some((s) => s.places.some((p) => live.includes(p)) && cites(s.body, u.id))) continue;
626
+ const elsewhere = [...new Set(screens.filter((s) => cites(s.body, u.id)).flatMap((s) => s.places.length ? s.places : [`"${s.heading}"`]))];
627
+ const where = elsewhere.length
628
+ ? `is cited only under ${elsewhere.join(", ")}`
629
+ : cites(uxText, u.id) ? "is cited in ux-behavior.md but on no screen" : "is cited on no screen";
630
+ findings.push({ rule: "BREADBOARD-UI", level: "red", detail: `${u.id} (${live.map(name).join(" / ")}) ${where} — specify it in the screen section of its own Place` });
631
+ }
632
+
633
+ // BREADBOARD-TRACE — the rest of the breadboard, reported and never blocking.
634
+ const trace = [];
635
+ const lost = [...bb.code, ...bb.stores].map((x) => x.id).filter((id) => !cites(specText, id));
636
+ if (lost.length) trace.push(`N#/S# cited nowhere in the spec: ${lost.join(", ")}`);
637
+ const slicesText = [scopeSummaryText, scopeBoardText].filter((t) => t !== null && t !== undefined).join("\n");
638
+ if (scopeSummaryText !== null || scopeBoardText !== null) {
639
+ const unsliced = bb.slices.map((v) => v.id).filter((id) => !cites(slicesText, id));
640
+ if (unsliced.length) trace.push(`V# slices no scope board or scope summary records: ${unsliced.join(", ")}`);
641
+ }
642
+ if (scopes.length) {
643
+ const sourced = new Set(scopes.flatMap((s) => (s.affordance_manifest ?? []).map((a) => String(a?.source ?? "").trim())));
644
+ const unsourced = bb.ui.map((u) => u.id).filter((id) => cites(uxText, id) && !sourced.has(id));
645
+ if (unsourced.length) trace.push(`U# the spec places but no manifest entry names as its source: ${unsourced.join(", ")}`);
646
+ }
647
+ if (unplaceable.length) trace.push(`U# with no Place column to check placement against: ${unplaceable.join(", ")}`);
648
+ if (trace.length) findings.push({ rule: "BREADBOARD-TRACE", level: "warn", detail: trace.join("; ") });
649
+ return findings;
650
+ }
651
+
652
+ /**
653
+ * The breadboard a run's spec is linted against: the staged copy, else the intake when it carries
654
+ * one inline, else null — and null switches every BREADBOARD-* rule off.
655
+ * @param {string} cwd - Project root.
656
+ * @param {string} slug - Feature slug.
657
+ * @param {string} intakeContent - The run's intake, verbatim ("" when absent).
658
+ * @returns {(string|null)} The breadboard text, or null when the run has none.
659
+ */
660
+ export function runBreadboard(cwd, slug, intakeContent) {
661
+ const p = stagedBreadboard(cwd, slug);
662
+ if (existsSync(p)) return readFileSync(p, "utf8");
663
+ return hasBreadboardTables(intakeContent) ? intakeContent : null;
664
+ }
665
+
497
666
  /**
498
667
  * Run the full spec lint (scopes + structure) for a slug.
499
668
  * @param {{cwd:string, slug:string}} opts - Working root and feature slug.
500
669
  * @returns {{slug:string, scopes:number, tasks:number, red:number, warn:number,
501
- * findings:Array<object>}} Counts and the combined findings from {@link lintScopes} and
502
- * {@link lintStructure}.
670
+ * findings:Array<object>}} Counts and the combined findings from {@link lintScopes},
671
+ * {@link lintStructure} and, when the run has a breadboard, {@link lintBreadboard}.
503
672
  */
504
673
  export function lint({ cwd, slug }) {
505
674
  const specRoot = specDir(cwd, slug);
@@ -525,6 +694,25 @@ export function lint({ cwd, slug }) {
525
694
  ...lintScopeAnchors({ scopes, specDir: specRoot, reqIds, tasks }),
526
695
  ...lintCommittedTier({ cwd, slug }),
527
696
  ...lintStructure({ specDir: specRoot, tasks, intakeContent }),
697
+ ...(() => {
698
+ const bbText = runBreadboard(cwd, slug, intakeContent);
699
+ if (!bbText) return [];
700
+ /**
701
+ * A file's text, or null when it does not exist.
702
+ * @param {string} p - Absolute path.
703
+ * @returns {(string|null)} The contents, or null.
704
+ */
705
+ const readOr = (p) => (existsSync(p) ? readFileSync(p, "utf8") : null);
706
+ const specFiles = existsSync(specRoot) ? walkFiles(specRoot).filter((f) => f.endsWith(".md")) : [];
707
+ return lintBreadboard({
708
+ uxText: readOr(join(specRoot, "ux-behavior.md")) ?? "",
709
+ specText: specFiles.map((f) => readFileSync(join(specRoot, f), "utf8")).join("\n"),
710
+ scopes,
711
+ scopeSummaryText: readOr(join(specRoot, "scope-summary.md")),
712
+ scopeBoardText: readOr(join(sharedRoot(cwd, slug), "scope-board.md")),
713
+ bbText,
714
+ });
715
+ })(),
528
716
  ];
529
717
  return {
530
718
  slug,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shapeup-sdlc",
3
- "version": "3.1.2",
3
+ "version": "3.3.0",
4
4
  "description": "Shape Up for coding agents \u2014 with gates the agent can't talk its way past. Harness for Claude Code.",
5
5
  "bin": {
6
6
  "shapeup-sdlc": "bin/init.mjs"