muse-crew 0.11.0 → 0.12.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.
@@ -9,7 +9,18 @@
9
9
  // caller appends AFTER this caption. Deterministic: every line is extracted
10
10
  // mechanically from the Crew API, the task's events, and the merge commit —
11
11
  // no LLM prose. The caller (seed/cron-body-template.md Step 6) prints this
12
- // caption verbatim, then the two attachment lines, then logs delivery.
12
+ // caption verbatim, then the two attachment lines (only when the audit
13
+ // harness actually captured screenshots), then logs delivery.
14
+ //
15
+ // Capture guard (2026-09-17, room #14): the composer must SEE the captures
16
+ // before it claims them. It once fabricated "desktop + mobile captures
17
+ // below" for a terminal-surface task with no audit dir at all, and opened
18
+ // with "these screenshots are dropping in" when no screenshots existed. So
19
+ // it resolves the audit dir itself — <home>/workspace/ts-spaces/<deploy_slug>
20
+ // /audits/<auditDir>/, the same root lib/crew-api.js and lib/readback-disk.js
21
+ // resolve — and checks screenshot.png + screenshot-mobile.png are files.
22
+ // Missing deploy_slug, missing dir, or missing PNGs gets the honest
23
+ // no-captures line; terminal surfaces are named, not assumed.
13
24
  //
14
25
  // Usage:
15
26
  // node lib/compose-evidence-caption.js --crew-home <home> \
@@ -19,6 +30,7 @@
19
30
 
20
31
  const { execFileSync } = require("node:child_process");
21
32
  const fs = require("node:fs");
33
+ const os = require("node:os");
22
34
  const path = require("node:path");
23
35
 
