cool-workflow 0.1.97 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/README.md +11 -2
  4. package/apps/architecture-review/app.json +1 -1
  5. package/apps/architecture-review-fast/app.json +1 -1
  6. package/apps/end-to-end-golden-path/app.json +1 -1
  7. package/apps/pr-review-fix-ci/app.json +1 -1
  8. package/apps/release-cut/app.json +1 -1
  9. package/apps/research-synthesis/app.json +1 -1
  10. package/dist/cli/dispatch.js +236 -0
  11. package/dist/cli/entry.js +120 -0
  12. package/dist/cli/io.js +21 -4
  13. package/dist/cli/parseargv.js +157 -0
  14. package/dist/cli.js +6 -33
  15. package/dist/core/capability-table.js +3534 -0
  16. package/dist/core/format/help.js +314 -0
  17. package/dist/{state-explosion/format.js → core/format/state-explosion-text.js} +10 -1
  18. package/dist/core/hash.js +137 -0
  19. package/dist/core/multi-agent/candidate-scoring.js +219 -0
  20. package/dist/core/multi-agent/collaboration.js +481 -0
  21. package/dist/core/multi-agent/coordinator.js +515 -0
  22. package/dist/core/multi-agent/eval-replay.js +306 -0
  23. package/dist/core/multi-agent/runtime.js +929 -0
  24. package/dist/core/multi-agent/topology.js +298 -0
  25. package/dist/core/multi-agent/trust-policy.js +197 -0
  26. package/dist/core/pipeline/commit-gate.js +320 -0
  27. package/dist/{pipeline-contract.js → core/pipeline/contract.js} +24 -37
  28. package/dist/core/pipeline/dispatch.js +103 -0
  29. package/dist/core/pipeline/drive-decide.js +227 -0
  30. package/dist/core/pipeline/error-feedback.js +161 -0
  31. package/dist/core/pipeline/loop-expansion.js +124 -0
  32. package/dist/{result-normalize.js → core/pipeline/result-normalize.js} +14 -37
  33. package/dist/core/pipeline/runner.js +230 -0
  34. package/dist/{contract-migration.js → core/state/contract-migration.js} +68 -92
  35. package/dist/{state-migrations.js → core/state/migrations.js} +103 -96
  36. package/dist/core/state/node-projection.js +95 -0
  37. package/dist/core/state/node-snapshot.js +230 -0
  38. package/dist/core/state/run-paths.js +93 -0
  39. package/dist/{schema-validate.js → core/state/schema-validate.js} +35 -28
  40. package/dist/core/state/schema.js +50 -0
  41. package/dist/core/state/state-explosion/digest.js +243 -0
  42. package/dist/core/state/state-explosion/graph.js +527 -0
  43. package/dist/{state-explosion → core/state/state-explosion}/helpers.js +34 -3
  44. package/dist/core/state/state-explosion/report.js +187 -0
  45. package/dist/{state-explosion → core/state/state-explosion}/size.js +25 -7
  46. package/dist/{state-node.js → core/state/state-node.js} +90 -113
  47. package/dist/core/state/types.js +19 -0
  48. package/dist/{validation.js → core/state/validation.js} +64 -131
  49. package/dist/core/trust/evidence-grounding.js +134 -0
  50. package/dist/core/trust/ledger.js +199 -0
  51. package/dist/{telemetry-attestation.js → core/trust/telemetry-attestation.js} +94 -68
  52. package/dist/core/trust/telemetry-ledger.js +127 -0
  53. package/dist/core/types.js +20 -0
  54. package/dist/core/version.js +16 -0
  55. package/dist/{workflow-app-framework.js → core/workflow-apps/app-schema.js} +337 -426
  56. package/dist/mcp/dispatch.js +104 -0
  57. package/dist/mcp/server.js +144 -0
  58. package/dist/mcp-server.js +6 -84
  59. package/dist/{agent-config.js → shell/agent-config.js} +118 -71
  60. package/dist/shell/app-run-cli.js +88 -0
  61. package/dist/shell/audit-cli.js +259 -0
  62. package/dist/shell/audit-provenance.js +83 -0
  63. package/dist/shell/candidate-scoring-io.js +459 -0
  64. package/dist/shell/collaboration-io.js +264 -0
  65. package/dist/shell/commit-summary.js +104 -0
  66. package/dist/shell/commit.js +290 -0
  67. package/dist/shell/coordinator-io.js +476 -0
  68. package/dist/shell/demo-cli.js +19 -0
  69. package/dist/shell/dispatch.js +162 -0
  70. package/dist/{doctor.js → shell/doctor.js} +123 -56
  71. package/dist/shell/drive.js +873 -0
  72. package/dist/shell/error-feedback-io.js +305 -0
  73. package/dist/shell/eval-io.js +473 -0
  74. package/dist/{multi-agent-eval/format.js → shell/eval-text.js} +78 -49
  75. package/dist/{evidence-reasoning.js → shell/evidence-reasoning.js} +124 -255
  76. package/dist/shell/exec-backend-cli.js +88 -0
  77. package/dist/shell/execution-backend/agent.js +475 -0
  78. package/dist/shell/execution-backend/ci.js +15 -0
  79. package/dist/shell/execution-backend/container.js +69 -0
  80. package/dist/shell/execution-backend/envelopes.js +55 -0
  81. package/dist/shell/execution-backend/local.js +113 -0
  82. package/dist/shell/execution-backend/probes.js +175 -0
  83. package/dist/shell/execution-backend/registry.js +402 -0
  84. package/dist/shell/execution-backend/remote.js +128 -0
  85. package/dist/shell/execution-backend/types.js +11 -0
  86. package/dist/shell/feedback-cli.js +81 -0
  87. package/dist/shell/feedback-operations.js +48 -0
  88. package/dist/shell/fs-atomic.js +276 -0
  89. package/dist/shell/harness.js +98 -0
  90. package/dist/shell/ledger-cli.js +212 -0
  91. package/dist/shell/ledger-io.js +169 -0
  92. package/dist/shell/man-cli.js +89 -0
  93. package/dist/shell/metrics-cli.js +98 -0
  94. package/dist/shell/multi-agent-cli.js +1002 -0
  95. package/dist/shell/multi-agent-host.js +563 -0
  96. package/dist/shell/multi-agent-io.js +387 -0
  97. package/dist/{multi-agent-operator-ux.js → shell/multi-agent-operator-ux.js} +234 -191
  98. package/dist/shell/node-store.js +124 -0
  99. package/dist/{observability/format.js → shell/observability-format.js} +7 -1
  100. package/dist/{observability/intake.js → shell/observability-intake.js} +79 -56
  101. package/dist/{observability.js → shell/observability.js} +159 -332
  102. package/dist/{onramp.js → shell/onramp.js} +11 -0
  103. package/dist/{operator-ux/format.js → shell/operator-ux-text.js} +250 -239
  104. package/dist/shell/operator-ux.js +431 -0
  105. package/dist/shell/orchestrator.js +231 -0
  106. package/dist/shell/pipeline-cli.js +667 -0
  107. package/dist/shell/pipeline.js +217 -0
  108. package/dist/shell/reclamation-io.js +1366 -0
  109. package/dist/shell/registry-cli.js +329 -0
  110. package/dist/{remote-source.js → shell/remote-source.js} +12 -5
  111. package/dist/shell/report-cli.js +101 -0
  112. package/dist/shell/report-view-cli.js +117 -0
  113. package/dist/{orchestrator → shell}/report.js +289 -282
  114. package/dist/shell/reporter.js +62 -0
  115. package/dist/shell/run-export-cli.js +106 -0
  116. package/dist/shell/run-export.js +680 -0
  117. package/dist/shell/run-registry-io.js +1014 -0
  118. package/dist/shell/run-store.js +164 -0
  119. package/dist/{sandbox-profile.js → shell/sandbox-profile.js} +134 -95
  120. package/dist/{scheduler.js → shell/scheduler-io.js} +248 -48
  121. package/dist/shell/scheduling-io.js +311 -0
  122. package/dist/shell/state-cli.js +181 -0
  123. package/dist/shell/state-explosion-cli.js +197 -0
  124. package/dist/shell/telemetry-cli.js +85 -0
  125. package/dist/{telemetry-demo.js → shell/telemetry-demo.js} +149 -119
  126. package/dist/shell/telemetry-ledger-io.js +132 -0
  127. package/dist/{term.js → shell/term.js} +36 -46
  128. package/dist/shell/topology-io.js +361 -0
  129. package/dist/shell/trust-audit.js +471 -0
  130. package/dist/{multi-agent-trust.js → shell/trust-policy-io.js} +67 -205
  131. package/dist/shell/verifier.js +48 -0
  132. package/dist/shell/workbench-host.js +250 -0
  133. package/dist/shell/workbench-text.js +18 -0
  134. package/dist/shell/workbench.js +175 -0
  135. package/dist/shell/worker-cli.js +124 -0
  136. package/dist/shell/worker-isolation.js +852 -0
  137. package/dist/shell/workflow-app-loader.js +650 -0
  138. package/docs/agent-delegation-drive.7.md +4 -0
  139. package/docs/cli-mcp-parity.7.md +284 -211
  140. package/docs/contract-migration-tooling.7.md +4 -0
  141. package/docs/control-plane-scheduling.7.md +4 -0
  142. package/docs/cross-agent-ledger.7.md +217 -0
  143. package/docs/designs/handoff-ledger.md +145 -0
  144. package/docs/durable-state-and-locking.7.md +4 -0
  145. package/docs/evidence-adoption-reasoning-chain.7.md +4 -0
  146. package/docs/execution-backends.7.md +4 -0
  147. package/docs/handoff-setup.md +120 -0
  148. package/docs/multi-agent-cli-mcp-surface.7.md +4 -0
  149. package/docs/multi-agent-eval-replay-harness.7.md +4 -0
  150. package/docs/multi-agent-operator-ux.7.md +4 -0
  151. package/docs/node-snapshot-diff-replay.7.md +4 -0
  152. package/docs/observability-cost-accounting.7.md +4 -0
  153. package/docs/project-index.md +143 -71
  154. package/docs/real-execution-backends.7.md +4 -0
  155. package/docs/release-and-migration.7.md +4 -0
  156. package/docs/release-tooling.7.md +4 -0
  157. package/docs/run-registry-control-plane.7.md +4 -0
  158. package/docs/run-retention-reclamation.7.md +25 -0
  159. package/docs/state-explosion-management.7.md +4 -0
  160. package/docs/team-collaboration.7.md +4 -0
  161. package/docs/web-desktop-workbench.7.md +4 -0
  162. package/manifest/plugin.manifest.json +1 -1
  163. package/manifest/source-context-profiles.json +9 -13
  164. package/package.json +1 -1
  165. package/scripts/agents/codex-agent.js +34 -4
  166. package/scripts/agents/cw-attest-wrap.js +2 -2
  167. package/scripts/bump-version.js +4 -3
  168. package/scripts/canonical-apps.js +4 -4
  169. package/scripts/children/batch-delegate-child.js +30 -10
  170. package/scripts/dogfood-architecture-review.js +2 -3
  171. package/scripts/dogfood-release.js +3 -3
  172. package/scripts/gen-parity-doc.js +15 -2
  173. package/scripts/golden-path.js +4 -4
  174. package/scripts/onramp-check.js +1 -1
  175. package/scripts/parity-check.js +38 -21
  176. package/scripts/release-flow.js +9 -3
  177. package/scripts/sync-project-index.js +51 -27
  178. package/scripts/validate-run-state-schema.js +2 -2
  179. package/scripts/version-sync-check.js +30 -30
  180. package/dist/candidate-scoring.js +0 -729
  181. package/dist/capability-core.js +0 -1186
  182. package/dist/capability-registry.js +0 -879
  183. package/dist/cli/command-surface.js +0 -490
  184. package/dist/cli/format.js +0 -56
  185. package/dist/cli/handlers/audit.js +0 -82
  186. package/dist/cli/handlers/blackboard.js +0 -81
  187. package/dist/cli/handlers/candidate.js +0 -40
  188. package/dist/cli/handlers/clones.js +0 -34
  189. package/dist/cli/handlers/collaboration.js +0 -61
  190. package/dist/cli/handlers/eval.js +0 -40
  191. package/dist/cli/handlers/maintenance.js +0 -107
  192. package/dist/cli/handlers/multi-agent.js +0 -165
  193. package/dist/cli/handlers/node.js +0 -41
  194. package/dist/cli/handlers/operational.js +0 -155
  195. package/dist/cli/handlers/operator.js +0 -146
  196. package/dist/cli/handlers/registry.js +0 -68
  197. package/dist/cli/handlers/run.js +0 -153
  198. package/dist/cli/handlers/scheduling.js +0 -132
  199. package/dist/cli/handlers/workbench.js +0 -41
  200. package/dist/cli/handlers/worker.js +0 -45
  201. package/dist/cli/run-summary.js +0 -45
  202. package/dist/clones.js +0 -162
  203. package/dist/collaboration.js +0 -726
  204. package/dist/commit.js +0 -592
  205. package/dist/compare.js +0 -18
  206. package/dist/coordinator/classify.js +0 -45
  207. package/dist/coordinator/paths.js +0 -42
  208. package/dist/coordinator/util.js +0 -126
  209. package/dist/coordinator.js +0 -990
  210. package/dist/daemon.js +0 -44
  211. package/dist/dispatch.js +0 -250
  212. package/dist/drive.js +0 -827
  213. package/dist/error-feedback.js +0 -419
  214. package/dist/evidence-grounding.js +0 -184
  215. package/dist/execution-backend/agent.js +0 -294
  216. package/dist/execution-backend/probes.js +0 -112
  217. package/dist/execution-backend/util.js +0 -47
  218. package/dist/execution-backend.js +0 -961
  219. package/dist/gates.js +0 -48
  220. package/dist/harness.js +0 -61
  221. package/dist/loop-expansion.js +0 -60
  222. package/dist/mcp/tool-call.js +0 -434
  223. package/dist/mcp/tool-definitions.js +0 -1040
  224. package/dist/mcp-surface.js +0 -30
  225. package/dist/multi-agent/graph.js +0 -84
  226. package/dist/multi-agent/helpers.js +0 -141
  227. package/dist/multi-agent/ids.js +0 -20
  228. package/dist/multi-agent/paths.js +0 -22
  229. package/dist/multi-agent-eval/normalize.js +0 -51
  230. package/dist/multi-agent-eval.js +0 -678
  231. package/dist/multi-agent-host.js +0 -777
  232. package/dist/multi-agent.js +0 -984
  233. package/dist/node-projection.js +0 -59
  234. package/dist/node-snapshot.js +0 -260
  235. package/dist/operator-ux.js +0 -631
  236. package/dist/orchestrator/app-operations.js +0 -211
  237. package/dist/orchestrator/audit-operations.js +0 -182
  238. package/dist/orchestrator/candidate-operations.js +0 -117
  239. package/dist/orchestrator/cli-options.js +0 -294
  240. package/dist/orchestrator/collaboration-operations.js +0 -86
  241. package/dist/orchestrator/feedback-operations.js +0 -81
  242. package/dist/orchestrator/host-operations.js +0 -78
  243. package/dist/orchestrator/lifecycle-operations.js +0 -626
  244. package/dist/orchestrator/migration-operations.js +0 -44
  245. package/dist/orchestrator/multi-agent-operations.js +0 -362
  246. package/dist/orchestrator/topology-operations.js +0 -84
  247. package/dist/orchestrator.js +0 -917
  248. package/dist/pipeline-runner.js +0 -285
  249. package/dist/reclamation/hash.js +0 -72
  250. package/dist/reclamation.js +0 -812
  251. package/dist/reporter.js +0 -67
  252. package/dist/run-export.js +0 -784
  253. package/dist/run-registry/derive.js +0 -175
  254. package/dist/run-registry/format.js +0 -124
  255. package/dist/run-registry/gc.js +0 -251
  256. package/dist/run-registry/policy.js +0 -16
  257. package/dist/run-registry/queue.js +0 -115
  258. package/dist/run-registry.js +0 -850
  259. package/dist/run-state-schema.js +0 -68
  260. package/dist/scheduling.js +0 -184
  261. package/dist/state-explosion.js +0 -1014
  262. package/dist/state.js +0 -367
  263. package/dist/telemetry-ledger.js +0 -196
  264. package/dist/topology.js +0 -565
  265. package/dist/triggers.js +0 -184
  266. package/dist/trust-audit.js +0 -644
  267. package/dist/types/blackboard.js +0 -2
  268. package/dist/types/candidate.js +0 -2
  269. package/dist/types/collaboration.js +0 -2
  270. package/dist/types/core.js +0 -2
  271. package/dist/types/drive.js +0 -10
  272. package/dist/types/error-feedback.js +0 -2
  273. package/dist/types/evidence-reasoning.js +0 -2
  274. package/dist/types/execution-backend.js +0 -2
  275. package/dist/types/multi-agent.js +0 -2
  276. package/dist/types/observability.js +0 -2
  277. package/dist/types/pipeline.js +0 -2
  278. package/dist/types/reclamation.js +0 -8
  279. package/dist/types/report-bundle.js +0 -6
  280. package/dist/types/result.js +0 -2
  281. package/dist/types/run-registry.js +0 -2
  282. package/dist/types/run.js +0 -2
  283. package/dist/types/sandbox.js +0 -2
  284. package/dist/types/schedule.js +0 -2
  285. package/dist/types/state-node.js +0 -2
  286. package/dist/types/topology.js +0 -2
  287. package/dist/types/trust.js +0 -2
  288. package/dist/types/workbench.js +0 -2
  289. package/dist/types/worker.js +0 -2
  290. package/dist/types/workflow-app.js +0 -2
  291. package/dist/types.js +0 -44
  292. package/dist/util/fingerprint.js +0 -19
  293. package/dist/util/fingerprint.test.js +0 -27
  294. package/dist/verifier.js +0 -78
  295. package/dist/version.js +0 -8
  296. package/dist/workbench-host.js +0 -182
  297. package/dist/workbench.js +0 -192
  298. package/dist/worker-accept/acceptance.js +0 -114
  299. package/dist/worker-accept/blackboard-fanout.js +0 -80
  300. package/dist/worker-accept/blackboard-linkage.js +0 -19
  301. package/dist/worker-accept/context.js +0 -2
  302. package/dist/worker-accept/telemetry-ledger.js +0 -126
  303. package/dist/worker-accept/validation.js +0 -77
  304. package/dist/worker-accept/verifier-completion.js +0 -73
  305. package/dist/worker-isolation/helpers.js +0 -51
  306. package/dist/worker-isolation/paths.js +0 -46
  307. package/dist/worker-isolation.js +0 -656
  308. package/dist/workflow-api.js +0 -131
  309. /package/dist/{types → core/types}/boundary.js +0 -0
