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,182 @@
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.auditSummary = auditSummary;
7
+ exports.auditMultiAgent = auditMultiAgent;
8
+ exports.auditPolicy = auditPolicy;
9
+ exports.auditRole = auditRole;
10
+ exports.auditBlackboard = auditBlackboard;
11
+ exports.auditJudge = auditJudge;
12
+ exports.workerAudit = workerAudit;
13
+ exports.auditEvidenceProvenance = auditEvidenceProvenance;
14
+ exports.recordAuditAttestation = recordAuditAttestation;
15
+ exports.recordAuditDecision = recordAuditDecision;
16
+ // Audit domain operations (v0.1.40 self-audit P3 maintainability).
17
+ //
18
+ // Carved out of the CoolWorkflowRunner god-object as the first domain in the
19
+ // router pattern: every function here takes an already-loaded WorkflowRun and
20
+ // returns a value (mutating ops persist via the run), so the runner method is a
21
+ // thin `loadRun -> delegate` wrapper. Behavior is identical to the inline
22
+ // implementations these replaced; only the location changed.
23
+ const node_path_1 = __importDefault(require("node:path"));
24
+ const state_1 = require("../state");
25
+ const report_1 = require("./report");
26
+ const cli_options_1 = require("./cli-options");
27
+ const worker_isolation_1 = require("../worker-isolation");
28
+ const sandbox_profile_1 = require("../sandbox-profile");
29
+ const trust_audit_1 = require("../trust-audit");
30
+ const multi_agent_trust_1 = require("../multi-agent-trust");
31
+ function auditSummary(run) {
32
+ return (0, trust_audit_1.summarizeTrustAudit)(run);
33
+ }
34
+ function auditMultiAgent(run) {
35
+ return (0, multi_agent_trust_1.summarizeMultiAgentTrust)(run);
36
+ }
37
+ function auditPolicy(run) {
38
+ const summary = (0, multi_agent_trust_1.summarizeMultiAgentTrust)(run);
39
+ return {
40
+ schemaVersion: 1,
41
+ runId: run.id,
42
+ rolePolicies: summary.rolePolicies,
43
+ permissionDecisions: summary.permissionDecisions,
44
+ policyViolations: summary.policyViolations,
45
+ nextAction: summary.nextAction
46
+ };
47
+ }
48
+ function auditRole(run, roleId) {
49
+ const summary = (0, multi_agent_trust_1.summarizeMultiAgentTrust)(run);
50
+ const events = (0, trust_audit_1.listTrustAuditEvents)(run).filter((event) => event.agentRoleId === roleId);
51
+ return {
52
+ schemaVersion: 1,
53
+ runId: run.id,
54
+ roleId,
55
+ role: run.multiAgent?.roles.find((entry) => entry.id === roleId),
56
+ rolePolicies: summary.rolePolicies.filter((entry) => entry.subjectId === roleId),
57
+ permissionDecisions: events.filter((event) => event.kind === "multi-agent.permission"),
58
+ blackboardWrites: events.filter((event) => event.kind === "blackboard.write"),
59
+ messageProvenance: events.filter((event) => event.kind === "blackboard.message-provenance"),
60
+ judgeRationales: events.filter((event) => event.kind === "judge.rationale"),
61
+ panelDecisions: events.filter((event) => event.kind === "judge.panel-decision"),
62
+ policyViolations: events.filter((event) => event.kind === "policy.violation"),
63
+ events,
64
+ nextAction: `node scripts/cw.js audit multi-agent ${run.id} --json`
65
+ };
66
+ }
67
+ function auditBlackboard(run) {
68
+ const summary = (0, multi_agent_trust_1.summarizeMultiAgentTrust)(run);
69
+ return {
70
+ schemaVersion: 1,
71
+ runId: run.id,
72
+ blackboardWrites: summary.blackboardWrites,
73
+ messageProvenance: summary.messageProvenance,
74
+ policyViolations: summary.policyViolations.filter((event) => event.blackboardId),
75
+ nextAction: summary.nextAction
76
+ };
77
+ }
78
+ function auditJudge(run) {
79
+ const summary = (0, multi_agent_trust_1.summarizeMultiAgentTrust)(run);
80
+ return {
81
+ schemaVersion: 1,
82
+ runId: run.id,
83
+ judgeRationales: summary.judgeRationales,
84
+ panelDecisions: summary.panelDecisions,
85
+ permissionDecisions: summary.permissionDecisions.filter((event) => String(event.metadata?.operation || "").startsWith("judge.")),
86
+ policyViolations: summary.policyViolations.filter((event) => String(event.metadata?.operation || "").startsWith("judge.")),
87
+ nextAction: summary.nextAction
88
+ };
89
+ }
90
+ function workerAudit(run, workerId) {
91
+ return (0, trust_audit_1.workerTrustAudit)(run, workerId);
92
+ }
93
+ function auditEvidenceProvenance(run, options = {}) {
94
+ return (0, trust_audit_1.evidenceProvenance)(run, {
95
+ workerId: (0, cli_options_1.stringOption)(options.worker || options.workerId),
96
+ candidateId: (0, cli_options_1.stringOption)(options.candidate || options.candidateId),
97
+ commitId: (0, cli_options_1.stringOption)(options.commit || options.commitId)
98
+ });
99
+ }
100
+ function recordAuditAttestation(run, options = {}) {
101
+ const workerId = (0, cli_options_1.stringOption)(options.worker || options.workerId);
102
+ const worker = workerId ? (0, worker_isolation_1.getWorkerScope)(run, workerId) : undefined;
103
+ const event = (0, trust_audit_1.recordHostAttestation)(run, {
104
+ actor: (0, cli_options_1.stringOption)(options.actor) || "host",
105
+ workerId,
106
+ taskId: worker?.taskId || (0, cli_options_1.stringOption)(options.task || options.taskId),
107
+ sandboxProfileId: worker?.sandboxProfileId || (0, cli_options_1.stringOption)(options.sandboxProfileId),
108
+ policySnapshot: worker?.sandboxPolicy,
109
+ command: (0, cli_options_1.stringOption)(options.command),
110
+ networkTarget: (0, cli_options_1.stringOption)(options.network || options.networkTarget),
111
+ envVars: (0, cli_options_1.valuesOption)(options.env || options.envVar || options.envVars),
112
+ metadata: {
113
+ note: (0, cli_options_1.stringOption)(options.note || options.message),
114
+ hostEnforced: options.hostEnforced === undefined ? undefined : Boolean(options.hostEnforced)
115
+ }
116
+ });
117
+ (0, state_1.saveCheckpoint)(run);
118
+ return event;
119
+ }
120
+ function recordAuditDecision(run, workerId, options = {}) {
121
+ const worker = (0, worker_isolation_1.getWorkerScope)(run, workerId);
122
+ if (!worker)
123
+ throw new Error(`Unknown worker id for run ${run.id}: ${workerId}`);
124
+ const kind = (0, cli_options_1.stringOption)(options.kind) || (0, cli_options_1.inferAuditDecisionKind)(options);
125
+ const target = (0, cli_options_1.stringOption)(options.path || options.command || options.network || options.networkTarget || options.env || options.envVar);
126
+ if (!target)
127
+ throw new Error("Missing audit decision target: provide --path, --command, --network, or --env");
128
+ const policy = worker.sandboxPolicy;
129
+ let denied = null;
130
+ if (kind === "sandbox.command") {
131
+ denied = policy ? (0, sandbox_profile_1.validateSandboxCommand)(policy, target, workerId) : null;
132
+ }
133
+ else if (kind === "sandbox.network") {
134
+ denied = policy ? (0, sandbox_profile_1.validateSandboxNetwork)(policy, target, workerId) : null;
135
+ }
136
+ else if (kind === "sandbox.env") {
137
+ const name = target.includes("=") ? target.split("=")[0] : target;
138
+ const allowed = Boolean(policy?.env.inherit || policy?.env.expose.includes(name));
139
+ denied = allowed ? null : { code: "sandbox-env-denied", message: `Worker ${workerId} env var is outside sandbox profile ${policy?.id || "unknown"}: ${name}` };
140
+ }
141
+ else {
142
+ denied = (0, worker_isolation_1.validateWorkerBoundary)(run, workerId, { path: target });
143
+ }
144
+ const feedbackIds = [];
145
+ if (denied) {
146
+ const failure = (0, worker_isolation_1.recordWorkerFailure)(run, workerId, {
147
+ code: denied.code,
148
+ message: denied.message,
149
+ at: new Date().toISOString(),
150
+ path: denied.path || (kind === "sandbox.path" ? node_path_1.default.resolve(target) : undefined),
151
+ retryable: false
152
+ }, { persist: false });
153
+ feedbackIds.push(...(failure.feedbackIds || []));
154
+ }
155
+ const event = kind === "sandbox.path"
156
+ ? (0, trust_audit_1.recordSandboxPathDecision)(run, {
157
+ workerId,
158
+ taskId: worker.taskId,
159
+ sandboxProfileId: worker.sandboxProfileId,
160
+ policySnapshot: policy,
161
+ target,
162
+ decision: denied ? "denied" : "allowed",
163
+ feedbackIds,
164
+ metadata: { code: denied?.code }
165
+ })
166
+ : (0, trust_audit_1.recordSandboxPolicyDecision)(run, {
167
+ kind,
168
+ decision: denied ? "denied" : "allowed",
169
+ workerId,
170
+ taskId: worker.taskId,
171
+ sandboxProfileId: worker.sandboxProfileId,
172
+ policySnapshot: policy,
173
+ command: kind === "sandbox.command" ? target : undefined,
174
+ networkTarget: kind === "sandbox.network" ? target : undefined,
175
+ envVars: kind === "sandbox.env" ? [target.includes("=") ? target.split("=")[0] : target] : undefined,
176
+ feedbackIds,
177
+ metadata: { code: denied?.code }
178
+ });
179
+ (0, report_1.writeReport)(run);
180
+ (0, state_1.saveCheckpoint)(run);
181
+ return event;
182
+ }
@@ -0,0 +1,117 @@
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.listCandidates = listCandidates;
7
+ exports.showCandidate = showCandidate;
8
+ exports.registerCandidate = registerCandidate;
9
+ exports.scoreCandidate = scoreCandidate;
10
+ exports.rankCandidates = rankCandidates;
11
+ exports.selectCandidate = selectCandidate;
12
+ exports.rejectCandidate = rejectCandidate;
13
+ // Candidate domain operations (v0.1.40 self-audit P3 router pattern).
14
+ // Carved out of CoolWorkflowRunner; each function takes a loaded run. Behavior is
15
+ // identical to the inline implementations — only the location changed.
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ const state_1 = require("../state");
18
+ const report_1 = require("./report");
19
+ const cli_options_1 = require("./cli-options");
20
+ const worker_isolation_1 = require("../worker-isolation");
21
+ const candidate_scoring_1 = require("../candidate-scoring");
22
+ function listCandidates(run, options = {}) {
23
+ return (0, candidate_scoring_1.listCandidates)(run, {
24
+ status: options.status ? String(options.status) : undefined,
25
+ kind: options.kind ? String(options.kind) : undefined
26
+ });
27
+ }
28
+ function showCandidate(run, candidateId) {
29
+ const candidate = (0, candidate_scoring_1.getCandidate)(run, candidateId);
30
+ if (!candidate)
31
+ throw new Error(`Unknown candidate id for run ${run.id}: ${candidateId}`);
32
+ return candidate;
33
+ }
34
+ function registerCandidate(run, options = {}) {
35
+ const workerId = options.worker ? String(options.worker) : undefined;
36
+ const worker = workerId ? (0, worker_isolation_1.getWorkerScope)(run, workerId) : undefined;
37
+ if (workerId && !worker)
38
+ throw new Error(`Unknown worker id for run ${run.id}: ${workerId}`);
39
+ const task = worker ? run.tasks.find((candidate) => candidate.id === worker.taskId) : undefined;
40
+ const resultNodeId = (0, cli_options_1.stringOption)(options.resultNode) || worker?.resultNodeId || task?.resultNodeId;
41
+ const verifierNodeId = (0, cli_options_1.stringOption)(options.verifierNode) || worker?.output?.verifierNodeId || task?.verifierNodeId;
42
+ const resultPath = (0, cli_options_1.stringOption)(options.resultPath) || worker?.output?.resultPath || task?.resultPath;
43
+ const resultNode = resultNodeId ? run.nodes?.find((node) => node.id === resultNodeId) : undefined;
44
+ const verifierNode = verifierNodeId ? run.nodes?.find((node) => node.id === verifierNodeId) : undefined;
45
+ const candidate = (0, candidate_scoring_1.registerCandidate)(run, {
46
+ id: (0, cli_options_1.stringOption)(options.id),
47
+ kind: (0, cli_options_1.stringOption)(options.kind),
48
+ workerId,
49
+ taskId: (0, cli_options_1.stringOption)(options.task) || worker?.taskId,
50
+ resultNodeId,
51
+ verifierNodeId,
52
+ resultPath,
53
+ artifacts: [
54
+ ...(resultPath ? [{ id: "result", kind: "markdown", path: node_path_1.default.resolve(resultPath) }] : []),
55
+ ...(worker ? [{ id: "worker", kind: "json", path: node_path_1.default.join(worker.workerDir, "worker.json") }] : [])
56
+ ],
57
+ evidence: (0, cli_options_1.mergeEvidence)(resultNode?.evidence || [], verifierNode?.evidence || []),
58
+ metadata: {
59
+ source: worker ? "worker" : "manual",
60
+ workerDir: worker?.workerDir
61
+ }
62
+ }, { persist: false });
63
+ (0, report_1.writeReport)(run);
64
+ (0, state_1.saveCheckpoint)(run);
65
+ return candidate;
66
+ }
67
+ function scoreCandidate(run, candidateId, options = {}) {
68
+ const score = (0, candidate_scoring_1.scoreCandidate)(run, candidateId, {
69
+ id: (0, cli_options_1.stringOption)(options.id),
70
+ scorer: (0, cli_options_1.stringOption)(options.scorer),
71
+ criteria: (0, cli_options_1.parseCriteria)(options),
72
+ maxTotal: (0, cli_options_1.numberOption)(options.maxTotal || options.max),
73
+ verdict: (0, cli_options_1.stringOption)(options.verdict),
74
+ evidence: (0, cli_options_1.parseEvidence)(options.evidence),
75
+ notes: (0, cli_options_1.stringOption)(options.notes)
76
+ }, { persist: false });
77
+ (0, report_1.writeReport)(run);
78
+ (0, state_1.saveCheckpoint)(run);
79
+ return score;
80
+ }
81
+ function rankCandidates(run, options = {}) {
82
+ const ranking = (0, candidate_scoring_1.rankCandidates)(run, {
83
+ includeRejected: Boolean(options.includeRejected),
84
+ policy: {
85
+ minNormalized: (0, cli_options_1.numberOption)(options.minNormalized),
86
+ requireEvidence: options.requireEvidence === undefined ? undefined : Boolean(options.requireEvidence),
87
+ requireVerifierGate: options.requireVerifierGate === undefined ? undefined : Boolean(options.requireVerifierGate),
88
+ tieBreaker: (0, cli_options_1.stringOption)(options.tieBreaker)
89
+ }
90
+ });
91
+ (0, report_1.writeReport)(run);
92
+ (0, state_1.saveCheckpoint)(run);
93
+ return ranking;
94
+ }
95
+ function selectCandidate(run, candidateId, options = {}) {
96
+ const selection = (0, candidate_scoring_1.selectCandidate)(run, candidateId, {
97
+ selectedBy: (0, cli_options_1.stringOption)(options.by) || (0, cli_options_1.stringOption)(options.selectedBy),
98
+ reason: (0, cli_options_1.stringOption)(options.reason),
99
+ scoreId: (0, cli_options_1.stringOption)(options.score),
100
+ allowUnverified: Boolean(options.allowUnverified)
101
+ }, {
102
+ persist: false,
103
+ policy: {
104
+ minNormalized: (0, cli_options_1.numberOption)(options.minNormalized),
105
+ requireVerifierGate: options.requireVerifierGate === undefined ? undefined : Boolean(options.requireVerifierGate)
106
+ }
107
+ });
108
+ (0, report_1.writeReport)(run);
109
+ (0, state_1.saveCheckpoint)(run);
110
+ return selection;
111
+ }
112
+ function rejectCandidate(run, candidateId, reason) {
113
+ const candidate = (0, candidate_scoring_1.rejectCandidate)(run, candidateId, reason, { persist: false });
114
+ (0, report_1.writeReport)(run);
115
+ (0, state_1.saveCheckpoint)(run);
116
+ return candidate;
117
+ }
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ // CLI option parsing & coercion utilities — extracted from orchestrator.ts.
3
+ //
4
+ // Pure functions that turn the raw parsed-argv option bag into typed values
5
+ // (strings, numbers, arrays, actors, blackboard scopes, sandbox choices, …).
6
+ // No run state, no I/O. The orchestrator imports the subset it uses.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.COLLABORATION_TARGET_KINDS = void 0;
9
+ exports.isMissing = isMissing;
10
+ exports.numberOption = numberOption;
11
+ exports.stringOption = stringOption;
12
+ exports.requiredStringOption = requiredStringOption;
13
+ exports.collaborationTarget = collaborationTarget;
14
+ exports.collaborationTargetMaybe = collaborationTargetMaybe;
15
+ exports.actorInputFrom = actorInputFrom;
16
+ exports.firstDefined = firstDefined;
17
+ exports.graphViewOption = graphViewOption;
18
+ exports.graphViewsOption = graphViewsOption;
19
+ exports.metadataOption = metadataOption;
20
+ exports.withoutHostRunKeys = withoutHostRunKeys;
21
+ exports.optionsRecord = optionsRecord;
22
+ exports.parseBlackboardAuthor = parseBlackboardAuthor;
23
+ exports.parseBlackboardScope = parseBlackboardScope;
24
+ exports.parseBlackboardLinks = parseBlackboardLinks;
25
+ exports.parseSandboxChoices = parseSandboxChoices;
26
+ exports.parseCriteria = parseCriteria;
27
+ exports.parseEvidence = parseEvidence;
28
+ exports.mergeEvidence = mergeEvidence;
29
+ exports.arrayOption = arrayOption;
30
+ exports.valuesOption = valuesOption;
31
+ exports.inferAuditDecisionKind = inferAuditDecisionKind;
32
+ exports.isSandboxProfileError = isSandboxProfileError;
33
+ exports.validationIssuesFromError = validationIssuesFromError;
34
+ const sandbox_profile_1 = require("../sandbox-profile");
35
+ const state_explosion_1 = require("../state-explosion");
36
+ const workflow_app_framework_1 = require("../workflow-app-framework");
37
+ function isMissing(value) {
38
+ return value === undefined || value === null || value === "";
39
+ }
40
+ function numberOption(value) {
41
+ if (value === undefined || value === null || value === true)
42
+ return undefined;
43
+ const parsed = Number(value);
44
+ return Number.isFinite(parsed) ? parsed : undefined;
45
+ }
46
+ function stringOption(value) {
47
+ if (value === undefined || value === null || value === true)
48
+ return undefined;
49
+ return String(value);
50
+ }
51
+ function requiredStringOption(value, label) {
52
+ const parsed = stringOption(value);
53
+ if (!parsed)
54
+ throw new Error(`Missing ${label}`);
55
+ return parsed;
56
+ }
57
+ exports.COLLABORATION_TARGET_KINDS = ["run", "task", "candidate", "selection", "commit", "node"];
58
+ function collaborationTarget(kind, id) {
59
+ const normalizedKind = stringOption(kind);
60
+ const normalizedId = stringOption(id);
61
+ if (!normalizedKind || !exports.COLLABORATION_TARGET_KINDS.includes(normalizedKind)) {
62
+ throw new Error(`Target kind must be one of ${exports.COLLABORATION_TARGET_KINDS.join("|")}`);
63
+ }
64
+ if (!normalizedId)
65
+ throw new Error("Missing target id");
66
+ return { kind: normalizedKind, id: normalizedId };
67
+ }
68
+ function collaborationTargetMaybe(kind, id) {
69
+ if (!kind && !id)
70
+ return undefined;
71
+ return collaborationTarget(String(kind || ""), String(id || ""));
72
+ }
73
+ function actorInputFrom(options) {
74
+ return {
75
+ actor: stringOption(firstDefined(options, "actor", "by")),
76
+ actorKind: stringOption(firstDefined(options, "actorKind", "actor-kind", "kind")),
77
+ role: stringOption(firstDefined(options, "role", "roleId", "role-id")),
78
+ displayName: stringOption(firstDefined(options, "displayName", "display-name", "name")),
79
+ attested: Boolean(options.attested),
80
+ attestation: stringOption(options.attestation)
81
+ };
82
+ }
83
+ /** First option value present under any of the given keys (camelCase or dashed). */
84
+ function firstDefined(options, ...keys) {
85
+ for (const key of keys) {
86
+ if (options[key] !== undefined)
87
+ return options[key];
88
+ }
89
+ return undefined;
90
+ }
91
+ function graphViewOption(value) {
92
+ const parsed = stringOption(value);
93
+ if (!parsed)
94
+ return "compact";
95
+ if (!state_explosion_1.GRAPH_VIEWS.includes(parsed)) {
96
+ throw new Error(`Unknown graph view: ${parsed}. Valid views: ${state_explosion_1.GRAPH_VIEWS.join(", ")}`);
97
+ }
98
+ return parsed;
99
+ }
100
+ function graphViewsOption(options) {
101
+ const raw = arrayOption(options.view || options.views).map(String);
102
+ if (!raw.length)
103
+ return undefined;
104
+ for (const view of raw) {
105
+ if (!state_explosion_1.GRAPH_VIEWS.includes(view)) {
106
+ throw new Error(`Unknown graph view: ${view}. Valid views: ${state_explosion_1.GRAPH_VIEWS.join(", ")}`);
107
+ }
108
+ }
109
+ return raw;
110
+ }
111
+ function metadataOption(options) {
112
+ const raw = options.metadata;
113
+ if (raw && typeof raw === "object" && !Array.isArray(raw))
114
+ return raw;
115
+ if (typeof raw === "string")
116
+ return JSON.parse(raw);
117
+ return undefined;
118
+ }
119
+ function withoutHostRunKeys(args) {
120
+ const copy = { ...args };
121
+ for (const key of [
122
+ "app",
123
+ "appId",
124
+ "workflow",
125
+ "workflowId",
126
+ "inputs",
127
+ "topology",
128
+ "topologyId",
129
+ "topologyRun",
130
+ "topologyRunId",
131
+ "multiAgentRun",
132
+ "multiAgentRunId",
133
+ "blackboard",
134
+ "blackboardId",
135
+ "mapperCount",
136
+ "mappers",
137
+ "mapper",
138
+ "judgeCount",
139
+ "judges",
140
+ "judge",
141
+ "debateRounds",
142
+ "rounds",
143
+ "collectInitialFanin",
144
+ "collect-initial-fanin"
145
+ ]) {
146
+ delete copy[key];
147
+ }
148
+ return { ...copy, ...(optionsRecord(args.inputs) || {}) };
149
+ }
150
+ function optionsRecord(value) {
151
+ if (value && typeof value === "object" && !Array.isArray(value))
152
+ return value;
153
+ return undefined;
154
+ }
155
+ function parseBlackboardAuthor(options) {
156
+ const structured = options.author;
157
+ if (structured && typeof structured === "object" && !Array.isArray(structured))
158
+ return structured;
159
+ const id = stringOption(options.authorId || options.author || options.worker || options.workerId || options.role || options.roleId || options.group || options.groupId);
160
+ const kind = stringOption(options.authorKind || options.sourceKind || options.source);
161
+ const displayName = stringOption(options.authorName || options.displayName);
162
+ if (!id && !kind && !displayName)
163
+ return undefined;
164
+ return { kind: kind, id, displayName };
165
+ }
166
+ function parseBlackboardScope(options) {
167
+ const structured = options.scope;
168
+ if (structured && typeof structured === "object" && !Array.isArray(structured))
169
+ return structured;
170
+ const kind = stringOption(options.scopeKind);
171
+ const id = stringOption(options.scopeId);
172
+ if (!kind && !id)
173
+ return undefined;
174
+ return { kind: kind, id };
175
+ }
176
+ function parseBlackboardLinks(runId, options) {
177
+ const structured = options.provenance || options.links;
178
+ if (structured && typeof structured === "object" && !Array.isArray(structured))
179
+ return structured;
180
+ const links = {
181
+ workflowRunId: runId,
182
+ multiAgentRunId: stringOption(options.multiAgentRun || options.multiAgentRunId || options["multi-agent-run"]),
183
+ agentGroupId: stringOption(options.group || options.groupId || options["multi-agent-group"]),
184
+ agentRoleId: stringOption(options.role || options.roleId || options["multi-agent-role"]),
185
+ agentMembershipId: stringOption(options.membership || options.membershipId || options["multi-agent-membership"]),
186
+ agentFanoutId: stringOption(options.fanout || options.fanoutId || options["multi-agent-fanout"]),
187
+ agentFaninId: stringOption(options.fanin || options.faninId || options["multi-agent-fanin"]),
188
+ taskId: stringOption(options.task || options.taskId),
189
+ workerId: stringOption(options.worker || options.workerId),
190
+ candidateId: stringOption(options.candidate || options.candidateId),
191
+ verifierNodeId: stringOption(options.verifier || options.verifierNode || options.verifierNodeId),
192
+ commitId: stringOption(options.commit || options.commitId),
193
+ auditEventIds: arrayOption(options.audit || options.auditEvent || options.auditEventId || options["audit-event"]).map(String),
194
+ evidenceRefs: arrayOption(options.evidence || options.evidenceRef || options["evidence-ref"]).map(String)
195
+ };
196
+ const entries = Object.entries(links).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length));
197
+ return entries.length > 1 ? Object.fromEntries(entries) : undefined;
198
+ }
199
+ function parseSandboxChoices(options) {
200
+ const choices = {};
201
+ const structured = options.sandboxChoices || options.sandboxProfileChoices;
202
+ if (structured && typeof structured === "object" && !Array.isArray(structured)) {
203
+ for (const [key, value] of Object.entries(structured))
204
+ choices[key] = String(value);
205
+ }
206
+ for (const entry of arrayOption(options.sandboxChoice || options["sandbox-choice"])) {
207
+ const [key, ...rest] = String(entry).split("=");
208
+ if (key && rest.length)
209
+ choices[key] = rest.join("=");
210
+ }
211
+ const sandbox = stringOption(options.sandbox || options.sandboxProfile || options.sandboxProfileId);
212
+ if (sandbox && !Object.keys(choices).length)
213
+ choices.default = sandbox;
214
+ return Object.keys(choices).length ? choices : undefined;
215
+ }
216
+ function parseCriteria(options) {
217
+ const criteria = {};
218
+ const structured = options.criteria;
219
+ if (structured && typeof structured === "object" && !Array.isArray(structured)) {
220
+ for (const [key, value] of Object.entries(structured)) {
221
+ const parsed = Number(value);
222
+ if (key && Number.isFinite(parsed))
223
+ criteria[key] = parsed;
224
+ }
225
+ }
226
+ const rawCriteria = options.criterion || (typeof structured === "object" && !Array.isArray(structured) ? undefined : structured) || options.score;
227
+ for (const entry of arrayOption(rawCriteria)) {
228
+ const [key, value] = String(entry).split("=");
229
+ if (!key || value === undefined)
230
+ continue;
231
+ criteria[key] = Number(value);
232
+ }
233
+ if (!Object.keys(criteria).length && options.total !== undefined) {
234
+ criteria.total = Number(options.total);
235
+ }
236
+ if (!Object.keys(criteria).length)
237
+ throw new Error("Missing score criteria. Use --criterion name=value");
238
+ return criteria;
239
+ }
240
+ function parseEvidence(value) {
241
+ return arrayOption(value).map((entry, index) => ({
242
+ id: `score:${index + 1}`,
243
+ source: "candidate-score",
244
+ locator: String(entry),
245
+ summary: String(entry)
246
+ }));
247
+ }
248
+ function mergeEvidence(left, right) {
249
+ const merged = [...left];
250
+ for (const item of right) {
251
+ const index = merged.findIndex((entry) => entry.id === item.id);
252
+ if (index >= 0)
253
+ merged[index] = item;
254
+ else
255
+ merged.push(item);
256
+ }
257
+ return merged;
258
+ }
259
+ function arrayOption(value) {
260
+ if (value === undefined || value === null || value === true)
261
+ return [];
262
+ return Array.isArray(value) ? value : [value];
263
+ }
264
+ function valuesOption(value) {
265
+ return arrayOption(value).map((entry) => String(entry).split("=")[0]).filter(Boolean);
266
+ }
267
+ function inferAuditDecisionKind(options) {
268
+ if (options.command)
269
+ return "sandbox.command";
270
+ if (options.network || options.networkTarget)
271
+ return "sandbox.network";
272
+ if (options.env || options.envVar)
273
+ return "sandbox.env";
274
+ return "sandbox.path";
275
+ }
276
+ function isSandboxProfileError(error) {
277
+ return error instanceof sandbox_profile_1.SandboxProfileError || Boolean(error && typeof error === "object" && "code" in error && String(error.code).startsWith("sandbox-"));
278
+ }
279
+ function validationIssuesFromError(error) {
280
+ if (error instanceof workflow_app_framework_1.WorkflowAppValidationError)
281
+ return error.issues;
282
+ return [
283
+ {
284
+ code: "workflow-app-invalid",
285
+ message: error instanceof Error ? error.message : String(error)
286
+ }
287
+ ];
288
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collaborationApprove = collaborationApprove;
4
+ exports.collaborationComment = collaborationComment;
5
+ exports.collaborationCommentList = collaborationCommentList;
6
+ exports.collaborationHandoff = collaborationHandoff;
7
+ exports.reviewStatus = reviewStatus;
8
+ exports.reviewPolicy = reviewPolicy;
9
+ exports.formatReviewStatus = formatReviewStatus;
10
+ exports.formatCommentList = formatCommentList;
11
+ const state_1 = require("../state");
12
+ const report_1 = require("./report");
13
+ const cli_options_1 = require("./cli-options");
14
+ const collaboration_1 = require("../collaboration");
15
+ function collaborationApprove(run, targetKind, targetId, options = {}, decision = "approve") {
16
+ const record = (0, collaboration_1.recordApproval)(run, {
17
+ target: (0, cli_options_1.collaborationTarget)(targetKind, targetId),
18
+ decision,
19
+ ...(0, cli_options_1.actorInputFrom)(options),
20
+ rationale: (0, cli_options_1.stringOption)(options.rationale) || (0, cli_options_1.stringOption)(options.reason) || (0, cli_options_1.stringOption)(options.message),
21
+ supersedes: (0, cli_options_1.stringOption)(options.supersedes)
22
+ }, { persist: false });
23
+ (0, report_1.writeReport)(run);
24
+ (0, state_1.saveCheckpoint)(run);
25
+ return record;
26
+ }
27
+ function collaborationComment(run, targetKind, targetId, options = {}) {
28
+ const record = (0, collaboration_1.recordComment)(run, {
29
+ target: (0, cli_options_1.collaborationTarget)(targetKind, targetId),
30
+ body: (0, cli_options_1.stringOption)(options.body) || (0, cli_options_1.stringOption)(options.message) || (0, cli_options_1.stringOption)(options.text) || "",
31
+ threadId: (0, cli_options_1.stringOption)(options.thread) || (0, cli_options_1.stringOption)(options.threadId),
32
+ parentId: (0, cli_options_1.stringOption)(options.parent) || (0, cli_options_1.stringOption)(options.parentId),
33
+ ...(0, cli_options_1.actorInputFrom)(options)
34
+ }, { persist: false });
35
+ (0, report_1.writeReport)(run);
36
+ (0, state_1.saveCheckpoint)(run);
37
+ return record;
38
+ }
39
+ function collaborationCommentList(run, options = {}) {
40
+ const target = (0, cli_options_1.collaborationTargetMaybe)((0, cli_options_1.stringOption)(options.targetKind) || (0, cli_options_1.stringOption)(options.kind), (0, cli_options_1.stringOption)(options.target) || (0, cli_options_1.stringOption)(options.targetId));
41
+ const comments = (0, collaboration_1.listComments)(run, target);
42
+ return { schemaVersion: 1, surface: "collaboration", runId: run.id, target, count: comments.length, comments };
43
+ }
44
+ function collaborationHandoff(run, targetKind, targetId, options = {}) {
45
+ const record = (0, collaboration_1.recordHandoff)(run, {
46
+ target: (0, cli_options_1.collaborationTarget)(targetKind, targetId),
47
+ toActor: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "to", "toActor")),
48
+ toActorKind: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "toKind", "to-kind", "toActorKind")),
49
+ toRole: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "toRole", "to-role")),
50
+ toDisplayName: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "toName", "to-name", "toDisplayName")),
51
+ toAttested: Boolean((0, cli_options_1.firstDefined)(options, "toAttested", "to-attested")),
52
+ fromActor: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "from", "fromActor")),
53
+ fromActorKind: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "fromKind", "from-kind", "fromActorKind")),
54
+ fromRole: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "fromRole", "from-role")),
55
+ reason: (0, cli_options_1.stringOption)(options.reason) || (0, cli_options_1.stringOption)(options.message) || "handoff",
56
+ ...(0, cli_options_1.actorInputFrom)(options)
57
+ }, { persist: false });
58
+ (0, report_1.writeReport)(run);
59
+ (0, state_1.saveCheckpoint)(run);
60
+ return record;
61
+ }
62
+ function reviewStatus(run, options = {}) {
63
+ const now = typeof options.now === "string" && options.now ? options.now : new Date().toISOString();
64
+ const target = (0, cli_options_1.collaborationTargetMaybe)((0, cli_options_1.stringOption)(options.targetKind) || (0, cli_options_1.stringOption)(options.kind), (0, cli_options_1.stringOption)(options.target) || (0, cli_options_1.stringOption)(options.targetId));
65
+ return (0, collaboration_1.buildReviewStatusReport)(run, { now, target });
66
+ }
67
+ function reviewPolicy(run, options = {}) {
68
+ const allowSelf = (0, cli_options_1.firstDefined)(options, "allowSelfApproval", "allow-self-approval");
69
+ const requireAttested = (0, cli_options_1.firstDefined)(options, "requireAttestedActor", "require-attested-actor");
70
+ const policy = (0, collaboration_1.setReviewPolicy)(run, {
71
+ requiredApprovals: (0, cli_options_1.numberOption)((0, cli_options_1.firstDefined)(options, "requiredApprovals", "required-approvals", "required", "approvals")),
72
+ authorizedRoles: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "authorizedRoles", "authorized-roles", "roles")),
73
+ allowSelfApproval: allowSelf === undefined ? undefined : Boolean(allowSelf),
74
+ requireAttestedActor: requireAttested === undefined ? undefined : Boolean(requireAttested),
75
+ appliesTo: (0, cli_options_1.stringOption)((0, cli_options_1.firstDefined)(options, "appliesTo", "applies-to", "targets"))
76
+ }, { persist: false });
77
+ (0, report_1.writeReport)(run);
78
+ (0, state_1.saveCheckpoint)(run);
79
+ return { schemaVersion: 1, surface: "collaboration", runId: run.id, policy };
80
+ }
81
+ function formatReviewStatus(report) {
82
+ return (0, collaboration_1.formatReviewStatus)(report);
83
+ }
84
+ function formatCommentList(comments) {
85
+ return (0, collaboration_1.formatCommentList)(comments);
86
+ }