cool-workflow 0.1.83 → 0.1.84

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 (53) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/README.md +4 -0
  4. package/apps/architecture-review/app.json +1 -1
  5. package/apps/architecture-review-fast/app.json +1 -1
  6. package/apps/end-to-end-golden-path/app.json +1 -1
  7. package/apps/pr-review-fix-ci/app.json +1 -1
  8. package/apps/release-cut/app.json +1 -1
  9. package/apps/research-synthesis/app.json +1 -1
  10. package/dist/capability-registry.js +262 -0
  11. package/dist/cli/command-surface.js +1320 -0
  12. package/dist/cli.js +2 -1318
  13. package/dist/mcp-server.js +5 -1452
  14. package/dist/mcp-surface.js +1441 -0
  15. package/dist/version.js +1 -1
  16. package/dist/worker-accept/acceptance.js +114 -0
  17. package/dist/worker-accept/blackboard-fanout.js +80 -0
  18. package/dist/worker-accept/blackboard-linkage.js +19 -0
  19. package/dist/worker-accept/context.js +2 -0
  20. package/dist/worker-accept/telemetry-ledger.js +116 -0
  21. package/dist/worker-accept/validation.js +77 -0
  22. package/dist/worker-accept/verifier-completion.js +73 -0
  23. package/dist/worker-isolation.js +19 -444
  24. package/docs/agent-delegation-drive.7.md +4 -0
  25. package/docs/cli-mcp-parity.7.md +4 -0
  26. package/docs/contract-migration-tooling.7.md +4 -0
  27. package/docs/control-plane-scheduling.7.md +4 -0
  28. package/docs/durable-state-and-locking.7.md +4 -0
  29. package/docs/evidence-adoption-reasoning-chain.7.md +4 -0
  30. package/docs/execution-backends.7.md +4 -0
  31. package/docs/multi-agent-cli-mcp-surface.7.md +4 -0
  32. package/docs/multi-agent-eval-replay-harness.7.md +4 -0
  33. package/docs/multi-agent-operator-ux.7.md +4 -0
  34. package/docs/node-snapshot-diff-replay.7.md +4 -0
  35. package/docs/observability-cost-accounting.7.md +4 -0
  36. package/docs/project-index.md +11 -5
  37. package/docs/real-execution-backends.7.md +4 -0
  38. package/docs/release-and-migration.7.md +4 -0
  39. package/docs/release-tooling.7.md +14 -1
  40. package/docs/run-registry-control-plane.7.md +4 -0
  41. package/docs/run-retention-reclamation.7.md +4 -0
  42. package/docs/state-explosion-management.7.md +4 -0
  43. package/docs/team-collaboration.7.md +4 -0
  44. package/docs/web-desktop-workbench.7.md +4 -0
  45. package/manifest/plugin.manifest.json +1 -1
  46. package/package.json +1 -1
  47. package/scripts/bump-version.js +9 -1
  48. package/scripts/canonical-apps.js +4 -4
  49. package/scripts/dogfood-release.js +1 -1
  50. package/scripts/golden-path.js +4 -4
  51. package/scripts/parity-check.js +27 -57
  52. package/scripts/release-flow.js +7 -6
  53. package/scripts/sync-project-index.js +1 -1
package/dist/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MIN_SUPPORTED_RUN_STATE_SCHEMA_VERSION = exports.LEGACY_RUN_STATE_SCHEMA_VERSION = exports.CURRENT_RUN_STATE_SCHEMA_VERSION = exports.WORKFLOW_APP_SCHEMA_VERSION = exports.CURRENT_COOL_WORKFLOW_VERSION = void 0;
4
- exports.CURRENT_COOL_WORKFLOW_VERSION = "0.1.83";
4
+ exports.CURRENT_COOL_WORKFLOW_VERSION = "0.1.84";
5
5
  exports.WORKFLOW_APP_SCHEMA_VERSION = 1;
6
6
  exports.CURRENT_RUN_STATE_SCHEMA_VERSION = 1;
7
7
  exports.LEGACY_RUN_STATE_SCHEMA_VERSION = 0;