24
36
  function usage(msg) {
@@ -76,6 +88,22 @@ try {
76
88
  }
77
89
  const task = (state.tasks || []).find((t) => t.id === taskId);
78
90
  if (!task) usage("task " + taskId + " not found");
91
+ const project = (state.projects || []).find((p) => p.id === task.project);
92
+
93
+ // Capture guard (2026-09-17, room #14): resolve the audit dir the audit
94
+ // harness actually writes and verify the captures exist before claiming
95
+ // them. A bare --audit-dir name is never trusted on its own.
96
+ function isFile(p) {
97
+ try { return fs.statSync(p).isFile(); } catch { return false; }
98
+ }
99
+ let auditPath = null;
100
+ if (project && project.deploy_slug) {
101
+ auditPath = path.join(os.homedir(), "workspace", "ts-spaces",
102
+ project.deploy_slug, "audits", auditDir);
103
+ }
104
+ const hasCaptures = !!(auditPath &&
105
+ isFile(path.join(auditPath, "screenshot.png")) &&
106
+ isFile(path.join(auditPath, "screenshot-mobile.png")));
79
107
 
80
108
  let events = [];
81
109
  try {
@@ -149,8 +177,7 @@ if (!commit) {
149
177
  // task title when the commit is unknown or unreadable.
150
178
  let solution = "";
151
179
  if (commit) {
152
- const proj = (state.projects || []).find((p) => p.id === task.project);
153
- if (proj && proj.repo_path) solution = gitSubject(proj.repo_path, commit);
180
+ if (project && project.repo_path) solution = gitSubject(project.repo_path, commit);
154
181
  }
155
182
  if (!solution) solution = task.title;
156
183
 
@@ -169,16 +196,37 @@ const newestBaselineNote = notesNewest.find((e) => /^baseline:\s*/i.test(e.messa
169
196
  const visualUnavailable = !verdict && !!newestBaselineNote &&
170
197
  /^baseline:\s*none/i.test(newestBaselineNote.message || "");
171
198
 
199
+ const verdictLine = verdict
200
+ ? " QA verdict: " + verdict.status + (verdict.summary ? " — " + trimWords(verdict.summary, 200) : "") + "."
201
+ : " No QA verdict recorded.";
202
+
172
203
  const lines = [];
173
- lines.push("These screenshots are dropping in out of context — quick transition.");
204
+ if (hasCaptures) {
205
+ lines.push("These screenshots are dropping in out of context — quick transition.");
206
+ } else {
207
+ // Honest opener: no screenshots are arriving, so the report says so up
208
+ // front instead of pretending they are dropping in.
209
+ lines.push("QA evidence for this task — no screenshots, so this is the whole report.");
210
+ }
174
211
  lines.push("");
175
212
  lines.push("**" + task.title + "**");
176
213
  lines.push("Problem: " + problem);
177
214
  lines.push("Shipped: " + trimWords(solution, 160) +
178
215
  (commit ? " (commit `" + commit.slice(0, 12) + "`, parent-verified)" : " (provenance not yet stamped)"));
179
- lines.push("Evidence: desktop + mobile captures below, taken by the platform audit harness after deploy (`" + auditDir + "`)." +
180
- (verdict ? " QA verdict: " + verdict.status + (verdict.summary ? " — " + trimWords(verdict.summary, 200) : "") + "." : " No QA verdict recorded."));
181
- if (visualUnavailable) {
216
+ if (hasCaptures) {
217
+ lines.push("Evidence: desktop + mobile captures below, taken by the platform audit harness after deploy (`" + auditDir + "`)." + verdictLine);
218
+ } else {
219
+ // Honest no-captures line (2026-09-17, room #14): never claim captures
220
+ // that do not exist. Terminal surfaces are named, not assumed.
221
+ const surfaceNote = project && project.environment_type === "terminal"
222
+ ? " (terminal surface — QA judges the CLI, not pixels)"
223
+ : "";
224
+ lines.push("Evidence: no screenshots captured for this task" + surfaceNote + " — nothing to attach." + verdictLine);
225
+ }
226
+ if (visualUnavailable && hasCaptures) {
227
+ // The note's premise is the post-deploy capture — without captures it
228
+ // would fabricate evidence again (2026-09-17: the no-captures line above
229
+ // already covers the honest case).
182
230
  lines.push("Note: the visual protocol is unavailable — these are the post-deploy capture plus QA's mechanical checks, not a QA visual inspection.");
183
231
  }
184
232
  process.stdout.write(lines.join("\n") + "\n");
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ // compute-publish-diff.js — deterministic publish-diff computer.
3
+ //
4
+ // Room #14 (2026-09-17): the Publish phase asked an agent to run
5
+ // `git diff "$BASE" "$HEAD"` and return the raw unified diff as a JSON
6
+ // string field. The agent produced the diff correctly on disk but the
7
+ // JSON ferry dropped it — parseUnifiedDiff saw zero files and the task
8
+ // parked at "Publish diff parsed to zero files" for a real, valid
9
+ // 700-line / 23-file diff. General rule: NEVER ferry a deterministic
10
+ // unified diff through an LLM JSON response.
11
+ //
12
+ // This script is the deterministic replacement. The workflow's agent is
13
+ // pure hands — it runs exactly one command (this script) and returns the
14
+ // small JSON summary verbatim. The diff bytes live in a file; the LLM
15
+ // never carries them:
16
+ //
17
+ // node compute-publish-diff.js --repo-path <path> --base <sha> --out <file>
18
+ //
19
+ // --base is the previously-stamped provenance source_commit (or the
20
+ // empty-tree sha 4b825dc642cb6eb9a060e54bf8d69288fbee4904 for a first
21
+ // publish) — the SAME base the workflow read from get-provenance. The
22
+ // script echoes the base it used so the workflow can guard against the
23
+ // agent running the wrong command (fail-closed, as before).
24
+ //
25
+ // Stdout contract: exactly one JSON object, always small (no diff text):
26
+ // { ok:true, commit, base, ancestor:"yes", diff_file, sha256, bytes,
27
+ // file_count, changed_lines, files:[<paths>], has_binary, has_rename }
28
+ // { ok:false, error:"not-ancestor", commit, base } (semantic, exit 0)
29
+ //
30
+ // Exit codes: 0 ok (JSON on stdout) · 2 usage/validation · 1 git/diff/IO
31
+ // failure. On non-zero exit NOTHING is printed to stdout, so a caller
32
+ // must never treat stdout as a summary. Errors go to stderr as JSON.
33
+ //
34
+ // Security: --base must be 40-hex (or the empty tree); --repo-path must
35
+ // be an existing directory; git is invoked via execFileSync with an argv
36
+ // array (no shell). The diff file's parent directories are created.
37
+
38
+ import { execFileSync } from "node:child_process";
39
+ import { createHash } from "node:crypto";
40
+ import { existsSync, mkdirSync, statSync, writeFileSync, readFileSync } from "node:fs";
41
+ import { dirname, resolve } from "node:path";
42
+
43
+ const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
44
+
45
+ function arg(name, required = true) {
46
+ const i = process.argv.indexOf(name);
47
+ if (i < 0 || i + 1 >= process.argv.length) {
48
+ if (!required) return null;
49
+ fail("usage", `${name} is required.`, 2);
50
+ }
51
+ return process.argv[i + 1];
52
+ }
53
+ function fail(code, message, exitCode) {
54
+ process.stderr.write(JSON.stringify({ ok: false, error: code, message }) + "\n");
55
+ process.exit(exitCode);
56
+ }
57
+ function git(repoPath, args) {
58
+ try {
59
+ return execFileSync("git", ["-C", repoPath, ...args], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
60
+ } catch (e) {
61
+ fail("git-failed", `git ${args[0]} failed: ${(e && e.message) || e}`.slice(0, 500), 1);
62
+ }
63
+ }
64
+
65
+ const repoPath = arg("--repo-path");
66
+ const base = arg("--base");
67
+ const outFile = arg("--out");
68
+
69
+ if (!/^[0-9a-f]{40}$/.test(base)) fail("usage", "--base must be a 40-char hex commit SHA (or the empty-tree SHA).", 2);
70
+ let st = null;
71
+ try { st = statSync(repoPath); } catch { /* falls through */ }
72
+ if (!st || !st.isDirectory()) fail("usage", "--repo-path must be an existing directory.", 2);
73
+
74
+ const head = git(repoPath, ["rev-parse", "HEAD"]).trim();
75
+ if (!/^[0-9a-f]{40}$/.test(head)) fail("git-failed", "rev-parse HEAD did not return a commit SHA.", 1);
76
+
77
+ // Ancestor check — deterministic, in code. The empty tree is not a commit:
78
+ // git merge-base --is-ancestor fails on it, so a first publish hardcodes
79
+ // ANCESTOR=yes here instead of executing the conditional (clean-room
80
+ // 2026-09-16: an agent ran merge-base on the empty tree directly and parked).
81
+ let ancestor = "yes";
82
+ if (base !== EMPTY_TREE) {
83
+ try {
84
+ execFileSync("git", ["-C", repoPath, "merge-base", "--is-ancestor", base, head], { stdio: "ignore" });
85
+ ancestor = "yes";
86
+ } catch {
87
+ ancestor = "no";
88
+ }
89
+ }
90
+ if (ancestor !== "yes") {
91
+ process.stdout.write(JSON.stringify({ ok: false, error: "not-ancestor", commit: head, base }) + "\n");
92
+ process.exit(0);
93
+ }
94
+
95
+ const outPath = resolve(outFile);
96
+ mkdirSync(dirname(outPath), { recursive: true });
97
+ const diffText = git(repoPath, ["diff", base, head]);
98
+ writeFileSync(outPath, diffText, "utf8");
99
+ const bytes = readFileSync(outPath);
100
+ const sha256 = createHash("sha256").update(bytes).digest("hex");
101
+
102
+ // summarizeDiff — the parseUnifiedDiff logic, moved out of the workflows
103
+ // (canary run 4, 2026-09-11: the builder's source tree was stale and the
104
+ // workflow stamped a new hash on it — provenance fiction; the parse
105
+ // exists so Publish verifies the artifact builder applied the carried
106
+ // change). Counts changed lines (added + removed), never raw diff output
107
+ // lines: context lines and file headers inflated the old split("\n").length
108
+ // count ~2x, parking a 95-line change against the 200-line budget
109
+ // (Gate 1 Journey 3 attempt 3, 2026-09-13).
110
+ let files = [];
111
+ let current = null;
112
+ let added = 0;
113
+ let removed = 0;
114
+ let has_binary = false;
115
+ let has_rename = false;
116
+ for (const line of diffText.split("\n")) {
117
+ const m = /^diff --git a\/(.*) b\/(.*)$/.exec(line);
118
+ if (m) {
119
+ current = m[2];
120
+ files.push(current);
121
+ continue;
122
+ }
123
+ if (/^Binary files /.test(line)) { has_binary = true; continue; }
124
+ if (/^rename from /.test(line)) { has_rename = true; continue; }
125
+ if (current === null) continue;
126
+ if (/^--- /.test(line) || /^\+\+\+ /.test(line)) continue;
127
+ if (/^@@ /.test(line)) continue;
128
+ if (line.charAt(0) === "+") added++;
129
+ else if (line.charAt(0) === "-") removed++;
130
+ }
131
+
132
+ process.stdout.write(JSON.stringify({
133
+ ok: true,
134
+ commit: head,
135
+ base,
136
+ ancestor: "yes",
137
+ diff_file: outPath,
138
+ sha256,
139
+ bytes: bytes.length,
140
+ file_count: files.length,
141
+ changed_lines: added + removed,
142
+ files,
143
+ has_binary,
144
+ has_rename,
145
+ }) + "\n");
package/lib/crew-api.js CHANGED
@@ -28,6 +28,7 @@ import { randomUUID } from "node:crypto";
28
28
  import { execFileSync } from "node:child_process";
29
29
  import { DatabaseSync } from "node:sqlite";
30
30
  import { homedir } from "node:os";
31
+ import { classifySurface } from "./classify-surface.js";
31
32
 
32
33
  // ---------------------------------------------------------------------------
33
34
  // Errors
@@ -1618,17 +1619,47 @@ commands["create-project"] = (db, args, ctx) => {
1618
1619
  const repoPath = (args.repo_path ?? "").trim();
1619
1620
  if (!repoPath) throw usageError("repo_path is required.");
1620
1621
  if (!isGitRepoPath(repoPath)) throw usageError("repo_path must be a valid Git repository path.");
1621
- const deployType = args.deploy_type ?? "";
1622
+ let deployType = args.deploy_type ?? "";
1622
1623
  if (!["npm", "artifact", "vercel", ""].includes(deployType)) throw usageError("bad deploy_type.");
1623
1624
  if (db.prepare("SELECT id FROM projects WHERE id = ?").get(id)) {
1624
1625
  throw conflict("A project with this ID already exists.");
1625
1626
  }
1626
1627
  const timestamp = now();
1627
1628
  const visualProtocol = validateVisualProtocol(args.visual_protocol);
1628
- const environmentType = validateEnvironmentType(args.environment_type);
1629
+ // Surface classification default (room #14, 2026-09-17): the setup
1630
+ // conversation never classified the flashcards sample — environment_type
1631
+ // stayed null and no deploy target was set, so Capture skipped
1632
+ // ("surface unclassified"), Publish had nothing to build, and QA had no
1633
+ // runnable surface (J1/J2 parked). Fill OMITTED fields from the
1634
+ // deterministic repo scan (lib/classify-surface.js); explicit values
1635
+ // always win — including an explicit null environment_type, which still
1636
+ // means "unclassified". An artifact surface needs a deploy target:
1637
+ // classification alone doesn't close the loop, because Publish skips
1638
+ // when deploy_type is empty and QA can only run against the built
1639
+ // artifact. The initial-provenance stamp below then keys off the
1640
+ // defaulted deploy_type, so the sample's first publish diffs only the
1641
+ // task's changes instead of the whole tree.
1642
+ let environmentType = validateEnvironmentType(args.environment_type);
1643
+ let deploySlug = args.deploy_slug ?? null;
1644
+ if (args.environment_type === undefined || args.deploy_type === undefined) {
1645
+ let c = null;
1646
+ try { c = classifySurface(repoPath); } catch { c = null; }
1647
+ // Effective surface: an explicit environment_type always wins; the
1648
+ // classifier only speaks for omitted fields. Deploy defaults follow
1649
+ // the effective surface — an explicit "terminal" (or an explicit
1650
+ // null = "unclassified") never triggers artifact deploy defaults.
1651
+ // The slug is only auto-filled when we auto-set the artifact deploy;
1652
+ // a caller who chose their own deploy_type owns their slug.
1653
+ const effectiveSurface = args.environment_type === undefined ? (c && c.surface) : environmentType;
1654
+ if (args.environment_type === undefined && c && c.surface) environmentType = c.surface;
1655
+ if (effectiveSurface === "artifact" && args.deploy_type === undefined) {
1656
+ deployType = "artifact";
1657
+ if (args.deploy_slug === undefined && c && c.deploy_slug) deploySlug = c.deploy_slug;
1658
+ }
1659
+ }
1629
1660
  const row = {
1630
1661
  id, display_name: displayName, repo_path: repoPath, deploy_type: deployType,
1631
- deploy_slug: args.deploy_slug ?? null,
1662
+ deploy_slug: deploySlug,
1632
1663
  description: (args.description ?? "").trim().slice(0, 3000),
1633
1664
  simultaneity: args.simultaneity ?? 2,
1634
1665
  quiesced: args.quiesced ? 1 : 0,
@@ -4,17 +4,37 @@
4
4
  // Composes the deterministic building blocks after create-project:
5
5
  // 1. Scaffold $REPO/.orchestration/ (workflows/identities/phases versioned, user/ ignored)
6
6
  // 2. Optionally update .gitignore (only with explicit --consent)
7
+ // 3. Commit the scaffold (and the .gitignore update when consented) so
8
+ // the repo's main checkout is clean when setup finishes.
9
+ //
10
+ // Step 3 is the 2026-09-18 fix for the room #13 defect: 0.11.0 wrote the
11
+ // scaffold but never committed it, and the first task's Integrate then
12
+ // refused to merge onto the dirty main — twice, deterministically. Setup
13
+ // must leave main clean; the commit is mechanical, not agent judgment.
7
14
  //
8
15
  // This is the CLI path equivalent of what crew-init's dashboard mode does.
9
16
  // The dashboard calls the same script. No new API endpoint — composition.
10
17
  //
18
+ // Guards:
19
+ // - With --consent, .gitignore must be clean before we touch it. The
20
+ // commit only ever stages .orchestration/ (+ .gitignore when we changed
21
+ // it), but a pre-existing dirty .gitignore would be swept into our
22
+ // commit by `git add` — so refuse loudly instead. Commit or stash it,
23
+ // then re-run.
24
+ // - .orchestration/ is crew-owned: pre-existing uncommitted content there
25
+ // (e.g. left dirty by 0.11.0) is committed, not refused.
26
+ //
11
27
  // Usage:
12
28
  // node lib/setup-project-repo.js --repo <path> --crew-repo <path> [--consent]
13
29
  // --consent: user approved the .gitignore change (from the setup conversation)
14
- // Prints JSON: { orchestration: {...}, gitignore: {...} | { declined: true } }
30
+ // Prints JSON: { orchestration: {...}, gitignore: {...} | { declined: true }, commit: {...} }
31
+ // Exits non-zero on any failure (fail closed, loud).
15
32
 
33
+ const fs = require("fs");
34
+ const path = require("path");
16
35
  const { scaffoldRepoOrchestration } = require("./repo-orchestration");
17
36
  const { ensureGitignoreEntries, describeGitignoreChange } = require("./gitignore");
37
+ const { commitScaffold, isPathDirty } = require("./commit-scaffold");
18
38
 
19
39
  function main() {
20
40
  const argv = process.argv.slice(2);
@@ -31,18 +51,44 @@ function main() {
31
51
  process.exit(2);
32
52
  }
33
53
 
34
- const orchestration = scaffoldRepoOrchestration(repoPath, crewRepoPath);
54
+ try {
55
+ // Guard: never sweep the user's own .gitignore edits into our commit.
56
+ if (consent && fs.existsSync(path.join(repoPath, ".git")) && isPathDirty(repoPath, ".gitignore")) {
57
+ throw new Error(
58
+ "setup refused: .gitignore has uncommitted changes not made by setup — " +
59
+ "commit or stash them, then re-run setup"
60
+ );
61
+ }
35
62
 
36
- let gitignore;
37
- if (consent) {
38
- gitignore = ensureGitignoreEntries(repoPath);
39
- } else {
40
- // Declined (or non-interactive default): report what WOULD change.
41
- const preview = describeGitignoreChange(repoPath);
42
- gitignore = { declined: true, wouldChange: preview };
43
- }
63
+ const orchestration = scaffoldRepoOrchestration(repoPath, crewRepoPath);
44
64
 
45
- console.log(JSON.stringify({ orchestration, gitignore }, null, 2));
65
+ let gitignore;
66
+ if (consent) {
67
+ gitignore = ensureGitignoreEntries(repoPath);
68
+ } else {
69
+ // Declined (or non-interactive default): report what WOULD change.
70
+ const preview = describeGitignoreChange(repoPath);
71
+ gitignore = { declined: true, wouldChange: preview };
72
+ }
73
+
74
+ let commit;
75
+ try {
76
+ commit = commitScaffold(repoPath, { includeGitignore: consent });
77
+ } catch (commitErr) {
78
+ throw new Error(
79
+ "commit failed: " +
80
+ commitErr.message +
81
+ " — the repo has uncommitted crew files; configure git identity and run: " +
82
+ "node lib/commit-scaffold.js --repo <path>" +
83
+ (consent ? " --gitignore" : "")
84
+ );
85
+ }
86
+
87
+ console.log(JSON.stringify({ orchestration, gitignore, commit }, null, 2));
88
+ } catch (e) {
89
+ console.error("setup-project-repo failed: " + (e.message || e));
90
+ process.exit(1);
91
+ }
46
92
  }
47
93
 
48
94
  if (require.main === module) main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muse-crew",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Opinionated orchestration for Muse \u2014 workflows, identities, and tooling for autonomous software development.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -70,13 +70,14 @@ You are the dispatch trigger for Muse Crew. Run the authoritative dispatcher wor
70
70
  - Dedupe: for each candidate, check `get-events --json '{"task_id": "<id>", "limit": 50}'` for an event whose message starts with `evidence: delivered`. Skip tasks already delivered.
71
71
  - For each remaining task:
72
72
  - Read its QA verdict: from get-state's `sessions`, the completed session for this task whose notes mention Hazel/QA. Quote one verdict line (pass/fail and the one-line reason).
73
- - Find the screenshots (platform audit harness): `AUDIT=$(readlink ~/workspace/ts-spaces/<project>/audits/latest)` where `<project>` is the task's project field. Confirm `$AUDIT/screenshot.png` and `$AUDIT/screenshot-mobile.png` exist AND are newer than the task's `created_at` (compare with `stat -c %Y`). If the audit dir predates the task, the capture is stale from an earlier run — say so and do NOT attach it. Never attach screenshots from a different run.
74
- - Write the transition BEFORE the attachments (2026-09-14 — Eric: screenshots arriving out of context need a problem→solution handoff). Do not hand-write it: run the deterministic composer and paste its stdout verbatim, then the two attachment lines:
73
+ - Find the screenshots (platform audit harness): `AUDIT=$(readlink ~/workspace/ts-spaces/<project>/audits/latest)` where `<project>` is the task's project field. Confirm `$AUDIT/screenshot.png` and `$AUDIT/screenshot-mobile.png` exist AND are newer than the task's `created_at` (compare with `stat -c %Y`). Set `CAPTURES_OK=1` only when both PNGs exist and are fresh; otherwise `CAPTURES_OK=0`. If the audit dir predates the task, the capture is stale from an earlier run — say so and do NOT attach it. Never attach screenshots from a different run. Terminal-surface tasks never have harness captures — expect CAPTURES_OK=0 for them.
74
+ - Write the transition BEFORE the attachments (2026-09-14 — Eric: screenshots arriving out of context need a problem→solution handoff). Do not hand-write it: run the deterministic composer and paste its stdout verbatim:
75
75
  `node {crewHome}/lib/compose-evidence-caption.js --crew-home {crewHome} --task-id "<id>" --audit-dir "<resolved_dir>"`
76
- The composer emits: the out-of-context acknowledgment, the task title, Problem: (from the task description), Shipped: (the merge commit's subject + short-sha, or an honest "provenance not yet stamped"), Evidence: (the audit dir + QA verdict, or "No QA verdict recorded"), and the visual-protocol-unavailable honest label when the run recorded one. If the composer exits non-zero, say so in one line and attach nothing for that task.
77
- - Attach both to your report, each on its own plain line, using the RESOLVED dir name (not the `latest` symlink) so the evidence is pinned to this run:
76
+ The composer emits: the out-of-context acknowledgment, the task title, Problem: (from the task description), Shipped: (the merge commit's subject + short-sha, or an honest "provenance not yet stamped"), Evidence: (the audit dir + QA verdict when captures exist, or the honest no-captures line — 2026-09-17: the composer verifies the captures exist before claiming them, so a terminal-surface task with no audit dir gets the honest line, never "desktop + mobile captures below"), and the visual-protocol-unavailable honest label when the run recorded one. If the composer exits non-zero, say so in one line and attach nothing for that task.
77
+ - Attach the two screenshot lines ONLY when CAPTURES_OK=1, each on its own plain line, using the RESOLVED dir name (not the `latest` symlink) so the evidence is pinned to this run:
78
78
  `![desktop](sandbox://workspace/ts-spaces/<project>/audits/<resolved_dir>/screenshot.png)`
79
79
  `![mobile](sandbox://workspace/ts-spaces/<project>/audits/<resolved_dir>/screenshot-mobile.png)`
80
+ When CAPTURES_OK=0, attach nothing — the composer's caption already says so honestly.
80
81
  - Log the delivery so the next tick skips it: `node {crewHome}/lib/crew-api.js --crew-home {crewHome} log-event --json '{"task_id": "<id>", "type": "note", "message": "evidence: delivered <id> — screenshots attached to tick report"}'`.
81
82
  - If a done task has no fresh screenshots, say so in one line — never claim evidence you don't have.
82
83
 
@@ -81,9 +81,15 @@ const PUBLISH_NPM = RUN_LIB + "/publish-npm.sh";
81
81
  const CREW_API_PINNED = RUN_LIB + "/crew-api.js";
82
82
  const SCHEMA_SQL_SRC = crewHome + "/lib/schema.sql";
83
83
  const SCHEMA_SQL_PINNED = RUN_LIB + "/schema.sql";
84
- // The five basenames the pin step must materialize — asserted mechanically
84
+ const COMPUTE_DIFF_SRC = crewHome + "/current/lib/compute-publish-diff.js";
85
+ const COMPUTE_DIFF = RUN_LIB + "/compute-publish-diff.js";
86
+ // The six basenames the pin step must materialize — asserted mechanically
85
87
  // by workflow code from the verbatim listing, never from agent prose.
86
- const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED].map(function (p) { return p.split("/").pop(); });
88
+ // COMPUTE_DIFF is the deterministic publish-diff computer (room #14,
89
+ // 2026-09-17): the diff is computed by this script, never ferried as an
90
+ // agent JSON string. Pinned like the other publish-critical modules so a
91
+ // mid-run release swap cannot change it under the workflow.
92
+ const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED, COMPUTE_DIFF].map(function (p) { return p.split("/").pop(); });
87
93
 
88
94
  // Project config — passed by dispatcher, falls back to dashboard defaults
89
95
  const projectConfig = inputs.project_config || {};
@@ -259,7 +265,7 @@ function attemptKey(base, reworkCount) {
259
265
  return base + (reworkCount > 0 ? "-r" + reworkCount : "");
260
266
  }
261
267
  // pinLifecycle(key) — snapshot the lifecycle scripts into RUN_LIB and return
262
- // the verbatim `ls -1` listing so WORKFLOW CODE asserts the five pinned
268
+ // the verbatim `ls -1` listing so WORKFLOW CODE asserts the six pinned
263
269
  // basenames; the agent cannot self-certify. (The pin step was the one place
264
270
  // the workflows trusted agent prose: task 24be1cd6 walked to Publish on an
265
271
  // empty pin dir.) Byte-identical across standard/bugfix/chore — pinned by
@@ -267,7 +273,7 @@ function attemptKey(base, reworkCount) {
267
273
  function pinLifecycle(key) {
268
274
  return agent(
269
275
  "Snapshot lifecycle scripts for version pinning.\n" +
270
- "Run: mkdir -p " + RUN_LIB + " && cp " + LIFECYCLE_SRC + " " + LIFECYCLE + " && cp " + MERGE_LOCK_SRC + " " + MERGE_LOCK + " && cp " + PUBLISH_NPM_SRC + " " + PUBLISH_NPM + " && cp " + CREW_API_SRC + " " + CREW_API_PINNED + " && cp " + SCHEMA_SQL_SRC + " " + SCHEMA_SQL_PINNED + " && chmod +x " + LIFECYCLE + " " + MERGE_LOCK + " " + PUBLISH_NPM + " && ls -1 " + RUN_LIB + "\n" +
276
+ "Run: mkdir -p " + RUN_LIB + " && cp " + LIFECYCLE_SRC + " " + LIFECYCLE + " && cp " + MERGE_LOCK_SRC + " " + MERGE_LOCK + " && cp " + PUBLISH_NPM_SRC + " " + PUBLISH_NPM + " && cp " + CREW_API_SRC + " " + CREW_API_PINNED + " && cp " + SCHEMA_SQL_SRC + " " + SCHEMA_SQL_PINNED + " && cp " + COMPUTE_DIFF_SRC + " " + COMPUTE_DIFF + " && chmod +x " + LIFECYCLE + " " + MERGE_LOCK + " " + PUBLISH_NPM + " && ls -1 " + RUN_LIB + "\n" +
271
277
  "Return the verbatim output of the ls -1 command as { \"listing\": \"<verbatim output>\" } and nothing else.",
272
278
  { key: key, label: "Pinning lifecycle scripts",
273
279
  schema: { type: "object", properties: { listing: { type: "string" } }, required: ["listing"] } }
@@ -448,37 +454,6 @@ function hydrateReleaseDecision(rec) {
448
454
  return null;
449
455
  }
450
456
 
451
- // Publish diff transport: parse a unified diff into per-file {path, added,
452
- // removed} line lists. Pure function — no I/O, no clock. Used by Publish to
453
- // verify the artifact builder applied the carried change (canary run 4,
454
- // 2026-09-11: the builder's source tree was stale and disconnected from the
455
- // crew's repo; "rebuild from current source" rebuilt stale code and the
456
- // workflow stamped the new commit hash on it — provenance fiction).
457
- function parseUnifiedDiff(diffText) {
458
- var files = [];
459
- var current = null;
460
- var lines = (diffText || "").split("\n");
461
- for (var i = 0; i < lines.length; i++) {
462
- var line = lines[i];
463
- var m = /^diff --git a\/(.*) b\/(.*)$/.exec(line);
464
- if (m) {
465
- current = { path: m[2], added: [], removed: [] };
466
- files.push(current);
467
- continue;
468
- }
469
- if (!current) continue;
470
- if (/^--- /.test(line) || /^\+\+\+ /.test(line)) continue;
471
- if (/^@@ /.test(line)) continue;
472
- if (line.charAt(0) === "+") {
473
- current.added.push(line.slice(1));
474
- } else if (line.charAt(0) === "-") {
475
- current.removed.push(line.slice(1));
476
- }
477
- }
478
- return files;
479
- }
480
-
481
-
482
457
  // Publish read-back request (currently unavailable): the verbatim_request
483
458
  // the parent protocol (docs/publish-verification.md) would hand to an
484
459
  // independent read-back tool after the artifact build lands. artifact_inspect
@@ -1586,59 +1561,77 @@ while (i < STEPS.length) {
1586
1561
  } else if (!/^[0-9a-f]{40}$/.test(publishBase)) {
1587
1562
  return await parkTask("Publish base '" + publishBase + "' is not a valid commit SHA — cannot compute the publish diff. Human attention needed.");
1588
1563
  }
1589
- // The empty tree is not a commit: git merge-base --is-ancestor fails on it.
1590
- // The workflow knows publishBase == EMPTY_TREE_SHA (set above), so it
1591
- // hardcodes ANCESTOR=yes for a first publish instead of asking the agent
1592
- // to execute the conditional (clean-room 2026-09-16: the agent ran
1593
- // merge-base on the empty tree directly and parked).
1594
- var ancestorShell = (publishBase === EMPTY_TREE_SHA)
1595
- ? "ANCESTOR=yes && "
1596
- : "git merge-base --is-ancestor \"$BASE\" \"$HEAD\" && ANCESTOR=yes || ANCESTOR=no && ";
1564
+ // Publish diff transport (room #14, 2026-09-17): the diff used to be
1565
+ // ferried as a JSON string field in the agent's response — the agent
1566
+ // produced a valid 700-line diff on disk but the JSON ferry dropped
1567
+ // it, and the parse saw zero files ("Publish diff parsed to zero
1568
+ // files"). The diff now travels git -> file -> deterministic script
1569
+ // summary; the LLM never carries diff bytes. The agent is pure hands:
1570
+ // it runs exactly one command (the PINNED compute-publish-diff.js —
1571
+ // a mid-run release swap cannot change it under the workflow) and
1572
+ // returns the small JSON summary verbatim. All fail-closed parks
1573
+ // below are unchanged in meaning.
1574
+ var publishDiffFile = crewHome + "/.publish-diffs/" + taskId + (totalReworkCount > 0 ? "-r" + totalReworkCount : "") + ".diff";
1597
1575
  var diffResult = await agent(
1598
- "Run: cd " + REPO_PATH + " && BASE='" + publishBase + "' && HEAD=$(git rev-parse HEAD) && " +
1599
- ancestorShell +
1600
- "echo '---COMMIT---' && echo \"$HEAD\" && echo '---BASE---' && echo \"$BASE\" && echo '---ANCESTOR---' && echo \"$ANCESTOR\" && " +
1601
- "if [ \"$ANCESTOR\" = yes ]; then echo '---DIFF---' && git diff \"$BASE\" \"$HEAD\" && echo '---NAMES---' && git diff-tree --no-commit-id --name-only -r \"$BASE\" \"$HEAD\"; fi\n" +
1602
- "Return JSON { \"commit\": \"<HEAD trimmed>\", \"base\": \"<BASE trimmed>\", \"ancestor\": \"<yes|no>\", \"diff\": \"<raw unified diff, may be multi-line>\", \"files\": \"<newline-separated paths>\" } and nothing else.",
1576
+ "Run exactly one command and nothing else:\n" +
1577
+ "node " + COMPUTE_DIFF + " --repo-path \"" + REPO_PATH + "\" --base " + publishBase + " --out \"" + publishDiffFile + "\"\n" +
1578
+ "The script prints one small JSON object to stdout. Return the stdout verbatim as { \"output\": \"<verbatim stdout>\" } and nothing else. Do not interpret it.",
1603
1579
  { key: attemptKey("publish-artifact-diff-" + taskId, totalReworkCount), label: "Computing publish diff from stamped base",
1604
- schema: { type: "object", properties: { commit: { type: "string" }, base: { type: "string" }, ancestor: { type: "string" }, diff: { type: "string" }, files: { type: "string" } }, required: ["commit", "base", "ancestor", "diff"] } }
1580
+ schema: { type: "object", properties: { output: { type: "string" } }, required: ["output"] } }
1605
1581
  );
1606
- if ((diffResult.ancestor || "").trim() !== "yes") {
1607
- return await parkTask("Publish base " + publishBase.slice(0, 12) + " is not an ancestor of HEAD " + (diffResult.commit || "").trim().slice(0, 12) + " — the stamped provenance does not lead to the integrated commit. Human attention needed.");
1582
+ var diffSummary = null;
1583
+ try {
1584
+ diffSummary = JSON.parse((diffResult.output || "").trim());
1585
+ } catch (e) {
1586
+ return await parkTask("Publish diff computation returned unparseable output — cannot verify application. Human attention needed.");
1587
+ }
1588
+ if (!diffSummary || diffSummary.ok !== true) {
1589
+ if (diffSummary && diffSummary.error === "not-ancestor") {
1590
+ return await parkTask("Publish base " + publishBase.slice(0, 12) + " is not an ancestor of HEAD " + String(diffSummary.commit || "").slice(0, 12) + " — the stamped provenance does not lead to the integrated commit. Human attention needed.");
1591
+ }
1592
+ return await parkTask("Publish diff computation failed (" + ((diffSummary && diffSummary.error) || "unknown error") + ") — cannot verify application. Human attention needed.");
1608
1593
  }
1609
- if ((diffResult.base || "").trim() !== publishBase) {
1610
- return await parkTask("Publish diff base mismatch: agent reported '" + (diffResult.base || "").trim().slice(0, 12) + "' but the stamped base is '" + publishBase.slice(0, 12) + "'. Human attention needed.");
1594
+ if (diffSummary.base !== publishBase) {
1595
+ return await parkTask("Publish diff base mismatch: script reported '" + String(diffSummary.base || "").slice(0, 12) + "' but the stamped base is '" + publishBase.slice(0, 12) + "'. Human attention needed.");
1611
1596
  }
1612
- var mergeCommitForPublish = (diffResult.commit || "").trim();
1613
- var mergeDiff = diffResult.diff || "";
1614
- if (!mergeDiff.trim()) {
1597
+ var mergeCommitForPublish = String(diffSummary.commit || "").trim();
1598
+ var publishDiffSha256 = String(diffSummary.sha256 || "");
1599
+ if (!diffSummary.bytes) {
1615
1600
  return await parkTask("Publish diff is empty for commit " + (mergeCommitForPublish || "unknown") + " — a merge lock was held but there is no change to carry. Human attention needed.");
1616
1601
  }
1617
- if (/^Binary files /m.test(mergeDiff)) {
1618
- return await parkTask("Publish diff contains binary files — the text diff transport cannot carry them. Human attention needed.");
1602
+ if (diffSummary.has_binary) {
1603
+ return await parkTask("Publish diff contains binary files — the diff transport cannot carry them. Human attention needed.");
1619
1604
  }
1620
- if (/^rename from /m.test(mergeDiff)) {
1605
+ if (diffSummary.has_rename) {
1621
1606
  return await parkTask("Publish diff contains a rename — the diff transport cannot carry renames. Human attention needed.");
1622
1607
  }
1623
- var expectedChanges = parseUnifiedDiff(mergeDiff);
1624
1608
  // Budget counts CHANGED lines (added + removed), not raw unified-diff
1625
1609
  // output lines: context lines and file headers inflated the old
1626
1610
  // split("\n").length count ~2x, parking a 95-line change against a
1627
- // 200-line budget (Gate 1 Journey 3 attempt 3, 2026-09-13).
1628
- var mergeDiffChangedLines = expectedChanges.reduce(function (n, f) { return n + f.added.length + f.removed.length; }, 0);
1611
+ // 200-line budget (Gate 1 Journey 3 attempt 3, 2026-09-13). The count
1612
+ // now comes from the deterministic script summary, never from the LLM.
1613
+ var mergeDiffChangedLines = diffSummary.changed_lines || 0;
1629
1614
  if (mergeDiffChangedLines > 200) {
1630
1615
  return await parkTask("Publish diff changes " + mergeDiffChangedLines + " lines (budget 200) — too large for the diff transport. Human attention needed.");
1631
1616
  }
1632
- if (expectedChanges.length === 0) {
1617
+ if (!diffSummary.file_count) {
1633
1618
  return await parkTask("Publish diff parsed to zero files for commit " + (mergeCommitForPublish || "unknown") + " — cannot verify application. Human attention needed.");
1634
1619
  }
1620
+ // The trigger agent reads the diff from the checksummed file — the
1621
+ // workflow never holds diff bytes (room #14, 2026-09-17). The file
1622
+ // is small by construction: the 200-line budget above gates the
1623
+ // trigger. The sha256 check is the agent's only verification step;
1624
+ // a mismatch stops the trigger before any artifact_edit call.
1635
1625
  var rebuildPrompt =
1636
1626
  ARTIFACT_LOAD_PREAMBLE +
1637
- "Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
1627
+ "The change to apply is the unified diff in the file \"" + publishDiffFile + "\" (sha256 " + publishDiffSha256 + ").\n" +
1628
+ "1. Verify the file: run sha256sum on it. If the printed hash is not exactly " + publishDiffSha256 + ", STOP and end your turn — do not call artifact_edit.\n" +
1629
+ "2. Read the file's full content.\n" +
1630
+ "3. Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
1638
1631
  "'Apply the following change to your source tree, then rebuild and deploy.\n" +
1639
1632
  "\n" +
1640
1633
  "UNIFIED DIFF (relative to your source tree):\n" +
1641
- "```diff\n" + mergeDiff + "\n```\n" +
1634
+ "```diff\n<the full content of the verified file, pasted verbatim>\n```\n" +
1642
1635
  "\n" +
1643
1636
  "Rules:\n" +
1644
1637
  "- For each file in the diff, apply its hunks to the same path in your source tree (use git apply or equivalent).\n" +