cool-workflow 0.1.98 → 0.2.1

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 (315) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/README.md +18 -7
  4. package/apps/architecture-review/app.json +2 -2
  5. package/apps/architecture-review/workflow.js +12 -12
  6. package/apps/architecture-review-fast/app.json +1 -1
  7. package/apps/end-to-end-golden-path/app.json +1 -1
  8. package/apps/pr-review-fix-ci/app.json +1 -1
  9. package/apps/release-cut/app.json +1 -1
  10. package/apps/research-synthesis/app.json +1 -1
  11. package/dist/cli/dispatch.js +236 -0
  12. package/dist/cli/entry.js +120 -0
  13. package/dist/cli/io.js +21 -4
  14. package/dist/cli/parseargv.js +157 -0
  15. package/dist/cli.js +6 -33
  16. package/dist/core/capability-table.js +3518 -0
  17. package/dist/core/format/help.js +314 -0
  18. package/dist/{state-explosion/format.js → core/format/state-explosion-text.js} +10 -1
  19. package/dist/core/hash.js +137 -0
  20. package/dist/core/multi-agent/candidate-scoring.js +219 -0
  21. package/dist/core/multi-agent/collaboration.js +481 -0
  22. package/dist/core/multi-agent/coordinator.js +515 -0
  23. package/dist/core/multi-agent/eval-replay.js +306 -0
  24. package/dist/core/multi-agent/runtime.js +929 -0
  25. package/dist/core/multi-agent/topology.js +298 -0
  26. package/dist/core/multi-agent/trust-policy.js +197 -0
  27. package/dist/core/pipeline/commit-gate.js +320 -0
  28. package/dist/{pipeline-contract.js → core/pipeline/contract.js} +24 -37
  29. package/dist/core/pipeline/dispatch.js +103 -0
  30. package/dist/core/pipeline/drive-decide.js +227 -0
  31. package/dist/core/pipeline/error-feedback.js +161 -0
  32. package/dist/core/pipeline/loop-expansion.js +124 -0
  33. package/dist/{result-normalize.js → core/pipeline/result-normalize.js} +14 -37
  34. package/dist/core/pipeline/runner.js +230 -0
  35. package/dist/{contract-migration.js → core/state/contract-migration.js} +68 -92
  36. package/dist/{state-migrations.js → core/state/migrations.js} +103 -96
  37. package/dist/core/state/node-projection.js +95 -0
  38. package/dist/core/state/node-snapshot.js +230 -0
  39. package/dist/core/state/run-paths.js +93 -0
  40. package/dist/{schema-validate.js → core/state/schema-validate.js} +35 -28
  41. package/dist/core/state/schema.js +50 -0
  42. package/dist/core/state/state-explosion/digest.js +243 -0
  43. package/dist/core/state/state-explosion/graph.js +527 -0
  44. package/dist/{state-explosion → core/state/state-explosion}/helpers.js +34 -3
  45. package/dist/core/state/state-explosion/report.js +187 -0
  46. package/dist/{state-explosion → core/state/state-explosion}/size.js +25 -7
  47. package/dist/{state-node.js → core/state/state-node.js} +90 -113
  48. package/dist/core/state/types.js +19 -0
  49. package/dist/{validation.js → core/state/validation.js} +64 -131
  50. package/dist/core/trust/evidence-grounding.js +134 -0
  51. package/dist/core/trust/ledger.js +199 -0
  52. package/dist/{telemetry-attestation.js → core/trust/telemetry-attestation.js} +94 -68
  53. package/dist/core/trust/telemetry-ledger.js +127 -0
  54. package/dist/core/types.js +20 -0
  55. package/dist/core/version.js +16 -0
  56. package/dist/{workflow-app-framework.js → core/workflow-apps/app-schema.js} +337 -426
  57. package/dist/mcp/dispatch.js +104 -0
  58. package/dist/mcp/server.js +144 -0
  59. package/dist/mcp-server.js +6 -84
  60. package/dist/{agent-config.js → shell/agent-config.js} +118 -71
  61. package/dist/shell/app-run-cli.js +88 -0
  62. package/dist/shell/audit-cli.js +259 -0
  63. package/dist/shell/audit-provenance.js +83 -0
  64. package/dist/shell/candidate-scoring-io.js +459 -0
  65. package/dist/shell/collaboration-io.js +264 -0
  66. package/dist/shell/commit-summary.js +104 -0
  67. package/dist/shell/commit.js +290 -0
  68. package/dist/shell/coordinator-io.js +476 -0
  69. package/dist/shell/demo-cli.js +19 -0
  70. package/dist/shell/dispatch.js +162 -0
  71. package/dist/shell/doctor.js +292 -0
  72. package/dist/shell/drive.js +885 -0
  73. package/dist/shell/error-feedback-io.js +305 -0
  74. package/dist/shell/eval-io.js +473 -0
  75. package/dist/{multi-agent-eval/format.js → shell/eval-text.js} +78 -49
  76. package/dist/{evidence-reasoning.js → shell/evidence-reasoning.js} +124 -255
  77. package/dist/shell/exec-backend-cli.js +88 -0
  78. package/dist/shell/execution-backend/agent.js +507 -0
  79. package/dist/shell/execution-backend/ci.js +15 -0
  80. package/dist/shell/execution-backend/container.js +69 -0
  81. package/dist/shell/execution-backend/envelopes.js +55 -0
  82. package/dist/shell/execution-backend/local.js +113 -0
  83. package/dist/shell/execution-backend/probes.js +175 -0
  84. package/dist/shell/execution-backend/registry.js +402 -0
  85. package/dist/shell/execution-backend/remote.js +128 -0
  86. package/dist/shell/execution-backend/types.js +11 -0
  87. package/dist/shell/feedback-cli.js +81 -0
  88. package/dist/shell/feedback-operations.js +48 -0
  89. package/dist/shell/fs-atomic.js +276 -0
  90. package/dist/shell/harness.js +98 -0
  91. package/dist/shell/ledger-cli.js +212 -0
  92. package/dist/shell/ledger-io.js +169 -0
  93. package/dist/shell/man-cli.js +89 -0
  94. package/dist/shell/metrics-cli.js +100 -0
  95. package/dist/shell/multi-agent-cli.js +1002 -0
  96. package/dist/shell/multi-agent-host.js +563 -0
  97. package/dist/shell/multi-agent-io.js +387 -0
  98. package/dist/{multi-agent-operator-ux.js → shell/multi-agent-operator-ux.js} +234 -191
  99. package/dist/shell/node-store.js +124 -0
  100. package/dist/{observability/format.js → shell/observability-format.js} +7 -1
  101. package/dist/{observability/intake.js → shell/observability-intake.js} +79 -56
  102. package/dist/{observability.js → shell/observability.js} +159 -332
  103. package/dist/{onramp.js → shell/onramp.js} +11 -0
  104. package/dist/{operator-ux/format.js → shell/operator-ux-text.js} +250 -239
  105. package/dist/shell/operator-ux.js +431 -0
  106. package/dist/shell/orchestrator.js +231 -0
  107. package/dist/shell/pipeline-cli.js +667 -0
  108. package/dist/shell/pipeline.js +217 -0
  109. package/dist/shell/reclamation-io.js +1366 -0
  110. package/dist/shell/registry-cli.js +344 -0
  111. package/dist/{remote-source.js → shell/remote-source.js} +2 -2
  112. package/dist/shell/report-cli.js +101 -0
  113. package/dist/shell/report-view-cli.js +117 -0
  114. package/dist/{orchestrator → shell}/report.js +289 -282
  115. package/dist/shell/reporter.js +62 -0
  116. package/dist/shell/run-export-cli.js +106 -0
  117. package/dist/shell/run-export.js +680 -0
  118. package/dist/shell/run-registry-io.js +1014 -0
  119. package/dist/shell/run-store.js +164 -0
  120. package/dist/{sandbox-profile.js → shell/sandbox-profile.js} +134 -95
  121. package/dist/{scheduler.js → shell/scheduler-io.js} +257 -48
  122. package/dist/shell/scheduling-io.js +321 -0
  123. package/dist/shell/state-cli.js +181 -0
  124. package/dist/shell/state-explosion-cli.js +197 -0
  125. package/dist/shell/telemetry-cli.js +85 -0
  126. package/dist/{telemetry-demo.js → shell/telemetry-demo.js} +149 -119
  127. package/dist/shell/telemetry-ledger-io.js +132 -0
  128. package/dist/{term.js → shell/term.js} +36 -46
  129. package/dist/shell/topology-io.js +361 -0
  130. package/dist/shell/trust-audit.js +472 -0
  131. package/dist/{multi-agent-trust.js → shell/trust-policy-io.js} +67 -205
  132. package/dist/shell/verifier.js +48 -0
  133. package/dist/shell/workbench-host.js +258 -0
  134. package/dist/shell/workbench-text.js +18 -0
  135. package/dist/shell/workbench.js +170 -0
  136. package/dist/shell/worker-cli.js +124 -0
  137. package/dist/shell/worker-isolation.js +852 -0
  138. package/dist/shell/workflow-app-loader.js +650 -0
  139. package/docs/agent-delegation-drive.7.md +4 -0
  140. package/docs/cli-mcp-parity.7.md +282 -219
  141. package/docs/contract-migration-tooling.7.md +4 -0
  142. package/docs/control-plane-scheduling.7.md +4 -0
  143. package/docs/durable-state-and-locking.7.md +4 -0
  144. package/docs/evidence-adoption-reasoning-chain.7.md +4 -0
  145. package/docs/execution-backends.7.md +4 -0
  146. package/docs/multi-agent-cli-mcp-surface.7.md +4 -0
  147. package/docs/multi-agent-eval-replay-harness.7.md +4 -0
  148. package/docs/multi-agent-operator-ux.7.md +4 -0
  149. package/docs/node-snapshot-diff-replay.7.md +4 -0
  150. package/docs/observability-cost-accounting.7.md +6 -1
  151. package/docs/project-index.md +137 -71
  152. package/docs/real-execution-backends.7.md +4 -0
  153. package/docs/release-and-migration.7.md +4 -0
  154. package/docs/release-tooling.7.md +4 -0
  155. package/docs/remote-source-review.7.md +4 -4
  156. package/docs/report-verifiable-bundle.7.md +1 -1
  157. package/docs/run-registry-control-plane.7.md +4 -0
  158. package/docs/run-retention-reclamation.7.md +25 -0
  159. package/docs/security-trust-hardening.7.md +3 -1
  160. package/docs/state-explosion-management.7.md +4 -0
  161. package/docs/team-collaboration.7.md +4 -0
  162. package/docs/web-desktop-workbench.7.md +15 -1
  163. package/manifest/plugin.manifest.json +1 -1
  164. package/manifest/source-context-profiles.json +9 -13
  165. package/package.json +1 -1
  166. package/scripts/agents/agent-adapter-core.js +22 -2
  167. package/scripts/agents/claude-p-agent.js +8 -3
  168. package/scripts/agents/cw-attest-wrap.js +2 -2
  169. package/scripts/agents/gemini-agent.js +5 -1
  170. package/scripts/agents/opencode-agent.js +5 -1
  171. package/scripts/bump-version.js +4 -3
  172. package/scripts/canonical-apps.js +4 -4
  173. package/scripts/dogfood-architecture-review.js +2 -3
  174. package/scripts/dogfood-release.js +3 -3
  175. package/scripts/gen-parity-doc.js +15 -2
  176. package/scripts/golden-path.js +4 -4
  177. package/scripts/onramp-check.js +1 -1
  178. package/scripts/parity-check.js +38 -21
  179. package/scripts/release-flow.js +2 -2
  180. package/scripts/sync-project-index.js +51 -27
  181. package/scripts/validate-run-state-schema.js +2 -2
  182. package/scripts/version-sync-check.js +30 -30
  183. package/dist/candidate-scoring.js +0 -729
  184. package/dist/capability-core.js +0 -1189
  185. package/dist/capability-registry.js +0 -885
  186. package/dist/cli/command-surface.js +0 -494
  187. package/dist/cli/format.js +0 -56
  188. package/dist/cli/handlers/audit.js +0 -82
  189. package/dist/cli/handlers/blackboard.js +0 -81
  190. package/dist/cli/handlers/candidate.js +0 -40
  191. package/dist/cli/handlers/clones.js +0 -34
  192. package/dist/cli/handlers/collaboration.js +0 -61
  193. package/dist/cli/handlers/eval.js +0 -40
  194. package/dist/cli/handlers/ledger.js +0 -169
  195. package/dist/cli/handlers/maintenance.js +0 -107
  196. package/dist/cli/handlers/multi-agent.js +0 -165
  197. package/dist/cli/handlers/node.js +0 -41
  198. package/dist/cli/handlers/operational.js +0 -155
  199. package/dist/cli/handlers/operator.js +0 -146
  200. package/dist/cli/handlers/registry.js +0 -68
  201. package/dist/cli/handlers/run.js +0 -153
  202. package/dist/cli/handlers/scheduling.js +0 -132
  203. package/dist/cli/handlers/workbench.js +0 -41
  204. package/dist/cli/handlers/worker.js +0 -45
  205. package/dist/cli/run-summary.js +0 -45
  206. package/dist/clones.js +0 -162
  207. package/dist/collaboration.js +0 -726
  208. package/dist/commit.js +0 -592
  209. package/dist/compare.js +0 -18
  210. package/dist/coordinator/classify.js +0 -45
  211. package/dist/coordinator/paths.js +0 -42
  212. package/dist/coordinator/util.js +0 -126
  213. package/dist/coordinator.js +0 -990
  214. package/dist/daemon.js +0 -44
  215. package/dist/dispatch.js +0 -250
  216. package/dist/doctor.js +0 -212
  217. package/dist/drive.js +0 -864
  218. package/dist/error-feedback.js +0 -419
  219. package/dist/evidence-grounding.js +0 -184
  220. package/dist/execution-backend/agent.js +0 -354
  221. package/dist/execution-backend/probes.js +0 -112
  222. package/dist/execution-backend/util.js +0 -47
  223. package/dist/execution-backend.js +0 -961
  224. package/dist/gates.js +0 -48
  225. package/dist/harness.js +0 -61
  226. package/dist/ledger.js +0 -313
  227. package/dist/loop-expansion.js +0 -60
  228. package/dist/mcp/tool-call.js +0 -470
  229. package/dist/mcp/tool-definitions.js +0 -1066
  230. package/dist/mcp-surface.js +0 -30
  231. package/dist/multi-agent/graph.js +0 -84
  232. package/dist/multi-agent/helpers.js +0 -141
  233. package/dist/multi-agent/ids.js +0 -20
  234. package/dist/multi-agent/paths.js +0 -22
  235. package/dist/multi-agent-eval/normalize.js +0 -51
  236. package/dist/multi-agent-eval.js +0 -678
  237. package/dist/multi-agent-host.js +0 -777
  238. package/dist/multi-agent.js +0 -984
  239. package/dist/node-projection.js +0 -59
  240. package/dist/node-snapshot.js +0 -260
  241. package/dist/operator-ux.js +0 -631
  242. package/dist/orchestrator/app-operations.js +0 -211
  243. package/dist/orchestrator/audit-operations.js +0 -182
  244. package/dist/orchestrator/candidate-operations.js +0 -117
  245. package/dist/orchestrator/cli-options.js +0 -294
  246. package/dist/orchestrator/collaboration-operations.js +0 -86
  247. package/dist/orchestrator/feedback-operations.js +0 -81
  248. package/dist/orchestrator/host-operations.js +0 -78
  249. package/dist/orchestrator/lifecycle-operations.js +0 -650
  250. package/dist/orchestrator/migration-operations.js +0 -44
  251. package/dist/orchestrator/multi-agent-operations.js +0 -362
  252. package/dist/orchestrator/topology-operations.js +0 -84
  253. package/dist/orchestrator.js +0 -925
  254. package/dist/pipeline-runner.js +0 -285
  255. package/dist/reclamation/hash.js +0 -72
  256. package/dist/reclamation.js +0 -812
  257. package/dist/reporter.js +0 -67
  258. package/dist/run-export.js +0 -815
  259. package/dist/run-registry/derive.js +0 -175
  260. package/dist/run-registry/format.js +0 -124
  261. package/dist/run-registry/gc.js +0 -251
  262. package/dist/run-registry/policy.js +0 -16
  263. package/dist/run-registry/queue.js +0 -115
  264. package/dist/run-registry.js +0 -850
  265. package/dist/run-state-schema.js +0 -68
  266. package/dist/scheduling.js +0 -184
  267. package/dist/state-explosion.js +0 -1014
  268. package/dist/state.js +0 -367
  269. package/dist/telemetry-ledger.js +0 -196
  270. package/dist/topology.js +0 -565
  271. package/dist/triggers.js +0 -184
  272. package/dist/trust-audit.js +0 -644
  273. package/dist/types/blackboard.js +0 -2
  274. package/dist/types/candidate.js +0 -2
  275. package/dist/types/collaboration.js +0 -2
  276. package/dist/types/core.js +0 -2
  277. package/dist/types/drive.js +0 -10
  278. package/dist/types/error-feedback.js +0 -2
  279. package/dist/types/evidence-reasoning.js +0 -2
  280. package/dist/types/execution-backend.js +0 -2
  281. package/dist/types/multi-agent.js +0 -2
  282. package/dist/types/observability.js +0 -2
  283. package/dist/types/pipeline.js +0 -2
  284. package/dist/types/reclamation.js +0 -8
  285. package/dist/types/report-bundle.js +0 -6
  286. package/dist/types/result.js +0 -2
  287. package/dist/types/run-registry.js +0 -2
  288. package/dist/types/run.js +0 -2
  289. package/dist/types/sandbox.js +0 -2
  290. package/dist/types/schedule.js +0 -2
  291. package/dist/types/state-node.js +0 -2
  292. package/dist/types/topology.js +0 -2
  293. package/dist/types/trust.js +0 -2
  294. package/dist/types/workbench.js +0 -2
  295. package/dist/types/worker.js +0 -2
  296. package/dist/types/workflow-app.js +0 -2
  297. package/dist/types.js +0 -44
  298. package/dist/util/fingerprint.js +0 -19
  299. package/dist/util/fingerprint.test.js +0 -27
  300. package/dist/verifier.js +0 -78
  301. package/dist/version.js +0 -8
  302. package/dist/workbench-host.js +0 -192
  303. package/dist/workbench.js +0 -192
  304. package/dist/worker-accept/acceptance.js +0 -114
  305. package/dist/worker-accept/blackboard-fanout.js +0 -80
  306. package/dist/worker-accept/blackboard-linkage.js +0 -19
  307. package/dist/worker-accept/context.js +0 -2
  308. package/dist/worker-accept/telemetry-ledger.js +0 -126
  309. package/dist/worker-accept/validation.js +0 -77
  310. package/dist/worker-accept/verifier-completion.js +0 -73
  311. package/dist/worker-isolation/helpers.js +0 -51
  312. package/dist/worker-isolation/paths.js +0 -46
  313. package/dist/worker-isolation.js +0 -656
  314. package/dist/workflow-api.js +0 -131
  315. /package/dist/{types → core/types}/boundary.js +0 -0
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ // core/state/node-snapshot.ts — snapshotNode / diffNodeSnapshots /
3
+ // replayNodeSnapshot / verifyNodeReplay.
4
+ //
5
+ // MILESTONE 3. Byte-exact port of the old build's src/node-snapshot.ts,
6
+ // split into a PURE half (this file) and a shell half (shell/node-
7
+ // store.ts, which supplies the actual `writeJson` persistence and file
8
+ // scans for readNodeSnapshot/readNodeReplay). Every function here is pure
9
+ // given `(run, clock)` — no direct fs/Date calls; `now` is always an
10
+ // explicit parameter, `persist` is always a caller-supplied callback.
11
+ //
12
+ // RAW vs NORMALIZED fingerprints [docs/rebuild/PLAN.md byte-compat item 8 — do not
13
+ // merge these two code paths]:
14
+ // - `sourceFingerprint` is RAW: built from the node's raw id/status/
15
+ // updatedAt plus raw artifact/evidence id+path strings. ANY transition
16
+ // (even just `updatedAt` ticking) flips it — this is what freshness
17
+ // detection needs.
18
+ // - `body`/`outputFingerprint` are NORMALIZED via `projectNodeBody`/
19
+ // `replayStableStringify` (node-projection.ts): no timestamps, scrubbed
20
+ // paths, so replay output is byte-stable across recaptures of the same
21
+ // logical state.
22
+ // These stay two separate functions (`sourceFingerprint` vs
23
+ // `snapshotBody`/`outputFingerprint`'s computation) — never one call.
24
+ //
25
+ // Evidence: SPEC/state-core.md "src/node-snapshot.ts — snapshot / diff /
26
+ // replay", "Raw vs. normalized fingerprints", "Snapshot freshness
27
+ // fail-closed".
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.NodeSnapshotError = exports.NODE_SNAPSHOT_SCHEMA_VERSION = void 0;
30
+ exports.findRunNode = findRunNode;
31
+ exports.sourceFingerprint = sourceFingerprint;
32
+ exports.snapshotNode = snapshotNode;
33
+ exports.loadNodeSnapshot = loadNodeSnapshot;
34
+ exports.diffNodeSnapshots = diffNodeSnapshots;
35
+ exports.replayNodeSnapshot = replayNodeSnapshot;
36
+ exports.verifyNodeReplay = verifyNodeReplay;
37
+ const hash_1 = require("../hash");
38
+ const node_projection_1 = require("./node-projection");
39
+ exports.NODE_SNAPSHOT_SCHEMA_VERSION = 1;
40
+ /** Structured fail-closed error (mirrors PipelineContractError's shape). */
41
+ class NodeSnapshotError extends Error {
42
+ code;
43
+ freshness;
44
+ details;
45
+ constructor(code, message, options = {}) {
46
+ super(message);
47
+ this.name = "NodeSnapshotError";
48
+ this.code = code;
49
+ this.freshness = options.freshness;
50
+ this.details = options.details;
51
+ }
52
+ }
53
+ exports.NodeSnapshotError = NodeSnapshotError;
54
+ const SNAPSHOT_SECTIONS = [
55
+ "status",
56
+ "inputs",
57
+ "outputs",
58
+ "artifacts",
59
+ "evidence",
60
+ "errors",
61
+ "links",
62
+ "metadata",
63
+ ];
64
+ /** Look up a StateNode by id in `run.nodes`, or `undefined` if absent. Pure
65
+ * data lookup — no fs. */
66
+ function findRunNode(run, nodeId) {
67
+ return (run.nodes || []).find((candidate) => candidate.id === nodeId);
68
+ }
69
+ /** NORMALIZED projection of a node — timestamps/paths stripped, so it is
70
+ * byte-stable across captures of the same logical state. */
71
+ function snapshotBody(node) {
72
+ return (0, node_projection_1.projectNodeBody)(node);
73
+ }
74
+ /** RAW fingerprint (NOT normalized): any transition (updatedAt/status) or
75
+ * artifact/evidence change flips it — this is how drift is detected. */
76
+ function sourceFingerprint(node) {
77
+ return (0, hash_1.fingerprintStrings)([
78
+ `node:${node.id}:${node.status}:${node.updatedAt}`,
79
+ ...node.artifacts.map((artifact) => `artifact:${artifact.id}:${artifact.path}`),
80
+ ...node.evidence.map((evidence) => `evidence:${evidence.id}:${evidence.path || ""}`),
81
+ ]);
82
+ }
83
+ /** Snapshot one StateNode by id. Throws (fail closed) if the node is
84
+ * absent. */
85
+ function snapshotNode(run, nodeId, options = {}) {
86
+ const node = findRunNode(run, nodeId);
87
+ if (!node) {
88
+ throw new NodeSnapshotError("node-absent", `Cannot snapshot: node ${nodeId} not found in run ${run.id}`, {
89
+ freshness: "absent",
90
+ });
91
+ }
92
+ const fingerprint = sourceFingerprint(node);
93
+ const snapshot = {
94
+ schemaVersion: 1,
95
+ snapshotId: `snap-${safeFileNamePure(nodeId)}-${fingerprint.replace("sha256:", "").slice(0, 12)}`,
96
+ runId: run.id,
97
+ nodeId,
98
+ capturedAt: options.now || new Date(0).toISOString(),
99
+ sourceFingerprint: fingerprint,
100
+ body: snapshotBody(node),
101
+ };
102
+ if (options.persist !== false && typeof options.persist === "function")
103
+ options.persist(snapshot);
104
+ return snapshot;
105
+ }
106
+ /** Recompute freshness from the CURRENT source. `valid | stale | absent`. */
107
+ function loadNodeSnapshot(run, snapshot, pathExists = () => true) {
108
+ const node = findRunNode(run, snapshot.nodeId);
109
+ if (!node) {
110
+ return { snapshot, freshness: "absent", reason: `source node ${snapshot.nodeId} is gone from run ${run.id}` };
111
+ }
112
+ const missingArtifact = node.artifacts.find((artifact) => artifact.path && !pathExists(artifact.path));
113
+ if (missingArtifact) {
114
+ return { snapshot, freshness: "absent", reason: `referenced artifact path is unreadable: ${missingArtifact.id}` };
115
+ }
116
+ if (sourceFingerprint(node) !== snapshot.sourceFingerprint) {
117
+ return { snapshot, freshness: "stale", reason: `source node ${snapshot.nodeId} changed since capture` };
118
+ }
119
+ return { snapshot, freshness: "valid" };
120
+ }
121
+ function sectionValue(body, section) {
122
+ if (section === "links")
123
+ return { parents: body.parents, children: body.children };
124
+ return body[section];
125
+ }
126
+ /** Stable, structural diff of two snapshots: 8 sections, in fixed order. */
127
+ function diffNodeSnapshots(baseline, candidate) {
128
+ const sections = SNAPSHOT_SECTIONS.map((section) => {
129
+ const baselineValue = sectionValue(baseline.body, section);
130
+ const candidateValue = sectionValue(candidate.body, section);
131
+ const sameBytes = (0, node_projection_1.replayStableStringify)(baselineValue) === (0, node_projection_1.replayStableStringify)(candidateValue);
132
+ let change;
133
+ if (sameBytes)
134
+ change = "same";
135
+ else if (baselineValue === undefined)
136
+ change = "added";
137
+ else if (candidateValue === undefined)
138
+ change = "removed";
139
+ else
140
+ change = "changed";
141
+ const entry = { section, change };
142
+ if (change !== "same") {
143
+ entry.baseline = baselineValue;
144
+ entry.candidate = candidateValue;
145
+ }
146
+ return entry;
147
+ });
148
+ return {
149
+ schemaVersion: 1,
150
+ runId: baseline.runId,
151
+ baselineSnapshotId: baseline.snapshotId,
152
+ candidateSnapshotId: candidate.snapshotId,
153
+ baselineNodeId: baseline.nodeId,
154
+ candidateNodeId: candidate.nodeId,
155
+ changed: sections.some((entry) => entry.change !== "same"),
156
+ sections,
157
+ };
158
+ }
159
+ /** Deterministically replay one node from its snapshot, fail-closed on
160
+ * drift: freshness not `valid` throws `snapshot-stale`/`snapshot-absent`
161
+ * BEFORE any replay bytes are built. */
162
+ function replayNodeSnapshot(run, snapshot, options = {}) {
163
+ const { freshness, reason } = loadNodeSnapshot(run, snapshot, options.pathExists);
164
+ if (freshness !== "valid") {
165
+ throw new NodeSnapshotError(freshness === "stale" ? "snapshot-stale" : "snapshot-absent", reason || `cannot replay a ${freshness} snapshot of node ${snapshot.nodeId}`, { freshness, details: { runId: run.id, nodeId: snapshot.nodeId } });
166
+ }
167
+ const body = (0, node_projection_1.normalizeValue)(snapshot.body);
168
+ const outputFingerprint = (0, hash_1.fingerprintStrings)([(0, node_projection_1.replayStableStringify)(body)]);
169
+ const replay = {
170
+ schemaVersion: 1,
171
+ replayId: `replay-${snapshot.snapshotId}-${outputFingerprint.replace("sha256:", "").slice(0, 8)}`,
172
+ runId: run.id,
173
+ nodeId: snapshot.nodeId,
174
+ snapshotId: snapshot.snapshotId,
175
+ replayedAt: options.now || new Date(0).toISOString(),
176
+ freshness: "valid",
177
+ contractValidated: Boolean(snapshot.body.contractId),
178
+ outputFingerprint,
179
+ body,
180
+ };
181
+ if (options.persist !== false && typeof options.persist === "function")
182
+ options.persist(replay);
183
+ return replay;
184
+ }
185
+ /** Compare a replay to a FRESH (non-persisted) snapshot of the source node;
186
+ * pass = byte-identical normalized body. Never throws — a drifted source
187
+ * is a `pass:false` finding, not an exception. */
188
+ function verifyNodeReplay(run, replay, options = {}) {
189
+ const fresh = findRunNode(run, replay.nodeId);
190
+ if (!fresh) {
191
+ return {
192
+ schemaVersion: 1,
193
+ runId: run.id,
194
+ nodeId: replay.nodeId,
195
+ replayId: replay.replayId,
196
+ pass: false,
197
+ freshness: "absent",
198
+ findings: [{ id: "source-absent", severity: "error", category: "source", reason: `source node ${replay.nodeId} is gone` }],
199
+ };
200
+ }
201
+ const freshSnapshot = snapshotNode(run, replay.nodeId, { now: options.now, persist: false });
202
+ const diff = diffNodeSnapshots(freshSnapshot, { ...freshSnapshot, body: replay.body, snapshotId: replay.snapshotId });
203
+ const findings = diff.sections
204
+ .filter((section) => section.change !== "same")
205
+ .map((section) => ({
206
+ id: `drift:${section.section}`,
207
+ severity: "error",
208
+ category: section.section,
209
+ reason: `replay diverged from source in ${section.section}`,
210
+ baselineRef: replay.snapshotId,
211
+ replayRef: replay.replayId,
212
+ }));
213
+ return {
214
+ schemaVersion: 1,
215
+ runId: run.id,
216
+ nodeId: replay.nodeId,
217
+ replayId: replay.replayId,
218
+ pass: findings.length === 0,
219
+ freshness: "valid",
220
+ findings,
221
+ };
222
+ }
223
+ /** Pure re-implementation of shell/fs-atomic.ts's naming rule (replaces
224
+ * every run of chars outside `[a-zA-Z0-9_.:-]` with a single `_`), needed
225
+ * here purely as a STRING transform for id formatting — no fs. Kept in
226
+ * sync with `safeFileName` by the same regex; both are pinned by the same
227
+ * SPEC line (state-core.md's `safeFileName(value)`). */
228
+ function safeFileNamePure(value) {
229
+ return value.replace(/[^a-zA-Z0-9_.:-]+/g, "_");
230
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ // core/state/run-paths.ts — createRunPaths, ensureRunDirs.
3
+ //
4
+ // MILESTONE 3. Byte-exact port of the old build's src/state.ts:10-50.
5
+ // `createRunPaths` is pure path math (core/); `ensureRunDirs` touches disk
6
+ // (mkdirSync) so it lives here but is called from shell/run-store.ts, the
7
+ // only place that actually creates a run directory tree.
8
+ //
9
+ // Evidence: SPEC/state-core.md "src/state.ts — persistence kernel" and "The
10
+ // full .cw/runs/<run-id>/ layout".
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.createRunPaths = createRunPaths;
46
+ exports.ensureRunDirs = ensureRunDirs;
47
+ const fs = __importStar(require("node:fs"));
48
+ const path = __importStar(require("node:path"));
49
+ /** The 16-key RunPaths object, all joined under `runDir`. */
50
+ function createRunPaths(runDir) {
51
+ return {
52
+ runDir,
53
+ state: path.join(runDir, "state.json"),
54
+ report: path.join(runDir, "report.md"),
55
+ tasksDir: path.join(runDir, "tasks"),
56
+ resultsDir: path.join(runDir, "results"),
57
+ dispatchesDir: path.join(runDir, "dispatches"),
58
+ artifactsDir: path.join(runDir, "artifacts"),
59
+ commitsDir: path.join(runDir, "commits"),
60
+ stateNodesDir: path.join(runDir, "nodes"),
61
+ feedbackDir: path.join(runDir, "feedback"),
62
+ auditDir: path.join(runDir, "audit"),
63
+ workersDir: path.join(runDir, "workers"),
64
+ candidatesDir: path.join(runDir, "candidates"),
65
+ multiAgentDir: path.join(runDir, "multi-agent"),
66
+ blackboardDir: path.join(runDir, "blackboard"),
67
+ topologiesDir: path.join(runDir, "topologies"),
68
+ };
69
+ }
70
+ /** `mkdirSync` (recursive) every dir this run needs. Missing optional dir
71
+ * fields fall back to `path.join(runDir, "<name>")`, matching the old
72
+ * build's defensive default (a RunPaths loaded from an old/partial
73
+ * state.json may be missing an optional key). */
74
+ function ensureRunDirs(paths) {
75
+ const dirs = [
76
+ paths.runDir,
77
+ paths.tasksDir,
78
+ paths.resultsDir,
79
+ paths.dispatchesDir,
80
+ paths.artifactsDir,
81
+ paths.commitsDir,
82
+ paths.stateNodesDir,
83
+ paths.feedbackDir,
84
+ paths.auditDir || path.join(paths.runDir, "audit"),
85
+ paths.workersDir || path.join(paths.runDir, "workers"),
86
+ paths.candidatesDir || path.join(paths.runDir, "candidates"),
87
+ paths.multiAgentDir || path.join(paths.runDir, "multi-agent"),
88
+ paths.blackboardDir || path.join(paths.runDir, "blackboard"),
89
+ paths.topologiesDir || path.join(paths.runDir, "topologies"),
90
+ ];
91
+ for (const dir of dirs)
92
+ fs.mkdirSync(dir, { recursive: true });
93
+ }
@@ -1,21 +1,14 @@
1
1
  "use strict";
2
- // Minimal, dependency-free structural schema validation (Track 3).
2
+ // core/state/schema-validate.ts dependency-free JSON-schema subset.
3
3
  //
4
- // CW declares an optional output `schema` per task (WorkflowTaskDefinition.schema);
5
- // this enforces it at result-acceptance time so CW only records structured output
6
- // it has actually validated the other half of "auditable" (Track 1 proves the
7
- // telemetry is real; this proves the result SHAPE is what was declared).
4
+ // MILESTONE 3. Byte-exact port of the old build's src/schema-validate.ts.
5
+ // Deliberately a SUBSET of JSON Schema (type, const, enum, required,
6
+ // properties, additionalProperties:false, items)adds no runtime
7
+ // dependency. Unsupported keywords are surfaced as a stderr diagnostic
8
+ // (TTY only), never enforced.
8
9
  //
9
- // DELIBERATELY a subset of JSON Schema, NOT a full implementation: it adds NO
10
- // runtime dependency (the portability red line — CI runs on node/npm/git only).
11
- // Supported keywords cover structured-agent-output contracts:
12
- // type (object|array|string|number|integer|boolean|null, or an array of them),
13
- // enum, const, required, properties, additionalProperties (false), items.
14
- // Unsupported keywords ($ref, allOf/anyOf/oneOf, pattern, formats, numeric
15
- // bounds) are surfaced as WARNINGS (a constraint that wasn't checked), so the
16
- // operator can see their schema reliance is incomplete.
17
- // (If full JSON Schema is needed later, swap this module's impl for ajv behind
18
- // the same signature.)
10
+ // Evidence: SPEC/state-core.md "src/schema-validate.ts dependency-free
11
+ // JSON-schema subset", "Schema-validator error strings".
19
12
  Object.defineProperty(exports, "__esModule", { value: true });
20
13
  exports.validateAgainstSchema = validateAgainstSchema;
21
14
  function typeOf(value) {
@@ -23,7 +16,7 @@ function typeOf(value) {
23
16
  return "null";
24
17
  if (Array.isArray(value))
25
18
  return "array";
26
- return typeof value; // object | string | number | boolean | undefined | function
19
+ return typeof value;
27
20
  }
28
21
  function matchesType(value, type) {
29
22
  switch (type) {
@@ -42,38 +35,53 @@ function matchesType(value, type) {
42
35
  case "null":
43
36
  return value === null;
44
37
  default:
45
- return true; // unknown declared type not enforced (never a false fail)
38
+ return true; // unknown declared type => not enforced (never a false fail)
46
39
  }
47
40
  }
48
- /** Validate `value` against `schema`. Returns a list of human-readable errors;
49
- * empty ⇒ valid. Pure + deterministic; never throws on a malformed schema (an
50
- * unparseable schema constraint is skipped, not treated as a failure). */
41
+ const UNSUPPORTED_KEYWORDS = new Set([
42
+ "$ref",
43
+ "allOf",
44
+ "anyOf",
45
+ "oneOf",
46
+ "not",
47
+ "pattern",
48
+ "format",
49
+ "minimum",
50
+ "maximum",
51
+ "minLength",
52
+ "maxLength",
53
+ "minItems",
54
+ "maxItems",
55
+ "uniqueItems",
56
+ "contains",
57
+ "if",
58
+ "then",
59
+ "else",
60
+ ]);
61
+ /** Validate `value` against `schema`. Returns a list of human-readable
62
+ * errors; empty means valid. Pure + deterministic; never throws on a
63
+ * malformed schema. */
51
64
  function validateAgainstSchema(value, schema, path = "$") {
52
65
  const errors = [];
53
66
  if (!schema || typeof schema !== "object")
54
67
  return errors;
55
- // Unsupported keywords surface as diagnostics (Rule of Silence: stderr)
56
- const UNSUPPORTED = new Set(["$ref", "allOf", "anyOf", "oneOf", "not", "pattern", "format", "minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems", "uniqueItems", "contains", "if", "then", "else"]);
57
- const unsupported = Object.keys(schema).filter((k) => UNSUPPORTED.has(k));
68
+ const unsupported = Object.keys(schema).filter((k) => UNSUPPORTED_KEYWORDS.has(k));
58
69
  if (unsupported.length && process.stderr.isTTY) {
59
70
  process.stderr.write(`[cw] schema at ${path}: unsupported keywords ignored: ${unsupported.join(", ")}\n`);
60
71
  }
61
- // type
62
72
  if (schema.type !== undefined) {
63
73
  const types = Array.isArray(schema.type) ? schema.type.map(String) : [String(schema.type)];
64
74
  if (!types.some((t) => matchesType(value, t))) {
65
75
  errors.push(`${path}: expected type ${types.join("|")}, got ${typeOf(value)}`);
66
- return errors; // type mismatch downstream keyword checks would be noise
76
+ return errors; // type mismatch => downstream keyword checks would be noise
67
77
  }
68
78
  }
69
- // const / enum
70
79
  if ("const" in schema && JSON.stringify(value) !== JSON.stringify(schema.const)) {
71
80
  errors.push(`${path}: expected const ${JSON.stringify(schema.const)}`);
72
81
  }
73
82
  if (Array.isArray(schema.enum) && !schema.enum.some((option) => JSON.stringify(option) === JSON.stringify(value))) {
74
83
  errors.push(`${path}: ${JSON.stringify(value)} is not one of ${JSON.stringify(schema.enum)}`);
75
84
  }
76
- // object: required, properties, additionalProperties:false
77
85
  if (value !== null && typeof value === "object" && !Array.isArray(value)) {
78
86
  const obj = value;
79
87
  if (Array.isArray(schema.required)) {
@@ -94,7 +102,6 @@ function validateAgainstSchema(value, schema, path = "$") {
94
102
  }
95
103
  }
96
104
  }
97
- // array: items (single schema applied to every element)
98
105
  if (Array.isArray(value) && schema.items && typeof schema.items === "object" && !Array.isArray(schema.items)) {
99
106
  value.forEach((element, index) => {
100
107
  errors.push(...validateAgainstSchema(element, schema.items, `${path}[${index}]`));
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // core/state/schema.ts — the single field-list source for WorkflowRun.
3
+ //
4
+ // MILESTONE 3. Byte-exact port of the old build's src/run-state-schema.ts.
5
+ // Both migrations.ts's validation AND (eventually) a build gate derive
6
+ // their field knowledge from this module — a field added to WorkflowRun
7
+ // must be added here too.
8
+ //
9
+ // Evidence: SPEC/state-core.md "src/run-state-schema.ts — the single
10
+ // field-list source".
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OPTIONAL_TOP_LEVEL_KEYS = exports.REQUIRED_RECORD_KEYS = exports.REQUIRED_ARRAY_KEYS = exports.REQUIRED_TOP_LEVEL_KEYS = void 0;
13
+ /** Top-level required keys of WorkflowRun — every key that must exist
14
+ * after migration. */
15
+ exports.REQUIRED_TOP_LEVEL_KEYS = [
16
+ "schemaVersion",
17
+ "id",
18
+ "createdAt",
19
+ "updatedAt",
20
+ "cwd",
21
+ "workflow",
22
+ "inputs",
23
+ "loopStage",
24
+ "phases",
25
+ "tasks",
26
+ "dispatches",
27
+ "commits",
28
+ "paths",
29
+ ];
30
+ /** Top-level keys that must be arrays after migration. */
31
+ exports.REQUIRED_ARRAY_KEYS = ["phases", "tasks", "dispatches", "commits"];
32
+ /** Top-level keys that must be objects (Record) after migration. */
33
+ exports.REQUIRED_RECORD_KEYS = ["workflow", "paths", "multiAgent", "blackboard", "topologies"];
34
+ /** Keys from the WorkflowRun type that are OPTIONAL (exist at type level
35
+ * but are not required by validateMigratedRunState). */
36
+ exports.OPTIONAL_TOP_LEVEL_KEYS = [
37
+ "nodes",
38
+ "contracts",
39
+ "feedback",
40
+ "audit",
41
+ "workers",
42
+ "sandboxProfiles",
43
+ "customSandboxProfiles",
44
+ "candidates",
45
+ "candidateSelections",
46
+ "multiAgent",
47
+ "blackboard",
48
+ "topologies",
49
+ "collaboration",
50
+ ];