@code-yeongyu/senpi 2026.9.23-2 → 2026.9.23-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 +24 -0
- package/dist/bundle/chunks/{app-server-command-UO3ODP6D.js → app-server-command-U5Y46LHO.js} +1 -1
- package/dist/bundle/chunks/{chunk-OLJ7LQJY.js → chunk-BBOQ5H4W.js} +1 -1
- package/dist/bundle/chunks/{chunk-7EH64T6E.js → chunk-ORCF262V.js} +2 -2
- package/dist/bundle/chunks/{chunk-BPHXJ4N2.js → chunk-R6F525XB.js} +1 -1
- package/dist/bundle/chunks/{chunk-LMO3WYKH.js → chunk-TH4PERSI.js} +131 -124
- package/dist/bundle/chunks/{chunk-IBHBWRC4.js → chunk-TUVSARCZ.js} +2 -2
- package/dist/bundle/chunks/{chunk-WJ2BGYFK.js → chunk-XPDV6SIX.js} +1 -1
- package/dist/bundle/chunks/{chunk-IDJUNOOR.js → chunk-Y4AJLTFT.js} +2 -2
- package/dist/bundle/chunks/{cli-main-LUQZADLN.js → cli-main-65WMMIRT.js} +1 -1
- package/dist/bundle/chunks/{interactive-host-runtime-A6PM52FT.js → interactive-host-runtime-DUNYT24Q.js} +1 -1
- package/dist/bundle/chunks/{interactive-mode-VR7QYMAE.js → interactive-mode-SCG5PQZ6.js} +1 -1
- package/dist/bundle/chunks/{list-tips-VGOIMT6W.js → list-tips-Z62FXPOJ.js} +1 -1
- package/dist/bundle/chunks/{multi-session-host-LYOVVA75.js → multi-session-host-QC6BZZNH.js} +1 -1
- package/dist/bundle/chunks/{package-manager-cli-OMEJACX6.js → package-manager-cli-23GULCVL.js} +1 -1
- package/dist/bundle/chunks/{rpc-mode-AKGJA73P.js → rpc-mode-ZQ4E6FFA.js} +1 -1
- package/dist/bundle/chunks/{session-picker-UE5LOM6W.js → session-picker-CO2ZK3EC.js} +1 -1
- package/dist/bundle/chunks/session-worker.js +202 -195
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/executable-model-support.d.ts +19 -0
- package/dist/core/extensions/builtin/anthropic-subscription/executable-model-support.d.ts.map +1 -0
- package/dist/core/extensions/builtin/anthropic-subscription/executable-model-support.js +76 -0
- package/dist/core/extensions/builtin/anthropic-subscription/executable-model-support.js.map +1 -0
- package/dist/core/extensions/builtin/anthropic-subscription/executable-path-lookup.d.ts +7 -2
- package/dist/core/extensions/builtin/anthropic-subscription/executable-path-lookup.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/executable-path-lookup.js +28 -3
- package/dist/core/extensions/builtin/anthropic-subscription/executable-path-lookup.js.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/executable.d.ts +11 -0
- package/dist/core/extensions/builtin/anthropic-subscription/executable.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/executable.js +31 -10
- package/dist/core/extensions/builtin/anthropic-subscription/executable.js.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/guidance.d.ts +2 -1
- package/dist/core/extensions/builtin/anthropic-subscription/guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/guidance.js +18 -2
- package/dist/core/extensions/builtin/anthropic-subscription/guidance.js.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/stream-guidance.d.ts +2 -1
- package/dist/core/extensions/builtin/anthropic-subscription/stream-guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/stream-guidance.js +2 -2
- package/dist/core/extensions/builtin/anthropic-subscription/stream-guidance.js.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/anthropic-subscription/stream.js +5 -3
- package/dist/core/extensions/builtin/anthropic-subscription/stream.js.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.d.ts +6 -0
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js +8 -0
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +4 -2
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +3 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +32 -10
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/parked-wait.d.ts +16 -0
- package/dist/core/extensions/builtin/goal/parked-wait.d.ts.map +1 -0
- package/dist/core/extensions/builtin/goal/parked-wait.js +54 -0
- package/dist/core/extensions/builtin/goal/parked-wait.js.map +1 -0
- package/dist/core/extensions/builtin/mcp/auth/commands-auth-dispatch.d.ts +1 -1
- package/dist/core/extensions/builtin/mcp/auth/commands-auth-dispatch.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/auth/commands-auth-dispatch.js +8 -2
- package/dist/core/extensions/builtin/mcp/auth/commands-auth-dispatch.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/auth/commands-auth.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/auth/commands-auth.js +15 -4
- package/dist/core/extensions/builtin/mcp/auth/commands-auth.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/commands.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/commands.js +2 -0
- package/dist/core/extensions/builtin/mcp/commands.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +5 -5
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +16 -11
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +5 -5
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +9 -6
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/test-decision.d.ts +2 -0
- package/dist/core/extensions/builtin/prompt-preset/test-decision.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/test-decision.js +5 -0
- package/dist/core/extensions/builtin/prompt-preset/test-decision.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +6 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +5 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-config.d.ts +1 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +26 -20
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/models-json-migration.d.ts +30 -0
- package/dist/core/models-json-migration.d.ts.map +1 -0
- package/dist/core/models-json-migration.js +257 -0
- package/dist/core/models-json-migration.js.map +1 -0
- package/dist/core/output-guard.d.ts +2 -0
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js +31 -0
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +16 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-overrides.d.ts +8 -0
- package/dist/core/settings-overrides.d.ts.map +1 -0
- package/dist/core/settings-overrides.js +28 -0
- package/dist/core/settings-overrides.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +4 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts +10 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +22 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/exploration-call.d.ts +12 -0
- package/dist/modes/interactive/components/exploration-call.d.ts.map +1 -0
- package/dist/modes/interactive/components/exploration-call.js +41 -0
- package/dist/modes/interactive/components/exploration-call.js.map +1 -0
- package/dist/modes/interactive/components/exploration-group.d.ts +19 -0
- package/dist/modes/interactive/components/exploration-group.d.ts.map +1 -0
- package/dist/modes/interactive/components/exploration-group.js +89 -0
- package/dist/modes/interactive/components/exploration-group.js.map +1 -0
- package/dist/modes/interactive/components/exploration-transcript-container.d.ts +18 -0
- package/dist/modes/interactive/components/exploration-transcript-container.d.ts.map +1 -0
- package/dist/modes/interactive/components/exploration-transcript-container.js +67 -0
- package/dist/modes/interactive/components/exploration-transcript-container.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +7 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +4 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +24 -35
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/replay-assistant-tools.d.ts +14 -0
- package/dist/modes/interactive/replay-assistant-tools.d.ts.map +1 -0
- package/dist/modes/interactive/replay-assistant-tools.js +33 -0
- package/dist/modes/interactive/replay-assistant-tools.js.map +1 -0
- package/dist/modes/interactive/tool-progress.d.ts +2 -0
- package/dist/modes/interactive/tool-progress.d.ts.map +1 -1
- package/dist/modes/interactive/tool-progress.js +5 -2
- package/dist/modes/interactive/tool-progress.js.map +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +6 -1
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/docs/extensions.md +8 -0
- package/docs/mcp.md +9 -6
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +16 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +10 -8
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/display-code.ts +145 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-request.ts +7 -12
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +2 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +34 -16
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +1 -4
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/stderr-observer.d.ts +3 -0
- package/node_modules/@earendil-works/pi-tui/dist/stderr-observer.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/stderr-observer.js +14 -0
- package/node_modules/@earendil-works/pi-tui/dist/stderr-observer.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +4 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +8 -12
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -31,11 +31,27 @@ export function allAccountsBlockedGuidance(soonestUnblockAt, blockReason) {
|
|
|
31
31
|
` /login ${PROVIDER} - add another account`,
|
|
32
32
|
].join("\n");
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The remedy for a version-floor 400 depends on which binary ran: updating senpi/omo only helps
|
|
36
|
+
* the bundled one, and `claude update` (which the API text suggests) only helps a `claude` on PATH.
|
|
37
|
+
*/
|
|
38
|
+
function versionFloorRemedy(target, ran) {
|
|
39
|
+
switch (ran?.source) {
|
|
40
|
+
case "override":
|
|
41
|
+
return `The Claude Code binary set by CLAUDE_CODE_EXECUTABLE (${ran.executable}) is too old for this model. Replace it with ${target}, or unset CLAUDE_CODE_EXECUTABLE to use the Claude Code senpi/omo ships.`;
|
|
42
|
+
case "bundled":
|
|
43
|
+
return `The Claude Code bundled with senpi/omo (${ran.executable}) is too old for this model; \`claude update\` does not change it. Update senpi/omo (it ships a newer @anthropic-ai/claude-agent-sdk), install ${target} as \`claude\` on PATH (a newer one is used automatically), or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;
|
|
44
|
+
case "path":
|
|
45
|
+
return `The Claude Code on PATH (${ran.executable}) is too old for this model. Run \`claude update\` to get ${target}, or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;
|
|
46
|
+
case undefined:
|
|
47
|
+
return `The Claude Code binary is too old for this model. Update senpi/omo, update the \`claude\` on PATH, or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function claudeCodeVersionFloorGuidance(text, ran) {
|
|
35
51
|
const floor = /does not support this model; version (\S+?) or newer is required|claude_code_version_too_old/i.exec(text);
|
|
36
52
|
if (floor) {
|
|
37
53
|
const target = floor[1] === undefined ? "a newer Claude Code" : `Claude Code ${floor[1].replace(/[.,;:]+$/, "")} or newer`;
|
|
38
|
-
return
|
|
54
|
+
return versionFloorRemedy(target, ran);
|
|
39
55
|
}
|
|
40
56
|
if (/\bmodel_not_found\b|unrecognized_model|not found for provider/i.test(text)) {
|
|
41
57
|
return "The bundled Claude Code binary does not know this model id; update senpi/omo or set CLAUDE_CODE_EXECUTABLE to a newer Claude Code binary.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guidance.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/guidance.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C,MAAM,UAAU,iBAAiB,CAAC,sBAA+B;IAChE,MAAM,KAAK,GAAG;QACb,oCAAoC,QAAQ,GAAG;QAC/C,YAAY,QAAQ,mDAAmD;KACvE,CAAC;IACF,IAAI,sBAAsB,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;IACpF,CAAC;IACD,KAAK,CAAC,IAAI,CACT,kEAAkE,EAClE,mDAAmD,CACnD,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,gBAAoC,EAAE,WAA0B;IAC1G,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;QAClC,yEAAyE;QACzE,0EAA0E;QAC1E,yEAAyE;QACzE,OAAO;YACN,2BAA2B,QAAQ,gDAAgD;YACnF,YAAY,QAAQ,oDAAoD;YACxE,kDAAkD;SAClD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GACR,gBAAgB,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAClE,CAAC,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AAG,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import type { SdkErrorKind } from \"./errors.ts\";\n\nconst PROVIDER = \"anthropic-subscription\";\n\nexport function noAccountGuidance(hasAnthropicCredential: boolean): string {\n\tconst lines = [\n\t\t`No Claude account configured for ${PROVIDER}.`,\n\t\t` /login ${PROVIDER} - sign in with your Claude Pro/Max subscription`,\n\t];\n\tif (hasAnthropicCredential) {\n\t\tlines.push(\" (your existing Anthropic OAuth login will be offered as an import)\");\n\t}\n\tlines.push(\n\t\t\" Or set CLAUDE_CODE_OAUTH_TOKEN (and _2.._N for more accounts),\",\n\t\t\" or log in with the claude CLI for ambient auth.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\nexport function allAccountsBlockedGuidance(soonestUnblockAt: number | undefined, blockReason?: \"auth_error\"): string {\n\tif (blockReason === \"auth_error\") {\n\t\t// omo#8383: name the authentication failure. The recovery is a re-login,\n\t\t// and the outer credential-pool classifier maps \"authentication error\" to\n\t\t// auth_error instead of laundering the block into a rate-limit cooldown.\n\t\treturn [\n\t\t\t`All Claude accounts for ${PROVIDER} are currently blocked (authentication error).`,\n\t\t\t` /login ${PROVIDER} - re-authenticate to refresh the blocked account`,\n\t\t\t` /claude-account list - inspect account states`,\n\t\t].join(\"\\n\");\n\t}\n\tconst eta =\n\t\tsoonestUnblockAt !== undefined && Number.isFinite(soonestUnblockAt)\n\t\t\t? new Date(soonestUnblockAt).toISOString()\n\t\t\t: \"after re-login\";\n\treturn [\n\t\t`All Claude accounts for ${PROVIDER} are currently blocked (rate limit or auth errors).`,\n\t\t` Soonest automatic retry: ${eta}.`,\n\t\t` /claude-account list - inspect account states`,\n\t\t` /login ${PROVIDER} - add another account`,\n\t].join(\"\\n\");\n}\n\nexport function claudeCodeVersionFloorGuidance(text: string): string | undefined {\n\tconst floor = /does not support this model; version (\\S+?) or newer is required|claude_code_version_too_old/i.exec(\n\t\ttext,\n\t);\n\tif (floor) {\n\t\tconst target =\n\t\t\tfloor[1] === undefined ? \"a newer Claude Code\" : `Claude Code ${floor[1].replace(/[.,;:]+$/, \"\")} or newer`;\n\t\treturn `The bundled Claude Code binary is too old for this model. Update senpi/omo (it ships a newer @anthropic-ai/claude-agent-sdk) or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;\n\t}\n\tif (/\\bmodel_not_found\\b|unrecognized_model|not found for provider/i.test(text)) {\n\t\treturn \"The bundled Claude Code binary does not know this model id; update senpi/omo or set CLAUDE_CODE_EXECUTABLE to a newer Claude Code binary.\";\n\t}\n\treturn undefined;\n}\n\nexport function sdkErrorGuidance(kind: SdkErrorKind): string | undefined {\n\tswitch (kind) {\n\t\tcase \"org_not_allowed\":\n\t\t\treturn \"This organization's policy disallows subscription OAuth use here. Use an API key (ANTHROPIC_API_KEY) or an account from an allowed organization.\";\n\t\tcase \"billing\":\n\t\t\treturn \"The selected Claude account has a billing problem. Check the plan at claude.com or switch accounts with /claude-account pin <name>.\";\n\t\tcase \"auth_error\":\n\t\t\treturn `The account's OAuth token was rejected. Re-run /login ${PROVIDER} to refresh it, or remove the account with /claude-account remove <name>.`;\n\t\tcase \"entitlement\":\n\t\t\treturn \"This model needs usage credits on the selected Claude account (it is not included in the subscription). Switch models with /model, enable usage credits at claude.com, or pick another account with /claude-account pin <name>.\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport function missingBinaryGuidance(platform: string, arch: string): string {\n\treturn [\n\t\t`Claude native binary not found for ${platform}-${arch}.`,\n\t\t\"Reinstall @anthropic-ai/claude-agent-sdk without --omit=optional, or set CLAUDE_CODE_EXECUTABLE.\",\n\t].join(\"\\n\");\n}\n\nexport type SystemPromptMode = \"full\" | \"override\" | \"preset-append\";\n\nexport function overrideSystemPromptGuidance(path: string | undefined, reason: string): string {\n\tconst target = path === undefined ? \"systemPromptFile\" : `systemPromptFile \"${path}\"`;\n\treturn [\n\t\t`Anthropic Subscription override prompt could not load ${target}: ${reason}.`,\n\t\t'Set claudeSdkOauthProvider.systemPromptFile to a readable, non-empty UTF-8 prompt file, or select systemPromptMode \"full\".',\n\t].join(\" \");\n}\n\nconst armedSessions = new Set<string>();\n\nexport function resetPresetAppendDeprecation(sessionId?: string): void {\n\tif (sessionId !== undefined) {\n\t\tarmedSessions.delete(sessionId);\n\t} else {\n\t\tarmedSessions.clear();\n\t}\n}\n\nexport function presetAppendDeprecationGuidance(options: {\n\tmode: SystemPromptMode;\n\tconflict?: boolean;\n\tsessionId: string;\n}): string | undefined {\n\tif (armedSessions.has(options.sessionId)) {\n\t\treturn undefined;\n\t}\n\tconst isDeprecated = options.mode === \"preset-append\";\n\tif (!options.conflict && !isDeprecated) {\n\t\treturn undefined;\n\t}\n\tarmedSessions.add(options.sessionId);\n\tconst parts: string[] = [];\n\tif (isDeprecated) {\n\t\tparts.push(\n\t\t\t\"preset-append system-prompt mode is deprecated; \" +\n\t\t\t\t\"`full` mode delivers the complete senpi system prompt; \" +\n\t\t\t\t\"preset-append will be removed after one release.\",\n\t\t);\n\t}\n\tif (options.conflict) {\n\t\tparts.push(\"systemPromptMode wins.\");\n\t}\n\treturn parts.join(\" \");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"guidance.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/guidance.ts"],"names":[],"mappings":"AAGA,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C,MAAM,UAAU,iBAAiB,CAAC,sBAA+B;IAChE,MAAM,KAAK,GAAG;QACb,oCAAoC,QAAQ,GAAG;QAC/C,YAAY,QAAQ,mDAAmD;KACvE,CAAC;IACF,IAAI,sBAAsB,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAC;IACpF,CAAC;IACD,KAAK,CAAC,IAAI,CACT,kEAAkE,EAClE,mDAAmD,CACnD,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,gBAAoC,EAAE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,KAAK,SAAS,EAAE,CAAC;QAC7B,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACP,aAAa,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,OAI/C;IACA,IAAI,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,KAAK,eAAe,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,YAAY,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CACT,kDAAkD;YACjD,yDAAyD;YACzD,kDAAkD,CACnD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import type { SdkErrorKind } from \"./errors.ts\";\nimport type { ClaudeCodeRun } from \"./executable.ts\";\n\nconst PROVIDER = \"anthropic-subscription\";\n\nexport function noAccountGuidance(hasAnthropicCredential: boolean): string {\n\tconst lines = [\n\t\t`No Claude account configured for ${PROVIDER}.`,\n\t\t` /login ${PROVIDER} - sign in with your Claude Pro/Max subscription`,\n\t];\n\tif (hasAnthropicCredential) {\n\t\tlines.push(\" (your existing Anthropic OAuth login will be offered as an import)\");\n\t}\n\tlines.push(\n\t\t\" Or set CLAUDE_CODE_OAUTH_TOKEN (and _2.._N for more accounts),\",\n\t\t\" or log in with the claude CLI for ambient auth.\",\n\t);\n\treturn lines.join(\"\\n\");\n}\n\nexport function allAccountsBlockedGuidance(soonestUnblockAt: number | undefined, blockReason?: \"auth_error\"): string {\n\tif (blockReason === \"auth_error\") {\n\t\t// omo#8383: name the authentication failure. The recovery is a re-login,\n\t\t// and the outer credential-pool classifier maps \"authentication error\" to\n\t\t// auth_error instead of laundering the block into a rate-limit cooldown.\n\t\treturn [\n\t\t\t`All Claude accounts for ${PROVIDER} are currently blocked (authentication error).`,\n\t\t\t` /login ${PROVIDER} - re-authenticate to refresh the blocked account`,\n\t\t\t` /claude-account list - inspect account states`,\n\t\t].join(\"\\n\");\n\t}\n\tconst eta =\n\t\tsoonestUnblockAt !== undefined && Number.isFinite(soonestUnblockAt)\n\t\t\t? new Date(soonestUnblockAt).toISOString()\n\t\t\t: \"after re-login\";\n\treturn [\n\t\t`All Claude accounts for ${PROVIDER} are currently blocked (rate limit or auth errors).`,\n\t\t` Soonest automatic retry: ${eta}.`,\n\t\t` /claude-account list - inspect account states`,\n\t\t` /login ${PROVIDER} - add another account`,\n\t].join(\"\\n\");\n}\n\n/**\n * The remedy for a version-floor 400 depends on which binary ran: updating senpi/omo only helps\n * the bundled one, and `claude update` (which the API text suggests) only helps a `claude` on PATH.\n */\nfunction versionFloorRemedy(target: string, ran: ClaudeCodeRun | undefined): string {\n\tswitch (ran?.source) {\n\t\tcase \"override\":\n\t\t\treturn `The Claude Code binary set by CLAUDE_CODE_EXECUTABLE (${ran.executable}) is too old for this model. Replace it with ${target}, or unset CLAUDE_CODE_EXECUTABLE to use the Claude Code senpi/omo ships.`;\n\t\tcase \"bundled\":\n\t\t\treturn `The Claude Code bundled with senpi/omo (${ran.executable}) is too old for this model; \\`claude update\\` does not change it. Update senpi/omo (it ships a newer @anthropic-ai/claude-agent-sdk), install ${target} as \\`claude\\` on PATH (a newer one is used automatically), or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;\n\t\tcase \"path\":\n\t\t\treturn `The Claude Code on PATH (${ran.executable}) is too old for this model. Run \\`claude update\\` to get ${target}, or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;\n\t\tcase undefined:\n\t\t\treturn `The Claude Code binary is too old for this model. Update senpi/omo, update the \\`claude\\` on PATH, or set CLAUDE_CODE_EXECUTABLE to ${target} binary.`;\n\t}\n}\n\nexport function claudeCodeVersionFloorGuidance(text: string, ran?: ClaudeCodeRun): string | undefined {\n\tconst floor = /does not support this model; version (\\S+?) or newer is required|claude_code_version_too_old/i.exec(\n\t\ttext,\n\t);\n\tif (floor) {\n\t\tconst target =\n\t\t\tfloor[1] === undefined ? \"a newer Claude Code\" : `Claude Code ${floor[1].replace(/[.,;:]+$/, \"\")} or newer`;\n\t\treturn versionFloorRemedy(target, ran);\n\t}\n\tif (/\\bmodel_not_found\\b|unrecognized_model|not found for provider/i.test(text)) {\n\t\treturn \"The bundled Claude Code binary does not know this model id; update senpi/omo or set CLAUDE_CODE_EXECUTABLE to a newer Claude Code binary.\";\n\t}\n\treturn undefined;\n}\n\nexport function sdkErrorGuidance(kind: SdkErrorKind): string | undefined {\n\tswitch (kind) {\n\t\tcase \"org_not_allowed\":\n\t\t\treturn \"This organization's policy disallows subscription OAuth use here. Use an API key (ANTHROPIC_API_KEY) or an account from an allowed organization.\";\n\t\tcase \"billing\":\n\t\t\treturn \"The selected Claude account has a billing problem. Check the plan at claude.com or switch accounts with /claude-account pin <name>.\";\n\t\tcase \"auth_error\":\n\t\t\treturn `The account's OAuth token was rejected. Re-run /login ${PROVIDER} to refresh it, or remove the account with /claude-account remove <name>.`;\n\t\tcase \"entitlement\":\n\t\t\treturn \"This model needs usage credits on the selected Claude account (it is not included in the subscription). Switch models with /model, enable usage credits at claude.com, or pick another account with /claude-account pin <name>.\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport function missingBinaryGuidance(platform: string, arch: string): string {\n\treturn [\n\t\t`Claude native binary not found for ${platform}-${arch}.`,\n\t\t\"Reinstall @anthropic-ai/claude-agent-sdk without --omit=optional, or set CLAUDE_CODE_EXECUTABLE.\",\n\t].join(\"\\n\");\n}\n\nexport type SystemPromptMode = \"full\" | \"override\" | \"preset-append\";\n\nexport function overrideSystemPromptGuidance(path: string | undefined, reason: string): string {\n\tconst target = path === undefined ? \"systemPromptFile\" : `systemPromptFile \"${path}\"`;\n\treturn [\n\t\t`Anthropic Subscription override prompt could not load ${target}: ${reason}.`,\n\t\t'Set claudeSdkOauthProvider.systemPromptFile to a readable, non-empty UTF-8 prompt file, or select systemPromptMode \"full\".',\n\t].join(\" \");\n}\n\nconst armedSessions = new Set<string>();\n\nexport function resetPresetAppendDeprecation(sessionId?: string): void {\n\tif (sessionId !== undefined) {\n\t\tarmedSessions.delete(sessionId);\n\t} else {\n\t\tarmedSessions.clear();\n\t}\n}\n\nexport function presetAppendDeprecationGuidance(options: {\n\tmode: SystemPromptMode;\n\tconflict?: boolean;\n\tsessionId: string;\n}): string | undefined {\n\tif (armedSessions.has(options.sessionId)) {\n\t\treturn undefined;\n\t}\n\tconst isDeprecated = options.mode === \"preset-append\";\n\tif (!options.conflict && !isDeprecated) {\n\t\treturn undefined;\n\t}\n\tarmedSessions.add(options.sessionId);\n\tconst parts: string[] = [];\n\tif (isDeprecated) {\n\t\tparts.push(\n\t\t\t\"preset-append system-prompt mode is deprecated; \" +\n\t\t\t\t\"`full` mode delivers the complete senpi system prompt; \" +\n\t\t\t\t\"preset-append will be removed after one release.\",\n\t\t);\n\t}\n\tif (options.conflict) {\n\t\tparts.push(\"systemPromptMode wins.\");\n\t}\n\treturn parts.join(\" \");\n}\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ClaudeCodeRun } from "./executable.ts";
|
|
2
|
+
export declare function withAuthGuidance(error: unknown, message: string, ran?: ClaudeCodeRun): string;
|
|
2
3
|
//# sourceMappingURL=stream-guidance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-guidance.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream-guidance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-guidance.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream-guidance.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,CAO7F"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AllAccountsBlockedError } from "./affinity.js";
|
|
2
2
|
import { classifySdkError } from "./errors.js";
|
|
3
3
|
import { allAccountsBlockedGuidance, claudeCodeVersionFloorGuidance, sdkErrorGuidance } from "./guidance.js";
|
|
4
|
-
export function withAuthGuidance(error, message) {
|
|
4
|
+
export function withAuthGuidance(error, message, ran) {
|
|
5
5
|
if (error instanceof AllAccountsBlockedError)
|
|
6
6
|
return allAccountsBlockedGuidance(error.soonestUnblockAt, error.blockReason);
|
|
7
7
|
const guidance = sdkErrorGuidance(classifySdkError(error).kind);
|
|
8
|
-
const versionGuidance = claudeCodeVersionFloorGuidance(message);
|
|
8
|
+
const versionGuidance = claudeCodeVersionFloorGuidance(message, ran);
|
|
9
9
|
const hints = [guidance, versionGuidance].filter((hint) => hint !== undefined);
|
|
10
10
|
return hints.length > 0 ? `${message}\n${hints.join("\n")}` : message;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-guidance.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream-guidance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"stream-guidance.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream-guidance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE7G,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAe,EAAE,GAAmB;IACpF,IAAI,KAAK,YAAY,uBAAuB;QAC3C,OAAO,0BAA0B,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,eAAe,GAAG,8BAA8B,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC/F,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC","sourcesContent":["import { AllAccountsBlockedError } from \"./affinity.ts\";\nimport { classifySdkError } from \"./errors.ts\";\nimport type { ClaudeCodeRun } from \"./executable.ts\";\nimport { allAccountsBlockedGuidance, claudeCodeVersionFloorGuidance, sdkErrorGuidance } from \"./guidance.ts\";\n\nexport function withAuthGuidance(error: unknown, message: string, ran?: ClaudeCodeRun): string {\n\tif (error instanceof AllAccountsBlockedError)\n\t\treturn allAccountsBlockedGuidance(error.soonestUnblockAt, error.blockReason);\n\tconst guidance = sdkErrorGuidance(classifySdkError(error).kind);\n\tconst versionGuidance = claudeCodeVersionFloorGuidance(message, ran);\n\tconst hints = [guidance, versionGuidance].filter((hint): hint is string => hint !== undefined);\n\treturn hints.length > 0 ? `${message}\\n${hints.join(\"\\n\")}` : message;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,2BAA2B,EAChC,KAAK,OAAO,EAGZ,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,MAAM,uBAAuB,CAAC;AAoB/B,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,2BAA2B,EAChC,KAAK,OAAO,EAGZ,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,MAAM,uBAAuB,CAAC;AAoB/B,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CA8M7B"}
|
|
@@ -3,7 +3,7 @@ import { getSessionClaudeAccountPin } from "./account-command.js";
|
|
|
3
3
|
import { queryWithAuthLane } from "./auth-lane.js";
|
|
4
4
|
import { buildCustomToolServers } from "./custom-tools.js";
|
|
5
5
|
import { sdkAssistantFailure, sdkResultFailure, sdkResultFailureUsage } from "./errors.js";
|
|
6
|
-
import { defaultExecutableDeps,
|
|
6
|
+
import { defaultExecutableDeps, resolveClaudeCodeRun } from "./executable.js";
|
|
7
7
|
import { buildAnthropicSubscriptionQueryOptions } from "./options.js";
|
|
8
8
|
import { buildPromptBlocks, buildPromptStream } from "./prompt-bridge.js";
|
|
9
9
|
import { dedupeUltraworkBlocks } from "./prompt-directive-dedupe.js";
|
|
@@ -49,6 +49,7 @@ export function streamAnthropicSubscription(model, context, options) {
|
|
|
49
49
|
onAbort();
|
|
50
50
|
else
|
|
51
51
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
52
|
+
let claudeCodeRun;
|
|
52
53
|
try {
|
|
53
54
|
// Resident before the synchronous SDK member below (getSdkBoundary().query)
|
|
54
55
|
// reads it - see sdk-boundary.lazy.ts.
|
|
@@ -62,7 +63,8 @@ export function streamAnthropicSubscription(model, context, options) {
|
|
|
62
63
|
const providerSettings = loadAnthropicSubscriptionProviderSettingsFromDisk(process.cwd());
|
|
63
64
|
const toolLessRequest = options?.toolChoice === "none";
|
|
64
65
|
const mcpServers = toolLessRequest ? undefined : await buildCustomToolServers(resolvedTools.customTools);
|
|
65
|
-
|
|
66
|
+
claudeCodeRun = resolveClaudeCodeRun(defaultExecutableDeps());
|
|
67
|
+
const executable = claudeCodeRun.executable;
|
|
66
68
|
const buildOptions = (authLane) => {
|
|
67
69
|
const queryOptions = buildAnthropicSubscriptionQueryOptions({
|
|
68
70
|
model,
|
|
@@ -215,7 +217,7 @@ export function streamAnthropicSubscription(model, context, options) {
|
|
|
215
217
|
const billed = sdkResultFailureUsage(error);
|
|
216
218
|
if (billed)
|
|
217
219
|
updateUsage(model, output, billed);
|
|
218
|
-
output.errorMessage = withAuthGuidance(error, errorMessage(error));
|
|
220
|
+
output.errorMessage = withAuthGuidance(error, errorMessage(error), claudeCodeRun);
|
|
219
221
|
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
220
222
|
}
|
|
221
223
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream.ts"],"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G,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACnE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;gBAAS,CAAC;YACV,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,UAAU,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getSessionClaudeAccountPin } from \"./account-command.ts\";\nimport { queryWithAuthLane } from \"./auth-lane.ts\";\nimport { buildCustomToolServers } from \"./custom-tools.ts\";\nimport { sdkAssistantFailure, sdkResultFailure, sdkResultFailureUsage } from \"./errors.ts\";\nimport { defaultExecutableDeps, resolveClaudeCodeExecutable } from \"./executable.ts\";\nimport { buildAnthropicSubscriptionQueryOptions } from \"./options.ts\";\nimport { buildPromptBlocks, buildPromptStream } from \"./prompt-bridge.ts\";\nimport { dedupeUltraworkBlocks } from \"./prompt-directive-dedupe.ts\";\nimport { refusalError } from \"./refusal.ts\";\nimport { getSdkBoundary, loadClaudeAgentSdk, type SdkQueryHandle } from \"./sdk-boundary.ts\";\nimport { type ContinuityObservation, emitContinuityObservation } from \"./session-observability.ts\";\nimport { residentSessionMessages } from \"./session-stream.ts\";\nimport { loadAnthropicSubscriptionProviderSettingsFromDisk } from \"./settings.ts\";\nimport { applyStreamEvent } from \"./stream-events.ts\";\nimport { withAuthGuidance } from \"./stream-guidance.ts\";\nimport { emptyOutput, errorMessage, mapStopReason, type StreamBlock, updateUsage } from \"./stream-protocol.ts\";\nimport { toolWatch } from \"./tool-watch.ts\";\nimport { resolveSdkTools } from \"./tools.ts\";\n\nexport function streamAnthropicSubscription(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst output = emptyOutput(model);\n\t\tconst blocks: StreamBlock[] = [];\n\t\tlet sdkQuery: SdkQueryHandle | undefined;\n\t\tlet closed = false;\n\t\tlet wasAborted = false;\n\t\tlet started = false;\n\t\tlet sawStreamEvent = false;\n\t\tconst closeQuery = (): void => {\n\t\t\tif (closed || !sdkQuery) return;\n\t\t\tclosed = true;\n\t\t\tsdkQuery.close();\n\t\t};\n\t\tconst requestAbort = (): void => {\n\t\t\tif (!sdkQuery) return;\n\t\t\tvoid sdkQuery\n\t\t\t\t.interrupt()\n\t\t\t\t.catch(() => {})\n\t\t\t\t.finally(closeQuery);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t\trequestAbort();\n\t\t};\n\t\tif (options?.signal?.aborted) onAbort();\n\t\telse options?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\ttry {\n\t\t\t// Resident before the synchronous SDK member below (getSdkBoundary().query)\n\t\t\t// reads it - see sdk-boundary.lazy.ts.\n\t\t\tawait loadClaudeAgentSdk();\n\t\t\tconst resolvedTools = resolveSdkTools(context);\n\t\t\tconst affinityKey = options?.affinitySessionId ?? options?.sessionId;\n\t\t\tconst sessionKey = options?.sessionId ? toolWatch.sessionKey(options.sessionId) : undefined;\n\t\t\tif (sessionKey) toolWatch.reconcileWithContext(sessionKey, context);\n\t\t\tconst toolWatchNote = toolWatch.buildPromptNote(sessionKey, context, resolvedTools.customToolNameToSdk);\n\t\t\tconst providerSettings = loadAnthropicSubscriptionProviderSettingsFromDisk(process.cwd());\n\t\t\tconst toolLessRequest = options?.toolChoice === \"none\";\n\t\t\tconst mcpServers = toolLessRequest ? undefined : await buildCustomToolServers(resolvedTools.customTools);\n\t\t\tconst executable = resolveClaudeCodeExecutable(defaultExecutableDeps());\n\t\t\tconst buildOptions = (authLane: Parameters<typeof buildAnthropicSubscriptionQueryOptions>[0][\"authLane\"]) => {\n\t\t\t\tconst queryOptions = buildAnthropicSubscriptionQueryOptions({\n\t\t\t\t\tmodel,\n\t\t\t\t\tcontext,\n\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\tproviderSettings,\n\t\t\t\t\tauthLane,\n\t\t\t\t\ttools: resolvedTools.sdkTools,\n\t\t\t\t\tpathToClaudeCodeExecutable: executable,\n\t\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\t\tonGuidance: (text) => {\n\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_deprecation\", text),\n\t\t\t\t\t\t];\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (mcpServers) queryOptions.mcpServers = mcpServers;\n\t\t\t\treturn queryOptions;\n\t\t\t};\n\t\t\tconst recordContinuity = (observation: ContinuityObservation): void => {\n\t\t\t\t// Not a failure: carry the observation as details only, with no synthesized error.\n\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"claude_sdk_oauth_session_continuity\",\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\tdetails: { ...observation },\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t};\n\t\t\tconst useResidentSession =\n\t\t\t\toptions?.streamKind === \"main\" && providerSettings.resumeMode !== \"off\" && options.sessionId !== undefined;\n\t\t\tif (options?.streamKind === \"main\" && !useResidentSession) {\n\t\t\t\t// The reason must reflect the ACTUAL cause: resume mode \"off\"\n\t\t\t\t// disables the lane by setting, while any other mode simply has no\n\t\t\t\t// resident session to reuse yet.\n\t\t\t\temitContinuityObservation(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"disabled\",\n\t\t\t\t\t\treason: providerSettings.resumeMode === \"off\" ? \"resume_mode_off\" : \"registry_miss\",\n\t\t\t\t\t},\n\t\t\t\t\trecordContinuity,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst messages = useResidentSession\n\t\t\t\t? residentSessionMessages({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options.sessionId),\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t\tcustomToolNameToSdk: resolvedTools.customToolNameToSdk,\n\t\t\t\t\t\ttoolWatchNote,\n\t\t\t\t\t\tonContinuityDecision: recordContinuity,\n\t\t\t\t\t\tonResumeFallback: (error) => {\n\t\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_resume_fallback\", error),\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: queryWithAuthLane({\n\t\t\t\t\t\tprompt: buildPromptStream(\n\t\t\t\t\t\t\tdedupeUltraworkBlocks(buildPromptBlocks(context, resolvedTools.customToolNameToSdk, toolWatchNote))\n\t\t\t\t\t\t\t\t.blocks,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tquery: getSdkBoundary().query,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tenv: options?.env,\n\t\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t\t\tsessionId: affinityKey,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options?.sessionId),\n\t\t\t\t\t\tonQuery: (query) => {\n\t\t\t\t\t\t\tsdkQuery = query;\n\t\t\t\t\t\t\tif (wasAborted) requestAbort();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t});\n\n\t\t\tfor await (const message of messages) {\n\t\t\t\tconst refusal = refusalError(message);\n\t\t\t\tif (refusal) throw refusal;\n\t\t\t\tconst failure =\n\t\t\t\t\tmessage.type === \"assistant\"\n\t\t\t\t\t\t? sdkAssistantFailure(message)\n\t\t\t\t\t\t: message.type === \"result\"\n\t\t\t\t\t\t\t? sdkResultFailure(message)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\tif (failure) throw failure;\n\t\t\t\tif (!started) {\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\tstarted = true;\n\t\t\t\t}\n\t\t\t\tif (message.type === \"stream_event\") {\n\t\t\t\t\tsawStreamEvent = true;\n\t\t\t\t\tapplyStreamEvent(\n\t\t\t\t\t\t{ model, output, blocks, stream, customToolNameToPi: resolvedTools.customToolNameToPi },\n\t\t\t\t\t\tmessage.event,\n\t\t\t\t\t);\n\t\t\t\t} else if (message.type === \"system\" && message.subtype === \"compact_boundary\") {\n\t\t\t\t\t// Native compactions must reach the ledger: attach the boundary as a\n\t\t\t\t\t// diagnostic so the lane-policy collector can build a ledger entry\n\t\t\t\t\t// instead of the boundary being discarded in the stream.\n\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"claude_sdk_oauth_compact_boundary\",\n\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\t\t\ttrigger: message.compact_metadata?.trigger ?? \"unknown\",\n\t\t\t\t\t\t\t\t\tpreTokens: message.compact_metadata?.pre_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tpostTokens: message.compact_metadata?.post_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tlineageId: message.session_id ?? \"\",\n\t\t\t\t\t\t\t\t\tobservedAt: Date.now(),\n\t\t\t\t\t\t\t\t},\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} else if (message.type === \"result\" && message.subtype === \"success\") {\n\t\t\t\t\t// Both fields are optional on the wire, so only adopt them when present.\n\t\t\t\t\t// A terminal result must never downgrade a toolUse turn that the stream\n\t\t\t\t\t// already established, or the agent loop would stop instead of running\n\t\t\t\t\t// the tool call sitting in `output.content`.\n\t\t\t\t\tif (message.usage) updateUsage(model, output, message.usage);\n\t\t\t\t\tif (message.stop_reason != null && output.stopReason !== \"toolUse\") {\n\t\t\t\t\t\toutput.stopReason = mapStopReason(message.stop_reason);\n\t\t\t\t\t}\n\t\t\t\t\tif (!sawStreamEvent) output.content.push({ type: \"text\", text: message.result });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (wasAborted || options?.signal?.aborted) {\n\t\t\t\toutput.stopReason = \"aborted\";\n\t\t\t\toutput.errorMessage = \"Operation aborted\";\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: output });\n\t\t\t} else {\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"done\",\n\t\t\t\t\treason: output.stopReason === \"toolUse\" ? \"toolUse\" : output.stopReason === \"length\" ? \"length\" : \"stop\",\n\t\t\t\t\tmessage: output,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// no-excuse-ok: catch\n\t\t\t// Provider boundary converts every thrown SDK value into the stream error contract.\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\t// A failed result still bills its tokens; managed and resident lanes\n\t\t\t// throw before the result reaches this loop, so account for it here.\n\t\t\tconst billed = sdkResultFailureUsage(error);\n\t\t\tif (billed) updateUsage(model, output, billed);\n\t\t\toutput.errorMessage = withAuthGuidance(error, errorMessage(error));\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tcloseQuery();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/anthropic-subscription/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,gCAAgC,EAChC,iCAAiC,GAGjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAsB,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAAE,sCAAsC,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAuB,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAA8B,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,iDAAiD,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAoB,WAAW,EAAE,MAAM,sBAAsB,CAAC;A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E,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;YACnE,qEAAqE;YACrE,qEAAqE;YACrE,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YAC5C,IAAI,MAAM;gBAAE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YAC/C,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,CAAC;YAClF,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;gBAAS,CAAC;YACV,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,UAAU,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getSessionClaudeAccountPin } from \"./account-command.ts\";\nimport { queryWithAuthLane } from \"./auth-lane.ts\";\nimport { buildCustomToolServers } from \"./custom-tools.ts\";\nimport { sdkAssistantFailure, sdkResultFailure, sdkResultFailureUsage } from \"./errors.ts\";\nimport { type ClaudeCodeRun, defaultExecutableDeps, resolveClaudeCodeRun } from \"./executable.ts\";\nimport { buildAnthropicSubscriptionQueryOptions } from \"./options.ts\";\nimport { buildPromptBlocks, buildPromptStream } from \"./prompt-bridge.ts\";\nimport { dedupeUltraworkBlocks } from \"./prompt-directive-dedupe.ts\";\nimport { refusalError } from \"./refusal.ts\";\nimport { getSdkBoundary, loadClaudeAgentSdk, type SdkQueryHandle } from \"./sdk-boundary.ts\";\nimport { type ContinuityObservation, emitContinuityObservation } from \"./session-observability.ts\";\nimport { residentSessionMessages } from \"./session-stream.ts\";\nimport { loadAnthropicSubscriptionProviderSettingsFromDisk } from \"./settings.ts\";\nimport { applyStreamEvent } from \"./stream-events.ts\";\nimport { withAuthGuidance } from \"./stream-guidance.ts\";\nimport { emptyOutput, errorMessage, mapStopReason, type StreamBlock, updateUsage } from \"./stream-protocol.ts\";\nimport { toolWatch } from \"./tool-watch.ts\";\nimport { resolveSdkTools } from \"./tools.ts\";\n\nexport function streamAnthropicSubscription(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst output = emptyOutput(model);\n\t\tconst blocks: StreamBlock[] = [];\n\t\tlet sdkQuery: SdkQueryHandle | undefined;\n\t\tlet closed = false;\n\t\tlet wasAborted = false;\n\t\tlet started = false;\n\t\tlet sawStreamEvent = false;\n\t\tconst closeQuery = (): void => {\n\t\t\tif (closed || !sdkQuery) return;\n\t\t\tclosed = true;\n\t\t\tsdkQuery.close();\n\t\t};\n\t\tconst requestAbort = (): void => {\n\t\t\tif (!sdkQuery) return;\n\t\t\tvoid sdkQuery\n\t\t\t\t.interrupt()\n\t\t\t\t.catch(() => {})\n\t\t\t\t.finally(closeQuery);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t\trequestAbort();\n\t\t};\n\t\tif (options?.signal?.aborted) onAbort();\n\t\telse options?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tlet claudeCodeRun: ClaudeCodeRun | undefined;\n\n\t\ttry {\n\t\t\t// Resident before the synchronous SDK member below (getSdkBoundary().query)\n\t\t\t// reads it - see sdk-boundary.lazy.ts.\n\t\t\tawait loadClaudeAgentSdk();\n\t\t\tconst resolvedTools = resolveSdkTools(context);\n\t\t\tconst affinityKey = options?.affinitySessionId ?? options?.sessionId;\n\t\t\tconst sessionKey = options?.sessionId ? toolWatch.sessionKey(options.sessionId) : undefined;\n\t\t\tif (sessionKey) toolWatch.reconcileWithContext(sessionKey, context);\n\t\t\tconst toolWatchNote = toolWatch.buildPromptNote(sessionKey, context, resolvedTools.customToolNameToSdk);\n\t\t\tconst providerSettings = loadAnthropicSubscriptionProviderSettingsFromDisk(process.cwd());\n\t\t\tconst toolLessRequest = options?.toolChoice === \"none\";\n\t\t\tconst mcpServers = toolLessRequest ? undefined : await buildCustomToolServers(resolvedTools.customTools);\n\t\t\tclaudeCodeRun = resolveClaudeCodeRun(defaultExecutableDeps());\n\t\t\tconst executable = claudeCodeRun.executable;\n\t\t\tconst buildOptions = (authLane: Parameters<typeof buildAnthropicSubscriptionQueryOptions>[0][\"authLane\"]) => {\n\t\t\t\tconst queryOptions = buildAnthropicSubscriptionQueryOptions({\n\t\t\t\t\tmodel,\n\t\t\t\t\tcontext,\n\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\tproviderSettings,\n\t\t\t\t\tauthLane,\n\t\t\t\t\ttools: resolvedTools.sdkTools,\n\t\t\t\t\tpathToClaudeCodeExecutable: executable,\n\t\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\t\tonGuidance: (text) => {\n\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_deprecation\", text),\n\t\t\t\t\t\t];\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (mcpServers) queryOptions.mcpServers = mcpServers;\n\t\t\t\treturn queryOptions;\n\t\t\t};\n\t\t\tconst recordContinuity = (observation: ContinuityObservation): void => {\n\t\t\t\t// Not a failure: carry the observation as details only, with no synthesized error.\n\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"claude_sdk_oauth_session_continuity\",\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\tdetails: { ...observation },\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t};\n\t\t\tconst useResidentSession =\n\t\t\t\toptions?.streamKind === \"main\" && providerSettings.resumeMode !== \"off\" && options.sessionId !== undefined;\n\t\t\tif (options?.streamKind === \"main\" && !useResidentSession) {\n\t\t\t\t// The reason must reflect the ACTUAL cause: resume mode \"off\"\n\t\t\t\t// disables the lane by setting, while any other mode simply has no\n\t\t\t\t// resident session to reuse yet.\n\t\t\t\temitContinuityObservation(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"disabled\",\n\t\t\t\t\t\treason: providerSettings.resumeMode === \"off\" ? \"resume_mode_off\" : \"registry_miss\",\n\t\t\t\t\t},\n\t\t\t\t\trecordContinuity,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst messages = useResidentSession\n\t\t\t\t? residentSessionMessages({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options.sessionId),\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t\tcustomToolNameToSdk: resolvedTools.customToolNameToSdk,\n\t\t\t\t\t\ttoolWatchNote,\n\t\t\t\t\t\tonContinuityDecision: recordContinuity,\n\t\t\t\t\t\tonResumeFallback: (error) => {\n\t\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_resume_fallback\", error),\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: queryWithAuthLane({\n\t\t\t\t\t\tprompt: buildPromptStream(\n\t\t\t\t\t\t\tdedupeUltraworkBlocks(buildPromptBlocks(context, resolvedTools.customToolNameToSdk, toolWatchNote))\n\t\t\t\t\t\t\t\t.blocks,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tquery: getSdkBoundary().query,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tenv: options?.env,\n\t\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t\t\tsessionId: affinityKey,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options?.sessionId),\n\t\t\t\t\t\tonQuery: (query) => {\n\t\t\t\t\t\t\tsdkQuery = query;\n\t\t\t\t\t\t\tif (wasAborted) requestAbort();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t});\n\n\t\t\tfor await (const message of messages) {\n\t\t\t\tconst refusal = refusalError(message);\n\t\t\t\tif (refusal) throw refusal;\n\t\t\t\tconst failure =\n\t\t\t\t\tmessage.type === \"assistant\"\n\t\t\t\t\t\t? sdkAssistantFailure(message)\n\t\t\t\t\t\t: message.type === \"result\"\n\t\t\t\t\t\t\t? sdkResultFailure(message)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\tif (failure) throw failure;\n\t\t\t\tif (!started) {\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\tstarted = true;\n\t\t\t\t}\n\t\t\t\tif (message.type === \"stream_event\") {\n\t\t\t\t\tsawStreamEvent = true;\n\t\t\t\t\tapplyStreamEvent(\n\t\t\t\t\t\t{ model, output, blocks, stream, customToolNameToPi: resolvedTools.customToolNameToPi },\n\t\t\t\t\t\tmessage.event,\n\t\t\t\t\t);\n\t\t\t\t} else if (message.type === \"system\" && message.subtype === \"compact_boundary\") {\n\t\t\t\t\t// Native compactions must reach the ledger: attach the boundary as a\n\t\t\t\t\t// diagnostic so the lane-policy collector can build a ledger entry\n\t\t\t\t\t// instead of the boundary being discarded in the stream.\n\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"claude_sdk_oauth_compact_boundary\",\n\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\t\t\ttrigger: message.compact_metadata?.trigger ?? \"unknown\",\n\t\t\t\t\t\t\t\t\tpreTokens: message.compact_metadata?.pre_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tpostTokens: message.compact_metadata?.post_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tlineageId: message.session_id ?? \"\",\n\t\t\t\t\t\t\t\t\tobservedAt: Date.now(),\n\t\t\t\t\t\t\t\t},\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} else if (message.type === \"result\" && message.subtype === \"success\") {\n\t\t\t\t\t// Both fields are optional on the wire, so only adopt them when present.\n\t\t\t\t\t// A terminal result must never downgrade a toolUse turn that the stream\n\t\t\t\t\t// already established, or the agent loop would stop instead of running\n\t\t\t\t\t// the tool call sitting in `output.content`.\n\t\t\t\t\tif (message.usage) updateUsage(model, output, message.usage);\n\t\t\t\t\tif (message.stop_reason != null && output.stopReason !== \"toolUse\") {\n\t\t\t\t\t\toutput.stopReason = mapStopReason(message.stop_reason);\n\t\t\t\t\t}\n\t\t\t\t\tif (!sawStreamEvent) output.content.push({ type: \"text\", text: message.result });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (wasAborted || options?.signal?.aborted) {\n\t\t\t\toutput.stopReason = \"aborted\";\n\t\t\t\toutput.errorMessage = \"Operation aborted\";\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: output });\n\t\t\t} else {\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"done\",\n\t\t\t\t\treason: output.stopReason === \"toolUse\" ? \"toolUse\" : output.stopReason === \"length\" ? \"length\" : \"stop\",\n\t\t\t\t\tmessage: output,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// no-excuse-ok: catch\n\t\t\t// Provider boundary converts every thrown SDK value into the stream error contract.\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\t// A failed result still bills its tokens; managed and resident lanes\n\t\t\t// throw before the result reaches this loop, so account for it here.\n\t\t\tconst billed = sdkResultFailureUsage(error);\n\t\t\tif (billed) updateUsage(model, output, billed);\n\t\t\toutput.errorMessage = withAuthGuidance(error, errorMessage(error), claudeCodeRun);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tcloseQuery();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import type { CustomEntry } from "../../../session-manager.ts";
|
|
1
2
|
import type { EntryRenderer } from "../../types.ts";
|
|
2
3
|
import { type GoalCacheWarmupEntryData } from "./cache-warm.ts";
|
|
3
4
|
export declare const renderGoalCacheWarmupEntry: EntryRenderer<GoalCacheWarmupEntryData>;
|
|
5
|
+
/**
|
|
6
|
+
* One card per wait cycle: a cache-warm entry for the same Goal that directly follows the
|
|
7
|
+
* previous card (a reload re-arm, or the wake that ends the wait) replaces it in place.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isSameGoalCacheWarmCard(previous: CustomEntry<GoalCacheWarmupEntryData>, next: CustomEntry<GoalCacheWarmupEntryData>): boolean;
|
|
4
10
|
//# sourceMappingURL=cache-warm-renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-warm-renderer.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/cache-warm-renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache-warm-renderer.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/cache-warm-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAMN,KAAK,wBAAwB,EAC7B,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,0BAA0B,EAAE,aAAa,CAAC,wBAAwB,CAU7E,CAAC;AAEH;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,QAAQ,EAAE,WAAW,CAAC,wBAAwB,CAAC,EAC/C,IAAI,EAAE,WAAW,CAAC,wBAAwB,CAAC,GACzC,OAAO,CAGT"}
|
|
@@ -12,6 +12,14 @@ export const renderGoalCacheWarmupEntry = noticeEntryRenderer((entry) => {
|
|
|
12
12
|
expandedLine: expandedLine(data),
|
|
13
13
|
};
|
|
14
14
|
});
|
|
15
|
+
/**
|
|
16
|
+
* One card per wait cycle: a cache-warm entry for the same Goal that directly follows the
|
|
17
|
+
* previous card (a reload re-arm, or the wake that ends the wait) replaces it in place.
|
|
18
|
+
*/
|
|
19
|
+
export function isSameGoalCacheWarmCard(previous, next) {
|
|
20
|
+
const goalId = next.data?.goalId;
|
|
21
|
+
return typeof goalId === "string" && goalId.length > 0 && previous.data?.goalId === goalId;
|
|
22
|
+
}
|
|
15
23
|
function titleLine(data) {
|
|
16
24
|
const wakeSources = data.activeMonitorCount === 1 ? "1 wake source on duty" : `${data.activeMonitorCount} wake sources on duty`;
|
|
17
25
|
const iteration = validIteration(data.iteration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-warm-renderer.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/cache-warm-renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache-warm-renderer.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/cache-warm-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAA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;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,kCAAkC,CAAC;IAC9G,MAAM,KAAK,GACV,KAAK,CAAC,iBAAiB,KAAK,SAAS,IAAI,KAAK,CAAC,iBAAiB,GAAG,CAAC;QACnE,CAAC,CAAC,WAAW,cAAc,CAAC,KAAK,CAAC,iBAAiB,CAAC,0BAA0B;QAC9E,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,GAAG,IAAI,GAAG,KAAK,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import type { CustomEntry } from \"../../../session-manager.ts\";\nimport { noticeEntryRenderer } from \"../../notice/index.ts\";\nimport type { EntryRenderer } from \"../../types.ts\";\nimport {\n\tformatCacheTtl,\n\tformatSavedUsd,\n\tformatWakeDuration,\n\tformatWakeTimestamp,\n\tformatWarmTokenCount,\n\ttype GoalCacheWarmupEntryData,\n} from \"./cache-warm.ts\";\n\nexport const renderGoalCacheWarmupEntry: EntryRenderer<GoalCacheWarmupEntryData> = noticeEntryRenderer((entry) => {\n\tconst data = entry.data;\n\tif (data === undefined) return undefined;\n\tconst warm = warmLine(data);\n\treturn {\n\t\ttitle: titleLine(data),\n\t\twhy: whyLine(data),\n\t\textra: warm === undefined ? [] : [{ text: warm, tone: \"success\" }],\n\t\texpandedLine: expandedLine(data),\n\t};\n});\n\n/**\n * One card per wait cycle: a cache-warm entry for the same Goal that directly follows the\n * previous card (a reload re-arm, or the wake that ends the wait) replaces it in place.\n */\nexport function isSameGoalCacheWarmCard(\n\tprevious: CustomEntry<GoalCacheWarmupEntryData>,\n\tnext: CustomEntry<GoalCacheWarmupEntryData>,\n): boolean {\n\tconst goalId = next.data?.goalId;\n\treturn typeof goalId === \"string\" && goalId.length > 0 && previous.data?.goalId === goalId;\n}\n\nfunction titleLine(data: GoalCacheWarmupEntryData): string {\n\tconst wakeSources =\n\t\tdata.activeMonitorCount === 1 ? \"1 wake source on duty\" : `${data.activeMonitorCount} wake sources on duty`;\n\tconst iteration = validIteration(data.iteration);\n\tconst iterationText = iteration === undefined ? \"\" : ` · iteration ${iteration}`;\n\tswitch (data.phase) {\n\t\tcase \"scheduled\":\n\t\t\treturn `⚡ Cache-warm wait${iterationText} · ${wakeSources}`;\n\t\tcase \"resumed\":\n\t\t\treturn `⚡ Cache-warm wake${iterationText} · ${formatExpectedWake(data.dueAtMs, data.waitedMs ?? data.delayMs)} · ${wakeSources}`;\n\t}\n}\n\nfunction validIteration(value: number | undefined): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\nfunction whyLine(data: GoalCacheWarmupEntryData): string {\n\tswitch (data.phase) {\n\t\tcase \"scheduled\": {\n\t\t\t// The wait is not a cache-warm timer: it lets the live wake sources\n\t\t\t// deliver, and the timed wake is only the stall backstop.\n\t\t\tconst backstop = `Stall backstop ${formatExpectedWake(data.dueAtMs, data.delayMs)}`;\n\t\t\tif (data.cache?.ttlSeconds === undefined) {\n\t\t\t\treturn `${backstop} - the goal resumes as soon as a wake source delivers.`;\n\t\t\t}\n\t\t\treturn data.delayMs < data.cache.ttlSeconds * 1000\n\t\t\t\t? `${backstop} - the goal resumes as soon as a wake source delivers, inside the ${formatCacheTtl(data.cache.ttlSeconds)} prompt-cache TTL.`\n\t\t\t\t: `${backstop} - the goal resumes as soon as a wake source delivers; the ${formatCacheTtl(data.cache.ttlSeconds)} prompt-cache TTL may elapse first.`;\n\t\t}\n\t\tcase \"resumed\":\n\t\t\treturn \"Woke on schedule to keep pursuing the goal.\";\n\t}\n}\n\nfunction formatExpectedWake(dueAtMs: number | undefined, elapsedMs: number): string {\n\tif (dueAtMs === undefined || !Number.isFinite(dueAtMs)) return `waited ${formatWakeDuration(elapsedMs)}`;\n\treturn `ready ${formatWakeTimestamp(dueAtMs)} (${formatWakeDuration(elapsedMs)})`;\n}\n\nfunction expandedLine(data: GoalCacheWarmupEntryData): string {\n\tconst planned = `goal ${data.goalId} · planned delay ${formatWakeDuration(data.delayMs)}`;\n\tif (data.phase === \"scheduled\") return `${planned} · ${formatExpectedWake(data.dueAtMs, data.delayMs)}`;\n\treturn `${planned} · ${formatExpectedWake(data.dueAtMs, data.waitedMs ?? data.delayMs)}`;\n}\n\nfunction warmLine(data: GoalCacheWarmupEntryData): string | undefined {\n\tconst cache = data.cache;\n\tif (cache === undefined || cache.cachedTokens <= 0) return undefined;\n\tconst tokens = `~${formatWarmTokenCount(cache.cachedTokens)} tokens`;\n\tconst ttlMayHaveElapsed =\n\t\tcache.ttlSeconds !== undefined && (data.waitedMs ?? data.delayMs) >= cache.ttlSeconds * 1000;\n\tif (ttlMayHaveElapsed) {\n\t\treturn `${tokens} were cached after the prior turn · prompt-cache TTL may have elapsed before this wake`;\n\t}\n\tconst body = data.phase === \"scheduled\" ? `${tokens} kept warm` : `${tokens} stayed warm in the prompt cache`;\n\tconst saved =\n\t\tcache.estimatedSavedUsd !== undefined && cache.estimatedSavedUsd > 0\n\t\t\t? ` · est. ${formatSavedUsd(cache.estimatedSavedUsd)} saved vs a cold re-read`\n\t\t\t: \"\";\n\treturn `${body}${saved}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAgCrE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAgCrE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAwY5D"}
|
|
@@ -2,7 +2,7 @@ import { MANUAL_CONTINUE_CUSTOM_TYPE } from "../../../manual-continue.js";
|
|
|
2
2
|
import { GOAL_CONTINUATION_MESSAGE_TYPE } from "../../../messages.js";
|
|
3
3
|
import { continueGoalAfterAgentEnd } from "./agent-end-continuation.js";
|
|
4
4
|
import { GOAL_CACHE_WARMUP_ENTRY_TYPE } from "./cache-warm.js";
|
|
5
|
-
import { renderGoalCacheWarmupEntry } from "./cache-warm-renderer.js";
|
|
5
|
+
import { isSameGoalCacheWarmCard, renderGoalCacheWarmupEntry } from "./cache-warm-renderer.js";
|
|
6
6
|
import { registerGoalCommand } from "./command-registration.js";
|
|
7
7
|
import { GOAL_CONTINUATION_CAP } from "./continuation.js";
|
|
8
8
|
import { GoalDirectInputLifecycle } from "./direct-input-lifecycle.js";
|
|
@@ -51,7 +51,9 @@ export default function goalExtension(pi) {
|
|
|
51
51
|
const goalTicker = new GoalElapsedTicker({
|
|
52
52
|
render: (renderCtx, renderGoal, live) => updateGoalUi(renderCtx, renderGoal, live),
|
|
53
53
|
});
|
|
54
|
-
pi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry
|
|
54
|
+
pi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry, {
|
|
55
|
+
replaces: isSameGoalCacheWarmCard,
|
|
56
|
+
});
|
|
55
57
|
registerGoalTools(pi, {
|
|
56
58
|
goalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),
|
|
57
59
|
accountCurrentAgentTurn,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,EAA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CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM;QACtE,IAAI,KAAK,EAAE,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,UAAU,KAAK,8BAA8B;YAAE,KAAK,IAAI,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,GAAqB;IAC1C,OAAO,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { MANUAL_CONTINUE_CUSTOM_TYPE } from \"../../../manual-continue.ts\";\nimport { GOAL_CONTINUATION_MESSAGE_TYPE } from \"../../../messages.ts\";\nimport type { SessionEntry } from \"../../../session-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { continueGoalAfterAgentEnd } from \"./agent-end-continuation.ts\";\nimport { GOAL_CACHE_WARMUP_ENTRY_TYPE } from \"./cache-warm.ts\";\nimport { renderGoalCacheWarmupEntry } from \"./cache-warm-renderer.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { GOAL_CONTINUATION_CAP } from \"./continuation.ts\";\nimport { GoalDirectInputLifecycle } from \"./direct-input-lifecycle.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { isResumeOfStoppedGoal, queueGoalContinuation } from \"./lifecycle-helpers.ts\";\nimport { GOAL_CONTINUATION_SCHEDULED_EVENT, MonitorAwareGoalContinuation } from \"./monitor-continuation.ts\";\nimport { migrateLegacyGoalFile } from \"./persistence.ts\";\nimport { reengageGoalAfterReload } from \"./reload-reengagement.ts\";\nimport { isStaleExtensionContextError } from \"./stale-context.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { GOAL_STORE_CHANGED_EVENT, isGoalStoreChangedEvent } from \"./store-changed-event.ts\";\nimport { goalStoreRef as buildGoalStoreRef } from \"./store-ref.ts\";\nimport { staleGoalTodoReminder, todoResultAddsOpenTasks } from \"./todo-gate.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport { TurnUsageTracker } from \"./turn-usage.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\nimport { GOAL_WAIT_STATUS_KEY, GoalWaitTicker } from \"./wait-ticker.ts\";\n\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_STOPPED_CHOICE = \"Leave stopped\";\n\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet staleGoalReminderSentThisTurn = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet blockedThisTurnGoalId: string | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\tlet continuationPending = false;\n\tlet activeContext: ExtensionContext | undefined;\n\tconst turnUsage = new TurnUsageTracker();\n\t// No stale-ctx swallow here: GoalWaitTicker retires itself on a stale render\n\t// (a ticker that keeps ticking against a retired ctx freezes the footer\n\t// countdown forever); non-stale render errors still propagate.\n\tconst goalWaitTicker = new GoalWaitTicker({\n\t\trender: (renderCtx, status) => renderCtx.ui.setStatus(GOAL_WAIT_STATUS_KEY, status),\n\t});\n\tconst monitorContinuation = new MonitorAwareGoalContinuation(\n\t\tpi,\n\t\t() => continuationPending,\n\t\t() => {\n\t\t\tcontinuationPending = true;\n\t\t},\n\t\tgoalWaitTicker,\n\t);\n\tconst directInputLifecycle = new GoalDirectInputLifecycle({\n\t\tmonitor: monitorContinuation,\n\t\tgoalStoreRef,\n\t\tbeginAgentGoalAccounting,\n\t\trefreshGoalUi: refreshGoalUiBestEffort,\n\t\tresumeAfterSuppressedLoad: (resumeCtx, goal) => queueGoalContinuationForCurrentSession(pi, resumeCtx, goal),\n\t});\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => updateGoalUi(renderCtx, renderGoal, live),\n\t});\n\n\tpi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry);\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting: (goal) => {\n\t\t\tmonitorContinuation.noteContinuationStarted();\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t},\n\t\tmarkGoalBlockedThisTurn,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation: (extensionApi, commandCtx, goal) => {\n\t\t\tvoid queueGoalContinuationForCurrentSession(extensionApi, commandCtx, goal);\n\t\t},\n\t\trefreshGoalUi,\n\t});\n\n\tconst unsubscribeGoalStoreChanged =\n\t\tpi.events?.on(GOAL_STORE_CHANGED_EVENT, async (data) => {\n\t\t\tif (!isGoalStoreChangedEvent(data)) return;\n\t\t\tconst ctx = data.ctx ?? activeContext;\n\t\t\tif (\n\t\t\t\tctx === undefined ||\n\t\t\t\tctx.sessionManager.getSessionId() !== data.threadId ||\n\t\t\t\t!ctx.isIdle() ||\n\t\t\t\tctx.hasPendingMessages()\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\t\tif (goal?.status !== \"active\") return;\n\t\t\tmonitorContinuation.syncGoal(goal);\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\t\tpi.events?.emit(GOAL_CONTINUATION_SCHEDULED_EVENT, {\n\t\t\t\tgoalId: goal.id,\n\t\t\t\tdelayMs: 0,\n\t\t\t\tactiveMonitorCount: 0,\n\t\t\t\twakeSources: {},\n\t\t\t\treason: GOAL_STORE_CHANGED_EVENT,\n\t\t\t});\n\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t}) ?? (() => {});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tactiveContext = ctx;\n\t\tmonitorContinuation.start(ctx);\n\t\tdirectInputLifecycle.reset();\n\t\tconst ref = goalStoreRef(ctx);\n\t\tawait migrateLegacyGoalFile(ref);\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumeStoppedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\tif (goal && event.reason === \"reload\") {\n\t\t\t// A reload retires the extension generation and every armed continuation\n\t\t\t// timer with it. Re-engage through the reload path: stopped goals stay\n\t\t\t// stopped, active goals resume the wait the reload tore down.\n\t\t\tawait reengageGoalAfterReload({\n\t\t\t\tctx,\n\t\t\t\tgoal,\n\t\t\t\tmonitor: monitorContinuation,\n\t\t\t\tcountTrailingContinuations: () => countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch()),\n\t\t\t\tqueueContinuation: () => queueGoalContinuationForCurrentSession(pi, ctx, goal),\n\t\t\t});\n\t\t} else if (goal) {\n\t\t\t// Migration-lite admission: a resumed session carrying a trailing flood of\n\t\t\t// historical continuations must not reignite on load. Skip the auto-queue,\n\t\t\t// leave the goal active (no status rewrite), and tell the user how to resume.\n\t\t\tconst trailingContinuations = countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch());\n\t\t\tif (trailingContinuations >= GOAL_CONTINUATION_CAP) {\n\t\t\t\t// The load-time flood suppression parks the goal without rewriting its\n\t\t\t\t// status, so the only resume signal left is the user's next message.\n\t\t\t\t// Arm the one-shot latch the direct-input lifecycle fires when that\n\t\t\t\t// message is accepted; without it the promise in the notice is a lie\n\t\t\t\t// and the resumed session sits idle until the goal is recreated.\n\t\t\t\tdirectInputLifecycle.armSuppressedLoadResume();\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal auto-continuation suppressed for this resumed session (${trailingContinuations} historical continuations). Send a message to resume.`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t\t}\n\t\t}\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onInput(event, ctx);\n\t});\n\n\tpi.on(\"input_disposition\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onDisposition(event, ctx);\n\t});\n\n\tpi.on(\"turn_start\", async () => {\n\t\tstaleGoalReminderSentThisTurn = false;\n\t});\n\n\t// When the model starts tracking new open todo work while the thread has no\n\t// goal (or only a stale, already-complete one), append a system reminder to\n\t// the todo result so the model registers the goal when the work warrants it.\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tif (event.toolName !== \"todo\" || event.isError || staleGoalReminderSentThisTurn) return undefined;\n\t\tif (!todoResultAddsOpenTasks(event.details)) return undefined;\n\t\tconst reminder = staleGoalTodoReminder(await readGoal(goalStoreRef(ctx)));\n\t\tif (reminder === undefined) return undefined;\n\t\tstaleGoalReminderSentThisTurn = true;\n\t\treturn { content: [...event.content, { type: \"text\" as const, text: reminder }] };\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst continuationStarted = continuationPending;\n\t\tcontinuationPending = false;\n\t\tif (continuationStarted) monitorContinuation.noteContinuationStarted();\n\t\tagentTurnInProgress = true;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tturnUsage.reset();\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"message_start\", async (event, ctx) => {\n\t\tif (event.message.role !== \"custom\" || event.message.customType !== MANUAL_CONTINUE_CUSTOM_TYPE) return;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tconst goal = await readGoal(ref);\n\t\tif (goal?.status !== \"blocked\") return;\n\t\tsyncContinuationGoal(ctx, await updateGoal(ref, { status: \"active\" }, \"user\"));\n\t});\n\n\tpi.on(\"message_end\", async (event) => {\n\t\tturnUsage.noteMessageEnd(event.message);\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode =\n\t\t\tblockedThisTurnGoalId !== null\n\t\t\t\t? \"activeOrBlocked\"\n\t\t\t\t: completedThisTurnGoalId === null\n\t\t\t\t\t? \"active\"\n\t\t\t\t\t: \"activeOrComplete\";\n\t\tlet goal = await accountCurrentAgentTurn(ctx, mode, event.messages);\n\t\tagentTurnInProgress = false;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (event.aborted === true && event.abortSource === \"user\" && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t}\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tconst continuationGoal = await continueGoalAfterAgentEnd(monitorContinuation, { ctx, event, goal });\n\t\tif (continuationGoal !== goal) {\n\t\t\tgoal = continuationGoal;\n\t\t\tsyncContinuationGoal(ctx, goal);\n\t\t}\n\t});\n\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tconst goal = await monitorContinuation.afterAgentSettled();\n\t\tif (goal !== undefined) syncContinuationGoal(ctx, goal);\n\t});\n\n\tpi.on(\"session_abort\", async (_event, ctx) => {\n\t\tcontinuationPending = false;\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status !== \"active\") return;\n\t\tconst accounted = await accountCurrentAgentTurn(ctx, \"active\");\n\t\tif (accounted?.status === \"active\") {\n\t\t\tconst blocked = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, blocked);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tactiveContext = undefined;\n\t\tunsubscribeGoalStoreChanged();\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t\tmonitorContinuation.dispose();\n\t});\n\n\tasync function maybePromptResumeStoppedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfStoppedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\t\t// RPC switch_session cannot service a nested interactive UI request until the\n\t\t// switch response completes. Keep the goal stopped and let the user resume it\n\t\t// explicitly after the new session finishes binding.\n\t\tif (ctx.mode === \"rpc\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal remains ${goal.status} after session resume. Resume it explicitly after the session finishes loading.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume ${goal.status} goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_STOPPED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" }, \"user\");\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tasync function queueGoalContinuationForCurrentSession(\n\t\textensionApi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tgoal: Goal,\n\t): Promise<void> {\n\t\tconst continuedGoal = await queueGoalContinuation(extensionApi, ctx, goal, {\n\t\t\tcontinuationPending,\n\t\t\tmarkContinuationPending: () => {\n\t\t\t\tcontinuationPending = true;\n\t\t\t},\n\t\t});\n\t\tif (continuedGoal === null) {\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, null);\n\t\t\treturn;\n\t\t}\n\t\tif (continuedGoal.status === goal.status) return;\n\t\tif (continuedGoal.status === \"active\") beginAgentGoalAccounting(continuedGoal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, continuedGoal);\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tturnUsage.discardPending();\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalBlockedThisTurn(goal: Goal): void {\n\t\tif (agentTurnInProgress) blockedThisTurnGoalId = goal.id;\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (blockedThisTurnGoalId === goalId) {\n\t\t\tblockedThisTurnGoalId = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction syncContinuationGoal(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tif (goal?.status === \"active\") beginAgentGoalAccounting(goal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tmonitorContinuation.syncGoal(goal);\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (isStaleExtensionContextError(error)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tmode: GoalAccountingMode,\n\t\tagentRunMessages?: unknown[],\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst usage =\n\t\t\tagentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\n/**\n * Counts goal-continuation entries queued since the most recent real user message\n * in the current branch (mirrors the todo-gate / todo-bridge backward branch read).\n * A real user message is the only reset: the assistant turns in between are exactly\n * the unattended loop this admission guard exists to stop.\n */\nfunction countTrailingGoalContinuationEntries(entries: readonly SessionEntry[]): number {\n\tlet count = 0;\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type === \"message\" && entry.message.role === \"user\") break;\n\t\tif (entry?.type === \"custom_message\" && entry.customType === GOAL_CONTINUATION_MESSAGE_TYPE) count += 1;\n\t}\n\treturn count;\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\treturn buildGoalStoreRef(ctx.sessionManager, ctx.cwd);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,EAAE,yBAAyB,EAAE,MAA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AM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM;QACtE,IAAI,KAAK,EAAE,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,UAAU,KAAK,8BAA8B;YAAE,KAAK,IAAI,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,GAAqB;IAC1C,OAAO,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { MANUAL_CONTINUE_CUSTOM_TYPE } from \"../../../manual-continue.ts\";\nimport { GOAL_CONTINUATION_MESSAGE_TYPE } from \"../../../messages.ts\";\nimport type { SessionEntry } from \"../../../session-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { continueGoalAfterAgentEnd } from \"./agent-end-continuation.ts\";\nimport { GOAL_CACHE_WARMUP_ENTRY_TYPE } from \"./cache-warm.ts\";\nimport { isSameGoalCacheWarmCard, renderGoalCacheWarmupEntry } from \"./cache-warm-renderer.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { GOAL_CONTINUATION_CAP } from \"./continuation.ts\";\nimport { GoalDirectInputLifecycle } from \"./direct-input-lifecycle.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { isResumeOfStoppedGoal, queueGoalContinuation } from \"./lifecycle-helpers.ts\";\nimport { GOAL_CONTINUATION_SCHEDULED_EVENT, MonitorAwareGoalContinuation } from \"./monitor-continuation.ts\";\nimport { migrateLegacyGoalFile } from \"./persistence.ts\";\nimport { reengageGoalAfterReload } from \"./reload-reengagement.ts\";\nimport { isStaleExtensionContextError } from \"./stale-context.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { GOAL_STORE_CHANGED_EVENT, isGoalStoreChangedEvent } from \"./store-changed-event.ts\";\nimport { goalStoreRef as buildGoalStoreRef } from \"./store-ref.ts\";\nimport { staleGoalTodoReminder, todoResultAddsOpenTasks } from \"./todo-gate.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport { TurnUsageTracker } from \"./turn-usage.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\nimport { GOAL_WAIT_STATUS_KEY, GoalWaitTicker } from \"./wait-ticker.ts\";\n\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_STOPPED_CHOICE = \"Leave stopped\";\n\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet staleGoalReminderSentThisTurn = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet blockedThisTurnGoalId: string | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\tlet continuationPending = false;\n\tlet activeContext: ExtensionContext | undefined;\n\tconst turnUsage = new TurnUsageTracker();\n\t// No stale-ctx swallow here: GoalWaitTicker retires itself on a stale render\n\t// (a ticker that keeps ticking against a retired ctx freezes the footer\n\t// countdown forever); non-stale render errors still propagate.\n\tconst goalWaitTicker = new GoalWaitTicker({\n\t\trender: (renderCtx, status) => renderCtx.ui.setStatus(GOAL_WAIT_STATUS_KEY, status),\n\t});\n\tconst monitorContinuation = new MonitorAwareGoalContinuation(\n\t\tpi,\n\t\t() => continuationPending,\n\t\t() => {\n\t\t\tcontinuationPending = true;\n\t\t},\n\t\tgoalWaitTicker,\n\t);\n\tconst directInputLifecycle = new GoalDirectInputLifecycle({\n\t\tmonitor: monitorContinuation,\n\t\tgoalStoreRef,\n\t\tbeginAgentGoalAccounting,\n\t\trefreshGoalUi: refreshGoalUiBestEffort,\n\t\tresumeAfterSuppressedLoad: (resumeCtx, goal) => queueGoalContinuationForCurrentSession(pi, resumeCtx, goal),\n\t});\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => updateGoalUi(renderCtx, renderGoal, live),\n\t});\n\n\tpi.registerEntryRenderer(GOAL_CACHE_WARMUP_ENTRY_TYPE, renderGoalCacheWarmupEntry, {\n\t\treplaces: isSameGoalCacheWarmCard,\n\t});\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting: (goal) => {\n\t\t\tmonitorContinuation.noteContinuationStarted();\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t},\n\t\tmarkGoalBlockedThisTurn,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef: (ctx) => buildGoalStoreRef(ctx.sessionManager, ctx.cwd),\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation: (extensionApi, commandCtx, goal) => {\n\t\t\tvoid queueGoalContinuationForCurrentSession(extensionApi, commandCtx, goal);\n\t\t},\n\t\trefreshGoalUi,\n\t});\n\n\tconst unsubscribeGoalStoreChanged =\n\t\tpi.events?.on(GOAL_STORE_CHANGED_EVENT, async (data) => {\n\t\t\tif (!isGoalStoreChangedEvent(data)) return;\n\t\t\tconst ctx = data.ctx ?? activeContext;\n\t\t\tif (\n\t\t\t\tctx === undefined ||\n\t\t\t\tctx.sessionManager.getSessionId() !== data.threadId ||\n\t\t\t\t!ctx.isIdle() ||\n\t\t\t\tctx.hasPendingMessages()\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\t\tif (goal?.status !== \"active\") return;\n\t\t\tmonitorContinuation.syncGoal(goal);\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\t\tpi.events?.emit(GOAL_CONTINUATION_SCHEDULED_EVENT, {\n\t\t\t\tgoalId: goal.id,\n\t\t\t\tdelayMs: 0,\n\t\t\t\tactiveMonitorCount: 0,\n\t\t\t\twakeSources: {},\n\t\t\t\treason: GOAL_STORE_CHANGED_EVENT,\n\t\t\t});\n\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t}) ?? (() => {});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tactiveContext = ctx;\n\t\tmonitorContinuation.start(ctx);\n\t\tdirectInputLifecycle.reset();\n\t\tconst ref = goalStoreRef(ctx);\n\t\tawait migrateLegacyGoalFile(ref);\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumeStoppedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\tif (goal && event.reason === \"reload\") {\n\t\t\t// A reload retires the extension generation and every armed continuation\n\t\t\t// timer with it. Re-engage through the reload path: stopped goals stay\n\t\t\t// stopped, active goals resume the wait the reload tore down.\n\t\t\tawait reengageGoalAfterReload({\n\t\t\t\tctx,\n\t\t\t\tgoal,\n\t\t\t\tmonitor: monitorContinuation,\n\t\t\t\tcountTrailingContinuations: () => countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch()),\n\t\t\t\tqueueContinuation: () => queueGoalContinuationForCurrentSession(pi, ctx, goal),\n\t\t\t});\n\t\t} else if (goal) {\n\t\t\t// Migration-lite admission: a resumed session carrying a trailing flood of\n\t\t\t// historical continuations must not reignite on load. Skip the auto-queue,\n\t\t\t// leave the goal active (no status rewrite), and tell the user how to resume.\n\t\t\tconst trailingContinuations = countTrailingGoalContinuationEntries(ctx.sessionManager.getBranch());\n\t\t\tif (trailingContinuations >= GOAL_CONTINUATION_CAP) {\n\t\t\t\t// The load-time flood suppression parks the goal without rewriting its\n\t\t\t\t// status, so the only resume signal left is the user's next message.\n\t\t\t\t// Arm the one-shot latch the direct-input lifecycle fires when that\n\t\t\t\t// message is accepted; without it the promise in the notice is a lie\n\t\t\t\t// and the resumed session sits idle until the goal is recreated.\n\t\t\t\tdirectInputLifecycle.armSuppressedLoadResume();\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Goal auto-continuation suppressed for this resumed session (${trailingContinuations} historical continuations). Send a message to resume.`,\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, goal);\n\t\t\t}\n\t\t}\n\t});\n\n\tpi.on(\"input\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onInput(event, ctx);\n\t});\n\n\tpi.on(\"input_disposition\", async (event, ctx) => {\n\t\tawait directInputLifecycle.onDisposition(event, ctx);\n\t});\n\n\tpi.on(\"turn_start\", async () => {\n\t\tstaleGoalReminderSentThisTurn = false;\n\t});\n\n\t// When the model starts tracking new open todo work while the thread has no\n\t// goal (or only a stale, already-complete one), append a system reminder to\n\t// the todo result so the model registers the goal when the work warrants it.\n\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\tif (event.toolName !== \"todo\" || event.isError || staleGoalReminderSentThisTurn) return undefined;\n\t\tif (!todoResultAddsOpenTasks(event.details)) return undefined;\n\t\tconst reminder = staleGoalTodoReminder(await readGoal(goalStoreRef(ctx)));\n\t\tif (reminder === undefined) return undefined;\n\t\tstaleGoalReminderSentThisTurn = true;\n\t\treturn { content: [...event.content, { type: \"text\" as const, text: reminder }] };\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tconst continuationStarted = continuationPending;\n\t\tcontinuationPending = false;\n\t\tif (continuationStarted) monitorContinuation.noteContinuationStarted();\n\t\tagentTurnInProgress = true;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tturnUsage.reset();\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"message_start\", async (event, ctx) => {\n\t\tif (event.message.role !== \"custom\" || event.message.customType !== MANUAL_CONTINUE_CUSTOM_TYPE) return;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tconst goal = await readGoal(ref);\n\t\tif (goal?.status !== \"blocked\") return;\n\t\tsyncContinuationGoal(ctx, await updateGoal(ref, { status: \"active\" }, \"user\"));\n\t});\n\n\tpi.on(\"message_end\", async (event) => {\n\t\tturnUsage.noteMessageEnd(event.message);\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode =\n\t\t\tblockedThisTurnGoalId !== null\n\t\t\t\t? \"activeOrBlocked\"\n\t\t\t\t: completedThisTurnGoalId === null\n\t\t\t\t\t? \"active\"\n\t\t\t\t\t: \"activeOrComplete\";\n\t\tlet goal = await accountCurrentAgentTurn(ctx, mode, event.messages);\n\t\tagentTurnInProgress = false;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (event.aborted === true && event.abortSource === \"user\" && goal?.status === \"active\") {\n\t\t\tgoal = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t}\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tconst continuationGoal = await continueGoalAfterAgentEnd(monitorContinuation, { ctx, event, goal });\n\t\tif (continuationGoal !== goal) {\n\t\t\tgoal = continuationGoal;\n\t\t\tsyncContinuationGoal(ctx, goal);\n\t\t}\n\t});\n\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tconst goal = await monitorContinuation.afterAgentSettled();\n\t\tif (goal !== undefined) syncContinuationGoal(ctx, goal);\n\t});\n\n\tpi.on(\"session_abort\", async (_event, ctx) => {\n\t\tcontinuationPending = false;\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status !== \"active\") return;\n\t\tconst accounted = await accountCurrentAgentTurn(ctx, \"active\");\n\t\tif (accounted?.status === \"active\") {\n\t\t\tconst blocked = await updateGoal(\n\t\t\t\tgoalStoreRef(ctx),\n\t\t\t\t{ status: \"blocked\", reason: \"user interrupted the turn\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, blocked);\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tactiveContext = undefined;\n\t\tunsubscribeGoalStoreChanged();\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t\tmonitorContinuation.dispose();\n\t});\n\n\tasync function maybePromptResumeStoppedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfStoppedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\t\t// RPC switch_session cannot service a nested interactive UI request until the\n\t\t// switch response completes. Keep the goal stopped and let the user resume it\n\t\t// explicitly after the new session finishes binding.\n\t\tif (ctx.mode === \"rpc\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t`Goal remains ${goal.status} after session resume. Resume it explicitly after the session finishes loading.`,\n\t\t\t\t\"info\",\n\t\t\t);\n\t\t\treturn true;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume ${goal.status} goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_STOPPED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" }, \"user\");\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tawait queueGoalContinuationForCurrentSession(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tasync function queueGoalContinuationForCurrentSession(\n\t\textensionApi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tgoal: Goal,\n\t): Promise<void> {\n\t\tconst continuedGoal = await queueGoalContinuation(extensionApi, ctx, goal, {\n\t\t\tcontinuationPending,\n\t\t\tmarkContinuationPending: () => {\n\t\t\t\tcontinuationPending = true;\n\t\t\t},\n\t\t});\n\t\tif (continuedGoal === null) {\n\t\t\tclearAgentGoalAccounting();\n\t\t\trefreshGoalUiBestEffort(ctx, null);\n\t\t\treturn;\n\t\t}\n\t\tif (continuedGoal.status === goal.status) return;\n\t\tif (continuedGoal.status === \"active\") beginAgentGoalAccounting(continuedGoal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, continuedGoal);\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tturnUsage.discardPending();\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalBlockedThisTurn(goal: Goal): void {\n\t\tif (agentTurnInProgress) blockedThisTurnGoalId = goal.id;\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (blockedThisTurnGoalId === goalId) {\n\t\t\tblockedThisTurnGoalId = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tblockedThisTurnGoalId = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction syncContinuationGoal(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tif (goal?.status === \"active\") beginAgentGoalAccounting(goal);\n\t\telse clearAgentGoalAccounting();\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tmonitorContinuation.syncGoal(goal);\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (isStaleExtensionContextError(error)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tmode: GoalAccountingMode,\n\t\tagentRunMessages?: unknown[],\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst usage =\n\t\t\tagentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\n/**\n * Counts goal-continuation entries queued since the most recent real user message\n * in the current branch (mirrors the todo-gate / todo-bridge backward branch read).\n * A real user message is the only reset: the assistant turns in between are exactly\n * the unattended loop this admission guard exists to stop.\n */\nfunction countTrailingGoalContinuationEntries(entries: readonly SessionEntry[]): number {\n\tlet count = 0;\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry?.type === \"message\" && entry.message.role === \"user\") break;\n\t\tif (entry?.type === \"custom_message\" && entry.customType === GOAL_CONTINUATION_MESSAGE_TYPE) count += 1;\n\t}\n\treturn count;\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\treturn buildGoalStoreRef(ctx.sessionManager, ctx.cwd);\n}\n"]}
|
|
@@ -22,7 +22,9 @@ export declare class MonitorAwareGoalContinuation {
|
|
|
22
22
|
* Re-arms the monitor-delayed backstop a reload tore down with the retired
|
|
23
23
|
* generation, so a later wake-source drain can still deliver the goal
|
|
24
24
|
* continuation. No-op unless the goal is active, a wake source is live, and
|
|
25
|
-
* no continuation is already scheduled.
|
|
25
|
+
* no continuation is already scheduled. A wait the branch still records as
|
|
26
|
+
* parked is restored as-is (iteration, cache snapshot, original due time) so
|
|
27
|
+
* a reload never appends a second card or pushes the wake past the cache TTL.
|
|
26
28
|
*/
|
|
27
29
|
rearmMonitorBackstop(goal: Goal): void;
|
|
28
30
|
/** Temporarily prevents a scheduled continuation from racing unresolved direct-input admission. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-continuation.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/monitor-continuation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAcrE,OAAO,EACN,sCAAsC,EACtC,2CAA2C,GAC3C,MAAM,iBAAiB,CAAC;AAoBzB,OAAO,KAAK,EACX,eAAe,EAIf,uBAAuB,EAEvB,kBAAkB,EAClB,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"monitor-continuation.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/monitor-continuation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAcrE,OAAO,EACN,sCAAsC,EACtC,2CAA2C,GAC3C,MAAM,iBAAiB,CAAC;AAoBzB,OAAO,KAAK,EACX,eAAe,EAIf,uBAAuB,EAEvB,kBAAkB,EAClB,MAAM,iCAAiC,CAAC;AAOzC,OAAO,KAAK,EAAE,IAAI,EAAsB,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOvD,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAC/E,eAAO,MAAM,+BAA+B,8BAA8B,CAAC;AAC3E,eAAO,MAAM,mCAAmC,kCAAkC,CAAC;AACnF,eA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