cool-workflow 0.1.98 → 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 (306) 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} +2 -2
  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 +2 -0
  139. package/docs/cli-mcp-parity.7.md +280 -219
  140. package/docs/contract-migration-tooling.7.md +2 -0
  141. package/docs/control-plane-scheduling.7.md +2 -0
  142. package/docs/durable-state-and-locking.7.md +2 -0
  143. package/docs/evidence-adoption-reasoning-chain.7.md +2 -0
  144. package/docs/execution-backends.7.md +2 -0
  145. package/docs/multi-agent-cli-mcp-surface.7.md +2 -0
  146. package/docs/multi-agent-eval-replay-harness.7.md +2 -0
  147. package/docs/multi-agent-operator-ux.7.md +2 -0
  148. package/docs/node-snapshot-diff-replay.7.md +2 -0
  149. package/docs/observability-cost-accounting.7.md +2 -0
  150. package/docs/project-index.md +132 -71
  151. package/docs/real-execution-backends.7.md +2 -0
  152. package/docs/release-and-migration.7.md +2 -0
  153. package/docs/release-tooling.7.md +2 -0
  154. package/docs/run-registry-control-plane.7.md +2 -0
  155. package/docs/run-retention-reclamation.7.md +23 -0
  156. package/docs/state-explosion-management.7.md +2 -0
  157. package/docs/team-collaboration.7.md +2 -0
  158. package/docs/web-desktop-workbench.7.md +2 -0
  159. package/manifest/plugin.manifest.json +1 -1
  160. package/manifest/source-context-profiles.json +9 -13
  161. package/package.json +1 -1
  162. package/scripts/agents/cw-attest-wrap.js +2 -2
  163. package/scripts/bump-version.js +4 -3
  164. package/scripts/canonical-apps.js +4 -4
  165. package/scripts/dogfood-architecture-review.js +2 -3
  166. package/scripts/dogfood-release.js +3 -3
  167. package/scripts/gen-parity-doc.js +15 -2
  168. package/scripts/golden-path.js +4 -4
  169. package/scripts/onramp-check.js +1 -1
  170. package/scripts/parity-check.js +38 -21
  171. package/scripts/release-flow.js +2 -2
  172. package/scripts/sync-project-index.js +51 -27
  173. package/scripts/validate-run-state-schema.js +2 -2
  174. package/scripts/version-sync-check.js +30 -30
  175. package/dist/candidate-scoring.js +0 -729
  176. package/dist/capability-core.js +0 -1189
  177. package/dist/capability-registry.js +0 -885
  178. package/dist/cli/command-surface.js +0 -494
  179. package/dist/cli/format.js +0 -56
  180. package/dist/cli/handlers/audit.js +0 -82
  181. package/dist/cli/handlers/blackboard.js +0 -81
  182. package/dist/cli/handlers/candidate.js +0 -40
  183. package/dist/cli/handlers/clones.js +0 -34
  184. package/dist/cli/handlers/collaboration.js +0 -61
  185. package/dist/cli/handlers/eval.js +0 -40
  186. package/dist/cli/handlers/ledger.js +0 -169
  187. package/dist/cli/handlers/maintenance.js +0 -107
  188. package/dist/cli/handlers/multi-agent.js +0 -165
  189. package/dist/cli/handlers/node.js +0 -41
  190. package/dist/cli/handlers/operational.js +0 -155
  191. package/dist/cli/handlers/operator.js +0 -146
  192. package/dist/cli/handlers/registry.js +0 -68
  193. package/dist/cli/handlers/run.js +0 -153
  194. package/dist/cli/handlers/scheduling.js +0 -132
  195. package/dist/cli/handlers/workbench.js +0 -41
  196. package/dist/cli/handlers/worker.js +0 -45
  197. package/dist/cli/run-summary.js +0 -45
  198. package/dist/clones.js +0 -162
  199. package/dist/collaboration.js +0 -726
  200. package/dist/commit.js +0 -592
  201. package/dist/compare.js +0 -18
  202. package/dist/coordinator/classify.js +0 -45
  203. package/dist/coordinator/paths.js +0 -42
  204. package/dist/coordinator/util.js +0 -126
  205. package/dist/coordinator.js +0 -990
  206. package/dist/daemon.js +0 -44
  207. package/dist/dispatch.js +0 -250
  208. package/dist/drive.js +0 -864
  209. package/dist/error-feedback.js +0 -419
  210. package/dist/evidence-grounding.js +0 -184
  211. package/dist/execution-backend/agent.js +0 -354
  212. package/dist/execution-backend/probes.js +0 -112
  213. package/dist/execution-backend/util.js +0 -47
  214. package/dist/execution-backend.js +0 -961
  215. package/dist/gates.js +0 -48
  216. package/dist/harness.js +0 -61
  217. package/dist/ledger.js +0 -313
  218. package/dist/loop-expansion.js +0 -60
  219. package/dist/mcp/tool-call.js +0 -470
  220. package/dist/mcp/tool-definitions.js +0 -1066
  221. package/dist/mcp-surface.js +0 -30
  222. package/dist/multi-agent/graph.js +0 -84
  223. package/dist/multi-agent/helpers.js +0 -141
  224. package/dist/multi-agent/ids.js +0 -20
  225. package/dist/multi-agent/paths.js +0 -22
  226. package/dist/multi-agent-eval/normalize.js +0 -51
  227. package/dist/multi-agent-eval.js +0 -678
  228. package/dist/multi-agent-host.js +0 -777
  229. package/dist/multi-agent.js +0 -984
  230. package/dist/node-projection.js +0 -59
  231. package/dist/node-snapshot.js +0 -260
  232. package/dist/operator-ux.js +0 -631
  233. package/dist/orchestrator/app-operations.js +0 -211
  234. package/dist/orchestrator/audit-operations.js +0 -182
  235. package/dist/orchestrator/candidate-operations.js +0 -117
  236. package/dist/orchestrator/cli-options.js +0 -294
  237. package/dist/orchestrator/collaboration-operations.js +0 -86
  238. package/dist/orchestrator/feedback-operations.js +0 -81
  239. package/dist/orchestrator/host-operations.js +0 -78
  240. package/dist/orchestrator/lifecycle-operations.js +0 -650
  241. package/dist/orchestrator/migration-operations.js +0 -44
  242. package/dist/orchestrator/multi-agent-operations.js +0 -362
  243. package/dist/orchestrator/topology-operations.js +0 -84
  244. package/dist/orchestrator.js +0 -925
  245. package/dist/pipeline-runner.js +0 -285
  246. package/dist/reclamation/hash.js +0 -72
  247. package/dist/reclamation.js +0 -812
  248. package/dist/reporter.js +0 -67
  249. package/dist/run-export.js +0 -815
  250. package/dist/run-registry/derive.js +0 -175
  251. package/dist/run-registry/format.js +0 -124
  252. package/dist/run-registry/gc.js +0 -251
  253. package/dist/run-registry/policy.js +0 -16
  254. package/dist/run-registry/queue.js +0 -115
  255. package/dist/run-registry.js +0 -850
  256. package/dist/run-state-schema.js +0 -68
  257. package/dist/scheduling.js +0 -184
  258. package/dist/state-explosion.js +0 -1014
  259. package/dist/state.js +0 -367
  260. package/dist/telemetry-ledger.js +0 -196
  261. package/dist/topology.js +0 -565
  262. package/dist/triggers.js +0 -184
  263. package/dist/trust-audit.js +0 -644
  264. package/dist/types/blackboard.js +0 -2
  265. package/dist/types/candidate.js +0 -2
  266. package/dist/types/collaboration.js +0 -2
  267. package/dist/types/core.js +0 -2
  268. package/dist/types/drive.js +0 -10
  269. package/dist/types/error-feedback.js +0 -2
  270. package/dist/types/evidence-reasoning.js +0 -2
  271. package/dist/types/execution-backend.js +0 -2
  272. package/dist/types/multi-agent.js +0 -2
  273. package/dist/types/observability.js +0 -2
  274. package/dist/types/pipeline.js +0 -2
  275. package/dist/types/reclamation.js +0 -8
  276. package/dist/types/report-bundle.js +0 -6
  277. package/dist/types/result.js +0 -2
  278. package/dist/types/run-registry.js +0 -2
  279. package/dist/types/run.js +0 -2
  280. package/dist/types/sandbox.js +0 -2
  281. package/dist/types/schedule.js +0 -2
  282. package/dist/types/state-node.js +0 -2
  283. package/dist/types/topology.js +0 -2
  284. package/dist/types/trust.js +0 -2
  285. package/dist/types/workbench.js +0 -2
  286. package/dist/types/worker.js +0 -2
  287. package/dist/types/workflow-app.js +0 -2
  288. package/dist/types.js +0 -44
  289. package/dist/util/fingerprint.js +0 -19
  290. package/dist/util/fingerprint.test.js +0 -27
  291. package/dist/verifier.js +0 -78
  292. package/dist/version.js +0 -8
  293. package/dist/workbench-host.js +0 -192
  294. package/dist/workbench.js +0 -192
  295. package/dist/worker-accept/acceptance.js +0 -114
  296. package/dist/worker-accept/blackboard-fanout.js +0 -80
  297. package/dist/worker-accept/blackboard-linkage.js +0 -19
  298. package/dist/worker-accept/context.js +0 -2
  299. package/dist/worker-accept/telemetry-ledger.js +0 -126
  300. package/dist/worker-accept/validation.js +0 -77
  301. package/dist/worker-accept/verifier-completion.js +0 -73
  302. package/dist/worker-isolation/helpers.js +0 -51
  303. package/dist/worker-isolation/paths.js +0 -46
  304. package/dist/worker-isolation.js +0 -656
  305. package/dist/workflow-api.js +0 -131
  306. /package/dist/{types → core/types}/boundary.js +0 -0
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ // shell/dispatch.ts — createDispatchManifest: the imperative wrapper
3
+ // around core/pipeline/dispatch.ts's pure decision helpers.
4
+ //
5
+ // MILESTONE 6+7 (combined). Byte-exact port of the old build's
6
+ // src/dispatch.ts's IO half (worker-scope allocation, manifest file
7
+ // write, state-node append). Multi-agent attachment and custom sandbox
8
+ // profile persistence at dispatch (H7) are milestone 9's scope and are
9
+ // no-ops here.
10
+ //
11
+ // Evidence: SPEC/pipeline-run.md "Dispatch — src/dispatch.ts".
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.writeRunNode = void 0;
47
+ exports.createDispatchManifest = createDispatchManifest;
48
+ const fs = __importStar(require("node:fs"));
49
+ const path = __importStar(require("node:path"));
50
+ const dispatch_1 = require("../core/pipeline/dispatch");
51
+ const contract_1 = require("../core/pipeline/contract");
52
+ const state_node_1 = require("../core/state/state-node");
53
+ const node_store_1 = require("./node-store");
54
+ Object.defineProperty(exports, "writeRunNode", { enumerable: true, get: function () { return node_store_1.writeRunNode; } });
55
+ const fs_atomic_1 = require("./fs-atomic");
56
+ const worker_isolation_1 = require("./worker-isolation");
57
+ const multi_agent_io_1 = require("./multi-agent-io");
58
+ const registry_1 = require("./execution-backend/registry");
59
+ const sandbox_profile_1 = require("./sandbox-profile");
60
+ function createDispatchManifest(run, limit, options = {}) {
61
+ const requestedSandboxProfileId = options.sandboxProfileId || options.sandbox;
62
+ const sandboxProfileId = String(requestedSandboxProfileId || sandbox_profile_1.DEFAULT_SANDBOX_PROFILE_ID);
63
+ (0, sandbox_profile_1.resolveSandboxProfileById)(sandboxProfileId, (0, sandbox_profile_1.sandboxContextForValidation)(run.cwd));
64
+ // H7: if the requested profile is a CUSTOM profile loaded from a FILE (non-bundled,
65
+ // existing file), persist its DEFINITION on run.customSandboxProfiles keyed by the
66
+ // definition's logical id, so a worker boundary can re-resolve it by logical id after
67
+ // a scope snapshot is lost. Throws on an id collision (same id, different file).
68
+ (0, sandbox_profile_1.persistCustomSandboxProfile)(run, sandboxProfileId);
69
+ const backendSelection = (0, registry_1.resolveBackendSelection)(options.backendId);
70
+ const tasks = (0, dispatch_1.nextDispatchTasks)(run, limit);
71
+ if (!tasks.length) {
72
+ return { schemaVersion: 1, runId: run.id, dispatchId: null, tasks: [], manifestPath: null, sandboxProfileId, backendId: backendSelection.backendId, backendSelection };
73
+ }
74
+ const now = new Date().toISOString();
75
+ const dispatchId = (0, dispatch_1.formatDispatchId)((run.dispatches?.length || 0) + 1, now, /^(1|true|yes|on)$/i.test(process.env.CW_DETERMINISTIC_RUN_IDS || ""));
76
+ const manifestPath = path.join(run.paths.dispatchesDir, `${dispatchId}.json`);
77
+ fs.mkdirSync(run.paths.dispatchesDir, { recursive: true });
78
+ const taskIds = new Set(tasks.map((t) => t.id));
79
+ let sandboxPolicy;
80
+ let backendAttestation;
81
+ for (const task of run.tasks) {
82
+ if (!taskIds.has(task.id))
83
+ continue;
84
+ const taskSandboxProfileId = String(requestedSandboxProfileId || task.sandboxProfileId || sandbox_profile_1.DEFAULT_SANDBOX_PROFILE_ID);
85
+ task.status = "running";
86
+ task.loopStage = "act";
87
+ task.dispatchId = dispatchId;
88
+ task.dispatchedAt = now;
89
+ const scope = (0, worker_isolation_1.allocateWorkerScope)(run, task, { dispatchId, sandboxProfileId: taskSandboxProfileId, backendId: backendSelection.backendId, status: "running", metadata: { dispatchId, phase: task.phase } });
90
+ sandboxPolicy = sandboxPolicy || scope.sandboxPolicy;
91
+ backendAttestation = backendAttestation || scope.backendAttestation;
92
+ }
93
+ const selectedRunTasks = run.tasks.filter((t) => taskIds.has(t.id));
94
+ // Attach this dispatch to any active multi-agent run/group/role/fanout: the
95
+ // kernel binds each selected task to its membership and returns the multiAgent
96
+ // block that rides on the manifest + each task + run.dispatches, so a fanin can
97
+ // see its members. Byte-behavior port of the old build's dispatch attachment.
98
+ const multiAgentAttachment = (0, multi_agent_io_1.attachDispatchToMultiAgent)(run, {
99
+ multiAgentRunId: options.multiAgentRunId,
100
+ groupId: options.multiAgentGroupId,
101
+ roleId: options.multiAgentRoleId,
102
+ fanoutId: options.multiAgentFanoutId,
103
+ dispatchId,
104
+ tasks: selectedRunTasks,
105
+ sandboxProfileId,
106
+ concurrencyLimit: limit,
107
+ });
108
+ for (const task of selectedRunTasks) {
109
+ const worker = task.workerId ? (0, worker_isolation_1.getWorkerScope)(run, String(task.workerId)) : undefined;
110
+ if (worker)
111
+ (0, worker_isolation_1.writeWorkerManifest)(run, worker);
112
+ }
113
+ const multiAgentBlock = multiAgentAttachment.multiAgent
114
+ ? { ...multiAgentAttachment.multiAgent, membershipIds: multiAgentAttachment.membershipIds }
115
+ : undefined;
116
+ const dispatchNode = (0, node_store_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
117
+ id: `${run.id}:dispatch:${dispatchId}`,
118
+ kind: "dispatch",
119
+ status: "running",
120
+ loopStage: "act",
121
+ inputs: { taskIds: tasks.map((t) => t.id), phase: tasks[0].phase, sandboxProfileId },
122
+ outputs: { dispatchId, sandboxProfileId },
123
+ artifacts: [{ id: "dispatch", kind: "json", path: manifestPath }],
124
+ parents: tasks.map((t) => `${run.id}:task:${t.id}`),
125
+ contractId: contract_1.DEFAULT_PIPELINE_CONTRACT_ID,
126
+ metadata: { sandboxProfileId, sandboxPolicy },
127
+ }));
128
+ for (const task of run.tasks) {
129
+ if (!taskIds.has(task.id) || !task.stateNodeId)
130
+ continue;
131
+ const node = (run.nodes || []).find((n) => n.id === task.stateNodeId);
132
+ if (node && node.status === "pending") {
133
+ (0, node_store_1.appendRunNode)(run, (0, state_node_1.transitionStateNode)(node, { status: "running", loopStage: "act" }));
134
+ }
135
+ }
136
+ run.dispatches.push({ id: dispatchId, phase: tasks[0].phase || "", taskIds: tasks.map((t) => t.id), manifestPath, createdAt: now, stateNodeId: dispatchNode.id, workerIds: selectedRunTasks.filter((t) => t.workerId).map((t) => String(t.workerId)), sandboxProfileId, backendId: backendSelection.backendId, ...(multiAgentBlock ? { multiAgent: multiAgentBlock } : {}) });
137
+ // Advance the run-level loop stage so operator status ("Stage: act") reflects
138
+ // that work is dispatched — the standalone `cw dispatch` path, like the drive
139
+ // loop, moves interpret→act. (Old build advanced it here.)
140
+ run.loopStage = "act";
141
+ (0, dispatch_1.updatePhaseStatuses)(run);
142
+ const manifest = {
143
+ schemaVersion: 1,
144
+ runId: run.id,
145
+ dispatchId,
146
+ createdAt: now,
147
+ phase: tasks[0].phase,
148
+ 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>`.",
149
+ tasks: selectedRunTasks.map(dispatch_1.formatDispatchTask),
150
+ manifestPath,
151
+ stateNodeId: dispatchNode.id,
152
+ workerIndexPath: run.paths.workersDir ? path.join(run.paths.workersDir, "index.json") : undefined,
153
+ sandboxProfileId,
154
+ sandboxPolicy,
155
+ backendId: backendSelection.backendId,
156
+ backendSelection,
157
+ backendAttestation,
158
+ ...(multiAgentBlock ? { multiAgent: multiAgentBlock } : {}),
159
+ };
160
+ (0, fs_atomic_1.writeJson)(manifestPath, manifest);
161
+ return manifest;
162
+ }
@@ -1,80 +1,116 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ // shell/doctor.ts `cw doctor` environment diagnostics, in the spirit of
3
+ // `brew doctor`.
4
+ //
5
+ // MILESTONE 5 (v2/PLAN.md build order, step 5). Byte-exact port of
6
+ // plugins/cool-workflow/src/doctor.ts's checks this milestone needs
7
+ // (node/agent/agent-binary/git/home-registry/repo-state). The `--onramp`
8
+ // section (buildDoctorOnramp) is later-milestone (reporting) territory and
9
+ // is intentionally NOT wired here — no milestone-5 conformance case passes
10
+ // `--onramp`, and DoctorReport.onramp is optional so this is a strict
11
+ // subset, not a behavior change for any case this milestone must pass.
12
+ //
13
+ // Discipline (unchanged from the old build):
14
+ // - READ-ONLY. Never creates .cw/ or $CW_HOME as a side effect.
15
+ // - FAIL CLOSED. Any `fail` check => ok:false => the CLI exits non-zero.
16
+ // A `warn` (e.g. no agent yet) does not fail.
17
+ // - TWO RENDERINGS. Human text by default; a stable `--json` payload.
18
+ //
19
+ // Evidence: SPEC/execution-backend.md "Agent delegation config"; the doctor
20
+ // behavior itself is documented in the old build's src/doctor.ts (not yet a
21
+ // dedicated SPEC file — this milestone's conformance case,
22
+ // exec-doctor-agent-config.case.js, pins the exact text this file must
23
+ // produce).
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || (function () {
41
+ var ownKeys = function(o) {
42
+ ownKeys = Object.getOwnPropertyNames || function (o) {
43
+ var ar = [];
44
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
45
+ return ar;
46
+ };
47
+ return ownKeys(o);
48
+ };
49
+ return function (mod) {
50
+ if (mod && mod.__esModule) return mod;
51
+ var result = {};
52
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
53
+ __setModuleDefault(result, mod);
54
+ return result;
55
+ };
56
+ })();
5
57
  Object.defineProperty(exports, "__esModule", { value: true });
6
58
  exports.runDoctor = runDoctor;
7
59
  exports.formatDoctorReport = formatDoctorReport;
8
60
  exports.formatDoctorFixes = formatDoctorFixes;
9
- // `cw doctor` — environment diagnostics, in the spirit of `brew doctor`.
10
- //
11
- // Homebrew's `doctor` turned "something is subtly wrong with your setup" into a
12
- // proactive, named list of problems each paired with a concrete fix. We borrow
13
- // that idea: instead of letting a missing agent / old Node / unwritable state
14
- // surface as a confusing mid-run failure, `cw doctor` probes the host up front
15
- // and prints WHAT is wrong and WHAT TO DO about it.
16
- //
17
- // Discipline:
18
- // - READ-ONLY. Probes versions, $PATH, and the WRITABILITY of the nearest
19
- // existing ancestor dir (via access(2)) — it never creates `.cw/` or $CW_HOME
20
- // as a side effect, so running `doctor` changes nothing on disk.
21
- // - FAIL CLOSED. Any `fail` check ⇒ `ok:false` ⇒ the CLI exits non-zero. A
22
- // `warn` (e.g. no agent yet — demo/preview still work) does not fail.
23
- // - TWO RENDERINGS. Human text by default; a stable `--json` payload for scripts.
24
- const node_fs_1 = __importDefault(require("node:fs"));
25
- const node_os_1 = __importDefault(require("node:os"));
26
- const node_path_1 = __importDefault(require("node:path"));
61
+ const fs = __importStar(require("node:fs"));
62
+ const os = __importStar(require("node:os"));
63
+ const path = __importStar(require("node:path"));
27
64
  const node_child_process_1 = require("node:child_process");
28
65
  const agent_config_1 = require("./agent-config");
29
66
  const onramp_1 = require("./onramp");
30
67
  const term_1 = require("./term");
31
- /** Resolve a bare binary name against $PATH (or accept an explicit path). Returns
32
- * the resolved path, or undefined when not found. No spawning. */
33
68
  function whichBinary(bin, env) {
34
69
  if (bin.includes("/") || bin.includes("\\")) {
35
70
  try {
36
- return node_fs_1.default.statSync(bin).isFile() ? bin : undefined;
71
+ return fs.statSync(bin).isFile() ? bin : undefined;
37
72
  }
38
73
  catch {
39
74
  return undefined;
40
75
  }
41
76
  }
42
- const dirs = (env.PATH || "").split(node_path_1.default.delimiter).filter(Boolean);
77
+ const dirs = (env.PATH || "").split(path.delimiter).filter(Boolean);
43
78
  const exts = process.platform === "win32" ? (env.PATHEXT || ".EXE;.CMD;.BAT").split(";") : [""];
44
79
  for (const dir of dirs) {
45
80
  for (const ext of exts) {
46
- const candidate = node_path_1.default.join(dir, bin + ext);
81
+ const candidate = path.join(dir, bin + ext);
47
82
  try {
48
- if (node_fs_1.default.statSync(candidate).isFile())
83
+ if (fs.statSync(candidate).isFile())
49
84
  return candidate;
50
85
  }
51
- catch { /* keep looking */ }
86
+ catch {
87
+ /* keep looking */
88
+ }
52
89
  }
53
90
  }
54
91
  return undefined;
55
92
  }
56
- /** True when `target` could be created/written: walk up to the nearest EXISTING
57
- * ancestor and require it to be a writable DIRECTORY. (A file in the path is not
58
- * writable-as-a-dir even though access(2) W_OK on the file itself would pass.)
59
- * Does NOT create anything — a diagnostic must not have side effects. */
93
+ /** True when `target` could be created/written: walk up to the nearest
94
+ * EXISTING ancestor and require it to be a writable DIRECTORY. Does NOT
95
+ * create anything a diagnostic must not have side effects. */
60
96
  function dirWritable(target) {
61
- let dir = node_path_1.default.resolve(target);
97
+ let dir = path.resolve(target);
62
98
  for (;;) {
63
99
  let stat;
64
100
  try {
65
- stat = node_fs_1.default.statSync(dir);
101
+ stat = fs.statSync(dir);
66
102
  }
67
103
  catch {
68
- const parent = node_path_1.default.dirname(dir);
104
+ const parent = path.dirname(dir);
69
105
  if (parent === dir)
70
106
  return false;
71
107
  dir = parent;
72
108
  continue;
73
109
  }
74
110
  if (!stat.isDirectory())
75
- return false; // an existing file blocks mkdir beneath it
111
+ return false;
76
112
  try {
77
- node_fs_1.default.accessSync(dir, node_fs_1.default.constants.W_OK);
113
+ fs.accessSync(dir, fs.constants.W_OK);
78
114
  return true;
79
115
  }
80
116
  catch {
@@ -84,19 +120,24 @@ function dirWritable(target) {
84
120
  }
85
121
  function runDoctor(args = {}, env = process.env, cwd = process.cwd()) {
86
122
  const checks = [];
87
- // 1. Node runtime — the one hard prerequisite (README: v18+).
123
+ // 1. Node runtime — the one hard prerequisite (v18+).
88
124
  const major = Number((process.version.match(/^v(\d+)/) || [])[1]);
89
125
  checks.push(Number.isFinite(major) && major >= 18
90
126
  ? { name: "node", status: "ok", detail: `Node ${process.version} (>= 18).` }
91
- : { name: "node", status: "fail", detail: `Node ${process.version} is below the required v18.`, fix: "Install Node.js 18+ (e.g. `brew install node`, or https://nodejs.org)." });
127
+ : {
128
+ name: "node",
129
+ status: "fail",
130
+ detail: `Node ${process.version} is below the required v18.`,
131
+ fix: "Install Node.js 18+ (e.g. `brew install node`, or https://nodejs.org).",
132
+ });
92
133
  // 2. Agent backend — CW delegates execution; without one, real runs park.
93
134
  const cfg = (0, agent_config_1.resolveAgentConfig)(args, env);
94
135
  if (cfg.source === "auto") {
95
- const vendor = (cfg.model && cfg.model.startsWith("builtin:")) ? cfg.model.slice("builtin:".length) : "auto";
136
+ const vendor = cfg.model && cfg.model.startsWith("builtin:") ? cfg.model.slice("builtin:".length) : "auto";
96
137
  checks.push({
97
138
  name: "agent",
98
139
  status: "ok",
99
- detail: `Agent auto-detected: ${vendor}. Set CW_AGENT_COMMAND or --agent-command to override.`
140
+ detail: `Agent auto-detected: ${vendor}. Set CW_AGENT_COMMAND or --agent-command to override.`,
100
141
  });
101
142
  }
102
143
  else if (cfg.source === "none") {
@@ -104,7 +145,7 @@ function runDoctor(args = {}, env = process.env, cwd = process.cwd()) {
104
145
  name: "agent",
105
146
  status: "warn",
106
147
  detail: "No agent backend configured — `demo` and `--preview` work, but a real run reports status: blocked.",
107
- fix: 'Pass --agent-command "claude -p", set $CW_AGENT_COMMAND, or use --agent-command builtin:claude.'
148
+ fix: 'Pass --agent-command "claude -p", set $CW_AGENT_COMMAND, or use --agent-command builtin:claude.',
108
149
  });
109
150
  }
110
151
  else {
@@ -112,33 +153,50 @@ function runDoctor(args = {}, env = process.env, cwd = process.cwd()) {
112
153
  checks.push({
113
154
  name: "agent",
114
155
  status: "ok",
115
- detail: `Agent configured from ${cfg.source}${binToken ? `: ${binToken}` : cfg.endpoint ? " (HTTP endpoint)" : ""}.`
156
+ detail: `Agent configured from ${cfg.source}${binToken ? `: ${binToken}` : cfg.endpoint ? " (HTTP endpoint)" : ""}.`,
116
157
  });
117
- // 2b. If it is a command agent, is the binary actually on PATH?
118
158
  if (binToken) {
119
159
  const resolved = whichBinary(binToken, env);
120
160
  checks.push(resolved
121
161
  ? { name: "agent-binary", status: "ok", detail: `Agent binary "${binToken}" found at ${resolved}.` }
122
- : { name: "agent-binary", status: "warn", detail: `Configured agent binary "${binToken}" is not on $PATH.`, fix: `Install "${binToken}", or correct --agent-command / $CW_AGENT_COMMAND.` });
162
+ : {
163
+ name: "agent-binary",
164
+ status: "warn",
165
+ detail: `Configured agent binary "${binToken}" is not on $PATH.`,
166
+ fix: `Install "${binToken}", or correct --agent-command / $CW_AGENT_COMMAND.`,
167
+ });
123
168
  }
124
169
  }
125
- // 3. git — only needed for commit provenance (git HEAD); a warn, not a hard fail.
170
+ // 3. git — only needed for commit provenance; a warn, not a hard fail.
126
171
  const git = (0, node_child_process_1.spawnSync)("git", ["--version"], { encoding: "utf8", timeout: 5000 });
127
172
  checks.push(!git.error && git.status === 0
128
- ? { name: "git", status: "ok", detail: (String(git.stdout || "git").trim()) + "." }
129
- : { name: "git", status: "warn", detail: "git is not available — commit provenance (git HEAD) is recorded as absent.", fix: "Install git (e.g. `brew install git`) if you want commit provenance." });
173
+ ? { name: "git", status: "ok", detail: `${String(git.stdout || "git").trim()}.` }
174
+ : {
175
+ name: "git",
176
+ status: "warn",
177
+ detail: "git is not available — commit provenance (git HEAD) is recorded as absent.",
178
+ fix: "Install git (e.g. `brew install git`) if you want commit provenance.",
179
+ });
130
180
  // 4. Home registry — the cross-repo run index lives here; must be writable.
131
- const home = env.CW_HOME && String(env.CW_HOME).trim()
132
- ? node_path_1.default.resolve(String(env.CW_HOME))
133
- : node_path_1.default.join(node_os_1.default.homedir(), ".local", "state", "cool-workflow");
181
+ const home = env.CW_HOME && String(env.CW_HOME).trim() ? path.resolve(String(env.CW_HOME)) : path.join(os.homedir(), ".local", "state", "cool-workflow");
134
182
  checks.push(dirWritable(home)
135
183
  ? { name: "home-registry", status: "ok", detail: `Home registry location is writable (${home}).` }
136
- : { name: "home-registry", status: "fail", detail: `Home registry location is not writable: ${home}`, fix: "Set $CW_HOME to a writable directory, or fix the permissions." });
184
+ : {
185
+ name: "home-registry",
186
+ status: "fail",
187
+ detail: `Home registry location is not writable: ${home}`,
188
+ fix: "Set $CW_HOME to a writable directory, or fix the permissions.",
189
+ });
137
190
  // 5. Working-dir state — per-repo runs land under <cwd>/.cw.
138
- const cwState = node_path_1.default.join(node_path_1.default.resolve(cwd), ".cw");
191
+ const cwState = path.join(path.resolve(cwd), ".cw");
139
192
  checks.push(dirWritable(cwState)
140
193
  ? { name: "repo-state", status: "ok", detail: `Run state location is writable (${cwState}).` }
141
- : { name: "repo-state", status: "warn", detail: `Cannot write run state under ${cwState}.`, fix: "Run from a writable working directory, or pass --cwd PATH." });
194
+ : {
195
+ name: "repo-state",
196
+ status: "warn",
197
+ detail: `Cannot write run state under ${cwState}.`,
198
+ fix: "Run from a writable working directory, or pass --cwd PATH.",
199
+ });
142
200
  const fails = checks.filter((c) => c.status === "fail").length;
143
201
  const warns = checks.filter((c) => c.status === "warn").length;
144
202
  const ok = fails === 0;
@@ -152,9 +210,18 @@ function runDoctor(args = {}, env = process.env, cwd = process.cwd()) {
152
210
  ok,
153
211
  checks,
154
212
  summary,
213
+ // `--onramp` attaches the change-contract onramp block (byte-exact port
214
+ // of the old build's src/doctor.ts wiring). `--changed-from REF` threads
215
+ // the base ref through to resolveChangedFiles + evaluateOnrampContract.
155
216
  ...((0, onramp_1.optionEnabled)(args.onramp)
156
- ? { onramp: (0, onramp_1.buildDoctorOnramp)({ cwd, env, changedFrom: typeof args["changed-from"] === "string" ? args["changed-from"] : undefined }) }
157
- : {})
217
+ ? {
218
+ onramp: (0, onramp_1.buildDoctorOnramp)({
219
+ cwd,
220
+ env,
221
+ changedFrom: typeof args["changed-from"] === "string" ? args["changed-from"] : undefined,
222
+ }),
223
+ }
224
+ : {}),
158
225
  };
159
226
  }
160
227
  /** Human rendering (TTY/default). `--json` callers use the report object directly. */