cool-workflow 0.1.98 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/README.md +18 -7
  4. package/apps/architecture-review/app.json +2 -2
  5. package/apps/architecture-review/workflow.js +12 -12
  6. package/apps/architecture-review-fast/app.json +1 -1
  7. package/apps/end-to-end-golden-path/app.json +1 -1
  8. package/apps/pr-review-fix-ci/app.json +1 -1
  9. package/apps/release-cut/app.json +1 -1
  10. package/apps/research-synthesis/app.json +1 -1
  11. package/dist/cli/dispatch.js +236 -0
  12. package/dist/cli/entry.js +120 -0
  13. package/dist/cli/io.js +21 -4
  14. package/dist/cli/parseargv.js +157 -0
  15. package/dist/cli.js +6 -33
  16. package/dist/core/capability-table.js +3518 -0
  17. package/dist/core/format/help.js +314 -0
  18. package/dist/{state-explosion/format.js → core/format/state-explosion-text.js} +10 -1
  19. package/dist/core/hash.js +137 -0
  20. package/dist/core/multi-agent/candidate-scoring.js +219 -0
  21. package/dist/core/multi-agent/collaboration.js +481 -0
  22. package/dist/core/multi-agent/coordinator.js +515 -0
  23. package/dist/core/multi-agent/eval-replay.js +306 -0
  24. package/dist/core/multi-agent/runtime.js +929 -0
  25. package/dist/core/multi-agent/topology.js +298 -0
  26. package/dist/core/multi-agent/trust-policy.js +197 -0
  27. package/dist/core/pipeline/commit-gate.js +320 -0
  28. package/dist/{pipeline-contract.js → core/pipeline/contract.js} +24 -37
  29. package/dist/core/pipeline/dispatch.js +103 -0
  30. package/dist/core/pipeline/drive-decide.js +227 -0
  31. package/dist/core/pipeline/error-feedback.js +161 -0
  32. package/dist/core/pipeline/loop-expansion.js +124 -0
  33. package/dist/{result-normalize.js → core/pipeline/result-normalize.js} +14 -37
  34. package/dist/core/pipeline/runner.js +230 -0
  35. package/dist/{contract-migration.js → core/state/contract-migration.js} +68 -92
  36. package/dist/{state-migrations.js → core/state/migrations.js} +103 -96
  37. package/dist/core/state/node-projection.js +95 -0
  38. package/dist/core/state/node-snapshot.js +230 -0
  39. package/dist/core/state/run-paths.js +93 -0
  40. package/dist/{schema-validate.js → core/state/schema-validate.js} +35 -28
  41. package/dist/core/state/schema.js +50 -0
  42. package/dist/core/state/state-explosion/digest.js +243 -0
  43. package/dist/core/state/state-explosion/graph.js +527 -0
  44. package/dist/{state-explosion → core/state/state-explosion}/helpers.js +34 -3
  45. package/dist/core/state/state-explosion/report.js +187 -0
  46. package/dist/{state-explosion → core/state/state-explosion}/size.js +25 -7
  47. package/dist/{state-node.js → core/state/state-node.js} +90 -113
  48. package/dist/core/state/types.js +19 -0
  49. package/dist/{validation.js → core/state/validation.js} +64 -131
  50. package/dist/core/trust/evidence-grounding.js +134 -0
  51. package/dist/core/trust/ledger.js +199 -0
  52. package/dist/{telemetry-attestation.js → core/trust/telemetry-attestation.js} +94 -68
  53. package/dist/core/trust/telemetry-ledger.js +127 -0
  54. package/dist/core/types.js +20 -0
  55. package/dist/core/version.js +16 -0
  56. package/dist/{workflow-app-framework.js → core/workflow-apps/app-schema.js} +337 -426
  57. package/dist/mcp/dispatch.js +104 -0
  58. package/dist/mcp/server.js +144 -0
  59. package/dist/mcp-server.js +6 -84
  60. package/dist/{agent-config.js → shell/agent-config.js} +118 -71
  61. package/dist/shell/app-run-cli.js +88 -0
  62. package/dist/shell/audit-cli.js +259 -0
  63. package/dist/shell/audit-provenance.js +83 -0
  64. package/dist/shell/candidate-scoring-io.js +459 -0
  65. package/dist/shell/collaboration-io.js +264 -0
  66. package/dist/shell/commit-summary.js +104 -0
  67. package/dist/shell/commit.js +290 -0
  68. package/dist/shell/coordinator-io.js +476 -0
  69. package/dist/shell/demo-cli.js +19 -0
  70. package/dist/shell/dispatch.js +162 -0
  71. package/dist/shell/doctor.js +292 -0
  72. package/dist/shell/drive.js +885 -0
  73. package/dist/shell/error-feedback-io.js +305 -0
  74. package/dist/shell/eval-io.js +473 -0
  75. package/dist/{multi-agent-eval/format.js → shell/eval-text.js} +78 -49
  76. package/dist/{evidence-reasoning.js → shell/evidence-reasoning.js} +124 -255
  77. package/dist/shell/exec-backend-cli.js +88 -0
  78. package/dist/shell/execution-backend/agent.js +507 -0
  79. package/dist/shell/execution-backend/ci.js +15 -0
  80. package/dist/shell/execution-backend/container.js +69 -0
  81. package/dist/shell/execution-backend/envelopes.js +55 -0
  82. package/dist/shell/execution-backend/local.js +113 -0
  83. package/dist/shell/execution-backend/probes.js +175 -0
  84. package/dist/shell/execution-backend/registry.js +402 -0
  85. package/dist/shell/execution-backend/remote.js +128 -0
  86. package/dist/shell/execution-backend/types.js +11 -0
  87. package/dist/shell/feedback-cli.js +81 -0
  88. package/dist/shell/feedback-operations.js +48 -0
  89. package/dist/shell/fs-atomic.js +276 -0
  90. package/dist/shell/harness.js +98 -0
  91. package/dist/shell/ledger-cli.js +212 -0
  92. package/dist/shell/ledger-io.js +169 -0
  93. package/dist/shell/man-cli.js +89 -0
  94. package/dist/shell/metrics-cli.js +100 -0
  95. package/dist/shell/multi-agent-cli.js +1002 -0
  96. package/dist/shell/multi-agent-host.js +563 -0
  97. package/dist/shell/multi-agent-io.js +387 -0
  98. package/dist/{multi-agent-operator-ux.js → shell/multi-agent-operator-ux.js} +234 -191
  99. package/dist/shell/node-store.js +124 -0
  100. package/dist/{observability/format.js → shell/observability-format.js} +7 -1
  101. package/dist/{observability/intake.js → shell/observability-intake.js} +79 -56
  102. package/dist/{observability.js → shell/observability.js} +159 -332
  103. package/dist/{onramp.js → shell/onramp.js} +11 -0
  104. package/dist/{operator-ux/format.js → shell/operator-ux-text.js} +250 -239
  105. package/dist/shell/operator-ux.js +431 -0
  106. package/dist/shell/orchestrator.js +231 -0
  107. package/dist/shell/pipeline-cli.js +667 -0
  108. package/dist/shell/pipeline.js +217 -0
  109. package/dist/shell/reclamation-io.js +1366 -0
  110. package/dist/shell/registry-cli.js +344 -0
  111. package/dist/{remote-source.js → shell/remote-source.js} +2 -2
  112. package/dist/shell/report-cli.js +101 -0
  113. package/dist/shell/report-view-cli.js +117 -0
  114. package/dist/{orchestrator → shell}/report.js +289 -282
  115. package/dist/shell/reporter.js +62 -0
  116. package/dist/shell/run-export-cli.js +106 -0
  117. package/dist/shell/run-export.js +680 -0
  118. package/dist/shell/run-registry-io.js +1014 -0
  119. package/dist/shell/run-store.js +164 -0
  120. package/dist/{sandbox-profile.js → shell/sandbox-profile.js} +134 -95
  121. package/dist/{scheduler.js → shell/scheduler-io.js} +257 -48
  122. package/dist/shell/scheduling-io.js +321 -0
  123. package/dist/shell/state-cli.js +181 -0
  124. package/dist/shell/state-explosion-cli.js +197 -0
  125. package/dist/shell/telemetry-cli.js +85 -0
  126. package/dist/{telemetry-demo.js → shell/telemetry-demo.js} +149 -119
  127. package/dist/shell/telemetry-ledger-io.js +132 -0
  128. package/dist/{term.js → shell/term.js} +36 -46
  129. package/dist/shell/topology-io.js +361 -0
  130. package/dist/shell/trust-audit.js +472 -0
  131. package/dist/{multi-agent-trust.js → shell/trust-policy-io.js} +67 -205
  132. package/dist/shell/verifier.js +48 -0
  133. package/dist/shell/workbench-host.js +258 -0
  134. package/dist/shell/workbench-text.js +18 -0
  135. package/dist/shell/workbench.js +170 -0
  136. package/dist/shell/worker-cli.js +124 -0
  137. package/dist/shell/worker-isolation.js +852 -0
  138. package/dist/shell/workflow-app-loader.js +650 -0
  139. package/docs/agent-delegation-drive.7.md +4 -0
  140. package/docs/cli-mcp-parity.7.md +282 -219
  141. package/docs/contract-migration-tooling.7.md +4 -0
  142. package/docs/control-plane-scheduling.7.md +4 -0
  143. package/docs/durable-state-and-locking.7.md +4 -0
  144. package/docs/evidence-adoption-reasoning-chain.7.md +4 -0
  145. package/docs/execution-backends.7.md +4 -0
  146. package/docs/multi-agent-cli-mcp-surface.7.md +4 -0
  147. package/docs/multi-agent-eval-replay-harness.7.md +4 -0
  148. package/docs/multi-agent-operator-ux.7.md +4 -0
  149. package/docs/node-snapshot-diff-replay.7.md +4 -0
  150. package/docs/observability-cost-accounting.7.md +6 -1
  151. package/docs/project-index.md +137 -71
  152. package/docs/real-execution-backends.7.md +4 -0
  153. package/docs/release-and-migration.7.md +4 -0
  154. package/docs/release-tooling.7.md +4 -0
  155. package/docs/remote-source-review.7.md +4 -4
  156. package/docs/report-verifiable-bundle.7.md +1 -1
  157. package/docs/run-registry-control-plane.7.md +4 -0
  158. package/docs/run-retention-reclamation.7.md +25 -0
  159. package/docs/security-trust-hardening.7.md +3 -1
  160. package/docs/state-explosion-management.7.md +4 -0
  161. package/docs/team-collaboration.7.md +4 -0
  162. package/docs/web-desktop-workbench.7.md +15 -1
  163. package/manifest/plugin.manifest.json +1 -1
  164. package/manifest/source-context-profiles.json +9 -13
  165. package/package.json +1 -1
  166. package/scripts/agents/agent-adapter-core.js +22 -2
  167. package/scripts/agents/claude-p-agent.js +8 -3
  168. package/scripts/agents/cw-attest-wrap.js +2 -2
  169. package/scripts/agents/gemini-agent.js +5 -1
  170. package/scripts/agents/opencode-agent.js +5 -1
  171. package/scripts/bump-version.js +4 -3
  172. package/scripts/canonical-apps.js +4 -4
  173. package/scripts/dogfood-architecture-review.js +2 -3
  174. package/scripts/dogfood-release.js +3 -3
  175. package/scripts/gen-parity-doc.js +15 -2
  176. package/scripts/golden-path.js +4 -4
  177. package/scripts/onramp-check.js +1 -1
  178. package/scripts/parity-check.js +38 -21
  179. package/scripts/release-flow.js +2 -2
  180. package/scripts/sync-project-index.js +51 -27
  181. package/scripts/validate-run-state-schema.js +2 -2
  182. package/scripts/version-sync-check.js +30 -30
  183. package/dist/candidate-scoring.js +0 -729
  184. package/dist/capability-core.js +0 -1189
  185. package/dist/capability-registry.js +0 -885
  186. package/dist/cli/command-surface.js +0 -494
  187. package/dist/cli/format.js +0 -56
  188. package/dist/cli/handlers/audit.js +0 -82
  189. package/dist/cli/handlers/blackboard.js +0 -81
  190. package/dist/cli/handlers/candidate.js +0 -40
  191. package/dist/cli/handlers/clones.js +0 -34
  192. package/dist/cli/handlers/collaboration.js +0 -61
  193. package/dist/cli/handlers/eval.js +0 -40
  194. package/dist/cli/handlers/ledger.js +0 -169
  195. package/dist/cli/handlers/maintenance.js +0 -107
  196. package/dist/cli/handlers/multi-agent.js +0 -165
  197. package/dist/cli/handlers/node.js +0 -41
  198. package/dist/cli/handlers/operational.js +0 -155
  199. package/dist/cli/handlers/operator.js +0 -146
  200. package/dist/cli/handlers/registry.js +0 -68
  201. package/dist/cli/handlers/run.js +0 -153
  202. package/dist/cli/handlers/scheduling.js +0 -132
  203. package/dist/cli/handlers/workbench.js +0 -41
  204. package/dist/cli/handlers/worker.js +0 -45
  205. package/dist/cli/run-summary.js +0 -45
  206. package/dist/clones.js +0 -162
  207. package/dist/collaboration.js +0 -726
  208. package/dist/commit.js +0 -592
  209. package/dist/compare.js +0 -18
  210. package/dist/coordinator/classify.js +0 -45
  211. package/dist/coordinator/paths.js +0 -42
  212. package/dist/coordinator/util.js +0 -126
  213. package/dist/coordinator.js +0 -990
  214. package/dist/daemon.js +0 -44
  215. package/dist/dispatch.js +0 -250
  216. package/dist/doctor.js +0 -212
  217. package/dist/drive.js +0 -864
  218. package/dist/error-feedback.js +0 -419
  219. package/dist/evidence-grounding.js +0 -184
  220. package/dist/execution-backend/agent.js +0 -354
  221. package/dist/execution-backend/probes.js +0 -112
  222. package/dist/execution-backend/util.js +0 -47
  223. package/dist/execution-backend.js +0 -961
  224. package/dist/gates.js +0 -48
  225. package/dist/harness.js +0 -61
  226. package/dist/ledger.js +0 -313
  227. package/dist/loop-expansion.js +0 -60
  228. package/dist/mcp/tool-call.js +0 -470
  229. package/dist/mcp/tool-definitions.js +0 -1066
  230. package/dist/mcp-surface.js +0 -30
  231. package/dist/multi-agent/graph.js +0 -84
  232. package/dist/multi-agent/helpers.js +0 -141
  233. package/dist/multi-agent/ids.js +0 -20
  234. package/dist/multi-agent/paths.js +0 -22
  235. package/dist/multi-agent-eval/normalize.js +0 -51
  236. package/dist/multi-agent-eval.js +0 -678
  237. package/dist/multi-agent-host.js +0 -777
  238. package/dist/multi-agent.js +0 -984
  239. package/dist/node-projection.js +0 -59
  240. package/dist/node-snapshot.js +0 -260
  241. package/dist/operator-ux.js +0 -631
  242. package/dist/orchestrator/app-operations.js +0 -211
  243. package/dist/orchestrator/audit-operations.js +0 -182
  244. package/dist/orchestrator/candidate-operations.js +0 -117
  245. package/dist/orchestrator/cli-options.js +0 -294
  246. package/dist/orchestrator/collaboration-operations.js +0 -86
  247. package/dist/orchestrator/feedback-operations.js +0 -81
  248. package/dist/orchestrator/host-operations.js +0 -78
  249. package/dist/orchestrator/lifecycle-operations.js +0 -650
  250. package/dist/orchestrator/migration-operations.js +0 -44
  251. package/dist/orchestrator/multi-agent-operations.js +0 -362
  252. package/dist/orchestrator/topology-operations.js +0 -84
  253. package/dist/orchestrator.js +0 -925
  254. package/dist/pipeline-runner.js +0 -285
  255. package/dist/reclamation/hash.js +0 -72
  256. package/dist/reclamation.js +0 -812
  257. package/dist/reporter.js +0 -67
  258. package/dist/run-export.js +0 -815
  259. package/dist/run-registry/derive.js +0 -175
  260. package/dist/run-registry/format.js +0 -124
  261. package/dist/run-registry/gc.js +0 -251
  262. package/dist/run-registry/policy.js +0 -16
  263. package/dist/run-registry/queue.js +0 -115
  264. package/dist/run-registry.js +0 -850
  265. package/dist/run-state-schema.js +0 -68
  266. package/dist/scheduling.js +0 -184
  267. package/dist/state-explosion.js +0 -1014
  268. package/dist/state.js +0 -367
  269. package/dist/telemetry-ledger.js +0 -196
  270. package/dist/topology.js +0 -565
  271. package/dist/triggers.js +0 -184
  272. package/dist/trust-audit.js +0 -644
  273. package/dist/types/blackboard.js +0 -2
  274. package/dist/types/candidate.js +0 -2
  275. package/dist/types/collaboration.js +0 -2
  276. package/dist/types/core.js +0 -2
  277. package/dist/types/drive.js +0 -10
  278. package/dist/types/error-feedback.js +0 -2
  279. package/dist/types/evidence-reasoning.js +0 -2
  280. package/dist/types/execution-backend.js +0 -2
  281. package/dist/types/multi-agent.js +0 -2
  282. package/dist/types/observability.js +0 -2
  283. package/dist/types/pipeline.js +0 -2
  284. package/dist/types/reclamation.js +0 -8
  285. package/dist/types/report-bundle.js +0 -6
  286. package/dist/types/result.js +0 -2
  287. package/dist/types/run-registry.js +0 -2
  288. package/dist/types/run.js +0 -2
  289. package/dist/types/sandbox.js +0 -2
  290. package/dist/types/schedule.js +0 -2
  291. package/dist/types/state-node.js +0 -2
  292. package/dist/types/topology.js +0 -2
  293. package/dist/types/trust.js +0 -2
  294. package/dist/types/workbench.js +0 -2
  295. package/dist/types/worker.js +0 -2
  296. package/dist/types/workflow-app.js +0 -2
  297. package/dist/types.js +0 -44
  298. package/dist/util/fingerprint.js +0 -19
  299. package/dist/util/fingerprint.test.js +0 -27
  300. package/dist/verifier.js +0 -78
  301. package/dist/version.js +0 -8
  302. package/dist/workbench-host.js +0 -192
  303. package/dist/workbench.js +0 -192
  304. package/dist/worker-accept/acceptance.js +0 -114
  305. package/dist/worker-accept/blackboard-fanout.js +0 -80
  306. package/dist/worker-accept/blackboard-linkage.js +0 -19
  307. package/dist/worker-accept/context.js +0 -2
  308. package/dist/worker-accept/telemetry-ledger.js +0 -126
  309. package/dist/worker-accept/validation.js +0 -77
  310. package/dist/worker-accept/verifier-completion.js +0 -73
  311. package/dist/worker-isolation/helpers.js +0 -51
  312. package/dist/worker-isolation/paths.js +0 -46
  313. package/dist/worker-isolation.js +0 -656
  314. package/dist/workflow-api.js +0 -131
  315. /package/dist/{types → core/types}/boundary.js +0 -0
