cool-workflow 0.1.78

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 (193) hide show
  1. package/.claude-plugin/plugin.json +20 -0
  2. package/.codex-plugin/mcp.json +10 -0
  3. package/.codex-plugin/plugin.json +38 -0
  4. package/.mcp.json +10 -0
  5. package/LICENSE +24 -0
  6. package/README.md +638 -0
  7. package/apps/architecture-review/app.json +51 -0
  8. package/apps/architecture-review/workflow.js +116 -0
  9. package/apps/end-to-end-golden-path/app.json +30 -0
  10. package/apps/end-to-end-golden-path/workflow.js +33 -0
  11. package/apps/pr-review-fix-ci/app.json +59 -0
  12. package/apps/pr-review-fix-ci/workflow.js +90 -0
  13. package/apps/release-cut/app.json +54 -0
  14. package/apps/release-cut/workflow.js +82 -0
  15. package/apps/research-synthesis/app.json +50 -0
  16. package/apps/research-synthesis/workflow.js +76 -0
  17. package/apps/workflow-app-framework-demo/app.json +29 -0
  18. package/apps/workflow-app-framework-demo/workflow.js +44 -0
  19. package/dist/agent-config.js +223 -0
  20. package/dist/candidate-scoring.js +715 -0
  21. package/dist/capability-core.js +630 -0
  22. package/dist/capability-dispatcher.js +86 -0
  23. package/dist/capability-registry.js +523 -0
  24. package/dist/cli.js +1276 -0
  25. package/dist/collaboration.js +727 -0
  26. package/dist/commit.js +570 -0
  27. package/dist/contract-migration.js +234 -0
  28. package/dist/coordinator.js +1163 -0
  29. package/dist/daemon.js +44 -0
  30. package/dist/dispatch.js +201 -0
  31. package/dist/drive.js +503 -0
  32. package/dist/error-feedback.js +415 -0
  33. package/dist/evidence-grounding.js +179 -0
  34. package/dist/evidence-reasoning.js +733 -0
  35. package/dist/execution-backend.js +1279 -0
  36. package/dist/harness.js +61 -0
  37. package/dist/mcp-server.js +1615 -0
  38. package/dist/multi-agent-eval.js +857 -0
  39. package/dist/multi-agent-host.js +764 -0
  40. package/dist/multi-agent-operator-ux.js +537 -0
  41. package/dist/multi-agent-trust.js +366 -0
  42. package/dist/multi-agent.js +1173 -0
  43. package/dist/node-snapshot.js +270 -0
  44. package/dist/observability.js +922 -0
  45. package/dist/operator-ux.js +971 -0
  46. package/dist/orchestrator/audit-operations.js +182 -0
  47. package/dist/orchestrator/candidate-operations.js +117 -0
  48. package/dist/orchestrator/cli-options.js +288 -0
  49. package/dist/orchestrator/collaboration-operations.js +86 -0
  50. package/dist/orchestrator/feedback-operations.js +81 -0
  51. package/dist/orchestrator/host-operations.js +78 -0
  52. package/dist/orchestrator/lifecycle-operations.js +462 -0
  53. package/dist/orchestrator/migration-operations.js +44 -0
  54. package/dist/orchestrator/multi-agent-operations.js +362 -0
  55. package/dist/orchestrator/report.js +369 -0
  56. package/dist/orchestrator/topology-operations.js +84 -0
  57. package/dist/orchestrator.js +874 -0
  58. package/dist/pipeline-contract.js +92 -0
  59. package/dist/pipeline-runner.js +285 -0
  60. package/dist/reclamation.js +882 -0
  61. package/dist/result-normalize.js +194 -0
  62. package/dist/run-export.js +64 -0
  63. package/dist/run-registry.js +1347 -0
  64. package/dist/run-state-schema.js +67 -0
  65. package/dist/sandbox-profile.js +471 -0
  66. package/dist/scheduler.js +266 -0
  67. package/dist/scheduling.js +184 -0
  68. package/dist/schema-validate.js +98 -0
  69. package/dist/state-explosion.js +1213 -0
  70. package/dist/state-migrations.js +463 -0
  71. package/dist/state-node.js +301 -0
  72. package/dist/state.js +308 -0
  73. package/dist/telemetry-attestation.js +156 -0
  74. package/dist/telemetry-ledger.js +145 -0
  75. package/dist/topology.js +527 -0
  76. package/dist/triggers.js +159 -0
  77. package/dist/trust-audit.js +475 -0
  78. package/dist/types/blackboard.js +2 -0
  79. package/dist/types/boundary.js +29 -0
  80. package/dist/types/candidate.js +2 -0
  81. package/dist/types/collaboration.js +2 -0
  82. package/dist/types/core.js +2 -0
  83. package/dist/types/drive.js +10 -0
  84. package/dist/types/error-feedback.js +2 -0
  85. package/dist/types/evidence-reasoning.js +2 -0
  86. package/dist/types/execution-backend.js +2 -0
  87. package/dist/types/multi-agent.js +2 -0
  88. package/dist/types/observability.js +2 -0
  89. package/dist/types/pipeline.js +2 -0
  90. package/dist/types/reclamation.js +8 -0
  91. package/dist/types/result.js +2 -0
  92. package/dist/types/run-registry.js +2 -0
  93. package/dist/types/run.js +2 -0
  94. package/dist/types/sandbox.js +2 -0
  95. package/dist/types/schedule.js +2 -0
  96. package/dist/types/state-node.js +2 -0
  97. package/dist/types/topology.js +2 -0
  98. package/dist/types/trust.js +2 -0
  99. package/dist/types/workbench.js +2 -0
  100. package/dist/types/worker.js +2 -0
  101. package/dist/types/workflow-app.js +2 -0
  102. package/dist/types.js +43 -0
  103. package/dist/verifier-registry.js +46 -0
  104. package/dist/verifier.js +78 -0
  105. package/dist/version.js +8 -0
  106. package/dist/workbench-host.js +172 -0
  107. package/dist/workbench.js +190 -0
  108. package/dist/worker-isolation.js +1028 -0
  109. package/dist/workflow-api.js +98 -0
  110. package/dist/workflow-app-framework.js +626 -0
  111. package/docs/agent-delegation-drive.7.md +190 -0
  112. package/docs/agent-framework.md +176 -0
  113. package/docs/candidate-scoring.7.md +106 -0
  114. package/docs/canonical-workflow-apps.7.md +137 -0
  115. package/docs/capability-topology-registry.7.md +168 -0
  116. package/docs/cli-mcp-parity.7.md +373 -0
  117. package/docs/contract-migration-tooling.7.md +123 -0
  118. package/docs/control-plane-scheduling.7.md +110 -0
  119. package/docs/coordinator-blackboard.7.md +183 -0
  120. package/docs/dogfood/architecture-review-cool-workflow.md +16 -0
  121. package/docs/dogfood-one-real-repo.7.md +168 -0
  122. package/docs/durable-state-and-locking.7.md +107 -0
  123. package/docs/end-to-end-golden-path.7.md +117 -0
  124. package/docs/error-feedback.7.md +153 -0
  125. package/docs/evidence-adoption-reasoning-chain.7.md +270 -0
  126. package/docs/execution-backends.7.md +300 -0
  127. package/docs/getting-started.md +99 -0
  128. package/docs/index.md +41 -0
  129. package/docs/mcp-app-surface.7.md +235 -0
  130. package/docs/multi-agent-cli-mcp-surface.7.md +265 -0
  131. package/docs/multi-agent-eval-replay-harness.7.md +302 -0
  132. package/docs/multi-agent-operator-ux.7.md +314 -0
  133. package/docs/multi-agent-runtime-core.7.md +231 -0
  134. package/docs/multi-agent-topologies.7.md +103 -0
  135. package/docs/multi-agent-trust-policy-audit.7.md +154 -0
  136. package/docs/node-snapshot-diff-replay.7.md +135 -0
  137. package/docs/observability-cost-accounting.7.md +194 -0
  138. package/docs/operator-ux.7.md +180 -0
  139. package/docs/pipeline-runner.7.md +136 -0
  140. package/docs/project-index.md +261 -0
  141. package/docs/real-execution-backends.7.md +142 -0
  142. package/docs/release-and-migration.7.md +280 -0
  143. package/docs/release-tooling.7.md +159 -0
  144. package/docs/routines.md +48 -0
  145. package/docs/run-registry-control-plane.7.md +312 -0
  146. package/docs/run-retention-reclamation.7.md +191 -0
  147. package/docs/sandbox-profiles.7.md +137 -0
  148. package/docs/scheduled-tasks.md +80 -0
  149. package/docs/security-trust-hardening.7.md +117 -0
  150. package/docs/state-explosion-management.7.md +264 -0
  151. package/docs/state-node.7.md +96 -0
  152. package/docs/team-collaboration.7.md +207 -0
  153. package/docs/unix-principles.md +192 -0
  154. package/docs/verifier-gated-commit.7.md +140 -0
  155. package/docs/web-desktop-workbench.7.md +215 -0
  156. package/docs/worker-isolation.7.md +167 -0
  157. package/docs/workflow-app-framework.7.md +274 -0
  158. package/manifest/README.md +43 -0
  159. package/manifest/plugin.manifest.json +316 -0
  160. package/manifest/pricing.policy.json +14 -0
  161. package/package.json +79 -0
  162. package/scripts/agents/claude-p-agent.js +104 -0
  163. package/scripts/agents/claude-p-agent.sh +9 -0
  164. package/scripts/agents/cw-attest-keygen.js +55 -0
  165. package/scripts/agents/cw-attest-wrap.js +143 -0
  166. package/scripts/block-unapproved-tag.sh +39 -0
  167. package/scripts/bump-version.js +249 -0
  168. package/scripts/canonical-apps.js +171 -0
  169. package/scripts/cw.js +4 -0
  170. package/scripts/dist-drift-check.js +79 -0
  171. package/scripts/dogfood-architecture-review.js +237 -0
  172. package/scripts/dogfood-release.js +624 -0
  173. package/scripts/forward-ref-docs.js +73 -0
  174. package/scripts/gen-manifests.js +232 -0
  175. package/scripts/golden-path.js +300 -0
  176. package/scripts/mcp-server.js +4 -0
  177. package/scripts/new-feature.js +121 -0
  178. package/scripts/parity-check.js +213 -0
  179. package/scripts/release-check.js +118 -0
  180. package/scripts/release-flow.js +272 -0
  181. package/scripts/release-gate.sh +85 -0
  182. package/scripts/sync-project-index.js +387 -0
  183. package/scripts/validate-run-state-schema.js +126 -0
  184. package/scripts/verify-container-selfref.js +64 -0
  185. package/scripts/version-sync-check.js +237 -0
  186. package/skills/cool-workflow/SKILL.md +162 -0
  187. package/skills/cool-workflow/references/commands.md +282 -0
  188. package/tsconfig.json +16 -0
  189. package/ui/workbench/app.css +76 -0
  190. package/ui/workbench/app.js +159 -0
  191. package/ui/workbench/index.html +32 -0
  192. package/workflows/architecture-review.workflow.js +84 -0
  193. package/workflows/research-synthesis.workflow.js +47 -0
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.collectFeedback = collectFeedback;
37
+ exports.listFeedback = listFeedback;
38
+ exports.showFeedback = showFeedback;
39
+ exports.createFeedbackTask = createFeedbackTask;
40
+ exports.resolveFeedback = resolveFeedback;
41
+ const state_1 = require("../state");
42
+ const report_1 = require("./report");
43
+ const fb = __importStar(require("../error-feedback"));
44
+ function collectFeedback(run) {
45
+ const collected = fb.collectRunErrors(run);
46
+ (0, report_1.writeReport)(run);
47
+ (0, state_1.saveCheckpoint)(run);
48
+ return collected;
49
+ }
50
+ function listFeedback(run, options = {}) {
51
+ return fb.listFeedback(run, {
52
+ status: options.status ? String(options.status) : undefined,
53
+ severity: options.severity ? String(options.severity) : undefined,
54
+ classification: options.classification ? String(options.classification) : undefined
55
+ });
56
+ }
57
+ function showFeedback(run, feedbackId) {
58
+ const feedback = fb.getFeedback(run, feedbackId);
59
+ if (!feedback)
60
+ throw new Error(`Unknown feedback id for run ${run.id}: ${feedbackId}`);
61
+ return feedback;
62
+ }
63
+ function createFeedbackTask(run, feedbackId, options = {}) {
64
+ const feedback = fb.createCorrectionTask(run, feedbackId, {
65
+ verifierCommand: options.verify ? String(options.verify) : undefined,
66
+ guidance: options.guidance ? String(options.guidance) : undefined
67
+ });
68
+ (0, report_1.writeReport)(run);
69
+ (0, state_1.saveCheckpoint)(run);
70
+ return feedback;
71
+ }
72
+ function resolveFeedback(run, feedbackId, options = {}) {
73
+ const feedback = fb.resolveFeedback(run, feedbackId, {
74
+ status: options.status === "rejected" ? "rejected" : "resolved",
75
+ nodeId: options.node ? String(options.node) : undefined,
76
+ message: options.message ? String(options.message) : undefined
77
+ });
78
+ (0, report_1.writeReport)(run);
79
+ (0, state_1.saveCheckpoint)(run);
80
+ return feedback;
81
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.hostMultiAgentRun = hostMultiAgentRun;
37
+ exports.hostMultiAgentStatus = hostMultiAgentStatus;
38
+ exports.hostMultiAgentStep = hostMultiAgentStep;
39
+ exports.hostMultiAgentBlackboard = hostMultiAgentBlackboard;
40
+ exports.hostMultiAgentScore = hostMultiAgentScore;
41
+ exports.hostMultiAgentSelect = hostMultiAgentSelect;
42
+ const state_1 = require("../state");
43
+ const report_1 = require("./report");
44
+ const host = __importStar(require("../multi-agent-host"));
45
+ function hostMultiAgentRun(run, options = {}) {
46
+ const response = host.hostRun(run, options);
47
+ (0, report_1.writeReport)(run);
48
+ (0, state_1.saveCheckpoint)(run);
49
+ return response;
50
+ }
51
+ function hostMultiAgentStatus(run) {
52
+ (0, report_1.writeReport)(run);
53
+ return host.hostStatus(run);
54
+ }
55
+ function hostMultiAgentStep(run, options = {}) {
56
+ const response = host.hostStep(run, options);
57
+ (0, report_1.writeReport)(run);
58
+ (0, state_1.saveCheckpoint)(run);
59
+ return response;
60
+ }
61
+ function hostMultiAgentBlackboard(run, action, options = {}) {
62
+ const response = host.hostBlackboard(run, action, options);
63
+ (0, report_1.writeReport)(run);
64
+ (0, state_1.saveCheckpoint)(run);
65
+ return response;
66
+ }
67
+ function hostMultiAgentScore(run, options = {}) {
68
+ const response = host.hostScore(run, options);
69
+ (0, report_1.writeReport)(run);
70
+ (0, state_1.saveCheckpoint)(run);
71
+ return response;
72
+ }
73
+ function hostMultiAgentSelect(run, options = {}) {
74
+ const response = host.hostSelect(run, options);
75
+ (0, report_1.writeReport)(run);
76
+ (0, state_1.saveCheckpoint)(run);
77
+ return response;
78
+ }
@@ -0,0 +1,462 @@
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.plan = plan;
7
+ exports.dispatch = dispatch;
8
+ exports.recordResult = recordResult;
9
+ exports.recordWorkerOutput = recordWorkerOutput;
10
+ exports.recordWorkerFailure = recordWorkerFailure;
11
+ exports.checkState = checkState;
12
+ exports.commit = commit;
13
+ // Core run-lifecycle operations (v0.1.40 self-audit P3 router pattern).
14
+ //
15
+ // The engine core — plan / dispatch / recordResult / worker-output / commit /
16
+ // checkState — carved out of CoolWorkflowRunner so the runner is a pure router.
17
+ // plan() receives an already-resolved workflow app record (the runner still owns
18
+ // app loading, which is instance-stateful). Behavior is identical to the inline
19
+ // implementations; only the location changed.
20
+ const node_fs_1 = __importDefault(require("node:fs"));
21
+ const node_path_1 = __importDefault(require("node:path"));
22
+ const state_1 = require("../state");
23
+ const report_1 = require("./report");
24
+ const cli_options_1 = require("./cli-options");
25
+ const harness_1 = require("../harness");
26
+ const workflow_app_framework_1 = require("../workflow-app-framework");
27
+ const workflow_api_1 = require("../workflow-api");
28
+ const observability_1 = require("../observability");
29
+ const dispatch_1 = require("../dispatch");
30
+ const verifier_1 = require("../verifier");
31
+ const trust_audit_1 = require("../trust-audit");
32
+ const multi_agent_1 = require("../multi-agent");
33
+ const topology_1 = require("../topology");
34
+ const state_node_1 = require("../state-node");
35
+ const pipeline_contract_1 = require("../pipeline-contract");
36
+ const pipeline_runner_1 = require("../pipeline-runner");
37
+ const commit_1 = require("../commit");
38
+ const error_feedback_1 = require("../error-feedback");
39
+ const trust_audit_2 = require("../trust-audit");
40
+ const result_normalize_1 = require("../result-normalize");
41
+ const state_explosion_1 = require("../state-explosion");
42
+ const worker_isolation_1 = require("../worker-isolation");
43
+ function plan(appRecord, options) {
44
+ const workflow = appRecord.app.workflow;
45
+ const inputs = normalizeInputs(options);
46
+ validateInputs(workflow, inputs);
47
+ // Fold declared defaults: a missing OPTIONAL input renders as its declared
48
+ // default (or empty), so a task prompt referencing it never leaks a literal
49
+ // "{{name}}" placeholder into the agent's worker input.
50
+ for (const declared of workflow.inputs || []) {
51
+ if ((0, cli_options_1.isMissing)(inputs[declared.name]))
52
+ inputs[declared.name] = declared.default ?? "";
53
+ }
54
+ const cwd = node_path_1.default.resolve(String(inputs.cwd || inputs.repo || process.cwd()));
55
+ const runId = createRunId(workflow.id);
56
+ const runDir = node_path_1.default.join(cwd, ".cw", "runs", runId);
57
+ const paths = (0, state_1.createRunPaths)(runDir);
58
+ (0, state_1.ensureRunDirs)(paths);
59
+ const tasks = flattenTasks(workflow, inputs);
60
+ const run = {
61
+ schemaVersion: 1,
62
+ id: runId,
63
+ createdAt: new Date().toISOString(),
64
+ updatedAt: new Date().toISOString(),
65
+ cwd,
66
+ workflow: {
67
+ id: workflow.id,
68
+ title: workflow.title,
69
+ summary: workflow.summary || "",
70
+ limits: workflow.limits,
71
+ app: (0, workflow_app_framework_1.workflowAppRunMetadata)(appRecord)
72
+ },
73
+ inputs,
74
+ loopStage: "interpret",
75
+ phases: workflow.phases.map((phase) => ({
76
+ id: phase.id || (0, workflow_api_1.slugify)(phase.name),
77
+ name: phase.name,
78
+ status: "pending",
79
+ taskIds: phase.tasks.map((task) => task.id),
80
+ // parallel() DSL: the drive loop reads this to size its concurrent round.
81
+ ...(phase.mode ? { mode: phase.mode } : {})
82
+ })),
83
+ tasks,
84
+ dispatches: [],
85
+ commits: [],
86
+ paths,
87
+ nodes: [],
88
+ contracts: [],
89
+ feedback: [],
90
+ audit: {
91
+ schemaVersion: 1,
92
+ eventLogPath: paths.auditDir ? node_path_1.default.join(paths.auditDir, "events.jsonl") : undefined,
93
+ summaryPath: paths.auditDir ? node_path_1.default.join(paths.auditDir, "summary.json") : undefined,
94
+ indexPath: paths.auditDir ? node_path_1.default.join(paths.auditDir, "index.json") : undefined
95
+ },
96
+ workers: [],
97
+ sandboxProfiles: [],
98
+ candidates: [],
99
+ candidateSelections: [],
100
+ multiAgent: {
101
+ schemaVersion: 1,
102
+ runs: [],
103
+ roles: [],
104
+ groups: [],
105
+ memberships: [],
106
+ fanouts: [],
107
+ fanins: []
108
+ },
109
+ blackboard: {
110
+ schemaVersion: 1,
111
+ boards: [],
112
+ topics: [],
113
+ messages: [],
114
+ contexts: [],
115
+ artifacts: [],
116
+ snapshots: [],
117
+ decisions: []
118
+ },
119
+ topologies: {
120
+ schemaVersion: 1,
121
+ runs: []
122
+ }
123
+ };
124
+ (0, trust_audit_1.ensureTrustAudit)(run);
125
+ (0, multi_agent_1.ensureMultiAgentState)(run);
126
+ (0, topology_1.ensureTopologyState)(run);
127
+ (0, harness_1.writeTaskFiles)(run);
128
+ // Use app's custom pipeline if defined; fall back to default (v0.1.56).
129
+ const defaultContract = (0, pipeline_contract_1.createDefaultPipelineContract)();
130
+ const appPipeline = appRecord.app.pipeline;
131
+ const contract = appPipeline
132
+ ? (0, state_node_1.upsertRunContract)(run, { ...defaultContract, ...appPipeline, id: defaultContract.id })
133
+ : (0, state_node_1.upsertRunContract)(run, defaultContract);
134
+ const inputNode = (0, state_node_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
135
+ id: `${run.id}:input`,
136
+ kind: "input",
137
+ status: "completed",
138
+ loopStage: "interpret",
139
+ outputs: run.inputs,
140
+ artifacts: [{ id: "state", kind: "json", path: run.paths.state }],
141
+ contractId: contract.id,
142
+ metadata: { workflowId: workflow.id, app: (0, workflow_app_framework_1.workflowAppRunMetadata)(appRecord) }
143
+ }));
144
+ (0, state_1.saveCheckpoint)(run);
145
+ const pipeline = (0, pipeline_runner_1.createPipelineRunner)({ contractId: contract.id, persist: false });
146
+ for (const task of run.tasks) {
147
+ const taskResult = pipeline.runPipelineStage(run, "plan", inputNode.id, {
148
+ outputNodeId: `${run.id}:task:${task.id}`,
149
+ outputStatus: "pending",
150
+ loopStage: "interpret",
151
+ artifacts: [{ id: "task", kind: "markdown", path: task.taskPath }],
152
+ metadata: {
153
+ workflowId: workflow.id,
154
+ appId: appRecord.app.id,
155
+ appVersion: appRecord.app.version,
156
+ taskId: task.id,
157
+ phase: task.phase,
158
+ taskKind: task.kind,
159
+ requiresEvidence: task.requiresEvidence,
160
+ sandboxProfileId: task.sandboxProfileId
161
+ }
162
+ });
163
+ task.stateNodeId = taskResult.outputNodeId;
164
+ }
165
+ (0, report_1.writeReport)(run);
166
+ (0, commit_1.commitState)(run, "initial-plan");
167
+ (0, state_1.saveCheckpoint)(run);
168
+ return run;
169
+ }
170
+ function dispatch(run, options) {
171
+ try {
172
+ const manifest = (0, dispatch_1.createDispatchManifest)(run, (0, cli_options_1.numberOption)(options.limit), {
173
+ sandboxProfileId: (0, cli_options_1.stringOption)(options.sandbox) || (0, cli_options_1.stringOption)(options.sandboxProfile) || (0, cli_options_1.stringOption)(options.sandboxProfileId),
174
+ backendId: (0, cli_options_1.stringOption)(options.backend) || (0, cli_options_1.stringOption)(options.backendId) || (0, cli_options_1.stringOption)(options.executionBackend),
175
+ multiAgentRunId: (0, cli_options_1.stringOption)(options.multiAgentRun || options.multiAgentRunId || options["multi-agent-run"]),
176
+ multiAgentGroupId: (0, cli_options_1.stringOption)(options.multiAgentGroup || options.multiAgentGroupId || options.group || options["multi-agent-group"]),
177
+ multiAgentRoleId: (0, cli_options_1.stringOption)(options.multiAgentRole || options.multiAgentRoleId || options.role || options["multi-agent-role"]),
178
+ multiAgentFanoutId: (0, cli_options_1.stringOption)(options.multiAgentFanout || options.multiAgentFanoutId || options.fanout || options["multi-agent-fanout"])
179
+ });
180
+ run.loopStage = "act";
181
+ if (manifest.dispatchId)
182
+ (0, commit_1.commitState)(run, `dispatch:${manifest.dispatchId}`);
183
+ (0, state_1.saveCheckpoint)(run);
184
+ (0, report_1.writeReport)(run);
185
+ return manifest;
186
+ }
187
+ catch (error) {
188
+ if ((0, cli_options_1.isSandboxProfileError)(error)) {
189
+ run.loopStage = "adjust";
190
+ (0, error_feedback_1.recordFeedback)(run, {
191
+ source: "cli",
192
+ error: {
193
+ code: error.code,
194
+ message: error.message,
195
+ at: new Date().toISOString(),
196
+ path: error.path,
197
+ retryable: false,
198
+ details: error.details
199
+ },
200
+ retryable: false,
201
+ metadata: { sandboxProfileId: (0, cli_options_1.stringOption)(options.sandbox) || (0, cli_options_1.stringOption)(options.sandboxProfile) || (0, cli_options_1.stringOption)(options.sandboxProfileId) }
202
+ }, { persist: false });
203
+ (0, report_1.writeReport)(run);
204
+ (0, state_1.saveCheckpoint)(run);
205
+ }
206
+ throw error;
207
+ }
208
+ }
209
+ function recordResult(run, taskId, resultPath, options = {}) {
210
+ const task = run.tasks.find((candidate) => candidate.id === taskId);
211
+ if (!task)
212
+ throw new Error(`Unknown task id for run ${run.id}: ${taskId}`);
213
+ // Host-attested token usage (v0.1.31), if the caller supplied it. CW records
214
+ // it verbatim as provenance and NEVER synthesizes it; absent ⇒ `unreported`.
215
+ const usage = (0, observability_1.parseUsageFromArgs)(options, new Date().toISOString());
216
+ try {
217
+ (0, verifier_1.assertTaskCanComplete)(run, task);
218
+ const absoluteResultPath = node_path_1.default.resolve(resultPath);
219
+ if (!node_fs_1.default.existsSync(absoluteResultPath)) {
220
+ throw new Error(`Result file does not exist: ${absoluteResultPath}`);
221
+ }
222
+ const rawResult = node_fs_1.default.readFileSync(absoluteResultPath, "utf8");
223
+ run.loopStage = "observe";
224
+ const parsedResult = (0, verifier_1.parseResultEnvelope)(rawResult);
225
+ run.loopStage = "adjust";
226
+ (0, verifier_1.validateResultEnvelope)(task, parsedResult);
227
+ const destination = node_path_1.default.join(run.paths.resultsDir, `${(0, state_1.safeFileName)(taskId)}.md`);
228
+ node_fs_1.default.copyFileSync(absoluteResultPath, destination);
229
+ task.status = "completed";
230
+ task.completedAt = new Date().toISOString();
231
+ task.resultPath = destination;
232
+ task.loopStage = "observe";
233
+ task.result = parsedResult;
234
+ if (usage)
235
+ task.usage = usage;
236
+ const resultNode = (0, state_node_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
237
+ id: `${run.id}:result:${task.id}`,
238
+ kind: "result",
239
+ status: "completed",
240
+ loopStage: "observe",
241
+ inputs: { taskId: task.id, dispatchId: task.dispatchId },
242
+ outputs: parsedResult,
243
+ artifacts: [{ id: "result", kind: "markdown", path: destination }],
244
+ evidence: parsedResult.evidence.map((entry, index) => ({
245
+ id: `result:${index + 1}`,
246
+ source: "cw:result",
247
+ locator: entry,
248
+ summary: entry
249
+ })),
250
+ parents: task.dispatchId ? [`${run.id}:dispatch:${task.dispatchId}`] : [task.stateNodeId || `${run.id}:task:${task.id}`],
251
+ contractId: pipeline_contract_1.DEFAULT_PIPELINE_CONTRACT_ID,
252
+ metadata: {
253
+ taskId: task.id,
254
+ // Empty-capture warning (v0.1.42): surfaced, never silently passed.
255
+ ...((0, result_normalize_1.isEmptyCapture)(parsedResult) ? { captureWarning: "no findings or evidence captured from result.md" } : {})
256
+ }
257
+ }));
258
+ task.resultNodeId = resultNode.id;
259
+ if ((0, result_normalize_1.isEmptyCapture)(parsedResult)) {
260
+ (0, trust_audit_2.recordTrustAuditEvent)(run, {
261
+ kind: "worker.capture-warning",
262
+ decision: "recorded",
263
+ source: "cw-validated",
264
+ taskId: task.id,
265
+ nodeId: resultNode.id,
266
+ metadata: { reason: "no findings or evidence captured from result.md", resultPath: destination }
267
+ });
268
+ }
269
+ (0, dispatch_1.updatePhaseStatuses)(run);
270
+ (0, verifier_1.validateRunGates)(run);
271
+ const verifierResult = (0, pipeline_runner_1.createPipelineRunner)({ persist: false }).runPipelineStage(run, "verify", resultNode.id, {
272
+ outputNodeId: `${run.id}:verifier:${task.id}`,
273
+ outputStatus: "verified",
274
+ loopStage: "adjust",
275
+ outputs: { accepted: true },
276
+ artifacts: [{ id: "result", kind: "markdown", path: destination }],
277
+ evidence: resultNode.evidence.length
278
+ ? resultNode.evidence
279
+ : [{ id: "result:summary", source: "summary", summary: parsedResult.summary }],
280
+ metadata: { taskId: task.id, resultNodeId: resultNode.id }
281
+ });
282
+ task.verifierNodeId = verifierResult.outputNodeId;
283
+ (0, commit_1.commitState)(run, `result:${taskId}`);
284
+ (0, report_1.writeReport)(run);
285
+ (0, state_1.saveCheckpoint)(run);
286
+ return (0, report_1.summarizeRun)(run);
287
+ }
288
+ catch (error) {
289
+ (0, error_feedback_1.recordFeedback)(run, {
290
+ source: "verifier",
291
+ error: error instanceof Error ? error : String(error),
292
+ taskId: task.id,
293
+ path: resultPath ? node_path_1.default.resolve(resultPath) : undefined,
294
+ retryable: false,
295
+ metadata: {
296
+ taskStatus: task.status,
297
+ dispatchId: task.dispatchId,
298
+ stateNodeId: task.stateNodeId,
299
+ resultNodeId: task.resultNodeId
300
+ }
301
+ });
302
+ (0, report_1.writeReport)(run);
303
+ throw error;
304
+ }
305
+ }
306
+ function recordWorkerOutput(run, workerId, resultPath, options = {}) {
307
+ const usage = (0, observability_1.parseUsageFromArgs)(options, new Date().toISOString());
308
+ // Agent Delegation Drive (v0.1.38): the drive loop passes the agent-hop
309
+ // attestation through verbatim so recordWorkerOutput can fold the digests +
310
+ // model into provenance/trust-audit. Absent for a hand-fulfilled worker.
311
+ const agentDelegation = options.agentDelegation || undefined;
312
+ // Track 1 fail-closed (opt-in): forward the policy so recordWorkerOutput can
313
+ // park a hop whose telemetry isn't attested. Default (absent) ⇒ flag-and-surface.
314
+ const requireAttestedTelemetry = options.requireAttestedTelemetry === true;
315
+ try {
316
+ (0, worker_isolation_1.recordWorkerOutput)(run, workerId, resultPath, { persist: false, agentDelegation, requireAttestedTelemetry });
317
+ if (usage) {
318
+ const worker = (0, worker_isolation_1.getWorkerScope)(run, workerId);
319
+ // Host-attested token usage rides on the worker record as provenance.
320
+ if (worker)
321
+ worker.usage = usage;
322
+ }
323
+ run.loopStage = "observe";
324
+ (0, dispatch_1.updatePhaseStatuses)(run);
325
+ (0, verifier_1.validateRunGates)(run);
326
+ (0, commit_1.commitState)(run, `worker:${workerId}:result`);
327
+ (0, report_1.writeReport)(run);
328
+ (0, state_1.saveCheckpoint)(run);
329
+ return (0, report_1.summarizeRun)(run);
330
+ }
331
+ catch (error) {
332
+ run.loopStage = "adjust";
333
+ (0, dispatch_1.updatePhaseStatuses)(run);
334
+ (0, report_1.writeReport)(run);
335
+ (0, state_1.saveCheckpoint)(run);
336
+ throw error;
337
+ }
338
+ }
339
+ function recordWorkerFailure(run, workerId, message, options = {}) {
340
+ const failure = (0, worker_isolation_1.recordWorkerFailure)(run, workerId, {
341
+ code: String(options.code || "worker-runtime-error"),
342
+ message,
343
+ at: new Date().toISOString(),
344
+ path: options.path ? node_path_1.default.resolve(String(options.path)) : undefined,
345
+ retryable: Boolean(options.retryable)
346
+ }, { persist: false, retryCount: typeof options.retryCount === "number" ? Number(options.retryCount) : undefined });
347
+ run.loopStage = "adjust";
348
+ (0, dispatch_1.updatePhaseStatuses)(run);
349
+ (0, report_1.writeReport)(run);
350
+ (0, state_1.saveCheckpoint)(run);
351
+ return failure;
352
+ }
353
+ function checkState(runId, options = {}) {
354
+ const cwd = node_path_1.default.resolve(String(options.cwd || process.cwd()));
355
+ const statePath = options.state
356
+ ? node_path_1.default.resolve(String(options.state))
357
+ : node_path_1.default.join(cwd, ".cw", "runs", runId, "state.json");
358
+ const result = (0, state_1.migrateRunStateFile)(statePath, { write: Boolean(options.write) });
359
+ return result.report;
360
+ }
361
+ function commit(run, input = {}) {
362
+ run.loopStage = "checkpoint";
363
+ const options = typeof input === "string" ? { reason: input } : input;
364
+ const allowCheckpoint = Boolean(options.allowUnverifiedCheckpoint || options["allow-unverified-checkpoint"]);
365
+ const hasGateOption = Boolean(options.verifier || options.verifierNode || options["verifier-node"] || options.candidate || options.selection);
366
+ try {
367
+ const commitRecord = (0, commit_1.commitState)(run, {
368
+ reason: (0, cli_options_1.stringOption)(options.reason) || "manual",
369
+ verifierNodeId: (0, cli_options_1.stringOption)(options.verifier) || (0, cli_options_1.stringOption)(options.verifierNode) || (0, cli_options_1.stringOption)(options["verifier-node"]),
370
+ candidateId: (0, cli_options_1.stringOption)(options.candidate),
371
+ selectionId: (0, cli_options_1.stringOption)(options.selection),
372
+ verifierGated: hasGateOption || !allowCheckpoint,
373
+ allowUnverifiedCheckpoint: allowCheckpoint,
374
+ source: "cli"
375
+ });
376
+ (0, report_1.writeReport)(run);
377
+ (0, state_1.saveCheckpoint)(run);
378
+ (0, state_explosion_1.maybeCompactRun)(run);
379
+ return { runId: run.id, commit: commitRecord };
380
+ }
381
+ catch (error) {
382
+ (0, report_1.writeReport)(run);
383
+ (0, state_1.saveCheckpoint)(run);
384
+ throw error;
385
+ }
386
+ }
387
+ // ---- plan() private helpers (moved verbatim from the runner) ----------------
388
+ function normalizeInputs(options) {
389
+ const inputs = {};
390
+ for (const [key, value] of Object.entries(options)) {
391
+ if (key === "arg") {
392
+ const pairs = Array.isArray(value) ? value : [value];
393
+ for (const pair of pairs) {
394
+ const [argKey, ...rest] = String(pair).split("=");
395
+ inputs[argKey] = rest.join("=");
396
+ }
397
+ continue;
398
+ }
399
+ inputs[key] = value;
400
+ }
401
+ if (inputs.repo && !inputs.cwd)
402
+ inputs.cwd = inputs.repo;
403
+ return inputs;
404
+ }
405
+ function validateInputs(workflow, inputs) {
406
+ for (const input of workflow.inputs || []) {
407
+ if (input.required && (0, cli_options_1.isMissing)(inputs[input.name])) {
408
+ throw new Error(`Missing required input --${input.name}`);
409
+ }
410
+ }
411
+ }
412
+ function flattenTasks(workflow, inputs) {
413
+ const seen = new Set();
414
+ const tasks = [];
415
+ for (const phase of workflow.phases) {
416
+ for (const task of phase.tasks) {
417
+ if (seen.has(task.id))
418
+ throw new Error(`Duplicate task id: ${task.id}`);
419
+ seen.add(task.id);
420
+ tasks.push({
421
+ id: task.id,
422
+ kind: task.kind,
423
+ phase: phase.name,
424
+ status: "pending",
425
+ loopStage: "interpret",
426
+ requiresEvidence: Boolean(task.requiresEvidence),
427
+ sandboxProfileId: task.sandboxProfileId,
428
+ prompt: renderPrompt(task.prompt, inputs),
429
+ taskPath: "",
430
+ resultPath: "",
431
+ // Track 3: carry the declared output schema onto the run task so
432
+ // validateResultEnvelope can enforce it at intake. Absent ⇒ no schema check.
433
+ ...(task.schema ? { schema: task.schema } : {}),
434
+ // Authoring metadata the drive READS: label (progress/operator views),
435
+ // model (per-task delegation override), agentType (dispatch backend).
436
+ ...(task.label ? { label: task.label } : {}),
437
+ ...(task.model ? { model: task.model } : {}),
438
+ ...(task.agentType ? { agentType: task.agentType } : {})
439
+ });
440
+ }
441
+ }
442
+ return tasks;
443
+ }
444
+ function renderPrompt(prompt, inputs) {
445
+ const invariant = Array.isArray(inputs.invariant)
446
+ ? inputs.invariant.join("; ")
447
+ : String(inputs.invariant || "");
448
+ let rendered = String(prompt)
449
+ .replaceAll("{{repo}}", String(inputs.repo || ""))
450
+ .replaceAll("{{question}}", String(inputs.question || ""))
451
+ .replaceAll("{{invariant}}", invariant);
452
+ for (const [key, value] of Object.entries(inputs)) {
453
+ const replacement = Array.isArray(value) ? value.join("; ") : String(value ?? "");
454
+ rendered = rendered.replaceAll(`{{${key}}}`, replacement);
455
+ }
456
+ return rendered;
457
+ }
458
+ function createRunId(workflowId) {
459
+ const stamp = new Date().toISOString().replace(/[-:]/g, "").replace(/\..+/, "Z");
460
+ const suffix = Math.random().toString(36).slice(2, 8);
461
+ return `${workflowId}-${stamp}-${suffix}`;
462
+ }
@@ -0,0 +1,44 @@
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.migrationList = migrationList;
7
+ exports.migrationCheck = migrationCheck;
8
+ exports.migrationProve = migrationProve;
9
+ exports.loadMigrationSnapshot = loadMigrationSnapshot;
10
+ // Contract-migration domain operations (v0.1.40 self-audit P3 router pattern).
11
+ // Carved out of CoolWorkflowRunner; pure functions (no instance state). Behavior
12
+ // is identical to the inline versions.
13
+ const node_fs_1 = __importDefault(require("node:fs"));
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const state_1 = require("../state");
16
+ const contract_migration_1 = require("../contract-migration");
17
+ function migrationList() {
18
+ return { contracts: (0, contract_migration_1.listMigrationContracts)() };
19
+ }
20
+ function migrationCheck(target, options = {}) {
21
+ const { snapshot, contract } = loadMigrationSnapshot(target, options);
22
+ return (0, contract_migration_1.checkMigration)(contract, snapshot);
23
+ }
24
+ function migrationProve(target, options = {}) {
25
+ const { snapshot, contract, dir } = loadMigrationSnapshot(target, options);
26
+ const proof = (0, contract_migration_1.proveMigration)(contract, snapshot);
27
+ // Append-only: persist the proof beside the target, NEVER overwriting source.
28
+ try {
29
+ (0, state_1.writeJson)(node_path_1.default.join(dir, "migration", `${proof.fingerprint.replace("sha256:", "").slice(0, 16)}.json`), proof);
30
+ }
31
+ catch {
32
+ /* read-only target — the proof is still returned */
33
+ }
34
+ return proof;
35
+ }
36
+ function loadMigrationSnapshot(target, options) {
37
+ const contract = options.contract === "workflow-app" ? "workflow-app" : "run-state";
38
+ const file = node_fs_1.default.existsSync(target) && node_fs_1.default.statSync(target).isFile()
39
+ ? node_path_1.default.resolve(target)
40
+ : node_path_1.default.join(process.cwd(), ".cw", "runs", target, "state.json");
41
+ if (!node_fs_1.default.existsSync(file))
42
+ throw new Error(`Migration target not found: ${target}`);
43
+ return { snapshot: JSON.parse(node_fs_1.default.readFileSync(file, "utf8")), contract, dir: node_path_1.default.dirname(file) };
44
+ }