@caupulican/pi-adaptative 0.93.2 → 0.93.4
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 +26 -0
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +6 -6
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +2 -2
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +16 -11
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +1 -0
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +4 -1
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/composite-tool-gate.d.ts +13 -0
- package/dist/core/autonomy/composite-tool-gate.d.ts.map +1 -0
- package/dist/core/autonomy/composite-tool-gate.js +44 -0
- package/dist/core/autonomy/composite-tool-gate.js.map +1 -0
- package/dist/core/autonomy/envelope-enforcement.d.ts +2 -0
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +48 -7
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +48 -76
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js +7 -7
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +1 -1
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-tool-task-controller.d.ts +2 -0
- package/dist/core/background-tool-task-controller.d.ts.map +1 -1
- package/dist/core/background-tool-task-controller.js +13 -5
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +3 -0
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +132 -97
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/cost-guard.js +1 -1
- package/dist/core/cost-guard.js.map +1 -1
- package/dist/core/delegation/session-root-mailbox.d.ts.map +1 -1
- package/dist/core/delegation/session-root-mailbox.js +14 -1
- package/dist/core/delegation/session-root-mailbox.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +6 -9
- 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 +7 -5
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +3 -2
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +5 -2
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +10 -8
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +2 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +18 -9
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +3 -5
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +6 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.js +1 -1
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +1 -0
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +2 -0
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +1 -1
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +32 -9
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +5 -5
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
- package/dist/core/orchestration/policy-compiler.js +7 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -1
- package/dist/core/orchestration/profile-registry.js +2 -2
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +0 -10
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +0 -14
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/pipelines/active-context.d.ts +16 -0
- package/dist/core/pipelines/active-context.d.ts.map +1 -0
- package/dist/core/pipelines/active-context.js +29 -0
- package/dist/core/pipelines/active-context.js.map +1 -0
- package/dist/core/pipelines/context.d.ts +1 -1
- package/dist/core/pipelines/context.d.ts.map +1 -1
- package/dist/core/pipelines/context.js +40 -31
- package/dist/core/pipelines/context.js.map +1 -1
- package/dist/core/pipelines/discover.d.ts +5 -1
- package/dist/core/pipelines/discover.d.ts.map +1 -1
- package/dist/core/pipelines/discover.js +91 -33
- package/dist/core/pipelines/discover.js.map +1 -1
- package/dist/core/pipelines/increment.d.ts +0 -2
- package/dist/core/pipelines/increment.d.ts.map +1 -1
- package/dist/core/pipelines/increment.js +35 -13
- package/dist/core/pipelines/increment.js.map +1 -1
- package/dist/core/pipelines/index.d.ts +4 -3
- package/dist/core/pipelines/index.d.ts.map +1 -1
- package/dist/core/pipelines/index.js +4 -3
- package/dist/core/pipelines/index.js.map +1 -1
- package/dist/core/pipelines/run-state.d.ts +8 -0
- package/dist/core/pipelines/run-state.d.ts.map +1 -1
- package/dist/core/pipelines/run-state.js +172 -38
- package/dist/core/pipelines/run-state.js.map +1 -1
- package/dist/core/pipelines/types.d.ts +2 -0
- package/dist/core/pipelines/types.d.ts.map +1 -1
- package/dist/core/pipelines/types.js +21 -4
- package/dist/core/pipelines/types.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +1 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
- package/dist/core/provider-prompt-contracts.js +6 -5
- package/dist/core/provider-prompt-contracts.js.map +1 -1
- package/dist/core/reflection-controller.js +1 -1
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +2 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +46 -10
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/settings-manager.d.ts +5 -6
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +8 -13
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +2 -4
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +35 -11
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +6 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +2 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -1
- package/dist/core/tasks/task-projection.js +2 -0
- package/dist/core/tasks/task-projection.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts +10 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +43 -2
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -3
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +136 -28
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +0 -16
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +21 -11
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +45 -7
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +5 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +17 -1
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
- package/dist/core/tools/orchestration-panel.js +1 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -1
- package/dist/core/tools/persistent-process-coordinator.d.ts.map +1 -1
- package/dist/core/tools/persistent-process-coordinator.js +12 -7
- package/dist/core/tools/persistent-process-coordinator.js.map +1 -1
- package/dist/core/tools/pipeline.d.ts +1 -0
- package/dist/core/tools/pipeline.d.ts.map +1 -1
- package/dist/core/tools/pipeline.js +95 -44
- package/dist/core/tools/pipeline.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +0 -9
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +0 -3
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +2 -1
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +6 -1
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/core/tools/task-steps.d.ts +10 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +70 -29
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +6 -1
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts +8 -0
- package/dist/core/util/bounded-file.d.ts.map +1 -1
- package/dist/core/util/bounded-file.js +81 -16
- package/dist/core/util/bounded-file.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +7 -16
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +2 -11
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
- package/dist/modes/interactive/local-model-commands.js +1 -10
- package/dist/modes/interactive/local-model-commands.js.map +1 -1
- package/dist/modes/interactive/thinking-level-descriptions.d.ts +4 -0
- package/dist/modes/interactive/thinking-level-descriptions.d.ts.map +1 -0
- package/dist/modes/interactive/thinking-level-descriptions.js +12 -0
- package/dist/modes/interactive/thinking-level-descriptions.js.map +1 -0
- package/docs/resources.md +1 -1
- package/docs/settings.md +7 -5
- package/docs/worker-profiles.md +3 -3
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 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gB,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"}
|
|
@@ -38,8 +38,10 @@ export async function runProviderCompletionWithBackoff(args) {
|
|
|
38
38
|
args.onAttemptFailure();
|
|
39
39
|
if (args.signal?.aborted)
|
|
40
40
|
throw error;
|
|
41
|
-
if (error instanceof WorkerCompletionProtocolError
|
|
42
|
-
|
|
41
|
+
if (error instanceof WorkerCompletionProtocolError) {
|
|
42
|
+
throw new BoundedCompletionFailureError("failed", "worker_protocol_error", error.message, error);
|
|
43
|
+
}
|
|
44
|
+
if (error instanceof WorkerConversationOwnershipError ||
|
|
43
45
|
error instanceof CapabilityGatewayDeniedError ||
|
|
44
46
|
error instanceof WorkerTreeBudgetExceededError ||
|
|
45
47
|
error instanceof BoundedCompletionFailureError) {
|
|
@@ -456,7 +458,7 @@ export function createWorkerAttemptExecutor(options) {
|
|
|
456
458
|
throw error;
|
|
457
459
|
}
|
|
458
460
|
},
|
|
459
|
-
onMessage: (message) => {
|
|
461
|
+
onMessage: (message, origin) => {
|
|
460
462
|
try {
|
|
461
463
|
signal.throwIfAborted();
|
|
462
464
|
if (message.role === "assistant" && isToolRequest(message)) {
|
|
@@ -475,12 +477,12 @@ export function createWorkerAttemptExecutor(options) {
|
|
|
475
477
|
if (pending)
|
|
476
478
|
persistToolRequest(pending);
|
|
477
479
|
}
|
|
478
|
-
if (message.role === "assistant") {
|
|
480
|
+
if (message.role === "assistant" && origin !== "local") {
|
|
479
481
|
providerTurn.accountAssistantUsage(message.usage);
|
|
480
482
|
}
|
|
481
483
|
options.conversation.appendMessage(message);
|
|
482
484
|
options.agentControl.acknowledgeMailboxMessage(options.agentId, message);
|
|
483
|
-
if (message.role === "assistant") {
|
|
485
|
+
if (message.role === "assistant" && origin !== "local") {
|
|
484
486
|
checkpointUsage("Persisted worker assistant response and its cumulative provider usage.");
|
|
485
487
|
providerTurn.consumeTerminalAssistantAndHold();
|
|
486
488
|
}
|
|
@@ -1 +1 @@
|
|
|
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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AC,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 { 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
|
+
{"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,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CAAC;4BACxE,IAAI,CAAC,SAAS;gCAAE,OAAO,CAAC,YAAY,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;wBAC9E,CAAC;oBACF,CAAC,CAAC;oBACF,IAAI,CAAC;wBACJ,UAAU,GAAG,MAAM,gCAAgC,CAAC;4BACnD,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 { 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 (error instanceof WorkerCompletionProtocolError) {\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"worker_protocol_error\", error.message, error);\n\t\t\t}\n\t\t\tif (\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, origin) => {\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\" && origin !== \"local\") {\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\" && origin !== \"local\") {\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-authority-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAGN,KAAK,yBAAyB,EAE9B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAEvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAyBpD,MAAM,WAAW,8BAA8B;IAC9C,SAAS,CAAC,EAAE,gCAAgC,CAAC;IAC7C,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,eAAe,CAAC,EAAE,KAAK,CAAC,GA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AAC,GAAG,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED,MAAM,MAAM,yBAAyB,GAClC;IACA,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,qBAAqB,CAAC;IAChC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAqCjC,8FAA8F;AAC9F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,8BAA8B,GAAG,yBAAyB,CA6HvG"}
|
|
@@ -4,7 +4,7 @@ import { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from "../default-tool
|
|
|
4
4
|
import { ORCHESTRATION_SCHEMA_VERSION, } from "../orchestration/contracts.js";
|
|
5
5
|
import { CLASSIFIED_LANE_TOOL_NAMES } from "../orchestration/lane-tool-manifests.js";
|
|
6
6
|
import { resolvePinnedOrchestrationModel } from "../orchestration/model-binding.js";
|
|
7
|
-
import { getToolCapabilityPolicy } from "../tool-capability-policy.js";
|
|
7
|
+
import { envelopeHasToolCapability, getToolCapabilityPolicy } from "../tool-capability-policy.js";
|
|
8
8
|
import { LEAN_WORKER_DELEGATION_LIMITS } from "./worker-fleet-limits.js";
|
|
9
9
|
/**
|
|
10
10
|
* Smallest token grant a worker can survive on. A worker's first response pays the full
|
|
@@ -111,12 +111,13 @@ export function resolveWorkerAuthority(input) {
|
|
|
111
111
|
if (uniqueToolNames.includes("delegate") && inheritsDelegation) {
|
|
112
112
|
capabilities.add("workflow.delegate");
|
|
113
113
|
}
|
|
114
|
+
const capabilityList = [...capabilities];
|
|
114
115
|
const toolNames = [];
|
|
115
116
|
for (const toolName of uniqueToolNames) {
|
|
116
117
|
const policy = getToolCapabilityPolicy(toolName);
|
|
117
118
|
if (!policy)
|
|
118
119
|
return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };
|
|
119
|
-
if (
|
|
120
|
+
if (envelopeHasToolCapability(capabilityList, toolName)) {
|
|
120
121
|
toolNames.push(toolName);
|
|
121
122
|
continue;
|
|
122
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAEN,4BAA4B,GAG5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAGzE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IAC1B,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;IACJ,OAAO;IACP,MAAM;IACN,QAAQ;IACR,sBAAsB;IACtB,UAAU;CACD,CAAC;AACX,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,0BAA0B,EAAE,UAAU,CAAC,CAAC,CAAC;AACvG,MAAM,oBAAoB,GAAiC;IAC1D,iBAAiB;IACjB,kBAAkB;IAClB,eAAe;IACf,iBAAiB;IACjB,cAAc;IACd,cAAc;IACd,aAAa;IACb,cAAc;CACd,CAAC;AAoBF,SAAS,kBAAkB,CAC1B,QAA+C,EAC/C,SAAuD,EACvD,IAAuC,EACvC,eAAuC,EACvC,aAA4B;IAE5B,IAAI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AC,KAAK,CAAC,IAAI,EAAE,gBAAgB,IAAI,EAAE,CAAC;YACrE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD;QACD,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAN_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tmodelPin?: OrchestrationModelBinding;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tmodelPin: OrchestrationModelBinding | undefined,\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tif (modelPin) return { ...modelPin };\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) {\n\t\tconst floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);\n\t\tif (floorFailure) return { ok: false, reason: floorFailure };\n\t\tif (!input.modelPin) return { ok: true, shipment: input.base };\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tinput.modelPin,\n\t\t\tinput.modelRegistry,\n\t\t\tinput.isModelExhausted,\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tshipment: {\n\t\t\t\t...input.base,\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: {\n\t\t\t\t\t...input.base.profile,\n\t\t\t\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tconst binding = selectModelBinding(\n\t\tinput.modelPin,\n\t\tinput.authority,\n\t\tinput.base,\n\t\tinput.foregroundModel,\n\t\tinput.modelRegistry,\n\t);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst inheritsDelegation =\n\t\tinput.authority?.capabilities === undefined &&\n\t\t(input.base === undefined ||\n\t\t\t(input.base.profile.toolNames.includes(\"delegate\") &&\n\t\t\t\tinput.base.profile.capabilityCeiling.includes(\"workflow.delegate\")));\n\tconst requestedToolNames =\n\t\tinheritsDelegation && !configuredToolNames.includes(\"delegate\")\n\t\t\t? [...configuredToolNames, \"delegate\"]\n\t\t\t: configuredToolNames;\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tif (uniqueToolNames.includes(\"delegate\") && inheritsDelegation) {\n\t\tcapabilities.add(\"workflow.delegate\");\n\t}\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (policy.capabilityCandidates.some((capability) => capabilities.has(capability))) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst delegationLimits = input.base\n\t\t? input.base.profile.delegationLimits\n\t\t: structuredClone(LEAN_WORKER_DELEGATION_LIMITS);\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\t...(delegationLimits ? { delegationLimits: structuredClone(delegationLimits) } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAEN,4BAA4B,GAG5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAAE,6BAA6B,EAAE,MAA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EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,EAAE,mBAAmB,EAAE,MAAM,CAAC;QACtF,8BAA8B,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,8BAA8B,IAAI,KAAK;QAC3F,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,qBAAqB;YAC5C,CAAC,CAAC,EAAE,qBAAqB,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE;YACrE,CAAC,CAAC,EAAE,CAAC;QACN,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,GAAG;KACd,CAAC;IACF,OAAO;QACN,EAAE,EAAE,IAAI;QACR,QAAQ,EAAE;YACT,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,CAAC,OAAO;YACnC,OAAO;YACP,gBAAgB,EAAE,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,IAAI,EAAE,CAAC;YACrE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD;QACD,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { envelopeHasToolCapability, getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAN_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tmodelPin?: OrchestrationModelBinding;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tmodelPin: OrchestrationModelBinding | undefined,\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tif (modelPin) return { ...modelPin };\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) {\n\t\tconst floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);\n\t\tif (floorFailure) return { ok: false, reason: floorFailure };\n\t\tif (!input.modelPin) return { ok: true, shipment: input.base };\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tinput.modelPin,\n\t\t\tinput.modelRegistry,\n\t\t\tinput.isModelExhausted,\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tshipment: {\n\t\t\t\t...input.base,\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: {\n\t\t\t\t\t...input.base.profile,\n\t\t\t\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tconst binding = selectModelBinding(\n\t\tinput.modelPin,\n\t\tinput.authority,\n\t\tinput.base,\n\t\tinput.foregroundModel,\n\t\tinput.modelRegistry,\n\t);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst inheritsDelegation =\n\t\tinput.authority?.capabilities === undefined &&\n\t\t(input.base === undefined ||\n\t\t\t(input.base.profile.toolNames.includes(\"delegate\") &&\n\t\t\t\tinput.base.profile.capabilityCeiling.includes(\"workflow.delegate\")));\n\tconst requestedToolNames =\n\t\tinheritsDelegation && !configuredToolNames.includes(\"delegate\")\n\t\t\t? [...configuredToolNames, \"delegate\"]\n\t\t\t: configuredToolNames;\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tif (uniqueToolNames.includes(\"delegate\") && inheritsDelegation) {\n\t\tcapabilities.add(\"workflow.delegate\");\n\t}\n\tconst capabilityList = [...capabilities];\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (envelopeHasToolCapability(capabilityList, toolName)) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst delegationLimits = input.base\n\t\t? input.base.profile.delegationLimits\n\t\t: structuredClone(LEAN_WORKER_DELEGATION_LIMITS);\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\t...(delegationLimits ? { delegationLimits: structuredClone(delegationLimits) } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
@@ -15,7 +15,10 @@ export interface WorkerDelegationModelRequest {
|
|
|
15
15
|
provider: string;
|
|
16
16
|
modelId: string;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Trusted caller execution preferences compiled into an immutable, inherited runtime grant.
|
|
20
|
+
* The model-facing `delegate` adapter intentionally exposes a budget-free subset.
|
|
21
|
+
*/
|
|
19
22
|
export interface WorkerDelegationAuthorityRequest {
|
|
20
23
|
role?: WorkerRole;
|
|
21
24
|
model?: WorkerDelegationModelRequest;
|
|
@@ -29,7 +32,7 @@ export interface WorkerDelegationAuthorityRequest {
|
|
|
29
32
|
export declare class WorkerDelegationRequestError extends Error {
|
|
30
33
|
constructor(message: string);
|
|
31
34
|
}
|
|
32
|
-
/** Parse
|
|
35
|
+
/** Parse a caller authority request before it reaches admission or durable state. */
|
|
33
36
|
export declare function parseWorkerDelegationAuthorityRequest(value: unknown): WorkerDelegationAuthorityRequest;
|
|
34
37
|
/** A profile is an optional preset; authority is compiled and persisted by the host. */
|
|
35
38
|
export interface WorkerDelegationRequest {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-delegation-request.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,iBAAiB,EAOtB,KAAK,0BAA0B,EAC/B,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,MAAM,+BAA+B,CAAC;AAIvC,oGAAoG;AACpG,MAAM,WAAW,2BAA2B;IAC3C,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;OAIG;IACH,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,4BAA4B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"worker-delegation-request.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,iBAAiB,EAOtB,KAAK,0BAA0B,EAC/B,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,MAAM,+BAA+B,CAAC;AAIvC,oGAAoG;AACpG,MAAM,WAAW,2BAA2B;IAC3C,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,sBAAsB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C;;;;OAIG;IACH,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,4BAA4B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,gCAAgC;IAChD,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,4BAA4B,CAAC;IACrC,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,YAAY,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC5C,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,qBAAa,4BAA6B,SAAQ,KAAK;IACtD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAYD,qFAAqF;AACrF,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,OAAO,GAAG,gCAAgC,CA4EtG;AAED,wFAAwF;AACxF,MAAM,WAAW,uBAAuB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,gCAAgC,CAAC;IAC7C,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qGAAqG;IACrG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iGAAiG;IACjG,WAAW,CAAC,EAAE,2BAA2B,CAAC;CAC1C"}
|
|
@@ -17,7 +17,7 @@ function uniqueStringArray(value, label, options = {}) {
|
|
|
17
17
|
createError: (message) => new WorkerDelegationRequestError(message),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
/** Parse
|
|
20
|
+
/** Parse a caller authority request before it reaches admission or durable state. */
|
|
21
21
|
export function parseWorkerDelegationAuthorityRequest(value) {
|
|
22
22
|
if (!isPlainRecord(value))
|
|
23
23
|
throw new WorkerDelegationRequestError("Delegation authority must be an object.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-delegation-request.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAEN,mBAAmB,EACnB,iCAAiC,EACjC,uCAAuC,EACvC,gCAAgC,EAChC,0BAA0B,EAC1B,6BAA6B,EAG7B,YAAY,GAEZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAgCrE,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACtD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC5C,CAAC;CACD;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAE,KAAa,EAAE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CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7B,CAAC;AACH,CAAC","sourcesContent":["import { parseBoundedStringArray } from \"../orchestration/bounded-string-array.ts\";\nimport {\n\ttype HarnessCapability,\n\tisHarnessCapability,\n\tMAX_ORCHESTRATION_MODEL_ID_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tMAX_WORKER_AUTHORITY_PATH_LENGTH,\n\tMAX_WORKER_AUTHORITY_PATHS,\n\tORCHESTRATION_THINKING_LEVELS,\n\ttype OrchestrationThinkingLevel,\n\ttype RiskBudget,\n\tWORKER_ROLES,\n\ttype WorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport { parseRiskBudget } from \"../orchestration/risk-budget.ts\";\nimport { hasOnlyKeys, isPlainRecord } from \"../util/value-guards.ts\";\n\n/** Runtime-owned task correlation retained with a durable worker dispatch. Never model-settable. */\nexport interface WorkerDelegationTaskContext {\n\trequirementIds: readonly string[];\n\tdependsOnTaskIds: readonly string[];\n\tacceptanceCriterionIds: readonly string[];\n\t/**\n\t * Optional runtime narrowing of the owner-admitted profile resources. An empty list does not\n\t * suppress owner resources: admission expands it to the immutable profile pointer set and\n\t * persists that exact selection with the attempt.\n\t */\n\tresourcePointerIds: readonly string[];\n}\n\nexport interface WorkerDelegationModelRequest {\n\tprovider: string;\n\tmodelId: string;\n}\n\n/** Model-authored execution preferences compiled into an immutable, inherited runtime grant. */\nexport interface WorkerDelegationAuthorityRequest {\n\trole?: WorkerRole;\n\tmodel?: WorkerDelegationModelRequest;\n\tthinkingLevel?: OrchestrationThinkingLevel;\n\tcapabilities?: readonly HarnessCapability[];\n\ttoolNames?: readonly string[];\n\treadPaths?: readonly string[];\n\twritePaths?: readonly string[];\n\tbudget?: RiskBudget;\n}\n\nexport class WorkerDelegationRequestError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"WorkerDelegationRequestError\";\n\t}\n}\n\nfunction uniqueStringArray(value: unknown, label: string, options: { maxEntries?: number; maxLength?: number } = {}) {\n\treturn parseBoundedStringArray(value, {\n\t\t...options,\n\t\ttrim: true,\n\t\tinvalidMessage: `${label} must contain bounded, non-empty strings.`,\n\t\tduplicateMessage: `${label} must contain unique strings.`,\n\t\tcreateError: (message) => new WorkerDelegationRequestError(message),\n\t});\n}\n\n/** Parse the model-facing authority request before it reaches admission or durable state. */\nexport function parseWorkerDelegationAuthorityRequest(value: unknown): WorkerDelegationAuthorityRequest {\n\tif (!isPlainRecord(value)) throw new WorkerDelegationRequestError(\"Delegation authority must be an object.\");\n\tif (\n\t\t!hasOnlyKeys(value, [\n\t\t\t\"role\",\n\t\t\t\"model\",\n\t\t\t\"thinkingLevel\",\n\t\t\t\"capabilities\",\n\t\t\t\"toolNames\",\n\t\t\t\"readPaths\",\n\t\t\t\"writePaths\",\n\t\t\t\"budget\",\n\t\t])\n\t) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority contains an unsupported field.\");\n\t}\n\tif (value.role !== undefined && !WORKER_ROLES.includes(value.role as WorkerRole)) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority role is invalid.\");\n\t}\n\tif (\n\t\tvalue.thinkingLevel !== undefined &&\n\t\t!ORCHESTRATION_THINKING_LEVELS.includes(value.thinkingLevel as OrchestrationThinkingLevel)\n\t) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority thinkingLevel is invalid.\");\n\t}\n\tlet model: WorkerDelegationModelRequest | undefined;\n\tif (value.model !== undefined) {\n\t\tif (\n\t\t\t!isPlainRecord(value.model) ||\n\t\t\t!hasOnlyKeys(value.model, [\"provider\", \"modelId\"]) ||\n\t\t\ttypeof value.model.provider !== \"string\" ||\n\t\t\t!value.model.provider.trim() ||\n\t\t\tvalue.model.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\ttypeof value.model.modelId !== \"string\" ||\n\t\t\t!value.model.modelId.trim() ||\n\t\t\tvalue.model.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH\n\t\t) {\n\t\t\tthrow new WorkerDelegationRequestError(\"Delegation authority model is invalid.\");\n\t\t}\n\t\tmodel = { provider: value.model.provider.trim(), modelId: value.model.modelId.trim() };\n\t}\n\tlet capabilities: HarnessCapability[] | undefined;\n\tif (value.capabilities !== undefined) {\n\t\tconst parsed = uniqueStringArray(value.capabilities, \"Delegation authority capabilities\");\n\t\tif (!parsed.every(isHarnessCapability)) {\n\t\t\tthrow new WorkerDelegationRequestError(\"Delegation authority contains an unknown capability.\");\n\t\t}\n\t\tcapabilities = parsed;\n\t}\n\tconst toolNames =\n\t\tvalue.toolNames === undefined ? undefined : uniqueStringArray(value.toolNames, \"Delegation authority toolNames\");\n\tconst pathOptions = { maxEntries: MAX_WORKER_AUTHORITY_PATHS, maxLength: MAX_WORKER_AUTHORITY_PATH_LENGTH };\n\tconst readPaths =\n\t\tvalue.readPaths === undefined\n\t\t\t? undefined\n\t\t\t: uniqueStringArray(value.readPaths, \"Delegation authority readPaths\", pathOptions);\n\tconst writePaths =\n\t\tvalue.writePaths === undefined\n\t\t\t? undefined\n\t\t\t: uniqueStringArray(value.writePaths, \"Delegation authority writePaths\", pathOptions);\n\tlet budget: RiskBudget | undefined;\n\ttry {\n\t\tbudget = value.budget === undefined ? undefined : parseRiskBudget(value.budget, \"Delegation authority budget\");\n\t} catch (error) {\n\t\tthrow new WorkerDelegationRequestError(error instanceof Error ? error.message : String(error));\n\t}\n\treturn {\n\t\t...(value.role ? { role: value.role as WorkerRole } : {}),\n\t\t...(model ? { model } : {}),\n\t\t...(value.thinkingLevel ? { thinkingLevel: value.thinkingLevel as OrchestrationThinkingLevel } : {}),\n\t\t...(capabilities ? { capabilities } : {}),\n\t\t...(toolNames ? { toolNames } : {}),\n\t\t...(readPaths ? { readPaths } : {}),\n\t\t...(writePaths ? { writePaths } : {}),\n\t\t...(budget ? { budget } : {}),\n\t};\n}\n\n/** A profile is an optional preset; authority is compiled and persisted by the host. */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\tauthority?: WorkerDelegationAuthorityRequest;\n\t/** Tool-facing immutable birth-context selection for a newly admitted logical worker. */\n\tforkTurns?: string;\n\t/** Runtime-owned creator identity for recursive delegation; never accepted from a model argument. */\n\tparentAgentId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n\t/** Runtime-owned durable task correlation; the delegate tool schema intentionally omits this. */\n\ttaskContext?: WorkerDelegationTaskContext;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-delegation-request.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAEN,mBAAmB,EACnB,iCAAiC,EACjC,uCAAuC,EACvC,gCAAgC,EAChC,0BAA0B,EAC1B,6BAA6B,EAG7B,YAAY,GAEZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAmCrE,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACtD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC5C,CAAC;CACD;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAE,KAAa,EAAE,OAAO,GAAgD,EAAE;IAClH,OAAO,uBAAuB,CAAC,KAAK,EAAE;QACrC,G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AAE,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7B,CAAC;AACH,CAAC","sourcesContent":["import { parseBoundedStringArray } from \"../orchestration/bounded-string-array.ts\";\nimport {\n\ttype HarnessCapability,\n\tisHarnessCapability,\n\tMAX_ORCHESTRATION_MODEL_ID_LENGTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tMAX_WORKER_AUTHORITY_PATH_LENGTH,\n\tMAX_WORKER_AUTHORITY_PATHS,\n\tORCHESTRATION_THINKING_LEVELS,\n\ttype OrchestrationThinkingLevel,\n\ttype RiskBudget,\n\tWORKER_ROLES,\n\ttype WorkerRole,\n} from \"../orchestration/contracts.ts\";\nimport { parseRiskBudget } from \"../orchestration/risk-budget.ts\";\nimport { hasOnlyKeys, isPlainRecord } from \"../util/value-guards.ts\";\n\n/** Runtime-owned task correlation retained with a durable worker dispatch. Never model-settable. */\nexport interface WorkerDelegationTaskContext {\n\trequirementIds: readonly string[];\n\tdependsOnTaskIds: readonly string[];\n\tacceptanceCriterionIds: readonly string[];\n\t/**\n\t * Optional runtime narrowing of the owner-admitted profile resources. An empty list does not\n\t * suppress owner resources: admission expands it to the immutable profile pointer set and\n\t * persists that exact selection with the attempt.\n\t */\n\tresourcePointerIds: readonly string[];\n}\n\nexport interface WorkerDelegationModelRequest {\n\tprovider: string;\n\tmodelId: string;\n}\n\n/**\n * Trusted caller execution preferences compiled into an immutable, inherited runtime grant.\n * The model-facing `delegate` adapter intentionally exposes a budget-free subset.\n */\nexport interface WorkerDelegationAuthorityRequest {\n\trole?: WorkerRole;\n\tmodel?: WorkerDelegationModelRequest;\n\tthinkingLevel?: OrchestrationThinkingLevel;\n\tcapabilities?: readonly HarnessCapability[];\n\ttoolNames?: readonly string[];\n\treadPaths?: readonly string[];\n\twritePaths?: readonly string[];\n\tbudget?: RiskBudget;\n}\n\nexport class WorkerDelegationRequestError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"WorkerDelegationRequestError\";\n\t}\n}\n\nfunction uniqueStringArray(value: unknown, label: string, options: { maxEntries?: number; maxLength?: number } = {}) {\n\treturn parseBoundedStringArray(value, {\n\t\t...options,\n\t\ttrim: true,\n\t\tinvalidMessage: `${label} must contain bounded, non-empty strings.`,\n\t\tduplicateMessage: `${label} must contain unique strings.`,\n\t\tcreateError: (message) => new WorkerDelegationRequestError(message),\n\t});\n}\n\n/** Parse a caller authority request before it reaches admission or durable state. */\nexport function parseWorkerDelegationAuthorityRequest(value: unknown): WorkerDelegationAuthorityRequest {\n\tif (!isPlainRecord(value)) throw new WorkerDelegationRequestError(\"Delegation authority must be an object.\");\n\tif (\n\t\t!hasOnlyKeys(value, [\n\t\t\t\"role\",\n\t\t\t\"model\",\n\t\t\t\"thinkingLevel\",\n\t\t\t\"capabilities\",\n\t\t\t\"toolNames\",\n\t\t\t\"readPaths\",\n\t\t\t\"writePaths\",\n\t\t\t\"budget\",\n\t\t])\n\t) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority contains an unsupported field.\");\n\t}\n\tif (value.role !== undefined && !WORKER_ROLES.includes(value.role as WorkerRole)) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority role is invalid.\");\n\t}\n\tif (\n\t\tvalue.thinkingLevel !== undefined &&\n\t\t!ORCHESTRATION_THINKING_LEVELS.includes(value.thinkingLevel as OrchestrationThinkingLevel)\n\t) {\n\t\tthrow new WorkerDelegationRequestError(\"Delegation authority thinkingLevel is invalid.\");\n\t}\n\tlet model: WorkerDelegationModelRequest | undefined;\n\tif (value.model !== undefined) {\n\t\tif (\n\t\t\t!isPlainRecord(value.model) ||\n\t\t\t!hasOnlyKeys(value.model, [\"provider\", \"modelId\"]) ||\n\t\t\ttypeof value.model.provider !== \"string\" ||\n\t\t\t!value.model.provider.trim() ||\n\t\t\tvalue.model.provider.length > MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH ||\n\t\t\ttypeof value.model.modelId !== \"string\" ||\n\t\t\t!value.model.modelId.trim() ||\n\t\t\tvalue.model.modelId.length > MAX_ORCHESTRATION_MODEL_ID_LENGTH\n\t\t) {\n\t\t\tthrow new WorkerDelegationRequestError(\"Delegation authority model is invalid.\");\n\t\t}\n\t\tmodel = { provider: value.model.provider.trim(), modelId: value.model.modelId.trim() };\n\t}\n\tlet capabilities: HarnessCapability[] | undefined;\n\tif (value.capabilities !== undefined) {\n\t\tconst parsed = uniqueStringArray(value.capabilities, \"Delegation authority capabilities\");\n\t\tif (!parsed.every(isHarnessCapability)) {\n\t\t\tthrow new WorkerDelegationRequestError(\"Delegation authority contains an unknown capability.\");\n\t\t}\n\t\tcapabilities = parsed;\n\t}\n\tconst toolNames =\n\t\tvalue.toolNames === undefined ? undefined : uniqueStringArray(value.toolNames, \"Delegation authority toolNames\");\n\tconst pathOptions = { maxEntries: MAX_WORKER_AUTHORITY_PATHS, maxLength: MAX_WORKER_AUTHORITY_PATH_LENGTH };\n\tconst readPaths =\n\t\tvalue.readPaths === undefined\n\t\t\t? undefined\n\t\t\t: uniqueStringArray(value.readPaths, \"Delegation authority readPaths\", pathOptions);\n\tconst writePaths =\n\t\tvalue.writePaths === undefined\n\t\t\t? undefined\n\t\t\t: uniqueStringArray(value.writePaths, \"Delegation authority writePaths\", pathOptions);\n\tlet budget: RiskBudget | undefined;\n\ttry {\n\t\tbudget = value.budget === undefined ? undefined : parseRiskBudget(value.budget, \"Delegation authority budget\");\n\t} catch (error) {\n\t\tthrow new WorkerDelegationRequestError(error instanceof Error ? error.message : String(error));\n\t}\n\treturn {\n\t\t...(value.role ? { role: value.role as WorkerRole } : {}),\n\t\t...(model ? { model } : {}),\n\t\t...(value.thinkingLevel ? { thinkingLevel: value.thinkingLevel as OrchestrationThinkingLevel } : {}),\n\t\t...(capabilities ? { capabilities } : {}),\n\t\t...(toolNames ? { toolNames } : {}),\n\t\t...(readPaths ? { readPaths } : {}),\n\t\t...(writePaths ? { writePaths } : {}),\n\t\t...(budget ? { budget } : {}),\n\t};\n}\n\n/** A profile is an optional preset; authority is compiled and persisted by the host. */\nexport interface WorkerDelegationRequest {\n\tinstructions: string;\n\tprofileId?: string;\n\tauthority?: WorkerDelegationAuthorityRequest;\n\t/** Tool-facing immutable birth-context selection for a newly admitted logical worker. */\n\tforkTurns?: string;\n\t/** Runtime-owned creator identity for recursive delegation; never accepted from a model argument. */\n\tparentAgentId?: string;\n\t/** Runtime-owned correlation for an automatically dispatched verifier; never model-settable. */\n\tverificationOfTaskId?: string;\n\t/** Runtime-owned durable task correlation; the delegate tool schema intentionally omits this. */\n\ttaskContext?: WorkerDelegationTaskContext;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-execution-policy.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-execution-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,sBAAsB,EACtB,gCAAgC,EAChC,UAAU,EACV,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-execution-policy.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-execution-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,sBAAsB,EACtB,gCAAgC,EAChC,UAAU,EACV,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAU/E,MAAM,WAAW,mBAAmB;IACnC,aAAa,EAAE,SAAS,sBAAsB,EAAE,CAAC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