@@ -0,0 +1,114 @@
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.acceptWorkerResult = acceptWorkerResult;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const state_1 = require("../state");
10
+ const pipeline_contract_1 = require("../pipeline-contract");
11
+ const state_node_1 = require("../state-node");
12
+ const result_normalize_1 = require("../result-normalize");
13
+ const trust_audit_1 = require("../trust-audit");
14
+ /** Step 3 — recordStateNode/audit: the irreversible accept. Records the allowed
15
+ * path decision, copies the result into the run results dir, completes the task,
16
+ * builds + appends the result node, emits the accepted audit event, re-normalizes
17
+ * node evidence against both audit ids, and surfaces the empty-capture warning.
18
+ * Writes destination/pathAuditId/acceptedAuditId/resultNode back into `accept`. */
19
+ function acceptWorkerResult(accept, delegation) {
20
+ const { run, workerId, scope, task, absoluteResultPath, parsedResult } = accept;
21
+ const { agentDelegation } = delegation;
22
+ const pathAudit = (0, trust_audit_1.recordSandboxPathDecision)(run, {
23
+ workerId,
24
+ taskId: task.id,
25
+ sandboxProfileId: scope.sandboxProfileId,
26
+ policySnapshot: scope.sandboxPolicy,
27
+ target: absoluteResultPath,
28
+ decision: "allowed",
29
+ metadata: { operation: "worker-output-acceptance" }
30
+ });
31
+ const destination = node_path_1.default.join(run.paths.resultsDir, `${(0, state_1.safeFileName)(task.id)}.md`);
32
+ node_fs_1.default.mkdirSync(run.paths.resultsDir, { recursive: true });
33
+ node_fs_1.default.copyFileSync(absoluteResultPath, destination);
34
+ task.status = "completed";
35
+ task.completedAt = new Date().toISOString();
36
+ task.resultPath = destination;
37
+ task.loopStage = "observe";
38
+ task.result = parsedResult;
39
+ const evidence = (0, trust_audit_1.normalizeEvidence)(run, parsedResult.evidence.map((entry, index) => ({
40
+ id: `result:${index + 1}`,
41
+ source: "cw:result",
42
+ locator: entry,
43
+ summary: entry
44
+ })), { source: "cw-validated", workerId, taskId: task.id, auditEventIds: [pathAudit.id] });
45
+ const resultNode = (0, state_node_1.appendRunNode)(run, (0, state_node_1.createStateNode)({
46
+ id: `${run.id}:result:${task.id}`,
47
+ kind: "result",
48
+ status: "completed",
49
+ loopStage: "observe",
50
+ inputs: { taskId: task.id, dispatchId: task.dispatchId, workerId },
51
+ outputs: parsedResult,
52
+ artifacts: [
53
+ { id: "result", kind: "markdown", path: destination },
54
+ { id: "worker-result", kind: "markdown", path: absoluteResultPath }
55
+ ],
56
+ evidence,
57
+ parents: task.dispatchId ? [`${run.id}:dispatch:${task.dispatchId}`] : [task.stateNodeId || `${run.id}:task:${task.id}`],
58
+ contractId: pipeline_contract_1.DEFAULT_PIPELINE_CONTRACT_ID,
59
+ metadata: {
60
+ taskId: task.id,
61
+ workerId,
62
+ workerDir: scope.workerDir,
63
+ sandboxProfileId: scope.sandboxProfileId,
64
+ auditEventIds: [pathAudit.id],
65
+ // Empty-capture warning (v0.1.42): even after robust normalization the result
66
+ // yielded NO findings and NO evidence — surfaced, never silently passed.
67
+ ...((0, result_normalize_1.isEmptyCapture)(parsedResult) ? { captureWarning: "no findings or evidence captured from result.md" } : {}),
68
+ // Folded into the snapshotted node body so v0.1.35 replay re-verifies the
69
+ // prompt/result/model digests WITHOUT re-spawning the agent. NOT evidence.
70
+ ...(agentDelegation ? { agentDelegation } : {})
71
+ }
72
+ }));
73
+ const acceptedAudit = (0, trust_audit_1.recordTrustAuditEvent)(run, {
74
+ kind: "worker.output",
75
+ decision: "accepted",
76
+ source: "cw-validated",
77
+ workerId,
78
+ taskId: task.id,
79
+ nodeId: resultNode.id,
80
+ sandboxProfileId: scope.sandboxProfileId,
81
+ policySnapshot: scope.sandboxPolicy,
82
+ normalizedPath: absoluteResultPath,
83
+ evidence,
84
+ parentEventIds: [pathAudit.id],
85
+ metadata: { destination }
86
+ });
87
+ resultNode.evidence = (0, trust_audit_1.normalizeEvidence)(run, resultNode.evidence, {
88
+ source: "cw-validated",
89
+ workerId,
90
+ taskId: task.id,
91
+ resultNodeId: resultNode.id,
92
+ auditEventIds: [pathAudit.id, acceptedAudit.id]
93
+ });
94
+ (0, state_node_1.appendRunNode)(run, resultNode);
95
+ task.resultNodeId = resultNode.id;
96
+ // Warn (don't silently pass) when a worker's result captured no structured signal
97
+ // at all — the v0.1.41 self-audit's "accepted with evidenceCount:0" failure mode.
98
+ if ((0, result_normalize_1.isEmptyCapture)(parsedResult)) {
99
+ (0, trust_audit_1.recordTrustAuditEvent)(run, {
100
+ kind: "worker.capture-warning",
101
+ decision: "recorded",
102
+ source: "cw-validated",
103
+ workerId,
104
+ taskId: task.id,
105
+ nodeId: resultNode.id,
106
+ parentEventIds: [acceptedAudit.id],
107
+ metadata: { reason: "no findings or evidence captured from result.md", resultPath: destination }
108
+ });
109
+ }
110
+ accept.destination = destination;
111
+ accept.pathAuditId = pathAudit.id;
112
+ accept.acceptedAuditId = acceptedAudit.id;
113
+ accept.resultNode = resultNode;
114
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fanOutWorkerOutput = fanOutWorkerOutput;
4
+ const coordinator_1 = require("../coordinator");
5
+ const multi_agent_1 = require("../multi-agent");
6
+ const blackboard_linkage_1 = require("./blackboard-linkage");
7
+ /** Step 7 — fanOut: publish the accepted output to the blackboard and record the
8
+ * multi-agent worker output (linking the blackboard message/artifact refs). */
9
+ function fanOutWorkerOutput(accept) {
10
+ const { run, workerId, scope, task, absoluteResultPath, parsedResult, destination, resultNode, verifierNodeId, acceptedAuditId } = accept;
11
+ const blackboardLinks = publishWorkerOutputToBlackboard(run, scope, task, parsedResult.summary, destination, absoluteResultPath, resultNode.evidence, acceptedAuditId);
12
+ (0, multi_agent_1.recordMultiAgentWorkerOutput)(run, {
13
+ workerId,
14
+ taskId: task.id,
15
+ resultNodeId: resultNode.id,
16
+ verifierNodeId,
17
+ evidence: resultNode.evidence,
18
+ artifactPaths: [destination, absoluteResultPath],
19
+ blackboardMessageIds: blackboardLinks.messageIds,
20
+ blackboardArtifactRefIds: blackboardLinks.artifactRefIds
21
+ });
22
+ }
23
+ function publishWorkerOutputToBlackboard(run, scope, task, summary, destination, workerResultPath, evidence, acceptedAuditId) {
24
+ const linkage = (0, blackboard_linkage_1.blackboardLinkage)(run, scope);
25
+ if (!linkage.blackboardId || !linkage.topicIds.length)
26
+ return { messageIds: [], artifactRefIds: [] };
27
+ const topicId = linkage.topicIds[0];
28
+ const artifactRefs = [
29
+ (0, coordinator_1.addBlackboardArtifact)(run, {
30
+ topicId,
31
+ blackboardId: linkage.blackboardId,
32
+ kind: "worker-result",
33
+ path: destination,
34
+ owner: { kind: "worker", id: scope.id },
35
+ author: { kind: "runtime", id: "cw" },
36
+ source: "cw-validated-worker-output",
37
+ provenance: {
38
+ workerId: scope.id,
39
+ taskId: task.id,
40
+ multiAgentRunId: scope.multiAgent?.runId,
41
+ agentGroupId: scope.multiAgent?.groupId,
42
+ agentRoleId: scope.multiAgent?.roleId,
43
+ agentMembershipId: scope.multiAgent?.membershipId,
44
+ auditEventIds: [acceptedAuditId]
45
+ },
46
+ evidenceRefs: evidence.map((entry) => entry.locator || entry.path || entry.summary || entry.id).filter(Boolean),
47
+ auditEventIds: [acceptedAuditId],
48
+ metadata: { workerResultPath }
49
+ })
50
+ ];
51
+ const message = (0, coordinator_1.postBlackboardMessage)(run, {
52
+ topicId,
53
+ blackboardId: linkage.blackboardId,
54
+ body: summary,
55
+ author: { kind: "worker", id: scope.id },
56
+ scope: { kind: "worker", id: scope.id },
57
+ artifactRefIds: artifactRefs.map((artifact) => artifact.id),
58
+ evidenceRefs: evidence.map((entry) => entry.locator || entry.path || entry.summary || entry.id).filter(Boolean),
59
+ auditEventIds: [acceptedAuditId],
60
+ links: {
61
+ multiAgentRunId: scope.multiAgent?.runId,
62
+ agentGroupId: scope.multiAgent?.groupId,
63
+ agentRoleId: scope.multiAgent?.roleId,
64
+ agentMembershipId: scope.multiAgent?.membershipId,
65
+ agentFanoutId: scope.multiAgent?.fanoutId,
66
+ taskId: task.id,
67
+ workerId: scope.id,
68
+ auditEventIds: [acceptedAuditId]
69
+ },
70
+ metadata: {
71
+ taskId: task.id,
72
+ resultPath: destination,
73
+ multiAgent: scope.multiAgent
74
+ }
75
+ });
76
+ return {
77
+ messageIds: [message.id],
78
+ artifactRefIds: artifactRefs.map((artifact) => artifact.id)
79
+ };
80
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blackboardLinkage = blackboardLinkage;
4
+ const helpers_1 = require("../worker-isolation/helpers");
5
+ function blackboardLinkage(run, scope) {
6
+ const membershipId = scope.multiAgent?.membershipId;
7
+ const membership = membershipId ? run.multiAgent?.memberships.find((entry) => entry.id === membershipId) : undefined;
8
+ const group = scope.multiAgent?.groupId ? run.multiAgent?.groups.find((entry) => entry.id === scope.multiAgent?.groupId) : undefined;
9
+ const role = scope.multiAgent?.roleId ? run.multiAgent?.roles.find((entry) => entry.id === scope.multiAgent?.roleId) : undefined;
10
+ const multiAgentRun = scope.multiAgent?.runId ? run.multiAgent?.runs.find((entry) => entry.id === scope.multiAgent?.runId) : undefined;
11
+ const blackboardId = membership?.blackboardId || group?.blackboardId || role?.blackboardId || multiAgentRun?.blackboardId;
12
+ const topicIds = (0, helpers_1.unique)([
13
+ ...(membership?.topicIds || []),
14
+ ...(group?.topicIds || []),
15
+ ...(role?.topicIds || []),
16
+ ...(multiAgentRun?.topicIds || [])
17
+ ]);
18
+ return { blackboardId, topicIds };
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attestWorkerDelegation = attestWorkerDelegation;
4
+ exports.recordWorkerDelegationLedger = recordWorkerDelegationLedger;
5
+ const execution_backend_1 = require("../execution-backend");
6
+ const telemetry_attestation_1 = require("../telemetry-attestation");
7
+ const telemetry_ledger_1 = require("../telemetry-ledger");
8
+ const trust_audit_1 = require("../trust-audit");
9
+ const helpers_1 = require("../worker-isolation/helpers");
10
+ /** Step 2 — attestSandbox/attestDelegation: verify the agent's signed telemetry
11
+ * BEFORE recording it, enforce the opt-in require-attested-telemetry gate (still
12
+ * fail-closed, pre-mutation), and build the agent-hop provenance. Non-agent hops
13
+ * return an empty delegation. */
14
+ function attestWorkerDelegation(accept, deps) {
15
+ const { run, workerId, options, task, absoluteResultPath, rawResult } = accept;
16
+ // Agent Delegation Drive (v0.1.38): if this worker's result.md was produced by an
17
+ // EXTERNAL agent, record the agent-hop attestation AS PROVENANCE — the agent
18
+ // (kind:process) handle, the agent-REPORTED model (never CW_AGENT_MODEL), the
19
+ // prompt digest, the secret-stripped args, and the result digest computed HERE
20
+ // from the accepted result.md. These live in the result node's metadata (covered
21
+ // by the v0.1.35 snapshot body) + a trust-audit event, NEVER in `evidence`.
22
+ // Track 1: verify the agent's signed telemetry BEFORE recording it. CW holds
23
+ // only the operator's PUBLIC key — it verifies attribution, never measures
24
+ // usage. Absent/invalid signature => `unattested`/`absent`, surfaced loudly,
25
+ // NEVER silently recorded as trusted.
26
+ const telemetry = options.agentDelegation
27
+ ? (0, telemetry_attestation_1.verifyTelemetryAttestation)(options.agentDelegation.reportedUsage, options.agentDelegation.usageSignature, (0, telemetry_attestation_1.resolveTrustPublicKey)(options.agentDelegation.usageTrustPublicKey), { runId: run.id, taskId: task.id, promptDigest: options.agentDelegation.promptDigest })
28
+ : undefined;
29
+ // Track 1 fail-closed (Decision 2 — OPT-IN, off by default). When the operator
30
+ // requires attested telemetry, a delegated hop whose verdict is not `attested`
31
+ // is REJECTED here — BEFORE any accept-side state mutation — so the drive parks
32
+ // it instead of recording unverifiable usage. Default behavior is unchanged
33
+ // (flag-and-surface). Non-agent hops carry no verdict and are never blocked.
34
+ if (options.requireAttestedTelemetry && telemetry && telemetry.status !== "attested") {
35
+ const error = (0, helpers_1.structuredError)("telemetry-unattested-blocked", `Worker ${workerId} telemetry is ${telemetry.status} (${telemetry.reason || "unverified"}) and require-attested-telemetry is enabled — refusing to accept a hop whose usage cannot be cryptographically verified`, { path: absoluteResultPath, retryable: false });
36
+ deps.recordWorkerFailure(run, workerId, error, { ...options, persist: options.persist });
37
+ throw new Error(error.message);
38
+ }
39
+ const agentDelegation = options.agentDelegation
40
+ ? {
41
+ schemaVersion: 1,
42
+ backendId: "agent",
43
+ handle: options.agentDelegation.handle,
44
+ model: options.agentDelegation.model,
45
+ promptDigest: options.agentDelegation.promptDigest,
46
+ resultDigest: (0, execution_backend_1.sha256)(rawResult),
47
+ command: options.agentDelegation.command,
48
+ args: options.agentDelegation.args,
49
+ exitCode: options.agentDelegation.exitCode,
50
+ ...(options.agentDelegation.reportedUsage ? { reportedUsage: options.agentDelegation.reportedUsage } : {}),
51
+ ...(options.agentDelegation.usageSignature ? { usageSignature: options.agentDelegation.usageSignature } : {}),
52
+ ...(telemetry ? { usageAttestation: telemetry.status, usageAttestationReason: telemetry.reason } : {})
53
+ }
54
+ : undefined;
55
+ return { agentDelegation, telemetry };
56
+ }
57
+ /** Step 4 — recordTelemetryLedger: the agent-hop attestation. Binds the telemetry
58
+ * verdict into the append-only hash-chained ledger BEFORE the audit event (so the
59
+ * event can cross-link the record hash), then emits the worker.agent-delegation
60
+ * audit event. No-op for non-agent hops. */
61
+ function recordWorkerDelegationLedger(accept, delegation) {
62
+ const { agentDelegation } = delegation;
63
+ // The agent-hop attestation event — hung off worker.output, alongside
64
+ // worker.backend. Recorded in trust-audit/provenance, NEVER in node evidence.
65
+ if (!agentDelegation)
66
+ return;
67
+ const { run, workerId, scope, task, resultNode, acceptedAuditId } = accept;
68
+ // Track 1 (tamper-evidence): bind this verdict into the append-only,
69
+ // hash-chained telemetry ledger BEFORE the audit event, so the event can
70
+ // cross-link the record hash. Editing the recorded verdict/usage later breaks
71
+ // the chain (verifyTelemetryLedger). Only when a verdict was computed.
72
+ const ledgerRecord = agentDelegation.usageAttestation
73
+ ? (0, telemetry_ledger_1.appendTelemetryAttestation)(run, {
74
+ workerId,
75
+ taskId: task.id,
76
+ promptDigest: agentDelegation.promptDigest,
77
+ reportedUsage: agentDelegation.reportedUsage,
78
+ usageSignature: agentDelegation.usageSignature,
79
+ attestation: agentDelegation.usageAttestation,
80
+ attestationReason: agentDelegation.usageAttestationReason
81
+ })
82
+ : undefined;
83
+ (0, trust_audit_1.recordTrustAuditEvent)(run, {
84
+ kind: "worker.agent-delegation",
85
+ decision: "recorded",
86
+ source: "host-attested",
87
+ workerId,
88
+ taskId: task.id,
89
+ nodeId: resultNode.id,
90
+ sandboxProfileId: scope.sandboxProfileId,
91
+ policySnapshot: scope.sandboxPolicy,
92
+ parentEventIds: [acceptedAuditId],
93
+ metadata: {
94
+ backendId: agentDelegation.backendId,
95
+ handleKind: agentDelegation.handle.kind,
96
+ handleRef: agentDelegation.handle.ref,
97
+ model: agentDelegation.model,
98
+ promptDigest: agentDelegation.promptDigest,
99
+ resultDigest: agentDelegation.resultDigest,
100
+ command: agentDelegation.command,
101
+ args: agentDelegation.args,
102
+ exitCode: agentDelegation.exitCode,
103
+ // Track 1: the telemetry verdict travels with the agent-hop event so the
104
+ // audit report can surface `unattested` usage loudly. Absent => no usage.
105
+ ...(agentDelegation.usageAttestation
106
+ ? {
107
+ telemetryAttestation: agentDelegation.usageAttestation,
108
+ ...(agentDelegation.usageAttestationReason ? { telemetryAttestationReason: agentDelegation.usageAttestationReason } : {}),
109
+ ...(agentDelegation.reportedUsage ? { reportedUsage: agentDelegation.reportedUsage } : {}),
110
+ // Cross-link to the hash-chained ledger entry (tamper-evidence).
111
+ ...(ledgerRecord ? { telemetryRecordId: ledgerRecord.recordId, telemetryRecordHash: ledgerRecord.recordHash, telemetryPrevHash: ledgerRecord.prevHash } : {})
112
+ }
113
+ : {})
114
+ }
115
+ });
116
+ }
@@ -0,0 +1,77 @@
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.validateWorkerResult = validateWorkerResult;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const verifier_1 = require("../verifier");
10
+ const evidence_grounding_1 = require("../evidence-grounding");
11
+ const trust_audit_1 = require("../trust-audit");
12
+ const helpers_1 = require("../worker-isolation/helpers");
13
+ /** Step 1 — validateResult: resolve scope/task, enforce the sandbox boundary, the
14
+ * result-file existence, the envelope contract, and (opt-in) resolvable evidence.
15
+ * Fail-closed: any guard records a worker failure and throws BEFORE accept-side
16
+ * state mutation. Returns the partially-filled accept context on success. */
17
+ function validateWorkerResult(run, workerId, resultPath, options, deps) {
18
+ const scope = deps.requireWorkerScope(run, workerId);
19
+ const task = deps.requireWorkerTask(run, scope);
20
+ const absoluteResultPath = node_path_1.default.resolve(resultPath);
21
+ const violation = deps.validateWorkerBoundary(run, workerId, { ...options, policy: options.policy, path: absoluteResultPath });
22
+ if (violation) {
23
+ (0, trust_audit_1.recordSandboxPathDecision)(run, {
24
+ workerId,
25
+ taskId: task.id,
26
+ sandboxProfileId: scope.sandboxProfileId,
27
+ policySnapshot: scope.sandboxPolicy,
28
+ target: absoluteResultPath,
29
+ decision: "denied",
30
+ metadata: { code: violation.code, allowedPaths: violation.allowedPaths }
31
+ });
32
+ deps.recordWorkerFailure(run, workerId, violation, { ...options, path: absoluteResultPath, code: violation.code, retryable: false });
33
+ throw new Error(violation.message);
34
+ }
35
+ if (!node_fs_1.default.existsSync(absoluteResultPath)) {
36
+ const error = (0, helpers_1.structuredError)("worker-result-missing", `Worker result file does not exist: ${absoluteResultPath}`, {
37
+ path: absoluteResultPath,
38
+ retryable: true
39
+ });
40
+ deps.recordWorkerFailure(run, workerId, error, { ...options, persist: options.persist });
41
+ throw new Error(error.message);
42
+ }
43
+ const rawResult = node_fs_1.default.readFileSync(absoluteResultPath, "utf8");
44
+ const parsedResult = (0, verifier_1.parseResultEnvelope)(rawResult);
45
+ (0, verifier_1.validateResultEnvelope)(task, parsedResult);
46
+ // Strict evidence resolution (v0.1.40 self-audit P1, opt-in via
47
+ // CW_REQUIRE_RESOLVABLE_EVIDENCE): fail closed if the result cites file-style
48
+ // evidence that does not resolve on disk, so a worker cannot land a result
49
+ // whose evidence locators point nowhere. Off by default — the default gate is
50
+ // the deterministic grounding check in validateResultEnvelope.
51
+ if ((0, evidence_grounding_1.requireResolvableEvidence)()) {
52
+ const baseDirs = Array.from(new Set([run.cwd, process.cwd(), scope.workerDir, run.paths.runDir].filter(Boolean)));
53
+ const unresolved = (0, evidence_grounding_1.unresolvedFileEvidence)(parsedResult.evidence, baseDirs);
54
+ if (unresolved.length) {
55
+ const error = (0, helpers_1.structuredError)("worker-evidence-unresolvable", `Worker ${workerId} result cites file evidence that does not resolve on disk: ${unresolved.join(", ")}`, { path: absoluteResultPath, retryable: false });
56
+ deps.recordWorkerFailure(run, workerId, error, { ...options, persist: options.persist });
57
+ throw new Error(error.message);
58
+ }
59
+ }
60
+ return {
61
+ run,
62
+ workerId,
63
+ options,
64
+ scope,
65
+ task,
66
+ absoluteResultPath,
67
+ rawResult,
68
+ parsedResult,
69
+ destination: "",
70
+ pathAuditId: "",
71
+ acceptedAuditId: "",
72
+ resultNode: undefined,
73
+ verifierNodeId: "",
74
+ verifierStatus: "",
75
+ output: undefined
76
+ };
77
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWorkerVerify = runWorkerVerify;
4
+ exports.recordWorkerCompletion = recordWorkerCompletion;
5
+ const pipeline_runner_1 = require("../pipeline-runner");
6
+ const telemetry_attestation_1 = require("../telemetry-attestation");
7
+ const execution_backend_1 = require("../execution-backend");
8
+ /** Step 5 — runVerify: drive the verify pipeline stage off the accepted result node
9
+ * and record the verifier node id on the task + accept context. */
10
+ function runWorkerVerify(accept) {
11
+ const { run, workerId, scope, task, parsedResult, destination, resultNode } = accept;
12
+ const verifierResult = (0, pipeline_runner_1.createPipelineRunner)({ persist: false }).runPipelineStage(run, "verify", resultNode.id, {
13
+ outputNodeId: `${run.id}:verifier:${task.id}`,
14
+ outputStatus: "verified",
15
+ loopStage: "adjust",
16
+ outputs: { accepted: true, workerId },
17
+ artifacts: [{ id: "result", kind: "markdown", path: destination }],
18
+ evidence: resultNode.evidence.length
19
+ ? resultNode.evidence
20
+ : [{ id: "result:summary", source: "summary", summary: parsedResult.summary }],
21
+ metadata: { taskId: task.id, workerId, resultNodeId: resultNode.id, sandboxProfileId: scope.sandboxProfileId }
22
+ });
23
+ task.verifierNodeId = verifierResult.outputNodeId;
24
+ accept.verifierNodeId = verifierResult.outputNodeId;
25
+ // Carry the verify verdict for the scope-status transition in recordWorkerCompletion.
26
+ accept.verifierStatus = verifierResult.status;
27
+ }
28
+ /** Step 6 — recordStateNode (worker record): assemble the worker output record +
29
+ * host-attested usage record, then persist the worker scope with the verify-derived
30
+ * status, output digest/size, and (when present) usage. */
31
+ function recordWorkerCompletion(accept, delegation, deps) {
32
+ const { run, workerId, scope, task, absoluteResultPath, rawResult, resultNode, verifierNodeId, verifierStatus, pathAuditId, acceptedAuditId } = accept;
33
+ const { agentDelegation, telemetry } = delegation;
34
+ const output = {
35
+ workerId,
36
+ taskId: task.id,
37
+ resultPath: absoluteResultPath,
38
+ recordedAt: new Date().toISOString(),
39
+ stateNodeId: resultNode.id,
40
+ verifierNodeId,
41
+ auditEventIds: [pathAuditId, acceptedAuditId]
42
+ };
43
+ // Host-attested usage rides on the worker record. Recorded when the agent
44
+ // REPORTED a model OR token usage — `unreported`/absent stays ABSENT (never
45
+ // backfilled from the operator-chosen CW_AGENT_MODEL, never synthesized).
46
+ // Track 1: the attestation verdict (`attested`/`unattested`/`absent`) and its
47
+ // reason ride along, and the token buckets come from the (verified-or-not)
48
+ // reported usage — CW still never measures them, it records + labels them.
49
+ const reportedModel = agentDelegation && agentDelegation.model && agentDelegation.model !== "unreported" ? agentDelegation.model : undefined;
50
+ const usageRecord = agentDelegation && (reportedModel || agentDelegation.reportedUsage)
51
+ ? {
52
+ schemaVersion: 1,
53
+ source: "host-attested",
54
+ ...(reportedModel ? { model: reportedModel } : {}),
55
+ ...(0, telemetry_attestation_1.normalizeReportedUsage)(agentDelegation.reportedUsage),
56
+ attestedAt: new Date().toISOString(),
57
+ ...(telemetry ? { attestation: telemetry.status, ...(telemetry.reason ? { attestationReason: telemetry.reason } : {}) } : {}),
58
+ note: "agent-delegation host-attested usage"
59
+ }
60
+ : undefined;
61
+ deps.updateWorkerScope(run, {
62
+ ...scope,
63
+ updatedAt: new Date().toISOString(),
64
+ status: verifierStatus === "advanced" ? "verified" : "completed",
65
+ resultNodeId: resultNode.id,
66
+ output,
67
+ // Output integrity (v0.1.63): SHA256 digest + file size
68
+ outputDigest: (0, execution_backend_1.sha256)(rawResult),
69
+ outputSizeBytes: Buffer.byteLength(rawResult, "utf8"),
70
+ ...(usageRecord ? { usage: usageRecord } : {})
71
+ });
72
+ accept.output = output;
73
+ }