@caupulican/pi-adaptative 0.93.2 → 0.93.3
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 +10 -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 +1 -2
- package/dist/core/agent-session.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/cost-guard.js +1 -1
- package/dist/core/cost-guard.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-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/goals/goal-session-controller.js +1 -1
- package/dist/core/goals/goal-session-controller.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/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/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/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 +1 -4
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +10 -10
- package/dist/core/system-prompt-builder.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.js +1 -1
- package/dist/core/tools/edit.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/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 -4
|
@@ -3,7 +3,7 @@ export { SUBAGENT_CORE_SYSTEM_PROMPT };
|
|
|
3
3
|
/**
|
|
4
4
|
* Agent system-prompt composition with an irreducible execution-contract core.
|
|
5
5
|
*
|
|
6
|
-
* The core is the "ultimate level-0 default": ~
|
|
6
|
+
* The core is the "ultimate level-0 default": ~100 tokens of non-negotiable rules that survive ANY
|
|
7
7
|
* customization. Everything above it — the lane's role prompt and a shipped profile's soul — is a
|
|
8
8
|
* replaceable layer: settings, a lane profile, or the calling model (delegate tool) can erase and
|
|
9
9
|
* replace it entirely. This keeps shipped subagents maximally efficient on small open models (a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-prompt.js","sourceRoot":"","sources":["../../../src/core/autonomy/subagent-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAqBvC,MAAM,UAAU,2BAA2B,CAAC,KAA0B;IACrE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GACV,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC9B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAClE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,2BAA2B,CAAC;AACtG,CAAC","sourcesContent":["import { SUBAGENT_CORE_SYSTEM_PROMPT } from \"../provider-prompt-contracts.ts\";\n\nexport { SUBAGENT_CORE_SYSTEM_PROMPT };\n\n/**\n * Agent system-prompt composition with an irreducible execution-contract core.\n *\n * The core is the \"ultimate level-0 default\": ~
|
|
1
|
+
{"version":3,"file":"subagent-prompt.js","sourceRoot":"","sources":["../../../src/core/autonomy/subagent-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAqBvC,MAAM,UAAU,2BAA2B,CAAC,KAA0B;IACrE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GACV,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC9B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAClE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,2BAA2B,CAAC;AACtG,CAAC","sourcesContent":["import { SUBAGENT_CORE_SYSTEM_PROMPT } from \"../provider-prompt-contracts.ts\";\n\nexport { SUBAGENT_CORE_SYSTEM_PROMPT };\n\n/**\n * Agent system-prompt composition with an irreducible execution-contract core.\n *\n * The core is the \"ultimate level-0 default\": ~100 tokens of non-negotiable rules that survive ANY\n * customization. Everything above it — the lane's role prompt and a shipped profile's soul — is a\n * replaceable layer: settings, a lane profile, or the calling model (delegate tool) can erase and\n * replace it entirely. This keeps shipped subagents maximally efficient on small open models (a\n * caller can hand a tiny model a purpose-built minimal prompt) while the kernel remains the sole\n * authority and budget owner. Keep the core UNDER 300 tokens; it is deliberately terse.\n */\nexport interface SubagentPromptParts {\n\t/** Situational identity from the shipped profile (replaceable layer). */\n\tsoul?: string;\n\t/** The lane's default role prompt (replaceable layer). */\n\trolePrompt: string;\n\t/** User- or model-provided replacement for every layer above level 0. */\n\toverride?: string;\n}\n\nexport function composeSubagentSystemPrompt(parts: SubagentPromptParts): string {\n\tconst override = parts.override?.trim();\n\tconst above =\n\t\toverride && override.length > 0\n\t\t\t? override\n\t\t\t: [parts.soul?.trim(), parts.rolePrompt]\n\t\t\t\t\t.filter((part): part is string => Boolean(part && part.length > 0))\n\t\t\t\t\t.join(\"\\n\\n\");\n\treturn above.length > 0 ? `${SUBAGENT_CORE_SYSTEM_PROMPT}\\n\\n${above}` : SUBAGENT_CORE_SYSTEM_PROMPT;\n}\n"]}
|
package/dist/core/cost-guard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cost-guard.js","sourceRoot":"","sources":["../../src/core/cost-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAMnC;IACA,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;IAC/E,MAAM,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;IACxC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC;IACnD,MAAM,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,MAAM,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,wBAAwB,CAAC,SAAS,EAAE,SAAS,CAAC,KAAK,aAAa;YAC/F,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Proactive per-turn token cost guard (Hermes-parity superiority item #34).\n *\n * Hermes (and pi today) only react to context growth by compressing AFTER it's expensive. This estimates\n * the dollar cost of the NEXT LLM call BEFORE it is submitted, so the agent can warn the user or\n * automatically reduce reasoning effort before a runaway billing spike — a proactive ceiling, not a\n * reactive cleanup. Pure functions: no I/O, fully testable.\n */\n\n/** Per-million-token USD prices, as carried on `Model.cost`. */\nexport interface ModelTokenCost {\n\tinput: number;\n\toutput: number;\n\tcacheRead?: number;\n\tcacheWrite?: number;\n}\n\n/**\n * Estimate the USD cost of one turn: the whole current context is billed as input, plus up to\n * `maxOutputTokens` of output. `cachedInputTokens` (prefix-cache hits) are billed at the cheaper\n * cache-read rate. Fresh input is billed once at the higher of the uncached-input and cache-write\n * rates because a provider may select that prefix for a new cache write. This is an UPPER bound on\n * the turn (it also assumes the model emits its full output budget), which is what a spending ceiling\n * should bound against.\n */\nexport function estimateTurnCostUsd(args: {\n\tinputTokens: number;\n\tmaxOutputTokens: number;\n\tcost: ModelTokenCost;\n\tcachedInputTokens?: number;\n\tlongContextPricing?: { thresholdTokens: number; inputMultiplier: number; outputMultiplier: number };\n}): number {\n\tconst { inputTokens, maxOutputTokens, cost } = args;\n\tconst cached = Math.max(0, Math.min(args.cachedInputTokens ?? 0, inputTokens));\n\tconst freshInput = inputTokens - cached;\n\tconst cacheReadRate = cost.cacheRead ?? cost.input;\n\tconst freshInputRate = Math.max(cost.input, cost.cacheWrite ?? cost.input);\n\tconst longContextPricing = args.longContextPricing;\n\tconst useLongContextTier = longContextPricing && inputTokens > longContextPricing.thresholdTokens;\n\tconst inputMultiplier = useLongContextTier ? longContextPricing.inputMultiplier : 1;\n\tconst outputMultiplier = useLongContextTier ? longContextPricing.outputMultiplier : 1;\n\tconst inputUsd = ((freshInput * freshInputRate + cached * cacheReadRate) * inputMultiplier) / 1_000_000;\n\tconst outputUsd = (Math.max(0, maxOutputTokens) * cost.output * outputMultiplier) / 1_000_000;\n\treturn inputUsd + outputUsd;\n}\n\n/** What to do when a turn's projected cost exceeds the threshold. */\nexport type CostGuardAction = \"warn\" | \"downgrade\";\n\nexport interface CostGuardSettings {\n\t/** Per-turn projected USD threshold. `0` disables the guard entirely. */\n\tmaxTurnUsd: number;\n\t/** Over the ceiling: `warn` (surface a notice) or `downgrade` (also reduce reasoning effort). */\n\taction: CostGuardAction;\n}\n\nexport const DEFAULT_COST_GUARD_SETTINGS: CostGuardSettings = {\n\tmaxTurnUsd: 0,\n\taction: \"warn\",\n};\n\nexport interface CostGuardDecision {\n\t/** True when the guard is enabled AND the projected TOTAL (estUsd + backgroundUsd) exceeds the ceiling. */\n\tover: boolean;\n\t/** Projected USD cost of the next foreground call alone (unchanged meaning — what the footer's \"/turn\" label shows). */\n\testUsd: number;\n\t/** Background/spawned-lane USD spend (research/worker/reflection/fitness) folded into this decision — the caller decides the window (e.g. since the current turn began). */\n\tbackgroundUsd: number;\n\t/** `estUsd + backgroundUsd` — the value actually compared against `thresholdUsd`. */\n\ttotalUsd: number;\n\tthresholdUsd: number;\n\taction: CostGuardAction;\n}\n\n/**\n * Decide whether the projected turn cost trips the guard. Disabled (`maxTurnUsd<=0`) is never `over`.\n *\n * `cumulativeBackgroundUsd` (default 0) is spawned/background-lane spend (research, worker delegation,\n * reflection, model-fitness probes — see {@link SpawnedUsageTotals}) folded into the same ceiling as the\n * next foreground call. This function is window-agnostic — it just sums whatever the caller passes — but\n * the intended caller convention (agent-session.ts) is spend attributed to the CURRENT turn only (a\n * baseline snapshotted at the top of the turn, subtracted from the live cumulative total), not the\n * session's entire lifetime, so a turn that is cheap in the foreground but has quietly spent a lot in\n * background lanes THIS turn still trips the guard, without a prior turn's spend keeping it stuck over\n * forever (still warn-only by default).\n */\nexport function evaluateCostGuard(\n\testUsd: number,\n\tsettings: CostGuardSettings,\n\tcumulativeBackgroundUsd = 0,\n): CostGuardDecision {\n\tconst enabled = settings.maxTurnUsd > 0;\n\tconst backgroundUsd = Math.max(0, cumulativeBackgroundUsd);\n\tconst totalUsd = estUsd + backgroundUsd;\n\treturn {\n\t\tover: enabled && totalUsd > settings.maxTurnUsd,\n\t\testUsd,\n\t\tbackgroundUsd,\n\t\ttotalUsd,\n\t\tthresholdUsd: settings.maxTurnUsd,\n\t\taction: settings.action,\n\t};\n}\n\n/** Reasoning levels in descending cost order, used to pick the next-cheaper level on a downgrade. */\nconst REASONING_LADDER = [\"ultra\", \"max\", \"xhigh\", \"high\", \"medium\", \"low\", \"minimal\", \"off\"] as const;\nexport type ReasoningLevel = (typeof REASONING_LADDER)[number];\nexport type ReasoningEffortMap = Readonly<Partial<Record<ReasoningLevel, string | null>>>;\n\nfunction effectiveReasoningEffort(level: ReasoningLevel, effortMap: ReasoningEffortMap | undefined): string | null {\n\tconst mapped = effortMap?.[level];\n\treturn mapped === undefined ? level : mapped;\n}\n\n/**\n * One supported step down the reasoning ladder (cost reduction) from `current`. When\n * `supportedLevels` is provided, unsupported intermediate levels are skipped instead of relying on a\n * provider clamp that may move back upward. Returns `current` unchanged when already at the model's\n * floor or unrecognized — the guard never raises effort, only lowers it.\n */\nexport function downgradeReasoning(\n\tcurrent: string,\n\tsupportedLevels?: readonly ReasoningLevel[],\n\teffortMap?: ReasoningEffortMap,\n): ReasoningLevel | string {\n\tconst i = REASONING_LADDER.indexOf(current as ReasoningLevel);\n\tif (i < 0) return current;\n\tif (!supportedLevels) {\n\t\treturn REASONING_LADDER[Math.min(i + 1, REASONING_LADDER.length - 1)];\n\t}\n\tconst supported = new Set<ReasoningLevel>(supportedLevels);\n\tconst currentEffort = effectiveReasoningEffort(current as ReasoningLevel, effortMap);\n\tfor (let nextIndex = i + 1; nextIndex < REASONING_LADDER.length; nextIndex++) {\n\t\tconst candidate = REASONING_LADDER[nextIndex];\n\t\tif (supported.has(candidate) && effectiveReasoningEffort(candidate, effortMap) !== currentEffort)\n\t\t\treturn candidate;\n\t}\n\treturn current;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-attempt-executor.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,GAAG,EAA6B,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAE3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AAC5G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAa,KAAK,gB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CAAC,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,EAAE,aAAa,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;IAC3G,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAgFD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,4BAA4B,GAAG;IACnF,MAAM,EAAE,4BAA4B,CAAC;IACrC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAAC;IACvD,GAAG,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC7C,CAgiBA"}
|
|
@@ -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,E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,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 (\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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;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"]}
|
|
@@ -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,OAAO,GAAgD,EAAE;IAClH,OAAO,uBAAuB,CAAC,KAAK,EAAE;QACrC,GAAG,OAAO;QACV,IAAI,EAAE,IAAI;QACV,cAAc,EAAE,GAAG,KAAK,2CAA2C;QACnE,gBAAgB,EAAE,GAAG,KAAK,+BAA+B;QACzD,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,4BAA4B,CAAC,OAAO,CAAC;KACnE,CAAC,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,qCAAqC,CAAC,KAAc;IACnE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,4BAA4B,CAAC,yCAAyC,CAAC,CAAC;IAC7G,IACC,CAAC,WAAW,CAAC,KAAK,EAAE;QACnB,MAAM;QACN,OAAO;QACP,eAAe;QACf,cAAc;QACd,WAAW;QACX,W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M,IAAI,4BAA4B,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChG,CAAC;IACD,OAAO;QACN,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,aAA2C,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,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,GAAG,OAAO;QACV,IAAI,EAAE,IAAI;QACV,cAAc,EAAE,GAAG,KAAK,2CAA2C;QACnE,gBAAgB,EAAE,GAAG,KAAK,+BAA+B;QACzD,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,4BAA4B,CAAC,OAAO,CAAC;KACnE,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,qCAAqC,CAAC,KAAc;IACnE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,4BAA4B,CAAC,yCAAyC,CAAC,CAAC;IAC7G,IACC,CAAC,WAAW,CAAC,KAAK,EAAE;QACnB,MAAM;QACN,OAAO;QACP,eAAe;QACf,cAAc;QACd,WAAW;QACX,WAAW;QACX,YAAY;QACZ,QAAQ;KACR,CAAC,EACD,CAAC;QACF,MAAM,IAAI,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AC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChG,CAAC;IACD,OAAO;QACN,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,aAA2C,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,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/**\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"]}
|
|
@@ -367,7 +367,7 @@ export class GoalSessionController {
|
|
|
367
367
|
}
|
|
368
368
|
markHarnessGuardBlocked(info) {
|
|
369
369
|
const reason = info.reason === "provider_turn_limit"
|
|
370
|
-
? `provider_turn_limit: reached the ${info.repeats}-request provider-turn
|
|
370
|
+
? `provider_turn_limit: reached the explicit ${info.repeats}-request provider-turn limit`
|
|
371
371
|
: `runaway_tool_loop: repeated tool-call signature ${info.signature} ${info.repeats} times without progress`;
|
|
372
372
|
return this.stopActiveGoal("blocked", reason);
|
|
373
373
|
}
|