@@ -0,0 +1,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
+ }
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ // shell/doctor.ts — `cw doctor` environment diagnostics, in the spirit of
3
+ // `brew doctor`.
4
+ //
5
+ // MILESTONE 5 (docs/rebuild/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
+ })();
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.runDoctor = runDoctor;
59
+ exports.formatDoctorReport = formatDoctorReport;
60
+ exports.formatDoctorFixes = formatDoctorFixes;
61
+ const fs = __importStar(require("node:fs"));
62
+ const os = __importStar(require("node:os"));
63
+ const path = __importStar(require("node:path"));
64
+ const node_child_process_1 = require("node:child_process");
65
+ const agent_config_1 = require("./agent-config");
66
+ const onramp_1 = require("./onramp");
67
+ const term_1 = require("./term");
68
+ function whichBinary(bin, env) {
69
+ if (bin.includes("/") || bin.includes("\\")) {
70
+ try {
71
+ return fs.statSync(bin).isFile() ? bin : undefined;
72
+ }
73
+ catch {
74
+ return undefined;
75
+ }
76
+ }
77
+ const dirs = (env.PATH || "").split(path.delimiter).filter(Boolean);
78
+ const exts = process.platform === "win32" ? (env.PATHEXT || ".EXE;.CMD;.BAT").split(";") : [""];
79
+ for (const dir of dirs) {
80
+ for (const ext of exts) {
81
+ const candidate = path.join(dir, bin + ext);
82
+ try {
83
+ if (fs.statSync(candidate).isFile())
84
+ return candidate;
85
+ }
86
+ catch {
87
+ /* keep looking */
88
+ }
89
+ }
90
+ }
91
+ return undefined;
92
+ }
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. */
96
+ function dirWritable(target) {
97
+ let dir = path.resolve(target);
98
+ for (;;) {
99
+ let stat;
100
+ try {
101
+ stat = fs.statSync(dir);
102
+ }
103
+ catch {
104
+ const parent = path.dirname(dir);
105
+ if (parent === dir)
106
+ return false;
107
+ dir = parent;
108
+ continue;
109
+ }
110
+ if (!stat.isDirectory())
111
+ return false;
112
+ try {
113
+ fs.accessSync(dir, fs.constants.W_OK);
114
+ return true;
115
+ }
116
+ catch {
117
+ return false;
118
+ }
119
+ }
120
+ }
121
+ function runDoctor(args = {}, env = process.env, cwd = process.cwd()) {
122
+ const checks = [];
123
+ // 1. Node runtime — the one hard prerequisite (v18+).
124
+ const major = Number((process.version.match(/^v(\d+)/) || [])[1]);
125
+ checks.push(Number.isFinite(major) && major >= 18
126
+ ? { name: "node", status: "ok", detail: `Node ${process.version} (>= 18).` }
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
+ });
133
+ // 2. Agent backend — CW delegates execution; without one, real runs park.
134
+ const cfg = (0, agent_config_1.resolveAgentConfig)(args, env);
135
+ if (cfg.source === "auto") {
136
+ const vendor = cfg.model && cfg.model.startsWith("builtin:") ? cfg.model.slice("builtin:".length) : "auto";
137
+ checks.push({
138
+ name: "agent",
139
+ status: "ok",
140
+ detail: `Agent auto-detected: ${vendor}. Set CW_AGENT_COMMAND or --agent-command to override.`,
141
+ });
142
+ }
143
+ else if (cfg.source === "none") {
144
+ checks.push({
145
+ name: "agent",
146
+ status: "warn",
147
+ detail: "No agent backend configured — `demo` and `--preview` work, but a real run reports status: blocked.",
148
+ fix: 'Pass --agent-command "claude -p", set $CW_AGENT_COMMAND, or use --agent-command builtin:claude.',
149
+ });
150
+ }
151
+ else {
152
+ const binToken = cfg.command ? String(cfg.command).split(/\s+/)[0] : undefined;
153
+ checks.push({
154
+ name: "agent",
155
+ status: "ok",
156
+ detail: `Agent configured from ${cfg.source}${binToken ? `: ${binToken}` : cfg.endpoint ? " (HTTP endpoint)" : ""}.`,
157
+ });
158
+ if (binToken) {
159
+ const resolved = whichBinary(binToken, env);
160
+ checks.push(resolved
161
+ ? { name: "agent-binary", status: "ok", detail: `Agent binary "${binToken}" found at ${resolved}.` }
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
+ });
168
+ }
169
+ }
170
+ // 3. Sandbox enforcement boundary — a fixed architectural fact (see
171
+ // docs/sandbox-profiles.7.md), not a host-specific problem to fix, so this
172
+ // is "ok" (informational), never "warn": CW validates sandbox policy and
173
+ // gates worker-output acceptance, but OS-level read/write/execute/network/
174
+ // env isolation is the execution host's responsibility, which this doctor
175
+ // run cannot itself verify. An "ok" check carries no `fix` line by
176
+ // convention (see the node/git checks above), so the pointer to the docs
177
+ // lives in `detail` instead.
178
+ checks.push({
179
+ name: "sandbox-enforceability",
180
+ status: "ok",
181
+ detail: "CW sandbox profiles validate policy and gate worker-output acceptance; OS-level read/write/execute/network/env isolation is the execution host's responsibility (see docs/sandbox-profiles.7.md's ENFORCEMENT section) — this doctor run cannot verify that host enforcement.",
182
+ });
183
+ // 4. git — only needed for commit provenance; a warn, not a hard fail.
184
+ const git = (0, node_child_process_1.spawnSync)("git", ["--version"], { encoding: "utf8", timeout: 5000 });
185
+ checks.push(!git.error && git.status === 0
186
+ ? { name: "git", status: "ok", detail: `${String(git.stdout || "git").trim()}.` }
187
+ : {
188
+ name: "git",
189
+ status: "warn",
190
+ detail: "git is not available — commit provenance (git HEAD) is recorded as absent.",
191
+ fix: "Install git (e.g. `brew install git`) if you want commit provenance.",
192
+ });
193
+ // 5. Home registry — the cross-repo run index lives here; must be writable.
194
+ const home = env.CW_HOME && String(env.CW_HOME).trim() ? path.resolve(String(env.CW_HOME)) : path.join(os.homedir(), ".local", "state", "cool-workflow");
195
+ checks.push(dirWritable(home)
196
+ ? { name: "home-registry", status: "ok", detail: `Home registry location is writable (${home}).` }
197
+ : {
198
+ name: "home-registry",
199
+ status: "fail",
200
+ detail: `Home registry location is not writable: ${home}`,
201
+ fix: "Set $CW_HOME to a writable directory, or fix the permissions.",
202
+ });
203
+ // 6. Working-dir state — per-repo runs land under <cwd>/.cw.
204
+ const cwState = path.join(path.resolve(cwd), ".cw");
205
+ checks.push(dirWritable(cwState)
206
+ ? { name: "repo-state", status: "ok", detail: `Run state location is writable (${cwState}).` }
207
+ : {
208
+ name: "repo-state",
209
+ status: "warn",
210
+ detail: `Cannot write run state under ${cwState}.`,
211
+ fix: "Run from a writable working directory, or pass --cwd PATH.",
212
+ });
213
+ const fails = checks.filter((c) => c.status === "fail").length;
214
+ const warns = checks.filter((c) => c.status === "warn").length;
215
+ const ok = fails === 0;
216
+ const summary = ok
217
+ ? warns === 0
218
+ ? "ready — all checks passed"
219
+ : `ready, with ${warns} warning${warns === 1 ? "" : "s"}`
220
+ : `${fails} blocking problem${fails === 1 ? "" : "s"} found`;
221
+ return {
222
+ schemaVersion: 1,
223
+ ok,
224
+ checks,
225
+ summary,
226
+ // `--onramp` attaches the change-contract onramp block (byte-exact port
227
+ // of the old build's src/doctor.ts wiring). `--changed-from REF` threads
228
+ // the base ref through to resolveChangedFiles + evaluateOnrampContract.
229
+ ...((0, onramp_1.optionEnabled)(args.onramp)
230
+ ? {
231
+ onramp: (0, onramp_1.buildDoctorOnramp)({
232
+ cwd,
233
+ env,
234
+ changedFrom: typeof args["changed-from"] === "string" ? args["changed-from"] : undefined,
235
+ }),
236
+ }
237
+ : {}),
238
+ };
239
+ }
240
+ /** Human rendering (TTY/default). `--json` callers use the report object directly. */
241
+ function formatDoctorReport(report) {
242
+ const lines = [(0, term_1.bold)("cw doctor")];
243
+ for (const check of report.checks) {
244
+ lines.push(` ${(0, term_1.doctorGlyph)(check.status)} ${check.name}: ${check.detail}`);
245
+ if (check.fix && check.status !== "ok")
246
+ lines.push(` fix: ${check.fix}`);
247
+ }
248
+ lines.push("");
249
+ const summaryGlyph = report.ok ? (0, term_1.green)("✓") : (0, term_1.red)("✗");
250
+ lines.push(`${summaryGlyph} ${report.summary}`);
251
+ if (report.onramp) {
252
+ lines.push("");
253
+ lines.push("Quick start (3 steps):");
254
+ lines.push(" 1. cw demo tamper — prove trust checks work (30s)");
255
+ lines.push(" 2. cw demo bundle — prove portable bundles (30s)");
256
+ lines.push(' 3. cw -q "what risks?" — your first real report (needs an agent)');
257
+ lines.push(' cw quickstart research-synthesis --repo <folder> --question "..." — cited report over a docs/papers folder, not only code');
258
+ lines.push("");
259
+ lines.push("Onramp");
260
+ lines.push(` ${report.onramp.summary}`);
261
+ if (report.onramp.recommendedChecks) {
262
+ lines.push("");
263
+ lines.push(" Recommended Checks");
264
+ for (const command of report.onramp.recommendedChecks.commands)
265
+ lines.push(` - ${command}`);
266
+ }
267
+ if (report.onramp.contract && !report.onramp.contract.ok) {
268
+ lines.push("");
269
+ lines.push(" Contract Issues");
270
+ for (const issue of report.onramp.contract.issues) {
271
+ lines.push(` - ${issue.code}: ${issue.detail}`);
272
+ lines.push(` fix: ${issue.fix}`);
273
+ }
274
+ }
275
+ for (const section of report.onramp.sections) {
276
+ lines.push("");
277
+ lines.push(` ${section.title}: ${section.summary}`);
278
+ for (const action of section.actions) {
279
+ lines.push(` - ${action.command}`);
280
+ lines.push(` ${action.reason}`);
281
+ }
282
+ }
283
+ }
284
+ return lines.join("\n");
285
+ }
286
+ /** `--fix` rendering: consolidates all fix strings into an actionable block. */
287
+ function formatDoctorFixes(report) {
288
+ const fixes = report.checks.filter((c) => c.fix && c.status !== "ok").map((c) => c.fix);
289
+ if (!fixes.length)
290
+ return "No fixes needed.";
291
+ return [(0, term_1.bold)("Fix Commands"), ...fixes.map((f, i) => ` ${i + 1}. ${f}`), ""].join("\n");
292
+ }