muse-crew 0.11.1 → 0.13.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.
@@ -89,9 +89,20 @@ const PUBLISH_NPM = RUN_LIB + "/publish-npm.sh";
89
89
  const CREW_API_PINNED = RUN_LIB + "/crew-api.js";
90
90
  const SCHEMA_SQL_SRC = crewHome + "/lib/schema.sql";
91
91
  const SCHEMA_SQL_PINNED = RUN_LIB + "/schema.sql";
92
- // The five basenames the pin step must materialize — asserted mechanically
92
+ const COMPUTE_DIFF_SRC = crewHome + "/current/lib/compute-publish-diff.js";
93
+ const COMPUTE_DIFF = RUN_LIB + "/compute-publish-diff.js";
94
+ const CLASSIFY_SURFACE_SRC = crewHome + "/current/lib/classify-surface.js";
95
+ const CLASSIFY_SURFACE = RUN_LIB + "/classify-surface.js";
96
+ // The seven basenames the pin step must materialize — asserted mechanically
93
97
  // by workflow code from the verbatim listing, never from agent prose.
94
- const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED].map(function (p) { return p.split("/").pop(); });
98
+ // COMPUTE_DIFF is the deterministic publish-diff computer (room #14,
99
+ // 2026-09-17): the diff is computed by this script, never ferried as an
100
+ // agent JSON string. Pinned like the other publish-critical modules so a
101
+ // mid-run release swap cannot change it under the workflow.
102
+ // CLASSIFY_SURFACE is the surface classifier (room #15, 2026-09-18):
103
+ // crew-api.js statically imports it, so the pin must carry it — a pin
104
+ // without it kills every claim with ERR_MODULE_NOT_FOUND.
105
+ const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED, COMPUTE_DIFF, CLASSIFY_SURFACE].map(function (p) { return p.split("/").pop(); });
95
106
 
96
107
  // Project config — passed by dispatcher, falls back to dashboard defaults
97
108
  const projectConfig = inputs.project_config || {};
@@ -267,7 +278,7 @@ function attemptKey(base, reworkCount) {
267
278
  return base + (reworkCount > 0 ? "-r" + reworkCount : "");
268
279
  }
269
280
  // pinLifecycle(key) — snapshot the lifecycle scripts into RUN_LIB and return
270
- // the verbatim `ls -1` listing so WORKFLOW CODE asserts the five pinned
281
+ // the verbatim `ls -1` listing so WORKFLOW CODE asserts the six pinned
271
282
  // basenames; the agent cannot self-certify. (The pin step was the one place
272
283
  // the workflows trusted agent prose: task 24be1cd6 walked to Publish on an
273
284
  // empty pin dir.) Byte-identical across standard/bugfix/chore — pinned by
