@caupulican/pi-adaptative 0.90.7 → 0.90.12
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 +56 -0
- package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +5 -4
- package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +6 -3
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +1 -0
- package/dist/core/agent-session-contracts.d.ts +2 -0
- 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 +8 -7
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +84 -197
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +7 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +8 -2
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +14 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/context/current-work-memory.d.ts +1 -1
- package/dist/core/context/current-work-memory.d.ts.map +1 -1
- package/dist/core/context/current-work-memory.js +2 -1
- package/dist/core/context/current-work-memory.js.map +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
- package/dist/core/context/long-term-memory-trigger.js +2 -1
- package/dist/core/context/long-term-memory-trigger.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +2 -2
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +13 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +71 -8
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +13 -8
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +14 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +3 -2
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +95 -42
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +5 -1
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +7 -4
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +8 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts +21 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +65 -2
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +7 -0
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +24 -7
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-system-prompt.d.ts +54 -0
- package/dist/core/delegation/worker-system-prompt.d.ts.map +1 -0
- package/dist/core/delegation/worker-system-prompt.js +85 -0
- package/dist/core/delegation/worker-system-prompt.js.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +4 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +4 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +28 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.js +14 -3
- package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
- package/dist/core/extension-binding-controller.d.ts +107 -0
- package/dist/core/extension-binding-controller.d.ts.map +1 -0
- package/dist/core/extension-binding-controller.js +224 -0
- package/dist/core/extension-binding-controller.js.map +1 -0
- package/dist/core/extensions/extension-session-scope.d.ts +17 -0
- package/dist/core/extensions/extension-session-scope.d.ts.map +1 -0
- package/dist/core/extensions/extension-session-scope.js +135 -0
- package/dist/core/extensions/extension-session-scope.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -0
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts +2 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +10 -4
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.d.ts +9 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +35 -9
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +10 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +2 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-execution-errors.d.ts +18 -0
- package/dist/core/goals/goal-execution-errors.d.ts.map +1 -0
- package/dist/core/goals/goal-execution-errors.js +21 -0
- package/dist/core/goals/goal-execution-errors.js.map +1 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js +3 -3
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +11 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +74 -14
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-state.js +1 -1
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +2 -2
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/natural-language-goal.d.ts +18 -0
- package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
- package/dist/core/goals/natural-language-goal.js +99 -16
- package/dist/core/goals/natural-language-goal.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +10 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +3 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +4 -4
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +8 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +9 -7
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
- package/dist/core/orchestration/worker-model-pins.d.ts +7 -0
- package/dist/core/orchestration/worker-model-pins.d.ts.map +1 -1
- package/dist/core/orchestration/worker-model-pins.js +17 -1
- package/dist/core/orchestration/worker-model-pins.js.map +1 -1
- package/dist/core/provider-request-runtime-controller.d.ts +9 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -1
- package/dist/core/provider-request-runtime-controller.js +17 -3
- package/dist/core/provider-request-runtime-controller.js.map +1 -1
- package/dist/core/provider-tool-text.d.ts +15 -1
- package/dist/core/provider-tool-text.d.ts.map +1 -1
- package/dist/core/provider-tool-text.js +42 -10
- package/dist/core/provider-tool-text.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +1 -1
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +2 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +8 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +6 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +2 -1
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -2
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +4 -2
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +13 -0
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +20 -18
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +7 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +8 -6
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/faultable-fs.d.ts +30 -0
- package/dist/core/util/faultable-fs.d.ts.map +1 -0
- package/dist/core/util/faultable-fs.js +30 -0
- package/dist/core/util/faultable-fs.js.map +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +4 -3
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +2 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +3 -2
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +3 -2
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/extensions.md +1 -0
- package/docs/providers.md +3 -0
- package/docs/settings.md +4 -2
- package/docs/tool-repair.md +1 -0
- 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 +9 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-attempt-executor.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,GAAG,EAA6B,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-attempt-executor.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,GAAG,EAA6B,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACtF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AIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,4BAA4B,GAAG;IACnF,MAAM,EAAE,4BAA4B,CAAC;IACrC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAAC;IACvD,GAAG,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC7C,CAgiBA"}
|
|
@@ -4,14 +4,15 @@ import { compact } from "@caupulican/pi-agent-core/compaction/compaction";
|
|
|
4
4
|
import { classifyFailure, computeRetryDelayMs, sleepAbortable, } from "@caupulican/pi-agent-core/reliability";
|
|
5
5
|
import { sanitizeToolFailureContext } from "@caupulican/pi-agent-core/tool-failure-memory";
|
|
6
6
|
import { addUsage, createEmptyUsage } from "@caupulican/pi-agent-core/usage";
|
|
7
|
+
import { BoundedCompletionFailureError } from "../autonomy/bounded-completion.js";
|
|
7
8
|
import { safeRealpathSync } from "../autonomy/path-scope.js";
|
|
8
|
-
import { composeSubagentSystemPrompt } from "../autonomy/subagent-prompt.js";
|
|
9
9
|
import { attemptUsageFromGatewayUsage, EMPTY_ATTEMPT_USAGE } from "../orchestration/attempt-usage.js";
|
|
10
10
|
import { CapabilityGatewayDeniedError } from "../orchestration/capability-gateway.js";
|
|
11
11
|
import { WorkerActionJournal } from "./worker-action-journal.js";
|
|
12
12
|
import { WorkerConversationOwnershipError } from "./worker-conversation-revision.js";
|
|
13
13
|
import { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from "./worker-provider-turn-protocol.js";
|
|
14
14
|
import { runWorker } from "./worker-runner.js";
|
|
15
|
+
import { buildWorkerSystemPrompt } from "./worker-system-prompt.js";
|
|
15
16
|
import { WorkerTreeBudgetExceededError } from "./worker-tree-budget-coordinator.js";
|
|
16
17
|
/**
|
|
17
18
|
* Backoff policy for transient worker provider failures. Without it, a dropped provider socket
|
|
@@ -40,15 +41,18 @@ export async function runProviderCompletionWithBackoff(args) {
|
|
|
40
41
|
if (error instanceof WorkerCompletionProtocolError ||
|
|
41
42
|
error instanceof WorkerConversationOwnershipError ||
|
|
42
43
|
error instanceof CapabilityGatewayDeniedError ||
|
|
43
|
-
error instanceof WorkerTreeBudgetExceededError
|
|
44
|
+
error instanceof WorkerTreeBudgetExceededError ||
|
|
45
|
+
error instanceof BoundedCompletionFailureError) {
|
|
44
46
|
throw error;
|
|
45
47
|
}
|
|
46
48
|
const classified = classifyFailure({
|
|
47
49
|
message: error instanceof Error ? error.message : String(error),
|
|
48
50
|
provider: args.provider,
|
|
49
51
|
});
|
|
50
|
-
if (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts)
|
|
51
|
-
|
|
52
|
+
if (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts) {
|
|
53
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
54
|
+
throw new BoundedCompletionFailureError("failed", "completion_error", message, error);
|
|
55
|
+
}
|
|
52
56
|
const delayMs = computeRetryDelayMs(WORKER_PROVIDER_RETRY_POLICY, attempt, {
|
|
53
57
|
...(classified.retryAfterMs !== undefined ? { retryAfterMs: classified.retryAfterMs } : {}),
|
|
54
58
|
});
|
|
@@ -393,11 +397,12 @@ export function createWorkerAttemptExecutor(options) {
|
|
|
393
397
|
let result;
|
|
394
398
|
try {
|
|
395
399
|
result = await options.runIsolatedCompletion({
|
|
396
|
-
systemPrompt:
|
|
400
|
+
systemPrompt: buildWorkerSystemPrompt({
|
|
397
401
|
soul: options.soul,
|
|
398
|
-
rolePrompt:
|
|
399
|
-
|
|
400
|
-
|
|
402
|
+
rolePrompt: systemPrompt,
|
|
403
|
+
workerResourceSystemPrompt: options.workerResourceSystemPrompt,
|
|
404
|
+
agentDir: options.agentDir,
|
|
405
|
+
model: options.model,
|
|
401
406
|
}),
|
|
402
407
|
history,
|
|
403
408
|
messages: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-attempt-executor.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings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nD,OAAO,EAAE,yBAAyB;4BAClC,gBAAgB,EAAE,uBAAuB;4BACzC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;4BAChC,MAAM,EAAE,OAAO,CAAC,MAAM;4BACtB,IAAI,EAAE,OAAO,CAAC,IAAI;4BAClB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;yBAC7B,CAAC,CAAC;oBACJ,CAAC;4BAAS,CAAC;wBACV,uBAAuB,EAAE,CAAC;oBAC3B,CAAC;oBACD,MAAM,eAAe,GAAG,eAAe,CACtC,sEAAsE,CACtE,CAAC;oBACF,OAAO;wBACN,IAAI,EAAE,UAAU,CAAC,IAAI;wBACrB,OAAO,EAAE,eAAe,CAAC,OAAO;wBAChC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;wBACzC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;wBAC/B,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC;qBACzB,CAAC;gBACH,CAAC;aACD,CAAC,CAAC;YACH,MAAM,KAAK,GAAG,eAAe,CAAC,iEAAiE,CAAC,CAAC;YACjG,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC;QAC/D,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { compact } from \"@caupulican/pi-agent-core/compaction/compaction\";\nimport {\n\tclassifyFailure,\n\tcomputeRetryDelayMs,\n\ttype RetryPolicy,\n\tsleepAbortable,\n} from \"@caupulican/pi-agent-core/reliability\";\nimport { sanitizeToolFailureContext } from \"@caupulican/pi-agent-core/tool-failure-memory\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport { addUsage, createEmptyUsage } from \"@caupulican/pi-agent-core/usage\";\nimport type { Api, AssistantMessage, Message, Model, Usage } from \"@caupulican/pi-ai\";\nimport type { IsolatedCompletionOptions, IsolatedCompletionResult } from \"../agent-session-contracts.ts\";\nimport type { WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport { composeSubagentSystemPrompt } from \"../autonomy/subagent-prompt.ts\";\nimport type { ModelCapabilityProfile } from \"../model-capability.ts\";\nimport { attemptUsageFromGatewayUsage, EMPTY_ATTEMPT_USAGE } from \"../orchestration/attempt-usage.ts\";\nimport { CapabilityGatewayDeniedError, type ProviderBudgetReservation } from \"../orchestration/capability-gateway.ts\";\nimport type { AttemptUsageSnapshot, ExecutionGrant } from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport { WorkerActionJournal } from \"./worker-action-journal.ts\";\nimport type { AppliedActionsReport, WorkerAction } from \"./worker-actions.ts\";\nimport type { WorkerAgentControlCoordinator } from \"./worker-agent-control-coordinator.ts\";\nimport { WorkerConversationOwnershipError } from \"./worker-conversation-revision.ts\";\nimport type { WorkerConversation, WorkerConversationRetentionPolicy } from \"./worker-conversation-store.ts\";\nimport type { WorkerExecutionPlan } from \"./worker-execution-policy.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from \"./worker-provider-turn-protocol.ts\";\nimport { runWorker, type WorkerRunOutcome } from \"./worker-runner.ts\";\nimport { WorkerTreeBudgetExceededError } from \"./worker-tree-budget-coordinator.ts\";\n\nexport interface RecoveredWorkerTerminalCompletion {\n\ttext: string;\n\tusage: Usage;\n\tstopReason: string;\n}\n\n/** The live mutable state that must be visible to session disposal before provider work yields. */\nexport interface WorkerAttemptExecutionLedger {\n\tchangedFiles: Set<string>;\n\tgetUsage(): AttemptUsageSnapshot;\n}\n\nexport interface WorkerAttemptExecutionResult {\n\trawOutcome: WorkerRunOutcome;\n\tusage: AttemptUsageSnapshot;\n\tchangedFiles: readonly string[];\n}\n\n/**\n * Backoff policy for transient worker provider failures. Without it, a dropped provider socket\n * kills the attempt instantly at $0 spend and an immediate re-dispatch hits the same dead\n * connection (field session 019fd4dc: paired $0 `completion_error` lanes ~10s apart). Jitter\n * de-synchronizes sibling workers that all lost the same connection at once.\n */\nconst WORKER_PROVIDER_RETRY_POLICY: RetryPolicy = {\n\tmaxAttempts: 3,\n\tbaseDelayMs: 2_000,\n\tmaxDelayMs: 30_000,\n\tjitterRatio: 0.2,\n};\n\nexport async function runProviderCompletionWithBackoff(args: {\n\tattempt: () => Promise<IsolatedCompletionResult>;\n\t/** Release per-attempt provider reservations before waiting; the final failure is rethrown. */\n\tonAttemptFailure: () => void;\n\tprovider: string;\n\tlaneId: string;\n\twarn: (message: string) => void;\n\tsignal?: AbortSignal;\n}): Promise<IsolatedCompletionResult> {\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\tconst completion = await args.attempt();\n\t\t\tif (completion.stopReason !== \"error\") return completion;\n\t\t\tthrow new Error(\n\t\t\t\tcompletion.errorMessage?.trim() || \"Provider completion stopped with an error without diagnostic detail.\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\targs.onAttemptFailure();\n\t\t\tif (args.signal?.aborted) throw error;\n\t\t\tif (\n\t\t\t\terror instanceof WorkerCompletionProtocolError ||\n\t\t\t\terror instanceof WorkerConversationOwnershipError ||\n\t\t\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\t\t\terror instanceof WorkerTreeBudgetExceededError\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst classified = classifyFailure({\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tprovider: args.provider,\n\t\t\t});\n\t\t\tif (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts) throw error;\n\t\t\tconst delayMs = computeRetryDelayMs(WORKER_PROVIDER_RETRY_POLICY, attempt, {\n\t\t\t\t...(classified.retryAfterMs !== undefined ? { retryAfterMs: classified.retryAfterMs } : {}),\n\t\t\t});\n\t\t\targs.warn(\n\t\t\t\t`Worker ${args.laneId} provider request failed (${classified.reason}); retrying in ${Math.ceil(delayMs / 1000)}s (attempt ${attempt + 1}/${WORKER_PROVIDER_RETRY_POLICY.maxAttempts}).`,\n\t\t\t);\n\t\t\tawait sleepAbortable(delayMs, args.signal);\n\t\t}\n\t}\n}\n\n/**\n * The provider/tool-loop portion of a prepared worker attempt.\n *\n * Admission, durable leasing, grant compilation, terminalization, notification, verification, and\n * scheduling remain outside this boundary. This unit owns only the ordered child conversation:\n * persist assistant tool requests before execution, append messages before mailbox acknowledgements,\n * checkpoint cumulative usage before later boundaries, and compact only the provider projection.\n */\nexport interface WorkerAttemptExecutorOptions {\n\trequest: WorkerRequest;\n\tgrant: ExecutionGrant;\n\texecutionPlan: WorkerExecutionPlan;\n\ttoolSurface: LaneToolSurface;\n\tconversation: WorkerConversation;\n\tlifecycle: Pick<WorkerLifecycle, \"checkpoint\">;\n\tlaneId: string;\n\tagentId: string;\n\tdurableHandle: StartedDelegationAttempt;\n\tparentSessionId: string;\n\tagentDir: string;\n\tcwd: string;\n\tmodel: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tlaneCapability: Pick<ModelCapabilityProfile, \"laneMaxOutputTokens\">;\n\tsoul?: string;\n\tworkerResourceSystemPrompt: string;\n\tinitialUsage: AttemptUsageSnapshot;\n\thasPersistedUsageCheckpoint: boolean;\n\tusageReportId: string;\n\tprocessCapable: boolean;\n\tverificationSubjectTaskId?: string;\n\trecoveredTerminal?: RecoveredWorkerTerminalCompletion;\n\tretentionPolicy?: WorkerConversationRetentionPolicy;\n\tsignal?: AbortSignal;\n\trunIsolatedCompletion(options: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n\tagentControl: Pick<WorkerAgentControlCoordinator, \"acknowledgeMailboxMessage\" | \"mailboxMessagesForConversation\">;\n\tapplyActions?(actions: readonly WorkerAction[], actionJournal?: WorkerActionJournal): AppliedActionsReport;\n\twarn(message: string): void;\n}\n\nfunction isToolRequest(message: Message): boolean {\n\treturn message.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n}\n\nfunction workerCompletionCallbackFailure(error: unknown): Error {\n\tif (\n\t\terror instanceof WorkerCompletionProtocolError ||\n\t\terror instanceof WorkerConversationOwnershipError ||\n\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\terror instanceof WorkerTreeBudgetExceededError\n\t) {\n\t\treturn error;\n\t}\n\treturn new WorkerCompletionProtocolError(\n\t\t\"Worker completion callback failed before its authority and durable transcript were verified.\",\n\t);\n}\n\nfunction callbackEvidencedCompletion(\n\tresult: IsolatedCompletionResult,\n\thistoryLength: number,\n\temittedMessages: readonly Message[],\n): { completion: IsolatedCompletionResult; suffix: Message[] } {\n\tif (result.messages !== undefined && result.messages.length < historyLength) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned fewer messages than its input history.\",\n\t\t);\n\t}\n\tlet suffix: Message[];\n\tif (result.messages !== undefined) {\n\t\tsuffix = result.messages.slice(historyLength);\n\t\tif (!isDeepStrictEqual(suffix, emittedMessages)) {\n\t\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\t\"Worker completion protocol returned a suffix without exact callback evidence.\",\n\t\t\t);\n\t\t}\n\t} else {\n\t\tsuffix = [...emittedMessages];\n\t}\n\tif (suffix.length === 0) {\n\t\tthrow new WorkerCompletionProtocolError(\"Worker completion protocol returned no durable message suffix.\");\n\t}\n\tif (!suffix.some((message) => message.role === \"assistant\")) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned no assistant in its durable suffix.\",\n\t\t);\n\t}\n\tconst assistants = emittedMessages.filter((message): message is AssistantMessage => message.role === \"assistant\");\n\tconst finalMessage = emittedMessages.at(-1);\n\tif (!finalMessage || finalMessage.role !== \"assistant\") {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol did not durably emit an assistant as its terminal message.\",\n\t\t);\n\t}\n\tconst usage = createEmptyUsage();\n\tfor (const assistant of assistants) addUsage(usage, assistant.usage);\n\tconst text = finalMessage.content.flatMap((content) => (content.type === \"text\" ? [content.text] : [])).join(\"\");\n\tif (\n\t\tresult.text !== text ||\n\t\tresult.stopReason !== finalMessage.stopReason ||\n\t\t!isDeepStrictEqual(result.usage, usage) ||\n\t\tresult.errorMessage !== finalMessage.errorMessage\n\t) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion result disagrees with its durable callback-evidenced terminal assistant.\",\n\t\t);\n\t}\n\treturn {\n\t\tsuffix,\n\t\tcompletion: {\n\t\t\ttext,\n\t\t\tusage,\n\t\t\tstopReason: finalMessage.stopReason,\n\t\t\t...(finalMessage.errorMessage ? { errorMessage: finalMessage.errorMessage } : {}),\n\t\t},\n\t};\n}\n\n/**\n * Constructs one execution exactly once. The caller registers {@link ledger} before calling\n * {@link run}, allowing synchronous disposal to observe mutations and cumulative usage while the\n * provider/tool loop is suspended.\n */\nexport function createWorkerAttemptExecutor(options: WorkerAttemptExecutorOptions): {\n\tledger: WorkerAttemptExecutionLedger;\n\tcheckpointUsage(summary: string): AttemptUsageSnapshot;\n\trun(): Promise<WorkerAttemptExecutionResult>;\n} {\n\tconst changedFiles = new Set(options.conversation.getChangedFiles(options.durableHandle.attemptId));\n\tconst toolIssues = new Set<string>();\n\tconst recordChangedFile = (filePath: string): void => {\n\t\tchangedFiles.add(filePath);\n\t\ttry {\n\t\t\toptions.conversation.recordChangedFile(options.durableHandle.attemptId, filePath);\n\t\t} catch (error) {\n\t\t\ttoolIssues.add(\"worker changed-file progress could not be persisted; parent review is required\");\n\t\t\toptions.warn(\n\t\t\t\t`Worker changed-file progress persistence failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t};\n\tconst actionJournal = options.request.envelope.capabilities.includes(\"filesystem.write\")\n\t\t? new WorkerActionJournal({\n\t\t\t\tagentDir: options.agentDir,\n\t\t\t\tparentSessionId: options.parentSessionId,\n\t\t\t\ttaskId: options.durableHandle.taskId,\n\t\t\t\tattemptId: options.durableHandle.attemptId,\n\t\t\t\tfencingToken: options.durableHandle.fencingToken,\n\t\t\t})\n\t\t: undefined;\n\tlet retentionWarningEmitted = false;\n\tlet firstMailboxPoll = true;\n\tlet ran = false;\n\n\tconst currentUsage = (): AttemptUsageSnapshot =>\n\t\tattemptUsageFromGatewayUsage(\n\t\t\toptions.toolSurface.gateway?.getUsage() ?? {\n\t\t\t\t...EMPTY_ATTEMPT_USAGE,\n\t\t\t\twallClockMs: options.initialUsage.activeWallClockMs,\n\t\t\t},\n\t\t);\n\tconst checkpointUsage = (summary: string): AttemptUsageSnapshot => {\n\t\tconst usage = currentUsage();\n\t\toptions.lifecycle.checkpoint(options.laneId, { summary, usage });\n\t\treturn usage;\n\t};\n\tconst remainingAttemptTokens = (): number | undefined => options.toolSurface.gateway?.remainingAttemptTokenBudget();\n\tconst reserveProviderBudget = async (\n\t\trequestedMaxTokens: number,\n\t\tsubject: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<ProviderBudgetReservation> => {\n\t\tif (options.toolSurface.gateway) {\n\t\t\treturn options.toolSurface.gateway.reserveProviderBudget(requestedMaxTokens, subject, signal);\n\t\t}\n\t\tif (signal?.aborted) throw signal.reason;\n\t\treturn { maxTokens: requestedMaxTokens, release: () => undefined };\n\t};\n\tconst createRetentionPolicy = (completeSignal: AbortSignal): WorkerConversationRetentionPolicy | undefined => {\n\t\tif (!options.retentionPolicy) return undefined;\n\t\tlet failedCompactionUsage: Usage | undefined;\n\t\treturn {\n\t\t\t...options.retentionPolicy,\n\t\t\tgenerateVerifiedCompaction: async (preparation: Parameters<typeof compact>[0]) => {\n\t\t\t\tconst compactionUsage = createEmptyUsage();\n\t\t\t\tfailedCompactionUsage = compactionUsage;\n\t\t\t\treturn compact(\n\t\t\t\t\tpreparation,\n\t\t\t\t\toptions.model,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tcompleteSignal,\n\t\t\t\t\toptions.thinkingLevel,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\t{\n\t\t\t\t\t\tcompletion: async (model, context, requestOptions): Promise<AssistantMessage> => {\n\t\t\t\t\t\t\tconst requestSignal = requestOptions.signal ?? completeSignal;\n\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\tif (model.provider !== options.model.provider || model.id !== options.model.id) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction attempted to select a model outside the lane binding.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_compaction_provider_completion\");\n\t\t\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before compaction provider completion.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst requestedMaxTokens = requestOptions.maxTokens;\n\t\t\t\t\t\t\tconst configuredMaxTokens =\n\t\t\t\t\t\t\t\ttypeof requestedMaxTokens === \"number\" &&\n\t\t\t\t\t\t\t\tNumber.isSafeInteger(requestedMaxTokens) &&\n\t\t\t\t\t\t\t\trequestedMaxTokens > 0\n\t\t\t\t\t\t\t\t\t? requestedMaxTokens\n\t\t\t\t\t\t\t\t\t: options.laneCapability.laneMaxOutputTokens;\n\t\t\t\t\t\t\tconst maxTokens = Math.min(configuredMaxTokens, availableTokens ?? configuredMaxTokens);\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(maxTokens) || maxTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction provider completion has no valid remaining token budget.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet preflightFailed = false;\n\t\t\t\t\t\t\tlet preflightFailure: unknown;\n\t\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\t\treserveProviderBudget(maxTokens, \"worker_compaction_provider_completion\", requestSignal),\n\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\tonFailure: (error) => {\n\t\t\t\t\t\t\t\t\tif (preflightFailed) return;\n\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tcompletion = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\t\tsystemPrompt: context.systemPrompt ?? \"\",\n\t\t\t\t\t\t\t\t\t\tmessages: context.messages,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\t\tmaxTokens,\n\t\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\t\t\t\t\t\tlaneKind: \"worker-compaction\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tconst response: AssistantMessage = {\n\t\t\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\t\t\tcontent: completion.text ? [{ type: \"text\", text: completion.text }] : [],\n\t\t\t\t\t\t\t\t\tapi: options.model.api,\n\t\t\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\t\t\tmodel: options.model.id,\n\t\t\t\t\t\t\t\t\tusage: completion.usage,\n\t\t\t\t\t\t\t\t\tstopReason: completion.stopReason,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\t...(completion.stopReason === \"error\"\n\t\t\t\t\t\t\t\t\t\t? { errorMessage: completion.text || \"Worker compaction provider request failed.\" }\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\taddUsage(compactionUsage, completion.usage);\n\t\t\t\t\t\t\t\tif (providerTurn.hasOutstandingAssistantReservation()) {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(completion.usage);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountUnverifiedResultUsageDelta(completion.usage);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker compaction provider usage before verification.\");\n\t\t\t\t\t\t\t\tif (providerTurn.hasSuccessfulPreflight()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tif (!preflightFailed) {\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight(\"compaction\");\n\t\t\t\t\t\t\t\treturn response;\n\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\tproviderTurn.close();\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\t);\n\t\t\t},\n\t\t\tgetFailedCompactionUsage: () => failedCompactionUsage,\n\t\t};\n\t};\n\tconst ledger: WorkerAttemptExecutionLedger = {\n\t\tchangedFiles,\n\t\tgetUsage: currentUsage,\n\t};\n\n\treturn {\n\t\tledger,\n\t\tcheckpointUsage,\n\t\tasync run(): Promise<WorkerAttemptExecutionResult> {\n\t\t\tif (ran) throw new Error(\"A worker attempt executor may run only once.\");\n\t\t\tran = true;\n\t\t\toptions.conversation.beginAttemptUsage(options.durableHandle.attemptId);\n\t\t\tif (!options.hasPersistedUsageCheckpoint) {\n\t\t\t\tcheckpointUsage(\"Persisted deterministic cumulative usage baseline for the durable worker transcript.\");\n\t\t\t}\n\t\t\tconst rawOutcome = await runWorker({\n\t\t\t\trequest: options.request,\n\t\t\t\tmaxUsd: options.grant.budget.maxCostUsd,\n\t\t\t\tmaxWallClockMs: options.grant.budget.maxWallClockMs ?? 0,\n\t\t\t\tusageReportId: options.usageReportId,\n\t\t\t\tgetChangedFiles: () => [...changedFiles],\n\t\t\t\tsignal: options.signal,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tprocessCapable: options.processCapable,\n\t\t\t\tdelegationCapable: options.toolSurface.allowedTools.includes(\"delegate\"),\n\t\t\t\t...(options.verificationSubjectTaskId\n\t\t\t\t\t? { verificationSubjectTaskId: options.verificationSubjectTaskId }\n\t\t\t\t\t: {}),\n\t\t\t\t...(options.applyActions\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tapplyActions: (actions: readonly WorkerAction[]) => {\n\t\t\t\t\t\t\t\tconst report = options.applyActions!(actions, actionJournal);\n\t\t\t\t\t\t\t\tfor (const filePath of report.changedFiles) recordChangedFile(filePath);\n\t\t\t\t\t\t\t\treturn report;\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\tcomplete: async ({ systemPrompt, userPrompt, signal }) => {\n\t\t\t\t\tif (options.recoveredTerminal) {\n\t\t\t\t\t\tcheckpointUsage(\"Reused the persisted terminal worker assistant response after recovery.\");\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: options.recoveredTerminal.text,\n\t\t\t\t\t\t\tcostUsd: options.initialUsage.costUsd,\n\t\t\t\t\t\t\tstopReason: options.recoveredTerminal.stopReason,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst retentionPolicy = createRetentionPolicy(signal);\n\t\t\t\t\tconst persistedToolAssistantIds = new Set<string>();\n\t\t\t\t\tconst pendingToolAssistants = new Map<string, AssistantMessage>();\n\t\t\t\t\tlet activeProviderTurn: WorkerProviderTurnProtocol | undefined;\n\t\t\t\t\tconst closeActiveProviderTurn = (): void => {\n\t\t\t\t\t\tconst active = activeProviderTurn;\n\t\t\t\t\t\tactiveProviderTurn = undefined;\n\t\t\t\t\t\tactive?.close();\n\t\t\t\t\t};\n\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_provider_completion\");\n\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before provider completion.\");\n\t\t\t\t\t}\n\t\t\t\t\toptions.conversation.ensureAttemptUserPrompt(options.durableHandle.attemptId, userPrompt);\n\t\t\t\t\tlet history: Message[] = [];\n\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\tconst attemptProviderCompletion = async (): Promise<IsolatedCompletionResult> => {\n\t\t\t\t\t\t// Later attempts resume from the durably persisted transcript, not a stale snapshot.\n\t\t\t\t\t\tconst transcriptCommit = options.conversation.beginTranscriptCommit();\n\t\t\t\t\t\thistory = transcriptCommit.history;\n\t\t\t\t\t\tconst historyLength = history.length;\n\t\t\t\t\t\tconst transcriptCursor = transcriptCommit.cursor;\n\t\t\t\t\t\tconst durableCallbackMessages: Message[] = [];\n\t\t\t\t\t\tlet callbackFailed = false;\n\t\t\t\t\t\tlet callbackFailure: unknown;\n\t\t\t\t\t\tconst retainCallbackFailure = (error: unknown): void => {\n\t\t\t\t\t\t\tif (callbackFailed) return;\n\t\t\t\t\t\t\tcallbackFailed = true;\n\t\t\t\t\t\t\tcallbackFailure = error;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\treserveProviderBudget(\n\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\"worker_provider_completion\",\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\tonFailure: retainCallbackFailure,\n\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tactiveProviderTurn = providerTurn;\n\t\t\t\t\t\tconst persistToolRequest = (message: AssistantMessage): void => {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst toolCallIds = message.content.flatMap((content) =>\n\t\t\t\t\t\t\t\tcontent.type === \"toolCall\" ? [content.id] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (toolCallIds.length === 0 || toolCallIds.every((id) => persistedToolAssistantIds.has(id)))\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\tfor (const id of toolCallIds) {\n\t\t\t\t\t\t\t\tpersistedToolAssistantIds.add(id);\n\t\t\t\t\t\t\t\tpendingToolAssistants.delete(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker assistant tool request and its cumulative provider usage.\");\n\t\t\t\t\t\t\tproviderTurn.consumeToolAssistantAndRelease();\n\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tlet committed = false;\n\t\t\t\t\t\tconst abortTranscriptCursor = (): void => {\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\toptions.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", abortTranscriptCursor, { once: true });\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tlet result: IsolatedCompletionResult;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tresult = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\tsystemPrompt: composeSubagentSystemPrompt({\n\t\t\t\t\t\t\t\t\t\tsoul: options.soul,\n\t\t\t\t\t\t\t\t\t\trolePrompt: [systemPrompt, options.workerResourceSystemPrompt]\n\t\t\t\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t\t\t\t.join(\"\\n\\n\"),\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\tmaxTokens: Math.min(\n\t\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\tavailableTokens ?? Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\ttools: options.toolSurface.tools,\n\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\tbeforeToolCall: async (context, toolSignal) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tpersistToolRequest(context.assistantMessage);\n\t\t\t\t\t\t\t\t\t\t\tconst decision = await options.toolSurface.beforeToolCall(context, toolSignal);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (!decision?.block) {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t`Authorized worker tool '${context.toolCall.name}' under its durable grant.`,\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn decision;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tafterToolCall: async ({ toolCall, args }) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t(toolCall.name === \"write\" || toolCall.name === \"edit\") &&\n\t\t\t\t\t\t\t\t\t\t\t\targs &&\n\t\t\t\t\t\t\t\t\t\t\t\ttypeof args === \"object\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!Array.isArray(args)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst rawPath = (args as Record<string, unknown>).path;\n\t\t\t\t\t\t\t\t\t\t\t\tif (typeof rawPath === \"string\" && rawPath.length > 0) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconst absolutePath = path.isAbsolute(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? path.resolve(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: path.resolve(options.cwd, rawPath);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet canonicalPath = absolutePath;\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcanonicalPath = safeRealpathSync(absolutePath);\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// The operation entered execution; retain its lexical target if canonicalization failed.\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trecordChangedFile(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath.relative(options.cwd, canonicalPath).split(path.sep).join(\"/\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonMessage: (message) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && isToolRequest(message)) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Known calls are normalized before beforeToolCall and persist from that hook.\n\t\t\t\t\t\t\t\t\t\t\t\t// Retain the request only so immediate unknown/malformed results can close the\n\t\t\t\t\t\t\t\t\t\t\t\t// transcript without freezing pre-repair arguments into durable history.\n\t\t\t\t\t\t\t\t\t\t\t\tfor (const content of message.content) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (content.type === \"toolCall\") pendingToolAssistants.set(content.id, message);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\tmessage.role === \"toolResult\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!persistedToolAssistantIds.has(message.toolCallId)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst pending = pendingToolAssistants.get(message.toolCallId);\n\t\t\t\t\t\t\t\t\t\t\t\tif (pending) persistToolRequest(pending);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\") {\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\t\t\t\t\toptions.agentControl.acknowledgeMailboxMessage(options.agentId, message);\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Persisted worker assistant response and its cumulative provider usage.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"toolResult\")\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(`Persisted worker tool result '${message.toolCallId}'.`);\n\t\t\t\t\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetSteeringMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst includeFollowUp = firstMailboxPoll;\n\t\t\t\t\t\t\t\t\t\t\tfirstMailboxPoll = false;\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\tincludeFollowUp,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetFollowUpMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t...(retentionPolicy\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\ttransformContext: async (messages: AgentMessage[]) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconst retained = await options.conversation.compactProviderContext(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionPolicy,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.contextUsage.tokens > retentionPolicy.maxContextTokens &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t!retentionWarningEmitted\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker ${options.laneId} has one retained turn larger than its context policy; provider overflow recovery may be required.`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_verified\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_deterministic\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn sanitizeToolFailureContext(retained.context.messages, \"\").messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (error instanceof WorkerConversationOwnershipError) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!retentionWarningEmitted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker context retention failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\tcacheRetention: \"short\",\n\t\t\t\t\t\t\t\t\tlaneKind: \"worker\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\tif (signal.aborted) throw error;\n\t\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tproviderTurn.assertEverySuccessfulPreflightConsumed();\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tif (providerTurn.accountUnverifiedResultUsageDelta(result.usage)) {\n\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\"Persisted supplemental provider result usage before rejecting unverified completion evidence.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight();\n\t\t\t\t\t\t\tconst evidenced = callbackEvidencedCompletion(result, historyLength, durableCallbackMessages);\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst appended = options.conversation.commitTranscript(transcriptCursor, evidenced.suffix, {\n\t\t\t\t\t\t\t\tappendMissing: false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (appended !== 0) {\n\t\t\t\t\t\t\t\tthrow new WorkerConversationOwnershipError(\n\t\t\t\t\t\t\t\t\t\"Worker callback transcript verification unexpectedly appended missing messages.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcommitted = true;\n\t\t\t\t\t\t\treturn evidenced.completion;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abortTranscriptCursor);\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (activeProviderTurn === providerTurn) activeProviderTurn = undefined;\n\t\t\t\t\t\t\tif (!committed) options.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcompletion = await runProviderCompletionWithBackoff({\n\t\t\t\t\t\t\tattempt: attemptProviderCompletion,\n\t\t\t\t\t\t\tonAttemptFailure: closeActiveProviderTurn,\n\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\tlaneId: options.laneId,\n\t\t\t\t\t\t\twarn: options.warn,\n\t\t\t\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tcloseActiveProviderTurn();\n\t\t\t\t\t}\n\t\t\t\t\tconst cumulativeUsage = checkpointUsage(\n\t\t\t\t\t\t\"Verified the callback-persisted worker conversation terminal suffix.\",\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: completion.text,\n\t\t\t\t\t\tcostUsd: cumulativeUsage.costUsd,\n\t\t\t\t\t\tstopReason: String(completion.stopReason),\n\t\t\t\t\t\tchangedFiles: [...changedFiles],\n\t\t\t\t\t\tblockers: [...toolIssues],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst usage = checkpointUsage(\"Persisted final cumulative worker usage before terminal result.\");\n\t\t\treturn { rawOutcome, usage, changedFiles: [...changedFiles] };\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-attempt-executor.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAC1E,OAAO,EACN,eAAe,EACf,mBAAmB,EAEnB,cAAc,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAG7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,4BAA4B,EAAkC,MAAM,wCAAwC,CAAC;AAGtH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAIrF,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAoBpF;;;;;GAKG;AACH,MAAM,4BAA4B,GAAgB;IACjD,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,GAAG;CAChB,CAAC;AAEF,MAAM,CAAC,KAA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UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC;QAC/D,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { compact } from \"@caupulican/pi-agent-core/compaction/compaction\";\nimport {\n\tclassifyFailure,\n\tcomputeRetryDelayMs,\n\ttype RetryPolicy,\n\tsleepAbortable,\n} from \"@caupulican/pi-agent-core/reliability\";\nimport { sanitizeToolFailureContext } from \"@caupulican/pi-agent-core/tool-failure-memory\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport { addUsage, createEmptyUsage } from \"@caupulican/pi-agent-core/usage\";\nimport type { Api, AssistantMessage, Message, Model, Usage } from \"@caupulican/pi-ai\";\nimport type { IsolatedCompletionOptions, IsolatedCompletionResult } from \"../agent-session-contracts.ts\";\nimport { BoundedCompletionFailureError } from \"../autonomy/bounded-completion.ts\";\nimport type { WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport type { ModelCapabilityProfile } from \"../model-capability.ts\";\nimport { attemptUsageFromGatewayUsage, EMPTY_ATTEMPT_USAGE } from \"../orchestration/attempt-usage.ts\";\nimport { CapabilityGatewayDeniedError, type ProviderBudgetReservation } from \"../orchestration/capability-gateway.ts\";\nimport type { AttemptUsageSnapshot, ExecutionGrant } from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport { WorkerActionJournal } from \"./worker-action-journal.ts\";\nimport type { AppliedActionsReport, WorkerAction } from \"./worker-actions.ts\";\nimport type { WorkerAgentControlCoordinator } from \"./worker-agent-control-coordinator.ts\";\nimport { WorkerConversationOwnershipError } from \"./worker-conversation-revision.ts\";\nimport type { WorkerConversation, WorkerConversationRetentionPolicy } from \"./worker-conversation-store.ts\";\nimport type { WorkerExecutionPlan } from \"./worker-execution-policy.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from \"./worker-provider-turn-protocol.ts\";\nimport { runWorker, type WorkerRunOutcome } from \"./worker-runner.ts\";\nimport { buildWorkerSystemPrompt } from \"./worker-system-prompt.ts\";\nimport { WorkerTreeBudgetExceededError } from \"./worker-tree-budget-coordinator.ts\";\n\nexport interface RecoveredWorkerTerminalCompletion {\n\ttext: string;\n\tusage: Usage;\n\tstopReason: string;\n}\n\n/** The live mutable state that must be visible to session disposal before provider work yields. */\nexport interface WorkerAttemptExecutionLedger {\n\tchangedFiles: Set<string>;\n\tgetUsage(): AttemptUsageSnapshot;\n}\n\nexport interface WorkerAttemptExecutionResult {\n\trawOutcome: WorkerRunOutcome;\n\tusage: AttemptUsageSnapshot;\n\tchangedFiles: readonly string[];\n}\n\n/**\n * Backoff policy for transient worker provider failures. Without it, a dropped provider socket\n * kills the attempt instantly at $0 spend and an immediate re-dispatch hits the same dead\n * connection (field session 019fd4dc: paired $0 `completion_error` lanes ~10s apart). Jitter\n * de-synchronizes sibling workers that all lost the same connection at once.\n */\nconst WORKER_PROVIDER_RETRY_POLICY: RetryPolicy = {\n\tmaxAttempts: 3,\n\tbaseDelayMs: 2_000,\n\tmaxDelayMs: 30_000,\n\tjitterRatio: 0.2,\n};\n\nexport async function runProviderCompletionWithBackoff(args: {\n\tattempt: () => Promise<IsolatedCompletionResult>;\n\t/** Release per-attempt provider reservations before waiting; the final failure is rethrown. */\n\tonAttemptFailure: () => void;\n\tprovider: string;\n\tlaneId: string;\n\twarn: (message: string) => void;\n\tsignal?: AbortSignal;\n}): Promise<IsolatedCompletionResult> {\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\tconst completion = await args.attempt();\n\t\t\tif (completion.stopReason !== \"error\") return completion;\n\t\t\tthrow new Error(\n\t\t\t\tcompletion.errorMessage?.trim() || \"Provider completion stopped with an error without diagnostic detail.\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\targs.onAttemptFailure();\n\t\t\tif (args.signal?.aborted) throw error;\n\t\t\tif (\n\t\t\t\terror instanceof WorkerCompletionProtocolError ||\n\t\t\t\terror instanceof WorkerConversationOwnershipError ||\n\t\t\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\t\t\terror instanceof WorkerTreeBudgetExceededError ||\n\t\t\t\terror instanceof BoundedCompletionFailureError\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst classified = classifyFailure({\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tprovider: args.provider,\n\t\t\t});\n\t\t\tif (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"completion_error\", message, error);\n\t\t\t}\n\t\t\tconst delayMs = computeRetryDelayMs(WORKER_PROVIDER_RETRY_POLICY, attempt, {\n\t\t\t\t...(classified.retryAfterMs !== undefined ? { retryAfterMs: classified.retryAfterMs } : {}),\n\t\t\t});\n\t\t\targs.warn(\n\t\t\t\t`Worker ${args.laneId} provider request failed (${classified.reason}); retrying in ${Math.ceil(delayMs / 1000)}s (attempt ${attempt + 1}/${WORKER_PROVIDER_RETRY_POLICY.maxAttempts}).`,\n\t\t\t);\n\t\t\tawait sleepAbortable(delayMs, args.signal);\n\t\t}\n\t}\n}\n\n/**\n * The provider/tool-loop portion of a prepared worker attempt.\n *\n * Admission, durable leasing, grant compilation, terminalization, notification, verification, and\n * scheduling remain outside this boundary. This unit owns only the ordered child conversation:\n * persist assistant tool requests before execution, append messages before mailbox acknowledgements,\n * checkpoint cumulative usage before later boundaries, and compact only the provider projection.\n */\nexport interface WorkerAttemptExecutorOptions {\n\trequest: WorkerRequest;\n\tgrant: ExecutionGrant;\n\texecutionPlan: WorkerExecutionPlan;\n\ttoolSurface: LaneToolSurface;\n\tconversation: WorkerConversation;\n\tlifecycle: Pick<WorkerLifecycle, \"checkpoint\">;\n\tlaneId: string;\n\tagentId: string;\n\tdurableHandle: StartedDelegationAttempt;\n\tparentSessionId: string;\n\tagentDir: string;\n\tcwd: string;\n\tmodel: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tlaneCapability: Pick<ModelCapabilityProfile, \"laneMaxOutputTokens\">;\n\tsoul?: string;\n\tworkerResourceSystemPrompt: string;\n\tinitialUsage: AttemptUsageSnapshot;\n\thasPersistedUsageCheckpoint: boolean;\n\tusageReportId: string;\n\tprocessCapable: boolean;\n\tverificationSubjectTaskId?: string;\n\trecoveredTerminal?: RecoveredWorkerTerminalCompletion;\n\tretentionPolicy?: WorkerConversationRetentionPolicy;\n\tsignal?: AbortSignal;\n\trunIsolatedCompletion(options: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n\tagentControl: Pick<WorkerAgentControlCoordinator, \"acknowledgeMailboxMessage\" | \"mailboxMessagesForConversation\">;\n\tapplyActions?(actions: readonly WorkerAction[], actionJournal?: WorkerActionJournal): AppliedActionsReport;\n\twarn(message: string): void;\n}\n\nfunction isToolRequest(message: Message): boolean {\n\treturn message.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n}\n\nfunction workerCompletionCallbackFailure(error: unknown): Error {\n\tif (\n\t\terror instanceof WorkerCompletionProtocolError ||\n\t\terror instanceof WorkerConversationOwnershipError ||\n\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\terror instanceof WorkerTreeBudgetExceededError\n\t) {\n\t\treturn error;\n\t}\n\treturn new WorkerCompletionProtocolError(\n\t\t\"Worker completion callback failed before its authority and durable transcript were verified.\",\n\t);\n}\n\nfunction callbackEvidencedCompletion(\n\tresult: IsolatedCompletionResult,\n\thistoryLength: number,\n\temittedMessages: readonly Message[],\n): { completion: IsolatedCompletionResult; suffix: Message[] } {\n\tif (result.messages !== undefined && result.messages.length < historyLength) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned fewer messages than its input history.\",\n\t\t);\n\t}\n\tlet suffix: Message[];\n\tif (result.messages !== undefined) {\n\t\tsuffix = result.messages.slice(historyLength);\n\t\tif (!isDeepStrictEqual(suffix, emittedMessages)) {\n\t\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\t\"Worker completion protocol returned a suffix without exact callback evidence.\",\n\t\t\t);\n\t\t}\n\t} else {\n\t\tsuffix = [...emittedMessages];\n\t}\n\tif (suffix.length === 0) {\n\t\tthrow new WorkerCompletionProtocolError(\"Worker completion protocol returned no durable message suffix.\");\n\t}\n\tif (!suffix.some((message) => message.role === \"assistant\")) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned no assistant in its durable suffix.\",\n\t\t);\n\t}\n\tconst assistants = emittedMessages.filter((message): message is AssistantMessage => message.role === \"assistant\");\n\tconst finalMessage = emittedMessages.at(-1);\n\tif (!finalMessage || finalMessage.role !== \"assistant\") {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol did not durably emit an assistant as its terminal message.\",\n\t\t);\n\t}\n\tconst usage = createEmptyUsage();\n\tfor (const assistant of assistants) addUsage(usage, assistant.usage);\n\tconst text = finalMessage.content.flatMap((content) => (content.type === \"text\" ? [content.text] : [])).join(\"\");\n\tif (\n\t\tresult.text !== text ||\n\t\tresult.stopReason !== finalMessage.stopReason ||\n\t\t!isDeepStrictEqual(result.usage, usage) ||\n\t\tresult.errorMessage !== finalMessage.errorMessage\n\t) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion result disagrees with its durable callback-evidenced terminal assistant.\",\n\t\t);\n\t}\n\treturn {\n\t\tsuffix,\n\t\tcompletion: {\n\t\t\ttext,\n\t\t\tusage,\n\t\t\tstopReason: finalMessage.stopReason,\n\t\t\t...(finalMessage.errorMessage ? { errorMessage: finalMessage.errorMessage } : {}),\n\t\t},\n\t};\n}\n\n/**\n * Constructs one execution exactly once. The caller registers {@link ledger} before calling\n * {@link run}, allowing synchronous disposal to observe mutations and cumulative usage while the\n * provider/tool loop is suspended.\n */\nexport function createWorkerAttemptExecutor(options: WorkerAttemptExecutorOptions): {\n\tledger: WorkerAttemptExecutionLedger;\n\tcheckpointUsage(summary: string): AttemptUsageSnapshot;\n\trun(): Promise<WorkerAttemptExecutionResult>;\n} {\n\tconst changedFiles = new Set(options.conversation.getChangedFiles(options.durableHandle.attemptId));\n\tconst toolIssues = new Set<string>();\n\tconst recordChangedFile = (filePath: string): void => {\n\t\tchangedFiles.add(filePath);\n\t\ttry {\n\t\t\toptions.conversation.recordChangedFile(options.durableHandle.attemptId, filePath);\n\t\t} catch (error) {\n\t\t\ttoolIssues.add(\"worker changed-file progress could not be persisted; parent review is required\");\n\t\t\toptions.warn(\n\t\t\t\t`Worker changed-file progress persistence failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t};\n\tconst actionJournal = options.request.envelope.capabilities.includes(\"filesystem.write\")\n\t\t? new WorkerActionJournal({\n\t\t\t\tagentDir: options.agentDir,\n\t\t\t\tparentSessionId: options.parentSessionId,\n\t\t\t\ttaskId: options.durableHandle.taskId,\n\t\t\t\tattemptId: options.durableHandle.attemptId,\n\t\t\t\tfencingToken: options.durableHandle.fencingToken,\n\t\t\t})\n\t\t: undefined;\n\tlet retentionWarningEmitted = false;\n\tlet firstMailboxPoll = true;\n\tlet ran = false;\n\n\tconst currentUsage = (): AttemptUsageSnapshot =>\n\t\tattemptUsageFromGatewayUsage(\n\t\t\toptions.toolSurface.gateway?.getUsage() ?? {\n\t\t\t\t...EMPTY_ATTEMPT_USAGE,\n\t\t\t\twallClockMs: options.initialUsage.activeWallClockMs,\n\t\t\t},\n\t\t);\n\tconst checkpointUsage = (summary: string): AttemptUsageSnapshot => {\n\t\tconst usage = currentUsage();\n\t\toptions.lifecycle.checkpoint(options.laneId, { summary, usage });\n\t\treturn usage;\n\t};\n\tconst remainingAttemptTokens = (): number | undefined => options.toolSurface.gateway?.remainingAttemptTokenBudget();\n\tconst reserveProviderBudget = async (\n\t\trequestedMaxTokens: number,\n\t\tsubject: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<ProviderBudgetReservation> => {\n\t\tif (options.toolSurface.gateway) {\n\t\t\treturn options.toolSurface.gateway.reserveProviderBudget(requestedMaxTokens, subject, signal);\n\t\t}\n\t\tif (signal?.aborted) throw signal.reason;\n\t\treturn { maxTokens: requestedMaxTokens, release: () => undefined };\n\t};\n\tconst createRetentionPolicy = (completeSignal: AbortSignal): WorkerConversationRetentionPolicy | undefined => {\n\t\tif (!options.retentionPolicy) return undefined;\n\t\tlet failedCompactionUsage: Usage | undefined;\n\t\treturn {\n\t\t\t...options.retentionPolicy,\n\t\t\tgenerateVerifiedCompaction: async (preparation: Parameters<typeof compact>[0]) => {\n\t\t\t\tconst compactionUsage = createEmptyUsage();\n\t\t\t\tfailedCompactionUsage = compactionUsage;\n\t\t\t\treturn compact(\n\t\t\t\t\tpreparation,\n\t\t\t\t\toptions.model,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tcompleteSignal,\n\t\t\t\t\toptions.thinkingLevel,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\t{\n\t\t\t\t\t\tcompletion: async (model, context, requestOptions): Promise<AssistantMessage> => {\n\t\t\t\t\t\t\tconst requestSignal = requestOptions.signal ?? completeSignal;\n\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\tif (model.provider !== options.model.provider || model.id !== options.model.id) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction attempted to select a model outside the lane binding.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_compaction_provider_completion\");\n\t\t\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before compaction provider completion.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst requestedMaxTokens = requestOptions.maxTokens;\n\t\t\t\t\t\t\tconst configuredMaxTokens =\n\t\t\t\t\t\t\t\ttypeof requestedMaxTokens === \"number\" &&\n\t\t\t\t\t\t\t\tNumber.isSafeInteger(requestedMaxTokens) &&\n\t\t\t\t\t\t\t\trequestedMaxTokens > 0\n\t\t\t\t\t\t\t\t\t? requestedMaxTokens\n\t\t\t\t\t\t\t\t\t: options.laneCapability.laneMaxOutputTokens;\n\t\t\t\t\t\t\tconst maxTokens = Math.min(configuredMaxTokens, availableTokens ?? configuredMaxTokens);\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(maxTokens) || maxTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction provider completion has no valid remaining token budget.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet preflightFailed = false;\n\t\t\t\t\t\t\tlet preflightFailure: unknown;\n\t\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\t\treserveProviderBudget(maxTokens, \"worker_compaction_provider_completion\", requestSignal),\n\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\tonFailure: (error) => {\n\t\t\t\t\t\t\t\t\tif (preflightFailed) return;\n\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tcompletion = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\t\tsystemPrompt: context.systemPrompt ?? \"\",\n\t\t\t\t\t\t\t\t\t\tmessages: context.messages,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\t\tmaxTokens,\n\t\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\t\t\t\t\t\tlaneKind: \"worker-compaction\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tconst response: AssistantMessage = {\n\t\t\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\t\t\tcontent: completion.text ? [{ type: \"text\", text: completion.text }] : [],\n\t\t\t\t\t\t\t\t\tapi: options.model.api,\n\t\t\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\t\t\tmodel: options.model.id,\n\t\t\t\t\t\t\t\t\tusage: completion.usage,\n\t\t\t\t\t\t\t\t\tstopReason: completion.stopReason,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\t...(completion.stopReason === \"error\"\n\t\t\t\t\t\t\t\t\t\t? { errorMessage: completion.text || \"Worker compaction provider request failed.\" }\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\taddUsage(compactionUsage, completion.usage);\n\t\t\t\t\t\t\t\tif (providerTurn.hasOutstandingAssistantReservation()) {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(completion.usage);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountUnverifiedResultUsageDelta(completion.usage);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker compaction provider usage before verification.\");\n\t\t\t\t\t\t\t\tif (providerTurn.hasSuccessfulPreflight()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tif (!preflightFailed) {\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight(\"compaction\");\n\t\t\t\t\t\t\t\treturn response;\n\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\tproviderTurn.close();\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\t);\n\t\t\t},\n\t\t\tgetFailedCompactionUsage: () => failedCompactionUsage,\n\t\t};\n\t};\n\tconst ledger: WorkerAttemptExecutionLedger = {\n\t\tchangedFiles,\n\t\tgetUsage: currentUsage,\n\t};\n\n\treturn {\n\t\tledger,\n\t\tcheckpointUsage,\n\t\tasync run(): Promise<WorkerAttemptExecutionResult> {\n\t\t\tif (ran) throw new Error(\"A worker attempt executor may run only once.\");\n\t\t\tran = true;\n\t\t\toptions.conversation.beginAttemptUsage(options.durableHandle.attemptId);\n\t\t\tif (!options.hasPersistedUsageCheckpoint) {\n\t\t\t\tcheckpointUsage(\"Persisted deterministic cumulative usage baseline for the durable worker transcript.\");\n\t\t\t}\n\t\t\tconst rawOutcome = await runWorker({\n\t\t\t\trequest: options.request,\n\t\t\t\tmaxUsd: options.grant.budget.maxCostUsd,\n\t\t\t\tmaxWallClockMs: options.grant.budget.maxWallClockMs ?? 0,\n\t\t\t\tusageReportId: options.usageReportId,\n\t\t\t\tgetChangedFiles: () => [...changedFiles],\n\t\t\t\tsignal: options.signal,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tprocessCapable: options.processCapable,\n\t\t\t\tdelegationCapable: options.toolSurface.allowedTools.includes(\"delegate\"),\n\t\t\t\t...(options.verificationSubjectTaskId\n\t\t\t\t\t? { verificationSubjectTaskId: options.verificationSubjectTaskId }\n\t\t\t\t\t: {}),\n\t\t\t\t...(options.applyActions\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tapplyActions: (actions: readonly WorkerAction[]) => {\n\t\t\t\t\t\t\t\tconst report = options.applyActions!(actions, actionJournal);\n\t\t\t\t\t\t\t\tfor (const filePath of report.changedFiles) recordChangedFile(filePath);\n\t\t\t\t\t\t\t\treturn report;\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\tcomplete: async ({ systemPrompt, userPrompt, signal }) => {\n\t\t\t\t\tif (options.recoveredTerminal) {\n\t\t\t\t\t\tcheckpointUsage(\"Reused the persisted terminal worker assistant response after recovery.\");\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: options.recoveredTerminal.text,\n\t\t\t\t\t\t\tcostUsd: options.initialUsage.costUsd,\n\t\t\t\t\t\t\tstopReason: options.recoveredTerminal.stopReason,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst retentionPolicy = createRetentionPolicy(signal);\n\t\t\t\t\tconst persistedToolAssistantIds = new Set<string>();\n\t\t\t\t\tconst pendingToolAssistants = new Map<string, AssistantMessage>();\n\t\t\t\t\tlet activeProviderTurn: WorkerProviderTurnProtocol | undefined;\n\t\t\t\t\tconst closeActiveProviderTurn = (): void => {\n\t\t\t\t\t\tconst active = activeProviderTurn;\n\t\t\t\t\t\tactiveProviderTurn = undefined;\n\t\t\t\t\t\tactive?.close();\n\t\t\t\t\t};\n\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_provider_completion\");\n\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before provider completion.\");\n\t\t\t\t\t}\n\t\t\t\t\toptions.conversation.ensureAttemptUserPrompt(options.durableHandle.attemptId, userPrompt);\n\t\t\t\t\tlet history: Message[] = [];\n\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\tconst attemptProviderCompletion = async (): Promise<IsolatedCompletionResult> => {\n\t\t\t\t\t\t// Later attempts resume from the durably persisted transcript, not a stale snapshot.\n\t\t\t\t\t\tconst transcriptCommit = options.conversation.beginTranscriptCommit();\n\t\t\t\t\t\thistory = transcriptCommit.history;\n\t\t\t\t\t\tconst historyLength = history.length;\n\t\t\t\t\t\tconst transcriptCursor = transcriptCommit.cursor;\n\t\t\t\t\t\tconst durableCallbackMessages: Message[] = [];\n\t\t\t\t\t\tlet callbackFailed = false;\n\t\t\t\t\t\tlet callbackFailure: unknown;\n\t\t\t\t\t\tconst retainCallbackFailure = (error: unknown): void => {\n\t\t\t\t\t\t\tif (callbackFailed) return;\n\t\t\t\t\t\t\tcallbackFailed = true;\n\t\t\t\t\t\t\tcallbackFailure = error;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\treserveProviderBudget(\n\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\"worker_provider_completion\",\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\tonFailure: retainCallbackFailure,\n\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tactiveProviderTurn = providerTurn;\n\t\t\t\t\t\tconst persistToolRequest = (message: AssistantMessage): void => {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst toolCallIds = message.content.flatMap((content) =>\n\t\t\t\t\t\t\t\tcontent.type === \"toolCall\" ? [content.id] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (toolCallIds.length === 0 || toolCallIds.every((id) => persistedToolAssistantIds.has(id)))\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\tfor (const id of toolCallIds) {\n\t\t\t\t\t\t\t\tpersistedToolAssistantIds.add(id);\n\t\t\t\t\t\t\t\tpendingToolAssistants.delete(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker assistant tool request and its cumulative provider usage.\");\n\t\t\t\t\t\t\tproviderTurn.consumeToolAssistantAndRelease();\n\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tlet committed = false;\n\t\t\t\t\t\tconst abortTranscriptCursor = (): void => {\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\toptions.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", abortTranscriptCursor, { once: true });\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tlet result: IsolatedCompletionResult;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tresult = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\tsystemPrompt: buildWorkerSystemPrompt({\n\t\t\t\t\t\t\t\t\t\tsoul: options.soul,\n\t\t\t\t\t\t\t\t\t\trolePrompt: systemPrompt,\n\t\t\t\t\t\t\t\t\t\tworkerResourceSystemPrompt: options.workerResourceSystemPrompt,\n\t\t\t\t\t\t\t\t\t\tagentDir: options.agentDir,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\tmaxTokens: Math.min(\n\t\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\tavailableTokens ?? Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\ttools: options.toolSurface.tools,\n\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\tbeforeToolCall: async (context, toolSignal) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tpersistToolRequest(context.assistantMessage);\n\t\t\t\t\t\t\t\t\t\t\tconst decision = await options.toolSurface.beforeToolCall(context, toolSignal);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (!decision?.block) {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t`Authorized worker tool '${context.toolCall.name}' under its durable grant.`,\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn decision;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tafterToolCall: async ({ toolCall, args }) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t(toolCall.name === \"write\" || toolCall.name === \"edit\") &&\n\t\t\t\t\t\t\t\t\t\t\t\targs &&\n\t\t\t\t\t\t\t\t\t\t\t\ttypeof args === \"object\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!Array.isArray(args)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst rawPath = (args as Record<string, unknown>).path;\n\t\t\t\t\t\t\t\t\t\t\t\tif (typeof rawPath === \"string\" && rawPath.length > 0) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconst absolutePath = path.isAbsolute(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? path.resolve(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: path.resolve(options.cwd, rawPath);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet canonicalPath = absolutePath;\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcanonicalPath = safeRealpathSync(absolutePath);\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// The operation entered execution; retain its lexical target if canonicalization failed.\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trecordChangedFile(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath.relative(options.cwd, canonicalPath).split(path.sep).join(\"/\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonMessage: (message) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && isToolRequest(message)) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Known calls are normalized before beforeToolCall and persist from that hook.\n\t\t\t\t\t\t\t\t\t\t\t\t// Retain the request only so immediate unknown/malformed results can close the\n\t\t\t\t\t\t\t\t\t\t\t\t// transcript without freezing pre-repair arguments into durable history.\n\t\t\t\t\t\t\t\t\t\t\t\tfor (const content of message.content) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (content.type === \"toolCall\") pendingToolAssistants.set(content.id, message);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\tmessage.role === \"toolResult\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!persistedToolAssistantIds.has(message.toolCallId)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst pending = pendingToolAssistants.get(message.toolCallId);\n\t\t\t\t\t\t\t\t\t\t\t\tif (pending) persistToolRequest(pending);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\") {\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\t\t\t\t\toptions.agentControl.acknowledgeMailboxMessage(options.agentId, message);\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Persisted worker assistant response and its cumulative provider usage.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"toolResult\")\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(`Persisted worker tool result '${message.toolCallId}'.`);\n\t\t\t\t\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetSteeringMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst includeFollowUp = firstMailboxPoll;\n\t\t\t\t\t\t\t\t\t\t\tfirstMailboxPoll = false;\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\tincludeFollowUp,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetFollowUpMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t...(retentionPolicy\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\ttransformContext: async (messages: AgentMessage[]) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconst retained = await options.conversation.compactProviderContext(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionPolicy,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.contextUsage.tokens > retentionPolicy.maxContextTokens &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t!retentionWarningEmitted\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker ${options.laneId} has one retained turn larger than its context policy; provider overflow recovery may be required.`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_verified\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_deterministic\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn sanitizeToolFailureContext(retained.context.messages, \"\").messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (error instanceof WorkerConversationOwnershipError) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!retentionWarningEmitted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker context retention failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\tcacheRetention: \"short\",\n\t\t\t\t\t\t\t\t\tlaneKind: \"worker\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\tif (signal.aborted) throw error;\n\t\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tproviderTurn.assertEverySuccessfulPreflightConsumed();\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tif (providerTurn.accountUnverifiedResultUsageDelta(result.usage)) {\n\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\"Persisted supplemental provider result usage before rejecting unverified completion evidence.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight();\n\t\t\t\t\t\t\tconst evidenced = callbackEvidencedCompletion(result, historyLength, durableCallbackMessages);\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst appended = options.conversation.commitTranscript(transcriptCursor, evidenced.suffix, {\n\t\t\t\t\t\t\t\tappendMissing: false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (appended !== 0) {\n\t\t\t\t\t\t\t\tthrow new WorkerConversationOwnershipError(\n\t\t\t\t\t\t\t\t\t\"Worker callback transcript verification unexpectedly appended missing messages.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcommitted = true;\n\t\t\t\t\t\t\treturn evidenced.completion;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abortTranscriptCursor);\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (activeProviderTurn === providerTurn) activeProviderTurn = undefined;\n\t\t\t\t\t\t\tif (!committed) options.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcompletion = await runProviderCompletionWithBackoff({\n\t\t\t\t\t\t\tattempt: attemptProviderCompletion,\n\t\t\t\t\t\t\tonAttemptFailure: closeActiveProviderTurn,\n\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\tlaneId: options.laneId,\n\t\t\t\t\t\t\twarn: options.warn,\n\t\t\t\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tcloseActiveProviderTurn();\n\t\t\t\t\t}\n\t\t\t\t\tconst cumulativeUsage = checkpointUsage(\n\t\t\t\t\t\t\"Verified the callback-persisted worker conversation terminal suffix.\",\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: completion.text,\n\t\t\t\t\t\tcostUsd: cumulativeUsage.costUsd,\n\t\t\t\t\t\tstopReason: String(completion.stopReason),\n\t\t\t\t\t\tchangedFiles: [...changedFiles],\n\t\t\t\t\t\tblockers: [...toolIssues],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst usage = checkpointUsage(\"Persisted final cumulative worker usage before terminal result.\");\n\t\t\treturn { rawOutcome, usage, changedFiles: [...changedFiles] };\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-claim.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAK5G,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AACpD,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AACpD,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAClD,eAAO,MAAM,mCAAmC,OAAQ,CAAC;AACzD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,0CAA0C,MAAM,CAAC;AAC9D,eAAO,M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;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAGlH;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACzC,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,WAAW,CAAC;IACnB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,WAAW,CAwId;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IACnD,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC;+FAC2F;IAC3F,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,aAAa,CAAC,CAAC;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAwClD"}
|
|
@@ -118,7 +118,11 @@ export function boundedWorkerClaimChangedFiles(values) {
|
|
|
118
118
|
export function normalizeWorkerClaimForHost(value) {
|
|
119
119
|
const claim = ownWorkerClaimDataRecord(value, "claim");
|
|
120
120
|
const status = claim.status;
|
|
121
|
-
if (status !== "completed" &&
|
|
121
|
+
if (status !== "completed" &&
|
|
122
|
+
status !== "partial" &&
|
|
123
|
+
status !== "blocked" &&
|
|
124
|
+
status !== "failed" &&
|
|
125
|
+
status !== "cancelled") {
|
|
122
126
|
invalidWorkerClaim("claim.status is invalid.");
|
|
123
127
|
}
|
|
124
128
|
if (claim.outputFormat !== undefined && claim.outputFormat !== "structured" && claim.outputFormat !== "plain_text") {
|
|
@@ -239,6 +243,15 @@ export function validateWorkerClaim(args) {
|
|
|
239
243
|
message: `Claim requestId '${claim.requestId}' does not match request id '${request.id}'.`,
|
|
240
244
|
};
|
|
241
245
|
}
|
|
246
|
+
if (claim.status === "partial") {
|
|
247
|
+
return {
|
|
248
|
+
outcome: "ask-user",
|
|
249
|
+
gate: "worker_claim",
|
|
250
|
+
reasonCode: "parent_review_required",
|
|
251
|
+
message: `Worker finished with partial claim status '${claim.status}'.`,
|
|
252
|
+
details: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
242
255
|
if (claim.status !== "completed") {
|
|
243
256
|
return {
|
|
244
257
|
outcome: "block",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-claim.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAClD,MAAM,CAAC,MAAM,mCAAmC,GAAG,KAAK,CAAC;AACzD,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,CAAC;AACrD,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,CAAC;AAC9D,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,CAAC;AACpD,MAAM,CAAC,MAAM,8CAA8C,GAAG,GAAG,CAAC;AAClE,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,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AAO,KAAK,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import path from \"node:path\";\nimport type { CapabilityEnvelope, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { checkPathScope } from \"../autonomy/path-scope.ts\";\nimport { normalizeEvidenceBundleForStorage } from \"../research/evidence-bundle.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const MAX_WORKER_CLAIM_SUMMARY_CHARS = 8_000;\nexport const MAX_WORKER_CLAIM_BLOCKERS = 32;\nexport const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1_000;\nexport const MAX_WORKER_CLAIM_CHANGED_FILES = 128;\nexport const MAX_WORKER_CLAIM_CHANGED_FILE_CHARS = 2_048;\nexport const MAX_WORKER_CLAIM_REQUEST_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TIMESTAMP_CHARS = 128;\nexport const MAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_REASON_CODES = 32;\nexport const MAX_WORKER_CLAIM_REASON_CODE_CHARS = 128;\n\nexport interface BoundedWorkerClaimStrings {\n\tvalues: string[];\n\toverflowed: boolean;\n}\n\nfunction collectBoundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n\ttrim: boolean,\n): BoundedWorkerClaimStrings {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tlet overflowed = values.length > maximumCount;\n\tfor (let index = 0; index < Math.min(values.length, maximumCount); index++) {\n\t\tconst raw = values[index];\n\t\tif (typeof raw !== \"string\" || raw.length > maximumChars) {\n\t\t\toverflowed = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst normalized = trim ? raw.trim() : raw;\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t}\n\treturn { values: bounded, overflowed };\n}\n\n/** Native host observations may be reduced for terminal storage, but callers must surface overflow. */\nexport function collectBoundedWorkerClaimBlockers(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(values, MAX_WORKER_CLAIM_BLOCKERS, MAX_WORKER_CLAIM_BLOCKER_CHARS, true);\n}\n\n/** Changed paths preserve their exact spelling; trimming a real path could change its meaning. */\nexport function collectBoundedWorkerClaimChangedFiles(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(\n\t\tvalues,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\tfalse,\n\t);\n}\n\nfunction invalidWorkerClaim(message: string): never {\n\tthrow new Error(`Invalid worker claim: ${message}`);\n}\n\n/**\n * The worker boundary must not evaluate accessors from managed/external reports. Copy only own\n * data descriptors, then validate and construct a fresh contract object from the bounded values.\n */\nfunction ownWorkerClaimDataRecord(value: unknown, label: string): Record<string, unknown> {\n\tif (!isPlainRecord(value)) invalidWorkerClaim(`${label} must be a plain object.`);\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (!(\"value\" in descriptor)) invalidWorkerClaim(`${label}.${key} must not be an accessor.`);\n\t\trecord[key] = descriptor.value;\n\t}\n\treturn record;\n}\n\nfunction requiredWorkerClaimString(value: unknown, label: string, maximumChars: number): string {\n\tif (typeof value !== \"string\" || value.length === 0) invalidWorkerClaim(`${label} must be a non-empty string.`);\n\tif (value.length > maximumChars) invalidWorkerClaim(`${label} exceeds ${maximumChars} characters.`);\n\treturn value;\n}\n\nfunction optionalWorkerClaimString(value: unknown, label: string, maximumChars: number): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredWorkerClaimString(value, label, maximumChars);\n}\n\nfunction workerClaimStringArray(value: unknown, label: string, maximumCount: number, maximumChars: number): string[] {\n\tif (!Array.isArray(value)) invalidWorkerClaim(`${label} must be an array.`);\n\tif (value.length > maximumCount) invalidWorkerClaim(`${label} exceeds ${maximumCount} entries.`);\n\tconst copied: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\tif (!descriptor || !(\"value\" in descriptor)) invalidWorkerClaim(`${label}[${index}] must be a data value.`);\n\t\tconst item = requiredWorkerClaimString(descriptor.value, `${label}[${index}]`, maximumChars);\n\t\tif (seen.has(item)) continue;\n\t\tseen.add(item);\n\t\tcopied.push(item);\n\t}\n\treturn copied;\n}\n\nexport function boundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n): string[] {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const value of values) {\n\t\tconst normalized = value.trim().slice(0, maximumChars);\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t\tif (bounded.length >= maximumCount) break;\n\t}\n\treturn bounded;\n}\n\nexport function boundedWorkerClaimBlockers(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimBlockers(values).values;\n}\n\nexport function boundedWorkerClaimChangedFiles(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimChangedFiles(values).values;\n}\n\n/**\n * Applies the one mandatory bounded claim contract before persistence, review, finalization, or\n * artifact inspection. Host-built/native reports have already bounded their model output; foreign\n * reports must fit the exact same envelope and are rejected before cloning or getter invocation.\n */\nexport function normalizeWorkerClaimForHost(value: unknown): WorkerClaim {\n\tconst claim = ownWorkerClaimDataRecord(value, \"claim\");\n\tconst status = claim.status;\n\tif (status !== \"completed\" && status !== \"blocked\" && status !== \"failed\" && status !== \"cancelled\") {\n\t\tinvalidWorkerClaim(\"claim.status is invalid.\");\n\t}\n\tif (claim.outputFormat !== undefined && claim.outputFormat !== \"structured\" && claim.outputFormat !== \"plain_text\") {\n\t\tinvalidWorkerClaim(\"claim.outputFormat is invalid.\");\n\t}\n\tif (claim.parentReviewRequired !== undefined && typeof claim.parentReviewRequired !== \"boolean\") {\n\t\tinvalidWorkerClaim(\"claim.parentReviewRequired must be boolean.\");\n\t}\n\tconst verification =\n\t\tclaim.verification === undefined ? undefined : ownWorkerClaimDataRecord(claim.verification, \"claim.verification\");\n\tif (verification && verification.verdict !== \"accepted\" && verification.verdict !== \"rejected\") {\n\t\tinvalidWorkerClaim(\"claim.verification.verdict is invalid.\");\n\t}\n\tconst normalizedVerification: WorkerClaim[\"verification\"] = verification\n\t\t? {\n\t\t\t\tsubjectTaskId: requiredWorkerClaimString(\n\t\t\t\t\tverification.subjectTaskId,\n\t\t\t\t\t\"claim.verification.subjectTaskId\",\n\t\t\t\t\tMAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS,\n\t\t\t\t),\n\t\t\t\tverdict: verification.verdict === \"accepted\" ? \"accepted\" : \"rejected\",\n\t\t\t\treasonCodes: workerClaimStringArray(\n\t\t\t\t\tverification.reasonCodes,\n\t\t\t\t\t\"claim.verification.reasonCodes\",\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODES,\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t\t\t\t),\n\t\t\t}\n\t\t: undefined;\n\tif (normalizedVerification && normalizedVerification.reasonCodes.length === 0) {\n\t\tinvalidWorkerClaim(\"claim.verification.reasonCodes must not be empty.\");\n\t}\n\treturn {\n\t\trequestId: requiredWorkerClaimString(claim.requestId, \"claim.requestId\", MAX_WORKER_CLAIM_REQUEST_ID_CHARS),\n\t\t...(claim.terminalAttemptId !== undefined\n\t\t\t? {\n\t\t\t\t\tterminalAttemptId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.terminalAttemptId,\n\t\t\t\t\t\t\"claim.terminalAttemptId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tstatus,\n\t\tsummary: requiredWorkerClaimString(claim.summary, \"claim.summary\", MAX_WORKER_CLAIM_SUMMARY_CHARS),\n\t\t...(claim.outputFormat !== undefined ? { outputFormat: claim.outputFormat } : {}),\n\t\t...(claim.evidence !== undefined ? { evidence: normalizeEvidenceBundleForStorage(claim.evidence) } : {}),\n\t\tchangedFiles: workerClaimStringArray(\n\t\t\tclaim.changedFiles,\n\t\t\t\"claim.changedFiles\",\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\t),\n\t\t...(claim.blockers !== undefined\n\t\t\t? {\n\t\t\t\t\tblockers: workerClaimStringArray(\n\t\t\t\t\t\tclaim.blockers,\n\t\t\t\t\t\t\"claim.blockers\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKERS,\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.usageReportId !== undefined\n\t\t\t? {\n\t\t\t\t\tusageReportId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.usageReportId,\n\t\t\t\t\t\t\"claim.usageReportId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.createdAt !== undefined\n\t\t\t? {\n\t\t\t\t\tcreatedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.createdAt,\n\t\t\t\t\t\t\"claim.createdAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.parentReviewRequired !== undefined ? { parentReviewRequired: claim.parentReviewRequired } : {}),\n\t\t...(claim.parentReviewedAt !== undefined\n\t\t\t? {\n\t\t\t\t\tparentReviewedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.parentReviewedAt,\n\t\t\t\t\t\t\"claim.parentReviewedAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(normalizedVerification ? { verification: normalizedVerification } : {}),\n\t};\n}\n\nexport function normalizeWorkerClaimReasonCode(value: unknown, fallback: string): string {\n\treturn (typeof value === \"string\" && value.trim() ? value.trim() : fallback).slice(\n\t\t0,\n\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t);\n}\n\nexport function cloneWorkerClaimForStorage(claim: WorkerClaim): WorkerClaim {\n\treturn normalizeWorkerClaimForHost(claim);\n}\n\nexport function isWorkerClaim(value: unknown): value is WorkerClaim {\n\ttry {\n\t\tnormalizeWorkerClaimForHost(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function requiresParentReview(claim: WorkerClaim): boolean {\n\tif (claim.status !== \"completed\") {\n\t\treturn true;\n\t}\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn true;\n\t}\n\tif (claim.changedFiles.length > 0) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * True iff {@link validateWorkerClaim}'s gate would flag this claim \"ask-user\" /\n * \"parent_review_required\" (the two branches at :110 and :178 below) — an otherwise-completed\n * claim the parent must explicitly look at because it reports blockers, or reports file mutations\n * that passed path-scope validation. Reuses `validateWorkerClaim` itself rather than a\n * separately-maintained heuristic, so a persisted review marker can never drift from the\n * gate's actual verdict.\n */\nexport function isParentReviewRequired(args: { request: WorkerRequest; claim: WorkerClaim; cwd?: string }): boolean {\n\tconst acceptance = validateWorkerClaim(args);\n\treturn acceptance.outcome === \"ask-user\" && acceptance.reasonCode === \"parent_review_required\";\n}\n\nexport function validateWorkerClaim(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\t/**\n\t * Baseline for relative paths — BOTH the runner's cwd-relative `changedFiles` and the\n\t * envelope's possibly-relative path scopes resolve against this. Defaults to process.cwd()\n\t * for callers whose session cwd is the process cwd.\n\t */\n\tcwd?: string;\n}): GateOutcome {\n\tconst { request } = args;\n\tlet claim: WorkerClaim;\n\ttry {\n\t\tclaim = normalizeWorkerClaimForHost(args.claim);\n\t} catch (error) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"invalid_worker_claim\",\n\t\t\tmessage: error instanceof Error ? error.message : \"Worker claim failed host validation.\",\n\t\t};\n\t}\n\tconst baseDir = args.cwd ?? process.cwd();\n\n\tif (claim.requestId !== request.id) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"request_id_mismatch\",\n\t\t\tmessage: `Claim requestId '${claim.requestId}' does not match request id '${request.id}'.`,\n\t\t};\n\t}\n\n\tif (claim.status !== \"completed\") {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"worker_not_completed\",\n\t\t\tmessage: `Worker finished with status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (!claim.usageReportId) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"missing_usage_report\",\n\t\t\tmessage: \"Completed worker claim is missing usageReportId.\",\n\t\t};\n\t}\n\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Completed worker claim includes blockers and requires parent review.\",\n\t\t\tdetails: { blockers: [...claim.blockers] },\n\t\t};\n\t}\n\n\tif (claim.changedFiles.length > 0) {\n\t\tif (!request.envelope.allowedPaths || request.envelope.allowedPaths.length === 0) {\n\t\t\treturn {\n\t\t\t\toutcome: \"block\",\n\t\t\t\tgate: \"worker_claim\",\n\t\t\t\treasonCode: \"missing_path_scope\",\n\t\t\t\tmessage: \"Worker changed files but no allowedPaths are configured in the envelope.\",\n\t\t\t};\n\t\t}\n\n\t\t// The runner reports changed files relative to the session cwd — resolve file and scope\n\t\t// roots against the SAME baseline. Resolving per-root double-prefixed nested names and\n\t\t// let a denied subtree slip past the deny rule.\n\t\tconst resolvedAllowed = request.envelope.allowedPaths.map((p) => path.resolve(baseDir, p));\n\t\tconst resolvedDenied = request.envelope.deniedPaths?.map((p) => path.resolve(baseDir, p));\n\t\tfor (const changedFile of claim.changedFiles) {\n\t\t\tlet isInsideAny = false;\n\t\t\tlet isDenied = false;\n\n\t\t\tconst scopedChangedFile = path.resolve(baseDir, changedFile);\n\t\t\tfor (const root of resolvedAllowed) {\n\t\t\t\tconst decision = checkPathScope(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\tallowedPaths: resolvedAllowed,\n\t\t\t\t\t\tdeniedPaths: resolvedDenied,\n\t\t\t\t\t},\n\t\t\t\t\tscopedChangedFile,\n\t\t\t\t);\n\n\t\t\t\tif (decision.kind === \"denied\") {\n\t\t\t\t\tisDenied = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (decision.kind === \"inside\") {\n\t\t\t\t\tisInsideAny = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDenied) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_denied\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' which matches a denied path.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (!isInsideAny) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_outside_scope\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' outside allowed scope.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Files are inside scope, but worker output is untrusted\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Worker changed files require parent review.\",\n\t\t};\n\t}\n\n\treturn {\n\t\toutcome: \"allow\",\n\t\tgate: \"worker_claim\",\n\t\treasonCode: \"allowed\",\n\t\tmessage: \"Worker claim is read-only and allowed.\",\n\t};\n}\n\n/**\n * Path-scope-only re-review for a SELF-REPORTED (out-of-process) worker's claimed `changedFiles`\n * -- e.g. a tmux worker's own completion report, which (unlike an in-process worker's) never\n * passed through this process's `applyWorkerActions` envelope enforcement before the write\n * happened; the tmux worker's tool loop runs in a separate process this session does not gate.\n * Reuses {@link validateWorkerClaim}'s exact symlink-safe scope check verbatim -- never\n * reimplement path resolution: synthesizes a minimal, always-\"completed\" request/claim pair\n * carrying only the reported `changedFiles` and the scope's `allowedPaths`/`deniedPaths`, so the\n * ONLY thing that can vary the verdict is the path-scope branch.\n *\n * Deliberately broader than {@link isParentReviewRequired}: that helper only flags the gate's\n * \"ask-user\" branch, which is correct for an in-process worker (a write that would have been\n * \"block\"-worthy was already refused before it could happen, by the SAME envelope, via\n * `applyWorkerActions`). A self-reported claim has no such backstop -- an out-of-scope or denied\n * path already happened on the real filesystem whether or not this gate would allow it, so here\n * ANY non-\"allow\" verdict (in scope, out of scope, or no scope configured at all) means a human\n * must look, not \"the write didn't happen\".\n */\nexport function reviewManagedLaneChangedFiles(args: {\n\tchangedFiles: readonly string[];\n\t/** The scope to validate against -- e.g. the session's active `CapabilityEnvelope`, until a\n\t * per-launch tmux standing grant envelope lands in a later wave (documented follow-up). */\n\tenvelope: Pick<CapabilityEnvelope, \"allowedPaths\" | \"deniedPaths\">;\n\tcwd?: string;\n}): { reviewRequired: boolean; reasonCode: string } {\n\tconst boundedChangedFiles = normalizeWorkerClaimForHost({\n\t\trequestId: \"managed-lane-review\",\n\t\tstatus: \"completed\",\n\t\tsummary: \"Managed lane changed-file review.\",\n\t\tchangedFiles: args.changedFiles,\n\t\tusageReportId: \"managed-lane-review\",\n\t}).changedFiles;\n\tif (boundedChangedFiles.length === 0) {\n\t\treturn { reviewRequired: false, reasonCode: \"no_changed_files\" };\n\t}\n\tconst syntheticId = \"managed-lane-review\";\n\tconst acceptance = validateWorkerClaim({\n\t\trequest: {\n\t\t\tid: syntheticId,\n\t\t\tinstructions: \"\",\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: \"scoped-write\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"managed_lane_review\",\n\t\t\t\treasons: [],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: syntheticId,\n\t\t\t\tcapabilities: [\"filesystem.write\"],\n\t\t\t\tallowedPaths: args.envelope.allowedPaths,\n\t\t\t\tdeniedPaths: args.envelope.deniedPaths,\n\t\t\t},\n\t\t},\n\t\tclaim: {\n\t\t\trequestId: syntheticId,\n\t\t\tstatus: \"completed\",\n\t\t\tsummary: \"Managed lane changed-file review.\",\n\t\t\tchangedFiles: boundedChangedFiles,\n\t\t\tusageReportId: syntheticId,\n\t\t},\n\t\tcwd: args.cwd,\n\t});\n\treturn { reviewRequired: acceptance.outcome !== \"allow\", reasonCode: acceptance.reasonCode };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-claim.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,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";\nimport type { CapabilityEnvelope, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { checkPathScope } from \"../autonomy/path-scope.ts\";\nimport { normalizeEvidenceBundleForStorage } from \"../research/evidence-bundle.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const MAX_WORKER_CLAIM_SUMMARY_CHARS = 8_000;\nexport const MAX_WORKER_CLAIM_BLOCKERS = 32;\nexport const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1_000;\nexport const MAX_WORKER_CLAIM_CHANGED_FILES = 128;\nexport const MAX_WORKER_CLAIM_CHANGED_FILE_CHARS = 2_048;\nexport const MAX_WORKER_CLAIM_REQUEST_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TIMESTAMP_CHARS = 128;\nexport const MAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_REASON_CODES = 32;\nexport const MAX_WORKER_CLAIM_REASON_CODE_CHARS = 128;\n\nexport interface BoundedWorkerClaimStrings {\n\tvalues: string[];\n\toverflowed: boolean;\n}\n\nfunction collectBoundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n\ttrim: boolean,\n): BoundedWorkerClaimStrings {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tlet overflowed = values.length > maximumCount;\n\tfor (let index = 0; index < Math.min(values.length, maximumCount); index++) {\n\t\tconst raw = values[index];\n\t\tif (typeof raw !== \"string\" || raw.length > maximumChars) {\n\t\t\toverflowed = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst normalized = trim ? raw.trim() : raw;\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t}\n\treturn { values: bounded, overflowed };\n}\n\n/** Native host observations may be reduced for terminal storage, but callers must surface overflow. */\nexport function collectBoundedWorkerClaimBlockers(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(values, MAX_WORKER_CLAIM_BLOCKERS, MAX_WORKER_CLAIM_BLOCKER_CHARS, true);\n}\n\n/** Changed paths preserve their exact spelling; trimming a real path could change its meaning. */\nexport function collectBoundedWorkerClaimChangedFiles(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(\n\t\tvalues,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\tfalse,\n\t);\n}\n\nfunction invalidWorkerClaim(message: string): never {\n\tthrow new Error(`Invalid worker claim: ${message}`);\n}\n\n/**\n * The worker boundary must not evaluate accessors from managed/external reports. Copy only own\n * data descriptors, then validate and construct a fresh contract object from the bounded values.\n */\nfunction ownWorkerClaimDataRecord(value: unknown, label: string): Record<string, unknown> {\n\tif (!isPlainRecord(value)) invalidWorkerClaim(`${label} must be a plain object.`);\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (!(\"value\" in descriptor)) invalidWorkerClaim(`${label}.${key} must not be an accessor.`);\n\t\trecord[key] = descriptor.value;\n\t}\n\treturn record;\n}\n\nfunction requiredWorkerClaimString(value: unknown, label: string, maximumChars: number): string {\n\tif (typeof value !== \"string\" || value.length === 0) invalidWorkerClaim(`${label} must be a non-empty string.`);\n\tif (value.length > maximumChars) invalidWorkerClaim(`${label} exceeds ${maximumChars} characters.`);\n\treturn value;\n}\n\nfunction optionalWorkerClaimString(value: unknown, label: string, maximumChars: number): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredWorkerClaimString(value, label, maximumChars);\n}\n\nfunction workerClaimStringArray(value: unknown, label: string, maximumCount: number, maximumChars: number): string[] {\n\tif (!Array.isArray(value)) invalidWorkerClaim(`${label} must be an array.`);\n\tif (value.length > maximumCount) invalidWorkerClaim(`${label} exceeds ${maximumCount} entries.`);\n\tconst copied: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\tif (!descriptor || !(\"value\" in descriptor)) invalidWorkerClaim(`${label}[${index}] must be a data value.`);\n\t\tconst item = requiredWorkerClaimString(descriptor.value, `${label}[${index}]`, maximumChars);\n\t\tif (seen.has(item)) continue;\n\t\tseen.add(item);\n\t\tcopied.push(item);\n\t}\n\treturn copied;\n}\n\nexport function boundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n): string[] {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const value of values) {\n\t\tconst normalized = value.trim().slice(0, maximumChars);\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t\tif (bounded.length >= maximumCount) break;\n\t}\n\treturn bounded;\n}\n\nexport function boundedWorkerClaimBlockers(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimBlockers(values).values;\n}\n\nexport function boundedWorkerClaimChangedFiles(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimChangedFiles(values).values;\n}\n\n/**\n * Applies the one mandatory bounded claim contract before persistence, review, finalization, or\n * artifact inspection. Host-built/native reports have already bounded their model output; foreign\n * reports must fit the exact same envelope and are rejected before cloning or getter invocation.\n */\nexport function normalizeWorkerClaimForHost(value: unknown): WorkerClaim {\n\tconst claim = ownWorkerClaimDataRecord(value, \"claim\");\n\tconst status = claim.status;\n\tif (\n\t\tstatus !== \"completed\" &&\n\t\tstatus !== \"partial\" &&\n\t\tstatus !== \"blocked\" &&\n\t\tstatus !== \"failed\" &&\n\t\tstatus !== \"cancelled\"\n\t) {\n\t\tinvalidWorkerClaim(\"claim.status is invalid.\");\n\t}\n\tif (claim.outputFormat !== undefined && claim.outputFormat !== \"structured\" && claim.outputFormat !== \"plain_text\") {\n\t\tinvalidWorkerClaim(\"claim.outputFormat is invalid.\");\n\t}\n\tif (claim.parentReviewRequired !== undefined && typeof claim.parentReviewRequired !== \"boolean\") {\n\t\tinvalidWorkerClaim(\"claim.parentReviewRequired must be boolean.\");\n\t}\n\tconst verification =\n\t\tclaim.verification === undefined ? undefined : ownWorkerClaimDataRecord(claim.verification, \"claim.verification\");\n\tif (verification && verification.verdict !== \"accepted\" && verification.verdict !== \"rejected\") {\n\t\tinvalidWorkerClaim(\"claim.verification.verdict is invalid.\");\n\t}\n\tconst normalizedVerification: WorkerClaim[\"verification\"] = verification\n\t\t? {\n\t\t\t\tsubjectTaskId: requiredWorkerClaimString(\n\t\t\t\t\tverification.subjectTaskId,\n\t\t\t\t\t\"claim.verification.subjectTaskId\",\n\t\t\t\t\tMAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS,\n\t\t\t\t),\n\t\t\t\tverdict: verification.verdict === \"accepted\" ? \"accepted\" : \"rejected\",\n\t\t\t\treasonCodes: workerClaimStringArray(\n\t\t\t\t\tverification.reasonCodes,\n\t\t\t\t\t\"claim.verification.reasonCodes\",\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODES,\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t\t\t\t),\n\t\t\t}\n\t\t: undefined;\n\tif (normalizedVerification && normalizedVerification.reasonCodes.length === 0) {\n\t\tinvalidWorkerClaim(\"claim.verification.reasonCodes must not be empty.\");\n\t}\n\treturn {\n\t\trequestId: requiredWorkerClaimString(claim.requestId, \"claim.requestId\", MAX_WORKER_CLAIM_REQUEST_ID_CHARS),\n\t\t...(claim.terminalAttemptId !== undefined\n\t\t\t? {\n\t\t\t\t\tterminalAttemptId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.terminalAttemptId,\n\t\t\t\t\t\t\"claim.terminalAttemptId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tstatus,\n\t\tsummary: requiredWorkerClaimString(claim.summary, \"claim.summary\", MAX_WORKER_CLAIM_SUMMARY_CHARS),\n\t\t...(claim.outputFormat !== undefined ? { outputFormat: claim.outputFormat } : {}),\n\t\t...(claim.evidence !== undefined ? { evidence: normalizeEvidenceBundleForStorage(claim.evidence) } : {}),\n\t\tchangedFiles: workerClaimStringArray(\n\t\t\tclaim.changedFiles,\n\t\t\t\"claim.changedFiles\",\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\t),\n\t\t...(claim.blockers !== undefined\n\t\t\t? {\n\t\t\t\t\tblockers: workerClaimStringArray(\n\t\t\t\t\t\tclaim.blockers,\n\t\t\t\t\t\t\"claim.blockers\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKERS,\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.usageReportId !== undefined\n\t\t\t? {\n\t\t\t\t\tusageReportId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.usageReportId,\n\t\t\t\t\t\t\"claim.usageReportId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.createdAt !== undefined\n\t\t\t? {\n\t\t\t\t\tcreatedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.createdAt,\n\t\t\t\t\t\t\"claim.createdAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.parentReviewRequired !== undefined ? { parentReviewRequired: claim.parentReviewRequired } : {}),\n\t\t...(claim.parentReviewedAt !== undefined\n\t\t\t? {\n\t\t\t\t\tparentReviewedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.parentReviewedAt,\n\t\t\t\t\t\t\"claim.parentReviewedAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(normalizedVerification ? { verification: normalizedVerification } : {}),\n\t};\n}\n\nexport function normalizeWorkerClaimReasonCode(value: unknown, fallback: string): string {\n\treturn (typeof value === \"string\" && value.trim() ? value.trim() : fallback).slice(\n\t\t0,\n\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t);\n}\n\nexport function cloneWorkerClaimForStorage(claim: WorkerClaim): WorkerClaim {\n\treturn normalizeWorkerClaimForHost(claim);\n}\n\nexport function isWorkerClaim(value: unknown): value is WorkerClaim {\n\ttry {\n\t\tnormalizeWorkerClaimForHost(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function requiresParentReview(claim: WorkerClaim): boolean {\n\tif (claim.status !== \"completed\") {\n\t\treturn true;\n\t}\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn true;\n\t}\n\tif (claim.changedFiles.length > 0) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * True iff {@link validateWorkerClaim}'s gate would flag this claim \"ask-user\" /\n * \"parent_review_required\" (the two branches at :110 and :178 below) — an otherwise-completed\n * claim the parent must explicitly look at because it reports blockers, or reports file mutations\n * that passed path-scope validation. Reuses `validateWorkerClaim` itself rather than a\n * separately-maintained heuristic, so a persisted review marker can never drift from the\n * gate's actual verdict.\n */\nexport function isParentReviewRequired(args: { request: WorkerRequest; claim: WorkerClaim; cwd?: string }): boolean {\n\tconst acceptance = validateWorkerClaim(args);\n\treturn acceptance.outcome === \"ask-user\" && acceptance.reasonCode === \"parent_review_required\";\n}\n\nexport function validateWorkerClaim(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\t/**\n\t * Baseline for relative paths — BOTH the runner's cwd-relative `changedFiles` and the\n\t * envelope's possibly-relative path scopes resolve against this. Defaults to process.cwd()\n\t * for callers whose session cwd is the process cwd.\n\t */\n\tcwd?: string;\n}): GateOutcome {\n\tconst { request } = args;\n\tlet claim: WorkerClaim;\n\ttry {\n\t\tclaim = normalizeWorkerClaimForHost(args.claim);\n\t} catch (error) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"invalid_worker_claim\",\n\t\t\tmessage: error instanceof Error ? error.message : \"Worker claim failed host validation.\",\n\t\t};\n\t}\n\tconst baseDir = args.cwd ?? process.cwd();\n\n\tif (claim.requestId !== request.id) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"request_id_mismatch\",\n\t\t\tmessage: `Claim requestId '${claim.requestId}' does not match request id '${request.id}'.`,\n\t\t};\n\t}\n\n\tif (claim.status === \"partial\") {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: `Worker finished with partial claim status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (claim.status !== \"completed\") {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"worker_not_completed\",\n\t\t\tmessage: `Worker finished with status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (!claim.usageReportId) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"missing_usage_report\",\n\t\t\tmessage: \"Completed worker claim is missing usageReportId.\",\n\t\t};\n\t}\n\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Completed worker claim includes blockers and requires parent review.\",\n\t\t\tdetails: { blockers: [...claim.blockers] },\n\t\t};\n\t}\n\n\tif (claim.changedFiles.length > 0) {\n\t\tif (!request.envelope.allowedPaths || request.envelope.allowedPaths.length === 0) {\n\t\t\treturn {\n\t\t\t\toutcome: \"block\",\n\t\t\t\tgate: \"worker_claim\",\n\t\t\t\treasonCode: \"missing_path_scope\",\n\t\t\t\tmessage: \"Worker changed files but no allowedPaths are configured in the envelope.\",\n\t\t\t};\n\t\t}\n\n\t\t// The runner reports changed files relative to the session cwd — resolve file and scope\n\t\t// roots against the SAME baseline. Resolving per-root double-prefixed nested names and\n\t\t// let a denied subtree slip past the deny rule.\n\t\tconst resolvedAllowed = request.envelope.allowedPaths.map((p) => path.resolve(baseDir, p));\n\t\tconst resolvedDenied = request.envelope.deniedPaths?.map((p) => path.resolve(baseDir, p));\n\t\tfor (const changedFile of claim.changedFiles) {\n\t\t\tlet isInsideAny = false;\n\t\t\tlet isDenied = false;\n\n\t\t\tconst scopedChangedFile = path.resolve(baseDir, changedFile);\n\t\t\tfor (const root of resolvedAllowed) {\n\t\t\t\tconst decision = checkPathScope(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\tallowedPaths: resolvedAllowed,\n\t\t\t\t\t\tdeniedPaths: resolvedDenied,\n\t\t\t\t\t},\n\t\t\t\t\tscopedChangedFile,\n\t\t\t\t);\n\n\t\t\t\tif (decision.kind === \"denied\") {\n\t\t\t\t\tisDenied = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (decision.kind === \"inside\") {\n\t\t\t\t\tisInsideAny = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDenied) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_denied\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' which matches a denied path.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (!isInsideAny) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_outside_scope\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' outside allowed scope.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Files are inside scope, but worker output is untrusted\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Worker changed files require parent review.\",\n\t\t};\n\t}\n\n\treturn {\n\t\toutcome: \"allow\",\n\t\tgate: \"worker_claim\",\n\t\treasonCode: \"allowed\",\n\t\tmessage: \"Worker claim is read-only and allowed.\",\n\t};\n}\n\n/**\n * Path-scope-only re-review for a SELF-REPORTED (out-of-process) worker's claimed `changedFiles`\n * -- e.g. a tmux worker's own completion report, which (unlike an in-process worker's) never\n * passed through this process's `applyWorkerActions` envelope enforcement before the write\n * happened; the tmux worker's tool loop runs in a separate process this session does not gate.\n * Reuses {@link validateWorkerClaim}'s exact symlink-safe scope check verbatim -- never\n * reimplement path resolution: synthesizes a minimal, always-\"completed\" request/claim pair\n * carrying only the reported `changedFiles` and the scope's `allowedPaths`/`deniedPaths`, so the\n * ONLY thing that can vary the verdict is the path-scope branch.\n *\n * Deliberately broader than {@link isParentReviewRequired}: that helper only flags the gate's\n * \"ask-user\" branch, which is correct for an in-process worker (a write that would have been\n * \"block\"-worthy was already refused before it could happen, by the SAME envelope, via\n * `applyWorkerActions`). A self-reported claim has no such backstop -- an out-of-scope or denied\n * path already happened on the real filesystem whether or not this gate would allow it, so here\n * ANY non-\"allow\" verdict (in scope, out of scope, or no scope configured at all) means a human\n * must look, not \"the write didn't happen\".\n */\nexport function reviewManagedLaneChangedFiles(args: {\n\tchangedFiles: readonly string[];\n\t/** The scope to validate against -- e.g. the session's active `CapabilityEnvelope`, until a\n\t * per-launch tmux standing grant envelope lands in a later wave (documented follow-up). */\n\tenvelope: Pick<CapabilityEnvelope, \"allowedPaths\" | \"deniedPaths\">;\n\tcwd?: string;\n}): { reviewRequired: boolean; reasonCode: string } {\n\tconst boundedChangedFiles = normalizeWorkerClaimForHost({\n\t\trequestId: \"managed-lane-review\",\n\t\tstatus: \"completed\",\n\t\tsummary: \"Managed lane changed-file review.\",\n\t\tchangedFiles: args.changedFiles,\n\t\tusageReportId: \"managed-lane-review\",\n\t}).changedFiles;\n\tif (boundedChangedFiles.length === 0) {\n\t\treturn { reviewRequired: false, reasonCode: \"no_changed_files\" };\n\t}\n\tconst syntheticId = \"managed-lane-review\";\n\tconst acceptance = validateWorkerClaim({\n\t\trequest: {\n\t\t\tid: syntheticId,\n\t\t\tinstructions: \"\",\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: \"scoped-write\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"managed_lane_review\",\n\t\t\t\treasons: [],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: syntheticId,\n\t\t\t\tcapabilities: [\"filesystem.write\"],\n\t\t\t\tallowedPaths: args.envelope.allowedPaths,\n\t\t\t\tdeniedPaths: args.envelope.deniedPaths,\n\t\t\t},\n\t\t},\n\t\tclaim: {\n\t\t\trequestId: syntheticId,\n\t\t\tstatus: \"completed\",\n\t\t\tsummary: \"Managed lane changed-file review.\",\n\t\t\tchangedFiles: boundedChangedFiles,\n\t\t\tusageReportId: syntheticId,\n\t\t},\n\t\tcwd: args.cwd,\n\t});\n\treturn { reviewRequired: acceptance.outcome !== \"allow\", reasonCode: acceptance.reasonCode };\n}\n"]}
|
|
@@ -4,9 +4,9 @@ import type { AgentSessionEvent, IsolatedCompletionOptions, IsolatedCompletionRe
|
|
|
4
4
|
import type { CapabilityEnvelope, WorkerClaim, WorkerRequest } from "../autonomy/contracts.ts";
|
|
5
5
|
import { type LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
6
6
|
import { type AutonomyTelemetryEvent } from "../autonomy/telemetry-events.ts";
|
|
7
|
-
import type
|
|
7
|
+
import { type GoalState } from "../goals/goal-state.ts";
|
|
8
8
|
import type { ModelRegistry } from "../model-registry.ts";
|
|
9
|
-
import { type OrchestrationProfile } from "../orchestration/contracts.ts";
|
|
9
|
+
import { type OrchestrationProfile, type WorkerRole } from "../orchestration/contracts.ts";
|
|
10
10
|
import { type TaskProfileCreateInput, type TaskProfileCreateResult, type TaskProfileInspection } from "../orchestration/task-profile-writer.ts";
|
|
11
11
|
import type { TaskRuntimeProjection } from "../orchestration/task-runtime.ts";
|
|
12
12
|
import type { ResourceLoader } from "../resource-loader.ts";
|
|
@@ -156,6 +156,7 @@ export declare class WorkerDelegationController {
|
|
|
156
156
|
} | {
|
|
157
157
|
started: true;
|
|
158
158
|
record: LaneRecord;
|
|
159
|
+
modelPinBypass?: WorkerRole;
|
|
159
160
|
};
|
|
160
161
|
private startInternal;
|
|
161
162
|
runOnce(request: WorkerDelegationRequest, onStarted?: (record: LaneRecord) => void, existingRecord?: LaneRecord): Promise<WorkerDelegationRunOutcome>;
|