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
@@ -1,419 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ERROR_FEEDBACK_SCHEMA_VERSION = void 0;
7
- exports.createErrorFeedbackLoop = createErrorFeedbackLoop;
8
- exports.collectRunErrors = collectRunErrors;
9
- exports.recordFeedback = recordFeedback;
10
- exports.classifyFeedback = classifyFeedback;
11
- exports.createCorrectionTask = createCorrectionTask;
12
- exports.resolveFeedback = resolveFeedback;
13
- exports.listFeedback = listFeedback;
14
- exports.getFeedback = getFeedback;
15
- exports.summarizeFeedback = summarizeFeedback;
16
- const node_fs_1 = __importDefault(require("node:fs"));
17
- const node_path_1 = __importDefault(require("node:path"));
18
- const state_1 = require("./state");
19
- const state_node_1 = require("./state-node");
20
- exports.ERROR_FEEDBACK_SCHEMA_VERSION = 1;
21
- function createErrorFeedbackLoop(options = {}) {
22
- return {
23
- collectRunErrors: (run, collectOptions) => collectRunErrors(run, mergeOptions(options, collectOptions)),
24
- recordFeedback: (run, input) => recordFeedback(run, input, options),
25
- classifyFeedback,
26
- createCorrectionTask: (run, feedbackId, taskOptions) => createCorrectionTask(run, feedbackId, taskOptions),
27
- resolveFeedback: (run, feedbackId, result) => resolveFeedback(run, feedbackId, result),
28
- listFeedback: (run, listOptions) => listFeedback(run, listOptions),
29
- getFeedback,
30
- summarizeFeedback
31
- };
32
- }
33
- function collectRunErrors(run, options = {}) {
34
- const records = [];
35
- const existing = new Set((run.feedback || []).map(feedbackKey));
36
- for (const node of run.nodes || []) {
37
- if (node.status !== "failed" && !node.errors.length)
38
- continue;
39
- for (const error of node.errors) {
40
- const key = feedbackKey({
41
- runId: run.id,
42
- code: error.code,
43
- message: error.message,
44
- nodeId: node.id,
45
- stageId: stringMetadata(node.metadata, "pipelineStage"),
46
- contractId: node.contractId,
47
- path: error.path
48
- });
49
- if (existing.has(key))
50
- continue;
51
- const record = recordFeedback(run, {
52
- source: "state-node",
53
- error,
54
- nodeId: node.id,
55
- stageId: stringMetadata(node.metadata, "pipelineStage"),
56
- contractId: node.contractId,
57
- taskId: stringMetadata(node.metadata, "taskId"),
58
- path: error.path,
59
- retryable: error.retryable,
60
- evidence: node.evidence,
61
- artifacts: node.artifacts,
62
- metadata: {
63
- collectedFromNodeId: node.id,
64
- errorAt: error.at,
65
- details: error.details
66
- }
67
- }, options);
68
- records.push(record);
69
- existing.add(feedbackKey(record));
70
- }
71
- }
72
- if (options.persist !== false && records.length)
73
- (0, state_1.saveCheckpoint)(run);
74
- return records;
75
- }
76
- function recordFeedback(run, input, options = {}) {
77
- ensureFeedbackState(run);
78
- const error = normalizeError(input.error);
79
- const nodeId = input.nodeId || error.nodeId;
80
- const stageId = input.stageId;
81
- const contractId = input.contractId;
82
- const existing = (run.feedback || []).find((record) => record.status !== "resolved" &&
83
- record.code === error.code &&
84
- record.message === error.message &&
85
- record.nodeId === nodeId &&
86
- record.stageId === stageId &&
87
- record.contractId === contractId &&
88
- record.path === (input.path || error.path));
89
- if (existing)
90
- return existing;
91
- const classification = classifyFeedback(error, {
92
- source: input.source || options.source,
93
- stageId,
94
- contractId,
95
- metadata: input.metadata
96
- });
97
- const now = new Date().toISOString();
98
- const record = {
99
- schemaVersion: exports.ERROR_FEEDBACK_SCHEMA_VERSION,
100
- id: createFeedbackId(run, classification),
101
- runId: run.id,
102
- createdAt: now,
103
- updatedAt: now,
104
- status: "open",
105
- severity: severityFor(classification, error),
106
- classification,
107
- source: input.source || options.source || sourceFor(classification),
108
- code: error.code,
109
- message: error.message,
110
- nodeId,
111
- stageId,
112
- contractId,
113
- taskId: input.taskId,
114
- path: input.path || error.path,
115
- retryable: input.retryable ?? error.retryable ?? options.policy?.retryableByDefault ?? false,
116
- evidence: input.evidence || [],
117
- artifacts: input.artifacts || [],
118
- metadata: compactMetadata({
119
- ...input.metadata,
120
- details: input.metadata?.details || error.details
121
- })
122
- };
123
- run.feedback = [...(run.feedback || []), record];
124
- writeFeedback(run, record);
125
- writeFeedbackIndex(run);
126
- if (options.persist !== false)
127
- (0, state_1.saveCheckpoint)(run);
128
- return record;
129
- }
130
- function classifyFeedback(error, context = {}) {
131
- const normalized = normalizeError(error);
132
- const code = normalized.code.toLowerCase();
133
- if (code.includes("missing-artifact") || code.includes("artifact-path"))
134
- return "missing-artifact";
135
- if (code.includes("missing-required-evidence") || code.includes("missing-evidence"))
136
- return "missing-evidence";
137
- if (code.includes("verifier") || context.stageId === "verify" || context.source === "verifier")
138
- return "verifier-failure";
139
- if (code.includes("illegal-transition") || code.includes("state-transition"))
140
- return "state-transition";
141
- if (code.includes("contract") || code.includes("unexpected-node") || context.contractId)
142
- return "contract-violation";
143
- if (code.startsWith("sandbox-"))
144
- return "sandbox-policy";
145
- if (code.includes("parse") || code.includes("json"))
146
- return "parse-error";
147
- if (code.includes("pipeline"))
148
- return "pipeline-failure";
149
- if (normalized.code === "runtime-error")
150
- return "runtime-error";
151
- return "unknown";
152
- }
153
- function createCorrectionTask(run, feedbackId, options = {}) {
154
- const record = requireFeedback(run, feedbackId);
155
- if (record.correctionTaskId)
156
- return record;
157
- const taskId = `feedback:${(0, state_1.safeFileName)(record.id)}`;
158
- const taskPath = node_path_1.default.join(run.paths.tasksDir, `${(0, state_1.safeFileName)(taskId)}.md`);
159
- const body = renderCorrectionTask(record, options);
160
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(taskPath), { recursive: true });
161
- node_fs_1.default.writeFileSync(taskPath, body, "utf8");
162
- const node = (0, state_node_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
163
- id: `${run.id}:task:${taskId}`,
164
- kind: "task",
165
- status: "pending",
166
- loopStage: "adjust",
167
- inputs: { feedbackId: record.id, nodeId: record.nodeId, stageId: record.stageId, contractId: record.contractId },
168
- artifacts: [{ id: "task", kind: "markdown", path: taskPath }],
169
- parents: record.nodeId ? [record.nodeId] : [],
170
- contractId: record.contractId,
171
- metadata: { feedbackId: record.id, correctionTask: true, retryable: record.retryable }
172
- }));
173
- updateFeedback(run, {
174
- ...record,
175
- updatedAt: new Date().toISOString(),
176
- status: "tasked",
177
- correctionTaskId: taskId,
178
- metadata: {
179
- ...(record.metadata || {}),
180
- correctionTaskPath: taskPath,
181
- correctionTaskNodeId: node.id,
182
- verifierCommand: options.verifierCommand
183
- }
184
- });
185
- (0, state_1.saveCheckpoint)(run);
186
- return requireFeedback(run, feedbackId);
187
- }
188
- function resolveFeedback(run, feedbackId, result) {
189
- const record = requireFeedback(run, feedbackId);
190
- if (result.status === "resolved" && !result.nodeId) {
191
- throw new Error(`Feedback ${feedbackId} cannot resolve without a verified node id`);
192
- }
193
- if (result.status === "resolved") {
194
- const node = (run.nodes || []).find((candidate) => candidate.id === result.nodeId);
195
- if (!node)
196
- throw new Error(`Feedback ${feedbackId} resolution node not found: ${result.nodeId}`);
197
- if (node.status !== "verified" && node.status !== "committed") {
198
- throw new Error(`Feedback ${feedbackId} resolution node must be verified or committed`);
199
- }
200
- }
201
- const nextStatus = result.status === "resolved" ? "resolved" : "rejected";
202
- updateFeedback(run, {
203
- ...record,
204
- updatedAt: new Date().toISOString(),
205
- status: nextStatus,
206
- resolvedByNodeId: result.nodeId,
207
- resolvedAt: nextStatus === "resolved" ? new Date().toISOString() : record.resolvedAt,
208
- resolutionNote: result.message || record.resolutionNote,
209
- evidence: mergeById(record.evidence, result.evidence || []),
210
- artifacts: mergeById(record.artifacts, result.artifacts || []),
211
- metadata: compactMetadata({
212
- ...(record.metadata || {}),
213
- resolutionMessage: result.message,
214
- resolution: result.metadata
215
- })
216
- });
217
- (0, state_1.saveCheckpoint)(run);
218
- return requireFeedback(run, feedbackId);
219
- }
220
- function listFeedback(run, options = {}) {
221
- ensureFeedbackState(run);
222
- return (run.feedback || []).filter((record) => {
223
- if (options.status && record.status !== options.status)
224
- return false;
225
- if (options.severity && record.severity !== options.severity)
226
- return false;
227
- if (options.classification && record.classification !== options.classification)
228
- return false;
229
- return true;
230
- });
231
- }
232
- function getFeedback(run, feedbackId) {
233
- ensureFeedbackState(run);
234
- return (run.feedback || []).find((record) => record.id === feedbackId);
235
- }
236
- function summarizeFeedback(run) {
237
- ensureFeedbackState(run);
238
- const records = run.feedback || [];
239
- return {
240
- total: records.length,
241
- byStatus: countBy(records, (record) => record.status),
242
- bySeverity: countBy(records, (record) => record.severity),
243
- byClassification: countBy(records, (record) => record.classification),
244
- artifacts: records.map((record) => feedbackPath(run, record.id))
245
- };
246
- }
247
- function ensureFeedbackState(run) {
248
- run.paths.feedbackDir = run.paths.feedbackDir || node_path_1.default.join(run.paths.runDir, "feedback");
249
- node_fs_1.default.mkdirSync(run.paths.feedbackDir, { recursive: true });
250
- run.feedback = run.feedback || [];
251
- }
252
- function normalizeError(error) {
253
- if (typeof error === "string") {
254
- return { code: "runtime-error", message: error, at: new Date().toISOString() };
255
- }
256
- if (error instanceof Error) {
257
- return { code: codeFromError(error), message: error.message, at: new Date().toISOString() };
258
- }
259
- return {
260
- ...error,
261
- code: error.code || "runtime-error",
262
- message: error.message || "Unknown error",
263
- at: error.at || new Date().toISOString()
264
- };
265
- }
266
- function codeFromError(error) {
267
- if (/Invalid cw:result JSON/i.test(error.message))
268
- return "result-parse-error";
269
- if (/requires cw:result evidence/i.test(error.message))
270
- return "missing-required-evidence";
271
- if (/requires evidence/i.test(error.message))
272
- return "missing-required-evidence";
273
- if (/Phase gate blocked/i.test(error.message))
274
- return "phase-gate-blocked";
275
- return "runtime-error";
276
- }
277
- function severityFor(classification, error) {
278
- if (classification === "verifier-failure" || classification === "contract-violation")
279
- return "high";
280
- if (classification === "sandbox-policy")
281
- return "medium";
282
- if (classification === "state-transition" || classification === "missing-evidence")
283
- return "medium";
284
- if (classification === "missing-artifact" || classification === "parse-error" || classification === "pipeline-failure") {
285
- return error.retryable ? "medium" : "low";
286
- }
287
- return "low";
288
- }
289
- function sourceFor(classification) {
290
- if (classification === "contract-violation")
291
- return "contract";
292
- if (classification === "verifier-failure" || classification === "missing-evidence")
293
- return "verifier";
294
- if (classification === "pipeline-failure")
295
- return "pipeline-runner";
296
- if (classification === "sandbox-policy")
297
- return "contract";
298
- return "manual";
299
- }
300
- function writeFeedback(run, record) {
301
- (0, state_1.writeJson)(feedbackPath(run, record.id), record);
302
- }
303
- function writeFeedbackIndex(run) {
304
- ensureFeedbackState(run);
305
- (0, state_1.writeJson)(node_path_1.default.join(run.paths.feedbackDir, "index.json"), run.feedback || []);
306
- }
307
- function feedbackPath(run, feedbackId) {
308
- ensureFeedbackState(run);
309
- return node_path_1.default.join(run.paths.feedbackDir, `${(0, state_1.safeFileName)(feedbackId)}.json`);
310
- }
311
- function updateFeedback(run, record) {
312
- ensureFeedbackState(run);
313
- run.feedback = (run.feedback || []).map((candidate) => (candidate.id === record.id ? record : candidate));
314
- writeFeedback(run, record);
315
- writeFeedbackIndex(run);
316
- }
317
- function requireFeedback(run, feedbackId) {
318
- const record = getFeedback(run, feedbackId);
319
- if (!record)
320
- throw new Error(`Unknown feedback id for run ${run.id}: ${feedbackId}`);
321
- return record;
322
- }
323
- function renderCorrectionTask(record, options) {
324
- const verifier = options.verifierCommand || "Run the relevant verifier or smoke test and record the verified StateNode id.";
325
- const guidance = options.guidance || (record.retryable ? "Retry only after explicit correction input." : "Do not retry blindly.");
326
- return [
327
- `# Correction Task: ${record.id}`,
328
- "",
329
- `- Status: ${record.status}`,
330
- `- Severity: ${record.severity}`,
331
- `- Classification: ${record.classification}`,
332
- `- Source: ${record.source}`,
333
- `- Code: ${record.code}`,
334
- `- Message: ${record.message}`,
335
- `- Node: ${record.nodeId || ""}`,
336
- `- Stage: ${record.stageId || ""}`,
337
- `- Contract: ${record.contractId || ""}`,
338
- `- Path: ${record.path || ""}`,
339
- `- Retryable: ${record.retryable ? "yes" : "no"}`,
340
- "",
341
- "## Evidence",
342
- "",
343
- ...formatEvidence(record.evidence),
344
- "",
345
- "## Expected Verification",
346
- "",
347
- verifier,
348
- "",
349
- "## Guidance",
350
- "",
351
- guidance,
352
- ""
353
- ].join("\n");
354
- }
355
- function formatEvidence(evidence) {
356
- if (!evidence.length)
357
- return ["No evidence recorded."];
358
- return evidence.map((entry) => `- ${entry.id}: ${entry.locator || entry.path || entry.summary || entry.source || ""}`);
359
- }
360
- // Deterministic feedback id (FreeBSD-audit L12/L13): the feedback record's
361
- // POSITION in the run's append-only feedback log, qualified by classification for
362
- // readability. recordFeedback dedups identical errors before minting, so the
363
- // sequence is stable and collision-free across replays — no clock, no PRNG.
364
- function createFeedbackId(run, classification) {
365
- const seq = (run.feedback || []).length + 1;
366
- return `feedback-${classification}-${String(seq).padStart(4, "0")}`;
367
- }
368
- function feedbackKey(value) {
369
- return [
370
- value.runId || "",
371
- value.code || "",
372
- value.message || "",
373
- value.nodeId || "",
374
- value.stageId || "",
375
- value.contractId || "",
376
- value.path || ""
377
- ].join("\u001f");
378
- }
379
- function stringMetadata(metadata, key) {
380
- const value = metadata?.[key];
381
- return typeof value === "string" ? value : undefined;
382
- }
383
- function compactMetadata(metadata) {
384
- const compacted = {};
385
- for (const [key, value] of Object.entries(metadata)) {
386
- if (value !== undefined)
387
- compacted[key] = value;
388
- }
389
- return Object.keys(compacted).length ? compacted : undefined;
390
- }
391
- function mergeById(existing, next) {
392
- const values = [...existing];
393
- for (const item of next) {
394
- const index = values.findIndex((candidate) => candidate.id === item.id);
395
- if (index >= 0)
396
- values[index] = item;
397
- else
398
- values.push(item);
399
- }
400
- return values;
401
- }
402
- function countBy(values, key) {
403
- const counts = {};
404
- for (const value of values) {
405
- const bucket = key(value);
406
- counts[bucket] = (counts[bucket] || 0) + 1;
407
- }
408
- return counts;
409
- }
410
- function mergeOptions(base, next = {}) {
411
- return {
412
- ...base,
413
- ...next,
414
- policy: {
415
- ...(base.policy || {}),
416
- ...(next.policy || {})
417
- }
418
- };
419
- }
@@ -1,184 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isGroundedEvidence = isGroundedEvidence;
7
- exports.hasGroundedEvidence = hasGroundedEvidence;
8
- exports.requireResolvableEvidence = requireResolvableEvidence;
9
- exports.requireUrlReachability = requireUrlReachability;
10
- exports.resolveEvidenceLocator = resolveEvidenceLocator;
11
- exports.unresolvedFileEvidence = unresolvedFileEvidence;
12
- exports.computeEvidenceConfidence = computeEvidenceConfidence;
13
- exports.computeEvidenceConfidenceTiers = computeEvidenceConfidenceTiers;
14
- exports.maxEvidenceConfidence = maxEvidenceConfidence;
15
- exports.extractEvidenceContent = extractEvidenceContent;
16
- const node_fs_1 = __importDefault(require("node:fs"));
17
- const node_path_1 = __importDefault(require("node:path"));
18
- // ---------------------------------------------------------------------------
19
- // Evidence grounding (v0.1.40 self-audit P1).
20
- //
21
- // The flagship "evidence-gated commit" used to accept ANY non-empty string as
22
- // evidence (`verifier.ts` checked only `.some(entry => entry.trim())`). That made
23
- // the gate trust-on-self-report: an agent could pass it with `evidence: ["x"]`.
24
- //
25
- // CW's evidence is a deliberately free-form LOCATOR namespace — `file:line`,
26
- // URLs, and machine tokens like `exitCode:0`, `stdoutSha256:<hash>`, `refused:<why>`
27
- // are all legitimate — so we cannot require "must be a file that exists" by
28
- // default without breaking cross-repo, URL, and runtime-token evidence. Instead:
29
- //
30
- // 1. DEFAULT: require evidence to be GROUNDED — a URL, a path-like locator, or
31
- // a `namespace:value` token. This rejects bare prose ("x", "anything",
32
- // "HIGH severity") while accepting every shape CW itself emits. Being a pure
33
- // function of the string, it is replay-safe.
34
- //
35
- // 2. DEFAULT (v0.1.95): file-style evidence locators MUST also exist on disk.
36
- // CW_REQUIRE_RESOLVABLE_EVIDENCE=0 restores the prior shape-only behavior.
37
- // CW_REQUIRE_RESOLVABLE_EVIDENCE=url additionally requires URL reachability.
38
- // ---------------------------------------------------------------------------
39
- const URL_RE = /^[a-z][a-z0-9+.-]*:\/\//i;
40
- const PATH_SEP_RE = /[\\/]/;
41
- const FILE_EXT_RE = /\.[A-Za-z0-9]{1,12}(?::\d+(?:-\d+)?)?$/;
42
- const NAMESPACE_TOKEN_RE = /^[A-Za-z][A-Za-z0-9_.-]*:\S/;
43
- const LINE_SUFFIX_RE = /:(\d+(?:-\d+)?)$/;
44
- /** A single evidence string is "grounded" if it is machine-shaped — a URL, a
45
- * path-like locator, or a `namespace:value` token — rather than free prose. */
46
- function isGroundedEvidence(raw) {
47
- const value = String(raw ?? "").trim();
48
- if (!value)
49
- return false;
50
- if (URL_RE.test(value))
51
- return true;
52
- if (PATH_SEP_RE.test(value))
53
- return true;
54
- if (FILE_EXT_RE.test(value))
55
- return true;
56
- if (NAMESPACE_TOKEN_RE.test(value))
57
- return true;
58
- return false;
59
- }
60
- /** An evidence array passes the gate if at least one entry is grounded. */
61
- function hasGroundedEvidence(evidence) {
62
- return Array.isArray(evidence) && evidence.some((entry) => isGroundedEvidence(entry));
63
- }
64
- /** Whether opt-in strict resolution is requested via the environment.
65
- * Enabled by DEFAULT (v0.1.95): file-style evidence locators MUST exist on disk.
66
- * Set CW_REQUIRE_RESOLVABLE_EVIDENCE=0 to restore the prior shape-only check.
67
- * Set CW_REQUIRE_RESOLVABLE_EVIDENCE=url for URL reachability checks too. */
68
- function requireResolvableEvidence() {
69
- const raw = process.env.CW_REQUIRE_RESOLVABLE_EVIDENCE;
70
- if (raw === undefined || raw === null || raw === "")
71
- return true;
72
- if (/^(0|false|no|off)$/i.test(raw))
73
- return false;
74
- return true;
75
- }
76
- /** Whether URL reachability checks are enabled (v0.1.63). Always opt-in. */
77
- function requireUrlReachability() {
78
- return /url/i.test(process.env.CW_REQUIRE_RESOLVABLE_EVIDENCE || "");
79
- }
80
- function classify(raw) {
81
- const value = raw.trim();
82
- if (!value)
83
- return { kind: "opaque" };
84
- if (URL_RE.test(value))
85
- return { kind: "url" };
86
- const line = value.match(LINE_SUFFIX_RE);
87
- const pathPart = line ? value.slice(0, value.length - line[0].length) : value;
88
- const looksFile = (PATH_SEP_RE.test(pathPart) || FILE_EXT_RE.test(value)) && !/\s/.test(pathPart);
89
- return looksFile ? { kind: "file", pathPart } : { kind: "opaque" };
90
- }
91
- /** Resolve one locator against base dirs (used only in strict mode). */
92
- function resolveEvidenceLocator(raw, baseDirs) {
93
- const shape = classify(raw);
94
- if (shape.kind === "url")
95
- return "external";
96
- if (shape.kind === "opaque" || !shape.pathPart)
97
- return "opaque";
98
- const candidates = node_path_1.default.isAbsolute(shape.pathPart)
99
- ? [shape.pathPart]
100
- : baseDirs.filter(Boolean).map((base) => node_path_1.default.resolve(base, shape.pathPart));
101
- for (const candidate of candidates) {
102
- try {
103
- node_fs_1.default.statSync(candidate);
104
- return "resolved";
105
- }
106
- catch {
107
- /* try next base */
108
- }
109
- }
110
- return "unresolved";
111
- }
112
- /** In strict mode, the file-style locators that could NOT be resolved on disk.
113
- * Returns [] when strict mode is off or all file locators resolve. */
114
- function unresolvedFileEvidence(evidence, baseDirs) {
115
- if (!requireResolvableEvidence() || !Array.isArray(evidence))
116
- return [];
117
- return evidence
118
- .map((entry) => String(entry))
119
- .filter((entry) => resolveEvidenceLocator(entry, baseDirs) === "unresolved");
120
- }
121
- /** Compute the confidence tier for a single evidence string. Deterministic:
122
- * pure function of the string and optional base dirs for resolution. */
123
- function computeEvidenceConfidence(raw, baseDirs) {
124
- if (!isGroundedEvidence(raw))
125
- return "ungrounded";
126
- if (!baseDirs || !baseDirs.length || !requireResolvableEvidence())
127
- return "grounded";
128
- const value = String(raw).trim();
129
- const shape = classify(value);
130
- if (shape.kind === "url")
131
- return "grounded"; // URLs not resolved yet
132
- if (shape.kind === "opaque")
133
- return "grounded"; // namespace:value tokens are grounded
134
- // File-style: try resolution
135
- const resolution = resolveEvidenceLocator(value, baseDirs);
136
- return resolution === "resolved" ? "resolvable" : "grounded";
137
- }
138
- /** Compute confidence tiers for an array of evidence entries. */
139
- function computeEvidenceConfidenceTiers(evidence, baseDirs) {
140
- if (!Array.isArray(evidence))
141
- return [];
142
- return evidence.map((entry) => computeEvidenceConfidence(entry, baseDirs));
143
- }
144
- /** The highest confidence tier in an evidence array. Used for gate decisions. */
145
- function maxEvidenceConfidence(evidence, baseDirs) {
146
- const tiers = computeEvidenceConfidenceTiers(evidence, baseDirs);
147
- if (!tiers.length)
148
- return "ungrounded";
149
- const order = ["ungrounded", "grounded", "resolvable", "verified"];
150
- let max = "ungrounded";
151
- for (const tier of tiers) {
152
- if (order.indexOf(tier) > order.indexOf(max))
153
- max = tier;
154
- }
155
- return max;
156
- }
157
- /** Extract actual content from a file-style evidence locator (v0.1.74).
158
- * For `file.ts:42`, reads the file and returns line 42's content.
159
- * Never fabricates — returns undefined when the file doesn't exist or
160
- * the locator is not file-style. Lines are 1-indexed. */
161
- function extractEvidenceContent(locator, baseDirs) {
162
- const shape = classify(locator);
163
- if (shape.kind !== "file" || !shape.pathPart)
164
- return undefined;
165
- const lineMatch = locator.match(/:(\d+)$/);
166
- const lineNum = lineMatch ? Number(lineMatch[1]) : undefined;
167
- const candidatePath = node_path_1.default.isAbsolute(shape.pathPart)
168
- ? shape.pathPart
169
- : baseDirs.filter(Boolean).map((base) => node_path_1.default.resolve(base, shape.pathPart)).find((p) => node_fs_1.default.existsSync(p));
170
- if (!candidatePath)
171
- return undefined;
172
- try {
173
- const content = node_fs_1.default.readFileSync(candidatePath, "utf8");
174
- if (lineNum && lineNum > 0) {
175
- const lines = content.split("\n");
176
- return lines[lineNum - 1] || undefined;
177
- }
178
- // No line number: return first 200 chars as preview
179
- return content.slice(0, 200);
180
- }
181
- catch {
182
- return undefined;
183
- }
184
- }