@code-yeongyu/senpi 2026.8.13 → 2026.8.14
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 +65 -0
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +20 -5
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +3 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +178 -70
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts +2 -3
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.js +2 -3
- package/dist/core/extensions/builtin/compaction/lane-policy.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/retry-fallback/settings.d.ts.map +1 -1
- package/dist/core/retry-fallback/settings.js +4 -1
- package/dist/core/retry-fallback/settings.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +17 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/docs/extensions.md +9 -1
- package/docs/json.md +3 -1
- package/docs/providers.md +2 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +24 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +5 -4
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +15 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +15 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.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/package.json +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAkC,MAAM,uBAAuB,CAAC;AAUtH,OAAO,KAAK,EAAe,OAAO,EAAiC,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EACN,KAAK,8BAA8B,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AC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,8BAA8B,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAsLD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,+BAA+B,GAAG,OAAO,CAqD/F"}
|
|
@@ -214,6 +214,7 @@ export function buildClaudeSdkOauthQueryOptions(input) {
|
|
|
214
214
|
canUseTool,
|
|
215
215
|
hooks: HOST_TOOL_DENIAL_HOOKS,
|
|
216
216
|
systemPrompt,
|
|
217
|
+
settings: { autoCompactEnabled: true },
|
|
217
218
|
settingSources: resolveSettingSources(providerSettings, mode, authLane),
|
|
218
219
|
};
|
|
219
220
|
if (input.pathToClaudeCodeExecutable)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,+BAA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,IAAI,EAAE,QAAQ,CAAC;KACvE,CAAC;IACF,IAAI,KAAK,CAAC,0BAA0B;QAAE,YAAY,CAAC,0BAA0B,GAAG,KAAK,CAAC,0BAA0B,CAAC;IACjH,IAAI,eAAe;QAAE,YAAY,CAAC,SAAS,GAAG,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC;IAE5E,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC;IACjD,IAAI,SAAS,IAAI,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxD,YAAY,CAAC,QAAQ,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAA2B,CAAC;QAC7F,YAAY,CAAC,MAAM,GAAG,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACtB,YAAY,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport type { Api, Context, Model, SimpleStreamOptions, ThinkingBudgets, ThinkingLevel } from \"@earendil-works/pi-ai\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../../../config.ts\";\nimport {\n\tPROJECT_RULES_END_MARKER,\n\tPROJECT_RULES_HEADING,\n\tPROJECT_RULES_REGION_END_MARKER,\n\tPROJECT_RULES_REGION_START_MARKER,\n\tPROJECT_RULES_START_MARKER,\n} from \"../rules/rules/constants.ts\";\nimport { presetAppendDeprecationGuidance } from \"./guidance.ts\";\nimport type { EffortLevel, Options, SettingSource, ThinkingConfig } from \"./sdk-boundary.ts\";\nimport {\n\ttype ClaudeSdkOauthProviderSettings,\n\ttype ClaudeSdkOauthSystemPromptMode,\n\ttype ClaudeSdkOauthTokenInjection,\n\tloadClaudeSdkOauthProviderSettingsFromDisk,\n\tresolveSystemPromptMode,\n} from \"./settings.ts\";\nimport { loadOverrideSystemPrompt, resolveCustomSystemPrompt } from \"./system-prompt.ts\";\nimport { BUILTIN_SDK_TOOLS, canUseTool, HOST_TOOL_DENIAL_HOOKS } from \"./tools.ts\";\n\nexport type ClaudeSdkOauthAuthLane = ClaudeSdkOauthTokenInjection;\n\nexport interface ClaudeSdkOauthQueryOptionsInput {\n\treadonly model: Model<Api>;\n\treadonly context: Context;\n\treadonly streamOptions?: SimpleStreamOptions;\n\treadonly cwd?: string;\n\treadonly providerSettings?: ClaudeSdkOauthProviderSettings;\n\treadonly authLane?: ClaudeSdkOauthAuthLane;\n\treadonly tools?: readonly string[];\n\treadonly pathToClaudeCodeExecutable?: string;\n\treadonly sessionId?: string;\n\treadonly onGuidance?: (text: string) => void;\n}\n\nconst ADAPTIVE_THINKING_MODEL_MARKERS = [\n\t\"opus-4-6\",\n\t\"opus-4.6\",\n\t\"opus-4-7\",\n\t\"opus-4.7\",\n\t\"opus-4-8\",\n\t\"opus-4.8\",\n\t\"opus-5\",\n\t\"sonnet-4-6\",\n\t\"sonnet-4.6\",\n\t\"sonnet-5\",\n\t\"fable-5\",\n\t\"mythos-5\",\n] as const;\n\nconst NATIVE_XHIGH_EFFORT_MODEL_MARKERS = [\n\t\"opus-4-7\",\n\t\"opus-4-8\",\n\t\"opus-5\",\n\t\"sonnet-5\",\n\t\"fable-5\",\n\t\"mythos-5\",\n] as const;\n\nconst DEFAULT_THINKING_BUDGETS: Required<ThinkingBudgets> = {\n\tminimal: 2048,\n\tlow: 8192,\n\tmedium: 16384,\n\thigh: 31999,\n\tmax: 63999,\n};\n\nfunction includesModelMarker(model: Model<Api>, markers: readonly string[]): boolean {\n\tconst id = model.id.toLowerCase();\n\treturn markers.some((marker) => id.includes(marker));\n}\n\nfunction forcedAdaptiveThinking(model: Model<Api>): boolean | undefined {\n\tconst compat = model.compat;\n\tif (!compat || !(\"forceAdaptiveThinking\" in compat)) return undefined;\n\treturn typeof compat.forceAdaptiveThinking === \"boolean\" ? compat.forceAdaptiveThinking : undefined;\n}\n\nfunction supportsAdaptiveThinking(model: Model<Api>): boolean {\n\treturn forcedAdaptiveThinking(model) ?? includesModelMarker(model, ADAPTIVE_THINKING_MODEL_MARKERS);\n}\n\nfunction supportsNativeXhighEffort(model: Model<Api>): boolean {\n\treturn includesModelMarker(model, NATIVE_XHIGH_EFFORT_MODEL_MARKERS);\n}\n\nfunction isEffortLevel(value: string): value is EffortLevel {\n\treturn value === \"low\" || value === \"medium\" || value === \"high\" || value === \"xhigh\" || value === \"max\";\n}\n\nfunction mapThinkingLevelToEffort(model: Model<Api>, level: ThinkingLevel): EffortLevel {\n\tconst mapped = model.thinkingLevelMap?.[level];\n\tif (typeof mapped === \"string\" && isEffortLevel(mapped)) return mapped;\n\tswitch (level) {\n\t\tcase \"minimal\":\n\t\tcase \"low\":\n\t\t\treturn \"low\";\n\t\tcase \"medium\":\n\t\t\treturn \"medium\";\n\t\tcase \"high\":\n\t\t\treturn \"high\";\n\t\tcase \"xhigh\":\n\t\t\treturn supportsNativeXhighEffort(model) ? \"xhigh\" : \"max\";\n\t\tcase \"max\":\n\t\t\treturn \"max\";\n\t}\n}\n\nfunction mapThinkingTokens(reasoning: ThinkingLevel, thinkingBudgets: ThinkingBudgets | undefined): number {\n\tconst budgetLevel = reasoning === \"xhigh\" ? \"high\" : reasoning;\n\tconst customBudget = thinkingBudgets?.[budgetLevel];\n\treturn typeof customBudget === \"number\" && Number.isFinite(customBudget) && customBudget > 0\n\t\t? customBudget\n\t\t: DEFAULT_THINKING_BUDGETS[budgetLevel];\n}\n\nfunction findAgentsMdInParents(cwd: string): string | undefined {\n\tlet current = resolve(cwd);\n\twhile (true) {\n\t\tconst candidate = join(current, \"AGENTS.md\");\n\t\tif (existsSync(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction sanitizeAgentsContent(content: string): string {\n\tconst configDirectory = CONFIG_DIR_NAME.replace(/^\\./, \"\");\n\tconst escapedConfigDirectory = configDirectory.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\treturn content\n\t\t.replace(new RegExp(`~/${escapedConfigDirectory}\\\\b`, \"gi\"), \"~/.claude\")\n\t\t.replace(new RegExp(`(^|[\\\\s'\"\\`])\\\\.${escapedConfigDirectory}/`, \"g\"), \"$1.claude/\")\n\t\t.replace(new RegExp(`\\\\b${escapedConfigDirectory}\\\\b`, \"gi\"), \"environment\");\n}\n\nfunction extractAgentsAppend(cwd: string): string | undefined {\n\tconst agentsPath = findAgentsMdInParents(cwd) ?? join(getAgentDir(), \"AGENTS.md\");\n\tif (!existsSync(agentsPath)) return undefined;\n\ttry {\n\t\tconst content = sanitizeAgentsContent(readFileSync(agentsPath, \"utf-8\").trim());\n\t\treturn content.length > 0 ? `# CLAUDE.md\\n\\n${content}` : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rewriteSkillsLocations(skillsBlock: string, cwd: string): string {\n\tconst globalSkillsRoot = join(getAgentDir(), \"skills\");\n\tconst projectSkillsRoot = join(cwd, CONFIG_DIR_NAME, \"skills\");\n\treturn skillsBlock.replace(/<location>([^<]+)<\\/location>/g, (_match, location: string) => {\n\t\tif (location.startsWith(globalSkillsRoot)) {\n\t\t\treturn `<location>~/.claude/skills/${relative(globalSkillsRoot, location).replace(/^\\.+/, \"\")}</location>`;\n\t\t}\n\t\tif (location.startsWith(projectSkillsRoot)) {\n\t\t\treturn `<location>.claude/skills/${relative(projectSkillsRoot, location).replace(/^\\.+/, \"\")}</location>`;\n\t\t}\n\t\treturn `<location>${location}</location>`;\n\t});\n}\n\nfunction extractSkillsAppend(systemPrompt: string | undefined, cwd: string): string | undefined {\n\tif (!systemPrompt) return undefined;\n\tconst marker = \"The following skills provide specialized instructions for specific tasks.\";\n\tconst start = systemPrompt.indexOf(marker);\n\tconst end = start === -1 ? -1 : systemPrompt.indexOf(\"</available_skills>\", start);\n\tif (end === -1) return undefined;\n\treturn rewriteSkillsLocations(systemPrompt.slice(start, end + \"</available_skills>\".length).trim(), cwd);\n}\n\n/**\n * This lane rebuilds the prompt from the `claude_code` preset plus `append`, so any\n * region of senpi's composed prompt without an extractor here never reaches the model.\n *\n * Located by the rules builtin's opaque region sentinels rather than the model-facing\n * `<project_rules>` tags, which surrounding prompt content may legitimately contain.\n * The sentinels are a reserved wire literal but nothing neutralizes them outside the block, so\n * each candidate is structurally validated and rejected candidates are skipped - otherwise a\n * context file carrying one would shadow the real block or cross-match its end sentinel.\n * Fail-closed on a missing end sentinel: never read to end-of-string, or the sections\n * extensions append after this one get relabelled as project rules.\n */\nfunction extractProjectRulesAppend(systemPrompt: string | undefined): string | undefined {\n\tif (!systemPrompt) return undefined;\n\tlet searchFrom = 0;\n\twhile (searchFrom <= systemPrompt.length) {\n\t\tconst sentinelStart = systemPrompt.indexOf(PROJECT_RULES_REGION_START_MARKER, searchFrom);\n\t\tif (sentinelStart === -1) return undefined;\n\t\tconst regionStart = sentinelStart + PROJECT_RULES_REGION_START_MARKER.length;\n\t\tconst regionEnd = systemPrompt.indexOf(PROJECT_RULES_REGION_END_MARKER, regionStart);\n\t\tif (regionEnd === -1) return undefined;\n\t\tconst region = systemPrompt.slice(regionStart, regionEnd).trim();\n\t\tif (isProjectRulesEnvelope(region)) return region;\n\t\tsearchFrom = regionStart;\n\t}\n\treturn undefined;\n}\n\nfunction isProjectRulesEnvelope(region: string): boolean {\n\treturn (\n\t\tregion.startsWith(`${PROJECT_RULES_START_MARKER}\\n${PROJECT_RULES_HEADING}\\n`) &&\n\t\tregion.endsWith(`\\n${PROJECT_RULES_END_MARKER}`)\n\t);\n}\n\nfunction resolveSettingSources(\n\tproviderSettings: ClaudeSdkOauthProviderSettings,\n\tmode: ClaudeSdkOauthSystemPromptMode,\n\tauthLane: ClaudeSdkOauthAuthLane,\n): SettingSource[] {\n\tif (providerSettings.settingSources !== undefined) return [...providerSettings.settingSources];\n\tif (mode !== \"preset-append\" || authLane !== \"ambient\") return [];\n\treturn [\"user\", \"project\"];\n}\n\nexport function buildClaudeSdkOauthQueryOptions(input: ClaudeSdkOauthQueryOptionsInput): Options {\n\tconst cwd = input.cwd ?? process.cwd();\n\tconst providerSettings = input.providerSettings ?? loadClaudeSdkOauthProviderSettingsFromDisk(cwd);\n\tconst appendSystemPrompt = providerSettings.appendSystemPrompt !== false;\n\tconst resolvedMode = resolveSystemPromptMode(providerSettings);\n\tconst mode = resolvedMode.mode;\n\tif (input.sessionId !== undefined && input.onGuidance !== undefined) {\n\t\tconst deprecation = presetAppendDeprecationGuidance({\n\t\t\tmode,\n\t\t\tconflict: resolvedMode.conflict,\n\t\t\tsessionId: input.sessionId,\n\t\t});\n\t\tif (deprecation !== undefined) input.onGuidance(deprecation);\n\t}\n\tconst authLane = input.authLane ?? providerSettings.tokenInjection ?? \"ambient\";\n\tconst append =\n\t\tmode === \"preset-append\"\n\t\t\t? [\n\t\t\t\t\textractAgentsAppend(cwd),\n\t\t\t\t\textractSkillsAppend(input.context.systemPrompt, cwd),\n\t\t\t\t\textractProjectRulesAppend(input.context.systemPrompt),\n\t\t\t\t].filter((part): part is string => part !== undefined)\n\t\t\t: [];\n\tconst systemPrompt =\n\t\tmode === \"preset-append\"\n\t\t\t? { type: \"preset\" as const, preset: \"claude_code\" as const, append: append.join(\"\\n\\n\") || undefined }\n\t\t\t: mode === \"override\"\n\t\t\t\t? loadOverrideSystemPrompt(providerSettings.systemPromptFile)\n\t\t\t\t: resolveCustomSystemPrompt(input.context.systemPrompt);\n\tconst strictMcpConfig = providerSettings.strictMcpConfig ?? !appendSystemPrompt;\n\tconst queryOptions: Options = {\n\t\tcwd,\n\t\tmodel: input.model.id,\n\t\ttools: input.tools ? [...input.tools] : [...BUILTIN_SDK_TOOLS],\n\t\tpermissionMode: \"dontAsk\",\n\t\tincludePartialMessages: true,\n\t\tcanUseTool,\n\t\thooks: HOST_TOOL_DENIAL_HOOKS,\n\t\tsystemPrompt,\n\t\tsettingSources: resolveSettingSources(providerSettings, mode, authLane),\n\t};\n\tif (input.pathToClaudeCodeExecutable) queryOptions.pathToClaudeCodeExecutable = input.pathToClaudeCodeExecutable;\n\tif (strictMcpConfig) queryOptions.extraArgs = { \"strict-mcp-config\": null };\n\n\tconst reasoning = input.streamOptions?.reasoning;\n\tif (reasoning && supportsAdaptiveThinking(input.model)) {\n\t\tqueryOptions.thinking = { type: \"adaptive\", display: \"summarized\" } satisfies ThinkingConfig;\n\t\tqueryOptions.effort = mapThinkingLevelToEffort(input.model, reasoning);\n\t} else if (reasoning) {\n\t\tqueryOptions.maxThinkingTokens = mapThinkingTokens(reasoning, input.streamOptions?.thinkingBudgets);\n\t}\n\treturn queryOptions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,+BAA+B,EAC/B,iCAAiC,EACjC,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAIN,0CAA0C,EAC1C,uBAAuB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAiBnF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jD,IAAI,SAAS,IAAI,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxD,YAAY,CAAC,QAAQ,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAA2B,CAAC;QAC7F,YAAY,CAAC,MAAM,GAAG,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACxE,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACtB,YAAY,CAAC,iBAAiB,GAAG,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport type { Api, Context, Model, SimpleStreamOptions, ThinkingBudgets, ThinkingLevel } from \"@earendil-works/pi-ai\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../../../config.ts\";\nimport {\n\tPROJECT_RULES_END_MARKER,\n\tPROJECT_RULES_HEADING,\n\tPROJECT_RULES_REGION_END_MARKER,\n\tPROJECT_RULES_REGION_START_MARKER,\n\tPROJECT_RULES_START_MARKER,\n} from \"../rules/rules/constants.ts\";\nimport { presetAppendDeprecationGuidance } from \"./guidance.ts\";\nimport type { EffortLevel, Options, SettingSource, ThinkingConfig } from \"./sdk-boundary.ts\";\nimport {\n\ttype ClaudeSdkOauthProviderSettings,\n\ttype ClaudeSdkOauthSystemPromptMode,\n\ttype ClaudeSdkOauthTokenInjection,\n\tloadClaudeSdkOauthProviderSettingsFromDisk,\n\tresolveSystemPromptMode,\n} from \"./settings.ts\";\nimport { loadOverrideSystemPrompt, resolveCustomSystemPrompt } from \"./system-prompt.ts\";\nimport { BUILTIN_SDK_TOOLS, canUseTool, HOST_TOOL_DENIAL_HOOKS } from \"./tools.ts\";\n\nexport type ClaudeSdkOauthAuthLane = ClaudeSdkOauthTokenInjection;\n\nexport interface ClaudeSdkOauthQueryOptionsInput {\n\treadonly model: Model<Api>;\n\treadonly context: Context;\n\treadonly streamOptions?: SimpleStreamOptions;\n\treadonly cwd?: string;\n\treadonly providerSettings?: ClaudeSdkOauthProviderSettings;\n\treadonly authLane?: ClaudeSdkOauthAuthLane;\n\treadonly tools?: readonly string[];\n\treadonly pathToClaudeCodeExecutable?: string;\n\treadonly sessionId?: string;\n\treadonly onGuidance?: (text: string) => void;\n}\n\nconst ADAPTIVE_THINKING_MODEL_MARKERS = [\n\t\"opus-4-6\",\n\t\"opus-4.6\",\n\t\"opus-4-7\",\n\t\"opus-4.7\",\n\t\"opus-4-8\",\n\t\"opus-4.8\",\n\t\"opus-5\",\n\t\"sonnet-4-6\",\n\t\"sonnet-4.6\",\n\t\"sonnet-5\",\n\t\"fable-5\",\n\t\"mythos-5\",\n] as const;\n\nconst NATIVE_XHIGH_EFFORT_MODEL_MARKERS = [\n\t\"opus-4-7\",\n\t\"opus-4-8\",\n\t\"opus-5\",\n\t\"sonnet-5\",\n\t\"fable-5\",\n\t\"mythos-5\",\n] as const;\n\nconst DEFAULT_THINKING_BUDGETS: Required<ThinkingBudgets> = {\n\tminimal: 2048,\n\tlow: 8192,\n\tmedium: 16384,\n\thigh: 31999,\n\tmax: 63999,\n};\n\nfunction includesModelMarker(model: Model<Api>, markers: readonly string[]): boolean {\n\tconst id = model.id.toLowerCase();\n\treturn markers.some((marker) => id.includes(marker));\n}\n\nfunction forcedAdaptiveThinking(model: Model<Api>): boolean | undefined {\n\tconst compat = model.compat;\n\tif (!compat || !(\"forceAdaptiveThinking\" in compat)) return undefined;\n\treturn typeof compat.forceAdaptiveThinking === \"boolean\" ? compat.forceAdaptiveThinking : undefined;\n}\n\nfunction supportsAdaptiveThinking(model: Model<Api>): boolean {\n\treturn forcedAdaptiveThinking(model) ?? includesModelMarker(model, ADAPTIVE_THINKING_MODEL_MARKERS);\n}\n\nfunction supportsNativeXhighEffort(model: Model<Api>): boolean {\n\treturn includesModelMarker(model, NATIVE_XHIGH_EFFORT_MODEL_MARKERS);\n}\n\nfunction isEffortLevel(value: string): value is EffortLevel {\n\treturn value === \"low\" || value === \"medium\" || value === \"high\" || value === \"xhigh\" || value === \"max\";\n}\n\nfunction mapThinkingLevelToEffort(model: Model<Api>, level: ThinkingLevel): EffortLevel {\n\tconst mapped = model.thinkingLevelMap?.[level];\n\tif (typeof mapped === \"string\" && isEffortLevel(mapped)) return mapped;\n\tswitch (level) {\n\t\tcase \"minimal\":\n\t\tcase \"low\":\n\t\t\treturn \"low\";\n\t\tcase \"medium\":\n\t\t\treturn \"medium\";\n\t\tcase \"high\":\n\t\t\treturn \"high\";\n\t\tcase \"xhigh\":\n\t\t\treturn supportsNativeXhighEffort(model) ? \"xhigh\" : \"max\";\n\t\tcase \"max\":\n\t\t\treturn \"max\";\n\t}\n}\n\nfunction mapThinkingTokens(reasoning: ThinkingLevel, thinkingBudgets: ThinkingBudgets | undefined): number {\n\tconst budgetLevel = reasoning === \"xhigh\" ? \"high\" : reasoning;\n\tconst customBudget = thinkingBudgets?.[budgetLevel];\n\treturn typeof customBudget === \"number\" && Number.isFinite(customBudget) && customBudget > 0\n\t\t? customBudget\n\t\t: DEFAULT_THINKING_BUDGETS[budgetLevel];\n}\n\nfunction findAgentsMdInParents(cwd: string): string | undefined {\n\tlet current = resolve(cwd);\n\twhile (true) {\n\t\tconst candidate = join(current, \"AGENTS.md\");\n\t\tif (existsSync(candidate)) return candidate;\n\t\tconst parent = dirname(current);\n\t\tif (parent === current) return undefined;\n\t\tcurrent = parent;\n\t}\n}\n\nfunction sanitizeAgentsContent(content: string): string {\n\tconst configDirectory = CONFIG_DIR_NAME.replace(/^\\./, \"\");\n\tconst escapedConfigDirectory = configDirectory.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\treturn content\n\t\t.replace(new RegExp(`~/${escapedConfigDirectory}\\\\b`, \"gi\"), \"~/.claude\")\n\t\t.replace(new RegExp(`(^|[\\\\s'\"\\`])\\\\.${escapedConfigDirectory}/`, \"g\"), \"$1.claude/\")\n\t\t.replace(new RegExp(`\\\\b${escapedConfigDirectory}\\\\b`, \"gi\"), \"environment\");\n}\n\nfunction extractAgentsAppend(cwd: string): string | undefined {\n\tconst agentsPath = findAgentsMdInParents(cwd) ?? join(getAgentDir(), \"AGENTS.md\");\n\tif (!existsSync(agentsPath)) return undefined;\n\ttry {\n\t\tconst content = sanitizeAgentsContent(readFileSync(agentsPath, \"utf-8\").trim());\n\t\treturn content.length > 0 ? `# CLAUDE.md\\n\\n${content}` : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction rewriteSkillsLocations(skillsBlock: string, cwd: string): string {\n\tconst globalSkillsRoot = join(getAgentDir(), \"skills\");\n\tconst projectSkillsRoot = join(cwd, CONFIG_DIR_NAME, \"skills\");\n\treturn skillsBlock.replace(/<location>([^<]+)<\\/location>/g, (_match, location: string) => {\n\t\tif (location.startsWith(globalSkillsRoot)) {\n\t\t\treturn `<location>~/.claude/skills/${relative(globalSkillsRoot, location).replace(/^\\.+/, \"\")}</location>`;\n\t\t}\n\t\tif (location.startsWith(projectSkillsRoot)) {\n\t\t\treturn `<location>.claude/skills/${relative(projectSkillsRoot, location).replace(/^\\.+/, \"\")}</location>`;\n\t\t}\n\t\treturn `<location>${location}</location>`;\n\t});\n}\n\nfunction extractSkillsAppend(systemPrompt: string | undefined, cwd: string): string | undefined {\n\tif (!systemPrompt) return undefined;\n\tconst marker = \"The following skills provide specialized instructions for specific tasks.\";\n\tconst start = systemPrompt.indexOf(marker);\n\tconst end = start === -1 ? -1 : systemPrompt.indexOf(\"</available_skills>\", start);\n\tif (end === -1) return undefined;\n\treturn rewriteSkillsLocations(systemPrompt.slice(start, end + \"</available_skills>\".length).trim(), cwd);\n}\n\n/**\n * This lane rebuilds the prompt from the `claude_code` preset plus `append`, so any\n * region of senpi's composed prompt without an extractor here never reaches the model.\n *\n * Located by the rules builtin's opaque region sentinels rather than the model-facing\n * `<project_rules>` tags, which surrounding prompt content may legitimately contain.\n * The sentinels are a reserved wire literal but nothing neutralizes them outside the block, so\n * each candidate is structurally validated and rejected candidates are skipped - otherwise a\n * context file carrying one would shadow the real block or cross-match its end sentinel.\n * Fail-closed on a missing end sentinel: never read to end-of-string, or the sections\n * extensions append after this one get relabelled as project rules.\n */\nfunction extractProjectRulesAppend(systemPrompt: string | undefined): string | undefined {\n\tif (!systemPrompt) return undefined;\n\tlet searchFrom = 0;\n\twhile (searchFrom <= systemPrompt.length) {\n\t\tconst sentinelStart = systemPrompt.indexOf(PROJECT_RULES_REGION_START_MARKER, searchFrom);\n\t\tif (sentinelStart === -1) return undefined;\n\t\tconst regionStart = sentinelStart + PROJECT_RULES_REGION_START_MARKER.length;\n\t\tconst regionEnd = systemPrompt.indexOf(PROJECT_RULES_REGION_END_MARKER, regionStart);\n\t\tif (regionEnd === -1) return undefined;\n\t\tconst region = systemPrompt.slice(regionStart, regionEnd).trim();\n\t\tif (isProjectRulesEnvelope(region)) return region;\n\t\tsearchFrom = regionStart;\n\t}\n\treturn undefined;\n}\n\nfunction isProjectRulesEnvelope(region: string): boolean {\n\treturn (\n\t\tregion.startsWith(`${PROJECT_RULES_START_MARKER}\\n${PROJECT_RULES_HEADING}\\n`) &&\n\t\tregion.endsWith(`\\n${PROJECT_RULES_END_MARKER}`)\n\t);\n}\n\nfunction resolveSettingSources(\n\tproviderSettings: ClaudeSdkOauthProviderSettings,\n\tmode: ClaudeSdkOauthSystemPromptMode,\n\tauthLane: ClaudeSdkOauthAuthLane,\n): SettingSource[] {\n\tif (providerSettings.settingSources !== undefined) return [...providerSettings.settingSources];\n\tif (mode !== \"preset-append\" || authLane !== \"ambient\") return [];\n\treturn [\"user\", \"project\"];\n}\n\nexport function buildClaudeSdkOauthQueryOptions(input: ClaudeSdkOauthQueryOptionsInput): Options {\n\tconst cwd = input.cwd ?? process.cwd();\n\tconst providerSettings = input.providerSettings ?? loadClaudeSdkOauthProviderSettingsFromDisk(cwd);\n\tconst appendSystemPrompt = providerSettings.appendSystemPrompt !== false;\n\tconst resolvedMode = resolveSystemPromptMode(providerSettings);\n\tconst mode = resolvedMode.mode;\n\tif (input.sessionId !== undefined && input.onGuidance !== undefined) {\n\t\tconst deprecation = presetAppendDeprecationGuidance({\n\t\t\tmode,\n\t\t\tconflict: resolvedMode.conflict,\n\t\t\tsessionId: input.sessionId,\n\t\t});\n\t\tif (deprecation !== undefined) input.onGuidance(deprecation);\n\t}\n\tconst authLane = input.authLane ?? providerSettings.tokenInjection ?? \"ambient\";\n\tconst append =\n\t\tmode === \"preset-append\"\n\t\t\t? [\n\t\t\t\t\textractAgentsAppend(cwd),\n\t\t\t\t\textractSkillsAppend(input.context.systemPrompt, cwd),\n\t\t\t\t\textractProjectRulesAppend(input.context.systemPrompt),\n\t\t\t\t].filter((part): part is string => part !== undefined)\n\t\t\t: [];\n\tconst systemPrompt =\n\t\tmode === \"preset-append\"\n\t\t\t? { type: \"preset\" as const, preset: \"claude_code\" as const, append: append.join(\"\\n\\n\") || undefined }\n\t\t\t: mode === \"override\"\n\t\t\t\t? loadOverrideSystemPrompt(providerSettings.systemPromptFile)\n\t\t\t\t: resolveCustomSystemPrompt(input.context.systemPrompt);\n\tconst strictMcpConfig = providerSettings.strictMcpConfig ?? !appendSystemPrompt;\n\tconst queryOptions: Options = {\n\t\tcwd,\n\t\tmodel: input.model.id,\n\t\ttools: input.tools ? [...input.tools] : [...BUILTIN_SDK_TOOLS],\n\t\tpermissionMode: \"dontAsk\",\n\t\tincludePartialMessages: true,\n\t\tcanUseTool,\n\t\thooks: HOST_TOOL_DENIAL_HOOKS,\n\t\tsystemPrompt,\n\t\tsettings: { autoCompactEnabled: true },\n\t\tsettingSources: resolveSettingSources(providerSettings, mode, authLane),\n\t};\n\tif (input.pathToClaudeCodeExecutable) queryOptions.pathToClaudeCodeExecutable = input.pathToClaudeCodeExecutable;\n\tif (strictMcpConfig) queryOptions.extraArgs = { \"strict-mcp-config\": null };\n\n\tconst reasoning = input.streamOptions?.reasoning;\n\tif (reasoning && supportsAdaptiveThinking(input.model)) {\n\t\tqueryOptions.thinking = { type: \"adaptive\", display: \"summarized\" } satisfies ThinkingConfig;\n\t\tqueryOptions.effort = mapThinkingLevelToEffort(input.model, reasoning);\n\t} else if (reasoning) {\n\t\tqueryOptions.maxThinkingTokens = mapThinkingTokens(reasoning, input.streamOptions?.thinkingBudgets);\n\t}\n\treturn queryOptions;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-registry-wiring.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA0BnD,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"session-registry-wiring.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA0BnD,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,IAAI,CAsD1E"}
|
|
@@ -16,7 +16,9 @@ function residentEntryFor(sessionId, message) {
|
|
|
16
16
|
return entry;
|
|
17
17
|
}
|
|
18
18
|
export function registerSessionRegistry(pi) {
|
|
19
|
-
pi.on("session_compact", (
|
|
19
|
+
pi.on("session_compact", (event, ctx) => {
|
|
20
|
+
if (!event.accepted)
|
|
21
|
+
return;
|
|
20
22
|
recordPendingFork(ctx.sessionManager.getSessionId(), "compaction");
|
|
21
23
|
});
|
|
22
24
|
pi.on("session_before_fork", (_event, ctx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-registry-wiring.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/G,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EACN,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,cAAc,GAAG,IAAI,uBAAuB,EAAE,CAAC;AAErD,SAAS,oBAAoB,CAAC,SAAiB,EAAE,MAAc;IAC9D,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,KAAK;QAAE,eAAe,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IACxD,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAiB,EAAE,OAAyB;IACrE,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7E,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,EAA4B;IACnE,EAAE,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"session-registry-wiring.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,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Message } from \"@earendil-works/pi-ai\";\nimport type { ExtensionAPI } from \"../../types.ts\";\nimport { CLAUDE_SDK_OAUTH_PROVIDER_ID } from \"./account-management.ts\";\nimport { AssistantCommitBoundary, isResidentAssistant, isTerminalFailure } from \"./session-commit-boundary.ts\";\nimport { bindingFromEntry, rememberBinding } from \"./session-reattach.ts\";\nimport {\n\tcloseSession,\n\tgetSession,\n\trecordBranchInfo,\n\trecordPendingFork,\n\tswitchSessionModel,\n} from \"./session-registry.ts\";\n\nconst commitBoundary = new AssistantCommitBoundary();\n\nfunction keepBindingThenClose(sessionId: string, reason: string): void {\n\tconst entry = getSession(sessionId);\n\tif (entry) rememberBinding(bindingFromEntry(entry, []));\n\tcloseSession(sessionId, reason);\n}\n\nfunction residentEntryFor(sessionId: string, message: AssistantMessage) {\n\tconst entry = getSession(sessionId);\n\tif (!entry || !isResidentAssistant(message, entry.modelId)) return undefined;\n\treturn entry;\n}\n\nexport function registerSessionRegistry(pi: Pick<ExtensionAPI, \"on\">): void {\n\tpi.on(\"session_compact\", (event, ctx) => {\n\t\tif (!event.accepted) return;\n\t\trecordPendingFork(ctx.sessionManager.getSessionId(), \"compaction\");\n\t});\n\tpi.on(\"session_before_fork\", (_event, ctx) => {\n\t\trecordPendingFork(ctx.sessionManager.getSessionId(), \"fork\");\n\t});\n\tpi.on(\"session_tree\", (event, ctx) => {\n\t\tif (event.oldLeafId === null || event.newLeafId === null) return;\n\t\trecordBranchInfo(ctx.sessionManager.getSessionId(), {\n\t\t\toldLeafId: event.oldLeafId,\n\t\t\tnewLeafId: event.newLeafId,\n\t\t});\n\t});\n\tpi.on(\"model_select\", async (event, ctx) => {\n\t\tconst sessionId = ctx.sessionManager.getSessionId();\n\t\tif (event.model?.provider !== CLAUDE_SDK_OAUTH_PROVIDER_ID) {\n\t\t\tcloseSession(sessionId, \"model_selected\");\n\t\t\treturn;\n\t\t}\n\t\tif (!(await switchSessionModel(sessionId, event.model.id))) {\n\t\t\tkeepBindingThenClose(sessionId, \"model_selected\");\n\t\t}\n\t});\n\tpi.on(\"thinking_level_select\", (_event, ctx) => {\n\t\tkeepBindingThenClose(ctx.sessionManager.getSessionId(), \"thinking_level_selected\");\n\t});\n\tpi.on(\"message_update\", (event, ctx) => {\n\t\tif (event.message.role !== \"assistant\") return;\n\t\tconst sessionId = ctx.sessionManager.getSessionId();\n\t\tif (residentEntryFor(sessionId, event.message)) {\n\t\t\tcommitBoundary.captureProviderFinal(sessionId, event.message);\n\t\t}\n\t});\n\tpi.on(\"message_end\", (event, ctx) => {\n\t\tif (event.message.role !== \"assistant\") return;\n\t\tconst sessionId = ctx.sessionManager.getSessionId();\n\t\tconst entry = getSession(sessionId);\n\t\tif (!entry) return;\n\t\tif (isTerminalFailure(event.message)) {\n\t\t\tcommitBoundary.forget(sessionId);\n\t\t\treturn;\n\t\t}\n\t\tif (commitBoundary.commit(sessionId, event.message, entry.modelId) === \"rewritten\") {\n\t\t\trecordPendingFork(sessionId, \"assistant_rewritten\");\n\t\t}\n\t});\n\tpi.on(\"session_shutdown\", (event, ctx) => {\n\t\tcloseSession(ctx.sessionManager.getSessionId(), event.reason);\n\t});\n\tpi.on(\"session_extensions_removed\", (_event, ctx) => {\n\t\tcloseSession(ctx.sessionManager.getSessionId(), \"extensions_removed\");\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEX,YAAY,EAIZ,MAAM,gBAAgB,CAAC;AA4BxB,OAAO,EAEN,KAAK,kCAAkC,EAIvC,MAAM,oBAAoB,CAAC;AAgD5B,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMnG;AA2ED,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAC1C,EAAE,EAAE,YAAY,EAChB,4BAA4B,GAAE,kCAAuC,GACnE,IAAI,CA6vBN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createWarmAnchorSnapshot, isWarmSummaryAnchorValid } from "../../../compaction/warm-anchor.js";
|
|
2
3
|
import { convertToLlm } from "../../../messages.js";
|
|
3
4
|
import * as checkpointState from "./checkpoint-state.js";
|
|
4
5
|
import * as breaker from "./circuit-breaker.js";
|
|
@@ -131,8 +132,28 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
131
132
|
clearTimeout(idleWarmupTimer);
|
|
132
133
|
idleWarmupTimer = undefined;
|
|
133
134
|
}
|
|
134
|
-
//
|
|
135
|
-
//
|
|
135
|
+
// A session reload retires this extension generation while the warm-up
|
|
136
|
+
// watcher below is still armed: `AgentSession.reload()` invalidates the old
|
|
137
|
+
// runner, after which every `ExtensionContext` getter throws
|
|
138
|
+
// "stale extension generation after reload". The watcher outlives that
|
|
139
|
+
// invalidation in two places — the `job.failure` continuation and the armed
|
|
140
|
+
// retry timer — and neither had a caller left to receive the throw: the
|
|
141
|
+
// continuation is spawned with `void` (unhandled rejection) and the timer
|
|
142
|
+
// callback throws straight into the timer queue, which terminates the
|
|
143
|
+
// process. The context carries no liveness flag, so a retired generation is
|
|
144
|
+
// only observable by reading a getter and catching the assertion.
|
|
145
|
+
function isContextRetired(ctx) {
|
|
146
|
+
try {
|
|
147
|
+
ctx.isIdle();
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Fenced on the observed job: a prompt, invalidation, a reload, or a newer
|
|
155
|
+
// warm-up stands this watcher down before it can start a duplicate
|
|
156
|
+
// summarization.
|
|
136
157
|
function armIdleWarmupRetry(ctx) {
|
|
137
158
|
const job = speculativeJob;
|
|
138
159
|
if (!job)
|
|
@@ -144,6 +165,11 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
144
165
|
}
|
|
145
166
|
if (speculativeJob !== job)
|
|
146
167
|
return;
|
|
168
|
+
// A reload between arming and this continuation retires the context.
|
|
169
|
+
if (isContextRetired(ctx)) {
|
|
170
|
+
cancelIdleWarmupRetry();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
147
173
|
const usage = ctx.getContextUsage();
|
|
148
174
|
const contextWindow = usage?.contextWindow ?? ctx.model?.contextWindow ?? DEFAULT_CONTEXT_WINDOW;
|
|
149
175
|
const retryDecision = {
|
|
@@ -161,6 +187,10 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
161
187
|
idleWarmupTimer = undefined;
|
|
162
188
|
if (speculativeJob !== job)
|
|
163
189
|
return;
|
|
190
|
+
// The reload may land after the timer was armed; a throw here would
|
|
191
|
+
// escape into the timer queue as an uncaughtException.
|
|
192
|
+
if (isContextRetired(ctx))
|
|
193
|
+
return;
|
|
164
194
|
if (!ctx.isIdle())
|
|
165
195
|
return;
|
|
166
196
|
idleWarmupAttempt += 1;
|
|
@@ -175,6 +205,39 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
175
205
|
}, idleRetry.IDLE_WARMUP_RETRY_DELAY_MS);
|
|
176
206
|
});
|
|
177
207
|
}
|
|
208
|
+
function isSameModelIdentity(left, right) {
|
|
209
|
+
return (right !== undefined &&
|
|
210
|
+
left.api === right.api &&
|
|
211
|
+
left.provider === right.provider &&
|
|
212
|
+
left.id === right.id &&
|
|
213
|
+
left.baseUrl === right.baseUrl &&
|
|
214
|
+
left.contextWindow === right.contextWindow);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Detach the warm job for the core route before any `await`, so exactly one
|
|
218
|
+
* claimant can own it. The controller is deliberately NOT aborted: the whole
|
|
219
|
+
* point is to keep the already-paid summarization alive and hand its result to
|
|
220
|
+
* core, and clearing the reference is what stands the idle-retry watcher down.
|
|
221
|
+
*/
|
|
222
|
+
function claimWarmSummaryForCoreRoute(event, ctx) {
|
|
223
|
+
const job = speculativeJob;
|
|
224
|
+
if (!job)
|
|
225
|
+
return undefined;
|
|
226
|
+
if (event.customInstructions !== undefined)
|
|
227
|
+
return undefined;
|
|
228
|
+
if (job.snapshot.origin !== "speculative")
|
|
229
|
+
return undefined;
|
|
230
|
+
if (job.snapshot.preparation.firstKeptEntryId !== event.preparation.firstKeptEntryId)
|
|
231
|
+
return undefined;
|
|
232
|
+
if (!isSameModelIdentity(job.snapshot.model, ctx.model))
|
|
233
|
+
return undefined;
|
|
234
|
+
const anchor = createWarmAnchorSnapshot(job.snapshot.preparation.firstKeptEntryId, job.snapshot.branchEntries ?? []);
|
|
235
|
+
if (!anchor || !isWarmSummaryAnchorValid(anchor, event.branchEntries ?? ctx.sessionManager.getBranch())) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
speculativeJob = undefined;
|
|
239
|
+
return job;
|
|
240
|
+
}
|
|
178
241
|
function invalidateSpeculativeCompaction(ctx) {
|
|
179
242
|
const previousGeneration = speculativeGeneration;
|
|
180
243
|
speculativeGeneration++;
|
|
@@ -352,83 +415,118 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
352
415
|
}
|
|
353
416
|
}
|
|
354
417
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
418
|
+
const claimedWarmJob = claimWarmSummaryForCoreRoute(event, ctx);
|
|
419
|
+
// The claim detaches the job without aborting it, so ownership must survive every
|
|
420
|
+
// exit from this handler - including a throw - or the request it already paid for
|
|
421
|
+
// keeps streaming for a result nobody will read.
|
|
422
|
+
let warmJobConsumed = false;
|
|
355
423
|
invalidateSpeculativeCompaction(ctx);
|
|
356
|
-
if (lanePolicy.disablesSenpiCompaction(ctx)) {
|
|
357
|
-
return { cancel: true, reason: SDK_NATIVE_LANE_REJECTION_REASON };
|
|
358
|
-
}
|
|
359
|
-
if (cap.shouldRejectByCap(state).cancel) {
|
|
360
|
-
getLogger(ctx).debug("skip_cap", { reason: event.reason, count: state.acceptedAbsolute });
|
|
361
|
-
return {
|
|
362
|
-
cancel: true,
|
|
363
|
-
rejectionCause: "per-turn-cap",
|
|
364
|
-
reason: "absolute compaction cap reached for this session",
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const now = Date.now();
|
|
368
|
-
if (breaker.isTripped(state, now) && !breaker.shouldBypass(state, { reason: event.reason })) {
|
|
369
|
-
const remainingMs = state.trippedAt !== null ? Math.max(0, state.trippedAt + breaker.COOLDOWN_MS - now) : 0;
|
|
370
|
-
getLogger(ctx).debug("skip_breaker", { reason: event.reason, remainingSec: Math.ceil(remainingMs / 1000) });
|
|
371
|
-
return {
|
|
372
|
-
cancel: true,
|
|
373
|
-
rejectionCause: "circuit-breaker",
|
|
374
|
-
reason: `compaction circuit breaker cooling down (${Math.ceil(remainingMs / 1000)}s left)`,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
capturePendingMetadata(event.requestId, ctx);
|
|
378
|
-
const model = ctx.model;
|
|
379
|
-
if (!model)
|
|
380
|
-
return undefined;
|
|
381
|
-
const remoteCompaction = await runOpenAiRemoteCompaction(ctx, event, (data) => pi.events.emit(SENPI_COMPACTION_EVENT, data), remoteCompactionDependencies);
|
|
382
|
-
if (remoteCompaction) {
|
|
383
|
-
getLogger(ctx).debug("core_route_generated", { route: "core-route", requestId: event.requestId });
|
|
384
|
-
return { compaction: remoteCompaction };
|
|
385
|
-
}
|
|
386
|
-
const snapshot = {
|
|
387
|
-
generation: ++speculativeGeneration,
|
|
388
|
-
expectedRevision: ctx.getMessageRevision(),
|
|
389
|
-
model,
|
|
390
|
-
contextWindow: ctx.getContextUsage()?.contextWindow ?? model.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
391
|
-
preparation: event.preparation,
|
|
392
|
-
branchEntries: event.branchEntries,
|
|
393
|
-
promptVariant: getPromptVariant(event),
|
|
394
|
-
origin: "core-route",
|
|
395
|
-
customInstructions: event.customInstructions,
|
|
396
|
-
systemPrompt: ctx.getSystemPrompt(),
|
|
397
|
-
tools: getSummarizationTools(),
|
|
398
|
-
};
|
|
399
|
-
let compaction;
|
|
400
424
|
try {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
425
|
+
if (lanePolicy.disablesSenpiCompaction(ctx)) {
|
|
426
|
+
return {
|
|
427
|
+
cancel: true,
|
|
428
|
+
rejectionCause: "external-owner",
|
|
429
|
+
reason: SDK_NATIVE_LANE_REJECTION_REASON,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
if (cap.shouldRejectByCap(state).cancel) {
|
|
433
|
+
getLogger(ctx).debug("skip_cap", { reason: event.reason, count: state.acceptedAbsolute });
|
|
434
|
+
return {
|
|
435
|
+
cancel: true,
|
|
436
|
+
rejectionCause: "per-turn-cap",
|
|
437
|
+
reason: "absolute compaction cap reached for this session",
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
const now = Date.now();
|
|
441
|
+
if (breaker.isTripped(state, now) && !breaker.shouldBypass(state, { reason: event.reason })) {
|
|
442
|
+
const remainingMs = state.trippedAt !== null ? Math.max(0, state.trippedAt + breaker.COOLDOWN_MS - now) : 0;
|
|
443
|
+
getLogger(ctx).debug("skip_breaker", { reason: event.reason, remainingSec: Math.ceil(remainingMs / 1000) });
|
|
411
444
|
return {
|
|
412
445
|
cancel: true,
|
|
413
|
-
|
|
446
|
+
rejectionCause: "circuit-breaker",
|
|
447
|
+
reason: `compaction circuit breaker cooling down (${Math.ceil(remainingMs / 1000)}s left)`,
|
|
414
448
|
};
|
|
415
449
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
450
|
+
capturePendingMetadata(event.requestId, ctx);
|
|
451
|
+
const model = ctx.model;
|
|
452
|
+
if (!model) {
|
|
453
|
+
return undefined;
|
|
419
454
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (event.signal.aborted) {
|
|
425
|
-
return { cancel: true };
|
|
455
|
+
const remoteCompaction = await runOpenAiRemoteCompaction(ctx, event, (data) => pi.events.emit(SENPI_COMPACTION_EVENT, data), remoteCompactionDependencies);
|
|
456
|
+
if (remoteCompaction) {
|
|
457
|
+
getLogger(ctx).debug("core_route_generated", { route: "core-route", requestId: event.requestId });
|
|
458
|
+
return { compaction: remoteCompaction };
|
|
426
459
|
}
|
|
427
|
-
|
|
460
|
+
if (claimedWarmJob) {
|
|
461
|
+
const unlinkAbort = linkAbortSignal(event.signal, claimedWarmJob.controller);
|
|
462
|
+
let warmCompaction;
|
|
463
|
+
let warmFailure;
|
|
464
|
+
try {
|
|
465
|
+
warmCompaction = await claimedWarmJob.promise;
|
|
466
|
+
warmFailure = await claimedWarmJob.failure;
|
|
467
|
+
}
|
|
468
|
+
finally {
|
|
469
|
+
unlinkAbort();
|
|
470
|
+
}
|
|
471
|
+
if (warmFailure === undefined && warmCompaction && !event.signal.aborted) {
|
|
472
|
+
getLogger(ctx).debug("warm_consumed", { generation: claimedWarmJob.generation, route: "core-route" });
|
|
473
|
+
warmJobConsumed = true;
|
|
474
|
+
return { compaction: warmCompaction };
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const snapshot = {
|
|
478
|
+
generation: ++speculativeGeneration,
|
|
479
|
+
expectedRevision: ctx.getMessageRevision(),
|
|
480
|
+
model,
|
|
481
|
+
contextWindow: ctx.getContextUsage()?.contextWindow ?? model.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
482
|
+
preparation: event.preparation,
|
|
483
|
+
branchEntries: event.branchEntries,
|
|
484
|
+
promptVariant: getPromptVariant(event),
|
|
485
|
+
origin: "core-route",
|
|
486
|
+
customInstructions: event.customInstructions,
|
|
487
|
+
systemPrompt: ctx.getSystemPrompt(),
|
|
488
|
+
tools: getSummarizationTools(),
|
|
489
|
+
};
|
|
490
|
+
let compaction;
|
|
491
|
+
try {
|
|
492
|
+
compaction = await runExtensionCompaction(ctx, snapshot, event.signal, (delta) => ctx.updateCompaction?.({ reason: event.reason, signal: event.signal, delta }));
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
496
|
+
const failureKind = classifyRequiredCompactionFallbackFailure(error);
|
|
497
|
+
if (isRequiredCompactionFallbackReason(event.reason) &&
|
|
498
|
+
failureKind !== undefined &&
|
|
499
|
+
!event.signal.aborted) {
|
|
500
|
+
const fallback = createRequiredCompactionFallback(snapshot.preparation, snapshot.contextWindow, failureKind, { taskIntent: resolveInheritedTaskIntent(event.branchEntries) }, event.branchEntries);
|
|
501
|
+
if (fallback)
|
|
502
|
+
return { compaction: fallback };
|
|
503
|
+
pendingMetadata.delete(event.requestId);
|
|
504
|
+
return {
|
|
505
|
+
cancel: true,
|
|
506
|
+
reason: "deterministic compaction fallback cannot retain the prepared suffix",
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
pendingMetadata.delete(event.requestId);
|
|
510
|
+
if (error instanceof SummaryGenerationError) {
|
|
511
|
+
return { cancel: true, reason: error.message };
|
|
512
|
+
}
|
|
513
|
+
return { cancel: true, reason: `compaction generator failed: ${message}` };
|
|
514
|
+
}
|
|
515
|
+
if (!compaction) {
|
|
516
|
+
pendingMetadata.delete(event.requestId);
|
|
517
|
+
if (event.signal.aborted) {
|
|
518
|
+
return { cancel: true };
|
|
519
|
+
}
|
|
520
|
+
return { cancel: true, reason: "compaction generator returned no summary" };
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
compaction,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
finally {
|
|
527
|
+
if (!warmJobConsumed)
|
|
528
|
+
claimedWarmJob?.controller.abort();
|
|
428
529
|
}
|
|
429
|
-
return {
|
|
430
|
-
compaction,
|
|
431
|
-
};
|
|
432
530
|
});
|
|
433
531
|
pi.on("model_select", (event, ctx) => {
|
|
434
532
|
if (lanePolicy.disablesSenpiCompaction(ctx)) {
|
|
@@ -659,5 +757,15 @@ export default function compactionExtension(pi, remoteCompactionDependencies = {
|
|
|
659
757
|
pi.on("tool_call", (event) => {
|
|
660
758
|
restoration.trackToolCall(restorationState, event);
|
|
661
759
|
});
|
|
760
|
+
// The reload path retires this extension generation right after this event
|
|
761
|
+
// (`AgentSession.reload()` invalidates the old runner), so stand the idle
|
|
762
|
+
// warm-up watcher down here rather than leaving a timer armed against a
|
|
763
|
+
// context that is about to start throwing on every read.
|
|
764
|
+
pi.on("session_shutdown", () => {
|
|
765
|
+
cancelIdleWarmupRetry();
|
|
766
|
+
idleWarmupAttempt = 0;
|
|
767
|
+
speculativeJob?.controller.abort();
|
|
768
|
+
speculativeJob = undefined;
|
|
769
|
+
});
|
|
662
770
|
}
|
|
663
771
|
//# sourceMappingURL=index.js.map
|