@@ -0,0 +1,476 @@
1
+ "use strict";
2
+ // shell/coordinator-io.ts — the impure wrapper wiring core/multi-agent/
3
+ // coordinator.ts's pure record builders to real disk and the trust-audit
4
+ // chain.
5
+ //
6
+ // MILESTONE 9. Byte-exact port of the impure half of the old build's
7
+ // src/coordinator.ts: directory creation, index.json + messages.jsonl +
8
+ // per-record writes, and every create call's audit-event recording +
9
+ // state-node append + policy checks.
10
+ //
11
+ // Evidence: SPEC/multi-agent.md section C, "Files on disk";
12
+ // plugins/cool-workflow/src/coordinator.ts (byte-exact source for the
13
+ // wiring sequence).
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.ensureBlackboardState = ensureBlackboardState;
49
+ exports.persistBlackboardState = persistBlackboardState;
50
+ exports.resolveBlackboard = resolveBlackboard;
51
+ exports.createBlackboardTopic = createBlackboardTopic;
52
+ exports.postBlackboardMessage = postBlackboardMessage;
53
+ exports.putBlackboardContext = putBlackboardContext;
54
+ exports.addBlackboardArtifact = addBlackboardArtifact;
55
+ exports.createBlackboardSnapshot = createBlackboardSnapshot;
56
+ exports.recordCoordinatorDecision = recordCoordinatorDecision;
57
+ exports.summarizeBlackboard = summarizeBlackboard;
58
+ exports.listBlackboardMessages = listBlackboardMessages;
59
+ exports.listBlackboardArtifacts = listBlackboardArtifacts;
60
+ exports.buildBlackboardGraph = buildBlackboardGraph;
61
+ const fs = __importStar(require("node:fs"));
62
+ const path = __importStar(require("node:path"));
63
+ const crypto = __importStar(require("node:crypto"));
64
+ const fs_atomic_1 = require("./fs-atomic");
65
+ const node_store_1 = require("./node-store");
66
+ const state_node_1 = require("../core/state/state-node");
67
+ const contract_1 = require("../core/pipeline/contract");
68
+ const trust_audit_1 = require("./trust-audit");
69
+ const cb = __importStar(require("../core/multi-agent/coordinator"));
70
+ const runtime_1 = require("../core/multi-agent/runtime");
71
+ const trust_policy_io_1 = require("./trust-policy-io");
72
+ function blackboardRoot(run) {
73
+ return run.paths.blackboardDir || path.join(run.paths.runDir, "blackboard");
74
+ }
75
+ function messagesPath(run) {
76
+ return path.join(blackboardRoot(run), "messages.jsonl");
77
+ }
78
+ function recordPath(run, kind, id) {
79
+ const safe = id.replace(/[^a-zA-Z0-9_.:-]+/g, "_");
80
+ return path.join(blackboardRoot(run), kind, `${safe}.json`);
81
+ }
82
+ function boardPaths(run) {
83
+ const root = blackboardRoot(run);
84
+ return { root, index: path.join(root, "index.json"), messages: messagesPath(run), topicsDir: path.join(root, "topics"), contextsDir: path.join(root, "contexts"), artifactsDir: path.join(root, "artifacts"), snapshotsDir: path.join(root, "snapshots"), decisionsDir: path.join(root, "decisions") };
85
+ }
86
+ function now() {
87
+ return new Date().toISOString();
88
+ }
89
+ function ensureBlackboardState(run) {
90
+ run.paths.blackboardDir = blackboardRoot(run);
91
+ fs.mkdirSync(run.paths.blackboardDir, { recursive: true });
92
+ for (const dir of ["topics", "contexts", "artifacts", "snapshots", "decisions"])
93
+ fs.mkdirSync(path.join(run.paths.blackboardDir, dir), { recursive: true });
94
+ const existing = run.blackboard;
95
+ const state = existing || cb.emptyBlackboardState();
96
+ state.schemaVersion = cb.BLACKBOARD_SCHEMA_VERSION;
97
+ state.boards = state.boards || [];
98
+ state.topics = state.topics || [];
99
+ state.messages = state.messages || [];
100
+ state.contexts = state.contexts || [];
101
+ state.artifacts = state.artifacts || [];
102
+ state.snapshots = state.snapshots || [];
103
+ state.decisions = state.decisions || [];
104
+ run.blackboard = state;
105
+ return state;
106
+ }
107
+ function requireBoard(run, id) {
108
+ const board = ensureBlackboardState(run).boards.find((entry) => entry.id === id);
109
+ if (!board)
110
+ throw new Error(`Unknown Blackboard id: ${id}`);
111
+ return board;
112
+ }
113
+ function requireTopic(run, id) {
114
+ const topic = ensureBlackboardState(run).topics.find((entry) => entry.id === id);
115
+ if (!topic)
116
+ throw new Error(`Unknown BlackboardTopic id: ${id}`);
117
+ return topic;
118
+ }
119
+ function requireContext(run, id) {
120
+ const context = ensureBlackboardState(run).contexts.find((entry) => entry.id === id);
121
+ if (!context)
122
+ throw new Error(`Unknown BlackboardContext id: ${id}`);
123
+ return context;
124
+ }
125
+ function requireArtifactRefs(run, ids) {
126
+ const state = ensureBlackboardState(run);
127
+ for (const id of ids)
128
+ if (!state.artifacts.some((artifact) => artifact.id === id))
129
+ throw new Error(`Unknown BlackboardArtifactRef id: ${id}`);
130
+ return cb.unique(ids);
131
+ }
132
+ function requireMessages(run, ids) {
133
+ const state = ensureBlackboardState(run);
134
+ for (const id of ids)
135
+ if (!state.messages.some((message) => message.id === id))
136
+ throw new Error(`Unknown BlackboardMessage id: ${id}`);
137
+ return cb.unique(ids);
138
+ }
139
+ function checksumFile(file) {
140
+ return `sha256:${crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex")}`;
141
+ }
142
+ function linkMultiAgent(run, blackboardId, topicIds, input) {
143
+ const groupId = input.agentGroupId ?? input.groupId;
144
+ const roleId = input.agentRoleId ?? input.roleId;
145
+ const membershipId = input.agentMembershipId ?? input.membershipId;
146
+ if (input.multiAgentRunId) {
147
+ const record = (0, runtime_1.getMultiAgentRun)(run, input.multiAgentRunId);
148
+ if (record) {
149
+ record.blackboardId = blackboardId;
150
+ record.topicIds = cb.unique([...(record.topicIds || []), ...topicIds]);
151
+ record.links.blackboardId = blackboardId;
152
+ record.links.blackboardTopicIds = cb.unique([...(record.links.blackboardTopicIds || []), ...topicIds]);
153
+ }
154
+ }
155
+ if (groupId) {
156
+ const record = (0, runtime_1.getAgentGroup)(run, groupId);
157
+ if (record) {
158
+ record.blackboardId = blackboardId;
159
+ record.topicIds = cb.unique([...(record.topicIds || []), ...topicIds]);
160
+ }
161
+ }
162
+ if (roleId) {
163
+ const record = (0, runtime_1.getAgentRole)(run, roleId);
164
+ if (record) {
165
+ record.blackboardId = blackboardId;
166
+ record.topicIds = cb.unique([...(record.topicIds || []), ...topicIds]);
167
+ }
168
+ }
169
+ if (membershipId) {
170
+ const record = (0, runtime_1.getAgentMembership)(run, membershipId);
171
+ if (record) {
172
+ record.blackboardId = blackboardId;
173
+ record.topicIds = cb.unique([...(record.topicIds || []), ...topicIds]);
174
+ }
175
+ }
176
+ }
177
+ function appendBlackboardNode(run, kind, id, status, label, artifactPath, parents = []) {
178
+ const nodeId = kind === "blackboard" ? `${run.id}:blackboard:${id}` : kind === "coordinator-decision" ? `${run.id}:coordinator:decision:${id}` : `${run.id}:blackboard:${kind.replace("blackboard-", "")}:${id}`;
179
+ (0, node_store_1.appendRunNode)(run, (0, state_node_1.createStateNode)({ id: nodeId, kind, status, loopStage: run.loopStage, outputs: { id, label }, artifacts: [{ id: kind, kind: "json", path: artifactPath }], parents, contractId: contract_1.DEFAULT_PIPELINE_CONTRACT_ID, metadata: { id, label } }));
180
+ }
181
+ function persistBlackboardState(run) {
182
+ const state = ensureBlackboardState(run);
183
+ const root = blackboardRoot(run);
184
+ cb.assertNoRecordPathCollisions("BlackboardTopic", state.topics);
185
+ cb.assertNoRecordPathCollisions("BlackboardContext", state.contexts);
186
+ cb.assertNoRecordPathCollisions("BlackboardArtifactRef", state.artifacts);
187
+ cb.assertNoRecordPathCollisions("BlackboardSnapshot", state.snapshots);
188
+ cb.assertNoRecordPathCollisions("CoordinatorDecision", state.decisions);
189
+ (0, fs_atomic_1.writeJson)(path.join(root, "index.json"), {
190
+ schemaVersion: cb.BLACKBOARD_SCHEMA_VERSION,
191
+ runId: run.id,
192
+ generatedAt: now(),
193
+ counts: { boards: state.boards.length, topics: state.topics.length, messages: state.messages.length, contexts: state.contexts.length, artifacts: state.artifacts.length, snapshots: state.snapshots.length, decisions: state.decisions.length },
194
+ boards: state.boards.map(cb.indexRow),
195
+ topics: state.topics.map(cb.indexRow),
196
+ contexts: state.contexts.map(cb.indexRow),
197
+ artifacts: state.artifacts.map(cb.indexRow),
198
+ snapshots: state.snapshots.map(cb.indexRow),
199
+ decisions: state.decisions.map(cb.indexRow),
200
+ messages: state.messages.map((message) => ({ id: message.id, blackboardId: message.blackboardId, topicId: message.topicId, createdAt: message.createdAt, status: message.status, author: message.author, evidenceRefs: message.linkedEvidenceRefs, artifactRefIds: message.linkedArtifactRefIds })),
201
+ });
202
+ fs.writeFileSync(messagesPath(run), state.messages.sort(cb.compareRecords).map((message) => JSON.stringify(message)).join("\n") + (state.messages.length ? "\n" : ""), "utf8");
203
+ for (const topic of state.topics)
204
+ (0, fs_atomic_1.writeJson)(recordPath(run, "topics", topic.id), topic);
205
+ for (const context of state.contexts)
206
+ (0, fs_atomic_1.writeJson)(recordPath(run, "contexts", context.id), context);
207
+ for (const artifact of state.artifacts)
208
+ (0, fs_atomic_1.writeJson)(recordPath(run, "artifacts", artifact.id), artifact);
209
+ for (const snapshot of state.snapshots)
210
+ (0, fs_atomic_1.writeJson)(recordPath(run, "snapshots", snapshot.id), snapshot);
211
+ for (const decision of state.decisions)
212
+ (0, fs_atomic_1.writeJson)(recordPath(run, "decisions", decision.id), decision);
213
+ }
214
+ function resolveBlackboard(run, input = {}) {
215
+ const state = ensureBlackboardState(run);
216
+ const existing = input.id ? state.boards.find((board) => board.id === input.id) : input.multiAgentRunId ? state.boards.find((board) => board.links.multiAgentRunId === input.multiAgentRunId) : state.boards[0];
217
+ if (existing) {
218
+ linkMultiAgent(run, existing.id, existing.topicIds, input);
219
+ cb.touch(existing, now());
220
+ persistBlackboardState(run);
221
+ return existing;
222
+ }
223
+ const id = input.id || cb.createId("bb", state.boards.length + 1);
224
+ cb.assertUnique(state.boards, id, "Blackboard");
225
+ const board = cb.buildBlackboard(run.id, input, id, now(), boardPaths(run));
226
+ linkMultiAgent(run, board.id, [], input);
227
+ state.boards.push(board);
228
+ appendBlackboardNode(run, "blackboard", board.id, "running", board.title, board.paths.index);
229
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "blackboard.create", decision: "recorded", source: "runtime-derived", actor: board.author.id, multiAgentRunId: input.multiAgentRunId, agentGroupId: input.groupId, agentRoleId: input.roleId, agentMembershipId: input.membershipId, blackboardId: board.id, metadata: { scope: board.scope, tags: board.tags } });
230
+ board.links.auditEventIds = [audit.id];
231
+ persistBlackboardState(run);
232
+ return board;
233
+ }
234
+ function createBlackboardTopic(run, input) {
235
+ const board = resolveBlackboard(run, { id: input.blackboardId });
236
+ const state = ensureBlackboardState(run);
237
+ const id = input.id || cb.createId("topic", state.topics.length + 1);
238
+ cb.assertUnique(state.topics, id, "BlackboardTopic");
239
+ const topic = cb.buildTopic(run.id, board, input, id, now());
240
+ state.topics.push(topic);
241
+ board.topicIds = cb.unique([...board.topicIds, topic.id]);
242
+ cb.touch(board, now());
243
+ linkMultiAgent(run, board.id, [topic.id], board.links);
244
+ appendBlackboardNode(run, "blackboard-topic", topic.id, "running", topic.title, recordPath(run, "topics", topic.id), [`${run.id}:blackboard:${board.id}`]);
245
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "blackboard.topic", decision: "recorded", source: "operator-recorded", actor: topic.author.id, blackboardId: board.id, blackboardTopicId: topic.id, multiAgentRunId: topic.links.multiAgentRunId, agentGroupId: topic.links.agentGroupId, agentRoleId: topic.links.agentRoleId, agentMembershipId: topic.links.agentMembershipId, metadata: { title: topic.title, tags: topic.tags } });
246
+ topic.links.auditEventIds = cb.unique([...(topic.links.auditEventIds || []), audit.id]);
247
+ (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, { operation: "topic", status: topic.status, actor: topic.author, blackboardId: board.id, blackboardTopicId: topic.id, multiAgentRunId: topic.links.multiAgentRunId, agentGroupId: topic.links.agentGroupId, agentRoleId: topic.links.agentRoleId, agentMembershipId: topic.links.agentMembershipId, parentEventIds: [audit.id], metadata: { title: topic.title } });
248
+ persistBlackboardState(run);
249
+ return topic;
250
+ }
251
+ function postBlackboardMessage(run, input) {
252
+ const state = ensureBlackboardState(run);
253
+ const topic = requireTopic(run, input.topicId);
254
+ const board = requireBoard(run, input.blackboardId || topic.blackboardId);
255
+ if (input.replyToId && !state.messages.some((message) => message.id === input.replyToId))
256
+ throw new Error(`Unknown parent BlackboardMessage id: ${input.replyToId}`);
257
+ if (!input.body.trim())
258
+ throw new Error("Blackboard message body is required");
259
+ const id = input.id || cb.createId("msg", state.messages.length + 1);
260
+ cb.assertUnique(state.messages, id, "BlackboardMessage");
261
+ const author = cb.normalizeAuthor(input.author, "operator");
262
+ const links = cb.compactLinks(run.id, { ...topic.links, ...cb.roleLinkFromAuthor(author), ...(input.links || {}), evidenceRefs: input.evidenceRefs, auditEventIds: input.auditEventIds });
263
+ const enforcePolicy = cb.shouldEnforcePolicy(author, links);
264
+ const permission = enforcePolicy
265
+ ? (0, trust_policy_io_1.assertMultiAgentActionAllowed)(run, { operation: "message", actor: author, multiAgentRunId: links.multiAgentRunId, agentRoleId: links.agentRoleId, agentGroupId: links.agentGroupId, agentMembershipId: links.agentMembershipId, agentFanoutId: links.agentFanoutId, agentFaninId: links.agentFaninId, blackboardId: board.id, blackboardTopicId: topic.id, blackboardMessageId: id, evidenceRefs: input.evidenceRefs || [] })
266
+ : undefined;
267
+ requireArtifactRefs(run, input.artifactRefIds || []);
268
+ const message = cb.buildMessage(run.id, board, topic, input, id, now(), trust_policy_io_1.hashText, sourceForActorLocal);
269
+ state.messages.push(message);
270
+ topic.messageIds = cb.unique([...topic.messageIds, message.id]);
271
+ board.messageCount = state.messages.filter((entry) => entry.blackboardId === board.id).length;
272
+ cb.touch(topic, now());
273
+ cb.touch(board, now());
274
+ appendBlackboardNode(run, "blackboard-message", message.id, "completed", cb.truncate(message.body), messagesPath(run), [`${run.id}:blackboard:topic:${topic.id}`]);
275
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, {
276
+ kind: "blackboard.message",
277
+ decision: "recorded",
278
+ source: cb.sourceForAuthor(message.author),
279
+ actor: message.author.id,
280
+ blackboardId: board.id,
281
+ blackboardTopicId: topic.id,
282
+ blackboardMessageId: message.id,
283
+ workerId: message.links.workerId || (message.author.kind === "worker" ? message.author.id : undefined),
284
+ taskId: message.links.taskId,
285
+ multiAgentRunId: message.links.multiAgentRunId,
286
+ agentGroupId: message.links.agentGroupId,
287
+ agentRoleId: message.links.agentRoleId,
288
+ agentMembershipId: message.links.agentMembershipId,
289
+ evidenceRefs: message.linkedEvidenceRefs,
290
+ parentEventIds: message.linkedAuditEventIds,
291
+ metadata: { visibility: message.visibility },
292
+ });
293
+ const writeAudit = (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, {
294
+ operation: "message",
295
+ status: message.status,
296
+ actor: message.author,
297
+ multiAgentRunId: message.links.multiAgentRunId,
298
+ agentGroupId: message.links.agentGroupId,
299
+ agentRoleId: message.links.agentRoleId,
300
+ agentMembershipId: message.links.agentMembershipId,
301
+ agentFanoutId: message.links.agentFanoutId,
302
+ agentFaninId: message.links.agentFaninId,
303
+ blackboardId: board.id,
304
+ blackboardTopicId: topic.id,
305
+ blackboardMessageId: message.id,
306
+ evidenceRefs: message.linkedEvidenceRefs,
307
+ parentEventIds: cb.unique([...(permission ? [permission.event.id] : []), audit.id]),
308
+ policyRef: permission?.policyRef,
309
+ metadata: { visibility: message.visibility },
310
+ });
311
+ const provenanceAudit = (0, trust_policy_io_1.recordMessageProvenanceAudit)(run, {
312
+ messageId: message.id,
313
+ topicId: topic.id,
314
+ blackboardId: board.id,
315
+ actor: message.author,
316
+ body: message.body,
317
+ multiAgentRunId: message.links.multiAgentRunId,
318
+ agentRoleId: message.links.agentRoleId,
319
+ agentGroupId: message.links.agentGroupId,
320
+ agentMembershipId: message.links.agentMembershipId,
321
+ workerId: message.links.workerId,
322
+ evidenceRefs: message.linkedEvidenceRefs,
323
+ parentMessageIds: message.parentIds,
324
+ parentEventIds: [audit.id, writeAudit.id],
325
+ policyRef: permission?.policyRef,
326
+ });
327
+ if (message.metadata?.judgeRationale || message.tags.includes("judge-rationale")) {
328
+ const rationaleAudit = (0, trust_policy_io_1.recordJudgeRationaleAudit)(run, { kind: "judge.rationale", actor: message.author, multiAgentRunId: message.links.multiAgentRunId, agentRoleId: message.links.agentRoleId, agentGroupId: message.links.agentGroupId, agentMembershipId: message.links.agentMembershipId, blackboardId: board.id, blackboardTopicId: topic.id, blackboardMessageId: message.id, evidenceRefs: message.linkedEvidenceRefs, rationale: message.body, policyRef: permission?.policyRef, parentEventIds: [audit.id, writeAudit.id, provenanceAudit.id] });
329
+ message.linkedAuditEventIds = cb.unique([...message.linkedAuditEventIds, rationaleAudit.id]);
330
+ }
331
+ message.linkedAuditEventIds = cb.unique([...message.linkedAuditEventIds, audit.id, writeAudit.id, provenanceAudit.id]);
332
+ message.links.auditEventIds = cb.unique([...(message.links.auditEventIds || []), audit.id, writeAudit.id, provenanceAudit.id]);
333
+ if (message.provenance)
334
+ message.provenance.linkedAuditEventIds = cb.unique([...message.provenance.linkedAuditEventIds, audit.id, writeAudit.id, provenanceAudit.id]);
335
+ persistBlackboardState(run);
336
+ return message;
337
+ }
338
+ function sourceForActorLocal(author) {
339
+ return cb.sourceForAuthor(author);
340
+ }
341
+ function putBlackboardContext(run, input) {
342
+ const state = ensureBlackboardState(run);
343
+ const topic = requireTopic(run, input.topicId);
344
+ const board = requireBoard(run, input.blackboardId || topic.blackboardId);
345
+ const id = input.id || cb.createId("ctx", state.contexts.length + 1);
346
+ cb.assertUnique(state.contexts, id, "BlackboardContext");
347
+ const author = cb.normalizeAuthor(input.author, "operator");
348
+ const links = cb.compactLinks(run.id, { ...topic.links, ...cb.roleLinkFromAuthor(author), ...(input.links || {}), evidenceRefs: input.evidenceRefs });
349
+ const permission = cb.shouldEnforcePolicy(author, links) ? (0, trust_policy_io_1.assertMultiAgentActionAllowed)(run, { operation: "context", actor: author, multiAgentRunId: links.multiAgentRunId, agentRoleId: links.agentRoleId, agentGroupId: links.agentGroupId, agentMembershipId: links.agentMembershipId, blackboardId: board.id, blackboardTopicId: topic.id, blackboardContextId: id, evidenceRefs: input.evidenceRefs || [] }) : undefined;
350
+ requireArtifactRefs(run, input.artifactRefIds || []);
351
+ for (const supersededId of input.supersedesContextIds || []) {
352
+ const superseded = requireContext(run, supersededId);
353
+ superseded.status = "superseded";
354
+ superseded.supersededByContextId = id;
355
+ cb.touch(superseded, now());
356
+ }
357
+ const { context, conflicts } = cb.buildContext(run.id, board, topic, input, id, now(), state.contexts);
358
+ for (const conflict of conflicts) {
359
+ conflict.status = "conflicting";
360
+ conflict.conflictingContextIds = cb.unique([...conflict.conflictingContextIds, context.id]);
361
+ cb.touch(conflict, now());
362
+ }
363
+ state.contexts.push(context);
364
+ topic.contextIds = cb.unique([...topic.contextIds, context.id]);
365
+ board.contextIds = cb.unique([...board.contextIds, context.id]);
366
+ cb.touch(topic, now());
367
+ cb.touch(board, now());
368
+ const decision = recordCoordinatorDecision(run, {
369
+ blackboardId: board.id,
370
+ topicId: topic.id,
371
+ kind: conflicts.length ? "conflict-resolution" : "context-update",
372
+ outcome: conflicts.length ? "conflicting" : "accepted",
373
+ reason: conflicts.length ? `Context ${context.id} conflicts with ${conflicts.map((entry) => entry.id).join(", ")}` : `Accepted ${input.kind} context ${context.id}`,
374
+ subjectIds: [context.id, ...conflicts.map((entry) => entry.id)],
375
+ evidenceRefs: context.evidenceRefs,
376
+ artifactRefIds: context.artifactRefIds,
377
+ author: { kind: "coordinator", id: "cw" },
378
+ scope: context.scope,
379
+ parentIds: context.parentIds,
380
+ tags: ["context", input.kind],
381
+ });
382
+ context.decisionId = decision.id;
383
+ appendBlackboardNode(run, "blackboard-context", context.id, cb.coordinatorStatusToNodeStatus(context.status), `${context.kind}:${context.key}`, recordPath(run, "contexts", context.id), [`${run.id}:blackboard:topic:${topic.id}`]);
384
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "blackboard.context", decision: conflicts.length ? "failed" : "accepted", source: cb.sourceForAuthor(context.author), actor: context.author.id, blackboardId: board.id, blackboardTopicId: topic.id, blackboardContextId: context.id, coordinatorDecisionId: decision.id, evidenceRefs: context.evidenceRefs, multiAgentRunId: context.links.multiAgentRunId, agentGroupId: context.links.agentGroupId, agentRoleId: context.links.agentRoleId, agentMembershipId: context.links.agentMembershipId, metadata: { kind: context.kind, key: context.key, conflicts: context.conflictingContextIds } });
385
+ const writeAudit = (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, { operation: "context", status: context.status, actor: context.author, multiAgentRunId: context.links.multiAgentRunId, agentGroupId: context.links.agentGroupId, agentRoleId: context.links.agentRoleId, agentMembershipId: context.links.agentMembershipId, blackboardId: board.id, blackboardTopicId: topic.id, blackboardContextId: context.id, coordinatorDecisionId: decision.id, evidenceRefs: context.evidenceRefs, parentEventIds: cb.unique([...(permission ? [permission.event.id] : []), audit.id]), policyRef: permission?.policyRef, metadata: { kind: context.kind, key: context.key, conflicts: context.conflictingContextIds } });
386
+ context.links.auditEventIds = cb.unique([...(context.links.auditEventIds || []), audit.id]);
387
+ context.links.auditEventIds = cb.unique([...(context.links.auditEventIds || []), writeAudit.id]);
388
+ persistBlackboardState(run);
389
+ return context;
390
+ }
391
+ function addBlackboardArtifact(run, input) {
392
+ if (!input.path && !input.locator)
393
+ throw new Error("Blackboard artifact requires --path or --locator");
394
+ const state = ensureBlackboardState(run);
395
+ const board = resolveBlackboard(run, { id: input.blackboardId });
396
+ const topic = input.topicId ? requireTopic(run, input.topicId) : undefined;
397
+ if (topic && topic.blackboardId !== board.id)
398
+ throw new Error(`Topic ${topic.id} does not belong to blackboard ${board.id}`);
399
+ const id = input.id || cb.createId("artifact", state.artifacts.length + 1);
400
+ cb.assertUnique(state.artifacts, id, "BlackboardArtifactRef");
401
+ const author = cb.normalizeAuthor(input.author, "operator");
402
+ const links = cb.compactLinks(run.id, { ...board.links, ...(topic?.links || {}), ...cb.roleLinkFromAuthor(author), ...(input.links || {}), evidenceRefs: input.evidenceRefs, auditEventIds: input.auditEventIds });
403
+ const permission = cb.shouldEnforcePolicy(author, links) ? (0, trust_policy_io_1.assertMultiAgentActionAllowed)(run, { operation: "artifact", actor: author, multiAgentRunId: links.multiAgentRunId, agentRoleId: links.agentRoleId, agentGroupId: links.agentGroupId, agentMembershipId: links.agentMembershipId, blackboardId: board.id, blackboardTopicId: topic?.id, blackboardArtifactRefId: id, evidenceRefs: input.evidenceRefs || [] }) : undefined;
404
+ const absolutePath = input.path ? path.resolve(input.path) : undefined;
405
+ const checksum = absolutePath && fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile() ? checksumFile(absolutePath) : undefined;
406
+ const artifact = cb.buildArtifact(run.id, board, topic, input, id, now(), absolutePath, checksum);
407
+ state.artifacts.push(artifact);
408
+ board.artifactRefIds = cb.unique([...board.artifactRefIds, artifact.id]);
409
+ if (topic)
410
+ topic.artifactRefIds = cb.unique([...topic.artifactRefIds, artifact.id]);
411
+ cb.touch(board, now());
412
+ if (topic)
413
+ cb.touch(topic, now());
414
+ const decision = recordCoordinatorDecision(run, { blackboardId: board.id, topicId: topic?.id, kind: "artifact-index", outcome: "accepted", reason: `Indexed ${artifact.kind} artifact ${artifact.id}`, subjectIds: [artifact.id], evidenceRefs: artifact.evidenceRefs, artifactRefIds: [artifact.id], author: { kind: "coordinator", id: "cw" }, scope: artifact.scope, tags: ["artifact", artifact.kind] });
415
+ appendBlackboardNode(run, "blackboard-artifact", artifact.id, "completed", artifact.kind, recordPath(run, "artifacts", artifact.id), [topic ? `${run.id}:blackboard:topic:${topic.id}` : `${run.id}:blackboard:${board.id}`]);
416
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "blackboard.artifact", decision: "accepted", source: cb.sourceForAuthor(artifact.author), actor: artifact.author.id, blackboardId: board.id, blackboardTopicId: topic?.id, blackboardArtifactRefId: artifact.id, coordinatorDecisionId: decision.id, workerId: artifact.provenance.workerId, taskId: artifact.provenance.taskId, candidateId: artifact.provenance.candidateId, commitId: artifact.provenance.commitId, normalizedPath: absolutePath, evidenceRefs: artifact.evidenceRefs, parentEventIds: artifact.trustAuditEventIds, metadata: { kind: artifact.kind, locator: artifact.locator, checksum: artifact.checksum } });
417
+ const writeAudit = (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, { operation: "artifact", status: artifact.status, actor: artifact.author, multiAgentRunId: artifact.provenance.multiAgentRunId, agentGroupId: artifact.provenance.agentGroupId, agentRoleId: artifact.provenance.agentRoleId, agentMembershipId: artifact.provenance.agentMembershipId, blackboardId: board.id, blackboardTopicId: topic?.id, blackboardArtifactRefId: artifact.id, coordinatorDecisionId: decision.id, evidenceRefs: artifact.evidenceRefs, parentEventIds: cb.unique([...(permission ? [permission.event.id] : []), audit.id]), policyRef: permission?.policyRef, metadata: { kind: artifact.kind, locator: artifact.locator, checksum: artifact.checksum } });
418
+ artifact.trustAuditEventIds = cb.unique([...artifact.trustAuditEventIds, audit.id, writeAudit.id]);
419
+ persistBlackboardState(run);
420
+ return artifact;
421
+ }
422
+ function createBlackboardSnapshot(run, blackboardId) {
423
+ const state = ensureBlackboardState(run);
424
+ const board = resolveBlackboard(run, { id: blackboardId });
425
+ const id = cb.createId("snapshot", state.snapshots.length + 1);
426
+ const snapshotPath = recordPath(run, "snapshots", id);
427
+ const summary = summarizeBlackboard(run, board.id);
428
+ const messageIds = state.messages.filter((entry) => entry.blackboardId === board.id).map((entry) => entry.id);
429
+ const snapshot = cb.buildSnapshot(run.id, board, id, now(), snapshotPath, board.paths.index, summary, messageIds);
430
+ state.snapshots.push(snapshot);
431
+ board.snapshotIds = cb.unique([...board.snapshotIds, snapshot.id]);
432
+ cb.touch(board, now());
433
+ appendBlackboardNode(run, "blackboard-snapshot", snapshot.id, "completed", snapshot.id, snapshotPath, [`${run.id}:blackboard:${board.id}`]);
434
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "blackboard.snapshot", decision: "recorded", source: "runtime-derived", actor: "cw", blackboardId: board.id, blackboardSnapshotId: snapshot.id, metadata: { snapshotPath, counts: summary } });
435
+ const writeAudit = (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, { operation: "snapshot", status: snapshot.status, actor: snapshot.author, multiAgentRunId: snapshot.links.multiAgentRunId, agentGroupId: snapshot.links.agentGroupId, agentRoleId: snapshot.links.agentRoleId, agentMembershipId: snapshot.links.agentMembershipId, blackboardId: board.id, blackboardSnapshotId: snapshot.id, parentEventIds: [audit.id], metadata: { snapshotPath } });
436
+ snapshot.links.auditEventIds = [audit.id];
437
+ snapshot.links.auditEventIds = cb.unique([...snapshot.links.auditEventIds, writeAudit.id]);
438
+ persistBlackboardState(run);
439
+ return snapshot;
440
+ }
441
+ function recordCoordinatorDecision(run, input) {
442
+ const state = ensureBlackboardState(run);
443
+ const board = resolveBlackboard(run, { id: input.blackboardId });
444
+ const id = input.id || cb.createId("decision", state.decisions.length + 1);
445
+ cb.assertUnique(state.decisions, id, "CoordinatorDecision");
446
+ requireArtifactRefs(run, input.artifactRefIds || []);
447
+ requireMessages(run, input.messageIds || []);
448
+ const decision = cb.buildDecision(run.id, board, input, id, now());
449
+ state.decisions.push(decision);
450
+ board.decisionIds = cb.unique([...board.decisionIds, decision.id]);
451
+ cb.touch(board, now());
452
+ appendBlackboardNode(run, "coordinator-decision", decision.id, cb.coordinatorStatusToNodeStatus(decision.status), `${decision.kind}:${decision.outcome}`, recordPath(run, "decisions", decision.id), [`${run.id}:blackboard:${board.id}`, ...(input.topicId ? [`${run.id}:blackboard:topic:${input.topicId}`] : [])]);
453
+ const audit = (0, trust_audit_1.recordTrustAuditEvent)(run, { kind: "coordinator.decision", decision: cb.auditDecision(input.outcome), source: "cw-validated", actor: decision.author.id, blackboardId: board.id, blackboardTopicId: input.topicId, coordinatorDecisionId: decision.id, multiAgentRunId: decision.links.multiAgentRunId, agentGroupId: decision.links.agentGroupId, agentRoleId: decision.links.agentRoleId, agentMembershipId: decision.links.agentMembershipId, evidenceRefs: decision.evidenceRefs, metadata: { kind: decision.kind, outcome: decision.outcome, subjectIds: decision.subjectIds, reason: decision.reason } });
454
+ const writeAudit = (0, trust_policy_io_1.recordBlackboardWriteAudit)(run, { operation: "coordinator-decision", status: decision.status, actor: decision.author, multiAgentRunId: decision.links.multiAgentRunId, agentGroupId: decision.links.agentGroupId, agentRoleId: decision.links.agentRoleId, agentMembershipId: decision.links.agentMembershipId, blackboardId: board.id, blackboardTopicId: input.topicId, coordinatorDecisionId: decision.id, evidenceRefs: decision.evidenceRefs, parentEventIds: [audit.id], metadata: { kind: decision.kind, outcome: decision.outcome } });
455
+ if (decision.kind === "candidate-synthesis" || decision.tags.includes("panel-decision")) {
456
+ const panelAudit = (0, trust_policy_io_1.recordJudgeRationaleAudit)(run, { kind: "judge.panel-decision", actor: decision.author, multiAgentRunId: decision.links.multiAgentRunId, agentGroupId: decision.links.agentGroupId, agentRoleId: decision.links.agentRoleId, agentMembershipId: decision.links.agentMembershipId, blackboardId: board.id, blackboardTopicId: input.topicId, coordinatorDecisionId: decision.id, evidenceRefs: decision.evidenceRefs, rationale: decision.reason, parentEventIds: [audit.id, writeAudit.id] });
457
+ decision.links.auditEventIds = cb.unique([...(decision.links.auditEventIds || []), panelAudit.id]);
458
+ }
459
+ decision.links.auditEventIds = cb.unique([...(decision.links.auditEventIds || []), audit.id, writeAudit.id]);
460
+ persistBlackboardState(run);
461
+ return decision;
462
+ }
463
+ function summarizeBlackboard(run, blackboardId) {
464
+ const state = ensureBlackboardState(run);
465
+ return cb.summarizeBlackboard(run.id, state, blackboardId, path.join(blackboardRoot(run), "index.json"));
466
+ }
467
+ function listBlackboardMessages(run, options = {}) {
468
+ return cb.listBlackboardMessages(ensureBlackboardState(run), options);
469
+ }
470
+ function listBlackboardArtifacts(run, options = {}) {
471
+ return cb.listBlackboardArtifacts(ensureBlackboardState(run), options);
472
+ }
473
+ function buildBlackboardGraph(run) {
474
+ const state = ensureBlackboardState(run);
475
+ return cb.buildBlackboardGraph(run.id, state, (kind, id) => recordPath(run, kind, id), messagesPath(run));
476
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // shell/demo-cli.ts — CLI-reachable bodies for `cw demo tamper|bundle`.
3
+ // CLI-only per SPEC/ledger-trust.md ("`demo` is CLI-only").
4
+ //
5
+ // MILESTONE 8. Byte-exact port of the old build's capability-core.ts's
6
+ // `demoTamper`/`demoBundle` (both simply call the hermetic demo
7
+ // runners with no argument-derived behavior).
8
+ //
9
+ // Evidence: SPEC/ledger-trust.md "`cw demo tamper|bundle [--json]`".
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.demoTamperCli = demoTamperCli;
12
+ exports.demoBundleCli = demoBundleCli;
13
+ const telemetry_demo_1 = require("./telemetry-demo");
14
+ function demoTamperCli() {
15
+ return (0, telemetry_demo_1.runTamperDemo)();
16
+ }
17
+ function demoBundleCli() {
18
+ return (0, telemetry_demo_1.runBundleDemo)();
19
+ }