@@ -275,7 +286,7 @@ function attemptKey(base, reworkCount) {
275
286
  function pinLifecycle(key) {
276
287
  return agent(
277
288
  "Snapshot lifecycle scripts for version pinning.\n" +
278
- "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" +
289
+ "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 + " && cp " + CLASSIFY_SURFACE_SRC + " " + CLASSIFY_SURFACE + " && chmod +x " + LIFECYCLE + " " + MERGE_LOCK + " " + PUBLISH_NPM + " && ls -1 " + RUN_LIB + "\n" +
279
290
  "Return the verbatim output of the ls -1 command as { \"listing\": \"<verbatim output>\" } and nothing else.",
280
291
  { key: key, label: "Pinning lifecycle scripts",
281
292
  schema: { type: "object", properties: { listing: { type: "string" } }, required: ["listing"] } }
@@ -456,37 +467,6 @@ function hydrateReleaseDecision(rec) {
456
467
  return null;
457
468
  }
458
469
 
459
- // Publish diff transport: parse a unified diff into per-file {path, added,
460
- // removed} line lists. Pure function — no I/O, no clock. Used by Publish to
461
- // verify the artifact builder applied the carried change (canary run 4,
462
- // 2026-09-11: the builder's source tree was stale and disconnected from the
463
- // crew's repo; "rebuild from current source" rebuilt stale code and the
464
- // workflow stamped the new commit hash on it — provenance fiction).
465
- function parseUnifiedDiff(diffText) {
466
- var files = [];
467
- var current = null;
468
- var lines = (diffText || "").split("\n");
469
- for (var i = 0; i < lines.length; i++) {
470
- var line = lines[i];
471
- var m = /^diff --git a\/(.*) b\/(.*)$/.exec(line);
472
- if (m) {
473
- current = { path: m[2], added: [], removed: [] };
474
- files.push(current);
475
- continue;
476
- }
477
- if (!current) continue;
478
- if (/^--- /.test(line) || /^\+\+\+ /.test(line)) continue;
479
- if (/^@@ /.test(line)) continue;
480
- if (line.charAt(0) === "+") {
481
- current.added.push(line.slice(1));
482
- } else if (line.charAt(0) === "-") {
483
- current.removed.push(line.slice(1));
484
- }
485
- }
486
- return files;
487
- }
488
-
489
-
490
470
  // Publish read-back request (agent path currently unavailable): the
491
471
  // verbatim_request the parent protocol (docs/publish-verification.md) would
492
472
  // hand to an independent read-back tool after the artifact build lands.
@@ -1454,7 +1434,7 @@ while (i < STEPS.length) {
1454
1434
  // first publish (no provenance stamped yet).
1455
1435
  var EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
1456
1436
  var provResult = await agent(
1457
- crewCmd("get-provenance", {}) + "\n" +
1437
+ crewCmd("get-provenance", { project_id: LAUNCH_PROJECT_ID }) + "\n" +
1458
1438
  "Return JSON { \"provenance\": <the CLI's provenance object, or null when nothing is stamped> } and nothing else. Do not interpret it.",
1459
1439
  { key: attemptKey("publish-provenance-base-" + taskId, totalReworkCount), label: "Reading stamped publish base",
1460
1440
  schema: { type: "object", properties: { provenance: { type: ["object", "null"] } }, required: ["provenance"] } }
@@ -1467,59 +1447,77 @@ while (i < STEPS.length) {
1467
1447
  } else if (!/^[0-9a-f]{40}$/.test(publishBase)) {
1468
1448
  return await parkTask("Publish base '" + publishBase + "' is not a valid commit SHA — cannot compute the publish diff. Human attention needed.");
1469
1449
  }
1470
- // The empty tree is not a commit: git merge-base --is-ancestor fails on it.
1471
- // The workflow knows publishBase == EMPTY_TREE_SHA (set above), so it
1472
- // hardcodes ANCESTOR=yes for a first publish instead of asking the agent
1473
- // to execute the conditional (clean-room 2026-09-16: the agent ran
1474
- // merge-base on the empty tree directly and parked).
1475
- var ancestorShell = (publishBase === EMPTY_TREE_SHA)
1476
- ? "ANCESTOR=yes && "
1477
- : "git merge-base --is-ancestor \"$BASE\" \"$HEAD\" && ANCESTOR=yes || ANCESTOR=no && ";
1450
+ // Publish diff transport (room #14, 2026-09-17): the diff used to be
1451
+ // ferried as a JSON string field in the agent's response — the agent
1452
+ // produced a valid 700-line diff on disk but the JSON ferry dropped
1453
+ // it, and the parse saw zero files ("Publish diff parsed to zero
1454
+ // files"). The diff now travels git -> file -> deterministic script
1455
+ // summary; the LLM never carries diff bytes. The agent is pure hands:
1456
+ // it runs exactly one command (the PINNED compute-publish-diff.js —
1457
+ // a mid-run release swap cannot change it under the workflow) and
1458
+ // returns the small JSON summary verbatim. All fail-closed parks
1459
+ // below are unchanged in meaning.
1460
+ var publishDiffFile = crewHome + "/.publish-diffs/" + taskId + (totalReworkCount > 0 ? "-r" + totalReworkCount : "") + ".diff";
1478
1461
  var diffResult = await agent(
1479
- "Run: cd " + REPO_PATH + " && BASE='" + publishBase + "' && HEAD=$(git rev-parse HEAD) && " +
1480
- ancestorShell +
1481
- "echo '---COMMIT---' && echo \"$HEAD\" && echo '---BASE---' && echo \"$BASE\" && echo '---ANCESTOR---' && echo \"$ANCESTOR\" && " +
1482
- "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" +
1483
- "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.",
1462
+ "Run exactly one command and nothing else:\n" +
1463
+ "node " + COMPUTE_DIFF + " --repo-path \"" + REPO_PATH + "\" --base " + publishBase + " --out \"" + publishDiffFile + "\"\n" +
1464
+ "The script prints one small JSON object to stdout. Return the stdout verbatim as { \"output\": \"<verbatim stdout>\" } and nothing else. Do not interpret it.",
1484
1465
  { key: attemptKey("publish-artifact-diff-" + taskId, totalReworkCount), label: "Computing publish diff from stamped base",
1485
- schema: { type: "object", properties: { commit: { type: "string" }, base: { type: "string" }, ancestor: { type: "string" }, diff: { type: "string" }, files: { type: "string" } }, required: ["commit", "base", "ancestor", "diff"] } }
1466
+ schema: { type: "object", properties: { output: { type: "string" } }, required: ["output"] } }
1486
1467
  );
1487
- if ((diffResult.ancestor || "").trim() !== "yes") {
1488
- 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.");
1468
+ var diffSummary = null;
1469
+ try {
1470
+ diffSummary = JSON.parse((diffResult.output || "").trim());
1471
+ } catch (e) {
1472
+ return await parkTask("Publish diff computation returned unparseable output — cannot verify application. Human attention needed.");
1473
+ }
1474
+ if (!diffSummary || diffSummary.ok !== true) {
1475
+ if (diffSummary && diffSummary.error === "not-ancestor") {
1476
+ 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.");
1477
+ }
1478
+ return await parkTask("Publish diff computation failed (" + ((diffSummary && diffSummary.error) || "unknown error") + ") — cannot verify application. Human attention needed.");
1489
1479
  }
1490
- if ((diffResult.base || "").trim() !== publishBase) {
1491
- 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.");
1480
+ if (diffSummary.base !== publishBase) {
1481
+ 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.");
1492
1482
  }
1493
- var mergeCommitForPublish = (diffResult.commit || "").trim();
1494
- var mergeDiff = diffResult.diff || "";
1495
- if (!mergeDiff.trim()) {
1483
+ var mergeCommitForPublish = String(diffSummary.commit || "").trim();
1484
+ var publishDiffSha256 = String(diffSummary.sha256 || "");
1485
+ if (!diffSummary.bytes) {
1496
1486
  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.");
1497
1487
  }
1498
- if (/^Binary files /m.test(mergeDiff)) {
1499
- return await parkTask("Publish diff contains binary files — the text diff transport cannot carry them. Human attention needed.");
1488
+ if (diffSummary.has_binary) {
1489
+ return await parkTask("Publish diff contains binary files — the diff transport cannot carry them. Human attention needed.");
1500
1490
  }
1501
- if (/^rename from /m.test(mergeDiff)) {
1491
+ if (diffSummary.has_rename) {
1502
1492
  return await parkTask("Publish diff contains a rename — the diff transport cannot carry renames. Human attention needed.");
1503
1493
  }
1504
- var expectedChanges = parseUnifiedDiff(mergeDiff);
1505
1494
  // Budget counts CHANGED lines (added + removed), not raw unified-diff
1506
1495
  // output lines: context lines and file headers inflated the old
1507
1496
  // split("\n").length count ~2x, parking a 95-line change against a
1508
- // 200-line budget (Gate 1 Journey 3 attempt 3, 2026-09-13).
1509
- var mergeDiffChangedLines = expectedChanges.reduce(function (n, f) { return n + f.added.length + f.removed.length; }, 0);
1497
+ // 200-line budget (Gate 1 Journey 3 attempt 3, 2026-09-13). The count
1498
+ // now comes from the deterministic script summary, never from the LLM.
1499
+ var mergeDiffChangedLines = diffSummary.changed_lines || 0;
1510
1500
  if (mergeDiffChangedLines > 200) {
1511
1501
  return await parkTask("Publish diff changes " + mergeDiffChangedLines + " lines (budget 200) — too large for the diff transport. Human attention needed.");
1512
1502
  }
1513
- if (expectedChanges.length === 0) {
1503
+ if (!diffSummary.file_count) {
1514
1504
  return await parkTask("Publish diff parsed to zero files for commit " + (mergeCommitForPublish || "unknown") + " — cannot verify application. Human attention needed.");
1515
1505
  }
1506
+ // The trigger agent reads the diff from the checksummed file — the
1507
+ // workflow never holds diff bytes (room #14, 2026-09-17). The file
1508
+ // is small by construction: the 200-line budget above gates the
1509
+ // trigger. The sha256 check is the agent's only verification step;
1510
+ // a mismatch stops the trigger before any artifact_edit call.
1516
1511
  var rebuildPrompt =
1517
1512
  ARTIFACT_LOAD_PREAMBLE +
1518
- "Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
1513
+ "The change to apply is the unified diff in the file \"" + publishDiffFile + "\" (sha256 " + publishDiffSha256 + ").\n" +
1514
+ "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" +
1515
+ "2. Read the file's full content.\n" +
1516
+ "3. Call artifact_edit with slug \"" + PUBLISH_SLUG + "\" and verbatim_request:\n" +
1519
1517
  "'Apply the following change to your source tree, then rebuild and deploy.\n" +
1520
1518
  "\n" +
1521
1519
  "UNIFIED DIFF (relative to your source tree):\n" +
1522
- "```diff\n" + mergeDiff + "\n```\n" +
1520
+ "```diff\n<the full content of the verified file, pasted verbatim>\n```\n" +
1523
1521
  "\n" +
1524
1522
  "Rules:\n" +
1525
1523
  "- For each file in the diff, apply its hunks to the same path in your source tree (use git apply or equivalent).\n" +
@@ -2233,7 +2231,7 @@ while (i < STEPS.length) {
2233
2231
  "Run in shell and return the stdout verbatim:\n" + crewCmd("get-state", { events_limit: 1 }) + "\n" +
2234
2232
  "Use the returned tasks, sessions, and events to check the task's data-level effects.\n" +
2235
2233
  "DOCS GATE: If the change is public-affecting (it alters anything a user or consumer can observe: API actions, parameters, behavior, or errors), verify the public docs describe it. If public docs are missing or stale for a public-affecting change, report 'public docs missing/stale for [the change]', then end your report with exactly this line: VERDICT: FAIL. QA always fails when public-affecting changes lack public docs. Guide/tutorial gaps are lower priority — file a follow-up task for those instead of failing.\n\n" +
2236
- "PROVENANCE CHECK: Run in shell and return the stdout verbatim:\n" + crewCmd("get-provenance", {}) + "\n" +
2234
+ "PROVENANCE CHECK: Run in shell and return the stdout verbatim:\n" + crewCmd("get-provenance", { project_id: LAUNCH_PROJECT_ID }) + "\n" +
2237
2235
  "If provenance is null, report 'provenance missing — publish did not stamp source/crew release', then end your report with exactly this line: VERDICT: FAIL.\n" +
2238
2236
  "Run: cd " + REPO_PATH + " && git rev-parse HEAD — call this LIVE_HEAD.\n" +
2239
2237
  "Run: test -d " + crewHome + "/releases/<provenance.crew_release> (substitute the real stamped hash; do not run the literal placeholder). If the directory does not exist, FAIL: { \"passed\": false, \"summary\": \"provenance mismatch: crew_release [value from get-provenance] not found in release registry\" }.\n" +
@@ -2710,11 +2708,11 @@ while (i < STEPS.length) {
2710
2708
  // dashboard QA source check).
2711
2709
  try {
2712
2710
  var provRefresh = await agent(
2713
- "Run in shell and return the stdout verbatim:\n" + crewCmd("get-provenance", {}) + "\n" +
2711
+ "Run in shell and return the stdout verbatim:\n" + crewCmd("get-provenance", { project_id: LAUNCH_PROJECT_ID }) + "\n" +
2714
2712
  "If the response has no provenance (null), return JSON { \"refreshed\": false, \"reason\": \"no-record\" } and stop. " +
2715
2713
  "Otherwise run: basename $(readlink " + crewHome + "/current) — call this REL; " +
2716
2714
  "run: date -u +%Y-%m-%dT%H:%M:%SZ — call this TS. " +
2717
- "Then run in shell:\n" + crewCmd("set-provenance", { source_commit: "<existing provenance.source_commit>", crew_release: "<REL trimmed>", published_at: "<TS trimmed>", task_id: taskId }) + "\n" +
2715
+ "Then run in shell:\n" + crewCmd("set-provenance", { project_id: LAUNCH_PROJECT_ID, source_commit: "<existing provenance.source_commit>", crew_release: "<REL trimmed>", published_at: "<TS trimmed>", task_id: taskId }) + "\n" +
2718
2716
  "(substitute the real existing source_commit, REL, and TS for the placeholders). " +
2719
2717
  "Return JSON { \"refreshed\": <true if the set-provenance stdout contains ok: true, false otherwise>, \"crew_release\": \"<REL trimmed>\", \"published_at\": \"<TS trimmed>\" } and nothing else.",
2720
2718
  { key: attemptKey("publish-provenance-refresh-" + taskId, totalReworkCount), label: "Refreshing dashboard provenance after crew release",
@@ -157,9 +157,14 @@ const PUBLISH_NPM = RUN_LIB + "/publish-npm.sh";
157
157
  const CREW_API_PINNED = RUN_LIB + "/crew-api.js";
158
158
  const SCHEMA_SQL_SRC = crewHome + "/lib/schema.sql";
159
159
  const SCHEMA_SQL_PINNED = RUN_LIB + "/schema.sql";
160
- // The five basenames the pin step must materialize — asserted mechanically
160
+ const CLASSIFY_SURFACE_SRC = crewHome + "/current/lib/classify-surface.js";
161
+ const CLASSIFY_SURFACE = RUN_LIB + "/classify-surface.js";
162
+ // The six basenames the pin step must materialize — asserted mechanically
161
163
  // by workflow code from the verbatim listing, never from agent prose.
162
- const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED].map(function (p) { return p.split("/").pop(); });
164
+ // CLASSIFY_SURFACE is the surface classifier (room #15, 2026-09-18):
165
+ // crew-api.js statically imports it, so the pin must carry it — a pin
166
+ // without it kills every claim with ERR_MODULE_NOT_FOUND.
167
+ const PIN_BASENAMES = [LIFECYCLE, MERGE_LOCK, PUBLISH_NPM, CREW_API_PINNED, SCHEMA_SQL_PINNED, CLASSIFY_SURFACE].map(function (p) { return p.split("/").pop(); });
163
168
 
164
169
  // Project config — passed by dispatcher, falls back to dashboard defaults
165
170
  const projectConfig = inputs.project_config || {};
@@ -190,7 +195,7 @@ if (!taskId) {
190
195
  function pinLifecycle(key) {
191
196
  return agent(
192
197
  "Snapshot lifecycle scripts for version pinning.\n" +
193
- "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" +
198
+ "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 " + CLASSIFY_SURFACE_SRC + " " + CLASSIFY_SURFACE + " && chmod +x " + LIFECYCLE + " " + MERGE_LOCK + " " + PUBLISH_NPM + " && ls -1 " + RUN_LIB + "\n" +
194
199
  "Return the verbatim output of the ls -1 command as { \"listing\": \"<verbatim output>\" } and nothing else.",
195
200
  { key: key, label: "Pinning lifecycle scripts",
196
201
  schema: { type: "object", properties: { listing: { type: "string" } }, required: ["listing"] } }