@caupulican/pi-adaptative 0.81.41 → 0.81.42
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.
- package/CHANGELOG.md +16 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
- package/dist/core/agent-paths.d.ts +32 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +65 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +19 -1
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +2 -0
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +4 -9
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +17 -4
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts +14 -0
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js +37 -6
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +27 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +84 -41
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-claim.js +4 -3
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-action-journal.d.ts +73 -0
- package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
- package/dist/core/delegation/worker-action-journal.js +297 -0
- package/dist/core/delegation/worker-action-journal.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +36 -1
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +171 -46
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-agent-control.d.ts +66 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control.js +163 -0
- package/dist/core/delegation/worker-agent-control.js.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.js +343 -0
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
- package/dist/core/delegation/worker-claim.d.ts +30 -0
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +205 -53
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-store.js +442 -0
- package/dist/core/delegation/worker-conversation-store.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +386 -251
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +5 -7
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +120 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-process-owner.d.ts +18 -0
- package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
- package/dist/core/delegation/worker-process-owner.js +54 -0
- package/dist/core/delegation/worker-process-owner.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.js +116 -0
- package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.js +137 -0
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +3 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +189 -54
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
- package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
- package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
- package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation.js +348 -0
- package/dist/core/delegation/worker-write-reservation.js.map +1 -0
- package/dist/core/models/model-endpoint.d.ts +3 -0
- package/dist/core/models/model-endpoint.d.ts.map +1 -0
- package/dist/core/models/model-endpoint.js +11 -0
- package/dist/core/models/model-endpoint.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +2 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
- package/dist/core/orchestration/agent-resume.js +7 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -1
- package/dist/core/orchestration/attempt-usage.d.ts +28 -0
- package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-usage.js +168 -0
- package/dist/core/orchestration/attempt-usage.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +128 -28
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +35 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +17 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +78 -3
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +1 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +78 -38
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +81 -41
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/profile-store.d.ts.map +1 -1
- package/dist/core/orchestration/profile-store.js +18 -4
- package/dist/core/orchestration/profile-store.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +2 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +26 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +13 -1
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +127 -16
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +75 -23
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.js +167 -14
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +90 -54
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts +20 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +173 -69
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +7 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +15 -1
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-artifact-bundle.d.ts +35 -0
- package/dist/core/session-artifact-bundle.d.ts.map +1 -0
- package/dist/core/session-artifact-bundle.js +61 -0
- package/dist/core/session-artifact-bundle.js.map +1 -0
- package/dist/core/tools/delegate-status.d.ts +6 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +100 -18
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +9 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +323 -61
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +1 -1
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +69 -9
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +12 -5
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts +15 -0
- package/dist/core/util/bounded-file.d.ts.map +1 -0
- package/dist/core/util/bounded-file.js +120 -0
- package/dist/core/util/bounded-file.js.map +1 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
- package/dist/core/util/bounded-jsonl.js +119 -9
- package/dist/core/util/bounded-jsonl.js.map +1 -1
- package/dist/core/util/bounded-value.d.ts +3 -0
- package/dist/core/util/bounded-value.d.ts.map +1 -0
- package/dist/core/util/bounded-value.js +12 -0
- package/dist/core/util/bounded-value.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +2 -0
- package/dist/core/util/value-guards.d.ts.map +1 -1
- package/dist/core/util/value-guards.js +5 -0
- package/dist/core/util/value-guards.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +27 -44
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/docs/tool-repair.md +3 -0
- package/docs/windows.md +4 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runBoundedCompletion } from "../autonomy/bounded-completion.js";
|
|
2
2
|
import { createEvidenceBundle } from "../research/evidence-bundle.js";
|
|
3
|
-
import { parseWorkerActions } from "./worker-actions.js";
|
|
4
|
-
import { validateWorkerClaim } from "./worker-claim.js";
|
|
3
|
+
import { parseWorkerActions, } from "./worker-actions.js";
|
|
4
|
+
import { collectBoundedWorkerClaimBlockers, collectBoundedWorkerClaimChangedFiles, MAX_WORKER_CLAIM_BLOCKER_CHARS, MAX_WORKER_CLAIM_BLOCKERS, MAX_WORKER_CLAIM_SUMMARY_CHARS, normalizeWorkerClaimForHost, validateWorkerClaim, } from "./worker-claim.js";
|
|
5
5
|
/**
|
|
6
6
|
* Pure execution for one bounded specialist delegation: bounded isolated completion ->
|
|
7
7
|
* parse -> untrusted `WorkerClaim` -> parent validation via {@link validateWorkerClaim}.
|
|
@@ -66,67 +66,116 @@ export function buildWorkerUserPrompt(request) {
|
|
|
66
66
|
'Always return the JSON object required by the system prompt; put requested details inside "summary" and "findings".',
|
|
67
67
|
].join("\n");
|
|
68
68
|
}
|
|
69
|
+
const MAX_WORKER_OUTPUT_CHARS = 512 * 1024;
|
|
70
|
+
const MAX_WORKER_JSON_CANDIDATES = 64;
|
|
71
|
+
const MAX_WORKER_JSON_DEPTH = 256;
|
|
72
|
+
const MAX_WORKER_FINDINGS = 64;
|
|
73
|
+
const MAX_WORKER_FINDING_CHARS = 2_000;
|
|
74
|
+
const MAX_WORKER_REASON_CODES = 32;
|
|
75
|
+
const MAX_WORKER_REASON_CODE_CHARS = 128;
|
|
69
76
|
function balancedObjectCandidates(text) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
const ranges = [];
|
|
78
|
+
const starts = [];
|
|
79
|
+
let inString = false;
|
|
80
|
+
let escaped = false;
|
|
81
|
+
for (let index = 0; index < text.length; index++) {
|
|
82
|
+
const character = text[index];
|
|
83
|
+
if (inString) {
|
|
84
|
+
if (escaped)
|
|
85
|
+
escaped = false;
|
|
86
|
+
else if (character === "\\")
|
|
87
|
+
escaped = true;
|
|
88
|
+
else if (character === '"')
|
|
89
|
+
inString = false;
|
|
73
90
|
continue;
|
|
74
|
-
let depth = 0;
|
|
75
|
-
let inString = false;
|
|
76
|
-
let escaped = false;
|
|
77
|
-
for (let index = start; index < text.length; index++) {
|
|
78
|
-
const character = text[index];
|
|
79
|
-
if (inString) {
|
|
80
|
-
if (escaped)
|
|
81
|
-
escaped = false;
|
|
82
|
-
else if (character === "\\")
|
|
83
|
-
escaped = true;
|
|
84
|
-
else if (character === '"')
|
|
85
|
-
inString = false;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (character === '"') {
|
|
89
|
-
inString = true;
|
|
90
|
-
}
|
|
91
|
-
else if (character === "{") {
|
|
92
|
-
depth++;
|
|
93
|
-
}
|
|
94
|
-
else if (character === "}" && --depth === 0) {
|
|
95
|
-
candidates.push(text.slice(start, index + 1));
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
91
|
}
|
|
92
|
+
if (character === '"') {
|
|
93
|
+
inString = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (character === "{") {
|
|
97
|
+
if (starts.length >= MAX_WORKER_JSON_DEPTH)
|
|
98
|
+
return ranges.map(({ start, end }) => text.slice(start, end));
|
|
99
|
+
starts.push(index);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (character !== "}")
|
|
103
|
+
continue;
|
|
104
|
+
const start = starts.pop();
|
|
105
|
+
if (start === undefined || ranges.length >= MAX_WORKER_JSON_CANDIDATES)
|
|
106
|
+
continue;
|
|
107
|
+
const end = index + 1;
|
|
108
|
+
if (end - start <= MAX_WORKER_OUTPUT_CHARS)
|
|
109
|
+
ranges.push({ start, end });
|
|
99
110
|
}
|
|
100
|
-
return
|
|
111
|
+
return ranges.map(({ start, end }) => text.slice(start, end));
|
|
101
112
|
}
|
|
102
|
-
|
|
113
|
+
function workerOutputRecords(text) {
|
|
103
114
|
const trimmed = text.trim();
|
|
115
|
+
if (trimmed.length === 0 || trimmed.length > MAX_WORKER_OUTPUT_CHARS)
|
|
116
|
+
return [];
|
|
104
117
|
const candidates = [trimmed];
|
|
105
118
|
const fenced = /```(?:json)?\s*([\s\S]*?)```/.exec(trimmed);
|
|
106
119
|
if (fenced?.[1])
|
|
107
120
|
candidates.push(fenced[1].trim());
|
|
108
121
|
candidates.push(...balancedObjectCandidates(trimmed));
|
|
122
|
+
const records = [];
|
|
109
123
|
for (const candidate of candidates) {
|
|
110
|
-
let parsed;
|
|
111
124
|
try {
|
|
112
|
-
parsed = JSON.parse(candidate);
|
|
125
|
+
const parsed = JSON.parse(candidate);
|
|
126
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
127
|
+
records.push(parsed);
|
|
113
128
|
}
|
|
114
129
|
catch {
|
|
115
|
-
|
|
130
|
+
// Candidate extraction is deliberately best-effort; a later balanced candidate may still be valid.
|
|
116
131
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
132
|
+
}
|
|
133
|
+
return records;
|
|
134
|
+
}
|
|
135
|
+
function isWorkerStatus(value) {
|
|
136
|
+
return value === "completed" || value === "blocked";
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Plain-text fallback is for output that never attempted the worker claim envelope. A JSON object
|
|
140
|
+
* with a claim summary but malformed typed fields is a contract failure, never an implicit success.
|
|
141
|
+
*/
|
|
142
|
+
function hasMalformedWorkerClaimEnvelope(text) {
|
|
143
|
+
return workerOutputRecords(text).some((record) => {
|
|
144
|
+
if (typeof record.summary !== "string" || record.summary.trim().length === 0)
|
|
145
|
+
return false;
|
|
146
|
+
if (!isWorkerStatus(record.status))
|
|
147
|
+
return true;
|
|
148
|
+
if (record.verdict !== undefined && record.verdict !== "accepted" && record.verdict !== "rejected")
|
|
149
|
+
return true;
|
|
150
|
+
return (record.reasonCodes !== undefined &&
|
|
151
|
+
(!Array.isArray(record.reasonCodes) ||
|
|
152
|
+
record.reasonCodes.some((reasonCode) => typeof reasonCode !== "string" || reasonCode.trim().length === 0)));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
export function parseWorkerOutput(text) {
|
|
156
|
+
for (const record of workerOutputRecords(text)) {
|
|
120
157
|
const summary = record.summary;
|
|
121
158
|
if (typeof summary !== "string" || summary.trim().length === 0)
|
|
122
159
|
continue;
|
|
123
|
-
|
|
160
|
+
if (!isWorkerStatus(record.status))
|
|
161
|
+
continue;
|
|
162
|
+
if (record.verdict !== undefined && record.verdict !== "accepted" && record.verdict !== "rejected")
|
|
163
|
+
continue;
|
|
164
|
+
if (record.reasonCodes !== undefined &&
|
|
165
|
+
(!Array.isArray(record.reasonCodes) ||
|
|
166
|
+
record.reasonCodes.some((reasonCode) => typeof reasonCode !== "string" || reasonCode.trim().length === 0))) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const status = record.status;
|
|
124
170
|
const blockers = Array.isArray(record.blockers)
|
|
125
|
-
? record.blockers
|
|
171
|
+
? record.blockers
|
|
172
|
+
.filter((blocker) => typeof blocker === "string" && blocker.trim().length > 0)
|
|
173
|
+
.slice(0, MAX_WORKER_CLAIM_BLOCKERS)
|
|
174
|
+
.map((blocker) => blocker.trim().slice(0, MAX_WORKER_CLAIM_BLOCKER_CHARS))
|
|
126
175
|
: [];
|
|
127
176
|
const findings = [];
|
|
128
177
|
if (Array.isArray(record.findings)) {
|
|
129
|
-
for (const item of record.findings) {
|
|
178
|
+
for (const item of record.findings.slice(0, MAX_WORKER_FINDINGS)) {
|
|
130
179
|
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
131
180
|
continue;
|
|
132
181
|
const findingSummary = item.summary;
|
|
@@ -136,19 +185,24 @@ export function parseWorkerOutput(text) {
|
|
|
136
185
|
const confidence = typeof confidenceRaw === "number" && Number.isFinite(confidenceRaw)
|
|
137
186
|
? Math.min(Math.max(confidenceRaw, 0), 1)
|
|
138
187
|
: undefined;
|
|
139
|
-
findings.push({ summary: findingSummary.trim(), confidence });
|
|
188
|
+
findings.push({ summary: findingSummary.trim().slice(0, MAX_WORKER_FINDING_CHARS), confidence });
|
|
140
189
|
}
|
|
141
190
|
}
|
|
142
191
|
const verdict = record.verdict === "accepted" || record.verdict === "rejected" ? record.verdict : undefined;
|
|
143
192
|
const reasonCodes = Array.isArray(record.reasonCodes)
|
|
144
|
-
? record.reasonCodes
|
|
193
|
+
? record.reasonCodes
|
|
194
|
+
.filter((reasonCode) => typeof reasonCode === "string" && reasonCode.trim().length > 0)
|
|
195
|
+
.slice(0, MAX_WORKER_REASON_CODES)
|
|
196
|
+
.map((reasonCode) => reasonCode.trim().slice(0, MAX_WORKER_REASON_CODE_CHARS))
|
|
145
197
|
: [];
|
|
198
|
+
const actionOutcome = parseWorkerActions(record.actions);
|
|
146
199
|
return {
|
|
147
|
-
summary: summary.trim(),
|
|
200
|
+
summary: summary.trim().slice(0, MAX_WORKER_CLAIM_SUMMARY_CHARS),
|
|
148
201
|
status,
|
|
149
202
|
blockers,
|
|
150
203
|
findings,
|
|
151
|
-
actions:
|
|
204
|
+
actions: actionOutcome.kind === "accepted" ? actionOutcome.actions : [],
|
|
205
|
+
...(actionOutcome.kind === "rejected" ? { actionRejection: actionOutcome } : {}),
|
|
152
206
|
...(verdict ? { verdict } : {}),
|
|
153
207
|
reasonCodes,
|
|
154
208
|
};
|
|
@@ -184,9 +238,10 @@ function buildWorkerEvidence(request, findings) {
|
|
|
184
238
|
});
|
|
185
239
|
}
|
|
186
240
|
function finishOutcome(args) {
|
|
187
|
-
const
|
|
241
|
+
const claim = normalizeWorkerClaimForHost(args.claim);
|
|
242
|
+
const acceptance = validateWorkerClaim({ request: args.request, claim, cwd: args.cwd });
|
|
188
243
|
return {
|
|
189
|
-
claim
|
|
244
|
+
claim,
|
|
190
245
|
acceptance,
|
|
191
246
|
accepted: acceptance.outcome === "allow",
|
|
192
247
|
laneStatus: args.laneStatus,
|
|
@@ -216,9 +271,13 @@ export async function runWorker(options) {
|
|
|
216
271
|
}),
|
|
217
272
|
});
|
|
218
273
|
const costUsd = bounded.completion?.costUsd ?? 0;
|
|
219
|
-
const
|
|
274
|
+
const liveChangedFilesReport = collectBoundedWorkerClaimChangedFiles(options.getChangedFiles?.() ?? []);
|
|
275
|
+
const liveChangedFiles = liveChangedFilesReport.values;
|
|
220
276
|
if (bounded.failure) {
|
|
221
277
|
const cancelled = bounded.failure.status === "canceled" || bounded.failure.status === "timeout";
|
|
278
|
+
const blockers = liveChangedFilesReport.overflowed
|
|
279
|
+
? ["worker changed-file report exceeded the durable claim bound; parent review is required"]
|
|
280
|
+
: undefined;
|
|
222
281
|
return finishOutcome({
|
|
223
282
|
request: options.request,
|
|
224
283
|
cwd: options.cwd,
|
|
@@ -227,6 +286,7 @@ export async function runWorker(options) {
|
|
|
227
286
|
changedFiles: liveChangedFiles,
|
|
228
287
|
status: cancelled ? "cancelled" : "failed",
|
|
229
288
|
summary: `Worker did not complete: ${bounded.failure.reasonCode}`,
|
|
289
|
+
...(blockers ? { blockers } : {}),
|
|
230
290
|
},
|
|
231
291
|
laneStatus: bounded.failure.status,
|
|
232
292
|
reasonCode: bounded.failure.reasonCode,
|
|
@@ -234,7 +294,15 @@ export async function runWorker(options) {
|
|
|
234
294
|
});
|
|
235
295
|
}
|
|
236
296
|
const completion = bounded.completion;
|
|
237
|
-
const
|
|
297
|
+
const completionChangedFilesReport = collectBoundedWorkerClaimChangedFiles(completion?.changedFiles ?? []);
|
|
298
|
+
const mergedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([
|
|
299
|
+
...liveChangedFiles,
|
|
300
|
+
...completionChangedFilesReport.values,
|
|
301
|
+
]);
|
|
302
|
+
const changedFilesOverflowed = liveChangedFilesReport.overflowed ||
|
|
303
|
+
completionChangedFilesReport.overflowed ||
|
|
304
|
+
mergedChangedFilesReport.overflowed;
|
|
305
|
+
const completionChangedFiles = mergedChangedFilesReport.values;
|
|
238
306
|
const completionBaseClaim = { ...baseClaim, changedFiles: completionChangedFiles };
|
|
239
307
|
if (!completion || completion.stopReason === "error" || completion.stopReason === "aborted") {
|
|
240
308
|
return finishOutcome({
|
|
@@ -248,16 +316,37 @@ export async function runWorker(options) {
|
|
|
248
316
|
}
|
|
249
317
|
const parsed = parseWorkerOutput(completion.text);
|
|
250
318
|
if (!parsed) {
|
|
319
|
+
if (hasMalformedWorkerClaimEnvelope(completion.text)) {
|
|
320
|
+
return finishOutcome({
|
|
321
|
+
request: options.request,
|
|
322
|
+
cwd: options.cwd,
|
|
323
|
+
claim: {
|
|
324
|
+
...completionBaseClaim,
|
|
325
|
+
status: "failed",
|
|
326
|
+
summary: "Worker output used a malformed structured claim envelope.",
|
|
327
|
+
},
|
|
328
|
+
laneStatus: "failed",
|
|
329
|
+
reasonCode: "unparseable_output",
|
|
330
|
+
costUsd,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
251
333
|
const readOnlyPlainText = !options.verificationSubjectTaskId &&
|
|
252
334
|
!writeCapable &&
|
|
253
335
|
completion.text.trim().length > 0 &&
|
|
254
|
-
completionChangedFiles.length === 0
|
|
336
|
+
completionChangedFiles.length === 0 &&
|
|
337
|
+
!changedFilesOverflowed;
|
|
255
338
|
if (readOnlyPlainText) {
|
|
256
|
-
const
|
|
339
|
+
const completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);
|
|
340
|
+
const completionBlockers = completionBlockersReport.overflowed
|
|
341
|
+
? [
|
|
342
|
+
...completionBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),
|
|
343
|
+
"worker blocker report exceeded the durable claim bound; parent review is required",
|
|
344
|
+
]
|
|
345
|
+
: completionBlockersReport.values;
|
|
257
346
|
const incompleteNote = completion.stopReason === "stop"
|
|
258
347
|
? ""
|
|
259
348
|
: `\n\n[Worker output ended with stop reason '${completion.stopReason}'; verify completeness.]`;
|
|
260
|
-
const summary = `${completion.text.trim().slice(0, Math.max(0,
|
|
349
|
+
const summary = `${completion.text.trim().slice(0, Math.max(0, MAX_WORKER_CLAIM_SUMMARY_CHARS - incompleteNote.length))}${incompleteNote}`;
|
|
261
350
|
const blocked = completionBlockers.length > 0;
|
|
262
351
|
return finishOutcome({
|
|
263
352
|
request: options.request,
|
|
@@ -285,6 +374,13 @@ export async function runWorker(options) {
|
|
|
285
374
|
...completionBaseClaim,
|
|
286
375
|
status: "failed",
|
|
287
376
|
summary: "Worker output was not valid structured JSON.",
|
|
377
|
+
...(changedFilesOverflowed
|
|
378
|
+
? {
|
|
379
|
+
blockers: [
|
|
380
|
+
"worker changed-file report exceeded the durable claim bound; parent review is required",
|
|
381
|
+
],
|
|
382
|
+
}
|
|
383
|
+
: {}),
|
|
288
384
|
},
|
|
289
385
|
laneStatus: "failed",
|
|
290
386
|
reasonCode: "unparseable_output",
|
|
@@ -292,6 +388,21 @@ export async function runWorker(options) {
|
|
|
292
388
|
});
|
|
293
389
|
}
|
|
294
390
|
const evidence = buildWorkerEvidence(options.request, parsed.findings);
|
|
391
|
+
if (parsed.actionRejection) {
|
|
392
|
+
return finishOutcome({
|
|
393
|
+
request: options.request,
|
|
394
|
+
cwd: options.cwd,
|
|
395
|
+
claim: {
|
|
396
|
+
...completionBaseClaim,
|
|
397
|
+
status: "failed",
|
|
398
|
+
summary: "Worker output contained invalid structured actions.",
|
|
399
|
+
blockers: [parsed.actionRejection.reasonCode],
|
|
400
|
+
},
|
|
401
|
+
laneStatus: "failed",
|
|
402
|
+
reasonCode: "unparseable_output",
|
|
403
|
+
costUsd,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
295
406
|
if (options.verificationSubjectTaskId && (!parsed.verdict || parsed.reasonCodes.length === 0)) {
|
|
296
407
|
return finishOutcome({
|
|
297
408
|
request: options.request,
|
|
@@ -307,7 +418,14 @@ export async function runWorker(options) {
|
|
|
307
418
|
});
|
|
308
419
|
}
|
|
309
420
|
let changedFiles = [...completionChangedFiles];
|
|
310
|
-
const
|
|
421
|
+
const completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);
|
|
422
|
+
const actionBlockers = [...completionBlockersReport.values];
|
|
423
|
+
if (changedFilesOverflowed) {
|
|
424
|
+
actionBlockers.push("worker changed-file report exceeded the durable claim bound; parent review is required");
|
|
425
|
+
}
|
|
426
|
+
if (completionBlockersReport.overflowed) {
|
|
427
|
+
actionBlockers.push("worker blocker report exceeded the durable claim bound; parent review is required");
|
|
428
|
+
}
|
|
311
429
|
if (!writeCapable && completionChangedFiles.length > 0) {
|
|
312
430
|
actionBlockers.push("worker reported file changes without a filesystem.write envelope grant");
|
|
313
431
|
}
|
|
@@ -315,18 +433,35 @@ export async function runWorker(options) {
|
|
|
315
433
|
// Runner-side application through the envelope path scope: refusals and failures are
|
|
316
434
|
// surfaced as blockers so a partially-applied change can never look like clean success.
|
|
317
435
|
const applied = options.applyActions(parsed.actions);
|
|
318
|
-
|
|
436
|
+
const appliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles(applied.changedFiles);
|
|
437
|
+
const mergedAppliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([
|
|
438
|
+
...changedFiles,
|
|
439
|
+
...appliedChangedFilesReport.values,
|
|
440
|
+
]);
|
|
441
|
+
changedFiles = mergedAppliedChangedFilesReport.values;
|
|
442
|
+
if (appliedChangedFilesReport.overflowed || mergedAppliedChangedFilesReport.overflowed) {
|
|
443
|
+
actionBlockers.push("applied changed-file report exceeded the durable claim bound; parent review is required");
|
|
444
|
+
}
|
|
319
445
|
for (const refusal of applied.refused) {
|
|
320
446
|
actionBlockers.push(`action refused (${refusal.path}): ${refusal.reason}`);
|
|
321
447
|
}
|
|
322
448
|
for (const failure of applied.failed) {
|
|
323
449
|
actionBlockers.push(`action failed (${failure.path}): ${failure.reason}`);
|
|
324
450
|
}
|
|
451
|
+
for (const inspection of applied.inspectionRequired) {
|
|
452
|
+
actionBlockers.push(`action requires workspace/evidence inspection (${inspection.path}, ${inspection.state}): ${inspection.reasonCode}`);
|
|
453
|
+
}
|
|
325
454
|
}
|
|
326
455
|
else if (!writeCapable && parsed.actions.length > 0) {
|
|
327
456
|
actionBlockers.push("worker emitted file actions without a filesystem.write envelope grant; nothing was applied");
|
|
328
457
|
}
|
|
329
|
-
const
|
|
458
|
+
const allBlockersReport = collectBoundedWorkerClaimBlockers([...parsed.blockers, ...actionBlockers]);
|
|
459
|
+
const allBlockers = allBlockersReport.overflowed
|
|
460
|
+
? [
|
|
461
|
+
...allBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),
|
|
462
|
+
"worker blocker report exceeded the durable claim bound; parent review is required",
|
|
463
|
+
]
|
|
464
|
+
: allBlockersReport.values;
|
|
330
465
|
const claim = {
|
|
331
466
|
...baseClaim,
|
|
332
467
|
changedFiles,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-runner.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAA6B,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;GAOG;AAEH,kGAAkG;AAClG,MAAM,UAAU,uBAAuB,CAAC,YAAkD,EAAU;IACnG,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK;QACrC,CAAC,CAAC,0SAA0S;QAC5S,CAAC,CAAC,uLAAuL,CAAC;IAC3L,OAAO;QACN,2EAA2E;QAC3E,oFAAoF;QACpF,GAAG,CAAC,YAAY,CAAC,KAAK;YACrB,CAAC,CAAC,CAAC,oGAAoG,CAAC;YACxG,CAAC,CAAC,CAAC,+DAA+D,CAAC,CAAC;QACrE,GAAG,CAAC,YAAY,CAAC,OAAO;YACvB,CAAC,CAAC;gBACA,oJAAoJ;gBACpJ,iGAAiG;aACjG;YACF,CAAC,CAAC,EAAE,CAAC;QACN,+DAA+D;QAC/D,WAAW;QACX,GAAG,CAAC,YAAY,CAAC,KAAK;YACrB,CAAC,CAAC;gBACA,+BAA+B;gBAC/B,gHAAgH;aAChH;YACF,CAAC,CAAC,EAAE,CAAC;QACN,sGAAsG;QACtG,0DAA0D;KAC1D,CAAC,IAAI,CAAC,IA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AC,kBAAkB,CAAC,CAAC,CAAC,WAAW;QACzD,UAAU,EAAE,UAAU;YACrB,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,KAAK,CAAC,YAAY;gBACnB,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,KAAK,UAAU;oBAC1C,CAAC,CAAC,uBAAuB;oBACzB,CAAC,CAAC,uBAAuB;gBAC1B,CAAC,CAAC,kBAAkB;QACtB,OAAO;KACP,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { EvidenceRef, Finding, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport { createEvidenceBundle } from \"../research/evidence-bundle.ts\";\nimport { type AppliedActionsReport, parseWorkerActions, type WorkerAction } from \"./worker-actions.ts\";\nimport { validateWorkerClaim } from \"./worker-claim.ts\";\n\n/**\n * Pure execution for one bounded specialist delegation: bounded isolated completion ->\n * parse -> untrusted `WorkerClaim` -> parent validation via {@link validateWorkerClaim}.\n *\n * The injected completion may be a bounded child tool loop. Its tool surface is built and gated by\n * the host; this module keeps the structured-output contract and treats every claim as untrusted\n * until parent validation succeeds.\n */\n\n/** Builds one capability-exact prompt; no role text may deny a tool already granted by policy. */\nexport function buildWorkerSystemPrompt(capabilities: { write: boolean; process: boolean }): string {\n\tconst resultShape = capabilities.write\n\t\t? '{\"summary\":\"<what you did>\",\"status\":\"completed\"|\"blocked\",\"blockers\":[],\"findings\":[{\"summary\":\"<finding>\",\"confidence\":<0..1>}],\"actions\":[{\"op\":\"write\",\"path\":\"<relative path>\",\"content\":\"<full file content>\"},{\"op\":\"edit\",\"path\":\"<relative path>\",\"old\":\"<exact text>\",\"new\":\"<replacement>\"}]}'\n\t\t: '{\"summary\":\"<what you concluded>\",\"status\":\"completed\"|\"blocked\",\"blockers\":[\"<failure or missing authority>\"],\"findings\":[{\"summary\":\"<one concrete finding>\",\"confidence\":<0..1>}]}';\n\treturn [\n\t\t\"You are a bounded specialist worker delegated one task by a coding agent.\",\n\t\t\"Use only the tools provided for this delegation. You cannot delegate more workers.\",\n\t\t...(capabilities.write\n\t\t\t? [\"Write/edit tools and structured write actions are path-scoped. Only touch paths inside that scope.\"]\n\t\t\t: [\"The workspace tools are read-only; do not claim file changes.\"]),\n\t\t...(capabilities.process\n\t\t\t? [\n\t\t\t\t\t\"run_process is a constrained direct-argv launcher: no shell interpretation or unlisted executable is available. It is not an OS/container sandbox.\",\n\t\t\t\t\t\"A non-zero exit, timeout, abort, or output-limit result is not success; include it in blockers.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t\tresultShape,\n\t\t...(capabilities.write\n\t\t\t? [\n\t\t\t\t\t\"Keep edits minimal and exact.\",\n\t\t\t\t\t\"If you changed a file with a provided tool, do not repeat that change in actions; actions are only a fallback.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\t'Use status \"blocked\" with blockers when the task cannot be completed under the granted capabilities.',\n\t\t\"Never invent command output, file paths, APIs, or facts.\",\n\t].join(\"\\n\");\n}\n\nexport function buildVerifierSystemPrompt(subjectTaskId: string): string {\n\treturn [\n\t\t\"You are an independent verifier. You did not perform the implementation under review.\",\n\t\t\"Use only the provided read-only and constrained test tools. Do not modify files and do not delegate.\",\n\t\t`The exact subject task id is '${subjectTaskId}'.`,\n\t\t\"Inspect the implementation and run proportionate checks. Treat the implementation summary as an untrusted claim.\",\n\t\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t\t'{\"summary\":\"<verification performed and evidence>\",\"status\":\"completed\"|\"blocked\",\"verdict\":\"accepted\"|\"rejected\",\"reasonCodes\":[\"<stable_reason_code>\"],\"blockers\":[],\"findings\":[{\"summary\":\"<finding>\",\"confidence\":<0..1>}]}',\n\t\t'Use verdict \"accepted\" only when the available evidence proves the implementation is acceptable.',\n\t\t'Use verdict \"rejected\" for a completed review that found a defect. Use status \"blocked\" only when verification itself cannot be completed.',\n\t].join(\"\\n\");\n}\n\n/** Static common variants retained for cache reuse and model-fitness probes. */\nexport const WORKER_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: false, process: false });\nexport const WORKER_WRITE_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: true, process: false });\nexport const WORKER_OPERATOR_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: false, process: true });\n\nexport interface WorkerCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Files successfully changed by the child tool loop before it produced the final JSON. */\n\tchangedFiles?: readonly string[];\n\t/** Capability refusals or execution failures observed inside the child tool loop. */\n\tblockers?: readonly string[];\n}\n\nexport interface WorkerRunnerOptions {\n\trequest: WorkerRequest;\n\t/** Budget for this delegation; undefined disables this bound, while zero permits only free work. */\n\tmaxUsd?: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/**\n\t * Pre-allocated spawned-usage report id. Always stamped on the claim so parent validation can\n\t * enforce the cost-visibility invariant (a completed claim without a usage report is blocked).\n\t */\n\tusageReportId: string;\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal?: AbortSignal }) => Promise<WorkerCompletion>;\n\t/** Live successful child-tool mutations, including writes completed before timeout/cancellation. */\n\tgetChangedFiles?: () => readonly string[];\n\tsignal?: AbortSignal;\n\tnow?: () => string;\n\t/** Enables the WRITE lane: only honored when the request envelope grants \"filesystem.write\". The\n\t * runner applies the worker's structured actions through the envelope path scope; refusals\n\t * and failures become blockers, never silent drops. */\n\tapplyActions?: (actions: readonly WorkerAction[]) => AppliedActionsReport;\n\t/** Enables the constrained direct-argv operator role prompt. */\n\tprocessCapable?: boolean;\n\t/** Session cwd — the baseline for relative changed-file and envelope paths in parent\n\t * validation. Defaults to process.cwd(). */\n\tcwd?: string;\n\t/** Turns the child into a read-only semantic verifier for this exact durable task. */\n\tverificationSubjectTaskId?: string;\n}\n\nexport interface WorkerRunOutcome {\n\tclaim: WorkerClaim;\n\t/** Parent-review verdict from {@link validateWorkerClaim}; worker output stays untrusted. */\n\tacceptance: GateOutcome;\n\taccepted: boolean;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\tcostUsd: number;\n}\n\nexport function buildWorkerUserPrompt(request: WorkerRequest): string {\n\treturn [\n\t\t\"Delegated task:\",\n\t\t\"<task>\",\n\t\trequest.instructions,\n\t\t\"</task>\",\n\t\t\"\",\n\t\t\"The task may request a custom output format. Do not replace the worker claim envelope.\",\n\t\t'Always return the JSON object required by the system prompt; put requested details inside \"summary\" and \"findings\".',\n\t].join(\"\\n\");\n}\n\nexport interface ParsedWorkerOutput {\n\tsummary: string;\n\tstatus: \"completed\" | \"blocked\";\n\tblockers: string[];\n\tfindings: Array<{ summary: string; confidence?: number }>;\n\tactions: WorkerAction[];\n\tverdict?: \"accepted\" | \"rejected\";\n\treasonCodes: string[];\n}\n\nfunction balancedObjectCandidates(text: string): string[] {\n\tconst candidates: string[] = [];\n\tfor (let start = 0; start < text.length; start++) {\n\t\tif (text[start] !== \"{\") continue;\n\t\tlet depth = 0;\n\t\tlet inString = false;\n\t\tlet escaped = false;\n\t\tfor (let index = start; index < text.length; index++) {\n\t\t\tconst character = text[index];\n\t\t\tif (inString) {\n\t\t\t\tif (escaped) escaped = false;\n\t\t\t\telse if (character === \"\\\\\") escaped = true;\n\t\t\t\telse if (character === '\"') inString = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (character === '\"') {\n\t\t\t\tinString = true;\n\t\t\t} else if (character === \"{\") {\n\t\t\t\tdepth++;\n\t\t\t} else if (character === \"}\" && --depth === 0) {\n\t\t\t\tcandidates.push(text.slice(start, index + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn candidates;\n}\n\nexport function parseWorkerOutput(text: string): ParsedWorkerOutput | undefined {\n\tconst trimmed = text.trim();\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tcandidates.push(...balancedObjectCandidates(trimmed));\n\n\tfor (const candidate of candidates) {\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(candidate);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) continue;\n\t\tconst record = parsed as Record<string, unknown>;\n\t\tconst summary = record.summary;\n\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\n\t\tconst status = record.status === \"blocked\" ? \"blocked\" : \"completed\";\n\t\tconst blockers = Array.isArray(record.blockers)\n\t\t\t? record.blockers.filter((blocker): blocker is string => typeof blocker === \"string\" && blocker.length > 0)\n\t\t\t: [];\n\t\tconst findings: Array<{ summary: string; confidence?: number }> = [];\n\t\tif (Array.isArray(record.findings)) {\n\t\t\tfor (const item of record.findings) {\n\t\t\t\tif (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n\t\t\t\tconst findingSummary = (item as { summary?: unknown }).summary;\n\t\t\t\tif (typeof findingSummary !== \"string\" || findingSummary.trim().length === 0) continue;\n\t\t\t\tconst confidenceRaw = (item as { confidence?: unknown }).confidence;\n\t\t\t\tconst confidence =\n\t\t\t\t\ttypeof confidenceRaw === \"number\" && Number.isFinite(confidenceRaw)\n\t\t\t\t\t\t? Math.min(Math.max(confidenceRaw, 0), 1)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tfindings.push({ summary: findingSummary.trim(), confidence });\n\t\t\t}\n\t\t}\n\t\tconst verdict = record.verdict === \"accepted\" || record.verdict === \"rejected\" ? record.verdict : undefined;\n\t\tconst reasonCodes = Array.isArray(record.reasonCodes)\n\t\t\t? record.reasonCodes.filter(\n\t\t\t\t\t(reasonCode): reasonCode is string => typeof reasonCode === \"string\" && reasonCode.length > 0,\n\t\t\t\t)\n\t\t\t: [];\n\t\treturn {\n\t\t\tsummary: summary.trim(),\n\t\t\tstatus,\n\t\t\tblockers,\n\t\t\tfindings,\n\t\t\tactions: parseWorkerActions(record.actions),\n\t\t\t...(verdict ? { verdict } : {}),\n\t\t\treasonCodes,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction buildWorkerEvidence(request: WorkerRequest, findings: ParsedWorkerOutput[\"findings\"]) {\n\tif (findings.length === 0) return undefined;\n\tconst instructionsRef: EvidenceRef = {\n\t\tid: \"src-instructions\",\n\t\tkind: \"user\",\n\t\ttitle: \"Delegated task instructions\",\n\t\ttrusted: true,\n\t\texcerpt: request.instructions.slice(0, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-worker\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Delegated worker synthesis\",\n\t\ttrusted: false,\n\t};\n\tconst bundleFindings: Finding[] = findings.map((finding, index) => ({\n\t\tid: `finding-${index + 1}`,\n\t\tsummary: finding.summary,\n\t\tevidenceIds: [synthesisRef.id],\n\t\t...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),\n\t}));\n\treturn createEvidenceBundle({\n\t\tquery: `worker:${request.id}`,\n\t\tsources: [instructionsRef, synthesisRef],\n\t\tfindings: bundleFindings,\n\t});\n}\n\nfunction finishOutcome(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\tcostUsd: number;\n\tcwd?: string;\n}): WorkerRunOutcome {\n\tconst acceptance = validateWorkerClaim({ request: args.request, claim: args.claim, cwd: args.cwd });\n\treturn {\n\t\tclaim: args.claim,\n\t\tacceptance,\n\t\taccepted: acceptance.outcome === \"allow\",\n\t\tlaneStatus: args.laneStatus,\n\t\treasonCode: args.reasonCode,\n\t\tcostUsd: args.costUsd,\n\t};\n}\n\nexport async function runWorker(options: WorkerRunnerOptions): Promise<WorkerRunOutcome> {\n\tconst now = options.now ?? (() => new Date().toISOString());\n\tconst baseClaim = {\n\t\trequestId: options.request.id,\n\t\tchangedFiles: [] as string[],\n\t\tusageReportId: options.usageReportId,\n\t\tcreatedAt: now(),\n\t};\n\n\t// The write prompt requires BOTH the envelope grant and a caller-supplied applier.\n\tconst writeCapable =\n\t\toptions.request.envelope.capabilities.includes(\"filesystem.write\") && options.applyActions !== undefined;\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: options.verificationSubjectTaskId\n\t\t\t\t\t? buildVerifierSystemPrompt(options.verificationSubjectTaskId)\n\t\t\t\t\t: buildWorkerSystemPrompt({ write: writeCapable, process: options.processCapable === true }),\n\t\t\t\tuserPrompt: buildWorkerUserPrompt(options.request),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tconst costUsd = bounded.completion?.costUsd ?? 0;\n\tconst liveChangedFiles = [...new Set(options.getChangedFiles?.() ?? [])];\n\n\tif (bounded.failure) {\n\t\tconst cancelled = bounded.failure.status === \"canceled\" || bounded.failure.status === \"timeout\";\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...baseClaim,\n\t\t\t\tchangedFiles: liveChangedFiles,\n\t\t\t\tstatus: cancelled ? \"cancelled\" : \"failed\",\n\t\t\t\tsummary: `Worker did not complete: ${bounded.failure.reasonCode}`,\n\t\t\t},\n\t\t\tlaneStatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst completion = bounded.completion as WorkerCompletion | undefined;\n\tconst completionChangedFiles = [...new Set([...liveChangedFiles, ...(completion?.changedFiles ?? [])])];\n\tconst completionBaseClaim = { ...baseClaim, changedFiles: completionChangedFiles };\n\tif (!completion || completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: { ...completionBaseClaim, status: \"failed\", summary: \"Worker model call failed.\" },\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"model_error\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst parsed = parseWorkerOutput(completion.text);\n\tif (!parsed) {\n\t\tconst readOnlyPlainText =\n\t\t\t!options.verificationSubjectTaskId &&\n\t\t\t!writeCapable &&\n\t\t\tcompletion.text.trim().length > 0 &&\n\t\t\tcompletionChangedFiles.length === 0;\n\t\tif (readOnlyPlainText) {\n\t\t\tconst completionBlockers = [...(completion.blockers ?? [])];\n\t\t\tconst incompleteNote =\n\t\t\t\tcompletion.stopReason === \"stop\"\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `\\n\\n[Worker output ended with stop reason '${completion.stopReason}'; verify completeness.]`;\n\t\t\tconst summary = `${completion.text.trim().slice(0, Math.max(0, 8000 - incompleteNote.length))}${incompleteNote}`;\n\t\t\tconst blocked = completionBlockers.length > 0;\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: blocked ? \"blocked\" : \"completed\",\n\t\t\t\t\toutputFormat: \"plain_text\",\n\t\t\t\t\tsummary,\n\t\t\t\t\t...(blocked ? { blockers: completionBlockers } : {}),\n\t\t\t\t},\n\t\t\t\tlaneStatus: blocked ? \"failed\" : \"succeeded\",\n\t\t\t\treasonCode: blocked\n\t\t\t\t\t? \"worker_blocked\"\n\t\t\t\t\t: completion.stopReason === \"stop\"\n\t\t\t\t\t\t? \"worker_completed_plain_text\"\n\t\t\t\t\t\t: \"worker_completed_plain_text_incomplete\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output was not valid structured JSON.\",\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst evidence = buildWorkerEvidence(options.request, parsed.findings);\n\tif (options.verificationSubjectTaskId && (!parsed.verdict || parsed.reasonCodes.length === 0)) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Verifier output omitted its typed verdict or reasonCodes.\",\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"invalid_verifier_result\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tlet changedFiles: string[] = [...completionChangedFiles];\n\tconst actionBlockers: string[] = [...(completion.blockers ?? [])];\n\tif (!writeCapable && completionChangedFiles.length > 0) {\n\t\tactionBlockers.push(\"worker reported file changes without a filesystem.write envelope grant\");\n\t}\n\tif (writeCapable && parsed.status !== \"blocked\" && parsed.actions.length > 0 && options.applyActions) {\n\t\t// Runner-side application through the envelope path scope: refusals and failures are\n\t\t// surfaced as blockers so a partially-applied change can never look like clean success.\n\t\tconst applied = options.applyActions(parsed.actions);\n\t\tchangedFiles = [...new Set([...changedFiles, ...applied.changedFiles])];\n\t\tfor (const refusal of applied.refused) {\n\t\t\tactionBlockers.push(`action refused (${refusal.path}): ${refusal.reason}`);\n\t\t}\n\t\tfor (const failure of applied.failed) {\n\t\t\tactionBlockers.push(`action failed (${failure.path}): ${failure.reason}`);\n\t\t}\n\t} else if (!writeCapable && parsed.actions.length > 0) {\n\t\tactionBlockers.push(\"worker emitted file actions without a filesystem.write envelope grant; nothing was applied\");\n\t}\n\tconst allBlockers = [...parsed.blockers, ...actionBlockers];\n\tconst claim: WorkerClaim = {\n\t\t...baseClaim,\n\t\tchangedFiles,\n\t\tstatus: parsed.status === \"blocked\" || allBlockers.length > 0 ? \"blocked\" : \"completed\",\n\t\tsummary: parsed.summary,\n\t\t...(allBlockers.length > 0 ? { blockers: allBlockers } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...(options.verificationSubjectTaskId && parsed.verdict\n\t\t\t? {\n\t\t\t\t\tverification: {\n\t\t\t\t\t\tsubjectTaskId: options.verificationSubjectTaskId,\n\t\t\t\t\t\tverdict: parsed.verdict,\n\t\t\t\t\t\treasonCodes: parsed.reasonCodes,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n\n\tif (claim.status === \"blocked\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim,\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"worker_blocked\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst overBudget = options.maxUsd !== undefined && costUsd > options.maxUsd;\n\treturn finishOutcome({\n\t\trequest: options.request,\n\t\tcwd: options.cwd,\n\t\tclaim,\n\t\tlaneStatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: claim.verification\n\t\t\t\t? claim.verification.verdict === \"accepted\"\n\t\t\t\t\t? \"verification_accepted\"\n\t\t\t\t\t: \"verification_rejected\"\n\t\t\t\t: \"worker_completed\",\n\t\tcostUsd,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-runner.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAEN,kBAAkB,GAGlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,iCAAiC,EACjC,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AAU,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC5E,OAAO,aAAa,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK;QACL,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,WAAW;QACzD,UAAU,EAAE,UAAU;YACrB,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,KAAK,CAAC,YAAY;gBACnB,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,KAAK,UAAU;oBAC1C,CAAC,CAAC,uBAAuB;oBACzB,CAAC,CAAC,uBAAuB;gBAC1B,CAAC,CAAC,kBAAkB;QACtB,OAAO;KACP,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { EvidenceRef, Finding, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport { createEvidenceBundle } from \"../research/evidence-bundle.ts\";\nimport {\n\ttype AppliedActionsReport,\n\tparseWorkerActions,\n\ttype RejectedWorkerActions,\n\ttype WorkerAction,\n} from \"./worker-actions.ts\";\nimport {\n\tcollectBoundedWorkerClaimBlockers,\n\tcollectBoundedWorkerClaimChangedFiles,\n\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\tMAX_WORKER_CLAIM_BLOCKERS,\n\tMAX_WORKER_CLAIM_SUMMARY_CHARS,\n\tnormalizeWorkerClaimForHost,\n\tvalidateWorkerClaim,\n} from \"./worker-claim.ts\";\n\n/**\n * Pure execution for one bounded specialist delegation: bounded isolated completion ->\n * parse -> untrusted `WorkerClaim` -> parent validation via {@link validateWorkerClaim}.\n *\n * The injected completion may be a bounded child tool loop. Its tool surface is built and gated by\n * the host; this module keeps the structured-output contract and treats every claim as untrusted\n * until parent validation succeeds.\n */\n\n/** Builds one capability-exact prompt; no role text may deny a tool already granted by policy. */\nexport function buildWorkerSystemPrompt(capabilities: { write: boolean; process: boolean }): string {\n\tconst resultShape = capabilities.write\n\t\t? '{\"summary\":\"<what you did>\",\"status\":\"completed\"|\"blocked\",\"blockers\":[],\"findings\":[{\"summary\":\"<finding>\",\"confidence\":<0..1>}],\"actions\":[{\"op\":\"write\",\"path\":\"<relative path>\",\"content\":\"<full file content>\"},{\"op\":\"edit\",\"path\":\"<relative path>\",\"old\":\"<exact text>\",\"new\":\"<replacement>\"}]}'\n\t\t: '{\"summary\":\"<what you concluded>\",\"status\":\"completed\"|\"blocked\",\"blockers\":[\"<failure or missing authority>\"],\"findings\":[{\"summary\":\"<one concrete finding>\",\"confidence\":<0..1>}]}';\n\treturn [\n\t\t\"You are a bounded specialist worker delegated one task by a coding agent.\",\n\t\t\"Use only the tools provided for this delegation. You cannot delegate more workers.\",\n\t\t...(capabilities.write\n\t\t\t? [\"Write/edit tools and structured write actions are path-scoped. Only touch paths inside that scope.\"]\n\t\t\t: [\"The workspace tools are read-only; do not claim file changes.\"]),\n\t\t...(capabilities.process\n\t\t\t? [\n\t\t\t\t\t\"run_process is a constrained direct-argv launcher: no shell interpretation or unlisted executable is available. It is not an OS/container sandbox.\",\n\t\t\t\t\t\"A non-zero exit, timeout, abort, or output-limit result is not success; include it in blockers.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t\tresultShape,\n\t\t...(capabilities.write\n\t\t\t? [\n\t\t\t\t\t\"Keep edits minimal and exact.\",\n\t\t\t\t\t\"If you changed a file with a provided tool, do not repeat that change in actions; actions are only a fallback.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\t'Use status \"blocked\" with blockers when the task cannot be completed under the granted capabilities.',\n\t\t\"Never invent command output, file paths, APIs, or facts.\",\n\t].join(\"\\n\");\n}\n\nexport function buildVerifierSystemPrompt(subjectTaskId: string): string {\n\treturn [\n\t\t\"You are an independent verifier. You did not perform the implementation under review.\",\n\t\t\"Use only the provided read-only and constrained test tools. Do not modify files and do not delegate.\",\n\t\t`The exact subject task id is '${subjectTaskId}'.`,\n\t\t\"Inspect the implementation and run proportionate checks. Treat the implementation summary as an untrusted claim.\",\n\t\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t\t'{\"summary\":\"<verification performed and evidence>\",\"status\":\"completed\"|\"blocked\",\"verdict\":\"accepted\"|\"rejected\",\"reasonCodes\":[\"<stable_reason_code>\"],\"blockers\":[],\"findings\":[{\"summary\":\"<finding>\",\"confidence\":<0..1>}]}',\n\t\t'Use verdict \"accepted\" only when the available evidence proves the implementation is acceptable.',\n\t\t'Use verdict \"rejected\" for a completed review that found a defect. Use status \"blocked\" only when verification itself cannot be completed.',\n\t].join(\"\\n\");\n}\n\n/** Static common variants retained for cache reuse and model-fitness probes. */\nexport const WORKER_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: false, process: false });\nexport const WORKER_WRITE_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: true, process: false });\nexport const WORKER_OPERATOR_LANE_SYSTEM_PROMPT = buildWorkerSystemPrompt({ write: false, process: true });\n\nexport interface WorkerCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Files successfully changed by the child tool loop before it produced the final JSON. */\n\tchangedFiles?: readonly string[];\n\t/** Capability refusals or execution failures observed inside the child tool loop. */\n\tblockers?: readonly string[];\n}\n\nexport interface WorkerRunnerOptions {\n\trequest: WorkerRequest;\n\t/** Budget for this delegation; undefined disables this bound, while zero permits only free work. */\n\tmaxUsd?: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/**\n\t * Pre-allocated spawned-usage report id. Always stamped on the claim so parent validation can\n\t * enforce the cost-visibility invariant (a completed claim without a usage report is blocked).\n\t */\n\tusageReportId: string;\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal?: AbortSignal }) => Promise<WorkerCompletion>;\n\t/** Live successful child-tool mutations, including writes completed before timeout/cancellation. */\n\tgetChangedFiles?: () => readonly string[];\n\tsignal?: AbortSignal;\n\tnow?: () => string;\n\t/** Enables the WRITE lane: only honored when the request envelope grants \"filesystem.write\". The\n\t * runner applies the worker's structured actions through the envelope path scope; refusals\n\t * and failures become blockers, never silent drops. */\n\tapplyActions?: (actions: readonly WorkerAction[]) => AppliedActionsReport;\n\t/** Enables the constrained direct-argv operator role prompt. */\n\tprocessCapable?: boolean;\n\t/** Session cwd — the baseline for relative changed-file and envelope paths in parent\n\t * validation. Defaults to process.cwd(). */\n\tcwd?: string;\n\t/** Turns the child into a read-only semantic verifier for this exact durable task. */\n\tverificationSubjectTaskId?: string;\n}\n\nexport interface WorkerRunOutcome {\n\tclaim: WorkerClaim;\n\t/** Parent-review verdict from {@link validateWorkerClaim}; worker output stays untrusted. */\n\tacceptance: GateOutcome;\n\taccepted: boolean;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\tcostUsd: number;\n}\n\nexport function buildWorkerUserPrompt(request: WorkerRequest): string {\n\treturn [\n\t\t\"Delegated task:\",\n\t\t\"<task>\",\n\t\trequest.instructions,\n\t\t\"</task>\",\n\t\t\"\",\n\t\t\"The task may request a custom output format. Do not replace the worker claim envelope.\",\n\t\t'Always return the JSON object required by the system prompt; put requested details inside \"summary\" and \"findings\".',\n\t].join(\"\\n\");\n}\n\nexport interface ParsedWorkerOutput {\n\tsummary: string;\n\tstatus: \"completed\" | \"blocked\";\n\tblockers: string[];\n\tfindings: Array<{ summary: string; confidence?: number }>;\n\tactions: WorkerAction[];\n\t/** Present when the model emitted an action list that cannot safely reach execution. */\n\tactionRejection?: RejectedWorkerActions;\n\tverdict?: \"accepted\" | \"rejected\";\n\treasonCodes: string[];\n}\n\nconst MAX_WORKER_OUTPUT_CHARS = 512 * 1024;\nconst MAX_WORKER_JSON_CANDIDATES = 64;\nconst MAX_WORKER_JSON_DEPTH = 256;\nconst MAX_WORKER_FINDINGS = 64;\nconst MAX_WORKER_FINDING_CHARS = 2_000;\nconst MAX_WORKER_REASON_CODES = 32;\nconst MAX_WORKER_REASON_CODE_CHARS = 128;\n\nfunction balancedObjectCandidates(text: string): string[] {\n\tconst ranges: Array<{ start: number; end: number }> = [];\n\tconst starts: number[] = [];\n\tlet inString = false;\n\tlet escaped = false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tconst character = text[index];\n\t\tif (inString) {\n\t\t\tif (escaped) escaped = false;\n\t\t\telse if (character === \"\\\\\") escaped = true;\n\t\t\telse if (character === '\"') inString = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === '\"') {\n\t\t\tinString = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"{\") {\n\t\t\tif (starts.length >= MAX_WORKER_JSON_DEPTH) return ranges.map(({ start, end }) => text.slice(start, end));\n\t\t\tstarts.push(index);\n\t\t\tcontinue;\n\t\t}\n\t\tif (character !== \"}\") continue;\n\t\tconst start = starts.pop();\n\t\tif (start === undefined || ranges.length >= MAX_WORKER_JSON_CANDIDATES) continue;\n\t\tconst end = index + 1;\n\t\tif (end - start <= MAX_WORKER_OUTPUT_CHARS) ranges.push({ start, end });\n\t}\n\treturn ranges.map(({ start, end }) => text.slice(start, end));\n}\n\nfunction workerOutputRecords(text: string): Record<string, unknown>[] {\n\tconst trimmed = text.trim();\n\tif (trimmed.length === 0 || trimmed.length > MAX_WORKER_OUTPUT_CHARS) return [];\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tcandidates.push(...balancedObjectCandidates(trimmed));\n\tconst records: Record<string, unknown>[] = [];\n\tfor (const candidate of candidates) {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(candidate);\n\t\t\tif (parsed && typeof parsed === \"object\" && !Array.isArray(parsed))\n\t\t\t\trecords.push(parsed as Record<string, unknown>);\n\t\t} catch {\n\t\t\t// Candidate extraction is deliberately best-effort; a later balanced candidate may still be valid.\n\t\t}\n\t}\n\treturn records;\n}\n\nfunction isWorkerStatus(value: unknown): value is ParsedWorkerOutput[\"status\"] {\n\treturn value === \"completed\" || value === \"blocked\";\n}\n\n/**\n * Plain-text fallback is for output that never attempted the worker claim envelope. A JSON object\n * with a claim summary but malformed typed fields is a contract failure, never an implicit success.\n */\nfunction hasMalformedWorkerClaimEnvelope(text: string): boolean {\n\treturn workerOutputRecords(text).some((record) => {\n\t\tif (typeof record.summary !== \"string\" || record.summary.trim().length === 0) return false;\n\t\tif (!isWorkerStatus(record.status)) return true;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") return true;\n\t\treturn (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t);\n\t});\n}\n\nexport function parseWorkerOutput(text: string): ParsedWorkerOutput | undefined {\n\tfor (const record of workerOutputRecords(text)) {\n\t\tconst summary = record.summary;\n\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\t\tif (!isWorkerStatus(record.status)) continue;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") continue;\n\t\tif (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst status = record.status;\n\t\tconst blockers = Array.isArray(record.blockers)\n\t\t\t? record.blockers\n\t\t\t\t\t.filter((blocker): blocker is string => typeof blocker === \"string\" && blocker.trim().length > 0)\n\t\t\t\t\t.slice(0, MAX_WORKER_CLAIM_BLOCKERS)\n\t\t\t\t\t.map((blocker) => blocker.trim().slice(0, MAX_WORKER_CLAIM_BLOCKER_CHARS))\n\t\t\t: [];\n\t\tconst findings: Array<{ summary: string; confidence?: number }> = [];\n\t\tif (Array.isArray(record.findings)) {\n\t\t\tfor (const item of record.findings.slice(0, MAX_WORKER_FINDINGS)) {\n\t\t\t\tif (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n\t\t\t\tconst findingSummary = (item as { summary?: unknown }).summary;\n\t\t\t\tif (typeof findingSummary !== \"string\" || findingSummary.trim().length === 0) continue;\n\t\t\t\tconst confidenceRaw = (item as { confidence?: unknown }).confidence;\n\t\t\t\tconst confidence =\n\t\t\t\t\ttypeof confidenceRaw === \"number\" && Number.isFinite(confidenceRaw)\n\t\t\t\t\t\t? Math.min(Math.max(confidenceRaw, 0), 1)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tfindings.push({ summary: findingSummary.trim().slice(0, MAX_WORKER_FINDING_CHARS), confidence });\n\t\t\t}\n\t\t}\n\t\tconst verdict = record.verdict === \"accepted\" || record.verdict === \"rejected\" ? record.verdict : undefined;\n\t\tconst reasonCodes = Array.isArray(record.reasonCodes)\n\t\t\t? record.reasonCodes\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(reasonCode): reasonCode is string => typeof reasonCode === \"string\" && reasonCode.trim().length > 0,\n\t\t\t\t\t)\n\t\t\t\t\t.slice(0, MAX_WORKER_REASON_CODES)\n\t\t\t\t\t.map((reasonCode) => reasonCode.trim().slice(0, MAX_WORKER_REASON_CODE_CHARS))\n\t\t\t: [];\n\t\tconst actionOutcome = parseWorkerActions(record.actions);\n\t\treturn {\n\t\t\tsummary: summary.trim().slice(0, MAX_WORKER_CLAIM_SUMMARY_CHARS),\n\t\t\tstatus,\n\t\t\tblockers,\n\t\t\tfindings,\n\t\t\tactions: actionOutcome.kind === \"accepted\" ? actionOutcome.actions : [],\n\t\t\t...(actionOutcome.kind === \"rejected\" ? { actionRejection: actionOutcome } : {}),\n\t\t\t...(verdict ? { verdict } : {}),\n\t\t\treasonCodes,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction buildWorkerEvidence(request: WorkerRequest, findings: ParsedWorkerOutput[\"findings\"]) {\n\tif (findings.length === 0) return undefined;\n\tconst instructionsRef: EvidenceRef = {\n\t\tid: \"src-instructions\",\n\t\tkind: \"user\",\n\t\ttitle: \"Delegated task instructions\",\n\t\ttrusted: true,\n\t\texcerpt: request.instructions.slice(0, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-worker\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Delegated worker synthesis\",\n\t\ttrusted: false,\n\t};\n\tconst bundleFindings: Finding[] = findings.map((finding, index) => ({\n\t\tid: `finding-${index + 1}`,\n\t\tsummary: finding.summary,\n\t\tevidenceIds: [synthesisRef.id],\n\t\t...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),\n\t}));\n\treturn createEvidenceBundle({\n\t\tquery: `worker:${request.id}`,\n\t\tsources: [instructionsRef, synthesisRef],\n\t\tfindings: bundleFindings,\n\t});\n}\n\nfunction finishOutcome(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\tcostUsd: number;\n\tcwd?: string;\n}): WorkerRunOutcome {\n\tconst claim = normalizeWorkerClaimForHost(args.claim);\n\tconst acceptance = validateWorkerClaim({ request: args.request, claim, cwd: args.cwd });\n\treturn {\n\t\tclaim,\n\t\tacceptance,\n\t\taccepted: acceptance.outcome === \"allow\",\n\t\tlaneStatus: args.laneStatus,\n\t\treasonCode: args.reasonCode,\n\t\tcostUsd: args.costUsd,\n\t};\n}\n\nexport async function runWorker(options: WorkerRunnerOptions): Promise<WorkerRunOutcome> {\n\tconst now = options.now ?? (() => new Date().toISOString());\n\tconst baseClaim = {\n\t\trequestId: options.request.id,\n\t\tchangedFiles: [] as string[],\n\t\tusageReportId: options.usageReportId,\n\t\tcreatedAt: now(),\n\t};\n\n\t// The write prompt requires BOTH the envelope grant and a caller-supplied applier.\n\tconst writeCapable =\n\t\toptions.request.envelope.capabilities.includes(\"filesystem.write\") && options.applyActions !== undefined;\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: options.verificationSubjectTaskId\n\t\t\t\t\t? buildVerifierSystemPrompt(options.verificationSubjectTaskId)\n\t\t\t\t\t: buildWorkerSystemPrompt({ write: writeCapable, process: options.processCapable === true }),\n\t\t\t\tuserPrompt: buildWorkerUserPrompt(options.request),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tconst costUsd = bounded.completion?.costUsd ?? 0;\n\tconst liveChangedFilesReport = collectBoundedWorkerClaimChangedFiles(options.getChangedFiles?.() ?? []);\n\tconst liveChangedFiles = liveChangedFilesReport.values;\n\n\tif (bounded.failure) {\n\t\tconst cancelled = bounded.failure.status === \"canceled\" || bounded.failure.status === \"timeout\";\n\t\tconst blockers = liveChangedFilesReport.overflowed\n\t\t\t? [\"worker changed-file report exceeded the durable claim bound; parent review is required\"]\n\t\t\t: undefined;\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...baseClaim,\n\t\t\t\tchangedFiles: liveChangedFiles,\n\t\t\t\tstatus: cancelled ? \"cancelled\" : \"failed\",\n\t\t\t\tsummary: `Worker did not complete: ${bounded.failure.reasonCode}`,\n\t\t\t\t...(blockers ? { blockers } : {}),\n\t\t\t},\n\t\t\tlaneStatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst completion = bounded.completion as WorkerCompletion | undefined;\n\tconst completionChangedFilesReport = collectBoundedWorkerClaimChangedFiles(completion?.changedFiles ?? []);\n\tconst mergedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t...liveChangedFiles,\n\t\t...completionChangedFilesReport.values,\n\t]);\n\tconst changedFilesOverflowed =\n\t\tliveChangedFilesReport.overflowed ||\n\t\tcompletionChangedFilesReport.overflowed ||\n\t\tmergedChangedFilesReport.overflowed;\n\tconst completionChangedFiles = mergedChangedFilesReport.values;\n\tconst completionBaseClaim = { ...baseClaim, changedFiles: completionChangedFiles };\n\tif (!completion || completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: { ...completionBaseClaim, status: \"failed\", summary: \"Worker model call failed.\" },\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"model_error\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst parsed = parseWorkerOutput(completion.text);\n\tif (!parsed) {\n\t\tif (hasMalformedWorkerClaimEnvelope(completion.text)) {\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tsummary: \"Worker output used a malformed structured claim envelope.\",\n\t\t\t\t},\n\t\t\t\tlaneStatus: \"failed\",\n\t\t\t\treasonCode: \"unparseable_output\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\tconst readOnlyPlainText =\n\t\t\t!options.verificationSubjectTaskId &&\n\t\t\t!writeCapable &&\n\t\t\tcompletion.text.trim().length > 0 &&\n\t\t\tcompletionChangedFiles.length === 0 &&\n\t\t\t!changedFilesOverflowed;\n\t\tif (readOnlyPlainText) {\n\t\t\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\t\t\tconst completionBlockers = completionBlockersReport.overflowed\n\t\t\t\t? [\n\t\t\t\t\t\t...completionBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t]\n\t\t\t\t: completionBlockersReport.values;\n\t\t\tconst incompleteNote =\n\t\t\t\tcompletion.stopReason === \"stop\"\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `\\n\\n[Worker output ended with stop reason '${completion.stopReason}'; verify completeness.]`;\n\t\t\tconst summary = `${completion.text.trim().slice(0, Math.max(0, MAX_WORKER_CLAIM_SUMMARY_CHARS - incompleteNote.length))}${incompleteNote}`;\n\t\t\tconst blocked = completionBlockers.length > 0;\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: blocked ? \"blocked\" : \"completed\",\n\t\t\t\t\toutputFormat: \"plain_text\",\n\t\t\t\t\tsummary,\n\t\t\t\t\t...(blocked ? { blockers: completionBlockers } : {}),\n\t\t\t\t},\n\t\t\t\tlaneStatus: blocked ? \"failed\" : \"succeeded\",\n\t\t\t\treasonCode: blocked\n\t\t\t\t\t? \"worker_blocked\"\n\t\t\t\t\t: completion.stopReason === \"stop\"\n\t\t\t\t\t\t? \"worker_completed_plain_text\"\n\t\t\t\t\t\t: \"worker_completed_plain_text_incomplete\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output was not valid structured JSON.\",\n\t\t\t\t...(changedFilesOverflowed\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tblockers: [\n\t\t\t\t\t\t\t\t\"worker changed-file report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst evidence = buildWorkerEvidence(options.request, parsed.findings);\n\tif (parsed.actionRejection) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output contained invalid structured actions.\",\n\t\t\t\tblockers: [parsed.actionRejection.reasonCode],\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tif (options.verificationSubjectTaskId && (!parsed.verdict || parsed.reasonCodes.length === 0)) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Verifier output omitted its typed verdict or reasonCodes.\",\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"invalid_verifier_result\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tlet changedFiles: string[] = [...completionChangedFiles];\n\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\tconst actionBlockers: string[] = [...completionBlockersReport.values];\n\tif (changedFilesOverflowed) {\n\t\tactionBlockers.push(\"worker changed-file report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (completionBlockersReport.overflowed) {\n\t\tactionBlockers.push(\"worker blocker report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (!writeCapable && completionChangedFiles.length > 0) {\n\t\tactionBlockers.push(\"worker reported file changes without a filesystem.write envelope grant\");\n\t}\n\tif (writeCapable && parsed.status !== \"blocked\" && parsed.actions.length > 0 && options.applyActions) {\n\t\t// Runner-side application through the envelope path scope: refusals and failures are\n\t\t// surfaced as blockers so a partially-applied change can never look like clean success.\n\t\tconst applied = options.applyActions(parsed.actions);\n\t\tconst appliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles(applied.changedFiles);\n\t\tconst mergedAppliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t\t...changedFiles,\n\t\t\t...appliedChangedFilesReport.values,\n\t\t]);\n\t\tchangedFiles = mergedAppliedChangedFilesReport.values;\n\t\tif (appliedChangedFilesReport.overflowed || mergedAppliedChangedFilesReport.overflowed) {\n\t\t\tactionBlockers.push(\"applied changed-file report exceeded the durable claim bound; parent review is required\");\n\t\t}\n\t\tfor (const refusal of applied.refused) {\n\t\t\tactionBlockers.push(`action refused (${refusal.path}): ${refusal.reason}`);\n\t\t}\n\t\tfor (const failure of applied.failed) {\n\t\t\tactionBlockers.push(`action failed (${failure.path}): ${failure.reason}`);\n\t\t}\n\t\tfor (const inspection of applied.inspectionRequired) {\n\t\t\tactionBlockers.push(\n\t\t\t\t`action requires workspace/evidence inspection (${inspection.path}, ${inspection.state}): ${inspection.reasonCode}`,\n\t\t\t);\n\t\t}\n\t} else if (!writeCapable && parsed.actions.length > 0) {\n\t\tactionBlockers.push(\"worker emitted file actions without a filesystem.write envelope grant; nothing was applied\");\n\t}\n\tconst allBlockersReport = collectBoundedWorkerClaimBlockers([...parsed.blockers, ...actionBlockers]);\n\tconst allBlockers = allBlockersReport.overflowed\n\t\t? [\n\t\t\t\t...allBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t]\n\t\t: allBlockersReport.values;\n\tconst claim: WorkerClaim = {\n\t\t...baseClaim,\n\t\tchangedFiles,\n\t\tstatus: parsed.status === \"blocked\" || allBlockers.length > 0 ? \"blocked\" : \"completed\",\n\t\tsummary: parsed.summary,\n\t\t...(allBlockers.length > 0 ? { blockers: allBlockers } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...(options.verificationSubjectTaskId && parsed.verdict\n\t\t\t? {\n\t\t\t\t\tverification: {\n\t\t\t\t\t\tsubjectTaskId: options.verificationSubjectTaskId,\n\t\t\t\t\t\tverdict: parsed.verdict,\n\t\t\t\t\t\treasonCodes: parsed.reasonCodes,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n\n\tif (claim.status === \"blocked\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim,\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"worker_blocked\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst overBudget = options.maxUsd !== undefined && costUsd > options.maxUsd;\n\treturn finishOutcome({\n\t\trequest: options.request,\n\t\tcwd: options.cwd,\n\t\tclaim,\n\t\tlaneStatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: claim.verification\n\t\t\t\t? claim.verification.verdict === \"accepted\"\n\t\t\t\t\t? \"verification_accepted\"\n\t\t\t\t\t: \"verification_rejected\"\n\t\t\t\t: \"worker_completed\",\n\t\tcostUsd,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
2
|
+
import type { WorkerResultContract } from "../orchestration/contracts.ts";
|
|
3
|
+
import { type CreateWorkerResultContractInput } from "../orchestration/worker-result-adapter.ts";
|
|
4
|
+
import type { WorkerLifecycle } from "./worker-lifecycle.ts";
|
|
5
|
+
/**
|
|
6
|
+
* One terminal boundary for every worker execution adapter. It creates the fenced result, commits
|
|
7
|
+
* it through the durable lifecycle, and returns the event-driven handoff token without owning UI.
|
|
8
|
+
*/
|
|
9
|
+
export interface FinalizeWorkerClaimInput extends CreateWorkerResultContractInput {
|
|
10
|
+
/** Verification dispatch owns the next terminal signal until it reconciles the subject. */
|
|
11
|
+
notify?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface FinalizedWorkerClaim {
|
|
14
|
+
result: WorkerResultContract;
|
|
15
|
+
record: LaneRecord;
|
|
16
|
+
notification?: {
|
|
17
|
+
notificationId: string;
|
|
18
|
+
status: "pending" | "delivered";
|
|
19
|
+
record: LaneRecord;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function finalizeWorkerClaim(lifecycle: WorkerLifecycle, input: FinalizeWorkerClaimInput): FinalizedWorkerClaim;
|
|
23
|
+
//# sourceMappingURL=worker-terminal-finalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-terminal-finalizer.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-terminal-finalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACN,KAAK,+BAA+B,EAEpC,MAAM,2CAA2C,CAAC;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,+BAA+B;IAChF,2FAA2F;IAC3F,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC;CAC/F;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,wBAAwB,GAAG,oBAAoB,CAQrH","sourcesContent":["import type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerResultContract } from \"../orchestration/contracts.ts\";\nimport {\n\ttype CreateWorkerResultContractInput,\n\tcreateWorkerResultContract,\n} from \"../orchestration/worker-result-adapter.ts\";\nimport { normalizeWorkerClaimForHost } from \"./worker-claim.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\n\n/**\n * One terminal boundary for every worker execution adapter. It creates the fenced result, commits\n * it through the durable lifecycle, and returns the event-driven handoff token without owning UI.\n */\nexport interface FinalizeWorkerClaimInput extends CreateWorkerResultContractInput {\n\t/** Verification dispatch owns the next terminal signal until it reconciles the subject. */\n\tnotify?: boolean;\n}\n\nexport interface FinalizedWorkerClaim {\n\tresult: WorkerResultContract;\n\trecord: LaneRecord;\n\tnotification?: { notificationId: string; status: \"pending\" | \"delivered\"; record: LaneRecord };\n}\n\nexport function finalizeWorkerClaim(lifecycle: WorkerLifecycle, input: FinalizeWorkerClaimInput): FinalizedWorkerClaim {\n\tconst { notify, ...resultInput } = input;\n\t// Direct abort/error paths also pass here, so this boundary cannot rely on worker-runner\n\t// normalization. Reject before lifecycle mutation, filesystem observation, or notification.\n\tconst result = createWorkerResultContract({ ...resultInput, claim: normalizeWorkerClaimForHost(resultInput.claim) });\n\tconst record = lifecycle.finish(result, { ...(notify === false ? { notify: false } : {}) });\n\tconst notification = notify === false ? undefined : lifecycle.getTerminalNotification(record.laneId);\n\treturn { result, record, ...(notification ? { notification } : {}) };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createWorkerResultContract, } from "../orchestration/worker-result-adapter.js";
|
|
2
|
+
import { normalizeWorkerClaimForHost } from "./worker-claim.js";
|
|
3
|
+
export function finalizeWorkerClaim(lifecycle, input) {
|
|
4
|
+
const { notify, ...resultInput } = input;
|
|
5
|
+
// Direct abort/error paths also pass here, so this boundary cannot rely on worker-runner
|
|
6
|
+
// normalization. Reject before lifecycle mutation, filesystem observation, or notification.
|
|
7
|
+
const result = createWorkerResultContract({ ...resultInput, claim: normalizeWorkerClaimForHost(resultInput.claim) });
|
|
8
|
+
const record = lifecycle.finish(result, { ...(notify === false ? { notify: false } : {}) });
|
|
9
|
+
const notification = notify === false ? undefined : lifecycle.getTerminalNotification(record.laneId);
|
|
10
|
+
return { result, record, ...(notification ? { notification } : {}) };
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=worker-terminal-finalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-terminal-finalizer.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-terminal-finalizer.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,0BAA0B,GAC1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAkBhE,MAAM,UAAU,mBAAmB,CAAC,SAA0B,EAAE,KAA+B,EAAwB;IACtH,MAAM,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,KAAK,CAAC;IACzC,yFAAyF;IACzF,4FAA4F;IAC5F,MAAM,MAAM,GAAG,0BAA0B,CAAC,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,2BAA2B,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5F,MAAM,YAAY,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACrG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAAA,CACrE","sourcesContent":["import type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerResultContract } from \"../orchestration/contracts.ts\";\nimport {\n\ttype CreateWorkerResultContractInput,\n\tcreateWorkerResultContract,\n} from \"../orchestration/worker-result-adapter.ts\";\nimport { normalizeWorkerClaimForHost } from \"./worker-claim.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\n\n/**\n * One terminal boundary for every worker execution adapter. It creates the fenced result, commits\n * it through the durable lifecycle, and returns the event-driven handoff token without owning UI.\n */\nexport interface FinalizeWorkerClaimInput extends CreateWorkerResultContractInput {\n\t/** Verification dispatch owns the next terminal signal until it reconciles the subject. */\n\tnotify?: boolean;\n}\n\nexport interface FinalizedWorkerClaim {\n\tresult: WorkerResultContract;\n\trecord: LaneRecord;\n\tnotification?: { notificationId: string; status: \"pending\" | \"delivered\"; record: LaneRecord };\n}\n\nexport function finalizeWorkerClaim(lifecycle: WorkerLifecycle, input: FinalizeWorkerClaimInput): FinalizedWorkerClaim {\n\tconst { notify, ...resultInput } = input;\n\t// Direct abort/error paths also pass here, so this boundary cannot rely on worker-runner\n\t// normalization. Reject before lifecycle mutation, filesystem observation, or notification.\n\tconst result = createWorkerResultContract({ ...resultInput, claim: normalizeWorkerClaimForHost(resultInput.claim) });\n\tconst record = lifecycle.finish(result, { ...(notify === false ? { notify: false } : {}) });\n\tconst notification = notify === false ? undefined : lifecycle.getTerminalNotification(record.laneId);\n\treturn { result, record, ...(notification ? { notification } : {}) };\n}\n"]}
|