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,366 @@
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.policyForRole = policyForRole;
7
+ exports.policyForGroup = policyForGroup;
8
+ exports.policyForMembership = policyForMembership;
9
+ exports.recordRolePolicyAudit = recordRolePolicyAudit;
10
+ exports.authorizeMultiAgentAction = authorizeMultiAgentAction;
11
+ exports.assertMultiAgentActionAllowed = assertMultiAgentActionAllowed;
12
+ exports.recordBlackboardWriteAudit = recordBlackboardWriteAudit;
13
+ exports.recordMessageProvenanceAudit = recordMessageProvenanceAudit;
14
+ exports.recordJudgeRationaleAudit = recordJudgeRationaleAudit;
15
+ exports.summarizeMultiAgentTrust = summarizeMultiAgentTrust;
16
+ exports.hasAcceptedJudgeRationale = hasAcceptedJudgeRationale;
17
+ exports.sourceForActor = sourceForActor;
18
+ exports.hashText = hashText;
19
+ const node_crypto_1 = __importDefault(require("node:crypto"));
20
+ const trust_audit_1 = require("./trust-audit");
21
+ function policyForRole(role) {
22
+ const topologyRole = String(role.metadata?.topologyRoleId || role.title || "").toLowerCase();
23
+ const isChair = topologyRole.includes("chair") || topologyRole.includes("reducer") || topologyRole.includes("synthesizer");
24
+ const isJudge = topologyRole.includes("judge");
25
+ return {
26
+ schemaVersion: 1,
27
+ id: `${role.id}-policy`,
28
+ policyRef: `multiAgent.roles.${role.id}.policy`,
29
+ subjectKind: "role",
30
+ subjectId: role.id,
31
+ allowedBlackboardTopicIds: unique(role.topicIds || ["*"]),
32
+ allowedWriteOperations: unique([
33
+ "message",
34
+ "context",
35
+ "artifact",
36
+ ...(isChair ? ["snapshot", "coordinator-decision"] : [])
37
+ ]),
38
+ allowedCandidateOperations: isChair ? ["score", "select"] : ["score"],
39
+ allowedJudgeOperations: unique([
40
+ ...(isJudge ? ["verdict", "rationale"] : []),
41
+ ...(isChair ? ["rationale", "panel-decision"] : [])
42
+ ]),
43
+ sandboxProfileHints: unique(role.sandboxProfileHints || []),
44
+ requiredEvidenceRefs: unique(role.requiredEvidence || []),
45
+ requiredEvidenceFor: {
46
+ "judge.rationale": ["judge rationale evidence"],
47
+ "judge.verdict": ["judge verdict evidence"],
48
+ "judge.panel-decision": ["judge messages", "score evidence", "coordinator decision"],
49
+ "candidate.select": ["score evidence", "judge rationale"]
50
+ },
51
+ deniedOperations: [],
52
+ metadata: { title: role.title, topologyRoleId: role.metadata?.topologyRoleId }
53
+ };
54
+ }
55
+ function policyForGroup(group) {
56
+ return {
57
+ schemaVersion: 1,
58
+ id: `${group.id}-policy`,
59
+ policyRef: `multiAgent.groups.${group.id}.policy`,
60
+ subjectKind: "group",
61
+ subjectId: group.id,
62
+ allowedBlackboardTopicIds: unique(group.topicIds || ["*"]),
63
+ allowedWriteOperations: ["message", "context", "artifact", "snapshot", "coordinator-decision"],
64
+ allowedCandidateOperations: ["register", "score", "select"],
65
+ allowedJudgeOperations: ["verdict", "rationale", "panel-decision"],
66
+ sandboxProfileHints: [],
67
+ requiredEvidenceRefs: [],
68
+ deniedOperations: [],
69
+ metadata: { phase: group.phase }
70
+ };
71
+ }
72
+ function policyForMembership(membership, role) {
73
+ const source = role?.policy || (role ? policyForRole(role) : undefined);
74
+ return {
75
+ ...(source || {
76
+ schemaVersion: 1,
77
+ id: `${membership.id}-policy`,
78
+ policyRef: `multiAgent.memberships.${membership.id}.policy`,
79
+ subjectKind: "membership",
80
+ subjectId: membership.id,
81
+ allowedBlackboardTopicIds: unique(membership.topicIds || ["*"]),
82
+ allowedWriteOperations: ["message", "context", "artifact"],
83
+ allowedCandidateOperations: [],
84
+ allowedJudgeOperations: [],
85
+ sandboxProfileHints: [],
86
+ requiredEvidenceRefs: [],
87
+ deniedOperations: []
88
+ }),
89
+ id: `${membership.id}-policy`,
90
+ policyRef: `multiAgent.memberships.${membership.id}.policy`,
91
+ subjectKind: "membership",
92
+ subjectId: membership.id
93
+ };
94
+ }
95
+ function recordRolePolicyAudit(run, role) {
96
+ return (0, trust_audit_1.recordTrustAuditEvent)(run, {
97
+ kind: "multi-agent.role-policy",
98
+ decision: "recorded",
99
+ source: "runtime-derived",
100
+ multiAgentRunId: role.multiAgentRunId,
101
+ agentRoleId: role.id,
102
+ blackboardId: role.blackboardId,
103
+ policyRef: role.policy?.policyRef,
104
+ metadata: role.policy
105
+ });
106
+ }
107
+ function authorizeMultiAgentAction(run, input) {
108
+ const roleId = input.agentRoleId || (input.actor?.kind === "role" ? input.actor.id : undefined);
109
+ const membershipId = input.agentMembershipId || (input.actor?.kind === "membership" ? input.actor.id : undefined);
110
+ const groupId = input.agentGroupId || (input.actor?.kind === "group" ? input.actor.id : undefined);
111
+ const policy = resolvePolicy(run, { roleId, membershipId, groupId });
112
+ const reason = evaluatePolicy(policy, input.operation, input.blackboardTopicId, input.evidenceRefs || []);
113
+ const allowed = !reason;
114
+ const metadata = {
115
+ operation: input.operation,
116
+ reason: reason || "allowed by explicit multi-agent policy",
117
+ policyRef: policy?.policyRef,
118
+ ...(input.metadata || {})
119
+ };
120
+ const event = (0, trust_audit_1.recordTrustAuditEvent)(run, {
121
+ kind: "multi-agent.permission",
122
+ decision: allowed ? "allowed" : "denied",
123
+ source: "cw-validated",
124
+ actor: input.actor?.id,
125
+ multiAgentRunId: input.multiAgentRunId || policyRunId(run, roleId, groupId, membershipId),
126
+ agentRoleId: roleId,
127
+ agentGroupId: groupId,
128
+ agentMembershipId: membershipId,
129
+ agentFanoutId: input.agentFanoutId,
130
+ agentFaninId: input.agentFaninId,
131
+ blackboardId: input.blackboardId,
132
+ blackboardTopicId: input.blackboardTopicId,
133
+ blackboardMessageId: input.blackboardMessageId,
134
+ blackboardContextId: input.blackboardContextId,
135
+ blackboardArtifactRefId: input.blackboardArtifactRefId,
136
+ blackboardSnapshotId: input.blackboardSnapshotId,
137
+ coordinatorDecisionId: input.coordinatorDecisionId,
138
+ candidateId: input.candidateId,
139
+ scoreId: input.scoreId,
140
+ selectionId: input.selectionId,
141
+ commitId: input.commitId,
142
+ sandboxProfileId: input.sandboxProfileId,
143
+ evidence: input.evidence,
144
+ evidenceRefs: input.evidenceRefs,
145
+ policyRef: policy?.policyRef,
146
+ metadata
147
+ });
148
+ if (!allowed) {
149
+ (0, trust_audit_1.recordTrustAuditEvent)(run, {
150
+ kind: "policy.violation",
151
+ decision: "denied",
152
+ source: "cw-validated",
153
+ actor: input.actor?.id,
154
+ multiAgentRunId: input.multiAgentRunId || policyRunId(run, roleId, groupId, membershipId),
155
+ agentRoleId: roleId,
156
+ agentGroupId: groupId,
157
+ agentMembershipId: membershipId,
158
+ blackboardId: input.blackboardId,
159
+ blackboardTopicId: input.blackboardTopicId,
160
+ candidateId: input.candidateId,
161
+ selectionId: input.selectionId,
162
+ evidenceRefs: input.evidenceRefs,
163
+ parentEventIds: [event.id],
164
+ policyRef: policy?.policyRef,
165
+ metadata
166
+ });
167
+ }
168
+ return {
169
+ allowed,
170
+ decision: allowed ? "allowed" : "denied",
171
+ reason: reason || "allowed by explicit multi-agent policy",
172
+ policyRef: policy?.policyRef,
173
+ policy,
174
+ missingEvidenceRefs: missingEvidence(policy, input.operation, input.evidenceRefs || []),
175
+ event
176
+ };
177
+ }
178
+ function assertMultiAgentActionAllowed(run, input) {
179
+ const decision = authorizeMultiAgentAction(run, input);
180
+ if (!decision.allowed)
181
+ throw new Error(decision.reason);
182
+ return decision;
183
+ }
184
+ function recordBlackboardWriteAudit(run, input) {
185
+ return (0, trust_audit_1.recordTrustAuditEvent)(run, {
186
+ kind: "blackboard.write",
187
+ decision: input.status === "denied" || input.status === "blocked" ? "denied" : input.status === "conflicting" ? "failed" : "accepted",
188
+ source: sourceForActor(input.actor),
189
+ actor: input.actor?.id,
190
+ multiAgentRunId: input.multiAgentRunId,
191
+ agentRoleId: input.agentRoleId,
192
+ agentGroupId: input.agentGroupId,
193
+ agentMembershipId: input.agentMembershipId,
194
+ agentFanoutId: input.agentFanoutId,
195
+ agentFaninId: input.agentFaninId,
196
+ blackboardId: input.blackboardId,
197
+ blackboardTopicId: input.blackboardTopicId,
198
+ blackboardMessageId: input.blackboardMessageId,
199
+ blackboardContextId: input.blackboardContextId,
200
+ blackboardArtifactRefId: input.blackboardArtifactRefId,
201
+ blackboardSnapshotId: input.blackboardSnapshotId,
202
+ coordinatorDecisionId: input.coordinatorDecisionId,
203
+ evidenceRefs: input.evidenceRefs,
204
+ parentEventIds: input.parentEventIds,
205
+ policyRef: input.policyRef,
206
+ metadata: { operation: input.operation, status: input.status, ...(input.metadata || {}) }
207
+ });
208
+ }
209
+ function recordMessageProvenanceAudit(run, input) {
210
+ return (0, trust_audit_1.recordTrustAuditEvent)(run, {
211
+ kind: "blackboard.message-provenance",
212
+ decision: "recorded",
213
+ source: sourceForActor(input.actor),
214
+ actor: input.actor?.id,
215
+ workerId: input.workerId,
216
+ multiAgentRunId: input.multiAgentRunId,
217
+ agentRoleId: input.agentRoleId,
218
+ agentGroupId: input.agentGroupId,
219
+ agentMembershipId: input.agentMembershipId,
220
+ blackboardId: input.blackboardId,
221
+ blackboardTopicId: input.topicId,
222
+ blackboardMessageId: input.messageId,
223
+ evidenceRefs: input.evidenceRefs,
224
+ parentEventIds: input.parentEventIds,
225
+ policyRef: input.policyRef,
226
+ metadata: {
227
+ authorKind: input.actor?.kind,
228
+ bodyHash: hashText(input.body),
229
+ summary: input.body.trim().slice(0, 120),
230
+ parentMessageIds: input.parentMessageIds || [],
231
+ topicScope: input.topicId,
232
+ locator: `${input.blackboardId}/messages/${input.messageId}`
233
+ }
234
+ });
235
+ }
236
+ function recordJudgeRationaleAudit(run, input) {
237
+ return (0, trust_audit_1.recordTrustAuditEvent)(run, {
238
+ kind: input.kind || "judge.rationale",
239
+ decision: input.evidenceRefs?.length && input.rationale ? "accepted" : "denied",
240
+ source: "cw-validated",
241
+ actor: input.actor?.id,
242
+ multiAgentRunId: input.multiAgentRunId,
243
+ agentRoleId: input.agentRoleId,
244
+ agentGroupId: input.agentGroupId,
245
+ agentMembershipId: input.agentMembershipId,
246
+ blackboardId: input.blackboardId,
247
+ blackboardTopicId: input.blackboardTopicId,
248
+ blackboardMessageId: input.blackboardMessageId,
249
+ coordinatorDecisionId: input.coordinatorDecisionId,
250
+ candidateId: input.candidateId,
251
+ scoreId: input.scoreId,
252
+ selectionId: input.selectionId,
253
+ evidenceRefs: input.evidenceRefs,
254
+ parentEventIds: input.parentEventIds,
255
+ policyRef: input.policyRef,
256
+ metadata: { rationale: input.rationale?.slice(0, 240) }
257
+ });
258
+ }
259
+ function summarizeMultiAgentTrust(run) {
260
+ const events = (0, trust_audit_1.listTrustAuditEvents)(run);
261
+ const rolePolicies = (run.multiAgent?.roles || []).map((role) => role.policy || policyForRole(role));
262
+ const byKind = (kind) => events.filter((event) => event.kind === kind);
263
+ const policyViolations = byKind("policy.violation");
264
+ return {
265
+ schemaVersion: 1,
266
+ runId: run.id,
267
+ rolePolicies,
268
+ permissionDecisions: byKind("multi-agent.permission"),
269
+ blackboardWrites: byKind("blackboard.write"),
270
+ messageProvenance: byKind("blackboard.message-provenance"),
271
+ judgeRationales: byKind("judge.rationale"),
272
+ panelDecisions: byKind("judge.panel-decision"),
273
+ policyViolations,
274
+ nextAction: policyViolations.length
275
+ ? `node scripts/cw.js audit policy ${run.id}`
276
+ : `node scripts/cw.js audit multi-agent ${run.id} --json`
277
+ };
278
+ }
279
+ function hasAcceptedJudgeRationale(run, input = {}) {
280
+ return (0, trust_audit_1.listTrustAuditEvents)(run).some((event) => event.kind === "judge.rationale" &&
281
+ event.decision === "accepted" &&
282
+ (!input.multiAgentRunId || event.multiAgentRunId === input.multiAgentRunId) &&
283
+ (!input.candidateId || event.candidateId === input.candidateId) &&
284
+ (!input.scoreId || !event.scoreId || event.scoreId === input.scoreId));
285
+ }
286
+ function sourceForActor(actor) {
287
+ if (!actor)
288
+ return "operator-recorded";
289
+ if (actor.kind === "worker")
290
+ return "host-attested";
291
+ if (actor.kind === "operator")
292
+ return "operator-recorded";
293
+ if (actor.kind === "runtime" || actor.kind === "coordinator" || actor.kind === "verifier")
294
+ return "runtime-derived";
295
+ return "cw-validated";
296
+ }
297
+ function hashText(value) {
298
+ return `sha256:${node_crypto_1.default.createHash("sha256").update(value).digest("hex")}`;
299
+ }
300
+ function resolvePolicy(run, input) {
301
+ const membership = input.membershipId ? run.multiAgent?.memberships.find((entry) => entry.id === input.membershipId) : undefined;
302
+ if (membership?.policy)
303
+ return membership.policy;
304
+ const roleId = input.roleId || membership?.roleId;
305
+ const role = roleId ? run.multiAgent?.roles.find((entry) => entry.id === roleId) : undefined;
306
+ if (role?.policy)
307
+ return role.policy;
308
+ if (role)
309
+ return policyForRole(role);
310
+ const group = input.groupId ? run.multiAgent?.groups.find((entry) => entry.id === input.groupId) : undefined;
311
+ if (group?.policy)
312
+ return group.policy;
313
+ if (group)
314
+ return policyForGroup(group);
315
+ return undefined;
316
+ }
317
+ function evaluatePolicy(policy, operation, topicId, evidenceRefs) {
318
+ if (!policy)
319
+ return "missing role authority or policy";
320
+ const denied = policy.deniedOperations.find((entry) => entry.operation === operation);
321
+ if (denied)
322
+ return denied.reason;
323
+ if (topicId && policy.allowedBlackboardTopicIds.length && !policy.allowedBlackboardTopicIds.includes("*") && !policy.allowedBlackboardTopicIds.includes(topicId)) {
324
+ return `topic ${topicId} is outside policy ${policy.policyRef}`;
325
+ }
326
+ if (operation.startsWith("candidate.")) {
327
+ const op = operation.slice("candidate.".length);
328
+ if (!policy.allowedCandidateOperations.includes(op))
329
+ return `candidate operation ${op} is outside policy ${policy.policyRef}`;
330
+ }
331
+ else if (operation.startsWith("judge.")) {
332
+ const op = operation.slice("judge.".length);
333
+ if (!policy.allowedJudgeOperations.includes(op))
334
+ return `judge operation ${op} is outside policy ${policy.policyRef}`;
335
+ }
336
+ else if (!policy.allowedWriteOperations.includes(operation)) {
337
+ return `blackboard write operation ${operation} is outside policy ${policy.policyRef}`;
338
+ }
339
+ const missing = missingEvidence(policy, operation, evidenceRefs);
340
+ if (missing.length)
341
+ return `operation ${operation} requires evidence refs: ${missing.join(", ")}`;
342
+ return undefined;
343
+ }
344
+ function missingEvidence(policy, operation, evidenceRefs) {
345
+ if (!policy)
346
+ return [];
347
+ const required = unique([...(policy.requiredEvidenceFor?.[operation] || [])]);
348
+ if (!required.length)
349
+ return [];
350
+ if (evidenceRefs.length)
351
+ return [];
352
+ return required;
353
+ }
354
+ function policyRunId(run, roleId, groupId, membershipId) {
355
+ const membership = membershipId ? run.multiAgent?.memberships.find((entry) => entry.id === membershipId) : undefined;
356
+ if (membership)
357
+ return membership.multiAgentRunId;
358
+ const role = roleId ? run.multiAgent?.roles.find((entry) => entry.id === roleId) : undefined;
359
+ if (role)
360
+ return role.multiAgentRunId;
361
+ const group = groupId ? run.multiAgent?.groups.find((entry) => entry.id === groupId) : undefined;
362
+ return group?.multiAgentRunId;
363
+ }
364
+ function unique(values) {
365
+ return Array.from(new Set(values.filter(Boolean)));
366
+ }