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
package/dist/daemon.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DesktopSchedulerDaemon = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const scheduler_1 = require("./scheduler");
10
- const state_1 = require("./state");
11
- class DesktopSchedulerDaemon {
12
- cwd;
13
- intervalSeconds;
14
- scheduler;
15
- constructor(options = {}) {
16
- this.cwd = node_path_1.default.resolve(String(options.cwd || process.cwd()));
17
- this.intervalSeconds = Number(options.intervalSeconds || 60);
18
- this.scheduler = new scheduler_1.Scheduler(this.cwd);
19
- }
20
- tick() {
21
- const due = this.scheduler.due();
22
- const checkedAt = new Date().toISOString();
23
- const inboxPath = node_path_1.default.join(this.cwd, ".cw", "schedules", "due-inbox.json");
24
- (0, state_1.writeJson)(inboxPath, {
25
- schemaVersion: 1,
26
- checkedAt,
27
- due
28
- });
29
- return {
30
- checkedAt,
31
- dueCount: due.length,
32
- dueIds: due.map((task) => task.id),
33
- inboxPath
34
- };
35
- }
36
- async run() {
37
- node_fs_1.default.mkdirSync(node_path_1.default.join(this.cwd, ".cw", "schedules"), { recursive: true });
38
- process.stdout.write(`${JSON.stringify(this.tick())}\n`);
39
- setInterval(() => {
40
- process.stdout.write(`${JSON.stringify(this.tick())}\n`);
41
- }, Math.max(1, this.intervalSeconds) * 1000);
42
- }
43
- }
44
- exports.DesktopSchedulerDaemon = DesktopSchedulerDaemon;
package/dist/dispatch.js DELETED
@@ -1,250 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.nextDispatchTasks = nextDispatchTasks;
7
- exports.createDispatchManifest = createDispatchManifest;
8
- exports.firstRunnablePhase = firstRunnablePhase;
9
- exports.updatePhaseStatuses = updatePhaseStatuses;
10
- exports.formatDispatchTask = formatDispatchTask;
11
- const node_fs_1 = __importDefault(require("node:fs"));
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const state_1 = require("./state");
14
- const pipeline_contract_1 = require("./pipeline-contract");
15
- const state_node_1 = require("./state-node");
16
- const worker_isolation_1 = require("./worker-isolation");
17
- const sandbox_profile_1 = require("./sandbox-profile");
18
- const execution_backend_1 = require("./execution-backend");
19
- const multi_agent_1 = require("./multi-agent");
20
- function nextDispatchTasks(run, limit) {
21
- const runnablePhase = firstRunnablePhase(run);
22
- if (!runnablePhase)
23
- return [];
24
- const max = Number(limit || run.workflow.limits.maxConcurrentAgents || 4);
25
- const runnableTaskIds = new Set(runnablePhase.taskIds);
26
- return run.tasks
27
- .filter((task) => task.status === "pending" && runnableTaskIds.has(task.id))
28
- .slice(0, max)
29
- .map(formatDispatchTask);
30
- }
31
- function createDispatchManifest(run, limit, options = {}) {
32
- const requestedSandboxProfileId = options.sandboxProfileId || options.sandbox;
33
- const sandboxProfileId = String(requestedSandboxProfileId || sandbox_profile_1.DEFAULT_SANDBOX_PROFILE_ID);
34
- (0, sandbox_profile_1.resolveSandboxProfileById)(sandboxProfileId, (0, sandbox_profile_1.sandboxContextForValidation)(run.cwd));
35
- // H7: if the requested profile is a CUSTOM profile loaded from a FILE (non-bundled,
36
- // existing file), persist its DEFINITION on run.customSandboxProfiles keyed by the
37
- // definition's logical id. This makes the custom profile durable with run state so a
38
- // worker boundary can re-resolve it by logical id after a scope snapshot is lost
39
- // (re-resolving against the worker context, not the dispatch-time file path).
40
- persistCustomSandboxProfile(run, sandboxProfileId);
41
- // Resolve the execution backend once (mechanism vs policy): the kernel records
42
- // WHICH backend was selected; it never branches on which one. Defaults to node
43
- // (behavior-preserving) when no `--backend` flag / CW_BACKEND env is set.
44
- const backendSelection = (0, execution_backend_1.resolveBackendSelection)(options.backendId);
45
- const tasks = nextDispatchTasks(run, limit);
46
- if (!tasks.length) {
47
- return {
48
- schemaVersion: 1,
49
- runId: run.id,
50
- dispatchId: null,
51
- tasks: [],
52
- manifestPath: null,
53
- sandboxProfileId,
54
- backendId: backendSelection.backendId,
55
- backendSelection
56
- };
57
- }
58
- const dispatchId = createDispatchId(run);
59
- const manifestPath = node_path_1.default.join(run.paths.dispatchesDir, `${dispatchId}.json`);
60
- node_fs_1.default.mkdirSync(run.paths.dispatchesDir, { recursive: true });
61
- const taskIds = new Set(tasks.map((task) => task.id));
62
- const createdAt = new Date().toISOString();
63
- const selectedSandboxProfileIds = new Set();
64
- let sandboxPolicy;
65
- for (const task of run.tasks) {
66
- if (taskIds.has(task.id)) {
67
- const taskSandboxProfileId = String(requestedSandboxProfileId || task.sandboxProfileId || sandbox_profile_1.DEFAULT_SANDBOX_PROFILE_ID);
68
- selectedSandboxProfileIds.add(taskSandboxProfileId);
69
- task.status = "running";
70
- task.loopStage = "act";
71
- task.dispatchId = dispatchId;
72
- task.dispatchedAt = createdAt;
73
- const scope = (0, worker_isolation_1.allocateWorkerScope)(run, task, {
74
- dispatchId,
75
- sandboxProfileId: taskSandboxProfileId,
76
- backendSelection,
77
- status: "running",
78
- persist: false,
79
- metadata: { dispatchId, phase: task.phase }
80
- });
81
- sandboxPolicy = sandboxPolicy || scope.sandboxPolicy;
82
- }
83
- }
84
- const selectedRunTasks = run.tasks.filter((task) => taskIds.has(task.id));
85
- const multiAgentAttachment = (0, multi_agent_1.attachDispatchToMultiAgent)(run, {
86
- multiAgentRunId: options.multiAgentRunId,
87
- groupId: options.multiAgentGroupId,
88
- roleId: options.multiAgentRoleId,
89
- fanoutId: options.multiAgentFanoutId,
90
- dispatchId,
91
- tasks: selectedRunTasks,
92
- sandboxProfileId: selectedSandboxProfileIds.size === 1 ? [...selectedSandboxProfileIds][0] : "mixed",
93
- concurrencyLimit: limit
94
- });
95
- for (const task of selectedRunTasks) {
96
- const worker = task.workerId ? (0, worker_isolation_1.syncWorkerScopeFromTask)(run, task.workerId) : undefined;
97
- if (worker)
98
- (0, worker_isolation_1.writeWorkerManifest)(run, worker);
99
- }
100
- const manifest = {
101
- schemaVersion: 1,
102
- runId: run.id,
103
- dispatchId,
104
- createdAt,
105
- phase: tasks[0].phase,
106
- instructions: "Spawn one worker per task when the user explicitly authorized agent/parallel/background work. Save each final summary as Markdown and record it with `cw.js result <run-id> <task-id> <file>`.",
107
- tasks: selectedRunTasks.map(formatDispatchTask),
108
- manifestPath,
109
- workerIndexPath: run.paths.workersDir ? node_path_1.default.join(run.paths.workersDir, "index.json") : undefined,
110
- sandboxProfileId: selectedSandboxProfileIds.size === 1 ? [...selectedSandboxProfileIds][0] : "mixed",
111
- sandboxPolicy: selectedSandboxProfileIds.size === 1 ? sandboxPolicy : undefined,
112
- backendId: backendSelection.backendId,
113
- backendSelection,
114
- backendAttestation: selectedRunTasks.find((task) => task.backendAttestation)?.backendAttestation,
115
- multiAgent: multiAgentAttachment.multiAgent
116
- ? {
117
- ...multiAgentAttachment.multiAgent,
118
- membershipIds: multiAgentAttachment.membershipIds
119
- }
120
- : undefined
121
- };
122
- const dispatchNode = (0, state_node_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
123
- id: `${run.id}:dispatch:${dispatchId}`,
124
- kind: "dispatch",
125
- status: "running",
126
- loopStage: "act",
127
- inputs: { taskIds: tasks.map((task) => task.id), phase: manifest.phase, sandboxProfileId: manifest.sandboxProfileId },
128
- outputs: { dispatchId, sandboxProfileId: manifest.sandboxProfileId },
129
- artifacts: [{ id: "dispatch", kind: "json", path: manifestPath }],
130
- parents: tasks.map((task) => `${run.id}:task:${task.id}`),
131
- contractId: pipeline_contract_1.DEFAULT_PIPELINE_CONTRACT_ID,
132
- metadata: { sandboxProfileId: manifest.sandboxProfileId, sandboxPolicy: manifest.sandboxPolicy }
133
- }));
134
- manifest.stateNodeId = dispatchNode.id;
135
- for (const task of run.tasks) {
136
- if (!taskIds.has(task.id) || !task.stateNodeId)
137
- continue;
138
- const node = run.nodes?.find((candidate) => candidate.id === task.stateNodeId);
139
- if (node && node.status === "pending") {
140
- (0, state_node_1.appendRunNode)(run, (0, state_node_1.transitionStateNode)(node, { status: "running", loopStage: "act" }));
141
- }
142
- }
143
- run.dispatches.push({
144
- id: dispatchId,
145
- phase: manifest.phase || "",
146
- taskIds: tasks.map((task) => task.id),
147
- manifestPath,
148
- createdAt,
149
- stateNodeId: dispatchNode.id,
150
- workerIds: selectedRunTasks.filter((task) => task.workerId).map((task) => String(task.workerId)),
151
- sandboxProfileId: manifest.sandboxProfileId,
152
- backendId: backendSelection.backendId,
153
- multiAgent: manifest.multiAgent
154
- });
155
- updatePhaseStatuses(run);
156
- (0, state_1.writeJson)(manifestPath, manifest);
157
- return manifest;
158
- }
159
- function firstRunnablePhase(run) {
160
- for (const phase of run.phases) {
161
- const phaseTasks = run.tasks.filter((task) => phase.taskIds.includes(task.id));
162
- if (phaseTasks.some((task) => task.status === "running"))
163
- return phase;
164
- if (phaseTasks.some((task) => task.status === "pending"))
165
- return phase;
166
- if (!phaseTasks.every((task) => task.status === "completed"))
167
- return null;
168
- }
169
- return null;
170
- }
171
- function updatePhaseStatuses(run) {
172
- for (const phase of run.phases) {
173
- const phaseTasks = run.tasks.filter((task) => phase.taskIds.includes(task.id));
174
- if (phaseTasks.every((task) => task.status === "completed")) {
175
- phase.status = "completed";
176
- }
177
- else if (phaseTasks.some((task) => task.status === "running" || task.status === "completed")) {
178
- phase.status = "running";
179
- }
180
- else {
181
- phase.status = "pending";
182
- }
183
- }
184
- }
185
- function formatDispatchTask(task) {
186
- return {
187
- id: task.id,
188
- kind: task.kind,
189
- phase: task.phase,
190
- status: task.status,
191
- taskPath: task.taskPath,
192
- prompt: task.prompt,
193
- workerId: task.workerId,
194
- workerManifestPath: task.workerManifestPath,
195
- workerDir: task.workerManifestPath ? node_path_1.default.dirname(task.workerManifestPath) : undefined,
196
- workerResultPath: task.workerId && task.workerManifestPath ? node_path_1.default.join(node_path_1.default.dirname(task.workerManifestPath), "result.md") : undefined,
197
- sandboxProfileId: task.sandboxProfileId,
198
- sandboxPolicy: task.sandboxPolicy,
199
- backendId: task.backendId,
200
- backendAttestation: task.backendAttestation,
201
- multiAgent: task.multiAgent
202
- };
203
- }
204
- // Deterministic dispatch id (replay-determinism self-audit): the wall-clock stamp
205
- // is an edge timestamp for human readability. Set CW_DETERMINISTIC_RUN_IDS=1 to
206
- // use a content-hash-based id without wall-clock, so re-running the same workflow
207
- // yields byte-identical dispatch ids. The suffix is a per-run sequence, so each
208
- // dispatch still gets a distinct, monotonically increasing id.
209
- function createDispatchId(run) {
210
- const stamp = new Date().toISOString().replace(/[-:]/g, "").replace(/\..+/, "Z");
211
- const seq = (run.dispatches?.length || 0) + 1;
212
- if (/^(1|true|yes|on)$/i.test(process.env.CW_DETERMINISTIC_RUN_IDS || "")) {
213
- return `dispatch-${String(seq).padStart(4, "0")}`;
214
- }
215
- return `dispatch-${stamp}-${String(seq).padStart(4, "0")}`;
216
- }
217
- // H7: persist a CUSTOM sandbox profile DEFINITION (loaded from a FILE at dispatch)
218
- // onto run.customSandboxProfiles, keyed by the definition's logical id. Only fires
219
- // for a non-bundled id that resolves to a readable, valid profile file. The
220
- // resolveSandboxProfileById call above has already validated the file (it throws on
221
- // invalid), so this re-parses only to recover the raw DEFINITION — we store the
222
- // definition (not a resolved policy) so worker-specific path tokens re-bind to the
223
- // correct worker context on every later re-resolve. Bundled ids and unknown ids are
224
- // left untouched, so this never shadows a bundled profile or masks a fail-closed.
225
- function persistCustomSandboxProfile(run, requested) {
226
- if (!requested || (0, sandbox_profile_1.isBundledSandboxProfileId)(requested))
227
- return;
228
- const absolute = node_path_1.default.resolve(requested);
229
- if (!node_fs_1.default.existsSync(absolute) || !node_fs_1.default.statSync(absolute).isFile())
230
- return;
231
- const validation = (0, sandbox_profile_1.validateSandboxProfileFile)(requested, (0, sandbox_profile_1.sandboxContextForValidation)(run.cwd));
232
- if (!validation.valid || !validation.profile)
233
- return;
234
- let definition;
235
- try {
236
- definition = JSON.parse(node_fs_1.default.readFileSync(absolute, "utf8"));
237
- }
238
- catch {
239
- return;
240
- }
241
- if (!definition || typeof definition !== "object" || typeof definition.id !== "string" || !definition.id)
242
- return;
243
- run.customSandboxProfiles = run.customSandboxProfiles || {};
244
- const previous = run.customSandboxProfiles[definition.id];
245
- if (previous && JSON.stringify(previous) !== JSON.stringify(definition)) {
246
- throw new Error(`Sandbox profile id collision: "${definition.id}" is already defined by a different custom profile ` +
247
- `(source: ${absolute}). Use a unique id in each custom profile file.`);
248
- }
249
- run.customSandboxProfiles[definition.id] = definition;
250
- }