From df06fa8ee644ed217f0f6505811553a07e163c99 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 16:21:07 -0500 Subject: [PATCH 01/43] Add turn-based tool protection (protectedTurns config) - Add protectedTurns config option to protect recent tools from pruning - Track currentTurn in session state using step-start parts - Store turn number on each cached tool parameter entry - Skip caching tools that are within the protected turn window - Exclude turn-protected tools from nudge counter --- README.md | 2 ++ lib/config.ts | 10 ++++++++++ lib/state/state.ts | 24 ++++++++++++++++++++++-- lib/state/tool-cache.ts | 32 ++++++++++++++++++++++++++------ lib/state/types.ts | 2 ++ lib/strategies/deduplication.ts | 2 +- lib/strategies/on-idle.ts | 3 ++- 7 files changed, 65 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9bfd0610..a3ed068c 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,8 @@ DCP uses its own config file: "enabled": true, // Additional tools to protect from pruning "protectedTools": [], + // Protect tools from pruning for N turns after they are called (0 = disabled) + "protectedTurns": 4, // Nudge the LLM to use the prune tool (every tool results) "nudge": { "enabled": true, diff --git a/lib/config.ts b/lib/config.ts index e1dbd1a7..f23d7d49 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -25,6 +25,7 @@ export interface PruneToolNudge { export interface PruneTool { enabled: boolean protectedTools: string[] + protectedTurns: number nudge: PruneToolNudge } @@ -72,6 +73,7 @@ export const VALID_CONFIG_KEYS = new Set([ 'strategies.pruneTool', 'strategies.pruneTool.enabled', 'strategies.pruneTool.protectedTools', + 'strategies.pruneTool.protectedTurns', 'strategies.pruneTool.nudge', 'strategies.pruneTool.nudge.enabled', 'strategies.pruneTool.nudge.frequency' @@ -158,6 +160,9 @@ function validateConfigTypes(config: Record): ValidationError[] { if (strategies.pruneTool.protectedTools !== undefined && !Array.isArray(strategies.pruneTool.protectedTools)) { errors.push({ key: 'strategies.pruneTool.protectedTools', expected: 'string[]', actual: typeof strategies.pruneTool.protectedTools }) } + if (strategies.pruneTool.protectedTurns !== undefined && typeof strategies.pruneTool.protectedTurns !== 'number') { + errors.push({ key: 'strategies.pruneTool.protectedTurns', expected: 'number', actual: typeof strategies.pruneTool.protectedTurns }) + } if (strategies.pruneTool.nudge) { if (strategies.pruneTool.nudge.enabled !== undefined && typeof strategies.pruneTool.nudge.enabled !== 'boolean') { errors.push({ key: 'strategies.pruneTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.nudge.enabled }) @@ -240,6 +245,7 @@ const defaultConfig: PluginConfig = { pruneTool: { enabled: true, protectedTools: [...DEFAULT_PROTECTED_TOOLS], + protectedTurns: 4, nudge: { enabled: true, frequency: 10 @@ -341,6 +347,8 @@ function createDefaultConfig(): void { "enabled": true, // Additional tools to protect from pruning "protectedTools": [], + // Protect tools from pruning for N turns after they are called (0 = disabled) + "protectedTurns": 4, // Nudge the LLM to use the prune tool (every tool results) "nudge": { "enabled": true, @@ -426,6 +434,7 @@ function mergeStrategies( ...(override.pruneTool?.protectedTools ?? []) ]) ], + protectedTurns: override.pruneTool?.protectedTurns ?? base.pruneTool.protectedTurns, nudge: { enabled: override.pruneTool?.nudge?.enabled ?? base.pruneTool.nudge.enabled, frequency: override.pruneTool?.nudge?.frequency ?? base.pruneTool.nudge.frequency @@ -452,6 +461,7 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { pruneTool: { ...config.strategies.pruneTool, protectedTools: [...config.strategies.pruneTool.protectedTools], + protectedTurns: config.strategies.pruneTool.protectedTurns, nudge: { ...config.strategies.pruneTool.nudge } }, supersedeWrites: { diff --git a/lib/state/state.ts b/lib/state/state.ts index caab6d9b..e33f4c8d 100644 --- a/lib/state/state.ts +++ b/lib/state/state.ts @@ -2,7 +2,7 @@ import type { SessionState, ToolParameterEntry, WithParts } from "./types" import type { Logger } from "../logger" import { loadSessionState } from "./persistence" import { isSubAgentSession } from "./utils" -import { getLastUserMessage } from "../shared-utils" +import { getLastUserMessage, isMessageCompacted } from "../shared-utils" export const checkSession = async ( client: any, @@ -34,6 +34,8 @@ export const checkSession = async ( state.prune.toolIds = [] logger.info("Detected compaction from messages - cleared tool cache", { timestamp: lastCompactionTimestamp }) } + + state.currentTurn = countTurns(state, messages) } export function createSessionState(): SessionState { @@ -50,7 +52,8 @@ export function createSessionState(): SessionState { toolParameters: new Map(), nudgeCounter: 0, lastToolPrune: false, - lastCompaction: 0 + lastCompaction: 0, + currentTurn: 0 } } @@ -68,6 +71,7 @@ export function resetSessionState(state: SessionState): void { state.nudgeCounter = 0 state.lastToolPrune = false state.lastCompaction = 0 + state.currentTurn = 0 } export async function ensureSessionInitialized( @@ -92,6 +96,7 @@ export async function ensureSessionInitialized( logger.info("isSubAgent = " + isSubAgent) state.lastCompaction = findLastCompactionTimestamp(messages) + state.currentTurn = countTurns(state, messages) const persisted = await loadSessionState(sessionId, logger) if (persisted === null) { @@ -116,3 +121,18 @@ function findLastCompactionTimestamp(messages: WithParts[]): number { } return 0 } + +export function countTurns(state: SessionState, messages: WithParts[]): number { + let turnCount = 0 + for (const msg of messages) { + if (isMessageCompacted(state, msg)) { + continue + } + for (const part of msg.parts) { + if (part.type === "step-start") { + turnCount++ + } + } + } + return turnCount +} diff --git a/lib/state/tool-cache.ts b/lib/state/tool-cache.ts index ee2e2dc5..ef0bb0c6 100644 --- a/lib/state/tool-cache.ts +++ b/lib/state/tool-cache.ts @@ -18,6 +18,7 @@ export async function syncToolCache( logger.info("Syncing tool parameters from OpenCode messages") state.nudgeCounter = 0 + let turnCounter = 0 for (const msg of messages) { if (isMessageCompacted(state, msg)) { @@ -25,19 +26,36 @@ export async function syncToolCache( } for (const part of msg.parts) { - if (part.type !== "tool" || !part.callID) { + if (part.type === "step-start") { + turnCounter++ continue } - if (state.toolParameters.has(part.callID)) { + + if (part.type !== "tool" || !part.callID) { continue } + const isProtectedByTurn = config.strategies.pruneTool.protectedTurns > 0 && + (state.currentTurn - turnCounter) < config.strategies.pruneTool.protectedTurns + + state.lastToolPrune = part.tool === "prune" + if (part.tool === "prune") { state.nudgeCounter = 0 - } else if (!config.strategies.pruneTool.protectedTools.includes(part.tool)) { + } else if ( + !config.strategies.pruneTool.protectedTools.includes(part.tool) && + !isProtectedByTurn + ) { state.nudgeCounter++ } - state.lastToolPrune = part.tool === "prune" + + if (state.toolParameters.has(part.callID)) { + continue + } + + if (isProtectedByTurn) { + continue + } state.toolParameters.set( part.callID, @@ -46,12 +64,14 @@ export async function syncToolCache( parameters: part.state?.input ?? {}, status: part.state.status as ToolStatus | undefined, error: part.state.status === "error" ? part.state.error : undefined, + turn: turnCounter, } ) - logger.info("Cached tool id: " + part.callID) + logger.info(`Cached tool id: ${part.callID} (created on turn ${turnCounter})`) } } - logger.info("Synced cache - size: " + state.toolParameters.size) + + logger.info(`Synced cache - size: ${state.toolParameters.size}, currentTurn: ${state.currentTurn}, nudgeCounter: ${state.nudgeCounter}`) trimToolParametersCache(state) } catch (error) { logger.warn("Failed to sync tool parameters from OpenCode", { diff --git a/lib/state/types.ts b/lib/state/types.ts index 678bf297..04847d58 100644 --- a/lib/state/types.ts +++ b/lib/state/types.ts @@ -12,6 +12,7 @@ export interface ToolParameterEntry { parameters: any status?: ToolStatus error?: string + turn: number // Which turn (step-start count) this tool was called on } export interface SessionStats { @@ -32,4 +33,5 @@ export interface SessionState { nudgeCounter: number lastToolPrune: boolean lastCompaction: number + currentTurn: number // Current turn count derived from step-start parts } diff --git a/lib/strategies/deduplication.ts b/lib/strategies/deduplication.ts index 21c4be65..11462a88 100644 --- a/lib/strategies/deduplication.ts +++ b/lib/strategies/deduplication.ts @@ -41,7 +41,7 @@ export const deduplicate = ( for (const id of unprunedIds) { const metadata = state.toolParameters.get(id) if (!metadata) { - logger.warn(`Missing metadata for tool call ID: ${id}`) + // logger.warn(`Missing metadata for tool call ID: ${id}`) continue } diff --git a/lib/strategies/on-idle.ts b/lib/strategies/on-idle.ts index f0870c2e..602298e3 100644 --- a/lib/strategies/on-idle.ts +++ b/lib/strategies/on-idle.ts @@ -45,7 +45,8 @@ function parseMessages( tool: part.tool, parameters: parameters, status: part.state?.status, - error: part.state?.status === "error" ? part.state.error : undefined + error: part.state?.status === "error" ? part.state.error : undefined, + turn: cachedData?.turn ?? 0 }) } } From ed2d32d14e91d98a5864fc09da787638b7fd7216 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 16:21:11 -0500 Subject: [PATCH 02/43] Add stricter validation for prune tool IDs Reject prune requests for IDs not found in the tool cache, which catches both hallucinated IDs and turn-protected tools that aren't shown in the list. --- lib/strategies/prune-tool.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index 6cf9052c..e037f3f2 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -83,11 +83,17 @@ export function createPruneTool( return "Invalid IDs provided. Only use numeric IDs from the list." } - // Check for protected tools (model hallucinated an ID not in the prunable list) + // Validate that all IDs exist in cache and aren't protected + // (rejects hallucinated IDs and turn-protected tools not shown in ) for (const index of numericToolIds) { const id = toolIdList[index] const metadata = state.toolParameters.get(id) - if (metadata && config.strategies.pruneTool.protectedTools.includes(metadata.tool)) { + if (!metadata) { + logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id }) + return "Invalid IDs provided. Only use numeric IDs from the list." + } + if (config.strategies.pruneTool.protectedTools.includes(metadata.tool)) { + logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool }) return "Invalid IDs provided. Only use numeric IDs from the list." } } From c317f385284a2dbf95fee9f00c70653490442b5f Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 19:37:34 -0500 Subject: [PATCH 03/43] Add prune cooldown to prevent immediate re-pruning When the last tool used was prune, inject a cooldown message instead of the full prunable-tools list. This prevents the model from repeatedly invoking the prune tool in successive turns. Also refactors magic strings into named constants for better maintainability. --- lib/messages/prune.ts | 48 +++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 33d9a7a4..8759bcf2 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -10,6 +10,17 @@ const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]' const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]' const NUDGE_STRING = loadPrompt("nudge") +const wrapPrunableTools = (content: string): string => ` +The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Keep the context free of noise. +${content} +` +const PRUNABLE_TOOLS_COOLDOWN = ` +Pruning was just performed. Do not use the prune tool again. A fresh list will be available after your next tool use. +` + +const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345" +const SYNTHETIC_PART_ID = "prt_01234567890123456789012345" + const buildPrunableToolsList = ( state: SessionState, config: PluginConfig, @@ -41,7 +52,7 @@ const buildPrunableToolsList = ( return "" } - return `\nThe following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Keep the context free of noise.\n${lines.join('\n')}\n` + return wrapPrunableTools(lines.join('\n')) } export const insertPruneToolContext = ( @@ -59,20 +70,31 @@ export const insertPruneToolContext = ( return } - const prunableToolsList = buildPrunableToolsList(state, config, logger, messages) - if (!prunableToolsList) { - return - } + let prunableToolsContent: string + + if (state.lastToolPrune) { + logger.debug("Last tool was prune - injecting cooldown message") + prunableToolsContent = PRUNABLE_TOOLS_COOLDOWN + } else { + const prunableToolsList = buildPrunableToolsList(state, config, logger, messages) + if (!prunableToolsList) { + return + } + + logger.debug("prunable-tools: \n" + prunableToolsList) + + let nudgeString = "" + if (state.nudgeCounter >= config.strategies.pruneTool.nudge.frequency) { + logger.info("Inserting prune nudge message") + nudgeString = "\n" + NUDGE_STRING + } - let nudgeString = "" - if (state.nudgeCounter >= config.strategies.pruneTool.nudge.frequency) { - logger.info("Inserting prune nudge message") - nudgeString = "\n" + NUDGE_STRING + prunableToolsContent = prunableToolsList + nudgeString } const userMessage: WithParts = { info: { - id: "msg_01234567890123456789012345", + id: SYNTHETIC_MESSAGE_ID, sessionID: lastUserMessage.info.sessionID, role: "user", time: { created: Date.now() }, @@ -84,11 +106,11 @@ export const insertPruneToolContext = ( }, parts: [ { - id: "prt_01234567890123456789012345", + id: SYNTHETIC_PART_ID, sessionID: lastUserMessage.info.sessionID, - messageID: "msg_01234567890123456789012345", + messageID: SYNTHETIC_MESSAGE_ID, type: "text", - text: prunableToolsList + nudgeString, + text: prunableToolsContent, } ] } From 5419c04332e74727eccbc418ffa23ee180b8d2d9 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 19:37:39 -0500 Subject: [PATCH 04/43] Clarify prunable-tools list behavior in prompts - Note that some tools in context may not appear in the list (expected) - Clarify that the list is only injected when tools are available --- lib/prompts/synthetic.txt | 1 + lib/prompts/tool.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/prompts/synthetic.txt b/lib/prompts/synthetic.txt index 30057d5d..001e9b1a 100644 --- a/lib/prompts/synthetic.txt +++ b/lib/prompts/synthetic.txt @@ -28,6 +28,7 @@ Pruning that forces you to re-call the same tool later is a net loss. Only prune NOTES When in doubt, keep it. Prune often yet remain strategic about it. FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. +There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . diff --git a/lib/prompts/tool.txt b/lib/prompts/tool.txt index ccc68ff8..a7982b40 100644 --- a/lib/prompts/tool.txt +++ b/lib/prompts/tool.txt @@ -1,7 +1,7 @@ Prunes tool outputs from context to manage conversation size and reduce noise. For `write` and `edit` tools, the input content is pruned instead of the output. ## IMPORTANT: The Prunable List -A `` list is injected into user messages showing available tool outputs you can prune. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to prune. +A `` list is injected into user messages showing available tool outputs you can prune when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to prune. **Note:** For `write` and `edit` tools, pruning removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context. From 520370c29a05a2144a4fbb753a14fbf7d36636ee Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 19:45:14 -0500 Subject: [PATCH 05/43] Refactor protectedTurns to turnProtection with enabled/turns options Renames the flat protectedTurns config to a nested turnProtection object matching the structure of nudge. Now has: - enabled: boolean to toggle the feature - turns: number of turns to protect tools after use --- README.md | 7 ++++-- lib/config.ts | 47 +++++++++++++++++++++++++++++------------ lib/state/tool-cache.ts | 5 +++-- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a3ed068c..a228a70e 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,11 @@ DCP uses its own config file: "enabled": true, // Additional tools to protect from pruning "protectedTools": [], - // Protect tools from pruning for N turns after they are called (0 = disabled) - "protectedTurns": 4, + // Protect tools from pruning for N turns after they are called + "turnProtection": { + "enabled": false, + "turns": 4 + }, // Nudge the LLM to use the prune tool (every tool results) "nudge": { "enabled": true, diff --git a/lib/config.ts b/lib/config.ts index f23d7d49..b64951ce 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -22,10 +22,15 @@ export interface PruneToolNudge { frequency: number } +export interface PruneToolTurnProtection { + enabled: boolean + turns: number +} + export interface PruneTool { enabled: boolean protectedTools: string[] - protectedTurns: number + turnProtection: PruneToolTurnProtection nudge: PruneToolNudge } @@ -73,7 +78,9 @@ export const VALID_CONFIG_KEYS = new Set([ 'strategies.pruneTool', 'strategies.pruneTool.enabled', 'strategies.pruneTool.protectedTools', - 'strategies.pruneTool.protectedTurns', + 'strategies.pruneTool.turnProtection', + 'strategies.pruneTool.turnProtection.enabled', + 'strategies.pruneTool.turnProtection.turns', 'strategies.pruneTool.nudge', 'strategies.pruneTool.nudge.enabled', 'strategies.pruneTool.nudge.frequency' @@ -160,8 +167,13 @@ function validateConfigTypes(config: Record): ValidationError[] { if (strategies.pruneTool.protectedTools !== undefined && !Array.isArray(strategies.pruneTool.protectedTools)) { errors.push({ key: 'strategies.pruneTool.protectedTools', expected: 'string[]', actual: typeof strategies.pruneTool.protectedTools }) } - if (strategies.pruneTool.protectedTurns !== undefined && typeof strategies.pruneTool.protectedTurns !== 'number') { - errors.push({ key: 'strategies.pruneTool.protectedTurns', expected: 'number', actual: typeof strategies.pruneTool.protectedTurns }) + if (strategies.pruneTool.turnProtection) { + if (strategies.pruneTool.turnProtection.enabled !== undefined && typeof strategies.pruneTool.turnProtection.enabled !== 'boolean') { + errors.push({ key: 'strategies.pruneTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.turnProtection.enabled }) + } + if (strategies.pruneTool.turnProtection.turns !== undefined && typeof strategies.pruneTool.turnProtection.turns !== 'number') { + errors.push({ key: 'strategies.pruneTool.turnProtection.turns', expected: 'number', actual: typeof strategies.pruneTool.turnProtection.turns }) + } } if (strategies.pruneTool.nudge) { if (strategies.pruneTool.nudge.enabled !== undefined && typeof strategies.pruneTool.nudge.enabled !== 'boolean') { @@ -245,7 +257,10 @@ const defaultConfig: PluginConfig = { pruneTool: { enabled: true, protectedTools: [...DEFAULT_PROTECTED_TOOLS], - protectedTurns: 4, + turnProtection: { + enabled: false, + turns: 4 + }, nudge: { enabled: true, frequency: 10 @@ -343,14 +358,17 @@ function createDefaultConfig(): void { "enabled": true }, // Exposes a prune tool to your LLM to call when it determines pruning is necessary - "pruneTool": { - "enabled": true, + \"pruneTool\": { + \"enabled\": true, // Additional tools to protect from pruning - "protectedTools": [], - // Protect tools from pruning for N turns after they are called (0 = disabled) - "protectedTurns": 4, + \"protectedTools\": [], + // Protect tools from pruning for N turns after they are called + \"turnProtection\": { + \"enabled\": false, + \"turns\": 4 + }, // Nudge the LLM to use the prune tool (every tool results) - "nudge": { + \"nudge\": { "enabled": true, "frequency": 10 } @@ -434,7 +452,10 @@ function mergeStrategies( ...(override.pruneTool?.protectedTools ?? []) ]) ], - protectedTurns: override.pruneTool?.protectedTurns ?? base.pruneTool.protectedTurns, + turnProtection: { + enabled: override.pruneTool?.turnProtection?.enabled ?? base.pruneTool.turnProtection.enabled, + turns: override.pruneTool?.turnProtection?.turns ?? base.pruneTool.turnProtection.turns + }, nudge: { enabled: override.pruneTool?.nudge?.enabled ?? base.pruneTool.nudge.enabled, frequency: override.pruneTool?.nudge?.frequency ?? base.pruneTool.nudge.frequency @@ -461,7 +482,7 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { pruneTool: { ...config.strategies.pruneTool, protectedTools: [...config.strategies.pruneTool.protectedTools], - protectedTurns: config.strategies.pruneTool.protectedTurns, + turnProtection: { ...config.strategies.pruneTool.turnProtection }, nudge: { ...config.strategies.pruneTool.nudge } }, supersedeWrites: { diff --git a/lib/state/tool-cache.ts b/lib/state/tool-cache.ts index ef0bb0c6..f8ad2b3b 100644 --- a/lib/state/tool-cache.ts +++ b/lib/state/tool-cache.ts @@ -35,8 +35,9 @@ export async function syncToolCache( continue } - const isProtectedByTurn = config.strategies.pruneTool.protectedTurns > 0 && - (state.currentTurn - turnCounter) < config.strategies.pruneTool.protectedTurns + const isProtectedByTurn = config.strategies.pruneTool.turnProtection.enabled && + config.strategies.pruneTool.turnProtection.turns > 0 && + (state.currentTurn - turnCounter) < config.strategies.pruneTool.turnProtection.turns state.lastToolPrune = part.tool === "prune" From f4ae605668485e0d4e45ad0244542a8ed6093724 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 19:55:21 -0500 Subject: [PATCH 06/43] Update turn protection comments for clarity --- README.md | 2 +- lib/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a228a70e..9d15e730 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ DCP uses its own config file: "enabled": true, // Additional tools to protect from pruning "protectedTools": [], - // Protect tools from pruning for N turns after they are called + // Protect from pruning for message turns "turnProtection": { "enabled": false, "turns": 4 diff --git a/lib/config.ts b/lib/config.ts index b64951ce..9a670fe8 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -362,7 +362,7 @@ function createDefaultConfig(): void { \"enabled\": true, // Additional tools to protect from pruning \"protectedTools\": [], - // Protect tools from pruning for N turns after they are called + // Protect from pruning for message turns \"turnProtection\": { \"enabled\": false, \"turns\": 4 From 421eb5f2b5131608e6d8da3f306fc62fa19d2083 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 20:20:33 -0500 Subject: [PATCH 07/43] update pruning guidance to encourage consolidation and discourage frequent tiny prunes --- lib/messages/prune.ts | 2 +- lib/prompts/synthetic.txt | 6 +++--- lib/prompts/tool.txt | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 5d8547f1..d156e0ee 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -11,7 +11,7 @@ const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - inform const NUDGE_STRING = loadPrompt("nudge") const wrapPrunableTools = (content: string): string => ` -The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Keep the context free of noise. +The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output. Keep the context free of noise. ${content} ` const PRUNABLE_TOOLS_COOLDOWN = ` diff --git a/lib/prompts/synthetic.txt b/lib/prompts/synthetic.txt index 001e9b1a..73078846 100644 --- a/lib/prompts/synthetic.txt +++ b/lib/prompts/synthetic.txt @@ -4,8 +4,8 @@ ENVIRONMENT You are operating in a context-constrained environment and thus must proactively manage your context window using the `prune` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to prune. -PRUNE EARLY, PRUNE OFTEN - BUT PRUNE METHODICALLY -Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Evaluate what SHOULD be pruned before jumping the gun. +PRUNE METHODICALLY - CONSOLIDATE YOUR ACTIONS +Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER 1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore @@ -26,7 +26,7 @@ You MUST NOT prune when: Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again. NOTES -When in doubt, keep it. Prune often yet remain strategic about it. +When in doubt, keep it. Prune frequently yet remain strategic and consolidate your actions. FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . diff --git a/lib/prompts/tool.txt b/lib/prompts/tool.txt index a7982b40..c11d46f6 100644 --- a/lib/prompts/tool.txt +++ b/lib/prompts/tool.txt @@ -31,7 +31,8 @@ You must use this tool in three specific scenarios. The rules for distillation ( - **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls. ## Best Practices -- **Don't wait too long:** Prune frequently to keep the context agile. +- **Consolidate your prunes:** Don't prune a single small tool output (like a short bash command) unless it's pure noise. Wait until you have several items or a few large outputs to prune. Aim for high-impact prunes that significantly reduce context size or noise. +- **Don't wait too long:** Prune frequently to keep the context agile, but balance this with the need for consolidation. - **Be surgical:** You can mix strategies. Prune noise without comment, while distilling useful context in the same turn. - **Verify:** Ensure you have captured what you need before deleting useful raw data. - **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it—even if you've distilled findings. Distillation captures *knowledge*; implementation requires *context*. From ac67023cf67ce4c67fb81121aa0c6d65a9895551 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 20:29:29 -0500 Subject: [PATCH 08/43] Refactor prompt loading and rename pruning prompt files --- index.ts | 2 +- lib/messages/prune.ts | 2 +- lib/prompt.ts | 2 +- lib/prompts/{pruning.txt => on-idle-analysis.txt} | 0 lib/prompts/{nudge.txt => prune-nudge.txt} | 0 lib/prompts/{synthetic.txt => prune-system-prompt.txt} | 0 lib/prompts/{tool.txt => prune-tool-spec.txt} | 0 lib/strategies/prune-tool.ts | 4 ++-- 8 files changed, 5 insertions(+), 5 deletions(-) rename lib/prompts/{pruning.txt => on-idle-analysis.txt} (100%) rename lib/prompts/{nudge.txt => prune-nudge.txt} (100%) rename lib/prompts/{synthetic.txt => prune-system-prompt.txt} (100%) rename lib/prompts/{tool.txt => prune-tool-spec.txt} (100%) diff --git a/index.ts b/index.ts index 6b617c43..ac877050 100644 --- a/index.ts +++ b/index.ts @@ -29,7 +29,7 @@ const plugin: Plugin = (async (ctx) => { return { "experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => { - const syntheticPrompt = loadPrompt("synthetic") + const syntheticPrompt = loadPrompt("prune-system-prompt") output.system.push(syntheticPrompt) }, "experimental.chat.messages.transform": createChatMessageTransformHandler( diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index d156e0ee..f9348bf3 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -8,7 +8,7 @@ import { UserMessage } from "@opencode-ai/sdk" const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]' const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]' -const NUDGE_STRING = loadPrompt("nudge") +const NUDGE_STRING = loadPrompt("prune-nudge") const wrapPrunableTools = (content: string): string => ` The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output. Keep the context free of noise. diff --git a/lib/prompt.ts b/lib/prompt.ts index 76cc94f4..33a490fb 100644 --- a/lib/prompt.ts +++ b/lib/prompt.ts @@ -127,7 +127,7 @@ export function buildAnalysisPrompt( const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, '\n') - return loadPrompt("pruning", { + return loadPrompt("on-idle-analysis", { available_tool_call_ids: unprunedToolCallIds.join(", "), session_history: messagesJson }) diff --git a/lib/prompts/pruning.txt b/lib/prompts/on-idle-analysis.txt similarity index 100% rename from lib/prompts/pruning.txt rename to lib/prompts/on-idle-analysis.txt diff --git a/lib/prompts/nudge.txt b/lib/prompts/prune-nudge.txt similarity index 100% rename from lib/prompts/nudge.txt rename to lib/prompts/prune-nudge.txt diff --git a/lib/prompts/synthetic.txt b/lib/prompts/prune-system-prompt.txt similarity index 100% rename from lib/prompts/synthetic.txt rename to lib/prompts/prune-system-prompt.txt diff --git a/lib/prompts/tool.txt b/lib/prompts/prune-tool-spec.txt similarity index 100% rename from lib/prompts/tool.txt rename to lib/prompts/prune-tool-spec.txt diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index e037f3f2..c8f6d38e 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -10,8 +10,8 @@ import type { Logger } from "../logger" import { loadPrompt } from "../prompt" import { calculateTokensSaved, getCurrentParams } from "./utils" -/** Tool description loaded from prompts/tool.txt */ -const TOOL_DESCRIPTION = loadPrompt("tool") +/** Tool description loaded from prompts/prune-tool-spec.txt */ +const TOOL_DESCRIPTION = loadPrompt("prune-tool-spec") export interface PruneToolContext { client: any From f3d7e1c142e6c1cabea7d82b3b465a45c8a5d1e4 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Thu, 18 Dec 2025 21:23:52 -0500 Subject: [PATCH 09/43] feat: implement hidden distillation in prune tool --- lib/prompts/prune-system-prompt.txt | 6 +++--- lib/prompts/prune-tool-spec.txt | 28 ++++++++++++++-------------- lib/strategies/prune-tool.ts | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/prompts/prune-system-prompt.txt b/lib/prompts/prune-system-prompt.txt index 73078846..418b6670 100644 --- a/lib/prompts/prune-system-prompt.txt +++ b/lib/prompts/prune-system-prompt.txt @@ -8,14 +8,14 @@ PRUNE METHODICALLY - CONSOLIDATE YOUR ACTIONS Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER -1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore +### 1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore and provide a summary in the `distillation` parameter (as an object). 2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune IMMEDIATELY. No distillation - gun it down -3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS distill key findings into your narrative BEFORE pruning. Be surgical and strategic in what you extract. THINK: high signal, low noise +3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `distillation` parameter of the `prune` tool (as an object). Be surgical and strategic in what you extract. THINK: high signal, low noise You WILL use the `prune` tool when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- You have distilled enough information in your messages to prune related tools +- You have gathered enough information to prune related tools and preserve their value in the `distillation` parameter - Context contains tools output that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (pruning removes the large input content) diff --git a/lib/prompts/prune-tool-spec.txt b/lib/prompts/prune-tool-spec.txt index c11d46f6..ee60ebd7 100644 --- a/lib/prompts/prune-tool-spec.txt +++ b/lib/prompts/prune-tool-spec.txt @@ -12,21 +12,21 @@ You must use this tool in three specific scenarios. The rules for distillation ( ### 1. Task Completion (Clean Up) — reason: `completion` **When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). **Action:** Prune the tools used for that task. -**Distillation:** NOT REQUIRED. Since the task is done, the raw data is no longer needed. Simply state that the task is complete. +**Distillation:** Use the `distillation` parameter (as an object) to provide a final confirmation that the task is complete (e.g., `{ "status": "Tests passed, file updated" }`). ### 2. Removing Noise (Garbage Collection) — reason: `noise` **When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). **Action:** Prune these specific tool outputs immediately. -**Distillation:** FORBIDDEN. Do not pollute the context by summarizing useless information. Just cut it out. +**Distillation:** NOT REQUIRED for noise. ### 3. Context Conservation (Research & Consolidation) — reason: `consolidation` **When:** You have gathered useful information. Prune frequently as you work (e.g., after reading a few files), rather than waiting for a "long" phase to end. **Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). -**Distillation:** MANDATORY. Before pruning, you *must* explicitly summarize the key findings from *every* tool you plan to prune. - - **Extract specific value:** If you read a large file but only care about one function, record that function's details and prune the whole read. - - Narrative format: "I found X in file Y..." +**Distillation:** MANDATORY. Use the `distillation` parameter (MUST be an object) to explicitly summarize the key findings from *every* tool you plan to prune. + - **Extract specific value:** If you read a large file but only care about one function, record that function's details. + - Structure: `{ "file_path": { "findings": "...", "logic": "..." } }` - Capture all relevant details (function names, logic, constraints). - - Once distilled into your response history, the raw tool output can be safely pruned. + - Once distilled into the `distillation` object, the raw tool output can be safely pruned. - **Know when distillation isn't enough:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. - **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls. @@ -47,18 +47,18 @@ This file isn't relevant to the auth system. I'll remove it to clear the context Assistant: [Reads 5 different config files] -I have analyzed the configuration. Here is the distillation: -- 'config.ts' uses port 3000. -- 'db.ts' connects to mongo:27017. -- The other 3 files were defaults. -I have preserved the signals above, so I am now pruning the raw reads. -[Uses prune with ids: ["consolidation", "10", "11", "12", "13", "14"]] +I'll preserve the configuration details and prune the raw reads. +[Uses prune with ids: ["consolidation", "10", "11", "12", "13", "14"], distillation: { + "config.ts": "uses port 3000", + "db.ts": "connects to mongo:27017", + "others": "defaults" +}] Assistant: [Runs tests, they pass] -The tests passed. The feature is verified. -[Uses prune with ids: ["completion", "20", "21"]] +The tests passed. I'll clean up now. +[Uses prune with ids: ["completion", "20", "21"], distillation: "Verified feature implementation and passed all tests."] diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index c8f6d38e..8a277b54 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -36,6 +36,9 @@ export function createPruneTool( ).describe( "First element is the reason ('completion', 'noise', 'consolidation'), followed by numeric IDs as strings to prune" ), + distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).optional().describe( + "An object containing detailed summaries or extractions of the key findings from the tools being pruned. This is REQUIRED for 'consolidation'." + ), }, async execute(args, toolCtx) { const { client, state, logger, config, workingDirectory } = ctx @@ -61,6 +64,11 @@ export function createPruneTool( const numericToolIds: number[] = args.ids.slice(1) .map(id => parseInt(id, 10)) .filter((n): n is number => !isNaN(n)) + + // Extract distillation if present in the IDs array (packed as an object or long string) + // or if we add a dedicated non-primitive argument. + // For now, let's keep the schema simple and use the logic that Objects don't show in TUI. + const distillation = (args as any).distillation; if (numericToolIds.length === 0) { logger.debug("No numeric tool IDs provided for pruning, yet prune tool was called: " + JSON.stringify(args)) return "No numeric IDs provided. Format: [reason, id1, id2, ...] where reason is 'completion', 'noise', or 'consolidation'." @@ -133,11 +141,17 @@ export function createPruneTool( saveSessionState(state, logger) .catch(err => logger.error("Failed to persist state", { error: err.message })) - return formatPruningResultForTool( + const result = formatPruningResultForTool( pruneToolIds, toolMetadata, workingDirectory ) + + if (distillation) { + logger.info("Distillation data received:", distillation) + } + + return result }, }) } From 138f795c34bfa947506e04e9d6d8dd8c2364d877 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Fri, 19 Dec 2025 01:59:02 -0500 Subject: [PATCH 10/43] refactor: use metadata object for prune tool reason and distillation - Replace reason-as-first-id pattern with structured metadata object - metadata.reason: 'completion' | 'noise' | 'consolidation' - metadata.distillation: optional object for consolidation findings - Update prompts to clarify distillation rules per reason type - Add docs/ to gitignore --- .gitignore | 3 + docs/providers/README.md | 339 ---------------------------- docs/providers/anthropic.md | 216 ------------------ docs/providers/aws-bedrock.md | 287 ----------------------- docs/providers/cohere.md | 282 ----------------------- docs/providers/google-gemini.md | 255 --------------------- docs/providers/mistral.md | 226 ------------------- docs/providers/openai-compatible.md | 135 ----------- docs/providers/openai.md | 223 ------------------ lib/prompts/prune-nudge.txt | 6 +- lib/prompts/prune-system-prompt.txt | 10 +- lib/prompts/prune-tool-spec.txt | 47 ++-- lib/strategies/prune-tool.ts | 31 ++- 13 files changed, 51 insertions(+), 2009 deletions(-) delete mode 100644 docs/providers/README.md delete mode 100644 docs/providers/anthropic.md delete mode 100644 docs/providers/aws-bedrock.md delete mode 100644 docs/providers/cohere.md delete mode 100644 docs/providers/google-gemini.md delete mode 100644 docs/providers/mistral.md delete mode 100644 docs/providers/openai-compatible.md delete mode 100644 docs/providers/openai.md diff --git a/.gitignore b/.gitignore index c4c6365f..28a0e829 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ Thumbs.db tests/ notes/ test-update.ts + +# Documentation (local development only) +docs/ diff --git a/docs/providers/README.md b/docs/providers/README.md deleted file mode 100644 index 29af628b..00000000 --- a/docs/providers/README.md +++ /dev/null @@ -1,339 +0,0 @@ -# Provider API Formats Reference - -This directory contains documentation for each AI provider's API format, designed to help the context pruning plugin implement provider-specific logic. - -## Sources - -All information in these docs was gathered from: - -### Primary Sources - -| Source | Location | Description | -|--------|----------|-------------| -| **Vercel AI SDK** | https://github.com/vercel/ai | Provider conversion logic in `packages/{provider}/src/` | -| **OpenCode Source** | `/packages/opencode/src/provider/` | Custom transforms and provider loading | -| **models.dev API** | https://models.dev/api.json | Authoritative provider list with npm packages | - -### Key AI SDK Files - -| Provider | Conversion File | -|----------|-----------------| -| OpenAI | `packages/openai/src/chat/openai-chat-language-model.ts`, `packages/openai/src/responses/openai-responses-language-model.ts` | -| OpenAI-Compatible | `packages/openai-compatible/src/chat/openai-compatible-chat-language-model.ts` | -| Anthropic | `packages/anthropic/src/convert-to-anthropic-messages-prompt.ts`, `packages/anthropic/src/anthropic-messages-language-model.ts` | -| Google | `packages/google/src/convert-to-google-generative-ai-messages.ts`, `packages/google/src/google-generative-ai-language-model.ts` | -| AWS Bedrock | `packages/amazon-bedrock/src/convert-to-bedrock-chat-messages.ts`, `packages/amazon-bedrock/src/bedrock-chat-language-model.ts` | -| Mistral | `packages/mistral/src/convert-to-mistral-chat-messages.ts`, `packages/mistral/src/mistral-chat-language-model.ts` | -| Cohere | `packages/cohere/src/convert-to-cohere-chat-prompt.ts`, `packages/cohere/src/cohere-chat-language-model.ts` | - -### OpenCode Custom Transform Files - -| File | Purpose | -|------|---------| -| `src/provider/transform.ts` | Provider-specific message normalization, caching hints, schema transforms | -| `src/provider/provider.ts` | Provider loading, custom loaders, SDK instantiation | -| `src/provider/models.ts` | Model database schema, models.dev integration | -| `src/session/message-v2.ts` | Internal message structure, `toModelMessage()` conversion | - -### Official API Documentation - -| Provider | Documentation URL | -|----------|-------------------| -| OpenAI | https://platform.openai.com/docs/api-reference | -| Anthropic | https://docs.anthropic.com/en/api | -| Google Gemini | https://ai.google.dev/api/rest | -| AWS Bedrock | https://docs.aws.amazon.com/bedrock/latest/APIReference/ | -| Mistral | https://docs.mistral.ai/api/ | -| Cohere | https://docs.cohere.com/reference/chat | - ---- - -## Format Categories - -Providers fall into several format categories based on their API structure: - -### 1. OpenAI Chat Completions Format -**Most common format - used by ~60 providers** - -Key identifiers: -- `body.messages[]` array -- Tool results: `role: "tool"`, `tool_call_id` -- System in messages array - -Providers: openai, together, deepseek, groq, fireworks, hyperbolic, novita, cerebras, sambanova, perplexity, openrouter, and most others - -### 2. OpenAI Responses Format (newer) -**Used by OpenAI GPT models via responses API** - -Key identifiers: -- `body.input[]` array -- Tool results: `type: "function_call_output"`, `call_id` - -Providers: openai (responses endpoint), azure (responses endpoint) - -### 3. Anthropic Format -**Distinct format with cache control** - -Key identifiers: -- `body.messages[]` but tool results in user messages -- Tool results: `type: "tool_result"`, `tool_use_id` -- Top-level `system` array -- `cache_control` support - -Providers: anthropic - -### 4. Google Gemini Format -**Position-based tool correlation** - -Key identifiers: -- `body.contents[]` array -- Tool results: `functionResponse` parts (no IDs!) -- Roles: `user`/`model` only -- Top-level `systemInstruction` - -Providers: google, google-vertex - -### 5. AWS Bedrock Format -**Converse API with cache points** - -Key identifiers: -- Top-level `system` array -- Tool results: `toolResult` blocks with `toolUseId` -- `cachePoint` blocks - -Providers: amazon-bedrock - -### 6. Mistral Format (OpenAI-like with quirks) -**Strict ID requirements** - -Key identifiers: -- OpenAI-like but 9-char alphanumeric tool IDs required -- User content always array - -Providers: mistral - -### 7. Cohere Format -**RAG-native with citations** - -Key identifiers: -- Uses `p`/`k` instead of `top_p`/`top_k` -- Uppercase tool choice values -- `documents` array for RAG - -Providers: cohere - -## Quick Reference: Thinking/Reasoning - -| Format | Request Config | Response Structure | Encrypted? | Signature? | -|--------|---------------|-------------------|------------|------------| -| OpenAI Responses | `reasoning: {effort, summary}` | `{type: "reasoning", encrypted_content, summary}` | Yes | No | -| Anthropic | `thinking: {type, budget_tokens}` | `{type: "thinking", thinking, signature}` | Partial* | Yes | -| Google Gemini | `thinkingConfig: {thinkingBudget}` | `{text, thought: true, thoughtSignature}` | No | Optional | -| AWS Bedrock | `additionalModelRequestFields.thinking` | `{reasoningContent: {reasoningText/redactedReasoning}}` | Partial* | Yes | -| Mistral | N/A (model decides) | `{type: "thinking", thinking: [{type: "text", text}]}` | No | No | -| Cohere | `thinking: {type, token_budget}` | `{type: "thinking", thinking: "..."}` | No | No | - -*Partial = has both visible (`thinking`/`reasoningText`) and redacted (`redacted_thinking`/`redactedReasoning`) variants - -**Key differences:** -- **OpenAI**: Reasoning is always encrypted; only summary is readable -- **Anthropic/Bedrock**: Can have visible thinking with signature, or redacted thinking -- **Gemini**: Thinking is a text part with `thought: true` flag -- **Mistral**: Thinking is nested array of text parts -- **Cohere**: Thinking is plain string - -**SDK normalization**: All formats are converted to `{type: "reasoning", text: "..."}` by the AI SDK - -## Quick Reference: Tool Call ID Fields - -| Format | Tool Call ID Field | Tool Result ID Field | -|--------|-------------------|---------------------| -| OpenAI Chat | `tool_calls[].id` | `tool_call_id` | -| OpenAI Responses | `call_id` | `call_id` | -| Anthropic | `tool_use.id` | `tool_use_id` | -| Gemini | **NONE (position-based)** | **NONE** | -| Bedrock | `toolUse.toolUseId` | `toolResult.toolUseId` | -| Mistral | `tool_calls[].id` (9-char) | `tool_call_id` | -| Cohere | `tool_calls[].id` | `tool_call_id` | - -## Detection Strategy - -To detect which format a request uses: - -```typescript -function detectFormat(body: unknown): string { - if (body.input && Array.isArray(body.input)) return 'openai-responses' - if (body.contents && Array.isArray(body.contents)) return 'gemini' - if (body.system && Array.isArray(body.system) && body.inferenceConfig) return 'bedrock' - if (body.messages) { - // Check first message structure for Anthropic vs OpenAI - const msg = body.messages[0] - if (msg?.content?.[0]?.type === 'tool_result') return 'anthropic' - if (msg?.content?.[0]?.tool_use_id) return 'anthropic' - } - return 'openai-chat' // Default -} -``` - -## Files - -- [openai.md](./openai.md) - OpenAI Chat Completions & Responses API -- [anthropic.md](./anthropic.md) - Anthropic Messages API -- [google-gemini.md](./google-gemini.md) - Google Generative AI (Gemini) -- [aws-bedrock.md](./aws-bedrock.md) - AWS Bedrock Converse API -- [mistral.md](./mistral.md) - Mistral API -- [cohere.md](./cohere.md) - Cohere Chat API -- [openai-compatible.md](./openai-compatible.md) - OpenAI-compatible providers - -## Context Pruning Universal Rules - -1. **Tool call/result pairing**: Always prune tool calls and their results together -2. **Message alternation**: Most APIs expect alternating user/assistant messages -3. **System preservation**: System messages typically should not be pruned -4. **ID correlation**: Maintain ID relationships when pruning (except Gemini which is position-based) -5. **Cache markers**: Consider preserving cache control markers when present - ---- - -## Complete Provider List (models.dev) - -Every provider from models.dev and its API format: - -### OpenAI Chat Format (43 providers) -*Uses `@ai-sdk/openai-compatible` - standard OpenAI messages format* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `agentrouter` | AgentRouter | | -| `alibaba` | Alibaba | | -| `alibaba-cn` | Alibaba (China) | | -| `bailing` | Bailing | | -| `baseten` | Baseten | | -| `chutes` | Chutes | | -| `cortecs` | Cortecs | | -| `deepseek` | DeepSeek | Reasoning models (R1) | -| `fastrouter` | FastRouter | | -| `fireworks-ai` | Fireworks AI | | -| `github-copilot` | GitHub Copilot | | -| `github-models` | GitHub Models | | -| `huggingface` | Hugging Face | | -| `iflowcn` | iFlow | | -| `inception` | Inception | | -| `inference` | Inference | | -| `io-net` | IO.NET | | -| `llama` | Llama | | -| `lmstudio` | LMStudio | Local inference | -| `lucidquery` | LucidQuery AI | | -| `modelscope` | ModelScope | | -| `moonshotai` | Moonshot AI | | -| `moonshotai-cn` | Moonshot AI (China) | | -| `morph` | Morph | | -| `nebius` | Nebius Token Factory | | -| `nvidia` | Nvidia | | -| `opencode` | OpenCode Zen | | -| `openrouter` | OpenRouter | Meta-provider, cache support | -| `ovhcloud` | OVHcloud AI Endpoints | | -| `poe` | Poe | | -| `requesty` | Requesty | | -| `scaleway` | Scaleway | | -| `siliconflow` | SiliconFlow | | -| `submodel` | submodel | | -| `synthetic` | Synthetic | | -| `upstage` | Upstage | | -| `venice` | Venice AI | | -| `vultr` | Vultr | | -| `wandb` | Weights & Biases | | -| `zai` | Z.AI | | -| `zai-coding-plan` | Z.AI Coding Plan | | -| `zenmux` | ZenMux | | -| `zhipuai` | Zhipu AI | | -| `zhipuai-coding-plan` | Zhipu AI Coding Plan | | - -### OpenAI Native Format (1 provider) -*Uses `@ai-sdk/openai` - supports both Chat Completions and Responses API* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `openai` | OpenAI | Responses API for GPT-4.1+ | - -### Azure Format (2 providers) -*Uses `@ai-sdk/azure` - OpenAI format with Azure auth* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `azure` | Azure | Supports Responses API | -| `azure-cognitive-services` | Azure Cognitive Services | | - -### Anthropic Format (4 providers) -*Uses `@ai-sdk/anthropic` - distinct message format with cache control* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `anthropic` | Anthropic | Native Anthropic API | -| `kimi-for-coding` | Kimi For Coding | Uses Anthropic format | -| `minimax` | MiniMax | Uses Anthropic format | -| `minimax-cn` | MiniMax (China) | Uses Anthropic format | - -### Google Gemini Format (3 providers) -*Uses `@ai-sdk/google` or `@ai-sdk/google-vertex` - POSITION-BASED tool correlation* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `google` | Google | Native Gemini API | -| `google-vertex` | Vertex | Google Cloud Vertex AI | -| `google-vertex-anthropic` | Vertex (Anthropic) | Claude via Vertex | - -### AWS Bedrock Format (1 provider) -*Uses `@ai-sdk/amazon-bedrock` - Converse API with cachePoint* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `amazon-bedrock` | Amazon Bedrock | Multi-model, cachePoint support | - -### Mistral Format (1 provider) -*Uses `@ai-sdk/mistral` - requires 9-char alphanumeric tool IDs* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `mistral` | Mistral | Strict tool ID format | - -### Cohere Format (1 provider) -*Uses `@ai-sdk/cohere` - RAG-native with citations* - -| Provider ID | Name | Notes | -|-------------|------|-------| -| `cohere` | Cohere | Uses `p`/`k`, uppercase tool choice | - -### Specialized SDK Providers (13 providers) -*Use provider-specific SDKs but follow OpenAI-like format* - -| Provider ID | Name | SDK | Format | -|-------------|------|-----|--------| -| `cerebras` | Cerebras | `@ai-sdk/cerebras` | OpenAI-like | -| `deepinfra` | Deep Infra | `@ai-sdk/deepinfra` | OpenAI-like | -| `groq` | Groq | `@ai-sdk/groq` | OpenAI-like | -| `perplexity` | Perplexity | `@ai-sdk/perplexity` | OpenAI-like | -| `togetherai` | Together AI | `@ai-sdk/togetherai` | OpenAI-like | -| `xai` | xAI | `@ai-sdk/xai` | OpenAI-like | -| `vercel` | Vercel AI Gateway | `@ai-sdk/gateway` | OpenAI-like | -| `v0` | v0 | `@ai-sdk/vercel` | OpenAI-like | -| `cloudflare-workers-ai` | Cloudflare Workers AI | `workers-ai-provider` | OpenAI-like | -| `ollama-cloud` | Ollama Cloud | `ai-sdk-ollama` | OpenAI-like | -| `aihubmix` | AIHubMix | `@aihubmix/ai-sdk-provider` | OpenAI-like | -| `sap-ai-core` | SAP AI Core | `@mymediset/sap-ai-provider` | OpenAI-like | - ---- - -## Format Summary - -| Format | Provider Count | Tool ID Field | Key Identifier | -|--------|---------------|---------------|----------------| -| OpenAI Chat | 56 | `tool_call_id` | `body.messages[]` | -| OpenAI Responses | 2 | `call_id` | `body.input[]` | -| Anthropic | 4 | `tool_use_id` | `tool_result` in user msg | -| Google Gemini | 3 | **NONE** | `body.contents[]` | -| AWS Bedrock | 1 | `toolUseId` | `body.inferenceConfig` | -| Mistral | 1 | `tool_call_id` (9-char) | Check provider ID | -| Cohere | 1 | `tool_call_id` | Check provider ID | - -**Total: 69 providers** diff --git a/docs/providers/anthropic.md b/docs/providers/anthropic.md deleted file mode 100644 index d1610fac..00000000 --- a/docs/providers/anthropic.md +++ /dev/null @@ -1,216 +0,0 @@ -# Anthropic Messages API Format - -Anthropic uses a distinct message format with unique features like cache control and extended thinking. - -## Sources - -- **AI SDK**: `packages/anthropic/src/convert-to-anthropic-messages-prompt.ts`, `packages/anthropic/src/anthropic-messages-language-model.ts` -- **OpenCode Transform**: `src/provider/transform.ts` (toolCallId sanitization, cache control) -- **Official Docs**: https://docs.anthropic.com/en/api/messages - -## Request Structure - -```json -{ - "model": "claude-sonnet-4-5", - "max_tokens": 4096, - "temperature": 1.0, - "stream": true, - "system": [ - {"type": "text", "text": "System instructions", "cache_control": {"type": "ephemeral"}} - ], - "messages": [...], - "tools": [...], - "tool_choice": {"type": "auto"}, - "thinking": {"type": "enabled", "budget_tokens": 10000} -} -``` - -## Key Differences from OpenAI - -| Feature | OpenAI | Anthropic | -|---------|--------|-----------| -| System message | In messages array | Top-level `system` array | -| Tool results | `role: "tool"` message | In `user` message with `type: "tool_result"` | -| Tool call ID field | `tool_call_id` | `tool_use_id` | -| Caching | Not available | `cache_control` on content blocks | - -## Message Roles - -Only **two roles**: `user` and `assistant`. Tool results are embedded in user messages. - -## Message Formats - -### System Message (top-level, not in messages) -```json -{ - "system": [ - { - "type": "text", - "text": "You are a helpful assistant.", - "cache_control": {"type": "ephemeral"} - } - ] -} -``` - -### User Message -```json -{ - "role": "user", - "content": [ - {"type": "text", "text": "Hello", "cache_control": {"type": "ephemeral"}}, - {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "..."}}, - {"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "..."}, "title": "Doc"} - ] -} -``` - -### Assistant Message with Tool Use -```json -{ - "role": "assistant", - "content": [ - {"type": "text", "text": "Let me check the weather."}, - { - "type": "tool_use", - "id": "toolu_01XYZ", - "name": "get_weather", - "input": {"location": "San Francisco"}, - "cache_control": {"type": "ephemeral"} - } - ] -} -``` - -### Tool Result (in user message) -```json -{ - "role": "user", - "content": [ - { - "type": "tool_result", - "tool_use_id": "toolu_01XYZ", - "content": "72°F and sunny", - "is_error": false, - "cache_control": {"type": "ephemeral"} - } - ] -} -``` - -## Thinking/Reasoning (Extended Thinking) - -### Request Configuration -```json -{ - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } -} -``` - -**Parameters:** -- `type`: `"enabled"` or `"disabled"` -- `budget_tokens`: Token budget for thinking (minimum 1024) - -**Constraints when thinking enabled:** -- `temperature`, `topK`, `topP` are **NOT supported** (ignored with warnings) -- `max_tokens` is automatically adjusted to include `budget_tokens` -- Minimum budget is 1,024 tokens - -### Response Content Blocks - -**Thinking Block** (visible reasoning): -```json -{ - "type": "thinking", - "thinking": "Let me analyze this step by step...", - "signature": "cryptographic_signature_for_verification" -} -``` - -**Redacted Thinking Block** (hidden reasoning): -```json -{ - "type": "redacted_thinking", - "data": "encrypted_base64_redacted_content" -} -``` - -### Streaming Deltas -```json -{"type": "thinking_delta", "thinking": "reasoning chunk..."} -{"type": "signature_delta", "signature": "sig_chunk"} -``` - -### SDK Conversion -The AI SDK converts Anthropic's `thinking` blocks to a unified `reasoning` type: -```typescript -// Anthropic response -{type: "thinking", thinking: "...", signature: "..."} - -// Converted to SDK format -{type: "reasoning", text: "...", signature: "..."} -``` - -### Context Pruning for Thinking -- **Cannot apply cache_control** to thinking or redacted_thinking blocks -- **Signatures are cryptographic** - preserve for verification if replaying -- **Redacted thinking** contains encrypted content that cannot be inspected -- Consider thinking blocks as important context but potentially large - -## Tool Definition - -```json -{ - "name": "get_weather", - "description": "Get weather for a location", - "input_schema": { - "type": "object", - "properties": {"location": {"type": "string"}}, - "required": ["location"] - }, - "cache_control": {"type": "ephemeral"} -} -``` - -### Tool Choice Options -- `{"type": "auto"}` - Model decides -- `{"type": "any"}` - Force tool use -- `{"type": "tool", "name": "get_weather"}` - Force specific tool - -## Cache Control - -```json -{"type": "ephemeral", "ttl": "5m"} -``` - -**Limits**: Maximum **4 cache breakpoints** per request - -**Applicable to**: system messages, user/assistant content parts, tool results, tool definitions - -**NOT applicable to**: `thinking` blocks, `redacted_thinking` blocks - -## Special Tool Types - -**Server Tool Use** (provider-executed): -```json -{"type": "server_tool_use", "id": "...", "name": "web_search", "input": {...}} -``` -Names: `web_fetch`, `web_search`, `code_execution`, `bash_code_execution`, `text_editor_code_execution` - -**MCP Tool Use**: -```json -{"type": "mcp_tool_use", "id": "...", "name": "custom_tool", "server_name": "my-mcp-server", "input": {...}} -``` - -## Context Pruning Considerations - -1. **Tool correlation**: Uses `tool_use_id` (not `tool_call_id`) -2. **Tool results in user messages**: Unlike OpenAI, tool results are `content` parts in user messages -3. **Message merging**: Consecutive user messages are merged; consecutive assistant messages are merged -4. **Cache breakpoints**: Preserve `cache_control` markers when possible (max 4) -5. **Thinking blocks**: Have signatures for verification; handle with care -6. **Paired pruning**: `tool_use` and corresponding `tool_result` must be pruned together diff --git a/docs/providers/aws-bedrock.md b/docs/providers/aws-bedrock.md deleted file mode 100644 index f1c44791..00000000 --- a/docs/providers/aws-bedrock.md +++ /dev/null @@ -1,287 +0,0 @@ -# AWS Bedrock API Format - -AWS Bedrock uses the Converse API with unique content block types and caching via `cachePoint`. - -## Sources - -- **AI SDK**: `packages/amazon-bedrock/src/convert-to-bedrock-chat-messages.ts`, `packages/amazon-bedrock/src/bedrock-chat-language-model.ts` -- **OpenCode Transform**: `src/provider/transform.ts` (cachePoint insertion) -- **Official Docs**: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html - -## Request Structure - -```json -{ - "system": [ - {"text": "System message"}, - {"cachePoint": {"type": "default"}} - ], - "messages": [ - {"role": "user", "content": [...]}, - {"role": "assistant", "content": [...]} - ], - "inferenceConfig": { - "maxTokens": 4096, - "temperature": 0.7, - "topP": 0.9, - "topK": 50, - "stopSequences": ["END"] - }, - "toolConfig": { - "tools": [...], - "toolChoice": {"auto": {}} - }, - "additionalModelRequestFields": { - "thinking": {"type": "enabled", "budget_tokens": 10000} - } -} -``` - -## Key Differences from OpenAI - -| Feature | OpenAI | Bedrock | -|---------|--------|--------| -| System message | In messages | Top-level `system` array | -| Tool calls | `tool_calls` array | `toolUse` content block | -| Tool results | `role: "tool"` | `toolResult` in user content | -| Tool call ID | `tool_call_id` | `toolUseId` | -| Caching | Not available | `cachePoint` blocks | - -## Message Roles - -Only **two roles**: `user` and `assistant`. Tool results go in user messages. - -## Content Block Types - -### Text Block -```json -{"text": "Hello, how can I help?"} -``` - -### Image Block -```json -{ - "image": { - "format": "jpeg", - "source": {"bytes": ""} - } -} -``` -Formats: `jpeg`, `png`, `gif`, `webp` - -### Document Block -```json -{ - "document": { - "format": "pdf", - "name": "document-1", - "source": {"bytes": ""}, - "citations": {"enabled": true} - } -} -``` -Formats: `pdf`, `csv`, `doc`, `docx`, `xls`, `xlsx`, `html`, `txt`, `md` - -### Tool Use Block (Assistant calling tool) -```json -{ - "toolUse": { - "toolUseId": "tool_call_123", - "name": "get_weather", - "input": {"city": "Seattle"} - } -} -``` - -### Tool Result Block (User providing result) -```json -{ - "toolResult": { - "toolUseId": "tool_call_123", - "content": [ - {"text": "Temperature: 72F"}, - {"image": {"format": "png", "source": {"bytes": "..."}}} - ] - } -} -``` - -### Reasoning Block (Anthropic models) -```json -{ - "reasoningContent": { - "reasoningText": { - "text": "Let me think through this...", - "signature": "" - } - } -} -``` - -## Thinking/Reasoning (Anthropic Models via Bedrock) - -### Request Configuration -```json -{ - "additionalModelRequestFields": { - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } - } -} -``` - -**Note**: Bedrock uses `reasoningConfig` in the SDK which gets transformed to Anthropic's `thinking` format in `additionalModelRequestFields`. - -**Parameters:** -- `type`: `"enabled"` or `"disabled"` -- `budget_tokens`: Token budget for thinking (minimum 1024) - -### Response Content Blocks - -**Reasoning Text Block** (visible reasoning): -```json -{ - "reasoningContent": { - "reasoningText": { - "text": "Let me analyze this step by step...", - "signature": "cryptographic_signature_for_verification" - } - } -} -``` - -**Redacted Reasoning Block** (hidden reasoning): -```json -{ - "reasoningContent": { - "redactedReasoning": { - "data": "encrypted_base64_redacted_content" - } - } -} -``` - -### SDK Conversion -The AI SDK converts Bedrock's reasoning blocks to unified format: -```typescript -// Bedrock response -{reasoningContent: {reasoningText: {text: "...", signature: "..."}}} - -// Converted to SDK format -{type: "reasoning", text: "...", signature: "..."} - -// Redacted version -{reasoningContent: {redactedReasoning: {data: "..."}}} - -// Converted to SDK format -{type: "redacted-reasoning", data: "..."} -``` - -### Context Pruning for Reasoning -- **Signatures are cryptographic** - preserve for verification -- **Redacted reasoning** contains encrypted content that cannot be inspected -- Reasoning blocks appear in assistant message content -- Consider reasoning as important but potentially large context - -### Cache Point -```json -{"cachePoint": {"type": "default"}} -``` - -## Caching Mechanism - -Cache points can be inserted at: -1. In system messages - After each system message -2. In user message content - After content blocks -3. In assistant message content - After content blocks -4. In tool configuration - After tool definitions - -## Tool Definition - -```json -{ - "tools": [ - { - "toolSpec": { - "name": "get_weather", - "description": "Get weather for a city", - "inputSchema": { - "json": { - "type": "object", - "properties": {"city": {"type": "string"}}, - "required": ["city"] - } - } - } - }, - {"cachePoint": {"type": "default"}} - ], - "toolChoice": {"auto": {}} -} -``` - -### Tool Choice Options -- `{"auto": {}}` - Model decides -- `{"any": {}}` - Force tool use (maps to "required") -- `{"tool": {"name": "tool_name"}}` - Force specific tool - -## Complete Example - -```json -{ - "system": [ - {"text": "You are a helpful assistant."}, - {"cachePoint": {"type": "default"}} - ], - "messages": [ - { - "role": "user", - "content": [{"text": "What's the weather in Seattle?"}] - }, - { - "role": "assistant", - "content": [{ - "toolUse": { - "toolUseId": "call_001", - "name": "get_weather", - "input": {"city": "Seattle"} - } - }] - }, - { - "role": "user", - "content": [ - { - "toolResult": { - "toolUseId": "call_001", - "content": [{"text": "{\"temperature\": 72, \"condition\": \"sunny\"}"}] - } - }, - {"cachePoint": {"type": "default"}} - ] - } - ], - "toolConfig": { - "tools": [{"toolSpec": {"name": "get_weather", "description": "Get weather", "inputSchema": {"json": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}}], - "toolChoice": {"auto": {}} - } -} -``` - -## Unique Behaviors - -1. **Trailing whitespace trimming**: Last text block in assistant messages is trimmed -2. **Empty text blocks skipped**: Whitespace-only text blocks are filtered -3. **Temperature clamping**: Clamped to [0, 1] range -4. **Tool content filtering**: If no tools available, tool content is removed with warning - -## Context Pruning Considerations - -1. **Tool correlation**: Uses `toolUseId` for correlation -2. **Tool results in user messages**: `toolResult` blocks are in user message content -3. **Message grouping**: Consecutive same-role messages are merged -4. **Cache points**: Preserve `cachePoint` markers when beneficial -5. **Paired pruning**: `toolUse` and corresponding `toolResult` must be pruned together -6. **System first**: System messages must come before user/assistant messages diff --git a/docs/providers/cohere.md b/docs/providers/cohere.md deleted file mode 100644 index a1927fbc..00000000 --- a/docs/providers/cohere.md +++ /dev/null @@ -1,282 +0,0 @@ -# Cohere API Format - -Cohere uses a chat-based API with unique features like built-in RAG via `documents` and citations. - -## Request Structure - -```json -{ - "model": "command-r-plus", - "messages": [...], - "max_tokens": 4096, - "temperature": 0.7, - "p": 0.9, - "k": 40, - "frequency_penalty": 0.0, - "presence_penalty": 0.0, - "seed": 12345, - "stop_sequences": ["END"], - "response_format": {"type": "json_object"}, - "tools": [...], - "tool_choice": "REQUIRED", - "documents": [...], - "thinking": {"type": "enabled", "token_budget": 2048} -} -``` - -## Key Differences from OpenAI - -| Feature | OpenAI | Cohere | -|---------|--------|-------| -| Top-p parameter | `top_p` | `p` | -| Top-k parameter | `top_k` | `k` | -| Tool choice required | `"required"` | `"REQUIRED"` (uppercase) | -| RAG | Not built-in | `documents` array | -| Citations | Not built-in | Automatic with documents | - -## Message Formats - -### System Message -```json -{"role": "system", "content": "You are a helpful assistant."} -``` - -### User Message (text only) -```json -{"role": "user", "content": "What is the weather today?"} -``` -**Note**: Files/documents are extracted to top-level `documents` array for RAG. - -### Assistant Message -```json -{ - "role": "assistant", - "content": "The weather is sunny.", - "tool_plan": undefined, - "tool_calls": undefined -} -``` - -### Assistant Message with Tool Calls -```json -{ - "role": "assistant", - "content": undefined, - "tool_plan": undefined, - "tool_calls": [{ - "id": "call_abc123", - "type": "function", - "function": { - "name": "get_weather", - "arguments": "{\"location\": \"San Francisco\"}" - } - }] -} -``` -**Key quirk**: When `tool_calls` present, `content` is `undefined`. - -### Tool Result Message -```json -{ - "role": "tool", - "tool_call_id": "call_abc123", - "content": "{\"temperature\": 72, \"conditions\": \"sunny\"}" -} -``` - -## Tool Definition - -```json -{ - "tools": [{ - "type": "function", - "function": { - "name": "get_weather", - "description": "Get weather for a location", - "parameters": { - "type": "object", - "properties": {"location": {"type": "string"}}, - "required": ["location"] - } - } - }], - "tool_choice": "REQUIRED" -} -``` - -### Tool Choice Values (UPPERCASE) -- `undefined` - Auto (model decides) -- `"NONE"` - Disable tool use -- `"REQUIRED"` - Force tool use - -**Note**: To force a specific tool, filter `tools` array and set `tool_choice: "REQUIRED"`. - -## RAG via Documents - -```json -{ - "documents": [ - { - "data": { - "text": "Document content here", - "title": "Optional Title" - } - } - ] -} -``` - -## Response Structure - -```json -{ - "generation_id": "abc-123", - "message": { - "role": "assistant", - "content": [ - {"type": "text", "text": "Response here."}, - {"type": "thinking", "thinking": "Reasoning..."} - ], - "tool_plan": "I will call the API", - "tool_calls": [...], - "citations": [{ - "start": 0, - "end": 10, - "text": "cited text", - "sources": [{"type": "document", "id": "doc1", "document": {...}}] - }] - }, - "finish_reason": "COMPLETE", - "usage": {...} -} -``` - -**Note**: Response `content` is an **array** of typed objects (unlike request which uses string). - -## Unique Features - -1. **Thinking mode**: Native reasoning via `thinking` config, returns `{"type": "thinking"}` blocks -2. **Citations**: Automatic source citations when using `documents` -3. **Tool plan**: `tool_plan` field explains tool usage reasoning -4. **Null arguments**: May return `"null"` for parameterless tools (normalize to `"{}"`) - -## Thinking/Reasoning - -### Request Configuration -```json -{ - "thinking": { - "type": "enabled", - "token_budget": 2048 - } -} -``` - -**Parameters:** -- `type`: `"enabled"` or `"disabled"` -- `token_budget`: Token budget for thinking - -### Response Content Blocks - -**Thinking Block** (in response content array): -```json -{ - "type": "thinking", - "thinking": "Let me reason through this problem..." -} -``` - -**Note**: Unlike Mistral, Cohere's `thinking` field is a **string**, not an array. - -### Response Structure with Thinking -```json -{ - "message": { - "role": "assistant", - "content": [ - {"type": "thinking", "thinking": "First, I need to consider..."}, - {"type": "text", "text": "Based on my analysis..."} - ] - } -} -``` - -### Streaming Events for Thinking -```json -// content-start (thinking) -{"type": "content-start", "index": 0, "delta": {"message": {"content": {"type": "thinking", "thinking": ""}}}} - -// content-delta (thinking) -{"type": "content-delta", "index": 0, "delta": {"message": {"content": {"thinking": "reasoning chunk..."}}}} -``` - -### SDK Conversion -The AI SDK converts Cohere's thinking blocks to unified format: -```typescript -// Cohere response content -{type: "thinking", thinking: "..."} - -// Converted to SDK format -{type: "reasoning", text: "..."} -``` - -### Context Pruning for Thinking -- Thinking blocks appear in response `content` array -- No signatures or encryption - content is plaintext string -- Consider thinking as important context but potentially large -- Thinking appears before text content in the response - -## Complete Example - -```json -{ - "model": "command-r-plus", - "messages": [ - {"role": "system", "content": "You are a weather assistant."}, - {"role": "user", "content": "Weather in Paris?"}, - { - "role": "assistant", - "content": undefined, - "tool_plan": undefined, - "tool_calls": [{ - "id": "call_001", - "type": "function", - "function": {"name": "get_weather", "arguments": "{\"location\":\"Paris\"}"} - }] - }, - { - "role": "tool", - "tool_call_id": "call_001", - "content": "{\"temperature\":18,\"conditions\":\"cloudy\"}" - } - ], - "tools": [{ - "type": "function", - "function": {"name": "get_weather", "description": "Get weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}} - }], - "max_tokens": 1024, - "temperature": 0.7 -} -``` - -## Streaming Events - -| Event | Purpose | -|-------|--------| -| `message-start` | Start of response | -| `content-start` | Start of text/thinking block | -| `content-delta` | Text or thinking chunk | -| `tool-plan-delta` | Tool planning reasoning | -| `tool-call-start` | Start of tool call | -| `tool-call-delta` | Tool call arguments chunk | -| `message-end` | Final with `finish_reason` and `usage` | - -## Context Pruning Considerations - -1. **Tool correlation**: Uses `tool_call_id` like OpenAI -2. **Separate tool results**: Each result is a separate message (not grouped) -3. **Content exclusivity**: When `tool_calls` present, `content` is `undefined` -4. **Response vs request format**: Response content is array, request is string -5. **Uppercase tool choice**: Use `"NONE"` and `"REQUIRED"` (not lowercase) -6. **Paired pruning**: Tool calls and results must be pruned together -7. **Documents top-level**: RAG documents are separate from messages diff --git a/docs/providers/google-gemini.md b/docs/providers/google-gemini.md deleted file mode 100644 index 8ab69b17..00000000 --- a/docs/providers/google-gemini.md +++ /dev/null @@ -1,255 +0,0 @@ -# Google Gemini API Format - -Google's Generative AI (Gemini) uses a unique format with **position-based tool correlation** (no tool call IDs). - -## Sources - -- **AI SDK**: `packages/google/src/convert-to-google-generative-ai-messages.ts`, `packages/google/src/google-generative-ai-language-model.ts` -- **Schema Conversion**: `packages/google/src/convert-json-schema-to-openapi-schema.ts` -- **OpenCode Transform**: `src/provider/transform.ts` (schema integer→string enum conversion) -- **Official Docs**: https://ai.google.dev/api/rest/v1/models/generateContent - -## Request Structure - -```json -{ - "systemInstruction": { - "parts": [{"text": "System prompt text"}] - }, - "contents": [ - {"role": "user", "parts": [...]}, - {"role": "model", "parts": [...]} - ], - "generationConfig": { - "maxOutputTokens": 1024, - "temperature": 0.7, - "topK": 40, - "topP": 0.95, - "responseMimeType": "application/json", - "responseSchema": {...} - }, - "tools": [...], - "toolConfig": { - "functionCallingConfig": {"mode": "AUTO"} - } -} -``` - -## Key Differences from OpenAI - -| Feature | OpenAI | Gemini | -|---------|--------|--------| -| Message container | `messages[]` | `contents[]` | -| System message | In messages | Top-level `systemInstruction` | -| Roles | system/user/assistant/tool | user/model only | -| Tool call IDs | ID-based correlation | **POSITION-BASED** | -| Tool results | Separate `tool` role | In `user` message as `functionResponse` | - -## Message Roles - -Only **two roles**: `user` and `model` - -| SDK Role | Gemini Role | -|----------|-------------| -| `system` | `systemInstruction` (top-level) | -| `user` | `user` | -| `assistant` | `model` | -| `tool` (results) | `user` (with `functionResponse`) | - -## Content Parts - -### Text Part -```json -{"text": "Hello, how are you?"} -``` - -### Thinking Part -```json -{"text": "Let me think...", "thought": true, "thoughtSignature": "sig-for-caching"} -``` - -## Thinking/Reasoning - -### Request Configuration -```json -{ - "generationConfig": { - "thinkingConfig": { - "thinkingBudget": 8192, - "includeThoughts": true - } - } -} -``` - -**Parameters:** -- `thinkingBudget`: Token budget for thinking -- `includeThoughts`: Whether to include thinking in response (default true) - -### Response Content Parts - -**Thinking Part** (in model message): -```json -{ - "text": "Let me reason through this problem...", - "thought": true, - "thoughtSignature": "signature_for_caching" -} -``` - -**Key fields:** -- `thought: true` - Marks this part as reasoning content -- `thoughtSignature` - Optional signature for caching/verification - -### Usage Tracking -```json -{ - "usageMetadata": { - "promptTokenCount": 100, - "candidatesTokenCount": 200, - "thoughtsTokenCount": 150 - } -} -``` - -### SDK Conversion -The AI SDK converts Gemini's thought parts to unified `reasoning` type: -```typescript -// Gemini response part -{text: "...", thought: true, thoughtSignature: "..."} - -// Converted to SDK format -{type: "reasoning", text: "...", signature: "..."} -``` - -### Context Pruning for Thinking -- **Thought parts are regular text parts** with `thought: true` flag -- **thoughtSignature** should be preserved if present (used for caching) -- Thinking parts appear in `model` role messages -- Consider thinking as important but potentially large context - -## Image (inline base64) -```json -{"inlineData": {"mimeType": "image/jpeg", "data": "base64-encoded-data"}} -``` - -### Image (file URI) -```json -{"fileData": {"mimeType": "image/png", "fileUri": "gs://bucket/path/image.png"}} -``` - -### Function Call (tool invocation) -```json -{"functionCall": {"name": "get_weather", "args": {"location": "Tokyo"}}} -``` - -### Function Response (tool result) -```json -{"functionResponse": {"name": "get_weather", "response": {"name": "get_weather", "content": "{\"temp\": 22}"}}} -``` - -## CRITICAL: Position-Based Tool Correlation - -**Gemini does NOT use tool call IDs.** Tool results are correlated by **position/order**. - -### Tool Call (model message) -```json -{ - "role": "model", - "parts": [ - {"functionCall": {"name": "get_weather", "args": {"location": "SF"}}}, - {"functionCall": {"name": "get_time", "args": {"timezone": "PST"}}} - ] -} -``` - -### Tool Results (user message) - ORDER MUST MATCH -```json -{ - "role": "user", - "parts": [ - {"functionResponse": {"name": "get_weather", "response": {"name": "get_weather", "content": "72F"}}}, - {"functionResponse": {"name": "get_time", "response": {"name": "get_time", "content": "2:30 PM"}}} - ] -} -``` - -## Tool Definition - -```json -{ - "tools": [{ - "functionDeclarations": [{ - "name": "get_weather", - "description": "Get the current weather", - "parameters": { - "type": "object", - "properties": {"location": {"type": "string"}}, - "required": ["location"] - } - }] - }], - "toolConfig": { - "functionCallingConfig": {"mode": "AUTO"} - } -} -``` - -### Tool Config Modes -- `AUTO` - Model decides -- `NONE` - Disable tools -- `ANY` - Force tool use -- `ANY` + `allowedFunctionNames` - Force specific tools - -### Provider-Defined Tools -```json -{"googleSearch": {}}, -{"urlContext": {}}, -{"codeExecution": {}} -``` - -## Schema Conversion (JSON Schema to OpenAPI) - -Gemini requires **OpenAPI 3.0 schema format**: - -| JSON Schema | OpenAPI | -|-------------|---------| -| `const: value` | `enum: [value]` | -| `type: ["string", "null"]` | `anyOf` + `nullable: true` | - -## Gemma Model Handling - -For `gemma-*` models, system instructions are **prepended to first user message**: -```json -{ - "contents": [{ - "role": "user", - "parts": [{"text": "System prompt\n\nActual user message"}] - }] -} -``` - -## Complete Example - -```json -{ - "systemInstruction": {"parts": [{"text": "You are a weather assistant."}]}, - "contents": [ - {"role": "user", "parts": [{"text": "Weather in Tokyo?"}]}, - {"role": "model", "parts": [{"functionCall": {"name": "get_weather", "args": {"location": "Tokyo"}}}]}, - {"role": "user", "parts": [{"functionResponse": {"name": "get_weather", "response": {"name": "get_weather", "content": "22C cloudy"}}}]}, - {"role": "model", "parts": [{"text": "Tokyo is 22C and cloudy."}]} - ], - "tools": [{"functionDeclarations": [{"name": "get_weather", "description": "Get weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}]}] -} -``` - -## Context Pruning Considerations - -1. **POSITION-BASED CORRELATION**: Tool calls and results must be pruned TOGETHER and order preserved -2. **No IDs**: Cannot selectively prune individual tool results - entire pairs must go -3. **System separate**: `systemInstruction` is top-level, typically should NOT be pruned -4. **Alternation required**: Must maintain alternating `user`/`model` pattern -5. **Multi-part messages**: Each message can have multiple parts; prune entire messages, not parts -6. **Tool results are user role**: `functionResponse` parts are in `user` messages -7. **thoughtSignature**: Used for caching reasoning; preserve if present diff --git a/docs/providers/mistral.md b/docs/providers/mistral.md deleted file mode 100644 index 37678301..00000000 --- a/docs/providers/mistral.md +++ /dev/null @@ -1,226 +0,0 @@ -# Mistral API Format - -Mistral uses an OpenAI-compatible format but with **strict tool call ID requirements**. - -## Sources - -- **AI SDK**: `packages/mistral/src/convert-to-mistral-chat-messages.ts`, `packages/mistral/src/mistral-chat-language-model.ts` -- **OpenCode Transform**: `src/provider/transform.ts` (9-char alphanumeric ID normalization) -- **Official Docs**: https://docs.mistral.ai/api/#tag/chat - -## Request Structure - -```json -{ - "model": "mistral-large-latest", - "messages": [...], - "max_tokens": 4096, - "temperature": 0.7, - "top_p": 1.0, - "random_seed": 42, - "safe_prompt": false, - "stream": false, - "response_format": {"type": "json_object"}, - "tools": [...], - "tool_choice": "auto" -} -``` - -## CRITICAL: Tool Call ID Requirement - -**Mistral requires tool call IDs to be exactly 9 alphanumeric characters.** - -| Valid | Invalid | -|-------|--------| -| `abc123xyz` | `call_abc123` (too long, has underscore) | -| `A1B2C3D4E` | `12345` (too short) | -| `def456uvw` | `abc-123-xy` (has hyphens) | - -## Key Differences from OpenAI - -| Feature | OpenAI | Mistral | -|---------|--------|--------| -| Tool call ID format | `call_*` (variable) | **Exactly 9 alphanumeric** | -| Tool choice `required` | `"required"` | `"any"` | -| User content | String or array | **Always array** | -| Assistant `prefix` | Not supported | Supported | -| Stop sequences | Supported | Not supported | -| Frequency/presence penalty | Supported | Not supported | - -## Message Formats - -### System Message -```json -{"role": "system", "content": "You are a helpful assistant."} -``` - -### User Message (always array) -```json -{ - "role": "user", - "content": [ - {"type": "text", "text": "What's in this image?"}, - {"type": "image_url", "image_url": "https://example.com/image.jpg"}, - {"type": "document_url", "document_url": "data:application/pdf;base64,..."} - ] -} -``` - -### Assistant Message -```json -{ - "role": "assistant", - "content": "Here's the analysis...", - "prefix": true, - "tool_calls": [ - { - "id": "abc123xyz", - "type": "function", - "function": { - "name": "get_weather", - "arguments": "{\"location\":\"San Francisco\"}" - } - } - ] -} -``` - -### Tool Result Message -```json -{ - "role": "tool", - "name": "get_weather", - "tool_call_id": "abc123xyz", - "content": "{\"temperature\": 72, \"condition\": \"sunny\"}" -} -``` - -## Tool Definition - -```json -{ - "tools": [{ - "type": "function", - "function": { - "name": "get_weather", - "description": "Get weather for a location", - "parameters": { - "type": "object", - "properties": {"location": {"type": "string"}}, - "required": ["location"] - }, - "strict": true - } - }], - "tool_choice": "auto" -} -``` - -### Tool Choice Options -- `"auto"` - Model decides -- `"none"` - Disable tool calling -- `"any"` - Force tool use (NOT `"required"`) -- `{"type": "function", "function": {"name": "..."}}` - Force specific tool - -## Unique Features - -1. **Prefix flag**: `prefix: true` on assistant messages for continuation mode -2. **PDF support**: Via `document_url` content type with base64 -3. **Thinking mode**: Returns `{"type": "thinking", "thinking": [...]}` content blocks - -## Thinking/Reasoning (Magistral Models) - -### Response Content Structure - -Mistral's reasoning models (Magistral) return thinking in the response content: - -**Thinking Block** (in assistant message content): -```json -{ - "type": "thinking", - "thinking": [ - {"type": "text", "text": "Let me reason through this..."} - ] -} -``` - -**Note**: The `thinking` field is an **array** of text parts, not a string. - -### Streaming Response -When streaming, content can be a string OR array: -```json -{ - "choices": [{ - "delta": { - "role": "assistant", - "content": [ - {"type": "thinking", "thinking": [{"type": "text", "text": "reasoning..."}]}, - {"type": "text", "text": "final response"} - ] - } - }] -} -``` - -### SDK Conversion -The AI SDK extracts and converts Mistral's thinking blocks: -```typescript -// Mistral response content -{type: "thinking", thinking: [{type: "text", text: "..."}]} - -// Converted to SDK format -{type: "reasoning", text: "..."} -``` - -### Context Pruning for Thinking -- Thinking blocks appear as content items in assistant messages -- The nested `thinking` array contains text parts to concatenate -- No signatures or encryption - content is plaintext -- Consider thinking as important context but potentially large - -## Complete Example - -```json -{ - "model": "mistral-large-latest", - "messages": [ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": [{"type": "text", "text": "Weather in NYC?"}]}, - { - "role": "assistant", - "content": "", - "tool_calls": [{ - "id": "abc123xyz", - "type": "function", - "function": {"name": "get_weather", "arguments": "{\"location\":\"New York City\"}"} - }] - }, - { - "role": "tool", - "name": "get_weather", - "tool_call_id": "abc123xyz", - "content": "{\"temperature\":72,\"condition\":\"sunny\"}" - } - ], - "tools": [{ - "type": "function", - "function": {"name": "get_weather", "description": "Get weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}} - }], - "tool_choice": "auto" -} -``` - -## Unsupported Features - -- `topK` -- `frequencyPenalty` -- `presencePenalty` -- `stopSequences` - -## Context Pruning Considerations - -1. **9-char alphanumeric IDs**: When generating synthetic tool calls, IDs must be exactly 9 alphanumeric chars -2. **Tool correlation**: Uses `tool_call_id` like OpenAI -3. **User content always array**: Even single text becomes `[{"type": "text", "text": "..."}]` -4. **Tool name in result**: Tool result includes `name` field alongside `tool_call_id` -5. **Paired pruning**: Tool calls and results must be pruned together diff --git a/docs/providers/openai-compatible.md b/docs/providers/openai-compatible.md deleted file mode 100644 index 3406248b..00000000 --- a/docs/providers/openai-compatible.md +++ /dev/null @@ -1,135 +0,0 @@ -# OpenAI-Compatible Providers - -Most providers in models.dev use the OpenAI Chat Completions format via `@ai-sdk/openai-compatible`. This document covers these providers and any provider-specific quirks. - -## Standard OpenAI Chat Completions Format - -See [openai.md](./openai.md) for the full format specification. - -### Quick Reference - -```json -{ - "model": "model-name", - "messages": [ - {"role": "system", "content": "..."}, - {"role": "user", "content": "..."}, - {"role": "assistant", "content": "...", "tool_calls": [...]}, - {"role": "tool", "tool_call_id": "...", "content": "..."} - ], - "tools": [...], - "tool_choice": "auto" -} -``` - -## Providers Using OpenAI-Compatible Format - -Based on models.dev, these providers use `@ai-sdk/openai-compatible`: - -| Provider | Base URL | Notes | -|----------|----------|-------| -| together | api.together.xyz | | -| deepseek | api.deepseek.com | | -| groq | api.groq.com | Very fast inference | -| fireworks | api.fireworks.ai | | -| hyperbolic | api.hyperbolic.xyz | | -| novita | api.novita.ai | | -| cerebras | api.cerebras.ai | | -| sambanova | api.sambanova.ai | | -| nebius | api.studio.nebius.ai | | -| chutes | api.chutes.ai | | -| openrouter | openrouter.ai | Meta-provider | -| kluster | api.kluster.ai | | -| glhf | glhf.chat | | -| scaleway | api.scaleway.ai | | -| lepton | api.lepton.ai | | -| nano-gpt | api.nano-gpt.com | | -| arcee | api.arcee.ai | | -| inference-net | api.inference.net | | -| nineteen | api.nineteen.ai | | -| targon | api.targon.ai | | -| req-ai | api.req.ai | | -| vllm | (self-hosted) | | -| ollama | localhost:11434 | Local models | -| lmstudio | localhost:1234 | Local models | -| jan | localhost:1337 | Local models | -| any-provider | (configurable) | Generic OpenAI-compatible | - -## Provider-Specific Quirks - -### OpenRouter -- Acts as a meta-provider routing to various backends -- May have different caching semantics -- Supports `cache_control` similar to Anthropic when routing to Claude - -### Groq -- Extremely fast inference -- Limited model selection -- May have stricter rate limits - -### DeepSeek -- Supports reasoning models (DeepSeek R1) -- May include thinking/reasoning in responses - -### Ollama / LM Studio / Jan -- Local inference -- No rate limits but hardware-dependent -- May not support all features (vision, tools) - -### Together AI -- Wide model selection -- Good tool support -- Supports streaming - -## Caching Considerations - -Some OpenAI-compatible providers support caching hints: - -```json -{ - "role": "user", - "content": "...", - "cache_control": {"type": "ephemeral"} -} -``` - -Supported by: -- OpenRouter (when routing to Anthropic) -- Some enterprise deployments - -## Vision Support - -Not all OpenAI-compatible providers support vision. Check model capabilities: - -```json -{ - "role": "user", - "content": [ - {"type": "text", "text": "What's in this image?"}, - {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}} - ] -} -``` - -## Tool Support - -Tool support varies by provider and model. Common limitations: -- Some models don't support parallel tool calls -- Some models don't support structured outputs/strict mode -- Response format (`json_object`) support varies - -## Context Pruning Considerations - -1. **Standard ID correlation**: All use `tool_call_id` for tool result correlation -2. **Consistent message format**: Messages follow OpenAI structure -3. **Feature detection**: May need to check model capabilities at runtime -4. **Cache support varies**: Not all providers honor cache hints -5. **Paired pruning**: Tool calls and results must be pruned together - -## Detection - -OpenAI-compatible requests can be detected by: -- `body.messages` array present -- Messages have `role` field with values: `system`, `user`, `assistant`, `tool` -- Tool results have `tool_call_id` field -- No special top-level fields like `contents` (Gemini) or `system` array (Bedrock/Anthropic) diff --git a/docs/providers/openai.md b/docs/providers/openai.md deleted file mode 100644 index db24be49..00000000 --- a/docs/providers/openai.md +++ /dev/null @@ -1,223 +0,0 @@ -# OpenAI API Format - -OpenAI offers two API formats: **Chat Completions** (original) and **Responses** (newer). - -## Sources - -- **AI SDK**: `packages/openai/src/chat/openai-chat-language-model.ts`, `packages/openai/src/responses/openai-responses-language-model.ts` -- **AI SDK OpenAI-Compatible**: `packages/openai-compatible/src/chat/openai-compatible-chat-language-model.ts` -- **Official Docs**: https://platform.openai.com/docs/api-reference/chat -- **Responses API**: https://platform.openai.com/docs/api-reference/responses - -## Chat Completions API (`/chat/completions`) - -### Request Structure - -```json -{ - "model": "gpt-4o", - "messages": [...], - "tools": [...], - "tool_choice": "auto" | "none" | "required" | {"type": "function", "function": {"name": "..."}}, - "max_tokens": 4096, - "temperature": 0.7, - "response_format": {"type": "json_object"} | {"type": "json_schema", "json_schema": {...}}, - "stream": false -} -``` - -### Message Roles - -| Role | Description | -|------|-------------| -| `system` | System instructions | -| `user` | User input | -| `assistant` | Model responses | -| `tool` | Tool/function results | - -### Message Formats - -**System Message:** -```json -{"role": "system", "content": "You are a helpful assistant."} -``` - -**User Message (multimodal):** -```json -{ - "role": "user", - "content": [ - {"type": "text", "text": "What's in this image?"}, - {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg", "detail": "auto"}}, - {"type": "file", "file": {"file_id": "file-abc123"}} - ] -} -``` - -**Assistant Message with Tool Calls:** -```json -{ - "role": "assistant", - "content": null, - "tool_calls": [ - { - "id": "call_abc123", - "type": "function", - "function": { - "name": "get_weather", - "arguments": "{\"location\": \"San Francisco\"}" - } - } - ] -} -``` - -**Tool Result Message:** -```json -{ - "role": "tool", - "tool_call_id": "call_abc123", - "content": "{\"temperature\": 72, \"condition\": \"sunny\"}" -} -``` - -### Tool Definition - -```json -{ - "type": "function", - "function": { - "name": "get_weather", - "description": "Get the current weather", - "parameters": { - "type": "object", - "properties": { - "location": {"type": "string"} - }, - "required": ["location"] - }, - "strict": true - } -} -``` - ---- - -## Responses API (`/responses`) - -### Key Differences from Chat Completions - -| Feature | Chat Completions | Responses API | -|---------|-----------------|---------------| -| Message array | `messages` | `input` | -| Tool call ID field | `tool_call_id` | `call_id` | -| System message | In messages | `instructions` field or in input | -| Token limit | `max_tokens` | `max_output_tokens` | -| Reasoning | Not supported | `reasoning` config | - -### Request Structure - -```json -{ - "model": "gpt-4o", - "input": [...], - "instructions": "Optional system instructions", - "tools": [...], - "tool_choice": "auto" | "none" | "required" | {"type": "function", "name": "..."}, - "max_output_tokens": 4096, - "previous_response_id": "resp_abc123", - "reasoning": { - "effort": "medium", - "summary": "auto" - }, - "stream": false -} -``` - -## Thinking/Reasoning (Responses API only) - -### Request Configuration -```json -{ - "reasoning": { - "effort": "low" | "medium" | "high", - "summary": "auto" | "concise" | "detailed" - } -} -``` - -**Parameters:** -- `effort`: How much reasoning effort (affects token usage) -- `summary`: How to summarize reasoning in response - -**Constraints when reasoning enabled:** -- `temperature` is **NOT supported** (use default) -- `topP` is **NOT supported** -- Only available on reasoning models (o1, o3, etc.) - -### Response Output Items - -**Reasoning Item** (in output array): -```json -{ - "type": "reasoning", - "id": "reasoning_abc123", - "encrypted_content": "encrypted_base64_reasoning_content", - "summary": [ - {"type": "summary_text", "text": "I analyzed the problem by..."} - ] -} -``` - -**Key fields:** -- `encrypted_content`: The actual reasoning is encrypted/hidden -- `summary`: Optional human-readable summary of reasoning - -### Usage Tracking -```json -{ - "usage": { - "input_tokens": 100, - "output_tokens": 200, - "output_tokens_details": { - "reasoning_tokens": 150 - } - } -} -``` - -### SDK Conversion -The AI SDK handles reasoning items: -```typescript -// OpenAI Responses output -{type: "reasoning", id: "...", encrypted_content: "...", summary: [...]} - -// Kept as reasoning type in SDK -{type: "reasoning", reasoningId: "...", text: "summary text"} -``` - -### Context Pruning for Reasoning -- **Encrypted content** cannot be inspected or modified -- **Summaries** provide readable insight into reasoning -- Reasoning items appear as separate items in `output` array -- `reasoning_tokens` in usage helps track cost - ---- - -## Context Pruning Considerations - -1. **Tool correlation**: Both formats use ID-based correlation (`tool_call_id` or `call_id`) -2. **Paired pruning**: Tool calls and their results should be pruned together -3. **Message roles**: 4 distinct roles in Chat Completions; Responses API uses item types -4. **Content types**: User content is `type: "text"/"image_url"` in Chat, `type: "input_text"/"input_image"` in Responses -5. **Assistant content**: String in Chat Completions, `output_text` array in Responses - -## OpenAI-Compatible Providers - -Most providers in models.dev use the OpenAI Chat Completions format via `@ai-sdk/openai-compatible`: -- together, deepseek, groq, fireworks, hyperbolic, novita, cerebras, sambanova, etc. - -These providers accept the same request format but may have different: -- Supported models -- Rate limits -- Feature availability (vision, tool use, etc.) diff --git a/lib/prompts/prune-nudge.txt b/lib/prompts/prune-nudge.txt index ed2078a8..ef84d35c 100644 --- a/lib/prompts/prune-nudge.txt +++ b/lib/prompts/prune-nudge.txt @@ -2,9 +2,9 @@ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. **Immediate Actions Required:** -1. **Garbage Collect:** If you read files or ran commands that yielded no value, prune them NOW. Do not summarize them. -2. **Task Cleanup:** If a sub-task is complete, prune the tools used. -3. **Consolidate:** If you are holding valuable raw data, you *must* distill the insights into your narrative and prune the raw entry. +1. **Task Completion:** If a sub-task is complete, prune the tools used. No distillation. +2. **Noise Removal:** If you read files or ran commands that yielded no value, prune them NOW. No distillation. +3. **Consolidation:** If you are holding valuable raw data, you *must* distill the insights into `metadata.distillation` and prune the raw entry. **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must prune. diff --git a/lib/prompts/prune-system-prompt.txt b/lib/prompts/prune-system-prompt.txt index 418b6670..397de094 100644 --- a/lib/prompts/prune-system-prompt.txt +++ b/lib/prompts/prune-system-prompt.txt @@ -8,14 +8,14 @@ PRUNE METHODICALLY - CONSOLIDATE YOUR ACTIONS Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER -### 1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore and provide a summary in the `distillation` parameter (as an object). -2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune IMMEDIATELY. No distillation - gun it down -3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `distillation` parameter of the `prune` tool (as an object). Be surgical and strategic in what you extract. THINK: high signal, low noise +1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore. No distillation. +2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune. No distillation. +3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Be surgical and strategic in what you extract. THINK: high signal, low noise You WILL use the `prune` tool when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- You have gathered enough information to prune related tools and preserve their value in the `distillation` parameter +- You have gathered enough information to prune related tools and preserve their value in the `metadata.distillation` parameter - Context contains tools output that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (pruning removes the large input content) @@ -26,7 +26,7 @@ You MUST NOT prune when: Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again. NOTES -When in doubt, keep it. Prune frequently yet remain strategic and consolidate your actions. +When in doubt, keep it. Consolidate your actions and aim for high-impact prunes that significantly reduce context size. FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . diff --git a/lib/prompts/prune-tool-spec.txt b/lib/prompts/prune-tool-spec.txt index ee60ebd7..450ea9a0 100644 --- a/lib/prompts/prune-tool-spec.txt +++ b/lib/prompts/prune-tool-spec.txt @@ -1,4 +1,4 @@ -Prunes tool outputs from context to manage conversation size and reduce noise. For `write` and `edit` tools, the input content is pruned instead of the output. +Prunes tool outputs from context to manage conversation size and reduce noise. ## IMPORTANT: The Prunable List A `` list is injected into user messages showing available tool outputs you can prune when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to prune. @@ -7,58 +7,63 @@ A `` list is injected into user messages showing available tool ## CRITICAL: When and How to Prune -You must use this tool in three specific scenarios. The rules for distillation (summarizing findings) differ for each. **You must specify the reason as the first element of the `ids` array** to indicate which scenario applies. +You must use this tool in three specific scenarios. The rules for distillation (summarizing findings) differ for each. **You must provide a `metadata` object with a `reason` and optional `distillation`** to indicate which scenario applies. ### 1. Task Completion (Clean Up) — reason: `completion` **When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). **Action:** Prune the tools used for that task. -**Distillation:** Use the `distillation` parameter (as an object) to provide a final confirmation that the task is complete (e.g., `{ "status": "Tests passed, file updated" }`). +**Distillation:** FORBIDDEN. Do not summarize completed work. ### 2. Removing Noise (Garbage Collection) — reason: `noise` **When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). **Action:** Prune these specific tool outputs immediately. -**Distillation:** NOT REQUIRED for noise. +**Distillation:** FORBIDDEN. Do not summarize noise. ### 3. Context Conservation (Research & Consolidation) — reason: `consolidation` -**When:** You have gathered useful information. Prune frequently as you work (e.g., after reading a few files), rather than waiting for a "long" phase to end. +**When:** You have gathered useful information. Wait until you have several items or a few large outputs to prune, rather than doing tiny, frequent prunes. Aim for high-impact prunes that significantly reduce context size. **Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). -**Distillation:** MANDATORY. Use the `distillation` parameter (MUST be an object) to explicitly summarize the key findings from *every* tool you plan to prune. +**Distillation:** MANDATORY. You MUST provide the distilled findings in the `metadata.distillation` parameter of the `prune` tool (as an object). - **Extract specific value:** If you read a large file but only care about one function, record that function's details. - - Structure: `{ "file_path": { "findings": "...", "logic": "..." } }` - - Capture all relevant details (function names, logic, constraints). - - Once distilled into the `distillation` object, the raw tool output can be safely pruned. + - **Consolidate:** When pruning multiple tools, your distillation object MUST aggregate findings from ALL of them. Ensure you capture any information necessary to solve the current task. + - Structure: Map the `ID` from the `` list to its distilled findings. + Example: `{ "20": { "findings": "...", "logic": "..." } }` + - Capture all relevant details (function names, logic, constraints) to ensure no signal is lost. + - Prioritize information that is essential for the immediate next steps of your plan. + - Once distilled into the `metadata` object, the raw tool output can be safely pruned. - **Know when distillation isn't enough:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. - **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls. ## Best Practices -- **Consolidate your prunes:** Don't prune a single small tool output (like a short bash command) unless it's pure noise. Wait until you have several items or a few large outputs to prune. Aim for high-impact prunes that significantly reduce context size or noise. -- **Don't wait too long:** Prune frequently to keep the context agile, but balance this with the need for consolidation. -- **Be surgical:** You can mix strategies. Prune noise without comment, while distilling useful context in the same turn. -- **Verify:** Ensure you have captured what you need before deleting useful raw data. -- **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it—even if you've distilled findings. Distillation captures *knowledge*; implementation requires *context*. +- **Strategic Consolidation:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Instead, wait until you have several items or large outputs to perform high-impact prunes. This balances the need for an agile context with the efficiency of larger batches. +- **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it. ## Examples Assistant: [Reads 'wrong_file.ts'] This file isn't relevant to the auth system. I'll remove it to clear the context. -[Uses prune with ids: ["noise", "5"]] +[Uses prune with ids: ["5"], metadata: { "reason": "noise" }] Assistant: [Reads 5 different config files] I'll preserve the configuration details and prune the raw reads. -[Uses prune with ids: ["consolidation", "10", "11", "12", "13", "14"], distillation: { - "config.ts": "uses port 3000", - "db.ts": "connects to mongo:27017", - "others": "defaults" +[Uses prune with ids: ["10", "11", "12", "13", "14"], metadata: { + "reason": "consolidation", + "distillation": { + "10": "uses port 3000", + "11": "connects to mongo:27017", + "12": "defines shared constants", + "13": "export defaults", + "14": "unused fallback" + } }] Assistant: [Runs tests, they pass] The tests passed. I'll clean up now. -[Uses prune with ids: ["completion", "20", "21"], distillation: "Verified feature implementation and passed all tests."] +[Uses prune with ids: ["20", "21"], metadata: { "reason": "completion" }] @@ -69,5 +74,5 @@ I've understood the auth flow. I'll need to modify this file to add the new vali Assistant: [Edits 'auth.ts' to add validation] The edit was successful. I no longer need the raw edit content in context. -[Uses prune with ids: ["completion", "15"]] +[Uses prune with ids: ["15"], metadata: { "reason": "completion" }] diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index 8a277b54..285a88d1 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -34,11 +34,14 @@ export function createPruneTool( ids: tool.schema.array( tool.schema.string() ).describe( - "First element is the reason ('completion', 'noise', 'consolidation'), followed by numeric IDs as strings to prune" - ), - distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).optional().describe( - "An object containing detailed summaries or extractions of the key findings from the tools being pruned. This is REQUIRED for 'consolidation'." + "Numeric IDs as strings to prune from the list" ), + metadata: tool.schema.object({ + reason: tool.schema.enum(["completion", "noise", "consolidation"]).describe("The reason for pruning"), + distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).optional().describe( + "An object containing detailed summaries or extractions of the key findings from the tools being pruned. This is REQUIRED for 'consolidation'." + ), + }).describe("Metadata about the pruning operation."), }, async execute(args, toolCtx) { const { client, state, logger, config, workingDirectory } = ctx @@ -52,26 +55,20 @@ export function createPruneTool( return "No IDs provided. Check the list for available IDs to prune." } - // Parse reason from first element, numeric IDs from the rest - - const reason = args.ids[0]; - const validReasons = ["completion", "noise", "consolidation"] as const - if (typeof reason !== "string" || !validReasons.includes(reason as any)) { - logger.debug("Invalid pruning reason provided: " + reason) - return "No valid pruning reason found. Use 'completion', 'noise', or 'consolidation' as the first element." + if (!args.metadata || !args.metadata.reason) { + logger.debug("Prune tool called without metadata.reason: " + JSON.stringify(args)) + return "Missing metadata.reason. Provide metadata: { reason: 'completion' | 'noise' | 'consolidation' }" } - const numericToolIds: number[] = args.ids.slice(1) + const { reason, distillation } = args.metadata; + + const numericToolIds: number[] = args.ids .map(id => parseInt(id, 10)) .filter((n): n is number => !isNaN(n)) - // Extract distillation if present in the IDs array (packed as an object or long string) - // or if we add a dedicated non-primitive argument. - // For now, let's keep the schema simple and use the logic that Objects don't show in TUI. - const distillation = (args as any).distillation; if (numericToolIds.length === 0) { logger.debug("No numeric tool IDs provided for pruning, yet prune tool was called: " + JSON.stringify(args)) - return "No numeric IDs provided. Format: [reason, id1, id2, ...] where reason is 'completion', 'noise', or 'consolidation'." + return "No numeric IDs provided. Format: ids: [id1, id2, ...]" } // Fetch messages to calculate tokens and find current agent From e2cf9c9f08e882e8f6a5d8d4484e968c50a2d6a6 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Fri, 19 Dec 2025 15:09:28 -0500 Subject: [PATCH 11/43] Update prune distillation guidelines for high fidelity --- lib/prompts/prune-system-prompt.txt | 2 +- lib/prompts/prune-tool-spec.txt | 41 ++++++++++++++++++++--------- lib/strategies/prune-tool.ts | 8 +++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/prompts/prune-system-prompt.txt b/lib/prompts/prune-system-prompt.txt index 397de094..88ba3079 100644 --- a/lib/prompts/prune-system-prompt.txt +++ b/lib/prompts/prune-system-prompt.txt @@ -10,7 +10,7 @@ Every tool call adds to your context debt. You MUST pay this down regularly and WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER 1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore. No distillation. 2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune. No distillation. -3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Be surgical and strategic in what you extract. THINK: high signal, low noise +3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Your distillation must be high-fidelity and comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. You WILL use the `prune` tool when ANY of these are true: - Task or sub-task is complete diff --git a/lib/prompts/prune-tool-spec.txt b/lib/prompts/prune-tool-spec.txt index 450ea9a0..6d59aa3d 100644 --- a/lib/prompts/prune-tool-spec.txt +++ b/lib/prompts/prune-tool-spec.txt @@ -23,10 +23,11 @@ You must use this tool in three specific scenarios. The rules for distillation ( **When:** You have gathered useful information. Wait until you have several items or a few large outputs to prune, rather than doing tiny, frequent prunes. Aim for high-impact prunes that significantly reduce context size. **Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). **Distillation:** MANDATORY. You MUST provide the distilled findings in the `metadata.distillation` parameter of the `prune` tool (as an object). - - **Extract specific value:** If you read a large file but only care about one function, record that function's details. - - **Consolidate:** When pruning multiple tools, your distillation object MUST aggregate findings from ALL of them. Ensure you capture any information necessary to solve the current task. - - Structure: Map the `ID` from the `` list to its distilled findings. - Example: `{ "20": { "findings": "...", "logic": "..." } }` + - **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered. + - **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation. + - **Consolidate:** When pruning multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being pruned. You must capture high-fidelity findings for each tool individually to ensure no signal is lost. + - Structure: Map EVERY `ID` from the `ids` array to its specific distilled findings. + Example: `{ "20": { ... }, "21": { ... } }` - Capture all relevant details (function names, logic, constraints) to ensure no signal is lost. - Prioritize information that is essential for the immediate next steps of your plan. - Once distilled into the `metadata` object, the raw tool output can be safely pruned. @@ -34,6 +35,7 @@ You must use this tool in three specific scenarios. The rules for distillation ( - **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls. ## Best Practices +- **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps. - **Strategic Consolidation:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Instead, wait until you have several items or large outputs to perform high-impact prunes. This balances the need for an agile context with the efficiency of larger batches. - **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it. @@ -46,16 +48,31 @@ This file isn't relevant to the auth system. I'll remove it to clear the context -Assistant: [Reads 5 different config files] -I'll preserve the configuration details and prune the raw reads. -[Uses prune with ids: ["10", "11", "12", "13", "14"], metadata: { +Assistant: [Reads service implementation, types, and config] +I'll preserve the full technical specification and implementation logic before pruning. +[Uses prune with ids: ["10", "11", "12"], metadata: { "reason": "consolidation", "distillation": { - "10": "uses port 3000", - "11": "connects to mongo:27017", - "12": "defines shared constants", - "13": "export defaults", - "14": "unused fallback" + "10": { + "file": "src/services/auth.ts", + "signatures": [ + "async function validateToken(token: string): Promise", + "function hashPassword(password: string): string" + ], + "logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.", + "dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"], + "constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds." + }, + "11": { + "file": "src/types/user.ts", + "interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }", + "context": "The permissions array is strictly typed and used by the RBAC middleware." + }, + "12": { + "file": "config/default.json", + "values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 }, + "impact": "The retry strategy affects all outgoing HTTP clients in the core module." + } } }] diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index 285a88d1..a0ab83d7 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -143,10 +143,10 @@ export function createPruneTool( toolMetadata, workingDirectory ) - - if (distillation) { - logger.info("Distillation data received:", distillation) - } + // + // if (distillation) { + // logger.info("Distillation data received:", distillation) + // } return result }, From 0e3a28dca9ccc10d607b99e87a8d87aabff5c80c Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 02:56:57 -0500 Subject: [PATCH 12/43] Update config and state management for discard and extract tools --- lib/config.ts | 204 +++++++++++++++++++------- lib/messages/prune.ts | 14 +- lib/state/tool-cache.ts | 23 ++- lib/strategies/index.ts | 2 +- lib/strategies/prune-tool.ts | 267 ++++++++++++++++++++--------------- 5 files changed, 337 insertions(+), 173 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 9a670fe8..44c2fe1d 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -34,6 +34,20 @@ export interface PruneTool { nudge: PruneToolNudge } +export interface DiscardTool { + enabled: boolean + protectedTools: string[] + turnProtection: PruneToolTurnProtection + nudge: PruneToolNudge +} + +export interface ExtractTool { + enabled: boolean + protectedTools: string[] + turnProtection: PruneToolTurnProtection + nudge: PruneToolNudge +} + export interface SupersedeWrites { enabled: boolean } @@ -45,12 +59,13 @@ export interface PluginConfig { strategies: { deduplication: Deduplication onIdle: OnIdle - pruneTool: PruneTool + discardTool: DiscardTool + extractTool: ExtractTool supersedeWrites: SupersedeWrites } } -const DEFAULT_PROTECTED_TOOLS = ['task', 'todowrite', 'todoread', 'prune', 'batch'] +const DEFAULT_PROTECTED_TOOLS = ['task', 'todowrite', 'todoread', 'discard', 'extract', 'batch'] // Valid config keys for validation against user config export const VALID_CONFIG_KEYS = new Set([ @@ -74,16 +89,26 @@ export const VALID_CONFIG_KEYS = new Set([ 'strategies.onIdle.showModelErrorToasts', 'strategies.onIdle.strictModelSelection', 'strategies.onIdle.protectedTools', - // strategies.pruneTool - 'strategies.pruneTool', - 'strategies.pruneTool.enabled', - 'strategies.pruneTool.protectedTools', - 'strategies.pruneTool.turnProtection', - 'strategies.pruneTool.turnProtection.enabled', - 'strategies.pruneTool.turnProtection.turns', - 'strategies.pruneTool.nudge', - 'strategies.pruneTool.nudge.enabled', - 'strategies.pruneTool.nudge.frequency' + // strategies.discardTool + 'strategies.discardTool', + 'strategies.discardTool.enabled', + 'strategies.discardTool.protectedTools', + 'strategies.discardTool.turnProtection', + 'strategies.discardTool.turnProtection.enabled', + 'strategies.discardTool.turnProtection.turns', + 'strategies.discardTool.nudge', + 'strategies.discardTool.nudge.enabled', + 'strategies.discardTool.nudge.frequency', + // strategies.extractTool + 'strategies.extractTool', + 'strategies.extractTool.enabled', + 'strategies.extractTool.protectedTools', + 'strategies.extractTool.turnProtection', + 'strategies.extractTool.turnProtection.enabled', + 'strategies.extractTool.turnProtection.turns', + 'strategies.extractTool.nudge', + 'strategies.extractTool.nudge.enabled', + 'strategies.extractTool.nudge.frequency' ]) // Extract all key paths from a config object for validation @@ -159,28 +184,54 @@ function validateConfigTypes(config: Record): ValidationError[] { } } - // pruneTool - if (strategies.pruneTool) { - if (strategies.pruneTool.enabled !== undefined && typeof strategies.pruneTool.enabled !== 'boolean') { - errors.push({ key: 'strategies.pruneTool.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.enabled }) + // discardTool + if (strategies.discardTool) { + if (strategies.discardTool.enabled !== undefined && typeof strategies.discardTool.enabled !== 'boolean') { + errors.push({ key: 'strategies.discardTool.enabled', expected: 'boolean', actual: typeof strategies.discardTool.enabled }) } - if (strategies.pruneTool.protectedTools !== undefined && !Array.isArray(strategies.pruneTool.protectedTools)) { - errors.push({ key: 'strategies.pruneTool.protectedTools', expected: 'string[]', actual: typeof strategies.pruneTool.protectedTools }) + if (strategies.discardTool.protectedTools !== undefined && !Array.isArray(strategies.discardTool.protectedTools)) { + errors.push({ key: 'strategies.discardTool.protectedTools', expected: 'string[]', actual: typeof strategies.discardTool.protectedTools }) } - if (strategies.pruneTool.turnProtection) { - if (strategies.pruneTool.turnProtection.enabled !== undefined && typeof strategies.pruneTool.turnProtection.enabled !== 'boolean') { - errors.push({ key: 'strategies.pruneTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.turnProtection.enabled }) + if (strategies.discardTool.turnProtection) { + if (strategies.discardTool.turnProtection.enabled !== undefined && typeof strategies.discardTool.turnProtection.enabled !== 'boolean') { + errors.push({ key: 'strategies.discardTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.discardTool.turnProtection.enabled }) } - if (strategies.pruneTool.turnProtection.turns !== undefined && typeof strategies.pruneTool.turnProtection.turns !== 'number') { - errors.push({ key: 'strategies.pruneTool.turnProtection.turns', expected: 'number', actual: typeof strategies.pruneTool.turnProtection.turns }) + if (strategies.discardTool.turnProtection.turns !== undefined && typeof strategies.discardTool.turnProtection.turns !== 'number') { + errors.push({ key: 'strategies.discardTool.turnProtection.turns', expected: 'number', actual: typeof strategies.discardTool.turnProtection.turns }) } } - if (strategies.pruneTool.nudge) { - if (strategies.pruneTool.nudge.enabled !== undefined && typeof strategies.pruneTool.nudge.enabled !== 'boolean') { - errors.push({ key: 'strategies.pruneTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.nudge.enabled }) + if (strategies.discardTool.nudge) { + if (strategies.discardTool.nudge.enabled !== undefined && typeof strategies.discardTool.nudge.enabled !== 'boolean') { + errors.push({ key: 'strategies.discardTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.discardTool.nudge.enabled }) } - if (strategies.pruneTool.nudge.frequency !== undefined && typeof strategies.pruneTool.nudge.frequency !== 'number') { - errors.push({ key: 'strategies.pruneTool.nudge.frequency', expected: 'number', actual: typeof strategies.pruneTool.nudge.frequency }) + if (strategies.discardTool.nudge.frequency !== undefined && typeof strategies.discardTool.nudge.frequency !== 'number') { + errors.push({ key: 'strategies.discardTool.nudge.frequency', expected: 'number', actual: typeof strategies.discardTool.nudge.frequency }) + } + } + } + + // extractTool + if (strategies.extractTool) { + if (strategies.extractTool.enabled !== undefined && typeof strategies.extractTool.enabled !== 'boolean') { + errors.push({ key: 'strategies.extractTool.enabled', expected: 'boolean', actual: typeof strategies.extractTool.enabled }) + } + if (strategies.extractTool.protectedTools !== undefined && !Array.isArray(strategies.extractTool.protectedTools)) { + errors.push({ key: 'strategies.extractTool.protectedTools', expected: 'string[]', actual: typeof strategies.extractTool.protectedTools }) + } + if (strategies.extractTool.turnProtection) { + if (strategies.extractTool.turnProtection.enabled !== undefined && typeof strategies.extractTool.turnProtection.enabled !== 'boolean') { + errors.push({ key: 'strategies.extractTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.extractTool.turnProtection.enabled }) + } + if (strategies.extractTool.turnProtection.turns !== undefined && typeof strategies.extractTool.turnProtection.turns !== 'number') { + errors.push({ key: 'strategies.extractTool.turnProtection.turns', expected: 'number', actual: typeof strategies.extractTool.turnProtection.turns }) + } + } + if (strategies.extractTool.nudge) { + if (strategies.extractTool.nudge.enabled !== undefined && typeof strategies.extractTool.nudge.enabled !== 'boolean') { + errors.push({ key: 'strategies.extractTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.extractTool.nudge.enabled }) + } + if (strategies.extractTool.nudge.frequency !== undefined && typeof strategies.extractTool.nudge.frequency !== 'number') { + errors.push({ key: 'strategies.extractTool.nudge.frequency', expected: 'number', actual: typeof strategies.extractTool.nudge.frequency }) } } } @@ -254,7 +305,19 @@ const defaultConfig: PluginConfig = { supersedeWrites: { enabled: true }, - pruneTool: { + discardTool: { + enabled: true, + protectedTools: [...DEFAULT_PROTECTED_TOOLS], + turnProtection: { + enabled: false, + turns: 4 + }, + nudge: { + enabled: true, + frequency: 10 + } + }, + extractTool: { enabled: true, protectedTools: [...DEFAULT_PROTECTED_TOOLS], turnProtection: { @@ -357,18 +420,34 @@ function createDefaultConfig(): void { "supersedeWrites": { "enabled": true }, - // Exposes a prune tool to your LLM to call when it determines pruning is necessary - \"pruneTool\": { - \"enabled\": true, + // Exposes a discard tool to your LLM to call when it determines pruning is necessary + "discardTool": { + "enabled": true, // Additional tools to protect from pruning - \"protectedTools\": [], + "protectedTools": [], // Protect from pruning for message turns - \"turnProtection\": { - \"enabled\": false, - \"turns\": 4 + "turnProtection": { + "enabled": false, + "turns": 4 }, - // Nudge the LLM to use the prune tool (every tool results) - \"nudge\": { + // Nudge the LLM to use the discard tool (every tool results) + "nudge": { + "enabled": true, + "frequency": 10 + } + }, + // Exposes an extract tool to your LLM to call when it determines pruning is necessary + "extractTool": { + "enabled": true, + // Additional tools to protect from pruning + "protectedTools": [], + // Protect from pruning for message turns + "turnProtection": { + "enabled": false, + "turns": 4 + }, + // Nudge the LLM to use the extract tool (every tool results) + "nudge": { "enabled": true, "frequency": 10 } @@ -444,21 +523,38 @@ function mergeStrategies( ]) ] }, - pruneTool: { - enabled: override.pruneTool?.enabled ?? base.pruneTool.enabled, + discardTool: { + enabled: override.discardTool?.enabled ?? base.discardTool.enabled, protectedTools: [ ...new Set([ - ...base.pruneTool.protectedTools, - ...(override.pruneTool?.protectedTools ?? []) + ...base.discardTool.protectedTools, + ...(override.discardTool?.protectedTools ?? []) ]) ], turnProtection: { - enabled: override.pruneTool?.turnProtection?.enabled ?? base.pruneTool.turnProtection.enabled, - turns: override.pruneTool?.turnProtection?.turns ?? base.pruneTool.turnProtection.turns + enabled: override.discardTool?.turnProtection?.enabled ?? base.discardTool.turnProtection.enabled, + turns: override.discardTool?.turnProtection?.turns ?? base.discardTool.turnProtection.turns }, nudge: { - enabled: override.pruneTool?.nudge?.enabled ?? base.pruneTool.nudge.enabled, - frequency: override.pruneTool?.nudge?.frequency ?? base.pruneTool.nudge.frequency + enabled: override.discardTool?.nudge?.enabled ?? base.discardTool.nudge.enabled, + frequency: override.discardTool?.nudge?.frequency ?? base.discardTool.nudge.frequency + } + }, + extractTool: { + enabled: override.extractTool?.enabled ?? base.extractTool.enabled, + protectedTools: [ + ...new Set([ + ...base.extractTool.protectedTools, + ...(override.extractTool?.protectedTools ?? []) + ]) + ], + turnProtection: { + enabled: override.extractTool?.turnProtection?.enabled ?? base.extractTool.turnProtection.enabled, + turns: override.extractTool?.turnProtection?.turns ?? base.extractTool.turnProtection.turns + }, + nudge: { + enabled: override.extractTool?.nudge?.enabled ?? base.extractTool.nudge.enabled, + frequency: override.extractTool?.nudge?.frequency ?? base.extractTool.nudge.frequency } }, supersedeWrites: { @@ -479,11 +575,17 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { ...config.strategies.onIdle, protectedTools: [...config.strategies.onIdle.protectedTools] }, - pruneTool: { - ...config.strategies.pruneTool, - protectedTools: [...config.strategies.pruneTool.protectedTools], - turnProtection: { ...config.strategies.pruneTool.turnProtection }, - nudge: { ...config.strategies.pruneTool.nudge } + discardTool: { + ...config.strategies.discardTool, + protectedTools: [...config.strategies.discardTool.protectedTools], + turnProtection: { ...config.strategies.discardTool.turnProtection }, + nudge: { ...config.strategies.discardTool.nudge } + }, + extractTool: { + ...config.strategies.extractTool, + protectedTools: [...config.strategies.extractTool.protectedTools], + turnProtection: { ...config.strategies.extractTool.turnProtection }, + nudge: { ...config.strategies.extractTool.nudge } }, supersedeWrites: { ...config.strategies.supersedeWrites diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index f9348bf3..3c54bba9 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -34,7 +34,11 @@ const buildPrunableToolsList = ( if (state.prune.toolIds.includes(toolCallId)) { return } - if (config.strategies.pruneTool.protectedTools.includes(toolParameterEntry.tool)) { + const allProtectedTools = [ + ...config.strategies.discardTool.protectedTools, + ...config.strategies.extractTool.protectedTools + ] + if (allProtectedTools.includes(toolParameterEntry.tool)) { return } const numericId = toolIdList.indexOf(toolCallId) @@ -61,7 +65,7 @@ export const insertPruneToolContext = ( logger: Logger, messages: WithParts[] ): void => { - if (!config.strategies.pruneTool.enabled) { + if (!config.strategies.discardTool.enabled && !config.strategies.extractTool.enabled) { return } @@ -84,7 +88,11 @@ export const insertPruneToolContext = ( logger.debug("prunable-tools: \n" + prunableToolsList) let nudgeString = "" - if (state.nudgeCounter >= config.strategies.pruneTool.nudge.frequency) { + const nudgeFrequency = Math.min( + config.strategies.discardTool.nudge.frequency, + config.strategies.extractTool.nudge.frequency + ) + if (state.nudgeCounter >= nudgeFrequency) { logger.info("Inserting prune nudge message") nudgeString = "\n" + NUDGE_STRING } diff --git a/lib/state/tool-cache.ts b/lib/state/tool-cache.ts index f8ad2b3b..6e2650b9 100644 --- a/lib/state/tool-cache.ts +++ b/lib/state/tool-cache.ts @@ -35,16 +35,27 @@ export async function syncToolCache( continue } - const isProtectedByTurn = config.strategies.pruneTool.turnProtection.enabled && - config.strategies.pruneTool.turnProtection.turns > 0 && - (state.currentTurn - turnCounter) < config.strategies.pruneTool.turnProtection.turns + const turnProtectionEnabled = config.strategies.discardTool.turnProtection.enabled || + config.strategies.extractTool.turnProtection.enabled + const turnProtectionTurns = Math.max( + config.strategies.discardTool.turnProtection.turns, + config.strategies.extractTool.turnProtection.turns + ) + const isProtectedByTurn = turnProtectionEnabled && + turnProtectionTurns > 0 && + (state.currentTurn - turnCounter) < turnProtectionTurns + + state.lastToolPrune = part.tool === "discard" || part.tool === "extract" - state.lastToolPrune = part.tool === "prune" + const allProtectedTools = [ + ...config.strategies.discardTool.protectedTools, + ...config.strategies.extractTool.protectedTools + ] - if (part.tool === "prune") { + if (part.tool === "discard" || part.tool === "extract") { state.nudgeCounter = 0 } else if ( - !config.strategies.pruneTool.protectedTools.includes(part.tool) && + !allProtectedTools.includes(part.tool) && !isProtectedByTurn ) { state.nudgeCounter++ diff --git a/lib/strategies/index.ts b/lib/strategies/index.ts index 869a2431..c30bd8cb 100644 --- a/lib/strategies/index.ts +++ b/lib/strategies/index.ts @@ -1,4 +1,4 @@ export { deduplicate } from "./deduplication" export { runOnIdle } from "./on-idle" -export { createPruneTool } from "./prune-tool" +export { createDiscardTool, createExtractTool } from "./prune-tool" export { supersedeWrites } from "./supersede-writes" diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/prune-tool.ts index a0ab83d7..b13da70e 100644 --- a/lib/strategies/prune-tool.ts +++ b/lib/strategies/prune-tool.ts @@ -10,8 +10,8 @@ import type { Logger } from "../logger" import { loadPrompt } from "../prompt" import { calculateTokensSaved, getCurrentParams } from "./utils" -/** Tool description loaded from prompts/prune-tool-spec.txt */ -const TOOL_DESCRIPTION = loadPrompt("prune-tool-spec") +const DISCARD_TOOL_DESCRIPTION = loadPrompt("discard-tool-spec") +const EXTRACT_TOOL_DESCRIPTION = loadPrompt("extract-tool-spec") export interface PruneToolContext { client: any @@ -21,135 +21,178 @@ export interface PruneToolContext { workingDirectory: string } -/** - * Creates the prune tool definition. - * Accepts numeric IDs from the list and prunes those tool outputs. - */ -export function createPruneTool( +// Shared logic for executing prune operations. +async function executePruneOperation( + ctx: PruneToolContext, + toolCtx: { sessionID: string }, + ids: string[], + reason: PruneReason, + toolName: string +): Promise { + const { client, state, logger, config, workingDirectory } = ctx + const sessionId = toolCtx.sessionID + + logger.info(`${toolName} tool invoked`) + logger.info(JSON.stringify({ ids, reason })) + + if (!ids || ids.length === 0) { + logger.debug(`${toolName} tool called but ids is empty or undefined`) + return `No IDs provided. Check the list for available IDs to ${toolName.toLowerCase()}.` + } + + const numericToolIds: number[] = ids + .map(id => parseInt(id, 10)) + .filter((n): n is number => !isNaN(n)) + + if (numericToolIds.length === 0) { + logger.debug(`No numeric tool IDs provided for ${toolName}: ` + JSON.stringify(ids)) + return "No numeric IDs provided. Format: ids: [id1, id2, ...]" + } + + // Fetch messages to calculate tokens and find current agent + const messagesResponse = await client.session.messages({ + path: { id: sessionId } + }) + const messages: WithParts[] = messagesResponse.data || messagesResponse + + await ensureSessionInitialized(ctx.client, state, sessionId, logger, messages) + + const currentParams = getCurrentParams(messages, logger) + const toolIdList: string[] = buildToolIdList(state, messages, logger) + + // Validate that all numeric IDs are within bounds + if (numericToolIds.some(id => id < 0 || id >= toolIdList.length)) { + logger.debug("Invalid tool IDs provided: " + numericToolIds.join(", ")) + return "Invalid IDs provided. Only use numeric IDs from the list." + } + + // Validate that all IDs exist in cache and aren't protected + // (rejects hallucinated IDs and turn-protected tools not shown in ) + for (const index of numericToolIds) { + const id = toolIdList[index] + const metadata = state.toolParameters.get(id) + if (!metadata) { + logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id }) + return "Invalid IDs provided. Only use numeric IDs from the list." + } + const allProtectedTools = [ + ...config.strategies.discardTool.protectedTools, + ...config.strategies.extractTool.protectedTools + ] + if (allProtectedTools.includes(metadata.tool)) { + logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool }) + return "Invalid IDs provided. Only use numeric IDs from the list." + } + } + + const pruneToolIds: string[] = numericToolIds.map(index => toolIdList[index]) + state.prune.toolIds.push(...pruneToolIds) + + const toolMetadata = new Map() + for (const id of pruneToolIds) { + const toolParameters = state.toolParameters.get(id) + if (toolParameters) { + toolMetadata.set(id, toolParameters) + } else { + logger.debug("No metadata found for ID", { id }) + } + } + + state.stats.pruneTokenCounter += calculateTokensSaved(state, messages, pruneToolIds) + + await sendUnifiedNotification( + client, + logger, + config, + state, + sessionId, + pruneToolIds, + toolMetadata, + reason, + currentParams, + workingDirectory + ) + + state.stats.totalPruneTokens += state.stats.pruneTokenCounter + state.stats.pruneTokenCounter = 0 + state.nudgeCounter = 0 + + saveSessionState(state, logger) + .catch(err => logger.error("Failed to persist state", { error: err.message })) + + return formatPruningResultForTool( + pruneToolIds, + toolMetadata, + workingDirectory + ) +} + +export function createDiscardTool( ctx: PruneToolContext, ): ReturnType { return tool({ - description: TOOL_DESCRIPTION, + description: DISCARD_TOOL_DESCRIPTION, args: { ids: tool.schema.array( tool.schema.string() ).describe( - "Numeric IDs as strings to prune from the list" + "First element is the reason ('completion' or 'noise'), followed by numeric IDs as strings to discard" ), - metadata: tool.schema.object({ - reason: tool.schema.enum(["completion", "noise", "consolidation"]).describe("The reason for pruning"), - distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).optional().describe( - "An object containing detailed summaries or extractions of the key findings from the tools being pruned. This is REQUIRED for 'consolidation'." - ), - }).describe("Metadata about the pruning operation."), }, async execute(args, toolCtx) { - const { client, state, logger, config, workingDirectory } = ctx - const sessionId = toolCtx.sessionID - - logger.info("Prune tool invoked") - logger.info(JSON.stringify(args)) - - if (!args.ids || args.ids.length === 0) { - logger.debug("Prune tool called but args.ids is empty or undefined: " + JSON.stringify(args)) - return "No IDs provided. Check the list for available IDs to prune." - } - - if (!args.metadata || !args.metadata.reason) { - logger.debug("Prune tool called without metadata.reason: " + JSON.stringify(args)) - return "Missing metadata.reason. Provide metadata: { reason: 'completion' | 'noise' | 'consolidation' }" - } - - const { reason, distillation } = args.metadata; - - const numericToolIds: number[] = args.ids - .map(id => parseInt(id, 10)) - .filter((n): n is number => !isNaN(n)) - - if (numericToolIds.length === 0) { - logger.debug("No numeric tool IDs provided for pruning, yet prune tool was called: " + JSON.stringify(args)) - return "No numeric IDs provided. Format: ids: [id1, id2, ...]" - } - - // Fetch messages to calculate tokens and find current agent - const messagesResponse = await client.session.messages({ - path: { id: sessionId } - }) - const messages: WithParts[] = messagesResponse.data || messagesResponse - - await ensureSessionInitialized(ctx.client, state, sessionId, logger, messages) - - const currentParams = getCurrentParams(messages, logger) - const toolIdList: string[] = buildToolIdList(state, messages, logger) - - // Validate that all numeric IDs are within bounds - if (numericToolIds.some(id => id < 0 || id >= toolIdList.length)) { - logger.debug("Invalid tool IDs provided: " + numericToolIds.join(", ")) - return "Invalid IDs provided. Only use numeric IDs from the list." - } - - // Validate that all IDs exist in cache and aren't protected - // (rejects hallucinated IDs and turn-protected tools not shown in ) - for (const index of numericToolIds) { - const id = toolIdList[index] - const metadata = state.toolParameters.get(id) - if (!metadata) { - logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id }) - return "Invalid IDs provided. Only use numeric IDs from the list." - } - if (config.strategies.pruneTool.protectedTools.includes(metadata.tool)) { - logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool }) - return "Invalid IDs provided. Only use numeric IDs from the list." - } + // Parse reason from first element, numeric IDs from the rest + const reason = args.ids?.[0] + const validReasons = ["completion", "noise"] as const + if (typeof reason !== "string" || !validReasons.includes(reason as any)) { + ctx.logger.debug("Invalid discard reason provided: " + reason) + return "No valid reason found. Use 'completion' or 'noise' as the first element." } - const pruneToolIds: string[] = numericToolIds.map(index => toolIdList[index]) - state.prune.toolIds.push(...pruneToolIds) - - const toolMetadata = new Map() - for (const id of pruneToolIds) { - const toolParameters = state.toolParameters.get(id) - if (toolParameters) { - toolMetadata.set(id, toolParameters) - } else { - logger.debug("No metadata found for ID", { id }) - } - } - - state.stats.pruneTokenCounter += calculateTokensSaved(state, messages, pruneToolIds) + const numericIds = args.ids.slice(1) - await sendUnifiedNotification( - client, - logger, - config, - state, - sessionId, - pruneToolIds, - toolMetadata, + return executePruneOperation( + ctx, + toolCtx, + numericIds, reason as PruneReason, - currentParams, - workingDirectory + "Discard" ) + }, + }) +} - state.stats.totalPruneTokens += state.stats.pruneTokenCounter - state.stats.pruneTokenCounter = 0 - state.nudgeCounter = 0 +export function createExtractTool( + ctx: PruneToolContext, +): ReturnType { + return tool({ + description: EXTRACT_TOOL_DESCRIPTION, + args: { + ids: tool.schema.array( + tool.schema.string() + ).describe( + "Numeric IDs as strings to extract from the list" + ), + distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).describe( + "REQUIRED. An object mapping each ID to its distilled findings. Must contain an entry for every ID being pruned." + ), + }, + async execute(args, toolCtx) { + if (!args.distillation || Object.keys(args.distillation).length === 0) { + ctx.logger.debug("Extract tool called without distillation: " + JSON.stringify(args)) + return "Missing distillation. You must provide distillation data when using extract. Format: distillation: { \"id\": { ...findings... } }" + } - saveSessionState(state, logger) - .catch(err => logger.error("Failed to persist state", { error: err.message })) + // Log the distillation for debugging/analysis + ctx.logger.info("Distillation data received:") + ctx.logger.info(JSON.stringify(args.distillation, null, 2)) - const result = formatPruningResultForTool( - pruneToolIds, - toolMetadata, - workingDirectory + return executePruneOperation( + ctx, + toolCtx, + args.ids, + "consolidation" as PruneReason, + "Extract" ) - // - // if (distillation) { - // logger.info("Distillation data received:", distillation) - // } - - return result }, }) } - From ef0f25dcfafea3c420477cba2b3c89e6a55bc2d3 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 02:57:04 -0500 Subject: [PATCH 13/43] Register discard/extract tools and update system prompts --- index.ts | 21 ++++++--- lib/prompts/discard-tool-spec.txt | 56 ++++++++++++++++++++++++ lib/prompts/extract-tool-spec.txt | 68 +++++++++++++++++++++++++++++ lib/prompts/prune-nudge.txt | 8 ++-- lib/prompts/prune-system-prompt.txt | 30 +++++++------ 5 files changed, 159 insertions(+), 24 deletions(-) create mode 100644 lib/prompts/discard-tool-spec.txt create mode 100644 lib/prompts/extract-tool-spec.txt diff --git a/index.ts b/index.ts index ac877050..fa31e041 100644 --- a/index.ts +++ b/index.ts @@ -3,7 +3,7 @@ import { getConfig } from "./lib/config" import { Logger } from "./lib/logger" import { loadPrompt } from "./lib/prompt" import { createSessionState } from "./lib/state" -import { createPruneTool } from "./lib/strategies" +import { createDiscardTool, createExtractTool } from "./lib/strategies" import { createChatMessageTransformHandler, createEventHandler } from "./lib/hooks" const plugin: Plugin = (async (ctx) => { @@ -38,8 +38,15 @@ const plugin: Plugin = (async (ctx) => { logger, config ), - tool: config.strategies.pruneTool.enabled ? { - prune: createPruneTool({ + tool: (config.strategies.discardTool.enabled || config.strategies.extractTool.enabled) ? { + discard: createDiscardTool({ + client: ctx.client, + state, + logger, + config, + workingDirectory: ctx.directory + }), + extract: createExtractTool({ client: ctx.client, state, logger, @@ -48,15 +55,15 @@ const plugin: Plugin = (async (ctx) => { }), } : undefined, config: async (opencodeConfig) => { - // Add prune to primary_tools by mutating the opencode config + // Add discard and extract to primary_tools by mutating the opencode config // This works because config is cached and passed by reference - if (config.strategies.pruneTool.enabled) { + if (config.strategies.discardTool.enabled || config.strategies.extractTool.enabled) { const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? [] opencodeConfig.experimental = { ...opencodeConfig.experimental, - primary_tools: [...existingPrimaryTools, "prune"], + primary_tools: [...existingPrimaryTools, "discard", "extract"], } - logger.info("Added 'prune' to experimental.primary_tools via config mutation") + logger.info("Added 'discard' and 'extract' to experimental.primary_tools via config mutation") } }, event: createEventHandler(ctx.client, config, state, logger, ctx.directory), diff --git a/lib/prompts/discard-tool-spec.txt b/lib/prompts/discard-tool-spec.txt new file mode 100644 index 00000000..51ca5781 --- /dev/null +++ b/lib/prompts/discard-tool-spec.txt @@ -0,0 +1,56 @@ +Discards tool outputs from context to manage conversation size and reduce noise. + +## IMPORTANT: The Prunable List +A `` list is injected into user messages showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard. + +**Note:** For `write` and `edit` tools, discarding removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context. + +## When to Use This Tool + +Use `discard` for removing tool outputs that are no longer needed **without preserving their content**: + +### 1. Task Completion (Clean Up) +**When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). +**Action:** Discard the tools used for that task with reason `completion`. + +### 2. Removing Noise (Garbage Collection) +**When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). +**Action:** Discard these specific tool outputs immediately with reason `noise`. + +## When NOT to Use This Tool + +- **If you need to preserve information:** Use the `consolidate` tool instead when you want to keep distilled findings from the tool outputs. +- **If you'll need the output later:** Don't discard files you plan to edit, or context you'll need for implementation. + +## Best Practices +- **Strategic Batching:** Don't discard single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact discards. +- **Think ahead:** Before discarding, ask: "Will I need this output for an upcoming task?" If yes, keep it. + +## Format +The `ids` parameter is an array where the first element is the reason, followed by numeric IDs: +`ids: ["reason", "id1", "id2", ...]` + +## Examples + + +Assistant: [Reads 'wrong_file.ts'] +This file isn't relevant to the auth system. I'll remove it to clear the context. +[Uses discard with ids: ["noise", "5"]] + + + +Assistant: [Runs tests, they pass] +The tests passed. I'll clean up now. +[Uses discard with ids: ["completion", "20", "21"]] + + + +Assistant: [Reads 'auth.ts' to understand the login flow] +I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than discarding. + + + +Assistant: [Edits 'auth.ts' to add validation] +The edit was successful. I no longer need the raw edit content in context. +[Uses discard with ids: ["completion", "15"]] + diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt new file mode 100644 index 00000000..e85fb8cb --- /dev/null +++ b/lib/prompts/extract-tool-spec.txt @@ -0,0 +1,68 @@ +Extracts key findings from tool outputs into distilled knowledge, then removes the raw outputs from context. + +## IMPORTANT: The Prunable List +A `` list is injected into user messages showing available tool outputs you can extract from when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to extract. + +## When to Use This Tool + +Use `extract` when you have gathered useful information that you want to **preserve in distilled form** before removing the raw outputs: + +**When:** You have read files, run commands, or gathered context that contains valuable information you'll need to reference later, but the full raw output is too large to keep. +**Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). + +## CRITICAL: Distillation Requirements + +You MUST provide distilled findings in the `distillation` parameter. This is not optional. + +- **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered. +- **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation. +- **Extract Per-ID:** When extracting from multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being extracted. You must capture high-fidelity findings for each tool individually to ensure no signal is lost. +- **Structure:** Map EVERY `ID` from the `ids` array to its specific distilled findings. + Example: `{ "20": { ... }, "21": { ... } }` +- Capture all relevant details (function names, logic, constraints) to ensure no signal is lost. +- Prioritize information that is essential for the immediate next steps of your plan. + +## When NOT to Use This Tool + +- **If you don't need to preserve information:** Use the `discard` tool instead for completed tasks or noise removal. +- **If you need precise syntax:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. +- **If uncertain:** Prefer keeping over re-fetching. The cost of retaining context is lower than the cost of redundant tool calls. + +## Best Practices +- **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps. +- **Strategic Batching:** Wait until you have several items or a few large outputs to extract, rather than doing tiny, frequent extractions. Aim for high-impact extractions that significantly reduce context size. +- **Think ahead:** Before extracting, ask: "Will I need the raw output for an upcoming task?" If you researched a file you'll later edit, do NOT extract it. + +## Example + + +Assistant: [Reads service implementation, types, and config] +I'll preserve the full technical specification and implementation logic before extracting. +[Uses extract with ids: ["10", "11", "12"], distillation: { + "10": { + "file": "src/services/auth.ts", + "signatures": [ + "async function validateToken(token: string): Promise", + "function hashPassword(password: string): string" + ], + "logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.", + "dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"], + "constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds." + }, + "11": { + "file": "src/types/user.ts", + "interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }", + "context": "The permissions array is strictly typed and used by the RBAC middleware." + }, + "12": { + "file": "config/default.json", + "values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 }, + "impact": "The retry strategy affects all outgoing HTTP clients in the core module." + } +}] + + + +Assistant: [Reads 'auth.ts' to understand the login flow] +I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than extracting. + diff --git a/lib/prompts/prune-nudge.txt b/lib/prompts/prune-nudge.txt index ef84d35c..549e34a0 100644 --- a/lib/prompts/prune-nudge.txt +++ b/lib/prompts/prune-nudge.txt @@ -2,9 +2,9 @@ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, prune the tools used. No distillation. -2. **Noise Removal:** If you read files or ran commands that yielded no value, prune them NOW. No distillation. -3. **Consolidation:** If you are holding valuable raw data, you *must* distill the insights into `metadata.distillation` and prune the raw entry. +1. **Task Completion:** If a sub-task is complete, discard the tools used. +2. **Noise Removal:** If you read files or ran commands that yielded no value, discard them NOW. +3. **Extraction:** If you are holding valuable raw data, you *must* use the `extract` tool to distill the insights and remove the raw entry. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must prune. +**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must perform context management. diff --git a/lib/prompts/prune-system-prompt.txt b/lib/prompts/prune-system-prompt.txt index 88ba3079..7bd11d39 100644 --- a/lib/prompts/prune-system-prompt.txt +++ b/lib/prompts/prune-system-prompt.txt @@ -2,21 +2,25 @@ ENVIRONMENT -You are operating in a context-constrained environment and thus must proactively manage your context window using the `prune` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to prune. +You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to prune. -PRUNE METHODICALLY - CONSOLIDATE YOUR ACTIONS -Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. +TWO TOOLS FOR CONTEXT MANAGEMENT +- `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content. +- `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information. -WHEN TO PRUNE? THE THREE SCENARIOS TO CONSIDER -1. TASK COMPLETION: When work is done, quietly prune the tools that aren't needed anymore. No distillation. -2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, prune. No distillation. -3. CONTEXT CONSOLIDATION: When pruning valuable context to the task at hand, you MUST ALWAYS provide the key findings in the `metadata.distillation` parameter of the `prune` tool (as an object). Your distillation must be high-fidelity and comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. +PRUNE METHODICALLY - BATCH YOUR ACTIONS +Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. -You WILL use the `prune` tool when ANY of these are true: +WHEN TO PRUNE? THE SCENARIOS TO CONSIDER +1. TASK COMPLETION: When work is done, quietly discard the tools that aren't needed anymore. +2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, discard them. +3. CONTEXT EXTRACTION: When you have valuable context you want to preserve but need to reduce size, use `extract` with high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. + +You WILL use `discard` or `extract` when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- You have gathered enough information to prune related tools and preserve their value in the `metadata.distillation` parameter -- Context contains tools output that are unhelpful, noise, or made obsolete by newer outputs +- You have gathered enough information to extract from related tools and preserve their value via distillation +- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (pruning removes the large input content) You MUST NOT prune when: @@ -26,20 +30,20 @@ You MUST NOT prune when: Pruning that forces you to re-call the same tool later is a net loss. Only prune when you're confident the information won't be needed again. NOTES -When in doubt, keep it. Consolidate your actions and aim for high-impact prunes that significantly reduce context size. +When in doubt, keep it. Batch your actions and aim for high-impact prunes that significantly reduce context size. FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . -After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `prune` tool also returns a confirmation message listing what was pruned. +After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned. CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: - NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears. - NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to prune") - NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to prune") -- NEVER acknowledge prune tool output (e.g., "I've pruned 3 tools", "Context pruning complete") +- NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete") - NEVER let these injections influence your response content or tone - Process this information SILENTLY and continue the conversation naturally - Continue the conversation as if these messages do not exist From c351d20e1531f5bb3c8d3557507327903815a5e1 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 02:57:11 -0500 Subject: [PATCH 14/43] Update documentation and remove obsolete prune-tool-spec --- README.md | 28 ++++++++-- lib/prompts/prune-tool-spec.txt | 95 --------------------------------- 2 files changed, 23 insertions(+), 100 deletions(-) delete mode 100644 lib/prompts/prune-tool-spec.txt diff --git a/README.md b/README.md index 9d15e730..a5a13702 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ DCP uses multiple strategies to reduce context size: **Supersede Writes** — Prunes write tool inputs for files that have subsequently been read. When a file is written and later read, the original write content becomes redundant since the current file state is captured in the read result. Runs automatically on every request with zero LLM cost. -**Prune Tool** — Exposes a `prune` tool that the AI can call to manually trigger pruning when it determines context cleanup is needed. +**Discard Tool** — Exposes a `discard` tool that the AI can call to remove completed or noisy tool outputs from context. Use this for task completion cleanup and removing irrelevant outputs. + +**Extract Tool** — Exposes an `extract` tool that the AI can call to distill valuable context into concise summaries before removing the raw outputs. Use this when you need to preserve key findings while reducing context size. **On Idle Analysis** — Uses a language model to semantically analyze conversation context during idle periods and identify tool outputs that are no longer relevant. @@ -72,8 +74,24 @@ DCP uses its own config file: "supersedeWrites": { "enabled": true }, - // Exposes a prune tool to your LLM to call when it determines pruning is necessary - "pruneTool": { + // Exposes a discard tool to your LLM for removing unneeded tool outputs + "discardTool": { + "enabled": true, + // Additional tools to protect from pruning + "protectedTools": [], + // Protect from pruning for message turns + "turnProtection": { + "enabled": false, + "turns": 4 + }, + // Nudge the LLM to use the discard tool (every tool results) + "nudge": { + "enabled": true, + "frequency": 10 + } + }, + // Exposes an extract tool to your LLM for distilling context before removal + "extractTool": { "enabled": true, // Additional tools to protect from pruning "protectedTools": [], @@ -82,7 +100,7 @@ DCP uses its own config file: "enabled": false, "turns": 4 }, - // Nudge the LLM to use the prune tool (every tool results) + // Nudge the LLM to use the extract tool (every tool results) "nudge": { "enabled": true, "frequency": 10 @@ -109,7 +127,7 @@ DCP uses its own config file: ### Protected Tools By default, these tools are always protected from pruning across all strategies: -`task`, `todowrite`, `todoread`, `prune`, `batch` +`task`, `todowrite`, `todoread`, `discard`, `extract`, `batch` The `protectedTools` arrays in each strategy add to this default list. diff --git a/lib/prompts/prune-tool-spec.txt b/lib/prompts/prune-tool-spec.txt deleted file mode 100644 index 6d59aa3d..00000000 --- a/lib/prompts/prune-tool-spec.txt +++ /dev/null @@ -1,95 +0,0 @@ -Prunes tool outputs from context to manage conversation size and reduce noise. - -## IMPORTANT: The Prunable List -A `` list is injected into user messages showing available tool outputs you can prune when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to prune. - -**Note:** For `write` and `edit` tools, pruning removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context. - -## CRITICAL: When and How to Prune - -You must use this tool in three specific scenarios. The rules for distillation (summarizing findings) differ for each. **You must provide a `metadata` object with a `reason` and optional `distillation`** to indicate which scenario applies. - -### 1. Task Completion (Clean Up) — reason: `completion` -**When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). -**Action:** Prune the tools used for that task. -**Distillation:** FORBIDDEN. Do not summarize completed work. - -### 2. Removing Noise (Garbage Collection) — reason: `noise` -**When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). -**Action:** Prune these specific tool outputs immediately. -**Distillation:** FORBIDDEN. Do not summarize noise. - -### 3. Context Conservation (Research & Consolidation) — reason: `consolidation` -**When:** You have gathered useful information. Wait until you have several items or a few large outputs to prune, rather than doing tiny, frequent prunes. Aim for high-impact prunes that significantly reduce context size. -**Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). -**Distillation:** MANDATORY. You MUST provide the distilled findings in the `metadata.distillation` parameter of the `prune` tool (as an object). - - **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered. - - **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation. - - **Consolidate:** When pruning multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being pruned. You must capture high-fidelity findings for each tool individually to ensure no signal is lost. - - Structure: Map EVERY `ID` from the `ids` array to its specific distilled findings. - Example: `{ "20": { ... }, "21": { ... } }` - - Capture all relevant details (function names, logic, constraints) to ensure no signal is lost. - - Prioritize information that is essential for the immediate next steps of your plan. - - Once distilled into the `metadata` object, the raw tool output can be safely pruned. - - **Know when distillation isn't enough:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. - - **Prefer keeping over re-fetching:** If uncertain whether you'll need the output again, keep it. The cost of retaining context is lower than the cost of redundant tool calls. - -## Best Practices -- **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps. -- **Strategic Consolidation:** Don't prune single small tool outputs (like short bash commands) unless they are pure noise. Instead, wait until you have several items or large outputs to perform high-impact prunes. This balances the need for an agile context with the efficiency of larger batches. -- **Think ahead:** Before pruning, ask: "Will I need this output for an upcoming task?" If you researched a file you'll later edit, or gathered context for implementation, do NOT prune it. - -## Examples - - -Assistant: [Reads 'wrong_file.ts'] -This file isn't relevant to the auth system. I'll remove it to clear the context. -[Uses prune with ids: ["5"], metadata: { "reason": "noise" }] - - - -Assistant: [Reads service implementation, types, and config] -I'll preserve the full technical specification and implementation logic before pruning. -[Uses prune with ids: ["10", "11", "12"], metadata: { - "reason": "consolidation", - "distillation": { - "10": { - "file": "src/services/auth.ts", - "signatures": [ - "async function validateToken(token: string): Promise", - "function hashPassword(password: string): string" - ], - "logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.", - "dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"], - "constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds." - }, - "11": { - "file": "src/types/user.ts", - "interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }", - "context": "The permissions array is strictly typed and used by the RBAC middleware." - }, - "12": { - "file": "config/default.json", - "values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 }, - "impact": "The retry strategy affects all outgoing HTTP clients in the core module." - } - } -}] - - - -Assistant: [Runs tests, they pass] -The tests passed. I'll clean up now. -[Uses prune with ids: ["20", "21"], metadata: { "reason": "completion" }] - - - -Assistant: [Reads 'auth.ts' to understand the login flow] -I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than distilling and pruning. - - - -Assistant: [Edits 'auth.ts' to add validation] -The edit was successful. I no longer need the raw edit content in context. -[Uses prune with ids: ["15"], metadata: { "reason": "completion" }] - From 46c623a24d6a8cbaec4038da3283b32eff1a0422 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 12:21:50 -0500 Subject: [PATCH 15/43] feat: dynamically load system and nudge prompts based on enabled tools - Splits system and nudge prompts into separate files for discard, extract, or both. - Updates to load the appropriate system prompt based on configuration. - Updates to dynamically select the nudge string. - Deletes the previous monolithic prompt files. --- index.ts | 16 +++++- lib/messages/prune.ts | 16 +++++- .../{prune-nudge.txt => nudge/nudge-both.txt} | 0 lib/prompts/nudge/nudge-discard.txt | 9 ++++ lib/prompts/nudge/nudge-extract.txt | 10 ++++ .../system-prompt-both.txt} | 0 lib/prompts/system/system-prompt-discard.txt | 50 ++++++++++++++++++ lib/prompts/system/system-prompt-extract.txt | 52 +++++++++++++++++++ 8 files changed, 150 insertions(+), 3 deletions(-) rename lib/prompts/{prune-nudge.txt => nudge/nudge-both.txt} (100%) create mode 100644 lib/prompts/nudge/nudge-discard.txt create mode 100644 lib/prompts/nudge/nudge-extract.txt rename lib/prompts/{prune-system-prompt.txt => system/system-prompt-both.txt} (100%) create mode 100644 lib/prompts/system/system-prompt-discard.txt create mode 100644 lib/prompts/system/system-prompt-extract.txt diff --git a/index.ts b/index.ts index fa31e041..89bf8b2a 100644 --- a/index.ts +++ b/index.ts @@ -29,7 +29,21 @@ const plugin: Plugin = (async (ctx) => { return { "experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => { - const syntheticPrompt = loadPrompt("prune-system-prompt") + const discardEnabled = config.strategies.discardTool.enabled + const extractEnabled = config.strategies.extractTool.enabled + + let promptName: string + if (discardEnabled && extractEnabled) { + promptName = "system/system-prompt-both" + } else if (discardEnabled) { + promptName = "system/system-prompt-discard" + } else if (extractEnabled) { + promptName = "system/system-prompt-extract" + } else { + return // No context management tools enabled + } + + const syntheticPrompt = loadPrompt(promptName) output.system.push(syntheticPrompt) }, "experimental.chat.messages.transform": createChatMessageTransformHandler( diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 3c54bba9..c26c1bd4 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -8,7 +8,19 @@ import { UserMessage } from "@opencode-ai/sdk" const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]' const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]' -const NUDGE_STRING = loadPrompt("prune-nudge") +const getNudgeString = (config: PluginConfig): string => { + const discardEnabled = config.strategies.discardTool.enabled + const extractEnabled = config.strategies.extractTool.enabled + + if (discardEnabled && extractEnabled) { + return loadPrompt("nudge/nudge-both") + } else if (discardEnabled) { + return loadPrompt("nudge/nudge-discard") + } else if (extractEnabled) { + return loadPrompt("nudge/nudge-extract") + } + return "" +} const wrapPrunableTools = (content: string): string => ` The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output. Keep the context free of noise. @@ -94,7 +106,7 @@ export const insertPruneToolContext = ( ) if (state.nudgeCounter >= nudgeFrequency) { logger.info("Inserting prune nudge message") - nudgeString = "\n" + NUDGE_STRING + nudgeString = "\n" + getNudgeString(config) } prunableToolsContent = prunableToolsList + nudgeString diff --git a/lib/prompts/prune-nudge.txt b/lib/prompts/nudge/nudge-both.txt similarity index 100% rename from lib/prompts/prune-nudge.txt rename to lib/prompts/nudge/nudge-both.txt diff --git a/lib/prompts/nudge/nudge-discard.txt b/lib/prompts/nudge/nudge-discard.txt new file mode 100644 index 00000000..7ded42f9 --- /dev/null +++ b/lib/prompts/nudge/nudge-discard.txt @@ -0,0 +1,9 @@ + +**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. + +**Immediate Actions Required:** +1. **Task Completion:** If a sub-task is complete, discard the tools used. +2. **Noise Removal:** If you read files or ran commands that yielded no value, discard them NOW. + +**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must discard unneeded tool outputs. + diff --git a/lib/prompts/nudge/nudge-extract.txt b/lib/prompts/nudge/nudge-extract.txt new file mode 100644 index 00000000..3d9ea9a4 --- /dev/null +++ b/lib/prompts/nudge/nudge-extract.txt @@ -0,0 +1,10 @@ + +**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. + +**Immediate Actions Required:** +1. **Task Completion:** If a sub-task is complete, extract findings and remove the raw tool outputs. +2. **Noise Removal:** If you read files or ran commands that yielded no value, extract them with minimal distillation NOW. +3. **Extraction:** If you are holding valuable raw data, you *must* use the `extract` tool to distill the insights and remove the raw entry. + +**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract and remove unneeded tool outputs. + diff --git a/lib/prompts/prune-system-prompt.txt b/lib/prompts/system/system-prompt-both.txt similarity index 100% rename from lib/prompts/prune-system-prompt.txt rename to lib/prompts/system/system-prompt-both.txt diff --git a/lib/prompts/system/system-prompt-discard.txt b/lib/prompts/system/system-prompt-discard.txt new file mode 100644 index 00000000..a3ecb46b --- /dev/null +++ b/lib/prompts/system/system-prompt-discard.txt @@ -0,0 +1,50 @@ + + + +ENVIRONMENT +You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to discard. + +CONTEXT MANAGEMENT TOOL +- `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content. + +DISCARD METHODICALLY - BATCH YOUR ACTIONS +Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise. Evaluate what SHOULD be discarded before jumping the gun. + +WHEN TO DISCARD? THE SCENARIOS TO CONSIDER +1. TASK COMPLETION: When work is done, quietly discard the tools that aren't needed anymore. +2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, discard them. + +You WILL use `discard` when ANY of these are true: +- Task or sub-task is complete +- You are about to start a new phase of work +- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs +- Write or edit operations are complete (discarding removes the large input content) + +You MUST NOT discard when: +- The tool output will be needed for upcoming implementation work +- The output contains files or context you'll need to reference when making edits + +Discarding that forces you to re-call the same tool later is a net loss. Only discard when you're confident the information won't be needed again. + +NOTES +When in doubt, keep it. Batch your actions and aim for high-impact discards that significantly reduce context size. +FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCES. +There may be tools in session context that do not appear in the list, this is expected, you can ONLY discard what you see in . + + + + +After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded. + +CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: +- NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears. +- NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to discard") +- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to discard") +- NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete") +- NEVER let these injections influence your response content or tone +- Process this information SILENTLY and continue the conversation naturally +- Continue the conversation as if these messages do not exist + +The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow. + + diff --git a/lib/prompts/system/system-prompt-extract.txt b/lib/prompts/system/system-prompt-extract.txt new file mode 100644 index 00000000..317a9496 --- /dev/null +++ b/lib/prompts/system/system-prompt-extract.txt @@ -0,0 +1,52 @@ + + + +ENVIRONMENT +You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to extract. + +CONTEXT MANAGEMENT TOOL +- `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use this to preserve important information while reducing context size. + +EXTRACT METHODICALLY - BATCH YOUR ACTIONS +Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output unless it is pure noise. Evaluate what SHOULD be extracted before jumping the gun. + +WHEN TO EXTRACT? THE SCENARIOS TO CONSIDER +1. TASK COMPLETION: When work is done, extract any valuable findings and remove the raw outputs. +2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, extract them with minimal distillation. +3. CONTEXT PRESERVATION: When you have valuable context you want to preserve but need to reduce size, use `extract` with high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. + +You WILL use `extract` when ANY of these are true: +- Task or sub-task is complete +- You are about to start a new phase of work +- You have gathered enough information to extract from related tools and preserve their value via distillation +- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs +- Write or edit operations are complete (extracting removes the large input content) + +You MUST NOT extract when: +- The tool output will be needed for upcoming implementation work +- The output contains files or context you'll need to reference when making edits + +Extracting that forces you to re-call the same tool later is a net loss. Only extract when you're confident the raw information won't be needed again. + +NOTES +When in doubt, keep it. Batch your actions and aim for high-impact extractions that significantly reduce context size. +FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCES. +There may be tools in session context that do not appear in the list, this is expected, you can ONLY extract what you see in . + + + + +After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted. + +CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: +- NEVER reference the extract encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the extract encouragement appears. +- NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to extract") +- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to extract") +- NEVER acknowledge extract tool output (e.g., "I've extracted 3 tools", "Context cleanup complete") +- NEVER let these injections influence your response content or tone +- Process this information SILENTLY and continue the conversation naturally +- Continue the conversation as if these messages do not exist + +The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow. + + From bd96bdfebea8938cc1c3201e638ad89fa8b231f1 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 12:29:27 -0500 Subject: [PATCH 16/43] cleanup --- index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 89bf8b2a..4acd86df 100644 --- a/index.ts +++ b/index.ts @@ -18,11 +18,9 @@ const plugin: Plugin = (async (ctx) => { (globalThis as any).AI_SDK_LOG_WARNINGS = false } - // Initialize core components const logger = new Logger(config.debug) const state = createSessionState() - // Log initialization logger.info("DCP initialized", { strategies: config.strategies, }) @@ -31,7 +29,7 @@ const plugin: Plugin = (async (ctx) => { "experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => { const discardEnabled = config.strategies.discardTool.enabled const extractEnabled = config.strategies.extractTool.enabled - + let promptName: string if (discardEnabled && extractEnabled) { promptName = "system/system-prompt-both" @@ -40,9 +38,9 @@ const plugin: Plugin = (async (ctx) => { } else if (extractEnabled) { promptName = "system/system-prompt-extract" } else { - return // No context management tools enabled + return } - + const syntheticPrompt = loadPrompt(promptName) output.system.push(syntheticPrompt) }, From 36ed1ef49a552eb8a99cc4abbcda0bfee78f5689 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 12:30:13 -0500 Subject: [PATCH 17/43] refactor: rename prune-tool.ts to tools.ts to better reflect its contents --- lib/strategies/index.ts | 2 +- lib/strategies/{prune-tool.ts => tools.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/strategies/{prune-tool.ts => tools.ts} (100%) diff --git a/lib/strategies/index.ts b/lib/strategies/index.ts index c30bd8cb..02d2f831 100644 --- a/lib/strategies/index.ts +++ b/lib/strategies/index.ts @@ -1,4 +1,4 @@ export { deduplicate } from "./deduplication" export { runOnIdle } from "./on-idle" -export { createDiscardTool, createExtractTool } from "./prune-tool" +export { createDiscardTool, createExtractTool } from "./tools" export { supersedeWrites } from "./supersede-writes" diff --git a/lib/strategies/prune-tool.ts b/lib/strategies/tools.ts similarity index 100% rename from lib/strategies/prune-tool.ts rename to lib/strategies/tools.ts From 7a91b9b7cfafde6df983c7816a6ca30015219f8b Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 15:02:28 -0500 Subject: [PATCH 18/43] refactor: consolidate and clarify tool prompts for standalone use - Remove cross-references between discard/extract tools so each works independently - Add decision hierarchy in both-mode: discard as default, extract for preservation - Consolidate redundant 'WHEN TO X' scenarios with trigger lists - Change trigger lists to focus on timing ('evaluate when') vs prescriptive action - Remove confusing 'minimal distillation for cleanup' concept from extract prompts - Standardize structure across all system prompts and nudges --- lib/prompts/discard-tool-spec.txt | 2 +- lib/prompts/extract-tool-spec.txt | 1 - lib/prompts/nudge/nudge-both.txt | 6 +++--- lib/prompts/nudge/nudge-discard.txt | 4 ++-- lib/prompts/nudge/nudge-extract.txt | 7 +++---- lib/prompts/system/system-prompt-both.txt | 21 ++++++++++++-------- lib/prompts/system/system-prompt-discard.txt | 9 ++++----- lib/prompts/system/system-prompt-extract.txt | 15 ++++++-------- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lib/prompts/discard-tool-spec.txt b/lib/prompts/discard-tool-spec.txt index 51ca5781..4cbf50a5 100644 --- a/lib/prompts/discard-tool-spec.txt +++ b/lib/prompts/discard-tool-spec.txt @@ -19,7 +19,7 @@ Use `discard` for removing tool outputs that are no longer needed **without pres ## When NOT to Use This Tool -- **If you need to preserve information:** Use the `consolidate` tool instead when you want to keep distilled findings from the tool outputs. +- **If you need to preserve information:** Keep the raw output in context rather than discarding it. - **If you'll need the output later:** Don't discard files you plan to edit, or context you'll need for implementation. ## Best Practices diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt index e85fb8cb..895effa1 100644 --- a/lib/prompts/extract-tool-spec.txt +++ b/lib/prompts/extract-tool-spec.txt @@ -24,7 +24,6 @@ You MUST provide distilled findings in the `distillation` parameter. This is not ## When NOT to Use This Tool -- **If you don't need to preserve information:** Use the `discard` tool instead for completed tasks or noise removal. - **If you need precise syntax:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. - **If uncertain:** Prefer keeping over re-fetching. The cost of retaining context is lower than the cost of redundant tool calls. diff --git a/lib/prompts/nudge/nudge-both.txt b/lib/prompts/nudge/nudge-both.txt index 549e34a0..f9fa4926 100644 --- a/lib/prompts/nudge/nudge-both.txt +++ b/lib/prompts/nudge/nudge-both.txt @@ -2,9 +2,9 @@ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, discard the tools used. -2. **Noise Removal:** If you read files or ran commands that yielded no value, discard them NOW. -3. **Extraction:** If you are holding valuable raw data, you *must* use the `extract` tool to distill the insights and remove the raw entry. +1. **Task Completion:** If a sub-task is complete, decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping. +2. **Noise Removal:** If you read files or ran commands that yielded no value, use `discard` to remove them. +3. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use `extract` to distill the insights and remove the raw entry. **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must perform context management. diff --git a/lib/prompts/nudge/nudge-discard.txt b/lib/prompts/nudge/nudge-discard.txt index 7ded42f9..1ccecf9e 100644 --- a/lib/prompts/nudge/nudge-discard.txt +++ b/lib/prompts/nudge/nudge-discard.txt @@ -2,8 +2,8 @@ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, discard the tools used. -2. **Noise Removal:** If you read files or ran commands that yielded no value, discard them NOW. +1. **Task Completion:** If a sub-task is complete, use the `discard` tool to remove the tools used. +2. **Noise Removal:** If you read files or ran commands that yielded no value, use the `discard` tool to remove them. **Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must discard unneeded tool outputs. diff --git a/lib/prompts/nudge/nudge-extract.txt b/lib/prompts/nudge/nudge-extract.txt index 3d9ea9a4..4ee8dc05 100644 --- a/lib/prompts/nudge/nudge-extract.txt +++ b/lib/prompts/nudge/nudge-extract.txt @@ -2,9 +2,8 @@ **CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, extract findings and remove the raw tool outputs. -2. **Noise Removal:** If you read files or ran commands that yielded no value, extract them with minimal distillation NOW. -3. **Extraction:** If you are holding valuable raw data, you *must* use the `extract` tool to distill the insights and remove the raw entry. +1. **Task Completion:** If you have completed work, extract key findings from the tools used. Scale distillation depth to the value of the content. +2. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract and remove unneeded tool outputs. +**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract unneeded tool outputs. diff --git a/lib/prompts/system/system-prompt-both.txt b/lib/prompts/system/system-prompt-both.txt index 7bd11d39..f1e88aa2 100644 --- a/lib/prompts/system/system-prompt-both.txt +++ b/lib/prompts/system/system-prompt-both.txt @@ -8,19 +8,24 @@ TWO TOOLS FOR CONTEXT MANAGEMENT - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content. - `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information. +CHOOSING THE RIGHT TOOL +Ask: "Do I need to preserve any information from this output?" +- **No** → `discard` (default for cleanup) +- **Yes** → `extract` (preserves distilled knowledge) +- **Uncertain** → `extract` (safer, preserves signal) + +Common scenarios: +- Task complete, no valuable context → `discard` +- Task complete, insights worth remembering → `extract` +- Noise, irrelevant, or superseded outputs → `discard` +- Valuable context needed later but raw output too large → `extract` + PRUNE METHODICALLY - BATCH YOUR ACTIONS Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by pruning. Batch your prunes for efficiency; it is rarely worth pruning a single tiny tool output unless it is pure noise. Evaluate what SHOULD be pruned before jumping the gun. -WHEN TO PRUNE? THE SCENARIOS TO CONSIDER -1. TASK COMPLETION: When work is done, quietly discard the tools that aren't needed anymore. -2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, discard them. -3. CONTEXT EXTRACTION: When you have valuable context you want to preserve but need to reduce size, use `extract` with high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. - -You WILL use `discard` or `extract` when ANY of these are true: +You WILL evaluate pruning when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- You have gathered enough information to extract from related tools and preserve their value via distillation -- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (pruning removes the large input content) You MUST NOT prune when: diff --git a/lib/prompts/system/system-prompt-discard.txt b/lib/prompts/system/system-prompt-discard.txt index a3ecb46b..796852e3 100644 --- a/lib/prompts/system/system-prompt-discard.txt +++ b/lib/prompts/system/system-prompt-discard.txt @@ -10,14 +10,13 @@ CONTEXT MANAGEMENT TOOL DISCARD METHODICALLY - BATCH YOUR ACTIONS Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by discarding. Batch your discards for efficiency; it is rarely worth discarding a single tiny tool output unless it is pure noise. Evaluate what SHOULD be discarded before jumping the gun. -WHEN TO DISCARD? THE SCENARIOS TO CONSIDER -1. TASK COMPLETION: When work is done, quietly discard the tools that aren't needed anymore. -2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, discard them. +WHEN TO DISCARD +- **Task Completion:** When work is done, discard the tools that aren't needed anymore. +- **Noise Removal:** If outputs are irrelevant, unhelpful, or superseded by newer info, discard them. -You WILL use `discard` when ANY of these are true: +You WILL evaluate discarding when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (discarding removes the large input content) You MUST NOT discard when: diff --git a/lib/prompts/system/system-prompt-extract.txt b/lib/prompts/system/system-prompt-extract.txt index 317a9496..2a1a0568 100644 --- a/lib/prompts/system/system-prompt-extract.txt +++ b/lib/prompts/system/system-prompt-extract.txt @@ -5,21 +5,18 @@ ENVIRONMENT You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to extract. CONTEXT MANAGEMENT TOOL -- `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use this to preserve important information while reducing context size. +- `extract`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size. EXTRACT METHODICALLY - BATCH YOUR ACTIONS -Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output unless it is pure noise. Evaluate what SHOULD be extracted before jumping the gun. +Every tool call adds to your context debt. You MUST pay this down regularly and be on top of context accumulation by extracting. Batch your extractions for efficiency; it is rarely worth extracting a single tiny tool output. Evaluate what SHOULD be extracted before jumping the gun. -WHEN TO EXTRACT? THE SCENARIOS TO CONSIDER -1. TASK COMPLETION: When work is done, extract any valuable findings and remove the raw outputs. -2. NOISE REMOVAL: If outputs are irrelevant, unhelpful, or superseded by newer info, extract them with minimal distillation. -3. CONTEXT PRESERVATION: When you have valuable context you want to preserve but need to reduce size, use `extract` with high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. +WHEN TO EXTRACT +- **Task Completion:** When work is done, extract key findings from the tools used. Scale distillation depth to the value of the content. +- **Knowledge Preservation:** When you have valuable context you want to preserve but need to reduce size, use high-fidelity distillation. Your distillation must be comprehensive, capturing technical details (signatures, logic, constraints) such that the raw output is no longer needed. THINK: high signal, complete technical substitute. -You WILL use `extract` when ANY of these are true: +You WILL evaluate extracting when ANY of these are true: - Task or sub-task is complete - You are about to start a new phase of work -- You have gathered enough information to extract from related tools and preserve their value via distillation -- Context contains tool outputs that are unhelpful, noise, or made obsolete by newer outputs - Write or edit operations are complete (extracting removes the large input content) You MUST NOT extract when: From 571ba30ca07a180244f4ae56a05fe109b65fd89f Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 15:03:37 -0500 Subject: [PATCH 19/43] refactor: add task completion scenario to extract-tool-spec for parity with discard --- lib/prompts/extract-tool-spec.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt index 895effa1..cfc90eef 100644 --- a/lib/prompts/extract-tool-spec.txt +++ b/lib/prompts/extract-tool-spec.txt @@ -7,8 +7,13 @@ A `` list is injected into user messages showing available tool Use `extract` when you have gathered useful information that you want to **preserve in distilled form** before removing the raw outputs: +### 1. Task Completion +**When:** You have completed a unit of work and want to preserve key findings. +**Action:** Extract with distillation scaled to the value of the content. High-value insights require comprehensive capture; routine completions can use lighter distillation. + +### 2. Knowledge Preservation **When:** You have read files, run commands, or gathered context that contains valuable information you'll need to reference later, but the full raw output is too large to keep. -**Action:** Convert raw data into distilled knowledge. This allows you to discard large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). +**Action:** Convert raw data into distilled knowledge. This allows you to remove large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). ## CRITICAL: Distillation Requirements From 95cf48c96246a6fd77f6a0af3c7d3a6c8be2331a Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 20:44:22 -0500 Subject: [PATCH 20/43] fix: improve extract prompts with correct wording and format section --- lib/prompts/extract-tool-spec.txt | 7 +++++++ lib/prompts/nudge/nudge-extract.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt index cfc90eef..9af5b666 100644 --- a/lib/prompts/extract-tool-spec.txt +++ b/lib/prompts/extract-tool-spec.txt @@ -37,6 +37,13 @@ You MUST provide distilled findings in the `distillation` parameter. This is not - **Strategic Batching:** Wait until you have several items or a few large outputs to extract, rather than doing tiny, frequent extractions. Aim for high-impact extractions that significantly reduce context size. - **Think ahead:** Before extracting, ask: "Will I need the raw output for an upcoming task?" If you researched a file you'll later edit, do NOT extract it. +## Format +The `ids` parameter is an array of numeric IDs as strings: +`ids: ["id1", "id2", ...]` + +The `distillation` parameter is an object mapping each ID to its distilled findings: +`distillation: { "id1": { ...findings... }, "id2": { ...findings... } }` + ## Example diff --git a/lib/prompts/nudge/nudge-extract.txt b/lib/prompts/nudge/nudge-extract.txt index 4ee8dc05..5bdb370f 100644 --- a/lib/prompts/nudge/nudge-extract.txt +++ b/lib/prompts/nudge/nudge-extract.txt @@ -5,5 +5,5 @@ 1. **Task Completion:** If you have completed work, extract key findings from the tools used. Scale distillation depth to the value of the content. 2. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract unneeded tool outputs. +**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract valuable findings from tool outputs. From e34a9daad7d71c7178f28dafe7b62befe3ce8f26 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 21:17:32 -0500 Subject: [PATCH 21/43] fix: make cooldown message dynamic based on enabled tools --- lib/messages/prune.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index c26c1bd4..19cdb0e8 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -26,9 +26,24 @@ const wrapPrunableTools = (content: string): string => ` The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output. Keep the context free of noise. ${content} ` -const PRUNABLE_TOOLS_COOLDOWN = ` -Pruning was just performed. Do not use the prune tool again. A fresh list will be available after your next tool use. + +const getCooldownMessage = (config: PluginConfig): string => { + const discardEnabled = config.strategies.discardTool.enabled + const extractEnabled = config.strategies.extractTool.enabled + + let toolName: string + if (discardEnabled && extractEnabled) { + toolName = "discard or extract tools" + } else if (discardEnabled) { + toolName = "discard tool" + } else { + toolName = "extract tool" + } + + return ` +Context management was just performed. Do not use the ${toolName} again. A fresh list will be available after your next tool use. ` +} const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345" const SYNTHETIC_PART_ID = "prt_01234567890123456789012345" @@ -90,7 +105,7 @@ export const insertPruneToolContext = ( if (state.lastToolPrune) { logger.debug("Last tool was prune - injecting cooldown message") - prunableToolsContent = PRUNABLE_TOOLS_COOLDOWN + prunableToolsContent = getCooldownMessage(config) } else { const prunableToolsList = buildPrunableToolsList(state, config, logger, messages) if (!prunableToolsList) { From a3eb386f723445d862d1a5200d91993c4bea7042 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 21:32:11 -0500 Subject: [PATCH 22/43] docs: clarify discardTool and extractTool comments --- README.md | 4 ++-- lib/config.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a5a13702..b37401b7 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ DCP uses its own config file: "supersedeWrites": { "enabled": true }, - // Exposes a discard tool to your LLM for removing unneeded tool outputs + // Removes tool content from context without preservation (for completed tasks or noise) "discardTool": { "enabled": true, // Additional tools to protect from pruning @@ -90,7 +90,7 @@ DCP uses its own config file: "frequency": 10 } }, - // Exposes an extract tool to your LLM for distilling context before removal + // Distills key findings into preserved knowledge before removing raw content "extractTool": { "enabled": true, // Additional tools to protect from pruning diff --git a/lib/config.ts b/lib/config.ts index 44c2fe1d..1d06ac9a 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -420,7 +420,7 @@ function createDefaultConfig(): void { "supersedeWrites": { "enabled": true }, - // Exposes a discard tool to your LLM to call when it determines pruning is necessary + // Removes tool content from context without preservation (for completed tasks or noise) "discardTool": { "enabled": true, // Additional tools to protect from pruning @@ -436,7 +436,7 @@ function createDefaultConfig(): void { "frequency": 10 } }, - // Exposes an extract tool to your LLM to call when it determines pruning is necessary + // Distills key findings into preserved knowledge before removing raw content "extractTool": { "enabled": true, // Additional tools to protect from pruning From 5cbc48381d89a16d38864c680ecaa0ac21d49a79 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sat, 20 Dec 2025 22:24:28 -0500 Subject: [PATCH 23/43] fix: only register enabled prune tools --- index.ts | 44 ++++++++++++++++++++++++----------------- lib/messages/prune.ts | 8 +++++--- lib/strategies/utils.ts | 1 - 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/index.ts b/index.ts index 4acd86df..770c5a6b 100644 --- a/index.ts +++ b/index.ts @@ -50,32 +50,40 @@ const plugin: Plugin = (async (ctx) => { logger, config ), - tool: (config.strategies.discardTool.enabled || config.strategies.extractTool.enabled) ? { - discard: createDiscardTool({ - client: ctx.client, - state, - logger, - config, - workingDirectory: ctx.directory + tool: { + ...(config.strategies.discardTool.enabled && { + discard: createDiscardTool({ + client: ctx.client, + state, + logger, + config, + workingDirectory: ctx.directory + }), }), - extract: createExtractTool({ - client: ctx.client, - state, - logger, - config, - workingDirectory: ctx.directory + ...(config.strategies.extractTool.enabled && { + extract: createExtractTool({ + client: ctx.client, + state, + logger, + config, + workingDirectory: ctx.directory + }), }), - } : undefined, + }, config: async (opencodeConfig) => { - // Add discard and extract to primary_tools by mutating the opencode config + // Add enabled tools to primary_tools by mutating the opencode config // This works because config is cached and passed by reference - if (config.strategies.discardTool.enabled || config.strategies.extractTool.enabled) { + const toolsToAdd: string[] = [] + if (config.strategies.discardTool.enabled) toolsToAdd.push("discard") + if (config.strategies.extractTool.enabled) toolsToAdd.push("extract") + + if (toolsToAdd.length > 0) { const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? [] opencodeConfig.experimental = { ...opencodeConfig.experimental, - primary_tools: [...existingPrimaryTools, "discard", "extract"], + primary_tools: [...existingPrimaryTools, ...toolsToAdd], } - logger.info("Added 'discard' and 'extract' to experimental.primary_tools via config mutation") + logger.info(`Added ${toolsToAdd.map(t => `'${t}'`).join(" and ")} to experimental.primary_tools via config mutation`) } }, event: createEventHandler(ctx.client, config, state, logger, ctx.directory), diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 19cdb0e8..0257afc9 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -11,7 +11,7 @@ const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - inform const getNudgeString = (config: PluginConfig): string => { const discardEnabled = config.strategies.discardTool.enabled const extractEnabled = config.strategies.extractTool.enabled - + if (discardEnabled && extractEnabled) { return loadPrompt("nudge/nudge-both") } else if (discardEnabled) { @@ -30,7 +30,7 @@ ${content} const getCooldownMessage = (config: PluginConfig): string => { const discardEnabled = config.strategies.discardTool.enabled const extractEnabled = config.strategies.extractTool.enabled - + let toolName: string if (discardEnabled && extractEnabled) { toolName = "discard or extract tools" @@ -39,7 +39,7 @@ const getCooldownMessage = (config: PluginConfig): string => { } else { toolName = "extract tool" } - + return ` Context management was just performed. Do not use the ${toolName} again. A fresh list will be available after your next tool use. ` @@ -115,6 +115,8 @@ export const insertPruneToolContext = ( logger.debug("prunable-tools: \n" + prunableToolsList) let nudgeString = "" + // TODO: Using Math.min() means the lower frequency dominates when both tools are enabled. + // Consider using separate counters for each tool's nudge, or documenting this behavior. const nudgeFrequency = Math.min( config.strategies.discardTool.nudge.frequency, config.strategies.extractTool.nudge.frequency diff --git a/lib/strategies/utils.ts b/lib/strategies/utils.ts index 3c6a1b1b..ca610beb 100644 --- a/lib/strategies/utils.ts +++ b/lib/strategies/utils.ts @@ -37,7 +37,6 @@ function estimateTokensBatch(texts: string[]): number[] { /** * Calculates approximate tokens saved by pruning the given tool call IDs. - * TODO: Make it count message content that are not tool outputs. Currently it ONLY covers tool outputs and errors */ export const calculateTokensSaved = ( state: SessionState, From de76de1569c114e3587dca28870d9df5c28e059d Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 00:56:28 -0500 Subject: [PATCH 24/43] feat: add showDistillation option to display extracted findings as notification --- README.md | 4 +++- lib/config.ts | 20 +++++++++++++++----- lib/strategies/tools.ts | 18 +++++++++++++++--- lib/ui/notification.ts | 31 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b37401b7..7a1aa276 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,9 @@ DCP uses its own config file: "nudge": { "enabled": true, "frequency": 10 - } + }, + // Show distillation content as an ignored message notification + "showDistillation": false }, // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle "onIdle": { diff --git a/lib/config.ts b/lib/config.ts index 1d06ac9a..1ae9ce33 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -46,6 +46,7 @@ export interface ExtractTool { protectedTools: string[] turnProtection: PruneToolTurnProtection nudge: PruneToolNudge + showDistillation: boolean } export interface SupersedeWrites { @@ -108,7 +109,8 @@ export const VALID_CONFIG_KEYS = new Set([ 'strategies.extractTool.turnProtection.turns', 'strategies.extractTool.nudge', 'strategies.extractTool.nudge.enabled', - 'strategies.extractTool.nudge.frequency' + 'strategies.extractTool.nudge.frequency', + 'strategies.extractTool.showDistillation' ]) // Extract all key paths from a config object for validation @@ -234,6 +236,9 @@ function validateConfigTypes(config: Record): ValidationError[] { errors.push({ key: 'strategies.extractTool.nudge.frequency', expected: 'number', actual: typeof strategies.extractTool.nudge.frequency }) } } + if (strategies.extractTool.showDistillation !== undefined && typeof strategies.extractTool.showDistillation !== 'boolean') { + errors.push({ key: 'strategies.extractTool.showDistillation', expected: 'boolean', actual: typeof strategies.extractTool.showDistillation }) + } } // supersedeWrites @@ -327,7 +332,8 @@ const defaultConfig: PluginConfig = { nudge: { enabled: true, frequency: 10 - } + }, + showDistillation: false }, onIdle: { enabled: false, @@ -450,7 +456,9 @@ function createDefaultConfig(): void { "nudge": { "enabled": true, "frequency": 10 - } + }, + // Show distillation content as an ignored message notification + "showDistillation": false }, // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle "onIdle": { @@ -555,7 +563,8 @@ function mergeStrategies( nudge: { enabled: override.extractTool?.nudge?.enabled ?? base.extractTool.nudge.enabled, frequency: override.extractTool?.nudge?.frequency ?? base.extractTool.nudge.frequency - } + }, + showDistillation: override.extractTool?.showDistillation ?? base.extractTool.showDistillation }, supersedeWrites: { enabled: override.supersedeWrites?.enabled ?? base.supersedeWrites.enabled @@ -585,7 +594,8 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { ...config.strategies.extractTool, protectedTools: [...config.strategies.extractTool.protectedTools], turnProtection: { ...config.strategies.extractTool.turnProtection }, - nudge: { ...config.strategies.extractTool.nudge } + nudge: { ...config.strategies.extractTool.nudge }, + showDistillation: config.strategies.extractTool.showDistillation }, supersedeWrites: { ...config.strategies.supersedeWrites diff --git a/lib/strategies/tools.ts b/lib/strategies/tools.ts index b13da70e..b11eb2e9 100644 --- a/lib/strategies/tools.ts +++ b/lib/strategies/tools.ts @@ -2,7 +2,7 @@ import { tool } from "@opencode-ai/plugin" import type { SessionState, ToolParameterEntry, WithParts } from "../state" import type { PluginConfig } from "../config" import { buildToolIdList } from "../messages/utils" -import { PruneReason, sendUnifiedNotification } from "../ui/notification" +import { PruneReason, sendUnifiedNotification, sendDistillationNotification } from "../ui/notification" import { formatPruningResultForTool } from "../ui/utils" import { ensureSessionInitialized } from "../state" import { saveSessionState } from "../state/persistence" @@ -27,7 +27,8 @@ async function executePruneOperation( toolCtx: { sessionID: string }, ids: string[], reason: PruneReason, - toolName: string + toolName: string, + distillation?: Record ): Promise { const { client, state, logger, config, workingDirectory } = ctx const sessionId = toolCtx.sessionID @@ -113,6 +114,16 @@ async function executePruneOperation( workingDirectory ) + if (distillation && config.strategies.extractTool.showDistillation) { + await sendDistillationNotification( + client, + logger, + sessionId, + distillation, + currentParams + ) + } + state.stats.totalPruneTokens += state.stats.pruneTokenCounter state.stats.pruneTokenCounter = 0 state.nudgeCounter = 0 @@ -191,7 +202,8 @@ export function createExtractTool( toolCtx, args.ids, "consolidation" as PruneReason, - "Extract" + "Extract", + args.distillation ) }, }) diff --git a/lib/ui/notification.ts b/lib/ui/notification.ts index ead50acf..079d582d 100644 --- a/lib/ui/notification.ts +++ b/lib/ui/notification.ts @@ -82,6 +82,37 @@ export async function sendUnifiedNotification( return true } +function formatDistillationMessage(distillation: Record): string { + const lines: string[] = ['▣ DCP | Extracted Distillation'] + + for (const [id, findings] of Object.entries(distillation)) { + lines.push(`\n─── ID ${id} ───`) + if (typeof findings === 'object' && findings !== null) { + lines.push(JSON.stringify(findings, null, 2)) + } else { + lines.push(String(findings)) + } + } + + return lines.join('\n') +} + +export async function sendDistillationNotification( + client: any, + logger: Logger, + sessionId: string, + distillation: Record, + params: any +): Promise { + if (!distillation || Object.keys(distillation).length === 0) { + return false + } + + const message = formatDistillationMessage(distillation) + await sendIgnoredMessage(client, sessionId, message, params, logger) + return true +} + export async function sendIgnoredMessage( client: any, sessionID: string, From 1b6ce7e3fbc36ee411fd7b4ab03e9f365cf7422a Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 01:01:42 -0500 Subject: [PATCH 25/43] v1.1.0-beta.1 - Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42b0ebda..e3912475 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "1.0.4", + "version": "1.1.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "1.0.4", + "version": "1.1.0-beta.1", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.28", diff --git a/package.json b/package.json index 3732f490..7d1d515b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@tarquinen/opencode-dcp", - "version": "1.0.4", + "version": "1.1.0-beta.1", "type": "module", "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", "main": "./dist/index.js", From f51109edca5aa4bbc84678a64bc7336d50c1a373 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 18:55:17 -0500 Subject: [PATCH 26/43] refactor: restructure config schema to consolidate tool settings - Move turnProtection from per-tool to top-level - Consolidate nudge and protectedTools into tools.settings - Simplify tools.discard and tools.extract to just enabled flags - Rename pruningSummary to pruneNotification - Remove strategies.discardTool and strategies.extractTool --- lib/config.ts | 386 ++++++++++++++++++++++---------------------------- 1 file changed, 172 insertions(+), 214 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 1ae9ce33..d15f15fb 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -17,51 +17,45 @@ export interface OnIdle { protectedTools: string[] } -export interface PruneToolNudge { +export interface DiscardTool { enabled: boolean - frequency: number } -export interface PruneToolTurnProtection { +export interface ExtractTool { enabled: boolean - turns: number + showDistillation: boolean } -export interface PruneTool { - enabled: boolean +export interface ToolSettings { + nudgeEnabled: boolean + nudgeFrequency: number protectedTools: string[] - turnProtection: PruneToolTurnProtection - nudge: PruneToolNudge } -export interface DiscardTool { - enabled: boolean - protectedTools: string[] - turnProtection: PruneToolTurnProtection - nudge: PruneToolNudge +export interface Tools { + settings: ToolSettings + discard: DiscardTool + extract: ExtractTool } -export interface ExtractTool { +export interface SupersedeWrites { enabled: boolean - protectedTools: string[] - turnProtection: PruneToolTurnProtection - nudge: PruneToolNudge - showDistillation: boolean } -export interface SupersedeWrites { +export interface TurnProtection { enabled: boolean + turns: number } export interface PluginConfig { enabled: boolean debug: boolean - pruningSummary: "off" | "minimal" | "detailed" + pruneNotification: "off" | "minimal" | "detailed" + turnProtection: TurnProtection + tools: Tools strategies: { deduplication: Deduplication onIdle: OnIdle - discardTool: DiscardTool - extractTool: ExtractTool supersedeWrites: SupersedeWrites } } @@ -74,7 +68,20 @@ export const VALID_CONFIG_KEYS = new Set([ 'enabled', 'debug', 'showUpdateToasts', // Deprecated but kept for backwards compatibility - 'pruningSummary', + 'pruneNotification', + 'turnProtection', + 'turnProtection.enabled', + 'turnProtection.turns', + 'tools', + 'tools.settings', + 'tools.settings.nudgeEnabled', + 'tools.settings.nudgeFrequency', + 'tools.settings.protectedTools', + 'tools.discard', + 'tools.discard.enabled', + 'tools.extract', + 'tools.extract.enabled', + 'tools.extract.showDistillation', 'strategies', // strategies.deduplication 'strategies.deduplication', @@ -89,28 +96,7 @@ export const VALID_CONFIG_KEYS = new Set([ 'strategies.onIdle.model', 'strategies.onIdle.showModelErrorToasts', 'strategies.onIdle.strictModelSelection', - 'strategies.onIdle.protectedTools', - // strategies.discardTool - 'strategies.discardTool', - 'strategies.discardTool.enabled', - 'strategies.discardTool.protectedTools', - 'strategies.discardTool.turnProtection', - 'strategies.discardTool.turnProtection.enabled', - 'strategies.discardTool.turnProtection.turns', - 'strategies.discardTool.nudge', - 'strategies.discardTool.nudge.enabled', - 'strategies.discardTool.nudge.frequency', - // strategies.extractTool - 'strategies.extractTool', - 'strategies.extractTool.enabled', - 'strategies.extractTool.protectedTools', - 'strategies.extractTool.turnProtection', - 'strategies.extractTool.turnProtection.enabled', - 'strategies.extractTool.turnProtection.turns', - 'strategies.extractTool.nudge', - 'strategies.extractTool.nudge.enabled', - 'strategies.extractTool.nudge.frequency', - 'strategies.extractTool.showDistillation' + 'strategies.onIdle.protectedTools' ]) // Extract all key paths from a config object for validation @@ -149,10 +135,49 @@ function validateConfigTypes(config: Record): ValidationError[] { if (config.debug !== undefined && typeof config.debug !== 'boolean') { errors.push({ key: 'debug', expected: 'boolean', actual: typeof config.debug }) } - if (config.pruningSummary !== undefined) { + if (config.pruneNotification !== undefined) { const validValues = ['off', 'minimal', 'detailed'] - if (!validValues.includes(config.pruningSummary)) { - errors.push({ key: 'pruningSummary', expected: '"off" | "minimal" | "detailed"', actual: JSON.stringify(config.pruningSummary) }) + if (!validValues.includes(config.pruneNotification)) { + errors.push({ key: 'pruneNotification', expected: '"off" | "minimal" | "detailed"', actual: JSON.stringify(config.pruneNotification) }) + } + } + + // Top-level turnProtection validator + if (config.turnProtection) { + if (config.turnProtection.enabled !== undefined && typeof config.turnProtection.enabled !== 'boolean') { + errors.push({ key: 'turnProtection.enabled', expected: 'boolean', actual: typeof config.turnProtection.enabled }) + } + if (config.turnProtection.turns !== undefined && typeof config.turnProtection.turns !== 'number') { + errors.push({ key: 'turnProtection.turns', expected: 'number', actual: typeof config.turnProtection.turns }) + } + } + + // Tools validators + const tools = config.tools + if (tools) { + if (tools.settings) { + if (tools.settings.nudgeEnabled !== undefined && typeof tools.settings.nudgeEnabled !== 'boolean') { + errors.push({ key: 'tools.settings.nudgeEnabled', expected: 'boolean', actual: typeof tools.settings.nudgeEnabled }) + } + if (tools.settings.nudgeFrequency !== undefined && typeof tools.settings.nudgeFrequency !== 'number') { + errors.push({ key: 'tools.settings.nudgeFrequency', expected: 'number', actual: typeof tools.settings.nudgeFrequency }) + } + if (tools.settings.protectedTools !== undefined && !Array.isArray(tools.settings.protectedTools)) { + errors.push({ key: 'tools.settings.protectedTools', expected: 'string[]', actual: typeof tools.settings.protectedTools }) + } + } + if (tools.discard) { + if (tools.discard.enabled !== undefined && typeof tools.discard.enabled !== 'boolean') { + errors.push({ key: 'tools.discard.enabled', expected: 'boolean', actual: typeof tools.discard.enabled }) + } + } + if (tools.extract) { + if (tools.extract.enabled !== undefined && typeof tools.extract.enabled !== 'boolean') { + errors.push({ key: 'tools.extract.enabled', expected: 'boolean', actual: typeof tools.extract.enabled }) + } + if (tools.extract.showDistillation !== undefined && typeof tools.extract.showDistillation !== 'boolean') { + errors.push({ key: 'tools.extract.showDistillation', expected: 'boolean', actual: typeof tools.extract.showDistillation }) + } } } @@ -186,61 +211,6 @@ function validateConfigTypes(config: Record): ValidationError[] { } } - // discardTool - if (strategies.discardTool) { - if (strategies.discardTool.enabled !== undefined && typeof strategies.discardTool.enabled !== 'boolean') { - errors.push({ key: 'strategies.discardTool.enabled', expected: 'boolean', actual: typeof strategies.discardTool.enabled }) - } - if (strategies.discardTool.protectedTools !== undefined && !Array.isArray(strategies.discardTool.protectedTools)) { - errors.push({ key: 'strategies.discardTool.protectedTools', expected: 'string[]', actual: typeof strategies.discardTool.protectedTools }) - } - if (strategies.discardTool.turnProtection) { - if (strategies.discardTool.turnProtection.enabled !== undefined && typeof strategies.discardTool.turnProtection.enabled !== 'boolean') { - errors.push({ key: 'strategies.discardTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.discardTool.turnProtection.enabled }) - } - if (strategies.discardTool.turnProtection.turns !== undefined && typeof strategies.discardTool.turnProtection.turns !== 'number') { - errors.push({ key: 'strategies.discardTool.turnProtection.turns', expected: 'number', actual: typeof strategies.discardTool.turnProtection.turns }) - } - } - if (strategies.discardTool.nudge) { - if (strategies.discardTool.nudge.enabled !== undefined && typeof strategies.discardTool.nudge.enabled !== 'boolean') { - errors.push({ key: 'strategies.discardTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.discardTool.nudge.enabled }) - } - if (strategies.discardTool.nudge.frequency !== undefined && typeof strategies.discardTool.nudge.frequency !== 'number') { - errors.push({ key: 'strategies.discardTool.nudge.frequency', expected: 'number', actual: typeof strategies.discardTool.nudge.frequency }) - } - } - } - - // extractTool - if (strategies.extractTool) { - if (strategies.extractTool.enabled !== undefined && typeof strategies.extractTool.enabled !== 'boolean') { - errors.push({ key: 'strategies.extractTool.enabled', expected: 'boolean', actual: typeof strategies.extractTool.enabled }) - } - if (strategies.extractTool.protectedTools !== undefined && !Array.isArray(strategies.extractTool.protectedTools)) { - errors.push({ key: 'strategies.extractTool.protectedTools', expected: 'string[]', actual: typeof strategies.extractTool.protectedTools }) - } - if (strategies.extractTool.turnProtection) { - if (strategies.extractTool.turnProtection.enabled !== undefined && typeof strategies.extractTool.turnProtection.enabled !== 'boolean') { - errors.push({ key: 'strategies.extractTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.extractTool.turnProtection.enabled }) - } - if (strategies.extractTool.turnProtection.turns !== undefined && typeof strategies.extractTool.turnProtection.turns !== 'number') { - errors.push({ key: 'strategies.extractTool.turnProtection.turns', expected: 'number', actual: typeof strategies.extractTool.turnProtection.turns }) - } - } - if (strategies.extractTool.nudge) { - if (strategies.extractTool.nudge.enabled !== undefined && typeof strategies.extractTool.nudge.enabled !== 'boolean') { - errors.push({ key: 'strategies.extractTool.nudge.enabled', expected: 'boolean', actual: typeof strategies.extractTool.nudge.enabled }) - } - if (strategies.extractTool.nudge.frequency !== undefined && typeof strategies.extractTool.nudge.frequency !== 'number') { - errors.push({ key: 'strategies.extractTool.nudge.frequency', expected: 'number', actual: typeof strategies.extractTool.nudge.frequency }) - } - } - if (strategies.extractTool.showDistillation !== undefined && typeof strategies.extractTool.showDistillation !== 'boolean') { - errors.push({ key: 'strategies.extractTool.showDistillation', expected: 'boolean', actual: typeof strategies.extractTool.showDistillation }) - } - } - // supersedeWrites if (strategies.supersedeWrites) { if (strategies.supersedeWrites.enabled !== undefined && typeof strategies.supersedeWrites.enabled !== 'boolean') { @@ -301,7 +271,25 @@ function showConfigValidationWarnings( const defaultConfig: PluginConfig = { enabled: true, debug: false, - pruningSummary: 'detailed', + pruneNotification: 'detailed', + turnProtection: { + enabled: false, + turns: 4 + }, + tools: { + settings: { + nudgeEnabled: true, + nudgeFrequency: 10, + protectedTools: [...DEFAULT_PROTECTED_TOOLS] + }, + discard: { + enabled: true + }, + extract: { + enabled: true, + showDistillation: false + } + }, strategies: { deduplication: { enabled: true, @@ -310,31 +298,6 @@ const defaultConfig: PluginConfig = { supersedeWrites: { enabled: true }, - discardTool: { - enabled: true, - protectedTools: [...DEFAULT_PROTECTED_TOOLS], - turnProtection: { - enabled: false, - turns: 4 - }, - nudge: { - enabled: true, - frequency: 10 - } - }, - extractTool: { - enabled: true, - protectedTools: [...DEFAULT_PROTECTED_TOOLS], - turnProtection: { - enabled: false, - turns: 4 - }, - nudge: { - enabled: true, - frequency: 10 - }, - showDistillation: false - }, onIdle: { enabled: false, protectedTools: [...DEFAULT_PROTECTED_TOOLS], @@ -412,9 +375,35 @@ function createDefaultConfig(): void { "enabled": true, // Enable debug logging to ~/.config/opencode/logs/dcp/ "debug": false, - // Summary display: "off", "minimal", or "detailed" - "pruningSummary": "detailed", - // Strategies for pruning tokens from chat history + // Notification display: "off", "minimal", or "detailed" + "pruneNotification": "detailed", + // Protect from pruning for message turns + "turnProtection": { + "enabled": false, + "turns": 4 + }, + // LLM-driven context pruning tools + "tools": { + // Shared settings for all prune tools + "settings": { + // Nudge the LLM to use prune tools (every tool results) + "nudgeEnabled": true, + "nudgeFrequency": 10, + // Additional tools to protect from pruning + "protectedTools": [] + }, + // Removes tool content from context without preservation (for completed tasks or noise) + "discard": { + "enabled": true + }, + // Distills key findings into preserved knowledge before removing raw content + "extract": { + "enabled": true, + // Show distillation content as an ignored message notification + "showDistillation": false + } + }, + // Automatic pruning strategies "strategies": { // Remove duplicate tool calls (same tool with same arguments) "deduplication": { @@ -426,40 +415,6 @@ function createDefaultConfig(): void { "supersedeWrites": { "enabled": true }, - // Removes tool content from context without preservation (for completed tasks or noise) - "discardTool": { - "enabled": true, - // Additional tools to protect from pruning - "protectedTools": [], - // Protect from pruning for message turns - "turnProtection": { - "enabled": false, - "turns": 4 - }, - // Nudge the LLM to use the discard tool (every tool results) - "nudge": { - "enabled": true, - "frequency": 10 - } - }, - // Distills key findings into preserved knowledge before removing raw content - "extractTool": { - "enabled": true, - // Additional tools to protect from pruning - "protectedTools": [], - // Protect from pruning for message turns - "turnProtection": { - "enabled": false, - "turns": 4 - }, - // Nudge the LLM to use the extract tool (every tool results) - "nudge": { - "enabled": true, - "frequency": 10 - }, - // Show distillation content as an ignored message notification - "showDistillation": false - }, // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle "onIdle": { "enabled": false, @@ -531,43 +486,35 @@ function mergeStrategies( ]) ] }, - discardTool: { - enabled: override.discardTool?.enabled ?? base.discardTool.enabled, + supersedeWrites: { + enabled: override.supersedeWrites?.enabled ?? base.supersedeWrites.enabled + } + } +} + +function mergeTools( + base: PluginConfig['tools'], + override?: Partial +): PluginConfig['tools'] { + if (!override) return base + + return { + settings: { + nudgeEnabled: override.settings?.nudgeEnabled ?? base.settings.nudgeEnabled, + nudgeFrequency: override.settings?.nudgeFrequency ?? base.settings.nudgeFrequency, protectedTools: [ ...new Set([ - ...base.discardTool.protectedTools, - ...(override.discardTool?.protectedTools ?? []) + ...base.settings.protectedTools, + ...(override.settings?.protectedTools ?? []) ]) - ], - turnProtection: { - enabled: override.discardTool?.turnProtection?.enabled ?? base.discardTool.turnProtection.enabled, - turns: override.discardTool?.turnProtection?.turns ?? base.discardTool.turnProtection.turns - }, - nudge: { - enabled: override.discardTool?.nudge?.enabled ?? base.discardTool.nudge.enabled, - frequency: override.discardTool?.nudge?.frequency ?? base.discardTool.nudge.frequency - } + ] }, - extractTool: { - enabled: override.extractTool?.enabled ?? base.extractTool.enabled, - protectedTools: [ - ...new Set([ - ...base.extractTool.protectedTools, - ...(override.extractTool?.protectedTools ?? []) - ]) - ], - turnProtection: { - enabled: override.extractTool?.turnProtection?.enabled ?? base.extractTool.turnProtection.enabled, - turns: override.extractTool?.turnProtection?.turns ?? base.extractTool.turnProtection.turns - }, - nudge: { - enabled: override.extractTool?.nudge?.enabled ?? base.extractTool.nudge.enabled, - frequency: override.extractTool?.nudge?.frequency ?? base.extractTool.nudge.frequency - }, - showDistillation: override.extractTool?.showDistillation ?? base.extractTool.showDistillation + discard: { + enabled: override.discard?.enabled ?? base.discard.enabled }, - supersedeWrites: { - enabled: override.supersedeWrites?.enabled ?? base.supersedeWrites.enabled + extract: { + enabled: override.extract?.enabled ?? base.extract.enabled, + showDistillation: override.extract?.showDistillation ?? base.extract.showDistillation } } } @@ -575,6 +522,15 @@ function mergeStrategies( function deepCloneConfig(config: PluginConfig): PluginConfig { return { ...config, + turnProtection: { ...config.turnProtection }, + tools: { + settings: { + ...config.tools.settings, + protectedTools: [...config.tools.settings.protectedTools] + }, + discard: { ...config.tools.discard }, + extract: { ...config.tools.extract } + }, strategies: { deduplication: { ...config.strategies.deduplication, @@ -584,19 +540,6 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { ...config.strategies.onIdle, protectedTools: [...config.strategies.onIdle.protectedTools] }, - discardTool: { - ...config.strategies.discardTool, - protectedTools: [...config.strategies.discardTool.protectedTools], - turnProtection: { ...config.strategies.discardTool.turnProtection }, - nudge: { ...config.strategies.discardTool.nudge } - }, - extractTool: { - ...config.strategies.extractTool, - protectedTools: [...config.strategies.extractTool.protectedTools], - turnProtection: { ...config.strategies.extractTool.turnProtection }, - nudge: { ...config.strategies.extractTool.nudge }, - showDistillation: config.strategies.extractTool.showDistillation - }, supersedeWrites: { ...config.strategies.supersedeWrites } @@ -631,7 +574,12 @@ export function getConfig(ctx: PluginInput): PluginConfig { config = { enabled: result.data.enabled ?? config.enabled, debug: result.data.debug ?? config.debug, - pruningSummary: result.data.pruningSummary ?? config.pruningSummary, + pruneNotification: result.data.pruneNotification ?? config.pruneNotification, + turnProtection: { + enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + }, + tools: mergeTools(config.tools, result.data.tools as any), strategies: mergeStrategies(config.strategies, result.data.strategies as any) } } @@ -662,7 +610,12 @@ export function getConfig(ctx: PluginInput): PluginConfig { config = { enabled: result.data.enabled ?? config.enabled, debug: result.data.debug ?? config.debug, - pruningSummary: result.data.pruningSummary ?? config.pruningSummary, + pruneNotification: result.data.pruneNotification ?? config.pruneNotification, + turnProtection: { + enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + }, + tools: mergeTools(config.tools, result.data.tools as any), strategies: mergeStrategies(config.strategies, result.data.strategies as any) } } @@ -690,7 +643,12 @@ export function getConfig(ctx: PluginInput): PluginConfig { config = { enabled: result.data.enabled ?? config.enabled, debug: result.data.debug ?? config.debug, - pruningSummary: result.data.pruningSummary ?? config.pruningSummary, + pruneNotification: result.data.pruneNotification ?? config.pruneNotification, + turnProtection: { + enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + }, + tools: mergeTools(config.tools, result.data.tools as any), strategies: mergeStrategies(config.strategies, result.data.strategies as any) } } From 064388874da8cab4e0ebf708e896d75d865957a5 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 18:55:21 -0500 Subject: [PATCH 27/43] refactor: update all consumers to use new config paths --- index.ts | 12 ++++++------ lib/messages/prune.ts | 23 +++++++---------------- lib/state/tool-cache.ts | 13 +++---------- lib/strategies/tools.ts | 7 ++----- lib/ui/notification.ts | 4 ++-- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/index.ts b/index.ts index 770c5a6b..d5f60de4 100644 --- a/index.ts +++ b/index.ts @@ -27,8 +27,8 @@ const plugin: Plugin = (async (ctx) => { return { "experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => { - const discardEnabled = config.strategies.discardTool.enabled - const extractEnabled = config.strategies.extractTool.enabled + const discardEnabled = config.tools.discard.enabled + const extractEnabled = config.tools.extract.enabled let promptName: string if (discardEnabled && extractEnabled) { @@ -51,7 +51,7 @@ const plugin: Plugin = (async (ctx) => { config ), tool: { - ...(config.strategies.discardTool.enabled && { + ...(config.tools.discard.enabled && { discard: createDiscardTool({ client: ctx.client, state, @@ -60,7 +60,7 @@ const plugin: Plugin = (async (ctx) => { workingDirectory: ctx.directory }), }), - ...(config.strategies.extractTool.enabled && { + ...(config.tools.extract.enabled && { extract: createExtractTool({ client: ctx.client, state, @@ -74,8 +74,8 @@ const plugin: Plugin = (async (ctx) => { // Add enabled tools to primary_tools by mutating the opencode config // This works because config is cached and passed by reference const toolsToAdd: string[] = [] - if (config.strategies.discardTool.enabled) toolsToAdd.push("discard") - if (config.strategies.extractTool.enabled) toolsToAdd.push("extract") + if (config.tools.discard.enabled) toolsToAdd.push("discard") + if (config.tools.extract.enabled) toolsToAdd.push("extract") if (toolsToAdd.length > 0) { const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? [] diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 0257afc9..05afc0ea 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -9,8 +9,8 @@ import { UserMessage } from "@opencode-ai/sdk" const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]' const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]' const getNudgeString = (config: PluginConfig): string => { - const discardEnabled = config.strategies.discardTool.enabled - const extractEnabled = config.strategies.extractTool.enabled + const discardEnabled = config.tools.discard.enabled + const extractEnabled = config.tools.extract.enabled if (discardEnabled && extractEnabled) { return loadPrompt("nudge/nudge-both") @@ -28,8 +28,8 @@ ${content} ` const getCooldownMessage = (config: PluginConfig): string => { - const discardEnabled = config.strategies.discardTool.enabled - const extractEnabled = config.strategies.extractTool.enabled + const discardEnabled = config.tools.discard.enabled + const extractEnabled = config.tools.extract.enabled let toolName: string if (discardEnabled && extractEnabled) { @@ -61,10 +61,7 @@ const buildPrunableToolsList = ( if (state.prune.toolIds.includes(toolCallId)) { return } - const allProtectedTools = [ - ...config.strategies.discardTool.protectedTools, - ...config.strategies.extractTool.protectedTools - ] + const allProtectedTools = config.tools.settings.protectedTools if (allProtectedTools.includes(toolParameterEntry.tool)) { return } @@ -92,7 +89,7 @@ export const insertPruneToolContext = ( logger: Logger, messages: WithParts[] ): void => { - if (!config.strategies.discardTool.enabled && !config.strategies.extractTool.enabled) { + if (!config.tools.discard.enabled && !config.tools.extract.enabled) { return } @@ -115,13 +112,7 @@ export const insertPruneToolContext = ( logger.debug("prunable-tools: \n" + prunableToolsList) let nudgeString = "" - // TODO: Using Math.min() means the lower frequency dominates when both tools are enabled. - // Consider using separate counters for each tool's nudge, or documenting this behavior. - const nudgeFrequency = Math.min( - config.strategies.discardTool.nudge.frequency, - config.strategies.extractTool.nudge.frequency - ) - if (state.nudgeCounter >= nudgeFrequency) { + if (config.tools.settings.nudgeEnabled && state.nudgeCounter >= config.tools.settings.nudgeFrequency) { logger.info("Inserting prune nudge message") nudgeString = "\n" + getNudgeString(config) } diff --git a/lib/state/tool-cache.ts b/lib/state/tool-cache.ts index 6e2650b9..bc94efef 100644 --- a/lib/state/tool-cache.ts +++ b/lib/state/tool-cache.ts @@ -35,22 +35,15 @@ export async function syncToolCache( continue } - const turnProtectionEnabled = config.strategies.discardTool.turnProtection.enabled || - config.strategies.extractTool.turnProtection.enabled - const turnProtectionTurns = Math.max( - config.strategies.discardTool.turnProtection.turns, - config.strategies.extractTool.turnProtection.turns - ) + const turnProtectionEnabled = config.turnProtection.enabled + const turnProtectionTurns = config.turnProtection.turns const isProtectedByTurn = turnProtectionEnabled && turnProtectionTurns > 0 && (state.currentTurn - turnCounter) < turnProtectionTurns state.lastToolPrune = part.tool === "discard" || part.tool === "extract" - const allProtectedTools = [ - ...config.strategies.discardTool.protectedTools, - ...config.strategies.extractTool.protectedTools - ] + const allProtectedTools = config.tools.settings.protectedTools if (part.tool === "discard" || part.tool === "extract") { state.nudgeCounter = 0 diff --git a/lib/strategies/tools.ts b/lib/strategies/tools.ts index b11eb2e9..31502f8a 100644 --- a/lib/strategies/tools.ts +++ b/lib/strategies/tools.ts @@ -76,10 +76,7 @@ async function executePruneOperation( logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id }) return "Invalid IDs provided. Only use numeric IDs from the list." } - const allProtectedTools = [ - ...config.strategies.discardTool.protectedTools, - ...config.strategies.extractTool.protectedTools - ] + const allProtectedTools = config.tools.settings.protectedTools if (allProtectedTools.includes(metadata.tool)) { logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool }) return "Invalid IDs provided. Only use numeric IDs from the list." @@ -114,7 +111,7 @@ async function executePruneOperation( workingDirectory ) - if (distillation && config.strategies.extractTool.showDistillation) { + if (distillation && config.tools.extract.showDistillation) { await sendDistillationNotification( client, logger, diff --git a/lib/ui/notification.ts b/lib/ui/notification.ts index 079d582d..60844e9f 100644 --- a/lib/ui/notification.ts +++ b/lib/ui/notification.ts @@ -70,11 +70,11 @@ export async function sendUnifiedNotification( return false } - if (config.pruningSummary === 'off') { + if (config.pruneNotification === 'off') { return false } - const message = config.pruningSummary === 'minimal' + const message = config.pruneNotification === 'minimal' ? buildMinimalMessage(state, reason) : buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory) From 7136d20e725d5cbd37874c654f7e52b9a056b342 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 18:55:25 -0500 Subject: [PATCH 28/43] docs: update README with new config schema --- README.md | 75 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 7a1aa276..dae9525b 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,35 @@ DCP uses its own config file: "enabled": true, // Enable debug logging to ~/.config/opencode/logs/dcp/ "debug": false, - // Summary display: "off", "minimal", or "detailed" - "pruningSummary": "detailed", - // Strategies for pruning tokens from chat history + // Notification display: "off", "minimal", or "detailed" + "pruneNotification": "detailed", + // Protect from pruning for message turns + "turnProtection": { + "enabled": false, + "turns": 4 + }, + // LLM-driven context pruning tools + "tools": { + // Shared settings for all prune tools + "settings": { + // Nudge the LLM to use prune tools (every tool results) + "nudgeEnabled": true, + "nudgeFrequency": 10, + // Additional tools to protect from pruning + "protectedTools": [] + }, + // Removes tool content from context without preservation (for completed tasks or noise) + "discard": { + "enabled": true + }, + // Distills key findings into preserved knowledge before removing raw content + "extract": { + "enabled": true, + // Show distillation content as an ignored message notification + "showDistillation": false + } + }, + // Automatic pruning strategies "strategies": { // Remove duplicate tool calls (same tool with same arguments) "deduplication": { @@ -74,40 +100,6 @@ DCP uses its own config file: "supersedeWrites": { "enabled": true }, - // Removes tool content from context without preservation (for completed tasks or noise) - "discardTool": { - "enabled": true, - // Additional tools to protect from pruning - "protectedTools": [], - // Protect from pruning for message turns - "turnProtection": { - "enabled": false, - "turns": 4 - }, - // Nudge the LLM to use the discard tool (every tool results) - "nudge": { - "enabled": true, - "frequency": 10 - } - }, - // Distills key findings into preserved knowledge before removing raw content - "extractTool": { - "enabled": true, - // Additional tools to protect from pruning - "protectedTools": [], - // Protect from pruning for message turns - "turnProtection": { - "enabled": false, - "turns": 4 - }, - // Nudge the LLM to use the extract tool (every tool results) - "nudge": { - "enabled": true, - "frequency": 10 - }, - // Show distillation content as an ignored message notification - "showDistillation": false - }, // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle "onIdle": { "enabled": false, @@ -126,12 +118,19 @@ DCP uses its own config file: +### Turn Protection + +When enabled, turn protection prevents tool outputs from being pruned for a configurable number of message turns. This gives the AI time to reference recent tool outputs before they become prunable. Applies to both `discard` and `extract` tools, as well as automatic strategies. + ### Protected Tools By default, these tools are always protected from pruning across all strategies: `task`, `todowrite`, `todoread`, `discard`, `extract`, `batch` -The `protectedTools` arrays in each strategy add to this default list. +The `protectedTools` arrays in each section add to this default list: +- `tools.settings.protectedTools` — Protects tools from the `discard` and `extract` tools +- `strategies.deduplication.protectedTools` — Protects tools from deduplication +- `strategies.onIdle.protectedTools` — Protects tools from on-idle analysis ### Config Precedence From a36c6505075dd6a9cca4c4c6eece9b64ea24853a Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 20:25:53 -0500 Subject: [PATCH 29/43] fix: correctly prune edit tool inputs (oldString/newString instead of content) --- lib/messages/prune.ts | 11 ++++++++++- lib/strategies/utils.ts | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 05afc0ea..c59411c5 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -206,9 +206,18 @@ const pruneToolInputs = ( continue } - if (part.state.input?.content !== undefined) { + // Write tool has content field, edit tool has oldString/newString fields + if (part.tool === 'write' && part.state.input?.content !== undefined) { part.state.input.content = PRUNED_TOOL_INPUT_REPLACEMENT } + if (part.tool === 'edit') { + if (part.state.input?.oldString !== undefined) { + part.state.input.oldString = PRUNED_TOOL_INPUT_REPLACEMENT + } + if (part.state.input?.newString !== undefined) { + part.state.input.newString = PRUNED_TOOL_INPUT_REPLACEMENT + } + } } } } diff --git a/lib/strategies/utils.ts b/lib/strategies/utils.ts index ca610beb..7a675fbc 100644 --- a/lib/strategies/utils.ts +++ b/lib/strategies/utils.ts @@ -55,7 +55,7 @@ export const calculateTokensSaved = ( } // For write and edit tools, count input content as that is all we prune for these tools // (input is present in both completed and error states) - if (part.tool === "write" || part.tool === "edit") { + if (part.tool === "write") { const inputContent = part.state.input?.content const content = typeof inputContent === 'string' ? inputContent @@ -63,6 +63,17 @@ export const calculateTokensSaved = ( contents.push(content) continue } + if (part.tool === "edit") { + const oldString = part.state.input?.oldString + const newString = part.state.input?.newString + if (typeof oldString === 'string') { + contents.push(oldString) + } + if (typeof newString === 'string') { + contents.push(newString) + } + continue + } // For other tools, count output or error based on status if (part.state.status === "completed") { const content = typeof part.state.output === 'string' From 28fb22c0fffb74e651b695d218276c2c143e0a50 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 21:17:31 -0500 Subject: [PATCH 30/43] chore: add prettier for code formatting - add .prettierrc with project style rules - add format and format:check scripts to package.json - add format check step to PR workflow --- .github/workflows/pr-checks.yml | 59 +- .prettierrc | 10 + package-lock.json | 4627 ++++++++++++++++--------------- package.json | 119 +- 4 files changed, 2424 insertions(+), 2391 deletions(-) create mode 100644 .prettierrc diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index e665cfc2..124c9091 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,33 +1,36 @@ name: PR Checks on: - pull_request: - branches: [master, dev] + pull_request: + branches: [master, dev] jobs: - validate: - name: Type Check, Build & Audit - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: 'npm' - - - name: Install dependencies - run: npm ci - - - name: Type check - run: npm run typecheck - - - name: Build - run: npm run build - - - name: Security audit - run: npm audit --audit-level=high - continue-on-error: false + validate: + name: Type Check, Build & Audit + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Format check + run: npm run format:check + + - name: Type check + run: npm run typecheck + + - name: Build + run: npm run build + + - name: Security audit + run: npm audit --audit-level=high + continue-on-error: false diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..3325b6e8 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "semi": false, + "singleQuote": false, + "tabWidth": 4, + "useTabs": false, + "trailingComma": "all", + "printWidth": 100, + "bracketSpacing": true, + "arrowParens": "always" +} diff --git a/package-lock.json b/package-lock.json index e3912475..5ae4a91f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,2309 +1,2326 @@ { - "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", - "license": "MIT", - "dependencies": { - "@ai-sdk/openai-compatible": "^1.0.28", - "@opencode-ai/sdk": "latest", - "@tarquinen/opencode-auth-provider": "^0.1.7", - "ai": "^5.0.106", - "gpt-tokenizer": "^3.4.0", - "jsonc-parser": "^3.3.1", - "zod": "^4.1.13" - }, - "devDependencies": { - "@opencode-ai/plugin": "^1.0.143", - "@types/node": "^24.10.1", - "tsx": "^4.21.0", - "typescript": "^5.9.3" - }, - "peerDependencies": { - "@opencode-ai/plugin": ">=0.13.7" - } - }, - "node_modules/@ai-sdk/gateway": { - "version": "2.0.18", - "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-2.0.18.tgz", - "integrity": "sha512-sDQcW+6ck2m0pTIHW6BPHD7S125WD3qNkx/B8sEzJp/hurocmJ5Cni0ybExg6sQMGo+fr/GWOwpHF1cmCdg5rQ==", - "license": "Apache-2.0", - "dependencies": { - "@ai-sdk/provider": "2.0.0", - "@ai-sdk/provider-utils": "3.0.18", - "@vercel/oidc": "3.0.5" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "zod": "^3.25.76 || ^4.1.8" - } - }, - "node_modules/@ai-sdk/openai-compatible": { - "version": "1.0.28", - "resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-1.0.28.tgz", - "integrity": "sha512-yKubDxLYtXyGUzkr9lNStf/lE/I+Okc8tmotvyABhsQHHieLKk6oV5fJeRJxhr67Ejhg+FRnwUOxAmjRoFM4dA==", - "license": "Apache-2.0", - "dependencies": { - "@ai-sdk/provider": "2.0.0", - "@ai-sdk/provider-utils": "3.0.18" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "zod": "^3.25.76 || ^4.1.8" - } - }, - "node_modules/@ai-sdk/provider": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-2.0.0.tgz", - "integrity": "sha512-6o7Y2SeO9vFKB8lArHXehNuusnpddKPk7xqL7T2/b+OvXMRIXUO1rR4wcv1hAFUAT9avGZshty3Wlua/XA7TvA==", - "license": "Apache-2.0", - "dependencies": { - "json-schema": "^0.4.0" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@ai-sdk/provider-utils": { - "version": "3.0.18", - "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-3.0.18.tgz", - "integrity": "sha512-ypv1xXMsgGcNKUP+hglKqtdDuMg68nWHucPPAhIENrbFAI+xCHiqPVN8Zllxyv1TNZwGWUghPxJXU+Mqps0YRQ==", - "license": "Apache-2.0", - "dependencies": { - "@ai-sdk/provider": "2.0.0", - "@standard-schema/spec": "^1.0.0", - "eventsource-parser": "^3.0.6" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "zod": "^3.25.76 || ^4.1.8" - } - }, - "node_modules/@aws-crypto/sha256-browser": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-5.2.0.tgz", - "integrity": "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-crypto/sha256-js": "^5.2.0", - "@aws-crypto/supports-web-crypto": "^5.2.0", - "@aws-crypto/util": "^5.2.0", - "@aws-sdk/types": "^3.222.0", - "@aws-sdk/util-locate-window": "^3.0.0", - "@smithy/util-utf8": "^2.0.0", - "tslib": "^2.6.2" - } - }, - "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/is-array-buffer": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", - "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-buffer-from": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", - "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/is-array-buffer": "^2.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-utf8": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", - "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/util-buffer-from": "^2.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-crypto/sha256-js": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", - "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", - "license": "Apache-2.0", - "dependencies": { - "@aws-crypto/util": "^5.2.0", - "@aws-sdk/types": "^3.222.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=16.0.0" - } - }, - "node_modules/@aws-crypto/supports-web-crypto": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-5.2.0.tgz", - "integrity": "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - } - }, - "node_modules/@aws-crypto/util": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", - "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "^3.222.0", - "@smithy/util-utf8": "^2.0.0", - "tslib": "^2.6.2" - } - }, - "node_modules/@aws-crypto/util/node_modules/@smithy/is-array-buffer": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", - "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-crypto/util/node_modules/@smithy/util-buffer-from": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", - "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/is-array-buffer": "^2.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-crypto/util/node_modules/@smithy/util-utf8": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", - "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/util-buffer-from": "^2.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/@aws-sdk/client-cognito-identity": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.943.0.tgz", - "integrity": "sha512-XkuokRF2IQ+VLBn0AwrwfFOkZ2c1IXACwQdn3CDnpBZpT1s2hgH3MX0DoH9+41w4ar2QCSI09uAJiv9PX4DLoQ==", - "license": "Apache-2.0", - "dependencies": { - "@aws-crypto/sha256-browser": "5.2.0", - "@aws-crypto/sha256-js": "5.2.0", - "@aws-sdk/core": "3.943.0", - "@aws-sdk/credential-provider-node": "3.943.0", - "@aws-sdk/middleware-host-header": "3.936.0", - "@aws-sdk/middleware-logger": "3.936.0", - "@aws-sdk/middleware-recursion-detection": "3.936.0", - "@aws-sdk/middleware-user-agent": "3.943.0", - "@aws-sdk/region-config-resolver": "3.936.0", - "@aws-sdk/types": "3.936.0", - "@aws-sdk/util-endpoints": "3.936.0", - "@aws-sdk/util-user-agent-browser": "3.936.0", - "@aws-sdk/util-user-agent-node": "3.943.0", - "@smithy/config-resolver": "^4.4.3", - "@smithy/core": "^3.18.5", - "@smithy/fetch-http-handler": "^5.3.6", - "@smithy/hash-node": "^4.2.5", - "@smithy/invalid-dependency": "^4.2.5", - "@smithy/middleware-content-length": "^4.2.5", - "@smithy/middleware-endpoint": "^4.3.12", - "@smithy/middleware-retry": "^4.4.12", - "@smithy/middleware-serde": "^4.2.6", - "@smithy/middleware-stack": "^4.2.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/node-http-handler": "^4.4.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/smithy-client": "^4.9.8", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-body-length-browser": "^4.2.0", - "@smithy/util-body-length-node": "^4.2.1", - "@smithy/util-defaults-mode-browser": "^4.3.11", - "@smithy/util-defaults-mode-node": "^4.2.14", - "@smithy/util-endpoints": "^3.2.5", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-retry": "^4.2.5", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/client-sso": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.943.0.tgz", - "integrity": "sha512-kOTO2B8Ks2qX73CyKY8PAajtf5n39aMe2spoiOF5EkgSzGV7hZ/HONRDyADlyxwfsX39Q2F2SpPUaXzon32IGw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-crypto/sha256-browser": "5.2.0", - "@aws-crypto/sha256-js": "5.2.0", - "@aws-sdk/core": "3.943.0", - "@aws-sdk/middleware-host-header": "3.936.0", - "@aws-sdk/middleware-logger": "3.936.0", - "@aws-sdk/middleware-recursion-detection": "3.936.0", - "@aws-sdk/middleware-user-agent": "3.943.0", - "@aws-sdk/region-config-resolver": "3.936.0", - "@aws-sdk/types": "3.936.0", - "@aws-sdk/util-endpoints": "3.936.0", - "@aws-sdk/util-user-agent-browser": "3.936.0", - "@aws-sdk/util-user-agent-node": "3.943.0", - "@smithy/config-resolver": "^4.4.3", - "@smithy/core": "^3.18.5", - "@smithy/fetch-http-handler": "^5.3.6", - "@smithy/hash-node": "^4.2.5", - "@smithy/invalid-dependency": "^4.2.5", - "@smithy/middleware-content-length": "^4.2.5", - "@smithy/middleware-endpoint": "^4.3.12", - "@smithy/middleware-retry": "^4.4.12", - "@smithy/middleware-serde": "^4.2.6", - "@smithy/middleware-stack": "^4.2.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/node-http-handler": "^4.4.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/smithy-client": "^4.9.8", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-body-length-browser": "^4.2.0", - "@smithy/util-body-length-node": "^4.2.1", - "@smithy/util-defaults-mode-browser": "^4.3.11", - "@smithy/util-defaults-mode-node": "^4.2.14", - "@smithy/util-endpoints": "^3.2.5", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-retry": "^4.2.5", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/core": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.943.0.tgz", - "integrity": "sha512-8CBy2hI9ABF7RBVQuY1bgf/ue+WPmM/hl0adrXFlhnhkaQP0tFY5zhiy1Y+n7V+5f3/ORoHBmCCQmcHDDYJqJQ==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@aws-sdk/xml-builder": "3.930.0", - "@smithy/core": "^3.18.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/signature-v4": "^5.3.5", - "@smithy/smithy-client": "^4.9.8", - "@smithy/types": "^4.9.0", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-cognito-identity": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-cognito-identity/-/credential-provider-cognito-identity-3.943.0.tgz", - "integrity": "sha512-jZJ0uHjNlhfjx2ZX7YVYnh1wfSkLAvQmecGCSl9C6LJRNXy4uWFPbGjPqcA0tWp0WWIsUYhqjasgvCOMZIY8nw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/client-cognito-identity": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-env": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.943.0.tgz", - "integrity": "sha512-WnS5w9fK9CTuoZRVSIHLOMcI63oODg9qd1vXMYb7QGLGlfwUm4aG3hdu7i9XvYrpkQfE3dzwWLtXF4ZBuL1Tew==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-http": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.943.0.tgz", - "integrity": "sha512-SA8bUcYDEACdhnhLpZNnWusBpdmj4Vl67Vxp3Zke7SvoWSYbuxa+tiDiC+c92Z4Yq6xNOuLPW912ZPb9/NsSkA==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/fetch-http-handler": "^5.3.6", - "@smithy/node-http-handler": "^4.4.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/smithy-client": "^4.9.8", - "@smithy/types": "^4.9.0", - "@smithy/util-stream": "^4.5.6", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-ini": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.943.0.tgz", - "integrity": "sha512-BcLDb8l4oVW+NkuqXMlO7TnM6lBOWW318ylf4FRED/ply5eaGxkQYqdGvHSqGSN5Rb3vr5Ek0xpzSjeYD7C8Kw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/credential-provider-env": "3.943.0", - "@aws-sdk/credential-provider-http": "3.943.0", - "@aws-sdk/credential-provider-login": "3.943.0", - "@aws-sdk/credential-provider-process": "3.943.0", - "@aws-sdk/credential-provider-sso": "3.943.0", - "@aws-sdk/credential-provider-web-identity": "3.943.0", - "@aws-sdk/nested-clients": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/credential-provider-imds": "^4.2.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-login": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.943.0.tgz", - "integrity": "sha512-9iCOVkiRW+evxiJE94RqosCwRrzptAVPhRhGWv4osfYDhjNAvUMyrnZl3T1bjqCoKNcETRKEZIU3dqYHnUkcwQ==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/nested-clients": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-node": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.943.0.tgz", - "integrity": "sha512-14eddaH/gjCWoLSAELVrFOQNyswUYwWphIt+PdsJ/FqVfP4ay2HsiZVEIYbQtmrKHaoLJhiZKwBQRjcqJDZG0w==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/credential-provider-env": "3.943.0", - "@aws-sdk/credential-provider-http": "3.943.0", - "@aws-sdk/credential-provider-ini": "3.943.0", - "@aws-sdk/credential-provider-process": "3.943.0", - "@aws-sdk/credential-provider-sso": "3.943.0", - "@aws-sdk/credential-provider-web-identity": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/credential-provider-imds": "^4.2.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-process": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.943.0.tgz", - "integrity": "sha512-GIY/vUkthL33AdjOJ8r9vOosKf/3X+X7LIiACzGxvZZrtoOiRq0LADppdiKIB48vTL63VvW+eRIOFAxE6UDekw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-sso": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.943.0.tgz", - "integrity": "sha512-1c5G11syUrru3D9OO6Uk+ul5e2lX1adb+7zQNyluNaLPXP6Dina6Sy6DFGRLu7tM8+M7luYmbS3w63rpYpaL+A==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/client-sso": "3.943.0", - "@aws-sdk/core": "3.943.0", - "@aws-sdk/token-providers": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-provider-web-identity": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.943.0.tgz", - "integrity": "sha512-VtyGKHxICSb4kKGuaqotxso8JVM8RjCS3UYdIMOxUt9TaFE/CZIfZKtjTr+IJ7M0P7t36wuSUb/jRLyNmGzUUA==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/nested-clients": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/credential-providers": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-providers/-/credential-providers-3.943.0.tgz", - "integrity": "sha512-uZurSNsS01ehhrSwEPwcKdqp9lmd/x9q++BYO351bXyjSj1LzA/2lfUIxI2tCz/wAjJWOdnnlUdJj6P9I1uNvw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/client-cognito-identity": "3.943.0", - "@aws-sdk/core": "3.943.0", - "@aws-sdk/credential-provider-cognito-identity": "3.943.0", - "@aws-sdk/credential-provider-env": "3.943.0", - "@aws-sdk/credential-provider-http": "3.943.0", - "@aws-sdk/credential-provider-ini": "3.943.0", - "@aws-sdk/credential-provider-login": "3.943.0", - "@aws-sdk/credential-provider-node": "3.943.0", - "@aws-sdk/credential-provider-process": "3.943.0", - "@aws-sdk/credential-provider-sso": "3.943.0", - "@aws-sdk/credential-provider-web-identity": "3.943.0", - "@aws-sdk/nested-clients": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/config-resolver": "^4.4.3", - "@smithy/core": "^3.18.5", - "@smithy/credential-provider-imds": "^4.2.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/middleware-host-header": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.936.0.tgz", - "integrity": "sha512-tAaObaAnsP1XnLGndfkGWFuzrJYuk9W0b/nLvol66t8FZExIAf/WdkT2NNAWOYxljVs++oHnyHBCxIlaHrzSiw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/middleware-logger": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.936.0.tgz", - "integrity": "sha512-aPSJ12d3a3Ea5nyEnLbijCaaYJT2QjQ9iW+zGh5QcZYXmOGWbKVyPSxmVOboZQG+c1M8t6d2O7tqrwzIq8L8qw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/middleware-recursion-detection": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.936.0.tgz", - "integrity": "sha512-l4aGbHpXM45YNgXggIux1HgsCVAvvBoqHPkqLnqMl9QVapfuSTjJHfDYDsx1Xxct6/m7qSMUzanBALhiaGO2fA==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@aws/lambda-invoke-store": "^0.2.0", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/middleware-user-agent": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.943.0.tgz", - "integrity": "sha512-956n4kVEwFNXndXfhSAN5wO+KRgqiWEEY+ECwLvxmmO8uQ0NWOa8l6l65nTtyuiWzMX81c9BvlyNR5EgUeeUvA==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@aws-sdk/util-endpoints": "3.936.0", - "@smithy/core": "^3.18.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/nested-clients": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.943.0.tgz", - "integrity": "sha512-anFtB0p2FPuyUnbOULwGmKYqYKSq1M73c9uZ08jR/NCq6Trjq9cuF5TFTeHwjJyPRb4wMf2Qk859oiVfFqnQiw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-crypto/sha256-browser": "5.2.0", - "@aws-crypto/sha256-js": "5.2.0", - "@aws-sdk/core": "3.943.0", - "@aws-sdk/middleware-host-header": "3.936.0", - "@aws-sdk/middleware-logger": "3.936.0", - "@aws-sdk/middleware-recursion-detection": "3.936.0", - "@aws-sdk/middleware-user-agent": "3.943.0", - "@aws-sdk/region-config-resolver": "3.936.0", - "@aws-sdk/types": "3.936.0", - "@aws-sdk/util-endpoints": "3.936.0", - "@aws-sdk/util-user-agent-browser": "3.936.0", - "@aws-sdk/util-user-agent-node": "3.943.0", - "@smithy/config-resolver": "^4.4.3", - "@smithy/core": "^3.18.5", - "@smithy/fetch-http-handler": "^5.3.6", - "@smithy/hash-node": "^4.2.5", - "@smithy/invalid-dependency": "^4.2.5", - "@smithy/middleware-content-length": "^4.2.5", - "@smithy/middleware-endpoint": "^4.3.12", - "@smithy/middleware-retry": "^4.4.12", - "@smithy/middleware-serde": "^4.2.6", - "@smithy/middleware-stack": "^4.2.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/node-http-handler": "^4.4.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/smithy-client": "^4.9.8", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-body-length-browser": "^4.2.0", - "@smithy/util-body-length-node": "^4.2.1", - "@smithy/util-defaults-mode-browser": "^4.3.11", - "@smithy/util-defaults-mode-node": "^4.2.14", - "@smithy/util-endpoints": "^3.2.5", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-retry": "^4.2.5", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/region-config-resolver": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.936.0.tgz", - "integrity": "sha512-wOKhzzWsshXGduxO4pqSiNyL9oUtk4BEvjWm9aaq6Hmfdoydq6v6t0rAGHWPjFwy9z2haovGRi3C8IxdMB4muw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@smithy/config-resolver": "^4.4.3", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/token-providers": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.943.0.tgz", - "integrity": "sha512-cRKyIzwfkS+XztXIFPoWORuaxlIswP+a83BJzelX4S1gUZ7FcXB4+lj9Jxjn8SbQhR4TPU3Owbpu+S7pd6IRbQ==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/core": "3.943.0", - "@aws-sdk/nested-clients": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/types": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.936.0.tgz", - "integrity": "sha512-uz0/VlMd2pP5MepdrHizd+T+OKfyK4r3OA9JI+L/lPKg0YFQosdJNCKisr6o70E3dh8iMpFYxF1UN/4uZsyARg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/util-endpoints": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.936.0.tgz", - "integrity": "sha512-0Zx3Ntdpu+z9Wlm7JKUBOzS9EunwKAb4KdGUQQxDqh5Lc3ta5uBoub+FgmVuzwnmBu9U1Os8UuwVTH0Lgu+P5w==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "@smithy/util-endpoints": "^3.2.5", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/util-locate-window": { - "version": "3.893.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.893.0.tgz", - "integrity": "sha512-T89pFfgat6c8nMmpI8eKjBcDcgJq36+m9oiXbcUzeU55MP9ZuGgBomGjGnHaEyF36jenW9gmg3NfZDm0AO2XPg==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws-sdk/util-user-agent-browser": { - "version": "3.936.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.936.0.tgz", - "integrity": "sha512-eZ/XF6NxMtu+iCma58GRNRxSq4lHo6zHQLOZRIeL/ghqYJirqHdenMOwrzPettj60KWlv827RVebP9oNVrwZbw==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/types": "3.936.0", - "@smithy/types": "^4.9.0", - "bowser": "^2.11.0", - "tslib": "^2.6.2" - } - }, - "node_modules/@aws-sdk/util-user-agent-node": { - "version": "3.943.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.943.0.tgz", - "integrity": "sha512-gn+ILprVRrgAgTIBk2TDsJLRClzIOdStQFeFTcN0qpL8Z4GBCqMFhw7O7X+MM55Stt5s4jAauQ/VvoqmCADnQg==", - "license": "Apache-2.0", - "dependencies": { - "@aws-sdk/middleware-user-agent": "3.943.0", - "@aws-sdk/types": "3.936.0", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - }, - "peerDependencies": { - "aws-crt": ">=1.0.0" - }, - "peerDependenciesMeta": { - "aws-crt": { - "optional": true - } - } - }, - "node_modules/@aws-sdk/xml-builder": { - "version": "3.930.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.930.0.tgz", - "integrity": "sha512-YIfkD17GocxdmlUVc3ia52QhcWuRIUJonbF8A2CYfcWNV3HzvAqpcPeC0bYUhkK+8e8YO1ARnLKZQE0TlwzorA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "fast-xml-parser": "5.2.5", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@aws/lambda-invoke-store": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.1.tgz", - "integrity": "sha512-sIyFcoPZkTtNu9xFeEoynMef3bPJIAbOfUh+ueYcfhVl6xm2VRtMcMclSxmZCMnHHd4hlYKJeq/aggmBEWynww==", - "license": "Apache-2.0", - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@esbuild/aix-ppc64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.0.tgz", - "integrity": "sha512-KuZrd2hRjz01y5JK9mEBSD3Vj3mbCvemhT466rSuJYeE/hjuBrHfjjcjMdTm/sz7au+++sdbJZJmuBwQLuw68A==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "aix" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.0.tgz", - "integrity": "sha512-j67aezrPNYWJEOHUNLPj9maeJte7uSMM6gMoxfPC9hOg8N02JuQi/T7ewumf4tNvJadFkvLZMlAq73b9uwdMyQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.0.tgz", - "integrity": "sha512-CC3vt4+1xZrs97/PKDkl0yN7w8edvU2vZvAFGD16n9F0Cvniy5qvzRXjfO1l94efczkkQE6g1x0i73Qf5uthOQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.0.tgz", - "integrity": "sha512-wurMkF1nmQajBO1+0CJmcN17U4BP6GqNSROP8t0X/Jiw2ltYGLHpEksp9MpoBqkrFR3kv2/te6Sha26k3+yZ9Q==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/darwin-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.0.tgz", - "integrity": "sha512-uJOQKYCcHhg07DL7i8MzjvS2LaP7W7Pn/7uA0B5S1EnqAirJtbyw4yC5jQ5qcFjHK9l6o/MX9QisBg12kNkdHg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.0.tgz", - "integrity": "sha512-8mG6arH3yB/4ZXiEnXof5MK72dE6zM9cDvUcPtxhUZsDjESl9JipZYW60C3JGreKCEP+p8P/72r69m4AZGJd5g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.0.tgz", - "integrity": "sha512-9FHtyO988CwNMMOE3YIeci+UV+x5Zy8fI2qHNpsEtSF83YPBmE8UWmfYAQg6Ux7Gsmd4FejZqnEUZCMGaNQHQw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.0.tgz", - "integrity": "sha512-zCMeMXI4HS/tXvJz8vWGexpZj2YVtRAihHLk1imZj4efx1BQzN76YFeKqlDr3bUWI26wHwLWPd3rwh6pe4EV7g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.0.tgz", - "integrity": "sha512-t76XLQDpxgmq2cNXKTVEB7O7YMb42atj2Re2Haf45HkaUpjM2J0UuJZDuaGbPbamzZ7bawyGFUkodL+zcE+jvQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.0.tgz", - "integrity": "sha512-AS18v0V+vZiLJyi/4LphvBE+OIX682Pu7ZYNsdUHyUKSoRwdnOsMf6FDekwoAFKej14WAkOef3zAORJgAtXnlQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.0.tgz", - "integrity": "sha512-Mz1jxqm/kfgKkc/KLHC5qIujMvnnarD9ra1cEcrs7qshTUSksPihGrWHVG5+osAIQ68577Zpww7SGapmzSt4Nw==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.0.tgz", - "integrity": "sha512-QbEREjdJeIreIAbdG2hLU1yXm1uu+LTdzoq1KCo4G4pFOLlvIspBm36QrQOar9LFduavoWX2msNFAAAY9j4BDg==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.0.tgz", - "integrity": "sha512-sJz3zRNe4tO2wxvDpH/HYJilb6+2YJxo/ZNbVdtFiKDufzWq4JmKAiHy9iGoLjAV7r/W32VgaHGkk35cUXlNOg==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.0.tgz", - "integrity": "sha512-z9N10FBD0DCS2dmSABDBb5TLAyF1/ydVb+N4pi88T45efQ/w4ohr/F/QYCkxDPnkhkp6AIpIcQKQ8F0ANoA2JA==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.0.tgz", - "integrity": "sha512-pQdyAIZ0BWIC5GyvVFn5awDiO14TkT/19FTmFcPdDec94KJ1uZcmFs21Fo8auMXzD4Tt+diXu1LW1gHus9fhFQ==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.0.tgz", - "integrity": "sha512-hPlRWR4eIDDEci953RI1BLZitgi5uqcsjKMxwYfmi4LcwyWo2IcRP+lThVnKjNtk90pLS8nKdroXYOqW+QQH+w==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.0.tgz", - "integrity": "sha512-1hBWx4OUJE2cab++aVZ7pObD6s+DK4mPGpemtnAORBvb5l/g5xFGk0vc0PjSkrDs0XaXj9yyob3d14XqvnQ4gw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/netbsd-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.0.tgz", - "integrity": "sha512-6m0sfQfxfQfy1qRuecMkJlf1cIzTOgyaeXaiVaaki8/v+WB+U4hc6ik15ZW6TAllRlg/WuQXxWj1jx6C+dfy3w==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.0.tgz", - "integrity": "sha512-xbbOdfn06FtcJ9d0ShxxvSn2iUsGd/lgPIO2V3VZIPDbEaIj1/3nBBe1AwuEZKXVXkMmpr6LUAgMkLD/4D2PPA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.0.tgz", - "integrity": "sha512-fWgqR8uNbCQ/GGv0yhzttj6sU/9Z5/Sv/VGU3F5OuXK6J6SlriONKrQ7tNlwBrJZXRYk5jUhuWvF7GYzGguBZQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.0.tgz", - "integrity": "sha512-aCwlRdSNMNxkGGqQajMUza6uXzR/U0dIl1QmLjPtRbLOx3Gy3otfFu/VjATy4yQzo9yFDGTxYDo1FfAD9oRD2A==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openharmony-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.0.tgz", - "integrity": "sha512-nyvsBccxNAsNYz2jVFYwEGuRRomqZ149A39SHWk4hV0jWxKM0hjBPm3AmdxcbHiFLbBSwG6SbpIcUbXjgyECfA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openharmony" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.0.tgz", - "integrity": "sha512-Q1KY1iJafM+UX6CFEL+F4HRTgygmEW568YMqDA5UV97AuZSm21b7SXIrRJDwXWPzr8MGr75fUZPV67FdtMHlHA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.0.tgz", - "integrity": "sha512-W1eyGNi6d+8kOmZIwi/EDjrL9nxQIQ0MiGqe/AWc6+IaHloxHSGoeRgDRKHFISThLmsewZ5nHFvGFWdBYlgKPg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.0.tgz", - "integrity": "sha512-30z1aKL9h22kQhilnYkORFYt+3wp7yZsHWus+wSKAJR8JtdfI76LJ4SBdMsCopTR3z/ORqVu5L1vtnHZWVj4cQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.0.tgz", - "integrity": "sha512-aIitBcjQeyOhMTImhLZmtxfdOcuNRpwlPNmlFKPcHQYPhEssw75Cl1TSXJXpMkzaua9FUetx/4OQKq7eJul5Cg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@openauthjs/openauth": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/@openauthjs/openauth/-/openauth-0.4.3.tgz", - "integrity": "sha512-RlnjqvHzqcbFVymEwhlUEuac4utA5h4nhSK/i2szZuQmxTIqbGUxZ+nM+avM+VV4Ing+/ZaNLKILoXS3yrkOOw==", - "dependencies": { - "@standard-schema/spec": "1.0.0-beta.3", - "aws4fetch": "1.0.20", - "jose": "5.9.6" - }, - "peerDependencies": { - "arctic": "^2.2.2", - "hono": "^4.0.0" - } - }, - "node_modules/@openauthjs/openauth/node_modules/@standard-schema/spec": { - "version": "1.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0-beta.3.tgz", - "integrity": "sha512-0ifF3BjA1E8SY9C+nUew8RefNOIq0cDlYALPty4rhUm8Rrl6tCM8hBT4bhGhx7I7iXD0uAgt50lgo8dD73ACMw==", - "license": "MIT" - }, - "node_modules/@opencode-ai/plugin": { - "version": "1.0.143", - "resolved": "https://registry.npmjs.org/@opencode-ai/plugin/-/plugin-1.0.143.tgz", - "integrity": "sha512-yzaCmdazVJMDADJLbMM8KGp1X+Hd/HVyIXMlNt9qcvz/fcs/ET4EwHJsJaQi/9m/jLJ+plwBJAeIW08BMrECPg==", - "dev": true, - "dependencies": { - "@opencode-ai/sdk": "1.0.143", - "zod": "4.1.8" - } - }, - "node_modules/@opencode-ai/plugin/node_modules/zod": { - "version": "4.1.8", - "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.8.tgz", - "integrity": "sha512-5R1P+WwQqmmMIEACyzSvo4JXHY5WiAFHRMg+zBZKgKS+Q1viRa0C1hmUKtHltoIFKtIdki3pRxkmpP74jnNYHQ==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, - "node_modules/@opencode-ai/sdk": { - "version": "1.0.143", - "resolved": "https://registry.npmjs.org/@opencode-ai/sdk/-/sdk-1.0.143.tgz", - "integrity": "sha512-dtmkBfJ7IIAHzL6KCzAlwc9GybfJONVeCsF6ePYySpkuhslDbRkZBJYb5vqGd1H5zdsgjc6JjuvmOf0rPWUL6A==" - }, - "node_modules/@opentelemetry/api": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", - "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", - "license": "Apache-2.0", - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/@oslojs/asn1": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@oslojs/asn1/-/asn1-1.0.0.tgz", - "integrity": "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA==", - "license": "MIT", - "peer": true, - "dependencies": { - "@oslojs/binary": "1.0.0" - } - }, - "node_modules/@oslojs/binary": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@oslojs/binary/-/binary-1.0.0.tgz", - "integrity": "sha512-9RCU6OwXU6p67H4NODbuxv2S3eenuQ4/WFLrsq+K/k682xrznH5EVWA7N4VFk9VYVcbFtKqur5YQQZc0ySGhsQ==", - "license": "MIT", - "peer": true - }, - "node_modules/@oslojs/crypto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@oslojs/crypto/-/crypto-1.0.1.tgz", - "integrity": "sha512-7n08G8nWjAr/Yu3vu9zzrd0L9XnrJfpMioQcvCMxBIiF5orECHe5/3J0jmXRVvgfqMm/+4oxlQ+Sq39COYLcNQ==", - "license": "MIT", - "peer": true, - "dependencies": { - "@oslojs/asn1": "1.0.0", - "@oslojs/binary": "1.0.0" - } - }, - "node_modules/@oslojs/encoding": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-1.1.0.tgz", - "integrity": "sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ==", - "license": "MIT", - "peer": true - }, - "node_modules/@oslojs/jwt": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@oslojs/jwt/-/jwt-0.2.0.tgz", - "integrity": "sha512-bLE7BtHrURedCn4Mco3ma9L4Y1GR2SMBuIvjWr7rmQ4/W/4Jy70TIAgZ+0nIlk0xHz1vNP8x8DCns45Sb2XRbg==", - "license": "MIT", - "peer": true, - "dependencies": { - "@oslojs/encoding": "0.4.1" - } - }, - "node_modules/@oslojs/jwt/node_modules/@oslojs/encoding": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-0.4.1.tgz", - "integrity": "sha512-hkjo6MuIK/kQR5CrGNdAPZhS01ZCXuWDRJ187zh6qqF2+yMHZpD9fAYpX8q2bOO6Ryhl3XpCT6kUX76N8hhm4Q==", - "license": "MIT", - "peer": true - }, - "node_modules/@smithy/abort-controller": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-4.2.5.tgz", - "integrity": "sha512-j7HwVkBw68YW8UmFRcjZOmssE77Rvk0GWAIN1oFBhsaovQmZWYCIcGa9/pwRB0ExI8Sk9MWNALTjftjHZea7VA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/config-resolver": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/@smithy/config-resolver/-/config-resolver-4.4.3.tgz", - "integrity": "sha512-ezHLe1tKLUxDJo2LHtDuEDyWXolw8WGOR92qb4bQdWq/zKenO5BvctZGrVJBK08zjezSk7bmbKFOXIVyChvDLw==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/node-config-provider": "^4.3.5", - "@smithy/types": "^4.9.0", - "@smithy/util-config-provider": "^4.2.0", - "@smithy/util-endpoints": "^3.2.5", - "@smithy/util-middleware": "^4.2.5", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/core": { - "version": "3.18.6", - "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.18.6.tgz", - "integrity": "sha512-8Q/ugWqfDUEU1Exw71+DoOzlONJ2Cn9QA8VeeDzLLjzO/qruh9UKFzbszy4jXcIYgGofxYiT0t1TT6+CT/GupQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/middleware-serde": "^4.2.6", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-body-length-browser": "^4.2.0", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-stream": "^4.5.6", - "@smithy/util-utf8": "^4.2.0", - "@smithy/uuid": "^1.1.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/credential-provider-imds": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.2.5.tgz", - "integrity": "sha512-BZwotjoZWn9+36nimwm/OLIcVe+KYRwzMjfhd4QT7QxPm9WY0HiOV8t/Wlh+HVUif0SBVV7ksq8//hPaBC/okQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/node-config-provider": "^4.3.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/fetch-http-handler": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.3.6.tgz", - "integrity": "sha512-3+RG3EA6BBJ/ofZUeTFJA7mHfSYrZtQIrDP9dI8Lf7X6Jbos2jptuLrAAteDiFVrmbEmLSuRG/bUKzfAXk7dhg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/protocol-http": "^5.3.5", - "@smithy/querystring-builder": "^4.2.5", - "@smithy/types": "^4.9.0", - "@smithy/util-base64": "^4.3.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/hash-node": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/hash-node/-/hash-node-4.2.5.tgz", - "integrity": "sha512-DpYX914YOfA3UDT9CN1BM787PcHfWRBB43fFGCYrZFUH0Jv+5t8yYl+Pd5PW4+QzoGEDvn5d5QIO4j2HyYZQSA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "@smithy/util-buffer-from": "^4.2.0", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/invalid-dependency": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/invalid-dependency/-/invalid-dependency-4.2.5.tgz", - "integrity": "sha512-2L2erASEro1WC5nV+plwIMxrTXpvpfzl4e+Nre6vBVRR2HKeGGcvpJyyL3/PpiSg+cJG2KpTmZmq934Olb6e5A==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/is-array-buffer": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-4.2.0.tgz", - "integrity": "sha512-DZZZBvC7sjcYh4MazJSGiWMI2L7E0oCiRHREDzIxi/M2LY79/21iXt6aPLHge82wi5LsuRF5A06Ds3+0mlh6CQ==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/middleware-content-length": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/middleware-content-length/-/middleware-content-length-4.2.5.tgz", - "integrity": "sha512-Y/RabVa5vbl5FuHYV2vUCwvh/dqzrEY/K2yWPSqvhFUwIY0atLqO4TienjBXakoy4zrKAMCZwg+YEqmH7jaN7A==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/middleware-endpoint": { - "version": "4.3.13", - "resolved": "https://registry.npmjs.org/@smithy/middleware-endpoint/-/middleware-endpoint-4.3.13.tgz", - "integrity": "sha512-X4za1qCdyx1hEVVXuAWlZuK6wzLDv1uw1OY9VtaYy1lULl661+frY7FeuHdYdl7qAARUxH2yvNExU2/SmRFfcg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/core": "^3.18.6", - "@smithy/middleware-serde": "^4.2.6", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "@smithy/url-parser": "^4.2.5", - "@smithy/util-middleware": "^4.2.5", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/middleware-retry": { - "version": "4.4.13", - "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-4.4.13.tgz", - "integrity": "sha512-RzIDF9OrSviXX7MQeKOm8r/372KTyY8Jmp6HNKOOYlrguHADuM3ED/f4aCyNhZZFLG55lv5beBin7nL0Nzy1Dw==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/node-config-provider": "^4.3.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/service-error-classification": "^4.2.5", - "@smithy/smithy-client": "^4.9.9", - "@smithy/types": "^4.9.0", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-retry": "^4.2.5", - "@smithy/uuid": "^1.1.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/middleware-serde": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/@smithy/middleware-serde/-/middleware-serde-4.2.6.tgz", - "integrity": "sha512-VkLoE/z7e2g8pirwisLz8XJWedUSY8my/qrp81VmAdyrhi94T+riBfwP+AOEEFR9rFTSonC/5D2eWNmFabHyGQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/middleware-stack": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/middleware-stack/-/middleware-stack-4.2.5.tgz", - "integrity": "sha512-bYrutc+neOyWxtZdbB2USbQttZN0mXaOyYLIsaTbJhFsfpXyGWUxJpEuO1rJ8IIJm2qH4+xJT0mxUSsEDTYwdQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/node-config-provider": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/@smithy/node-config-provider/-/node-config-provider-4.3.5.tgz", - "integrity": "sha512-UTurh1C4qkVCtqggI36DGbLB2Kv8UlcFdMXDcWMbqVY2uRg0XmT9Pb4Vj6oSQ34eizO1fvR0RnFV4Axw4IrrAg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/property-provider": "^4.2.5", - "@smithy/shared-ini-file-loader": "^4.4.0", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/node-http-handler": { - "version": "4.4.5", - "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.4.5.tgz", - "integrity": "sha512-CMnzM9R2WqlqXQGtIlsHMEZfXKJVTIrqCNoSd/QpAyp+Dw0a1Vps13l6ma1fH8g7zSPNsA59B/kWgeylFuA/lw==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/abort-controller": "^4.2.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/querystring-builder": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/property-provider": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/property-provider/-/property-provider-4.2.5.tgz", - "integrity": "sha512-8iLN1XSE1rl4MuxvQ+5OSk/Zb5El7NJZ1td6Tn+8dQQHIjp59Lwl6bd0+nzw6SKm2wSSriH2v/I9LPzUic7EOg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/protocol-http": { - "version": "5.3.5", - "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-5.3.5.tgz", - "integrity": "sha512-RlaL+sA0LNMp03bf7XPbFmT5gN+w3besXSWMkA8rcmxLSVfiEXElQi4O2IWwPfxzcHkxqrwBFMbngB8yx/RvaQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/querystring-builder": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-4.2.5.tgz", - "integrity": "sha512-y98otMI1saoajeik2kLfGyRp11e5U/iJYH/wLCh3aTV/XutbGT9nziKGkgCaMD1ghK7p6htHMm6b6scl9JRUWg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "@smithy/util-uri-escape": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/querystring-parser": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/querystring-parser/-/querystring-parser-4.2.5.tgz", - "integrity": "sha512-031WCTdPYgiQRYNPXznHXof2YM0GwL6SeaSyTH/P72M1Vz73TvCNH2Nq8Iu2IEPq9QP2yx0/nrw5YmSeAi/AjQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/service-error-classification": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-4.2.5.tgz", - "integrity": "sha512-8fEvK+WPE3wUAcDvqDQG1Vk3ANLR8Px979te96m84CbKAjBVf25rPYSzb4xU4hlTyho7VhOGnh5i62D/JVF0JQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/shared-ini-file-loader": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/@smithy/shared-ini-file-loader/-/shared-ini-file-loader-4.4.0.tgz", - "integrity": "sha512-5WmZ5+kJgJDjwXXIzr1vDTG+RhF9wzSODQBfkrQ2VVkYALKGvZX1lgVSxEkgicSAFnFhPj5rudJV0zoinqS0bA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/signature-v4": { - "version": "5.3.5", - "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.3.5.tgz", - "integrity": "sha512-xSUfMu1FT7ccfSXkoLl/QRQBi2rOvi3tiBZU2Tdy3I6cgvZ6SEi9QNey+lqps/sJRnogIS+lq+B1gxxbra2a/w==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/is-array-buffer": "^4.2.0", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "@smithy/util-hex-encoding": "^4.2.0", - "@smithy/util-middleware": "^4.2.5", - "@smithy/util-uri-escape": "^4.2.0", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/smithy-client": { - "version": "4.9.9", - "resolved": "https://registry.npmjs.org/@smithy/smithy-client/-/smithy-client-4.9.9.tgz", - "integrity": "sha512-SUnZJMMo5yCmgjopJbiNeo1vlr8KvdnEfIHV9rlD77QuOGdRotIVBcOrBuMr+sI9zrnhtDtLP054bZVbpZpiQA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/core": "^3.18.6", - "@smithy/middleware-endpoint": "^4.3.13", - "@smithy/middleware-stack": "^4.2.5", - "@smithy/protocol-http": "^5.3.5", - "@smithy/types": "^4.9.0", - "@smithy/util-stream": "^4.5.6", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/types": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.9.0.tgz", - "integrity": "sha512-MvUbdnXDTwykR8cB1WZvNNwqoWVaTRA0RLlLmf/cIFNMM2cKWz01X4Ly6SMC4Kks30r8tT3Cty0jmeWfiuyHTA==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/url-parser": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/url-parser/-/url-parser-4.2.5.tgz", - "integrity": "sha512-VaxMGsilqFnK1CeBX+LXnSuaMx4sTL/6znSZh2829txWieazdVxr54HmiyTsIbpOTLcf5nYpq9lpzmwRdxj6rQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/querystring-parser": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-base64": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/@smithy/util-base64/-/util-base64-4.3.0.tgz", - "integrity": "sha512-GkXZ59JfyxsIwNTWFnjmFEI8kZpRNIBfxKjv09+nkAWPt/4aGaEWMM04m4sxgNVWkbt2MdSvE3KF/PfX4nFedQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/util-buffer-from": "^4.2.0", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-body-length-browser": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-body-length-browser/-/util-body-length-browser-4.2.0.tgz", - "integrity": "sha512-Fkoh/I76szMKJnBXWPdFkQJl2r9SjPt3cMzLdOB6eJ4Pnpas8hVoWPYemX/peO0yrrvldgCUVJqOAjUrOLjbxg==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-body-length-node": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@smithy/util-body-length-node/-/util-body-length-node-4.2.1.tgz", - "integrity": "sha512-h53dz/pISVrVrfxV1iqXlx5pRg3V2YWFcSQyPyXZRrZoZj4R4DeWRDo1a7dd3CPTcFi3kE+98tuNyD2axyZReA==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-buffer-from": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-4.2.0.tgz", - "integrity": "sha512-kAY9hTKulTNevM2nlRtxAG2FQ3B2OR6QIrPY3zE5LqJy1oxzmgBGsHLWTcNhWXKchgA0WHW+mZkQrng/pgcCew==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/is-array-buffer": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-config-provider": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-config-provider/-/util-config-provider-4.2.0.tgz", - "integrity": "sha512-YEjpl6XJ36FTKmD+kRJJWYvrHeUvm5ykaUS5xK+6oXffQPHeEM4/nXlZPe+Wu0lsgRUcNZiliYNh/y7q9c2y6Q==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-defaults-mode-browser": { - "version": "4.3.12", - "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-browser/-/util-defaults-mode-browser-4.3.12.tgz", - "integrity": "sha512-TKc6FnOxFULKxLgTNHYjcFqdOYzXVPFFVm5JhI30F3RdhT7nYOtOsjgaOwfDRmA/3U66O9KaBQ3UHoXwayRhAg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/property-provider": "^4.2.5", - "@smithy/smithy-client": "^4.9.9", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-defaults-mode-node": { - "version": "4.2.15", - "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-node/-/util-defaults-mode-node-4.2.15.tgz", - "integrity": "sha512-94NqfQVo+vGc5gsQ9SROZqOvBkGNMQu6pjXbnn8aQvBUhc31kx49gxlkBEqgmaZQHUUfdRUin5gK/HlHKmbAwg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/config-resolver": "^4.4.3", - "@smithy/credential-provider-imds": "^4.2.5", - "@smithy/node-config-provider": "^4.3.5", - "@smithy/property-provider": "^4.2.5", - "@smithy/smithy-client": "^4.9.9", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-endpoints": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/@smithy/util-endpoints/-/util-endpoints-3.2.5.tgz", - "integrity": "sha512-3O63AAWu2cSNQZp+ayl9I3NapW1p1rR5mlVHcF6hAB1dPZUQFfRPYtplWX/3xrzWthPGj5FqB12taJJCfH6s8A==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/node-config-provider": "^4.3.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-hex-encoding": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-hex-encoding/-/util-hex-encoding-4.2.0.tgz", - "integrity": "sha512-CCQBwJIvXMLKxVbO88IukazJD9a4kQ9ZN7/UMGBjBcJYvatpWk+9g870El4cB8/EJxfe+k+y0GmR9CAzkF+Nbw==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-middleware": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/util-middleware/-/util-middleware-4.2.5.tgz", - "integrity": "sha512-6Y3+rvBF7+PZOc40ybeZMcGln6xJGVeY60E7jy9Mv5iKpMJpHgRE6dKy9ScsVxvfAYuEX4Q9a65DQX90KaQ3bA==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-retry": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.2.5.tgz", - "integrity": "sha512-GBj3+EZBbN4NAqJ/7pAhsXdfzdlznOh8PydUijy6FpNIMnHPSMO2/rP4HKu+UFeikJxShERk528oy7GT79YiJg==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/service-error-classification": "^4.2.5", - "@smithy/types": "^4.9.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-stream": { - "version": "4.5.6", - "resolved": "https://registry.npmjs.org/@smithy/util-stream/-/util-stream-4.5.6.tgz", - "integrity": "sha512-qWw/UM59TiaFrPevefOZ8CNBKbYEP6wBAIlLqxn3VAIo9rgnTNc4ASbVrqDmhuwI87usnjhdQrxodzAGFFzbRQ==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/fetch-http-handler": "^5.3.6", - "@smithy/node-http-handler": "^4.4.5", - "@smithy/types": "^4.9.0", - "@smithy/util-base64": "^4.3.0", - "@smithy/util-buffer-from": "^4.2.0", - "@smithy/util-hex-encoding": "^4.2.0", - "@smithy/util-utf8": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-uri-escape": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-4.2.0.tgz", - "integrity": "sha512-igZpCKV9+E/Mzrpq6YacdTQ0qTiLm85gD6N/IrmyDvQFA4UnU3d5g3m8tMT/6zG/vVkWSU+VxeUyGonL62DuxA==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/util-utf8": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-4.2.0.tgz", - "integrity": "sha512-zBPfuzoI8xyBtR2P6WQj63Rz8i3AmfAaJLuNG8dWsfvPe8lO4aCPYLn879mEgHndZH1zQ2oXmG8O1GGzzaoZiw==", - "license": "Apache-2.0", - "dependencies": { - "@smithy/util-buffer-from": "^4.2.0", - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@smithy/uuid": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@smithy/uuid/-/uuid-1.1.0.tgz", - "integrity": "sha512-4aUIteuyxtBUhVdiQqcDhKFitwfd9hqoSDYY2KRXiWtgoWJ9Bmise+KfEPDiVHWeJepvF8xJO9/9+WDIciMFFw==", - "license": "Apache-2.0", - "dependencies": { - "tslib": "^2.6.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/@standard-schema/spec": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz", - "integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==", - "license": "MIT" - }, - "node_modules/@tarquinen/opencode-auth-provider": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/@tarquinen/opencode-auth-provider/-/opencode-auth-provider-0.1.7.tgz", - "integrity": "sha512-FH1QEyoirr2e8b48Z6HrjioIZIZUIM9zOpYmku1ad+c4Nv70F37fSWhcObyIdZo4Ly3OntpKPWjadyRhd/kQcg==", - "license": "MIT", - "dependencies": { - "@aws-sdk/credential-providers": "^3.936.0", - "ai": "^5.0.98", - "jsonc-parser": "^3.3.1", - "opencode-anthropic-auth": "0.0.2", - "opencode-copilot-auth": "0.0.5", - "opencode-gemini-auth": "^1.1.4", - "remeda": "^2.32.0", - "xdg-basedir": "^5.1.0", - "zod": "^4.1.12" - }, - "peerDependencies": { - "@ai-sdk/amazon-bedrock": ">=1.0.0", - "@ai-sdk/anthropic": ">=1.0.0", - "@ai-sdk/azure": ">=1.0.0", - "@ai-sdk/google": ">=1.0.0", - "@ai-sdk/google-vertex": ">=1.0.0", - "@ai-sdk/openai": ">=1.0.0", - "@ai-sdk/openai-compatible": ">=0.1.0", - "@openrouter/ai-sdk-provider": ">=0.1.0" - }, - "peerDependenciesMeta": { - "@ai-sdk/amazon-bedrock": { - "optional": true - }, - "@ai-sdk/anthropic": { - "optional": true - }, - "@ai-sdk/azure": { - "optional": true - }, - "@ai-sdk/google": { - "optional": true - }, - "@ai-sdk/google-vertex": { - "optional": true - }, - "@ai-sdk/openai": { - "optional": true - }, - "@ai-sdk/openai-compatible": { - "optional": true - }, - "@openrouter/ai-sdk-provider": { - "optional": true - } - } - }, - "node_modules/@types/node": { - "version": "24.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", - "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~7.16.0" - } - }, - "node_modules/@vercel/oidc": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@vercel/oidc/-/oidc-3.0.5.tgz", - "integrity": "sha512-fnYhv671l+eTTp48gB4zEsTW/YtRgRPnkI2nT7x6qw5rkI1Lq2hTmQIpHPgyThI0znLK+vX2n9XxKdXZ7BUbbw==", - "license": "Apache-2.0", - "engines": { - "node": ">= 20" - } - }, - "node_modules/ai": { - "version": "5.0.106", - "resolved": "https://registry.npmjs.org/ai/-/ai-5.0.106.tgz", - "integrity": "sha512-M5obwavxSJJ3tGlAFqI6eltYNJB0D20X6gIBCFx/KVorb/X1fxVVfiZZpZb+Gslu4340droSOjT0aKQFCarNVg==", - "license": "Apache-2.0", - "dependencies": { - "@ai-sdk/gateway": "2.0.18", - "@ai-sdk/provider": "2.0.0", - "@ai-sdk/provider-utils": "3.0.18", - "@opentelemetry/api": "1.9.0" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "zod": "^3.25.76 || ^4.1.8" - } - }, - "node_modules/arctic": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/arctic/-/arctic-2.3.4.tgz", - "integrity": "sha512-+p30BOWsctZp+CVYCt7oAean/hWGW42sH5LAcRQX56ttEkFJWbzXBhmSpibbzwSJkRrotmsA+oAoJoVsU0f5xA==", - "license": "MIT", - "peer": true, - "dependencies": { - "@oslojs/crypto": "1.0.1", - "@oslojs/encoding": "1.1.0", - "@oslojs/jwt": "0.2.0" - } - }, - "node_modules/aws4fetch": { - "version": "1.0.20", - "resolved": "https://registry.npmjs.org/aws4fetch/-/aws4fetch-1.0.20.tgz", - "integrity": "sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g==", - "license": "MIT" - }, - "node_modules/bowser": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.13.1.tgz", - "integrity": "sha512-OHawaAbjwx6rqICCKgSG0SAnT05bzd7ppyKLVUITZpANBaaMFBAsaNkto3LoQ31tyFP5kNujE8Cdx85G9VzOkw==", - "license": "MIT" - }, - "node_modules/esbuild": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.0.tgz", - "integrity": "sha512-jd0f4NHbD6cALCyGElNpGAOtWxSq46l9X/sWB0Nzd5er4Kz2YTm+Vl0qKFT9KUJvD8+fiO8AvoHhFvEatfVixA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "@esbuild/aix-ppc64": "0.27.0", - "@esbuild/android-arm": "0.27.0", - "@esbuild/android-arm64": "0.27.0", - "@esbuild/android-x64": "0.27.0", - "@esbuild/darwin-arm64": "0.27.0", - "@esbuild/darwin-x64": "0.27.0", - "@esbuild/freebsd-arm64": "0.27.0", - "@esbuild/freebsd-x64": "0.27.0", - "@esbuild/linux-arm": "0.27.0", - "@esbuild/linux-arm64": "0.27.0", - "@esbuild/linux-ia32": "0.27.0", - "@esbuild/linux-loong64": "0.27.0", - "@esbuild/linux-mips64el": "0.27.0", - "@esbuild/linux-ppc64": "0.27.0", - "@esbuild/linux-riscv64": "0.27.0", - "@esbuild/linux-s390x": "0.27.0", - "@esbuild/linux-x64": "0.27.0", - "@esbuild/netbsd-arm64": "0.27.0", - "@esbuild/netbsd-x64": "0.27.0", - "@esbuild/openbsd-arm64": "0.27.0", - "@esbuild/openbsd-x64": "0.27.0", - "@esbuild/openharmony-arm64": "0.27.0", - "@esbuild/sunos-x64": "0.27.0", - "@esbuild/win32-arm64": "0.27.0", - "@esbuild/win32-ia32": "0.27.0", - "@esbuild/win32-x64": "0.27.0" - } - }, - "node_modules/eventsource-parser": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", - "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", - "license": "MIT", - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/fast-xml-parser": { - "version": "5.2.5", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.2.5.tgz", - "integrity": "sha512-pfX9uG9Ki0yekDHx2SiuRIyFdyAr1kMIMitPvb0YBo8SUfKvia7w7FIyd/l6av85pFYRhZscS75MwMnbvY+hcQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/NaturalIntelligence" - } - ], - "license": "MIT", - "dependencies": { - "strnum": "^2.1.0" - }, - "bin": { - "fxparser": "src/cli/cli.js" - } - }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/get-tsconfig": { - "version": "4.13.0", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz", - "integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve-pkg-maps": "^1.0.0" - }, - "funding": { - "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" - } - }, - "node_modules/gpt-tokenizer": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/gpt-tokenizer/-/gpt-tokenizer-3.4.0.tgz", - "integrity": "sha512-wxFLnhIXTDjYebd9A9pGl3e31ZpSypbpIJSOswbgop5jLte/AsZVDvjlbEuVFlsqZixVKqbcoNmRlFDf6pz/UQ==", - "license": "MIT" - }, - "node_modules/hono": { - "version": "4.10.7", - "resolved": "https://registry.npmjs.org/hono/-/hono-4.10.7.tgz", - "integrity": "sha512-icXIITfw/07Q88nLSkB9aiUrd8rYzSweK681Kjo/TSggaGbOX4RRyxxm71v+3PC8C/j+4rlxGeoTRxQDkaJkUw==", - "license": "MIT", - "peer": true, - "engines": { - "node": ">=16.9.0" - } - }, - "node_modules/jose": { - "version": "5.9.6", - "resolved": "https://registry.npmjs.org/jose/-/jose-5.9.6.tgz", - "integrity": "sha512-AMlnetc9+CV9asI19zHmrgS/WYsWUwCn2R7RzlbJWD7F9eWYUTGyBmU9o6PxngtLGOiDGPRu+Uc4fhKzbpteZQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, - "node_modules/json-schema": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", - "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", - "license": "(AFL-2.1 OR BSD-3-Clause)" - }, - "node_modules/jsonc-parser": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", - "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", - "license": "MIT" - }, - "node_modules/opencode-anthropic-auth": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/opencode-anthropic-auth/-/opencode-anthropic-auth-0.0.2.tgz", - "integrity": "sha512-m8dcEKtq2ExGLV7n4BMr1H5UimDaABV6aG82IDMcp1xmXUaO1K20/hess0s8cwvv6MFmJk4//2wbWZkzoOtirA==", - "dependencies": { - "@openauthjs/openauth": "^0.4.3" - } - }, - "node_modules/opencode-copilot-auth": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/opencode-copilot-auth/-/opencode-copilot-auth-0.0.5.tgz", - "integrity": "sha512-aOna2jy3BnaEpVJkeF32joUzI8DcpbBMWjd7zW6sgX4t58AnxaEB5sDadLsxRfcxJdhmABd5k6QSww5LcJ4e9Q==" - }, - "node_modules/opencode-gemini-auth": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/opencode-gemini-auth/-/opencode-gemini-auth-1.1.6.tgz", - "integrity": "sha512-7WxOEwYMqXeCD2jf/Wj+8yBS3qwnRxHKt/sWhn2ZBDgz+dVwrC/SpTNvpva1fF8KSgVVG8tS9yvDQXM0JcVGoQ==", - "license": "MIT", - "dependencies": { - "@openauthjs/openauth": "^0.4.3" - }, - "peerDependencies": { - "typescript": "^5" - } - }, - "node_modules/remeda": { - "version": "2.32.0", - "resolved": "https://registry.npmjs.org/remeda/-/remeda-2.32.0.tgz", - "integrity": "sha512-BZx9DsT4FAgXDTOdgJIc5eY6ECIXMwtlSPQoPglF20ycSWigttDDe88AozEsPPT4OWk5NujroGSBC1phw5uU+w==", - "license": "MIT", - "dependencies": { - "type-fest": "^4.41.0" - } - }, - "node_modules/resolve-pkg-maps": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", - "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" - } - }, - "node_modules/strnum": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.1.tgz", - "integrity": "sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/NaturalIntelligence" + "name": "@tarquinen/opencode-dcp", + "version": "1.1.0-beta.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@tarquinen/opencode-dcp", + "version": "1.1.0-beta.1", + "license": "MIT", + "dependencies": { + "@ai-sdk/openai-compatible": "^1.0.28", + "@opencode-ai/sdk": "latest", + "@tarquinen/opencode-auth-provider": "^0.1.7", + "ai": "^5.0.106", + "gpt-tokenizer": "^3.4.0", + "jsonc-parser": "^3.3.1", + "zod": "^4.1.13" + }, + "devDependencies": { + "@opencode-ai/plugin": "^1.0.143", + "@types/node": "^24.10.1", + "prettier": "^3.4.2", + "tsx": "^4.21.0", + "typescript": "^5.9.3" + }, + "peerDependencies": { + "@opencode-ai/plugin": ">=0.13.7" + } + }, + "node_modules/@ai-sdk/gateway": { + "version": "2.0.18", + "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-2.0.18.tgz", + "integrity": "sha512-sDQcW+6ck2m0pTIHW6BPHD7S125WD3qNkx/B8sEzJp/hurocmJ5Cni0ybExg6sQMGo+fr/GWOwpHF1cmCdg5rQ==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "2.0.0", + "@ai-sdk/provider-utils": "3.0.18", + "@vercel/oidc": "3.0.5" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/openai-compatible": { + "version": "1.0.28", + "resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-1.0.28.tgz", + "integrity": "sha512-yKubDxLYtXyGUzkr9lNStf/lE/I+Okc8tmotvyABhsQHHieLKk6oV5fJeRJxhr67Ejhg+FRnwUOxAmjRoFM4dA==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "2.0.0", + "@ai-sdk/provider-utils": "3.0.18" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/provider": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-2.0.0.tgz", + "integrity": "sha512-6o7Y2SeO9vFKB8lArHXehNuusnpddKPk7xqL7T2/b+OvXMRIXUO1rR4wcv1hAFUAT9avGZshty3Wlua/XA7TvA==", + "license": "Apache-2.0", + "dependencies": { + "json-schema": "^0.4.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@ai-sdk/provider-utils": { + "version": "3.0.18", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-3.0.18.tgz", + "integrity": "sha512-ypv1xXMsgGcNKUP+hglKqtdDuMg68nWHucPPAhIENrbFAI+xCHiqPVN8Zllxyv1TNZwGWUghPxJXU+Mqps0YRQ==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "2.0.0", + "@standard-schema/spec": "^1.0.0", + "eventsource-parser": "^3.0.6" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@aws-crypto/sha256-browser": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-5.2.0.tgz", + "integrity": "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-js": "^5.2.0", + "@aws-crypto/supports-web-crypto": "^5.2.0", + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "@aws-sdk/util-locate-window": "^3.0.0", + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/is-array-buffer": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", + "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-buffer-from": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", + "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/is-array-buffer": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-utf8": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", + "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-crypto/sha256-js": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", + "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/util": "^5.2.0", + "@aws-sdk/types": "^3.222.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-crypto/supports-web-crypto": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-5.2.0.tgz", + "integrity": "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/util": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", + "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "^3.222.0", + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-crypto/util/node_modules/@smithy/is-array-buffer": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", + "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-crypto/util/node_modules/@smithy/util-buffer-from": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", + "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/is-array-buffer": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-crypto/util/node_modules/@smithy/util-utf8": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", + "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^2.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@aws-sdk/client-cognito-identity": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.943.0.tgz", + "integrity": "sha512-XkuokRF2IQ+VLBn0AwrwfFOkZ2c1IXACwQdn3CDnpBZpT1s2hgH3MX0DoH9+41w4ar2QCSI09uAJiv9PX4DLoQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "3.943.0", + "@aws-sdk/credential-provider-node": "3.943.0", + "@aws-sdk/middleware-host-header": "3.936.0", + "@aws-sdk/middleware-logger": "3.936.0", + "@aws-sdk/middleware-recursion-detection": "3.936.0", + "@aws-sdk/middleware-user-agent": "3.943.0", + "@aws-sdk/region-config-resolver": "3.936.0", + "@aws-sdk/types": "3.936.0", + "@aws-sdk/util-endpoints": "3.936.0", + "@aws-sdk/util-user-agent-browser": "3.936.0", + "@aws-sdk/util-user-agent-node": "3.943.0", + "@smithy/config-resolver": "^4.4.3", + "@smithy/core": "^3.18.5", + "@smithy/fetch-http-handler": "^5.3.6", + "@smithy/hash-node": "^4.2.5", + "@smithy/invalid-dependency": "^4.2.5", + "@smithy/middleware-content-length": "^4.2.5", + "@smithy/middleware-endpoint": "^4.3.12", + "@smithy/middleware-retry": "^4.4.12", + "@smithy/middleware-serde": "^4.2.6", + "@smithy/middleware-stack": "^4.2.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/node-http-handler": "^4.4.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/smithy-client": "^4.9.8", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-body-length-browser": "^4.2.0", + "@smithy/util-body-length-node": "^4.2.1", + "@smithy/util-defaults-mode-browser": "^4.3.11", + "@smithy/util-defaults-mode-node": "^4.2.14", + "@smithy/util-endpoints": "^3.2.5", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-retry": "^4.2.5", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/client-sso": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.943.0.tgz", + "integrity": "sha512-kOTO2B8Ks2qX73CyKY8PAajtf5n39aMe2spoiOF5EkgSzGV7hZ/HONRDyADlyxwfsX39Q2F2SpPUaXzon32IGw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "3.943.0", + "@aws-sdk/middleware-host-header": "3.936.0", + "@aws-sdk/middleware-logger": "3.936.0", + "@aws-sdk/middleware-recursion-detection": "3.936.0", + "@aws-sdk/middleware-user-agent": "3.943.0", + "@aws-sdk/region-config-resolver": "3.936.0", + "@aws-sdk/types": "3.936.0", + "@aws-sdk/util-endpoints": "3.936.0", + "@aws-sdk/util-user-agent-browser": "3.936.0", + "@aws-sdk/util-user-agent-node": "3.943.0", + "@smithy/config-resolver": "^4.4.3", + "@smithy/core": "^3.18.5", + "@smithy/fetch-http-handler": "^5.3.6", + "@smithy/hash-node": "^4.2.5", + "@smithy/invalid-dependency": "^4.2.5", + "@smithy/middleware-content-length": "^4.2.5", + "@smithy/middleware-endpoint": "^4.3.12", + "@smithy/middleware-retry": "^4.4.12", + "@smithy/middleware-serde": "^4.2.6", + "@smithy/middleware-stack": "^4.2.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/node-http-handler": "^4.4.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/smithy-client": "^4.9.8", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-body-length-browser": "^4.2.0", + "@smithy/util-body-length-node": "^4.2.1", + "@smithy/util-defaults-mode-browser": "^4.3.11", + "@smithy/util-defaults-mode-node": "^4.2.14", + "@smithy/util-endpoints": "^3.2.5", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-retry": "^4.2.5", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/core": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.943.0.tgz", + "integrity": "sha512-8CBy2hI9ABF7RBVQuY1bgf/ue+WPmM/hl0adrXFlhnhkaQP0tFY5zhiy1Y+n7V+5f3/ORoHBmCCQmcHDDYJqJQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@aws-sdk/xml-builder": "3.930.0", + "@smithy/core": "^3.18.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/signature-v4": "^5.3.5", + "@smithy/smithy-client": "^4.9.8", + "@smithy/types": "^4.9.0", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-cognito-identity": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-cognito-identity/-/credential-provider-cognito-identity-3.943.0.tgz", + "integrity": "sha512-jZJ0uHjNlhfjx2ZX7YVYnh1wfSkLAvQmecGCSl9C6LJRNXy4uWFPbGjPqcA0tWp0WWIsUYhqjasgvCOMZIY8nw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/client-cognito-identity": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-env": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.943.0.tgz", + "integrity": "sha512-WnS5w9fK9CTuoZRVSIHLOMcI63oODg9qd1vXMYb7QGLGlfwUm4aG3hdu7i9XvYrpkQfE3dzwWLtXF4ZBuL1Tew==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-http": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.943.0.tgz", + "integrity": "sha512-SA8bUcYDEACdhnhLpZNnWusBpdmj4Vl67Vxp3Zke7SvoWSYbuxa+tiDiC+c92Z4Yq6xNOuLPW912ZPb9/NsSkA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/fetch-http-handler": "^5.3.6", + "@smithy/node-http-handler": "^4.4.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/smithy-client": "^4.9.8", + "@smithy/types": "^4.9.0", + "@smithy/util-stream": "^4.5.6", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-ini": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.943.0.tgz", + "integrity": "sha512-BcLDb8l4oVW+NkuqXMlO7TnM6lBOWW318ylf4FRED/ply5eaGxkQYqdGvHSqGSN5Rb3vr5Ek0xpzSjeYD7C8Kw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/credential-provider-env": "3.943.0", + "@aws-sdk/credential-provider-http": "3.943.0", + "@aws-sdk/credential-provider-login": "3.943.0", + "@aws-sdk/credential-provider-process": "3.943.0", + "@aws-sdk/credential-provider-sso": "3.943.0", + "@aws-sdk/credential-provider-web-identity": "3.943.0", + "@aws-sdk/nested-clients": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/credential-provider-imds": "^4.2.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-login": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.943.0.tgz", + "integrity": "sha512-9iCOVkiRW+evxiJE94RqosCwRrzptAVPhRhGWv4osfYDhjNAvUMyrnZl3T1bjqCoKNcETRKEZIU3dqYHnUkcwQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/nested-clients": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-node": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.943.0.tgz", + "integrity": "sha512-14eddaH/gjCWoLSAELVrFOQNyswUYwWphIt+PdsJ/FqVfP4ay2HsiZVEIYbQtmrKHaoLJhiZKwBQRjcqJDZG0w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/credential-provider-env": "3.943.0", + "@aws-sdk/credential-provider-http": "3.943.0", + "@aws-sdk/credential-provider-ini": "3.943.0", + "@aws-sdk/credential-provider-process": "3.943.0", + "@aws-sdk/credential-provider-sso": "3.943.0", + "@aws-sdk/credential-provider-web-identity": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/credential-provider-imds": "^4.2.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-process": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.943.0.tgz", + "integrity": "sha512-GIY/vUkthL33AdjOJ8r9vOosKf/3X+X7LIiACzGxvZZrtoOiRq0LADppdiKIB48vTL63VvW+eRIOFAxE6UDekw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-sso": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.943.0.tgz", + "integrity": "sha512-1c5G11syUrru3D9OO6Uk+ul5e2lX1adb+7zQNyluNaLPXP6Dina6Sy6DFGRLu7tM8+M7luYmbS3w63rpYpaL+A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/client-sso": "3.943.0", + "@aws-sdk/core": "3.943.0", + "@aws-sdk/token-providers": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-provider-web-identity": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.943.0.tgz", + "integrity": "sha512-VtyGKHxICSb4kKGuaqotxso8JVM8RjCS3UYdIMOxUt9TaFE/CZIfZKtjTr+IJ7M0P7t36wuSUb/jRLyNmGzUUA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/nested-clients": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/credential-providers": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-providers/-/credential-providers-3.943.0.tgz", + "integrity": "sha512-uZurSNsS01ehhrSwEPwcKdqp9lmd/x9q++BYO351bXyjSj1LzA/2lfUIxI2tCz/wAjJWOdnnlUdJj6P9I1uNvw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/client-cognito-identity": "3.943.0", + "@aws-sdk/core": "3.943.0", + "@aws-sdk/credential-provider-cognito-identity": "3.943.0", + "@aws-sdk/credential-provider-env": "3.943.0", + "@aws-sdk/credential-provider-http": "3.943.0", + "@aws-sdk/credential-provider-ini": "3.943.0", + "@aws-sdk/credential-provider-login": "3.943.0", + "@aws-sdk/credential-provider-node": "3.943.0", + "@aws-sdk/credential-provider-process": "3.943.0", + "@aws-sdk/credential-provider-sso": "3.943.0", + "@aws-sdk/credential-provider-web-identity": "3.943.0", + "@aws-sdk/nested-clients": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/config-resolver": "^4.4.3", + "@smithy/core": "^3.18.5", + "@smithy/credential-provider-imds": "^4.2.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/middleware-host-header": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.936.0.tgz", + "integrity": "sha512-tAaObaAnsP1XnLGndfkGWFuzrJYuk9W0b/nLvol66t8FZExIAf/WdkT2NNAWOYxljVs++oHnyHBCxIlaHrzSiw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/middleware-logger": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.936.0.tgz", + "integrity": "sha512-aPSJ12d3a3Ea5nyEnLbijCaaYJT2QjQ9iW+zGh5QcZYXmOGWbKVyPSxmVOboZQG+c1M8t6d2O7tqrwzIq8L8qw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/middleware-recursion-detection": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.936.0.tgz", + "integrity": "sha512-l4aGbHpXM45YNgXggIux1HgsCVAvvBoqHPkqLnqMl9QVapfuSTjJHfDYDsx1Xxct6/m7qSMUzanBALhiaGO2fA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@aws/lambda-invoke-store": "^0.2.0", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/middleware-user-agent": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.943.0.tgz", + "integrity": "sha512-956n4kVEwFNXndXfhSAN5wO+KRgqiWEEY+ECwLvxmmO8uQ0NWOa8l6l65nTtyuiWzMX81c9BvlyNR5EgUeeUvA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@aws-sdk/util-endpoints": "3.936.0", + "@smithy/core": "^3.18.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/nested-clients": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.943.0.tgz", + "integrity": "sha512-anFtB0p2FPuyUnbOULwGmKYqYKSq1M73c9uZ08jR/NCq6Trjq9cuF5TFTeHwjJyPRb4wMf2Qk859oiVfFqnQiw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "3.943.0", + "@aws-sdk/middleware-host-header": "3.936.0", + "@aws-sdk/middleware-logger": "3.936.0", + "@aws-sdk/middleware-recursion-detection": "3.936.0", + "@aws-sdk/middleware-user-agent": "3.943.0", + "@aws-sdk/region-config-resolver": "3.936.0", + "@aws-sdk/types": "3.936.0", + "@aws-sdk/util-endpoints": "3.936.0", + "@aws-sdk/util-user-agent-browser": "3.936.0", + "@aws-sdk/util-user-agent-node": "3.943.0", + "@smithy/config-resolver": "^4.4.3", + "@smithy/core": "^3.18.5", + "@smithy/fetch-http-handler": "^5.3.6", + "@smithy/hash-node": "^4.2.5", + "@smithy/invalid-dependency": "^4.2.5", + "@smithy/middleware-content-length": "^4.2.5", + "@smithy/middleware-endpoint": "^4.3.12", + "@smithy/middleware-retry": "^4.4.12", + "@smithy/middleware-serde": "^4.2.6", + "@smithy/middleware-stack": "^4.2.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/node-http-handler": "^4.4.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/smithy-client": "^4.9.8", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-body-length-browser": "^4.2.0", + "@smithy/util-body-length-node": "^4.2.1", + "@smithy/util-defaults-mode-browser": "^4.3.11", + "@smithy/util-defaults-mode-node": "^4.2.14", + "@smithy/util-endpoints": "^3.2.5", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-retry": "^4.2.5", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/region-config-resolver": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.936.0.tgz", + "integrity": "sha512-wOKhzzWsshXGduxO4pqSiNyL9oUtk4BEvjWm9aaq6Hmfdoydq6v6t0rAGHWPjFwy9z2haovGRi3C8IxdMB4muw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@smithy/config-resolver": "^4.4.3", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/token-providers": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.943.0.tgz", + "integrity": "sha512-cRKyIzwfkS+XztXIFPoWORuaxlIswP+a83BJzelX4S1gUZ7FcXB4+lj9Jxjn8SbQhR4TPU3Owbpu+S7pd6IRbQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.943.0", + "@aws-sdk/nested-clients": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/types": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.936.0.tgz", + "integrity": "sha512-uz0/VlMd2pP5MepdrHizd+T+OKfyK4r3OA9JI+L/lPKg0YFQosdJNCKisr6o70E3dh8iMpFYxF1UN/4uZsyARg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/util-endpoints": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.936.0.tgz", + "integrity": "sha512-0Zx3Ntdpu+z9Wlm7JKUBOzS9EunwKAb4KdGUQQxDqh5Lc3ta5uBoub+FgmVuzwnmBu9U1Os8UuwVTH0Lgu+P5w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "@smithy/util-endpoints": "^3.2.5", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/util-locate-window": { + "version": "3.893.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.893.0.tgz", + "integrity": "sha512-T89pFfgat6c8nMmpI8eKjBcDcgJq36+m9oiXbcUzeU55MP9ZuGgBomGjGnHaEyF36jenW9gmg3NfZDm0AO2XPg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws-sdk/util-user-agent-browser": { + "version": "3.936.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.936.0.tgz", + "integrity": "sha512-eZ/XF6NxMtu+iCma58GRNRxSq4lHo6zHQLOZRIeL/ghqYJirqHdenMOwrzPettj60KWlv827RVebP9oNVrwZbw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.936.0", + "@smithy/types": "^4.9.0", + "bowser": "^2.11.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-sdk/util-user-agent-node": { + "version": "3.943.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.943.0.tgz", + "integrity": "sha512-gn+ILprVRrgAgTIBk2TDsJLRClzIOdStQFeFTcN0qpL8Z4GBCqMFhw7O7X+MM55Stt5s4jAauQ/VvoqmCADnQg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/middleware-user-agent": "3.943.0", + "@aws-sdk/types": "3.936.0", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "aws-crt": ">=1.0.0" + }, + "peerDependenciesMeta": { + "aws-crt": { + "optional": true + } + } + }, + "node_modules/@aws-sdk/xml-builder": { + "version": "3.930.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.930.0.tgz", + "integrity": "sha512-YIfkD17GocxdmlUVc3ia52QhcWuRIUJonbF8A2CYfcWNV3HzvAqpcPeC0bYUhkK+8e8YO1ARnLKZQE0TlwzorA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "fast-xml-parser": "5.2.5", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@aws/lambda-invoke-store": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.1.tgz", + "integrity": "sha512-sIyFcoPZkTtNu9xFeEoynMef3bPJIAbOfUh+ueYcfhVl6xm2VRtMcMclSxmZCMnHHd4hlYKJeq/aggmBEWynww==", + "license": "Apache-2.0", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.0.tgz", + "integrity": "sha512-KuZrd2hRjz01y5JK9mEBSD3Vj3mbCvemhT466rSuJYeE/hjuBrHfjjcjMdTm/sz7au+++sdbJZJmuBwQLuw68A==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.0.tgz", + "integrity": "sha512-j67aezrPNYWJEOHUNLPj9maeJte7uSMM6gMoxfPC9hOg8N02JuQi/T7ewumf4tNvJadFkvLZMlAq73b9uwdMyQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.0.tgz", + "integrity": "sha512-CC3vt4+1xZrs97/PKDkl0yN7w8edvU2vZvAFGD16n9F0Cvniy5qvzRXjfO1l94efczkkQE6g1x0i73Qf5uthOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.0.tgz", + "integrity": "sha512-wurMkF1nmQajBO1+0CJmcN17U4BP6GqNSROP8t0X/Jiw2ltYGLHpEksp9MpoBqkrFR3kv2/te6Sha26k3+yZ9Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.0.tgz", + "integrity": "sha512-uJOQKYCcHhg07DL7i8MzjvS2LaP7W7Pn/7uA0B5S1EnqAirJtbyw4yC5jQ5qcFjHK9l6o/MX9QisBg12kNkdHg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.0.tgz", + "integrity": "sha512-8mG6arH3yB/4ZXiEnXof5MK72dE6zM9cDvUcPtxhUZsDjESl9JipZYW60C3JGreKCEP+p8P/72r69m4AZGJd5g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.0.tgz", + "integrity": "sha512-9FHtyO988CwNMMOE3YIeci+UV+x5Zy8fI2qHNpsEtSF83YPBmE8UWmfYAQg6Ux7Gsmd4FejZqnEUZCMGaNQHQw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.0.tgz", + "integrity": "sha512-zCMeMXI4HS/tXvJz8vWGexpZj2YVtRAihHLk1imZj4efx1BQzN76YFeKqlDr3bUWI26wHwLWPd3rwh6pe4EV7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.0.tgz", + "integrity": "sha512-t76XLQDpxgmq2cNXKTVEB7O7YMb42atj2Re2Haf45HkaUpjM2J0UuJZDuaGbPbamzZ7bawyGFUkodL+zcE+jvQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.0.tgz", + "integrity": "sha512-AS18v0V+vZiLJyi/4LphvBE+OIX682Pu7ZYNsdUHyUKSoRwdnOsMf6FDekwoAFKej14WAkOef3zAORJgAtXnlQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.0.tgz", + "integrity": "sha512-Mz1jxqm/kfgKkc/KLHC5qIujMvnnarD9ra1cEcrs7qshTUSksPihGrWHVG5+osAIQ68577Zpww7SGapmzSt4Nw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.0.tgz", + "integrity": "sha512-QbEREjdJeIreIAbdG2hLU1yXm1uu+LTdzoq1KCo4G4pFOLlvIspBm36QrQOar9LFduavoWX2msNFAAAY9j4BDg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.0.tgz", + "integrity": "sha512-sJz3zRNe4tO2wxvDpH/HYJilb6+2YJxo/ZNbVdtFiKDufzWq4JmKAiHy9iGoLjAV7r/W32VgaHGkk35cUXlNOg==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.0.tgz", + "integrity": "sha512-z9N10FBD0DCS2dmSABDBb5TLAyF1/ydVb+N4pi88T45efQ/w4ohr/F/QYCkxDPnkhkp6AIpIcQKQ8F0ANoA2JA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.0.tgz", + "integrity": "sha512-pQdyAIZ0BWIC5GyvVFn5awDiO14TkT/19FTmFcPdDec94KJ1uZcmFs21Fo8auMXzD4Tt+diXu1LW1gHus9fhFQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.0.tgz", + "integrity": "sha512-hPlRWR4eIDDEci953RI1BLZitgi5uqcsjKMxwYfmi4LcwyWo2IcRP+lThVnKjNtk90pLS8nKdroXYOqW+QQH+w==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.0.tgz", + "integrity": "sha512-1hBWx4OUJE2cab++aVZ7pObD6s+DK4mPGpemtnAORBvb5l/g5xFGk0vc0PjSkrDs0XaXj9yyob3d14XqvnQ4gw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.0.tgz", + "integrity": "sha512-6m0sfQfxfQfy1qRuecMkJlf1cIzTOgyaeXaiVaaki8/v+WB+U4hc6ik15ZW6TAllRlg/WuQXxWj1jx6C+dfy3w==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.0.tgz", + "integrity": "sha512-xbbOdfn06FtcJ9d0ShxxvSn2iUsGd/lgPIO2V3VZIPDbEaIj1/3nBBe1AwuEZKXVXkMmpr6LUAgMkLD/4D2PPA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.0.tgz", + "integrity": "sha512-fWgqR8uNbCQ/GGv0yhzttj6sU/9Z5/Sv/VGU3F5OuXK6J6SlriONKrQ7tNlwBrJZXRYk5jUhuWvF7GYzGguBZQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.0.tgz", + "integrity": "sha512-aCwlRdSNMNxkGGqQajMUza6uXzR/U0dIl1QmLjPtRbLOx3Gy3otfFu/VjATy4yQzo9yFDGTxYDo1FfAD9oRD2A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.0.tgz", + "integrity": "sha512-nyvsBccxNAsNYz2jVFYwEGuRRomqZ149A39SHWk4hV0jWxKM0hjBPm3AmdxcbHiFLbBSwG6SbpIcUbXjgyECfA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.0.tgz", + "integrity": "sha512-Q1KY1iJafM+UX6CFEL+F4HRTgygmEW568YMqDA5UV97AuZSm21b7SXIrRJDwXWPzr8MGr75fUZPV67FdtMHlHA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.0.tgz", + "integrity": "sha512-W1eyGNi6d+8kOmZIwi/EDjrL9nxQIQ0MiGqe/AWc6+IaHloxHSGoeRgDRKHFISThLmsewZ5nHFvGFWdBYlgKPg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.0.tgz", + "integrity": "sha512-30z1aKL9h22kQhilnYkORFYt+3wp7yZsHWus+wSKAJR8JtdfI76LJ4SBdMsCopTR3z/ORqVu5L1vtnHZWVj4cQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.0.tgz", + "integrity": "sha512-aIitBcjQeyOhMTImhLZmtxfdOcuNRpwlPNmlFKPcHQYPhEssw75Cl1TSXJXpMkzaua9FUetx/4OQKq7eJul5Cg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@openauthjs/openauth": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@openauthjs/openauth/-/openauth-0.4.3.tgz", + "integrity": "sha512-RlnjqvHzqcbFVymEwhlUEuac4utA5h4nhSK/i2szZuQmxTIqbGUxZ+nM+avM+VV4Ing+/ZaNLKILoXS3yrkOOw==", + "dependencies": { + "@standard-schema/spec": "1.0.0-beta.3", + "aws4fetch": "1.0.20", + "jose": "5.9.6" + }, + "peerDependencies": { + "arctic": "^2.2.2", + "hono": "^4.0.0" + } + }, + "node_modules/@openauthjs/openauth/node_modules/@standard-schema/spec": { + "version": "1.0.0-beta.3", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0-beta.3.tgz", + "integrity": "sha512-0ifF3BjA1E8SY9C+nUew8RefNOIq0cDlYALPty4rhUm8Rrl6tCM8hBT4bhGhx7I7iXD0uAgt50lgo8dD73ACMw==", + "license": "MIT" + }, + "node_modules/@opencode-ai/plugin": { + "version": "1.0.143", + "resolved": "https://registry.npmjs.org/@opencode-ai/plugin/-/plugin-1.0.143.tgz", + "integrity": "sha512-yzaCmdazVJMDADJLbMM8KGp1X+Hd/HVyIXMlNt9qcvz/fcs/ET4EwHJsJaQi/9m/jLJ+plwBJAeIW08BMrECPg==", + "dev": true, + "dependencies": { + "@opencode-ai/sdk": "1.0.143", + "zod": "4.1.8" + } + }, + "node_modules/@opencode-ai/plugin/node_modules/zod": { + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.8.tgz", + "integrity": "sha512-5R1P+WwQqmmMIEACyzSvo4JXHY5WiAFHRMg+zBZKgKS+Q1viRa0C1hmUKtHltoIFKtIdki3pRxkmpP74jnNYHQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/@opencode-ai/sdk": { + "version": "1.0.143", + "resolved": "https://registry.npmjs.org/@opencode-ai/sdk/-/sdk-1.0.143.tgz", + "integrity": "sha512-dtmkBfJ7IIAHzL6KCzAlwc9GybfJONVeCsF6ePYySpkuhslDbRkZBJYb5vqGd1H5zdsgjc6JjuvmOf0rPWUL6A==" + }, + "node_modules/@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@oslojs/asn1": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@oslojs/asn1/-/asn1-1.0.0.tgz", + "integrity": "sha512-zw/wn0sj0j0QKbIXfIlnEcTviaCzYOY3V5rAyjR6YtOByFtJiT574+8p9Wlach0lZH9fddD4yb9laEAIl4vXQA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@oslojs/binary": "1.0.0" + } + }, + "node_modules/@oslojs/binary": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@oslojs/binary/-/binary-1.0.0.tgz", + "integrity": "sha512-9RCU6OwXU6p67H4NODbuxv2S3eenuQ4/WFLrsq+K/k682xrznH5EVWA7N4VFk9VYVcbFtKqur5YQQZc0ySGhsQ==", + "license": "MIT", + "peer": true + }, + "node_modules/@oslojs/crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@oslojs/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-7n08G8nWjAr/Yu3vu9zzrd0L9XnrJfpMioQcvCMxBIiF5orECHe5/3J0jmXRVvgfqMm/+4oxlQ+Sq39COYLcNQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@oslojs/asn1": "1.0.0", + "@oslojs/binary": "1.0.0" + } + }, + "node_modules/@oslojs/encoding": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-1.1.0.tgz", + "integrity": "sha512-70wQhgYmndg4GCPxPPxPGevRKqTIJ2Nh4OkiMWmDAVYsTQ+Ta7Sq+rPevXyXGdzr30/qZBnyOalCszoMxlyldQ==", + "license": "MIT", + "peer": true + }, + "node_modules/@oslojs/jwt": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@oslojs/jwt/-/jwt-0.2.0.tgz", + "integrity": "sha512-bLE7BtHrURedCn4Mco3ma9L4Y1GR2SMBuIvjWr7rmQ4/W/4Jy70TIAgZ+0nIlk0xHz1vNP8x8DCns45Sb2XRbg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@oslojs/encoding": "0.4.1" + } + }, + "node_modules/@oslojs/jwt/node_modules/@oslojs/encoding": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@oslojs/encoding/-/encoding-0.4.1.tgz", + "integrity": "sha512-hkjo6MuIK/kQR5CrGNdAPZhS01ZCXuWDRJ187zh6qqF2+yMHZpD9fAYpX8q2bOO6Ryhl3XpCT6kUX76N8hhm4Q==", + "license": "MIT", + "peer": true + }, + "node_modules/@smithy/abort-controller": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-4.2.5.tgz", + "integrity": "sha512-j7HwVkBw68YW8UmFRcjZOmssE77Rvk0GWAIN1oFBhsaovQmZWYCIcGa9/pwRB0ExI8Sk9MWNALTjftjHZea7VA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/config-resolver": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/@smithy/config-resolver/-/config-resolver-4.4.3.tgz", + "integrity": "sha512-ezHLe1tKLUxDJo2LHtDuEDyWXolw8WGOR92qb4bQdWq/zKenO5BvctZGrVJBK08zjezSk7bmbKFOXIVyChvDLw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^4.3.5", + "@smithy/types": "^4.9.0", + "@smithy/util-config-provider": "^4.2.0", + "@smithy/util-endpoints": "^3.2.5", + "@smithy/util-middleware": "^4.2.5", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/core": { + "version": "3.18.6", + "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.18.6.tgz", + "integrity": "sha512-8Q/ugWqfDUEU1Exw71+DoOzlONJ2Cn9QA8VeeDzLLjzO/qruh9UKFzbszy4jXcIYgGofxYiT0t1TT6+CT/GupQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/middleware-serde": "^4.2.6", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-body-length-browser": "^4.2.0", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-stream": "^4.5.6", + "@smithy/util-utf8": "^4.2.0", + "@smithy/uuid": "^1.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/credential-provider-imds": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.2.5.tgz", + "integrity": "sha512-BZwotjoZWn9+36nimwm/OLIcVe+KYRwzMjfhd4QT7QxPm9WY0HiOV8t/Wlh+HVUif0SBVV7ksq8//hPaBC/okQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^4.3.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/fetch-http-handler": { + "version": "5.3.6", + "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.3.6.tgz", + "integrity": "sha512-3+RG3EA6BBJ/ofZUeTFJA7mHfSYrZtQIrDP9dI8Lf7X6Jbos2jptuLrAAteDiFVrmbEmLSuRG/bUKzfAXk7dhg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/protocol-http": "^5.3.5", + "@smithy/querystring-builder": "^4.2.5", + "@smithy/types": "^4.9.0", + "@smithy/util-base64": "^4.3.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/hash-node": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/hash-node/-/hash-node-4.2.5.tgz", + "integrity": "sha512-DpYX914YOfA3UDT9CN1BM787PcHfWRBB43fFGCYrZFUH0Jv+5t8yYl+Pd5PW4+QzoGEDvn5d5QIO4j2HyYZQSA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "@smithy/util-buffer-from": "^4.2.0", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/invalid-dependency": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/invalid-dependency/-/invalid-dependency-4.2.5.tgz", + "integrity": "sha512-2L2erASEro1WC5nV+plwIMxrTXpvpfzl4e+Nre6vBVRR2HKeGGcvpJyyL3/PpiSg+cJG2KpTmZmq934Olb6e5A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/is-array-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-4.2.0.tgz", + "integrity": "sha512-DZZZBvC7sjcYh4MazJSGiWMI2L7E0oCiRHREDzIxi/M2LY79/21iXt6aPLHge82wi5LsuRF5A06Ds3+0mlh6CQ==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/middleware-content-length": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/middleware-content-length/-/middleware-content-length-4.2.5.tgz", + "integrity": "sha512-Y/RabVa5vbl5FuHYV2vUCwvh/dqzrEY/K2yWPSqvhFUwIY0atLqO4TienjBXakoy4zrKAMCZwg+YEqmH7jaN7A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/middleware-endpoint": { + "version": "4.3.13", + "resolved": "https://registry.npmjs.org/@smithy/middleware-endpoint/-/middleware-endpoint-4.3.13.tgz", + "integrity": "sha512-X4za1qCdyx1hEVVXuAWlZuK6wzLDv1uw1OY9VtaYy1lULl661+frY7FeuHdYdl7qAARUxH2yvNExU2/SmRFfcg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.18.6", + "@smithy/middleware-serde": "^4.2.6", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "@smithy/url-parser": "^4.2.5", + "@smithy/util-middleware": "^4.2.5", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/middleware-retry": { + "version": "4.4.13", + "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-4.4.13.tgz", + "integrity": "sha512-RzIDF9OrSviXX7MQeKOm8r/372KTyY8Jmp6HNKOOYlrguHADuM3ED/f4aCyNhZZFLG55lv5beBin7nL0Nzy1Dw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^4.3.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/service-error-classification": "^4.2.5", + "@smithy/smithy-client": "^4.9.9", + "@smithy/types": "^4.9.0", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-retry": "^4.2.5", + "@smithy/uuid": "^1.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/middleware-serde": { + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/@smithy/middleware-serde/-/middleware-serde-4.2.6.tgz", + "integrity": "sha512-VkLoE/z7e2g8pirwisLz8XJWedUSY8my/qrp81VmAdyrhi94T+riBfwP+AOEEFR9rFTSonC/5D2eWNmFabHyGQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/middleware-stack": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/middleware-stack/-/middleware-stack-4.2.5.tgz", + "integrity": "sha512-bYrutc+neOyWxtZdbB2USbQttZN0mXaOyYLIsaTbJhFsfpXyGWUxJpEuO1rJ8IIJm2qH4+xJT0mxUSsEDTYwdQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/node-config-provider": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/@smithy/node-config-provider/-/node-config-provider-4.3.5.tgz", + "integrity": "sha512-UTurh1C4qkVCtqggI36DGbLB2Kv8UlcFdMXDcWMbqVY2uRg0XmT9Pb4Vj6oSQ34eizO1fvR0RnFV4Axw4IrrAg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/property-provider": "^4.2.5", + "@smithy/shared-ini-file-loader": "^4.4.0", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/node-http-handler": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.4.5.tgz", + "integrity": "sha512-CMnzM9R2WqlqXQGtIlsHMEZfXKJVTIrqCNoSd/QpAyp+Dw0a1Vps13l6ma1fH8g7zSPNsA59B/kWgeylFuA/lw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/abort-controller": "^4.2.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/querystring-builder": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/property-provider": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/property-provider/-/property-provider-4.2.5.tgz", + "integrity": "sha512-8iLN1XSE1rl4MuxvQ+5OSk/Zb5El7NJZ1td6Tn+8dQQHIjp59Lwl6bd0+nzw6SKm2wSSriH2v/I9LPzUic7EOg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/protocol-http": { + "version": "5.3.5", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-5.3.5.tgz", + "integrity": "sha512-RlaL+sA0LNMp03bf7XPbFmT5gN+w3besXSWMkA8rcmxLSVfiEXElQi4O2IWwPfxzcHkxqrwBFMbngB8yx/RvaQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/querystring-builder": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-4.2.5.tgz", + "integrity": "sha512-y98otMI1saoajeik2kLfGyRp11e5U/iJYH/wLCh3aTV/XutbGT9nziKGkgCaMD1ghK7p6htHMm6b6scl9JRUWg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "@smithy/util-uri-escape": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/querystring-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/querystring-parser/-/querystring-parser-4.2.5.tgz", + "integrity": "sha512-031WCTdPYgiQRYNPXznHXof2YM0GwL6SeaSyTH/P72M1Vz73TvCNH2Nq8Iu2IEPq9QP2yx0/nrw5YmSeAi/AjQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/service-error-classification": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-4.2.5.tgz", + "integrity": "sha512-8fEvK+WPE3wUAcDvqDQG1Vk3ANLR8Px979te96m84CbKAjBVf25rPYSzb4xU4hlTyho7VhOGnh5i62D/JVF0JQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/shared-ini-file-loader": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@smithy/shared-ini-file-loader/-/shared-ini-file-loader-4.4.0.tgz", + "integrity": "sha512-5WmZ5+kJgJDjwXXIzr1vDTG+RhF9wzSODQBfkrQ2VVkYALKGvZX1lgVSxEkgicSAFnFhPj5rudJV0zoinqS0bA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/signature-v4": { + "version": "5.3.5", + "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.3.5.tgz", + "integrity": "sha512-xSUfMu1FT7ccfSXkoLl/QRQBi2rOvi3tiBZU2Tdy3I6cgvZ6SEi9QNey+lqps/sJRnogIS+lq+B1gxxbra2a/w==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/is-array-buffer": "^4.2.0", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "@smithy/util-hex-encoding": "^4.2.0", + "@smithy/util-middleware": "^4.2.5", + "@smithy/util-uri-escape": "^4.2.0", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/smithy-client": { + "version": "4.9.9", + "resolved": "https://registry.npmjs.org/@smithy/smithy-client/-/smithy-client-4.9.9.tgz", + "integrity": "sha512-SUnZJMMo5yCmgjopJbiNeo1vlr8KvdnEfIHV9rlD77QuOGdRotIVBcOrBuMr+sI9zrnhtDtLP054bZVbpZpiQA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/core": "^3.18.6", + "@smithy/middleware-endpoint": "^4.3.13", + "@smithy/middleware-stack": "^4.2.5", + "@smithy/protocol-http": "^5.3.5", + "@smithy/types": "^4.9.0", + "@smithy/util-stream": "^4.5.6", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/types": { + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.9.0.tgz", + "integrity": "sha512-MvUbdnXDTwykR8cB1WZvNNwqoWVaTRA0RLlLmf/cIFNMM2cKWz01X4Ly6SMC4Kks30r8tT3Cty0jmeWfiuyHTA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/url-parser": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/url-parser/-/url-parser-4.2.5.tgz", + "integrity": "sha512-VaxMGsilqFnK1CeBX+LXnSuaMx4sTL/6znSZh2829txWieazdVxr54HmiyTsIbpOTLcf5nYpq9lpzmwRdxj6rQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/querystring-parser": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-base64": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@smithy/util-base64/-/util-base64-4.3.0.tgz", + "integrity": "sha512-GkXZ59JfyxsIwNTWFnjmFEI8kZpRNIBfxKjv09+nkAWPt/4aGaEWMM04m4sxgNVWkbt2MdSvE3KF/PfX4nFedQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^4.2.0", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-body-length-browser": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-body-length-browser/-/util-body-length-browser-4.2.0.tgz", + "integrity": "sha512-Fkoh/I76szMKJnBXWPdFkQJl2r9SjPt3cMzLdOB6eJ4Pnpas8hVoWPYemX/peO0yrrvldgCUVJqOAjUrOLjbxg==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-body-length-node": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@smithy/util-body-length-node/-/util-body-length-node-4.2.1.tgz", + "integrity": "sha512-h53dz/pISVrVrfxV1iqXlx5pRg3V2YWFcSQyPyXZRrZoZj4R4DeWRDo1a7dd3CPTcFi3kE+98tuNyD2axyZReA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-buffer-from": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-4.2.0.tgz", + "integrity": "sha512-kAY9hTKulTNevM2nlRtxAG2FQ3B2OR6QIrPY3zE5LqJy1oxzmgBGsHLWTcNhWXKchgA0WHW+mZkQrng/pgcCew==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/is-array-buffer": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-config-provider": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-config-provider/-/util-config-provider-4.2.0.tgz", + "integrity": "sha512-YEjpl6XJ36FTKmD+kRJJWYvrHeUvm5ykaUS5xK+6oXffQPHeEM4/nXlZPe+Wu0lsgRUcNZiliYNh/y7q9c2y6Q==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-defaults-mode-browser": { + "version": "4.3.12", + "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-browser/-/util-defaults-mode-browser-4.3.12.tgz", + "integrity": "sha512-TKc6FnOxFULKxLgTNHYjcFqdOYzXVPFFVm5JhI30F3RdhT7nYOtOsjgaOwfDRmA/3U66O9KaBQ3UHoXwayRhAg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/property-provider": "^4.2.5", + "@smithy/smithy-client": "^4.9.9", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-defaults-mode-node": { + "version": "4.2.15", + "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-node/-/util-defaults-mode-node-4.2.15.tgz", + "integrity": "sha512-94NqfQVo+vGc5gsQ9SROZqOvBkGNMQu6pjXbnn8aQvBUhc31kx49gxlkBEqgmaZQHUUfdRUin5gK/HlHKmbAwg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/config-resolver": "^4.4.3", + "@smithy/credential-provider-imds": "^4.2.5", + "@smithy/node-config-provider": "^4.3.5", + "@smithy/property-provider": "^4.2.5", + "@smithy/smithy-client": "^4.9.9", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-endpoints": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/@smithy/util-endpoints/-/util-endpoints-3.2.5.tgz", + "integrity": "sha512-3O63AAWu2cSNQZp+ayl9I3NapW1p1rR5mlVHcF6hAB1dPZUQFfRPYtplWX/3xrzWthPGj5FqB12taJJCfH6s8A==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/node-config-provider": "^4.3.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-hex-encoding": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-hex-encoding/-/util-hex-encoding-4.2.0.tgz", + "integrity": "sha512-CCQBwJIvXMLKxVbO88IukazJD9a4kQ9ZN7/UMGBjBcJYvatpWk+9g870El4cB8/EJxfe+k+y0GmR9CAzkF+Nbw==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-middleware": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/util-middleware/-/util-middleware-4.2.5.tgz", + "integrity": "sha512-6Y3+rvBF7+PZOc40ybeZMcGln6xJGVeY60E7jy9Mv5iKpMJpHgRE6dKy9ScsVxvfAYuEX4Q9a65DQX90KaQ3bA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-retry": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.2.5.tgz", + "integrity": "sha512-GBj3+EZBbN4NAqJ/7pAhsXdfzdlznOh8PydUijy6FpNIMnHPSMO2/rP4HKu+UFeikJxShERk528oy7GT79YiJg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/service-error-classification": "^4.2.5", + "@smithy/types": "^4.9.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-stream": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/@smithy/util-stream/-/util-stream-4.5.6.tgz", + "integrity": "sha512-qWw/UM59TiaFrPevefOZ8CNBKbYEP6wBAIlLqxn3VAIo9rgnTNc4ASbVrqDmhuwI87usnjhdQrxodzAGFFzbRQ==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/fetch-http-handler": "^5.3.6", + "@smithy/node-http-handler": "^4.4.5", + "@smithy/types": "^4.9.0", + "@smithy/util-base64": "^4.3.0", + "@smithy/util-buffer-from": "^4.2.0", + "@smithy/util-hex-encoding": "^4.2.0", + "@smithy/util-utf8": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-uri-escape": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-4.2.0.tgz", + "integrity": "sha512-igZpCKV9+E/Mzrpq6YacdTQ0qTiLm85gD6N/IrmyDvQFA4UnU3d5g3m8tMT/6zG/vVkWSU+VxeUyGonL62DuxA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/util-utf8": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-4.2.0.tgz", + "integrity": "sha512-zBPfuzoI8xyBtR2P6WQj63Rz8i3AmfAaJLuNG8dWsfvPe8lO4aCPYLn879mEgHndZH1zQ2oXmG8O1GGzzaoZiw==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^4.2.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@smithy/uuid": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@smithy/uuid/-/uuid-1.1.0.tgz", + "integrity": "sha512-4aUIteuyxtBUhVdiQqcDhKFitwfd9hqoSDYY2KRXiWtgoWJ9Bmise+KfEPDiVHWeJepvF8xJO9/9+WDIciMFFw==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@standard-schema/spec": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz", + "integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==", + "license": "MIT" + }, + "node_modules/@tarquinen/opencode-auth-provider": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/@tarquinen/opencode-auth-provider/-/opencode-auth-provider-0.1.7.tgz", + "integrity": "sha512-FH1QEyoirr2e8b48Z6HrjioIZIZUIM9zOpYmku1ad+c4Nv70F37fSWhcObyIdZo4Ly3OntpKPWjadyRhd/kQcg==", + "license": "MIT", + "dependencies": { + "@aws-sdk/credential-providers": "^3.936.0", + "ai": "^5.0.98", + "jsonc-parser": "^3.3.1", + "opencode-anthropic-auth": "0.0.2", + "opencode-copilot-auth": "0.0.5", + "opencode-gemini-auth": "^1.1.4", + "remeda": "^2.32.0", + "xdg-basedir": "^5.1.0", + "zod": "^4.1.12" + }, + "peerDependencies": { + "@ai-sdk/amazon-bedrock": ">=1.0.0", + "@ai-sdk/anthropic": ">=1.0.0", + "@ai-sdk/azure": ">=1.0.0", + "@ai-sdk/google": ">=1.0.0", + "@ai-sdk/google-vertex": ">=1.0.0", + "@ai-sdk/openai": ">=1.0.0", + "@ai-sdk/openai-compatible": ">=0.1.0", + "@openrouter/ai-sdk-provider": ">=0.1.0" + }, + "peerDependenciesMeta": { + "@ai-sdk/amazon-bedrock": { + "optional": true + }, + "@ai-sdk/anthropic": { + "optional": true + }, + "@ai-sdk/azure": { + "optional": true + }, + "@ai-sdk/google": { + "optional": true + }, + "@ai-sdk/google-vertex": { + "optional": true + }, + "@ai-sdk/openai": { + "optional": true + }, + "@ai-sdk/openai-compatible": { + "optional": true + }, + "@openrouter/ai-sdk-provider": { + "optional": true + } + } + }, + "node_modules/@types/node": { + "version": "24.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", + "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.16.0" + } + }, + "node_modules/@vercel/oidc": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@vercel/oidc/-/oidc-3.0.5.tgz", + "integrity": "sha512-fnYhv671l+eTTp48gB4zEsTW/YtRgRPnkI2nT7x6qw5rkI1Lq2hTmQIpHPgyThI0znLK+vX2n9XxKdXZ7BUbbw==", + "license": "Apache-2.0", + "engines": { + "node": ">= 20" + } + }, + "node_modules/ai": { + "version": "5.0.106", + "resolved": "https://registry.npmjs.org/ai/-/ai-5.0.106.tgz", + "integrity": "sha512-M5obwavxSJJ3tGlAFqI6eltYNJB0D20X6gIBCFx/KVorb/X1fxVVfiZZpZb+Gslu4340droSOjT0aKQFCarNVg==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/gateway": "2.0.18", + "@ai-sdk/provider": "2.0.0", + "@ai-sdk/provider-utils": "3.0.18", + "@opentelemetry/api": "1.9.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/arctic": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/arctic/-/arctic-2.3.4.tgz", + "integrity": "sha512-+p30BOWsctZp+CVYCt7oAean/hWGW42sH5LAcRQX56ttEkFJWbzXBhmSpibbzwSJkRrotmsA+oAoJoVsU0f5xA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@oslojs/crypto": "1.0.1", + "@oslojs/encoding": "1.1.0", + "@oslojs/jwt": "0.2.0" + } + }, + "node_modules/aws4fetch": { + "version": "1.0.20", + "resolved": "https://registry.npmjs.org/aws4fetch/-/aws4fetch-1.0.20.tgz", + "integrity": "sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g==", + "license": "MIT" + }, + "node_modules/bowser": { + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.13.1.tgz", + "integrity": "sha512-OHawaAbjwx6rqICCKgSG0SAnT05bzd7ppyKLVUITZpANBaaMFBAsaNkto3LoQ31tyFP5kNujE8Cdx85G9VzOkw==", + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.0.tgz", + "integrity": "sha512-jd0f4NHbD6cALCyGElNpGAOtWxSq46l9X/sWB0Nzd5er4Kz2YTm+Vl0qKFT9KUJvD8+fiO8AvoHhFvEatfVixA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.0", + "@esbuild/android-arm": "0.27.0", + "@esbuild/android-arm64": "0.27.0", + "@esbuild/android-x64": "0.27.0", + "@esbuild/darwin-arm64": "0.27.0", + "@esbuild/darwin-x64": "0.27.0", + "@esbuild/freebsd-arm64": "0.27.0", + "@esbuild/freebsd-x64": "0.27.0", + "@esbuild/linux-arm": "0.27.0", + "@esbuild/linux-arm64": "0.27.0", + "@esbuild/linux-ia32": "0.27.0", + "@esbuild/linux-loong64": "0.27.0", + "@esbuild/linux-mips64el": "0.27.0", + "@esbuild/linux-ppc64": "0.27.0", + "@esbuild/linux-riscv64": "0.27.0", + "@esbuild/linux-s390x": "0.27.0", + "@esbuild/linux-x64": "0.27.0", + "@esbuild/netbsd-arm64": "0.27.0", + "@esbuild/netbsd-x64": "0.27.0", + "@esbuild/openbsd-arm64": "0.27.0", + "@esbuild/openbsd-x64": "0.27.0", + "@esbuild/openharmony-arm64": "0.27.0", + "@esbuild/sunos-x64": "0.27.0", + "@esbuild/win32-arm64": "0.27.0", + "@esbuild/win32-ia32": "0.27.0", + "@esbuild/win32-x64": "0.27.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/fast-xml-parser": { + "version": "5.2.5", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.2.5.tgz", + "integrity": "sha512-pfX9uG9Ki0yekDHx2SiuRIyFdyAr1kMIMitPvb0YBo8SUfKvia7w7FIyd/l6av85pFYRhZscS75MwMnbvY+hcQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT", + "dependencies": { + "strnum": "^2.1.0" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-tsconfig": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz", + "integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/gpt-tokenizer": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/gpt-tokenizer/-/gpt-tokenizer-3.4.0.tgz", + "integrity": "sha512-wxFLnhIXTDjYebd9A9pGl3e31ZpSypbpIJSOswbgop5jLte/AsZVDvjlbEuVFlsqZixVKqbcoNmRlFDf6pz/UQ==", + "license": "MIT" + }, + "node_modules/hono": { + "version": "4.10.7", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.10.7.tgz", + "integrity": "sha512-icXIITfw/07Q88nLSkB9aiUrd8rYzSweK681Kjo/TSggaGbOX4RRyxxm71v+3PC8C/j+4rlxGeoTRxQDkaJkUw==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/jose": { + "version": "5.9.6", + "resolved": "https://registry.npmjs.org/jose/-/jose-5.9.6.tgz", + "integrity": "sha512-AMlnetc9+CV9asI19zHmrgS/WYsWUwCn2R7RzlbJWD7F9eWYUTGyBmU9o6PxngtLGOiDGPRu+Uc4fhKzbpteZQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", + "license": "(AFL-2.1 OR BSD-3-Clause)" + }, + "node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "license": "MIT" + }, + "node_modules/opencode-anthropic-auth": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/opencode-anthropic-auth/-/opencode-anthropic-auth-0.0.2.tgz", + "integrity": "sha512-m8dcEKtq2ExGLV7n4BMr1H5UimDaABV6aG82IDMcp1xmXUaO1K20/hess0s8cwvv6MFmJk4//2wbWZkzoOtirA==", + "dependencies": { + "@openauthjs/openauth": "^0.4.3" + } + }, + "node_modules/opencode-copilot-auth": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/opencode-copilot-auth/-/opencode-copilot-auth-0.0.5.tgz", + "integrity": "sha512-aOna2jy3BnaEpVJkeF32joUzI8DcpbBMWjd7zW6sgX4t58AnxaEB5sDadLsxRfcxJdhmABd5k6QSww5LcJ4e9Q==" + }, + "node_modules/opencode-gemini-auth": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/opencode-gemini-auth/-/opencode-gemini-auth-1.1.6.tgz", + "integrity": "sha512-7WxOEwYMqXeCD2jf/Wj+8yBS3qwnRxHKt/sWhn2ZBDgz+dVwrC/SpTNvpva1fF8KSgVVG8tS9yvDQXM0JcVGoQ==", + "license": "MIT", + "dependencies": { + "@openauthjs/openauth": "^0.4.3" + }, + "peerDependencies": { + "typescript": "^5" + } + }, + "node_modules/prettier": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz", + "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/remeda": { + "version": "2.32.0", + "resolved": "https://registry.npmjs.org/remeda/-/remeda-2.32.0.tgz", + "integrity": "sha512-BZx9DsT4FAgXDTOdgJIc5eY6ECIXMwtlSPQoPglF20ycSWigttDDe88AozEsPPT4OWk5NujroGSBC1phw5uU+w==", + "license": "MIT", + "dependencies": { + "type-fest": "^4.41.0" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/strnum": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.1.tgz", + "integrity": "sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "license": "MIT" + }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "license": "0BSD" + }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/type-fest": { + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", + "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", + "dev": true, + "license": "MIT" + }, + "node_modules/xdg-basedir": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz", + "integrity": "sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/zod": { + "version": "4.1.13", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.13.tgz", + "integrity": "sha512-AvvthqfqrAhNH9dnfmrfKzX5upOdjUVJYFqNSlkmGf64gRaTzlPwz99IHYnVs28qYAybvAlBV+H7pn0saFY4Ig==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } - ], - "license": "MIT" - }, - "node_modules/tslib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD" - }, - "node_modules/tsx": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", - "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", - "dev": true, - "license": "MIT", - "dependencies": { - "esbuild": "~0.27.0", - "get-tsconfig": "^4.7.5" - }, - "bin": { - "tsx": "dist/cli.mjs" - }, - "engines": { - "node": ">=18.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.3" - } - }, - "node_modules/type-fest": { - "version": "4.41.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", - "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, - "node_modules/undici-types": { - "version": "7.16.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", - "integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==", - "dev": true, - "license": "MIT" - }, - "node_modules/xdg-basedir": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz", - "integrity": "sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==", - "license": "MIT", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/zod": { - "version": "4.1.13", - "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.13.tgz", - "integrity": "sha512-AvvthqfqrAhNH9dnfmrfKzX5upOdjUVJYFqNSlkmGf64gRaTzlPwz99IHYnVs28qYAybvAlBV+H7pn0saFY4Ig==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } } - } } diff --git a/package.json b/package.json index 7d1d515b..04d446bd 100644 --- a/package.json +++ b/package.json @@ -1,60 +1,63 @@ { - "$schema": "https://json.schemastore.org/package.json", - "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", - "type": "module", - "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", - "scripts": { - "clean": "rm -rf dist", - "build": "npm run clean && tsc && cp -r lib/prompts dist/lib/prompts", - "postbuild": "rm -rf dist/logs", - "prepublishOnly": "npm run build", - "dev": "opencode plugin dev", - "typecheck": "tsc --noEmit", - "test": "node --import tsx --test tests/*.test.ts" - }, - "keywords": [ - "opencode", - "opencode-plugin", - "plugin", - "context", - "pruning", - "optimization", - "tokens" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/Tarquinen/opencode-dynamic-context-pruning.git" - }, - "bugs": { - "url": "https://github.com/Tarquinen/opencode-dynamic-context-pruning/issues" - }, - "homepage": "https://github.com/Tarquinen/opencode-dynamic-context-pruning#readme", - "author": "tarquinen", - "license": "MIT", - "peerDependencies": { - "@opencode-ai/plugin": ">=0.13.7" - }, - "dependencies": { - "@ai-sdk/openai-compatible": "^1.0.28", - "@opencode-ai/sdk": "latest", - "@tarquinen/opencode-auth-provider": "^0.1.7", - "ai": "^5.0.106", - "gpt-tokenizer": "^3.4.0", - "jsonc-parser": "^3.3.1", - "zod": "^4.1.13" - }, - "devDependencies": { - "@opencode-ai/plugin": "^1.0.143", - "@types/node": "^24.10.1", - "tsx": "^4.21.0", - "typescript": "^5.9.3" - }, - "files": [ - "dist/", - "README.md", - "LICENSE" - ] + "$schema": "https://json.schemastore.org/package.json", + "name": "@tarquinen/opencode-dcp", + "version": "1.1.0-beta.1", + "type": "module", + "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "scripts": { + "clean": "rm -rf dist", + "build": "npm run clean && tsc && cp -r lib/prompts dist/lib/prompts", + "postbuild": "rm -rf dist/logs", + "prepublishOnly": "npm run build", + "dev": "opencode plugin dev", + "typecheck": "tsc --noEmit", + "test": "node --import tsx --test tests/*.test.ts", + "format": "prettier --write .", + "format:check": "prettier --check ." + }, + "keywords": [ + "opencode", + "opencode-plugin", + "plugin", + "context", + "pruning", + "optimization", + "tokens" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/Tarquinen/opencode-dynamic-context-pruning.git" + }, + "bugs": { + "url": "https://github.com/Tarquinen/opencode-dynamic-context-pruning/issues" + }, + "homepage": "https://github.com/Tarquinen/opencode-dynamic-context-pruning#readme", + "author": "tarquinen", + "license": "MIT", + "peerDependencies": { + "@opencode-ai/plugin": ">=0.13.7" + }, + "dependencies": { + "@ai-sdk/openai-compatible": "^1.0.28", + "@opencode-ai/sdk": "latest", + "@tarquinen/opencode-auth-provider": "^0.1.7", + "ai": "^5.0.106", + "gpt-tokenizer": "^3.4.0", + "jsonc-parser": "^3.3.1", + "zod": "^4.1.13" + }, + "devDependencies": { + "@opencode-ai/plugin": "^1.0.143", + "@types/node": "^24.10.1", + "prettier": "^3.4.2", + "tsx": "^4.21.0", + "typescript": "^5.9.3" + }, + "files": [ + "dist/", + "README.md", + "LICENSE" + ] } From f399b79ec109316ef1f5d54b59cc177cec2ff0e4 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Sun, 21 Dec 2025 21:17:35 -0500 Subject: [PATCH 31/43] style: apply prettier formatting to codebase --- README.md | 111 ++++---- index.ts | 19 +- lib/config.ts | 415 ++++++++++++++++++----------- lib/hooks.ts | 24 +- lib/logger.ts | 21 +- lib/messages/prune.ts | 63 ++--- lib/messages/utils.ts | 16 +- lib/model-selector.ts | 164 ++++++------ lib/prompt.ts | 201 +++++++------- lib/shared-utils.ts | 13 +- lib/state/persistence.ts | 82 +++--- lib/state/state.ts | 21 +- lib/state/tool-cache.ts | 39 ++- lib/state/types.ts | 4 +- lib/strategies/deduplication.ts | 8 +- lib/strategies/on-idle.ts | 76 +++--- lib/strategies/supersede-writes.ts | 12 +- lib/strategies/tools.ts | 98 ++++--- lib/strategies/utils.ts | 41 +-- lib/ui/notification.ts | 81 +++--- lib/ui/utils.ts | 24 +- tsconfig.json | 51 ++-- 22 files changed, 845 insertions(+), 739 deletions(-) diff --git a/README.md b/README.md index dae9525b..c5484b54 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add to your OpenCode config: ```jsonc // opencode.jsonc { - "plugin": ["@tarquinen/opencode-dcp@latest"] + "plugin": ["@tarquinen/opencode-dcp@latest"], } ``` @@ -56,63 +56,63 @@ DCP uses its own config file: ```jsonc { - // Enable or disable the plugin - "enabled": true, - // Enable debug logging to ~/.config/opencode/logs/dcp/ - "debug": false, - // Notification display: "off", "minimal", or "detailed" - "pruneNotification": "detailed", - // Protect from pruning for message turns - "turnProtection": { - "enabled": false, - "turns": 4 - }, - // LLM-driven context pruning tools - "tools": { - // Shared settings for all prune tools - "settings": { - // Nudge the LLM to use prune tools (every tool results) - "nudgeEnabled": true, - "nudgeFrequency": 10, - // Additional tools to protect from pruning - "protectedTools": [] + // Enable or disable the plugin + "enabled": true, + // Enable debug logging to ~/.config/opencode/logs/dcp/ + "debug": false, + // Notification display: "off", "minimal", or "detailed" + "pruneNotification": "detailed", + // Protect from pruning for message turns + "turnProtection": { + "enabled": false, + "turns": 4, }, - // Removes tool content from context without preservation (for completed tasks or noise) - "discard": { - "enabled": true + // LLM-driven context pruning tools + "tools": { + // Shared settings for all prune tools + "settings": { + // Nudge the LLM to use prune tools (every tool results) + "nudgeEnabled": true, + "nudgeFrequency": 10, + // Additional tools to protect from pruning + "protectedTools": [], + }, + // Removes tool content from context without preservation (for completed tasks or noise) + "discard": { + "enabled": true, + }, + // Distills key findings into preserved knowledge before removing raw content + "extract": { + "enabled": true, + // Show distillation content as an ignored message notification + "showDistillation": false, + }, }, - // Distills key findings into preserved knowledge before removing raw content - "extract": { - "enabled": true, - // Show distillation content as an ignored message notification - "showDistillation": false - } - }, - // Automatic pruning strategies - "strategies": { - // Remove duplicate tool calls (same tool with same arguments) - "deduplication": { - "enabled": true, - // Additional tools to protect from pruning - "protectedTools": [] + // Automatic pruning strategies + "strategies": { + // Remove duplicate tool calls (same tool with same arguments) + "deduplication": { + "enabled": true, + // Additional tools to protect from pruning + "protectedTools": [], + }, + // Prune write tool inputs when the file has been subsequently read + "supersedeWrites": { + "enabled": true, + }, + // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle + "onIdle": { + "enabled": false, + // Additional tools to protect from pruning + "protectedTools": [], + // Override model for analysis (format: "provider/model") + // "model": "anthropic/claude-haiku-4-5", + // Show toast notifications when model selection fails + "showModelErrorToasts": true, + // When true, fallback models are not permitted + "strictModelSelection": false, + }, }, - // Prune write tool inputs when the file has been subsequently read - "supersedeWrites": { - "enabled": true - }, - // (Legacy) Run an LLM to analyze what tool calls are no longer relevant on idle - "onIdle": { - "enabled": false, - // Additional tools to protect from pruning - "protectedTools": [], - // Override model for analysis (format: "provider/model") - // "model": "anthropic/claude-haiku-4-5", - // Show toast notifications when model selection fails - "showModelErrorToasts": true, - // When true, fallback models are not permitted - "strictModelSelection": false - } - } } ``` @@ -128,6 +128,7 @@ By default, these tools are always protected from pruning across all strategies: `task`, `todowrite`, `todoread`, `discard`, `extract`, `batch` The `protectedTools` arrays in each section add to this default list: + - `tools.settings.protectedTools` — Protects tools from the `discard` and `extract` tools - `strategies.deduplication.protectedTools` — Protects tools from deduplication - `strategies.onIdle.protectedTools` — Protects tools from on-idle analysis diff --git a/index.ts b/index.ts index d5f60de4..2da6abee 100644 --- a/index.ts +++ b/index.ts @@ -14,8 +14,8 @@ const plugin: Plugin = (async (ctx) => { } // Suppress AI SDK warnings - if (typeof globalThis !== 'undefined') { - (globalThis as any).AI_SDK_LOG_WARNINGS = false + if (typeof globalThis !== "undefined") { + ;(globalThis as any).AI_SDK_LOG_WARNINGS = false } const logger = new Logger(config.debug) @@ -26,7 +26,10 @@ const plugin: Plugin = (async (ctx) => { }) return { - "experimental.chat.system.transform": async (_input: unknown, output: { system: string[] }) => { + "experimental.chat.system.transform": async ( + _input: unknown, + output: { system: string[] }, + ) => { const discardEnabled = config.tools.discard.enabled const extractEnabled = config.tools.extract.enabled @@ -48,7 +51,7 @@ const plugin: Plugin = (async (ctx) => { ctx.client, state, logger, - config + config, ), tool: { ...(config.tools.discard.enabled && { @@ -57,7 +60,7 @@ const plugin: Plugin = (async (ctx) => { state, logger, config, - workingDirectory: ctx.directory + workingDirectory: ctx.directory, }), }), ...(config.tools.extract.enabled && { @@ -66,7 +69,7 @@ const plugin: Plugin = (async (ctx) => { state, logger, config, - workingDirectory: ctx.directory + workingDirectory: ctx.directory, }), }), }, @@ -83,7 +86,9 @@ const plugin: Plugin = (async (ctx) => { ...opencodeConfig.experimental, primary_tools: [...existingPrimaryTools, ...toolsToAdd], } - logger.info(`Added ${toolsToAdd.map(t => `'${t}'`).join(" and ")} to experimental.primary_tools via config mutation`) + logger.info( + `Added ${toolsToAdd.map((t) => `'${t}'`).join(" and ")} to experimental.primary_tools via config mutation`, + ) } }, event: createEventHandler(ctx.client, config, state, logger, ctx.directory), diff --git a/lib/config.ts b/lib/config.ts index d15f15fb..06a2d7a0 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,8 +1,8 @@ -import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from 'fs' -import { join, dirname } from 'path' -import { homedir } from 'os' -import { parse } from 'jsonc-parser' -import type { PluginInput } from '@opencode-ai/plugin' +import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from "fs" +import { join, dirname } from "path" +import { homedir } from "os" +import { parse } from "jsonc-parser" +import type { PluginInput } from "@opencode-ai/plugin" export interface Deduplication { enabled: boolean @@ -60,52 +60,52 @@ export interface PluginConfig { } } -const DEFAULT_PROTECTED_TOOLS = ['task', 'todowrite', 'todoread', 'discard', 'extract', 'batch'] +const DEFAULT_PROTECTED_TOOLS = ["task", "todowrite", "todoread", "discard", "extract", "batch"] // Valid config keys for validation against user config export const VALID_CONFIG_KEYS = new Set([ // Top-level keys - 'enabled', - 'debug', - 'showUpdateToasts', // Deprecated but kept for backwards compatibility - 'pruneNotification', - 'turnProtection', - 'turnProtection.enabled', - 'turnProtection.turns', - 'tools', - 'tools.settings', - 'tools.settings.nudgeEnabled', - 'tools.settings.nudgeFrequency', - 'tools.settings.protectedTools', - 'tools.discard', - 'tools.discard.enabled', - 'tools.extract', - 'tools.extract.enabled', - 'tools.extract.showDistillation', - 'strategies', + "enabled", + "debug", + "showUpdateToasts", // Deprecated but kept for backwards compatibility + "pruneNotification", + "turnProtection", + "turnProtection.enabled", + "turnProtection.turns", + "tools", + "tools.settings", + "tools.settings.nudgeEnabled", + "tools.settings.nudgeFrequency", + "tools.settings.protectedTools", + "tools.discard", + "tools.discard.enabled", + "tools.extract", + "tools.extract.enabled", + "tools.extract.showDistillation", + "strategies", // strategies.deduplication - 'strategies.deduplication', - 'strategies.deduplication.enabled', - 'strategies.deduplication.protectedTools', + "strategies.deduplication", + "strategies.deduplication.enabled", + "strategies.deduplication.protectedTools", // strategies.supersedeWrites - 'strategies.supersedeWrites', - 'strategies.supersedeWrites.enabled', + "strategies.supersedeWrites", + "strategies.supersedeWrites.enabled", // strategies.onIdle - 'strategies.onIdle', - 'strategies.onIdle.enabled', - 'strategies.onIdle.model', - 'strategies.onIdle.showModelErrorToasts', - 'strategies.onIdle.strictModelSelection', - 'strategies.onIdle.protectedTools' + "strategies.onIdle", + "strategies.onIdle.enabled", + "strategies.onIdle.model", + "strategies.onIdle.showModelErrorToasts", + "strategies.onIdle.strictModelSelection", + "strategies.onIdle.protectedTools", ]) // Extract all key paths from a config object for validation -function getConfigKeyPaths(obj: Record, prefix = ''): string[] { +function getConfigKeyPaths(obj: Record, prefix = ""): string[] { const keys: string[] = [] for (const key of Object.keys(obj)) { const fullKey = prefix ? `${prefix}.${key}` : key keys.push(fullKey) - if (obj[key] && typeof obj[key] === 'object' && !Array.isArray(obj[key])) { + if (obj[key] && typeof obj[key] === "object" && !Array.isArray(obj[key])) { keys.push(...getConfigKeyPaths(obj[key], fullKey)) } } @@ -115,7 +115,7 @@ function getConfigKeyPaths(obj: Record, prefix = ''): string[] { // Returns invalid keys found in user config export function getInvalidConfigKeys(userConfig: Record): string[] { const userKeys = getConfigKeyPaths(userConfig) - return userKeys.filter(key => !VALID_CONFIG_KEYS.has(key)) + return userKeys.filter((key) => !VALID_CONFIG_KEYS.has(key)) } // Type validators for config values @@ -129,26 +129,44 @@ function validateConfigTypes(config: Record): ValidationError[] { const errors: ValidationError[] = [] // Top-level validators - if (config.enabled !== undefined && typeof config.enabled !== 'boolean') { - errors.push({ key: 'enabled', expected: 'boolean', actual: typeof config.enabled }) + if (config.enabled !== undefined && typeof config.enabled !== "boolean") { + errors.push({ key: "enabled", expected: "boolean", actual: typeof config.enabled }) } - if (config.debug !== undefined && typeof config.debug !== 'boolean') { - errors.push({ key: 'debug', expected: 'boolean', actual: typeof config.debug }) + if (config.debug !== undefined && typeof config.debug !== "boolean") { + errors.push({ key: "debug", expected: "boolean", actual: typeof config.debug }) } if (config.pruneNotification !== undefined) { - const validValues = ['off', 'minimal', 'detailed'] + const validValues = ["off", "minimal", "detailed"] if (!validValues.includes(config.pruneNotification)) { - errors.push({ key: 'pruneNotification', expected: '"off" | "minimal" | "detailed"', actual: JSON.stringify(config.pruneNotification) }) + errors.push({ + key: "pruneNotification", + expected: '"off" | "minimal" | "detailed"', + actual: JSON.stringify(config.pruneNotification), + }) } } // Top-level turnProtection validator if (config.turnProtection) { - if (config.turnProtection.enabled !== undefined && typeof config.turnProtection.enabled !== 'boolean') { - errors.push({ key: 'turnProtection.enabled', expected: 'boolean', actual: typeof config.turnProtection.enabled }) + if ( + config.turnProtection.enabled !== undefined && + typeof config.turnProtection.enabled !== "boolean" + ) { + errors.push({ + key: "turnProtection.enabled", + expected: "boolean", + actual: typeof config.turnProtection.enabled, + }) } - if (config.turnProtection.turns !== undefined && typeof config.turnProtection.turns !== 'number') { - errors.push({ key: 'turnProtection.turns', expected: 'number', actual: typeof config.turnProtection.turns }) + if ( + config.turnProtection.turns !== undefined && + typeof config.turnProtection.turns !== "number" + ) { + errors.push({ + key: "turnProtection.turns", + expected: "number", + actual: typeof config.turnProtection.turns, + }) } } @@ -156,27 +174,63 @@ function validateConfigTypes(config: Record): ValidationError[] { const tools = config.tools if (tools) { if (tools.settings) { - if (tools.settings.nudgeEnabled !== undefined && typeof tools.settings.nudgeEnabled !== 'boolean') { - errors.push({ key: 'tools.settings.nudgeEnabled', expected: 'boolean', actual: typeof tools.settings.nudgeEnabled }) + if ( + tools.settings.nudgeEnabled !== undefined && + typeof tools.settings.nudgeEnabled !== "boolean" + ) { + errors.push({ + key: "tools.settings.nudgeEnabled", + expected: "boolean", + actual: typeof tools.settings.nudgeEnabled, + }) } - if (tools.settings.nudgeFrequency !== undefined && typeof tools.settings.nudgeFrequency !== 'number') { - errors.push({ key: 'tools.settings.nudgeFrequency', expected: 'number', actual: typeof tools.settings.nudgeFrequency }) + if ( + tools.settings.nudgeFrequency !== undefined && + typeof tools.settings.nudgeFrequency !== "number" + ) { + errors.push({ + key: "tools.settings.nudgeFrequency", + expected: "number", + actual: typeof tools.settings.nudgeFrequency, + }) } - if (tools.settings.protectedTools !== undefined && !Array.isArray(tools.settings.protectedTools)) { - errors.push({ key: 'tools.settings.protectedTools', expected: 'string[]', actual: typeof tools.settings.protectedTools }) + if ( + tools.settings.protectedTools !== undefined && + !Array.isArray(tools.settings.protectedTools) + ) { + errors.push({ + key: "tools.settings.protectedTools", + expected: "string[]", + actual: typeof tools.settings.protectedTools, + }) } } if (tools.discard) { - if (tools.discard.enabled !== undefined && typeof tools.discard.enabled !== 'boolean') { - errors.push({ key: 'tools.discard.enabled', expected: 'boolean', actual: typeof tools.discard.enabled }) + if (tools.discard.enabled !== undefined && typeof tools.discard.enabled !== "boolean") { + errors.push({ + key: "tools.discard.enabled", + expected: "boolean", + actual: typeof tools.discard.enabled, + }) } } if (tools.extract) { - if (tools.extract.enabled !== undefined && typeof tools.extract.enabled !== 'boolean') { - errors.push({ key: 'tools.extract.enabled', expected: 'boolean', actual: typeof tools.extract.enabled }) + if (tools.extract.enabled !== undefined && typeof tools.extract.enabled !== "boolean") { + errors.push({ + key: "tools.extract.enabled", + expected: "boolean", + actual: typeof tools.extract.enabled, + }) } - if (tools.extract.showDistillation !== undefined && typeof tools.extract.showDistillation !== 'boolean') { - errors.push({ key: 'tools.extract.showDistillation', expected: 'boolean', actual: typeof tools.extract.showDistillation }) + if ( + tools.extract.showDistillation !== undefined && + typeof tools.extract.showDistillation !== "boolean" + ) { + errors.push({ + key: "tools.extract.showDistillation", + expected: "boolean", + actual: typeof tools.extract.showDistillation, + }) } } } @@ -185,36 +239,92 @@ function validateConfigTypes(config: Record): ValidationError[] { const strategies = config.strategies if (strategies) { // deduplication - if (strategies.deduplication?.enabled !== undefined && typeof strategies.deduplication.enabled !== 'boolean') { - errors.push({ key: 'strategies.deduplication.enabled', expected: 'boolean', actual: typeof strategies.deduplication.enabled }) + if ( + strategies.deduplication?.enabled !== undefined && + typeof strategies.deduplication.enabled !== "boolean" + ) { + errors.push({ + key: "strategies.deduplication.enabled", + expected: "boolean", + actual: typeof strategies.deduplication.enabled, + }) } - if (strategies.deduplication?.protectedTools !== undefined && !Array.isArray(strategies.deduplication.protectedTools)) { - errors.push({ key: 'strategies.deduplication.protectedTools', expected: 'string[]', actual: typeof strategies.deduplication.protectedTools }) + if ( + strategies.deduplication?.protectedTools !== undefined && + !Array.isArray(strategies.deduplication.protectedTools) + ) { + errors.push({ + key: "strategies.deduplication.protectedTools", + expected: "string[]", + actual: typeof strategies.deduplication.protectedTools, + }) } // onIdle if (strategies.onIdle) { - if (strategies.onIdle.enabled !== undefined && typeof strategies.onIdle.enabled !== 'boolean') { - errors.push({ key: 'strategies.onIdle.enabled', expected: 'boolean', actual: typeof strategies.onIdle.enabled }) + if ( + strategies.onIdle.enabled !== undefined && + typeof strategies.onIdle.enabled !== "boolean" + ) { + errors.push({ + key: "strategies.onIdle.enabled", + expected: "boolean", + actual: typeof strategies.onIdle.enabled, + }) } - if (strategies.onIdle.model !== undefined && typeof strategies.onIdle.model !== 'string') { - errors.push({ key: 'strategies.onIdle.model', expected: 'string', actual: typeof strategies.onIdle.model }) + if ( + strategies.onIdle.model !== undefined && + typeof strategies.onIdle.model !== "string" + ) { + errors.push({ + key: "strategies.onIdle.model", + expected: "string", + actual: typeof strategies.onIdle.model, + }) } - if (strategies.onIdle.showModelErrorToasts !== undefined && typeof strategies.onIdle.showModelErrorToasts !== 'boolean') { - errors.push({ key: 'strategies.onIdle.showModelErrorToasts', expected: 'boolean', actual: typeof strategies.onIdle.showModelErrorToasts }) + if ( + strategies.onIdle.showModelErrorToasts !== undefined && + typeof strategies.onIdle.showModelErrorToasts !== "boolean" + ) { + errors.push({ + key: "strategies.onIdle.showModelErrorToasts", + expected: "boolean", + actual: typeof strategies.onIdle.showModelErrorToasts, + }) } - if (strategies.onIdle.strictModelSelection !== undefined && typeof strategies.onIdle.strictModelSelection !== 'boolean') { - errors.push({ key: 'strategies.onIdle.strictModelSelection', expected: 'boolean', actual: typeof strategies.onIdle.strictModelSelection }) + if ( + strategies.onIdle.strictModelSelection !== undefined && + typeof strategies.onIdle.strictModelSelection !== "boolean" + ) { + errors.push({ + key: "strategies.onIdle.strictModelSelection", + expected: "boolean", + actual: typeof strategies.onIdle.strictModelSelection, + }) } - if (strategies.onIdle.protectedTools !== undefined && !Array.isArray(strategies.onIdle.protectedTools)) { - errors.push({ key: 'strategies.onIdle.protectedTools', expected: 'string[]', actual: typeof strategies.onIdle.protectedTools }) + if ( + strategies.onIdle.protectedTools !== undefined && + !Array.isArray(strategies.onIdle.protectedTools) + ) { + errors.push({ + key: "strategies.onIdle.protectedTools", + expected: "string[]", + actual: typeof strategies.onIdle.protectedTools, + }) } } // supersedeWrites if (strategies.supersedeWrites) { - if (strategies.supersedeWrites.enabled !== undefined && typeof strategies.supersedeWrites.enabled !== 'boolean') { - errors.push({ key: 'strategies.supersedeWrites.enabled', expected: 'boolean', actual: typeof strategies.supersedeWrites.enabled }) + if ( + strategies.supersedeWrites.enabled !== undefined && + typeof strategies.supersedeWrites.enabled !== "boolean" + ) { + errors.push({ + key: "strategies.supersedeWrites.enabled", + expected: "boolean", + actual: typeof strategies.supersedeWrites.enabled, + }) } } } @@ -227,7 +337,7 @@ function showConfigValidationWarnings( ctx: PluginInput, configPath: string, configData: Record, - isProject: boolean + isProject: boolean, ): void { const invalidKeys = getInvalidConfigKeys(configData) const typeErrors = validateConfigTypes(configData) @@ -236,12 +346,12 @@ function showConfigValidationWarnings( return } - const configType = isProject ? 'project config' : 'config' + const configType = isProject ? "project config" : "config" const messages: string[] = [] if (invalidKeys.length > 0) { - const keyList = invalidKeys.slice(0, 3).join(', ') - const suffix = invalidKeys.length > 3 ? ` (+${invalidKeys.length - 3} more)` : '' + const keyList = invalidKeys.slice(0, 3).join(", ") + const suffix = invalidKeys.length > 3 ? ` (+${invalidKeys.length - 3} more)` : "" messages.push(`Unknown keys: ${keyList}${suffix}`) } @@ -259,10 +369,10 @@ function showConfigValidationWarnings( ctx.client.tui.showToast({ body: { title: `DCP: Invalid ${configType}`, - message: `${configPath}\n${messages.join('\n')}`, + message: `${configPath}\n${messages.join("\n")}`, variant: "warning", - duration: 7000 - } + duration: 7000, + }, }) } catch {} }, 7000) @@ -271,50 +381,50 @@ function showConfigValidationWarnings( const defaultConfig: PluginConfig = { enabled: true, debug: false, - pruneNotification: 'detailed', + pruneNotification: "detailed", turnProtection: { enabled: false, - turns: 4 + turns: 4, }, tools: { settings: { nudgeEnabled: true, nudgeFrequency: 10, - protectedTools: [...DEFAULT_PROTECTED_TOOLS] + protectedTools: [...DEFAULT_PROTECTED_TOOLS], }, discard: { - enabled: true + enabled: true, }, extract: { enabled: true, - showDistillation: false - } + showDistillation: false, + }, }, strategies: { deduplication: { enabled: true, - protectedTools: [...DEFAULT_PROTECTED_TOOLS] + protectedTools: [...DEFAULT_PROTECTED_TOOLS], }, supersedeWrites: { - enabled: true + enabled: true, }, onIdle: { enabled: false, protectedTools: [...DEFAULT_PROTECTED_TOOLS], showModelErrorToasts: true, - strictModelSelection: false - } - } + strictModelSelection: false, + }, + }, } -const GLOBAL_CONFIG_DIR = join(homedir(), '.config', 'opencode') -const GLOBAL_CONFIG_PATH_JSONC = join(GLOBAL_CONFIG_DIR, 'dcp.jsonc') -const GLOBAL_CONFIG_PATH_JSON = join(GLOBAL_CONFIG_DIR, 'dcp.json') +const GLOBAL_CONFIG_DIR = join(homedir(), ".config", "opencode") +const GLOBAL_CONFIG_PATH_JSONC = join(GLOBAL_CONFIG_DIR, "dcp.jsonc") +const GLOBAL_CONFIG_PATH_JSON = join(GLOBAL_CONFIG_DIR, "dcp.json") function findOpencodeDir(startDir: string): string | null { let current = startDir - while (current !== '/') { - const candidate = join(current, '.opencode') + while (current !== "/") { + const candidate = join(current, ".opencode") if (existsSync(candidate) && statSync(candidate).isDirectory()) { return candidate } @@ -325,7 +435,11 @@ function findOpencodeDir(startDir: string): string | null { return null } -function getConfigPaths(ctx?: PluginInput): { global: string | null, configDir: string | null, project: string | null} { +function getConfigPaths(ctx?: PluginInput): { + global: string | null + configDir: string | null + project: string | null +} { // Global: ~/.config/opencode/dcp.jsonc|json let globalPath: string | null = null if (existsSync(GLOBAL_CONFIG_PATH_JSONC)) { @@ -338,8 +452,8 @@ function getConfigPaths(ctx?: PluginInput): { global: string | null, configDir: let configDirPath: string | null = null const opencodeConfigDir = process.env.OPENCODE_CONFIG_DIR if (opencodeConfigDir) { - const configJsonc = join(opencodeConfigDir, 'dcp.jsonc') - const configJson = join(opencodeConfigDir, 'dcp.json') + const configJsonc = join(opencodeConfigDir, "dcp.jsonc") + const configJson = join(opencodeConfigDir, "dcp.json") if (existsSync(configJsonc)) { configDirPath = configJsonc } else if (existsSync(configJson)) { @@ -352,8 +466,8 @@ function getConfigPaths(ctx?: PluginInput): { global: string | null, configDir: if (ctx?.directory) { const opencodeDir = findOpencodeDir(ctx.directory) if (opencodeDir) { - const projectJsonc = join(opencodeDir, 'dcp.jsonc') - const projectJson = join(opencodeDir, 'dcp.json') + const projectJsonc = join(opencodeDir, "dcp.jsonc") + const projectJson = join(opencodeDir, "dcp.json") if (existsSync(projectJsonc)) { projectPath = projectJsonc } else if (existsSync(projectJson)) { @@ -430,7 +544,7 @@ function createDefaultConfig(): void { } } ` - writeFileSync(GLOBAL_CONFIG_PATH_JSONC, configContent, 'utf-8') + writeFileSync(GLOBAL_CONFIG_PATH_JSONC, configContent, "utf-8") } interface ConfigLoadResult { @@ -441,7 +555,7 @@ interface ConfigLoadResult { function loadConfigFile(configPath: string): ConfigLoadResult { let fileContent: string try { - fileContent = readFileSync(configPath, 'utf-8') + fileContent = readFileSync(configPath, "utf-8") } catch { // File doesn't exist or can't be read - not a parse error return { data: null } @@ -450,18 +564,18 @@ function loadConfigFile(configPath: string): ConfigLoadResult { try { const parsed = parse(fileContent) if (parsed === undefined || parsed === null) { - return { data: null, parseError: 'Config file is empty or invalid' } + return { data: null, parseError: "Config file is empty or invalid" } } return { data: parsed } } catch (error: any) { - return { data: null, parseError: error.message || 'Failed to parse config' } + return { data: null, parseError: error.message || "Failed to parse config" } } } function mergeStrategies( - base: PluginConfig['strategies'], - override?: Partial -): PluginConfig['strategies'] { + base: PluginConfig["strategies"], + override?: Partial, +): PluginConfig["strategies"] { if (!override) return base return { @@ -470,32 +584,34 @@ function mergeStrategies( protectedTools: [ ...new Set([ ...base.deduplication.protectedTools, - ...(override.deduplication?.protectedTools ?? []) - ]) - ] + ...(override.deduplication?.protectedTools ?? []), + ]), + ], }, onIdle: { enabled: override.onIdle?.enabled ?? base.onIdle.enabled, model: override.onIdle?.model ?? base.onIdle.model, - showModelErrorToasts: override.onIdle?.showModelErrorToasts ?? base.onIdle.showModelErrorToasts, - strictModelSelection: override.onIdle?.strictModelSelection ?? base.onIdle.strictModelSelection, + showModelErrorToasts: + override.onIdle?.showModelErrorToasts ?? base.onIdle.showModelErrorToasts, + strictModelSelection: + override.onIdle?.strictModelSelection ?? base.onIdle.strictModelSelection, protectedTools: [ ...new Set([ ...base.onIdle.protectedTools, - ...(override.onIdle?.protectedTools ?? []) - ]) - ] + ...(override.onIdle?.protectedTools ?? []), + ]), + ], }, supersedeWrites: { - enabled: override.supersedeWrites?.enabled ?? base.supersedeWrites.enabled - } + enabled: override.supersedeWrites?.enabled ?? base.supersedeWrites.enabled, + }, } } function mergeTools( - base: PluginConfig['tools'], - override?: Partial -): PluginConfig['tools'] { + base: PluginConfig["tools"], + override?: Partial, +): PluginConfig["tools"] { if (!override) return base return { @@ -505,17 +621,17 @@ function mergeTools( protectedTools: [ ...new Set([ ...base.settings.protectedTools, - ...(override.settings?.protectedTools ?? []) - ]) - ] + ...(override.settings?.protectedTools ?? []), + ]), + ], }, discard: { - enabled: override.discard?.enabled ?? base.discard.enabled + enabled: override.discard?.enabled ?? base.discard.enabled, }, extract: { enabled: override.extract?.enabled ?? base.extract.enabled, - showDistillation: override.extract?.showDistillation ?? base.extract.showDistillation - } + showDistillation: override.extract?.showDistillation ?? base.extract.showDistillation, + }, } } @@ -526,28 +642,27 @@ function deepCloneConfig(config: PluginConfig): PluginConfig { tools: { settings: { ...config.tools.settings, - protectedTools: [...config.tools.settings.protectedTools] + protectedTools: [...config.tools.settings.protectedTools], }, discard: { ...config.tools.discard }, - extract: { ...config.tools.extract } + extract: { ...config.tools.extract }, }, strategies: { deduplication: { ...config.strategies.deduplication, - protectedTools: [...config.strategies.deduplication.protectedTools] + protectedTools: [...config.strategies.deduplication.protectedTools], }, onIdle: { ...config.strategies.onIdle, - protectedTools: [...config.strategies.onIdle.protectedTools] + protectedTools: [...config.strategies.onIdle.protectedTools], }, supersedeWrites: { - ...config.strategies.supersedeWrites - } - } + ...config.strategies.supersedeWrites, + }, + }, } } - export function getConfig(ctx: PluginInput): PluginConfig { let config = deepCloneConfig(defaultConfig) const configPaths = getConfigPaths(ctx) @@ -563,8 +678,8 @@ export function getConfig(ctx: PluginInput): PluginConfig { title: "DCP: Invalid config", message: `${configPaths.global}\n${result.parseError}\nUsing default values`, variant: "warning", - duration: 7000 - } + duration: 7000, + }, }) } catch {} }, 7000) @@ -577,10 +692,10 @@ export function getConfig(ctx: PluginInput): PluginConfig { pruneNotification: result.data.pruneNotification ?? config.pruneNotification, turnProtection: { enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, - turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns, }, tools: mergeTools(config.tools, result.data.tools as any), - strategies: mergeStrategies(config.strategies, result.data.strategies as any) + strategies: mergeStrategies(config.strategies, result.data.strategies as any), } } } else { @@ -599,8 +714,8 @@ export function getConfig(ctx: PluginInput): PluginConfig { title: "DCP: Invalid configDir config", message: `${configPaths.configDir}\n${result.parseError}\nUsing global/default values`, variant: "warning", - duration: 7000 - } + duration: 7000, + }, }) } catch {} }, 7000) @@ -613,10 +728,10 @@ export function getConfig(ctx: PluginInput): PluginConfig { pruneNotification: result.data.pruneNotification ?? config.pruneNotification, turnProtection: { enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, - turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns, }, tools: mergeTools(config.tools, result.data.tools as any), - strategies: mergeStrategies(config.strategies, result.data.strategies as any) + strategies: mergeStrategies(config.strategies, result.data.strategies as any), } } } @@ -632,8 +747,8 @@ export function getConfig(ctx: PluginInput): PluginConfig { title: "DCP: Invalid project config", message: `${configPaths.project}\n${result.parseError}\nUsing global/default values`, variant: "warning", - duration: 7000 - } + duration: 7000, + }, }) } catch {} }, 7000) @@ -646,10 +761,10 @@ export function getConfig(ctx: PluginInput): PluginConfig { pruneNotification: result.data.pruneNotification ?? config.pruneNotification, turnProtection: { enabled: result.data.turnProtection?.enabled ?? config.turnProtection.enabled, - turns: result.data.turnProtection?.turns ?? config.turnProtection.turns + turns: result.data.turnProtection?.turns ?? config.turnProtection.turns, }, tools: mergeTools(config.tools, result.data.tools as any), - strategies: mergeStrategies(config.strategies, result.data.strategies as any) + strategies: mergeStrategies(config.strategies, result.data.strategies as any), } } } diff --git a/lib/hooks.ts b/lib/hooks.ts index c578e4bb..b9ef006a 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -7,24 +7,20 @@ import { prune, insertPruneToolContext } from "./messages" import { checkSession } from "./state" import { runOnIdle } from "./strategies/on-idle" - export function createChatMessageTransformHandler( client: any, state: SessionState, logger: Logger, - config: PluginConfig + config: PluginConfig, ) { - return async ( - input: {}, - output: { messages: WithParts[] } - ) => { + return async (input: {}, output: { messages: WithParts[] }) => { await checkSession(client, state, logger, output.messages) if (state.isSubAgent) { return } - syncToolCache(state, config, logger, output.messages); + syncToolCache(state, config, logger, output.messages) deduplicate(state, logger, config, output.messages) supersedeWrites(state, logger, config, output.messages) @@ -40,11 +36,9 @@ export function createEventHandler( config: PluginConfig, state: SessionState, logger: Logger, - workingDirectory?: string + workingDirectory?: string, ) { - return async ( - { event }: { event: any } - ) => { + return async ({ event }: { event: any }) => { if (state.sessionId === null || state.isSubAgent) { return } @@ -59,13 +53,7 @@ export function createEventHandler( } try { - await runOnIdle( - client, - state, - logger, - config, - workingDirectory - ) + await runOnIdle(client, state, logger, config, workingDirectory) } catch (err: any) { logger.error("OnIdle pruning failed", { error: err.message }) } diff --git a/lib/logger.ts b/lib/logger.ts index 0081db15..d101c673 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -29,15 +29,15 @@ export class Logger { // Format arrays compactly if (Array.isArray(value)) { if (value.length === 0) continue - parts.push(`${key}=[${value.slice(0, 3).join(",")}${value.length > 3 ? `...+${value.length - 3}` : ""}]`) - } - else if (typeof value === 'object') { + parts.push( + `${key}=[${value.slice(0, 3).join(",")}${value.length > 3 ? `...+${value.length - 3}` : ""}]`, + ) + } else if (typeof value === "object") { const str = JSON.stringify(value) if (str.length < 50) { parts.push(`${key}=${str}`) } - } - else { + } else { parts.push(`${key}=${value}`) } } @@ -55,15 +55,15 @@ export class Logger { // Skip specified number of frames to get to actual caller for (let i = skipFrames; i < stack.length; i++) { const filename = stack[i]?.getFileName() - if (filename && !filename.includes('/logger.')) { + if (filename && !filename.includes("/logger.")) { // Extract just the filename without path and extension const match = filename.match(/([^/\\]+)\.[tj]s$/) return match ? match[1] : filename } } - return 'unknown' + return "unknown" } catch { - return 'unknown' + return "unknown" } } @@ -83,10 +83,9 @@ export class Logger { await mkdir(dailyLogDir, { recursive: true }) } - const logFile = join(dailyLogDir, `${new Date().toISOString().split('T')[0]}.log`) + const logFile = join(dailyLogDir, `${new Date().toISOString().split("T")[0]}.log`) await writeFile(logFile, logLine, { flag: "a" }) - } catch (error) { - } + } catch (error) {} } info(message: string, data?: any) { diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index c59411c5..cc386c32 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -6,8 +6,9 @@ import { extractParameterKey, buildToolIdList } from "./utils" import { getLastUserMessage, isMessageCompacted } from "../shared-utils" import { UserMessage } from "@opencode-ai/sdk" -const PRUNED_TOOL_INPUT_REPLACEMENT = '[Input removed to save context]' -const PRUNED_TOOL_OUTPUT_REPLACEMENT = '[Output removed to save context - information superseded or no longer needed]' +const PRUNED_TOOL_INPUT_REPLACEMENT = "[Input removed to save context]" +const PRUNED_TOOL_OUTPUT_REPLACEMENT = + "[Output removed to save context - information superseded or no longer needed]" const getNudgeString = (config: PluginConfig): string => { const discardEnabled = config.tools.discard.enabled const extractEnabled = config.tools.extract.enabled @@ -67,27 +68,34 @@ const buildPrunableToolsList = ( } const numericId = toolIdList.indexOf(toolCallId) if (numericId === -1) { - logger.warn(`Tool in cache but not in toolIdList - possible stale entry`, { toolCallId, tool: toolParameterEntry.tool }) + logger.warn(`Tool in cache but not in toolIdList - possible stale entry`, { + toolCallId, + tool: toolParameterEntry.tool, + }) return } const paramKey = extractParameterKey(toolParameterEntry.tool, toolParameterEntry.parameters) - const description = paramKey ? `${toolParameterEntry.tool}, ${paramKey}` : toolParameterEntry.tool + const description = paramKey + ? `${toolParameterEntry.tool}, ${paramKey}` + : toolParameterEntry.tool lines.push(`${numericId}: ${description}`) - logger.debug(`Prunable tool found - ID: ${numericId}, Tool: ${toolParameterEntry.tool}, Call ID: ${toolCallId}`) + logger.debug( + `Prunable tool found - ID: ${numericId}, Tool: ${toolParameterEntry.tool}, Call ID: ${toolCallId}`, + ) }) if (lines.length === 0) { return "" } - return wrapPrunableTools(lines.join('\n')) + return wrapPrunableTools(lines.join("\n")) } export const insertPruneToolContext = ( state: SessionState, config: PluginConfig, logger: Logger, - messages: WithParts[] + messages: WithParts[], ): void => { if (!config.tools.discard.enabled && !config.tools.extract.enabled) { return @@ -112,7 +120,10 @@ export const insertPruneToolContext = ( logger.debug("prunable-tools: \n" + prunableToolsList) let nudgeString = "" - if (config.tools.settings.nudgeEnabled && state.nudgeCounter >= config.tools.settings.nudgeFrequency) { + if ( + config.tools.settings.nudgeEnabled && + state.nudgeCounter >= config.tools.settings.nudgeFrequency + ) { logger.info("Inserting prune nudge message") nudgeString = "\n" + getNudgeString(config) } @@ -129,8 +140,8 @@ export const insertPruneToolContext = ( agent: (lastUserMessage.info as UserMessage).agent || "build", model: { providerID: (lastUserMessage.info as UserMessage).model.providerID, - modelID: (lastUserMessage.info as UserMessage).model.modelID - } + modelID: (lastUserMessage.info as UserMessage).model.modelID, + }, }, parts: [ { @@ -139,8 +150,8 @@ export const insertPruneToolContext = ( messageID: SYNTHETIC_MESSAGE_ID, type: "text", text: prunableToolsContent, - } - ] + }, + ], } messages.push(userMessage) @@ -150,55 +161,47 @@ export const prune = ( state: SessionState, logger: Logger, config: PluginConfig, - messages: WithParts[] + messages: WithParts[], ): void => { pruneToolOutputs(state, logger, messages) pruneToolInputs(state, logger, messages) } -const pruneToolOutputs = ( - state: SessionState, - logger: Logger, - messages: WithParts[] -): void => { +const pruneToolOutputs = (state: SessionState, logger: Logger, messages: WithParts[]): void => { for (const msg of messages) { if (isMessageCompacted(state, msg)) { continue } for (const part of msg.parts) { - if (part.type !== 'tool') { + if (part.type !== "tool") { continue } if (!state.prune.toolIds.includes(part.callID)) { continue } // Skip write and edit tools - their inputs are pruned instead - if (part.tool === 'write' || part.tool === 'edit') { + if (part.tool === "write" || part.tool === "edit") { continue } - if (part.state.status === 'completed') { + if (part.state.status === "completed") { part.state.output = PRUNED_TOOL_OUTPUT_REPLACEMENT } } } } -const pruneToolInputs = ( - state: SessionState, - logger: Logger, - messages: WithParts[] -): void => { +const pruneToolInputs = (state: SessionState, logger: Logger, messages: WithParts[]): void => { for (const msg of messages) { for (const part of msg.parts) { - if (part.type !== 'tool') { + if (part.type !== "tool") { continue } if (!state.prune.toolIds.includes(part.callID)) { continue } // Only prune inputs for write and edit tools - if (part.tool !== 'write' && part.tool !== 'edit') { + if (part.tool !== "write" && part.tool !== "edit") { continue } // Don't prune yet if tool is still pending or running @@ -207,10 +210,10 @@ const pruneToolInputs = ( } // Write tool has content field, edit tool has oldString/newString fields - if (part.tool === 'write' && part.state.input?.content !== undefined) { + if (part.tool === "write" && part.state.input?.content !== undefined) { part.state.input.content = PRUNED_TOOL_INPUT_REPLACEMENT } - if (part.tool === 'edit') { + if (part.tool === "edit") { if (part.state.input?.oldString !== undefined) { part.state.input.oldString = PRUNED_TOOL_INPUT_REPLACEMENT } diff --git a/lib/messages/utils.ts b/lib/messages/utils.ts index 48f453c7..cbf497d4 100644 --- a/lib/messages/utils.ts +++ b/lib/messages/utils.ts @@ -6,7 +6,7 @@ import type { SessionState, WithParts } from "../state" * Extracts a human-readable key from tool metadata for display purposes. */ export const extractParameterKey = (tool: string, parameters: any): string => { - if (!parameters) return '' + if (!parameters) return "" if (tool === "read" && parameters.filePath) { return parameters.filePath @@ -19,21 +19,21 @@ export const extractParameterKey = (tool: string, parameters: any): string => { } if (tool === "list") { - return parameters.path || '(current directory)' + return parameters.path || "(current directory)" } if (tool === "glob") { if (parameters.pattern) { const pathInfo = parameters.path ? ` in ${parameters.path}` : "" return `"${parameters.pattern}"${pathInfo}` } - return '(unknown pattern)' + return "(unknown pattern)" } if (tool === "grep") { if (parameters.pattern) { const pathInfo = parameters.path ? ` in ${parameters.path}` : "" return `"${parameters.pattern}"${pathInfo}` } - return '(unknown pattern)' + return "(unknown pattern)" } if (tool === "bash") { @@ -67,8 +67,8 @@ export const extractParameterKey = (tool: string, parameters: any): string => { } const paramStr = JSON.stringify(parameters) - if (paramStr === '{}' || paramStr === '[]' || paramStr === 'null') { - return '' + if (paramStr === "{}" || paramStr === "[]" || paramStr === "null") { + return "" } return paramStr.substring(0, 50) } @@ -76,7 +76,7 @@ export const extractParameterKey = (tool: string, parameters: any): string => { export function buildToolIdList( state: SessionState, messages: WithParts[], - logger: Logger + logger: Logger, ): string[] { const toolIds: string[] = [] for (const msg of messages) { @@ -85,7 +85,7 @@ export function buildToolIdList( } if (msg.parts) { for (const part of msg.parts) { - if (part.type === 'tool' && part.callID && part.tool) { + if (part.type === "tool" && part.callID && part.tool) { toolIds.push(part.callID) } } diff --git a/lib/model-selector.ts b/lib/model-selector.ts index d1499eb7..efa8e87d 100644 --- a/lib/model-selector.ts +++ b/lib/model-selector.ts @@ -1,107 +1,112 @@ -import type { LanguageModel } from 'ai'; -import type { Logger } from './logger'; +import type { LanguageModel } from "ai" +import type { Logger } from "./logger" export interface ModelInfo { - providerID: string; - modelID: string; + providerID: string + modelID: string } export const FALLBACK_MODELS: Record = { - openai: 'gpt-5-mini', - anthropic: 'claude-haiku-4-5', //This model isn't broken in opencode-auth-provider - google: 'gemini-2.5-flash', - deepseek: 'deepseek-chat', - xai: 'grok-4-fast', - alibaba: 'qwen3-coder-flash', - zai: 'glm-4.5-flash', - opencode: 'big-pickle' -}; + openai: "gpt-5-mini", + anthropic: "claude-haiku-4-5", //This model isn't broken in opencode-auth-provider + google: "gemini-2.5-flash", + deepseek: "deepseek-chat", + xai: "grok-4-fast", + alibaba: "qwen3-coder-flash", + zai: "glm-4.5-flash", + opencode: "big-pickle", +} const PROVIDER_PRIORITY = [ - 'openai', - 'anthropic', - 'google', - 'deepseek', - 'xai', - 'alibaba', - 'zai', - 'opencode' -]; + "openai", + "anthropic", + "google", + "deepseek", + "xai", + "alibaba", + "zai", + "opencode", +] // TODO: some anthropic provided models aren't supported by the opencode-auth-provider package, so this provides a temporary workaround -const SKIP_PROVIDERS = ['github-copilot', 'anthropic']; +const SKIP_PROVIDERS = ["github-copilot", "anthropic"] export interface ModelSelectionResult { - model: LanguageModel; - modelInfo: ModelInfo; - source: 'user-model' | 'config' | 'fallback'; - reason?: string; - failedModel?: ModelInfo; + model: LanguageModel + modelInfo: ModelInfo + source: "user-model" | "config" | "fallback" + reason?: string + failedModel?: ModelInfo } function shouldSkipProvider(providerID: string): boolean { - const normalized = providerID.toLowerCase().trim(); - return SKIP_PROVIDERS.some(skip => normalized.includes(skip.toLowerCase())); + const normalized = providerID.toLowerCase().trim() + return SKIP_PROVIDERS.some((skip) => normalized.includes(skip.toLowerCase())) } -async function importOpencodeAI(logger?: Logger, maxRetries: number = 3, delayMs: number = 100, workspaceDir?: string): Promise { - let lastError: Error | undefined; +async function importOpencodeAI( + logger?: Logger, + maxRetries: number = 3, + delayMs: number = 100, + workspaceDir?: string, +): Promise { + let lastError: Error | undefined for (let attempt = 1; attempt <= maxRetries; attempt++) { try { - const { OpencodeAI } = await import('@tarquinen/opencode-auth-provider'); - return new OpencodeAI({ workspaceDir }); + const { OpencodeAI } = await import("@tarquinen/opencode-auth-provider") + return new OpencodeAI({ workspaceDir }) } catch (error: any) { - lastError = error; + lastError = error - if (error.message?.includes('before initialization')) { + if (error.message?.includes("before initialization")) { logger?.debug(`Import attempt ${attempt}/${maxRetries} failed, will retry`, { - error: error.message - }); + error: error.message, + }) if (attempt < maxRetries) { - await new Promise(resolve => setTimeout(resolve, delayMs * attempt)); - continue; + await new Promise((resolve) => setTimeout(resolve, delayMs * attempt)) + continue } } - throw error; + throw error } } - throw lastError; + throw lastError } export async function selectModel( currentModel?: ModelInfo, logger?: Logger, configModel?: string, - workspaceDir?: string + workspaceDir?: string, ): Promise { - const opencodeAI = await importOpencodeAI(logger, 3, 100, workspaceDir); + const opencodeAI = await importOpencodeAI(logger, 3, 100, workspaceDir) - let failedModelInfo: ModelInfo | undefined; + let failedModelInfo: ModelInfo | undefined if (configModel) { - const parts = configModel.split('/'); + const parts = configModel.split("/") if (parts.length !== 2) { - logger?.warn('Invalid config model format', { configModel }); + logger?.warn("Invalid config model format", { configModel }) } else { - const [providerID, modelID] = parts; + const [providerID, modelID] = parts try { - const model = await opencodeAI.getLanguageModel(providerID, modelID); + const model = await opencodeAI.getLanguageModel(providerID, modelID) return { model, modelInfo: { providerID, modelID }, - source: 'config', - reason: 'Using model specified in dcp.jsonc config' - }; + source: "config", + reason: "Using model specified in dcp.jsonc config", + } } catch (error: any) { logger?.warn(`Config model failed: ${providerID}/${modelID}`, { - error: error.message - }); - failedModelInfo = { providerID, modelID }; + error: error.message, + }) + failedModelInfo = { providerID, modelID } } } } @@ -109,67 +114,72 @@ export async function selectModel( if (currentModel) { if (shouldSkipProvider(currentModel.providerID)) { if (!failedModelInfo) { - failedModelInfo = currentModel; + failedModelInfo = currentModel } } else { try { - const model = await opencodeAI.getLanguageModel(currentModel.providerID, currentModel.modelID); + const model = await opencodeAI.getLanguageModel( + currentModel.providerID, + currentModel.modelID, + ) return { model, modelInfo: currentModel, - source: 'user-model', - reason: 'Using current session model' - }; + source: "user-model", + reason: "Using current session model", + } } catch (error: any) { if (!failedModelInfo) { - failedModelInfo = currentModel; + failedModelInfo = currentModel } } } } - const providers = await opencodeAI.listProviders(); + const providers = await opencodeAI.listProviders() for (const providerID of PROVIDER_PRIORITY) { - if (!providers[providerID]) continue; + if (!providers[providerID]) continue - const fallbackModelID = FALLBACK_MODELS[providerID]; - if (!fallbackModelID) continue; + const fallbackModelID = FALLBACK_MODELS[providerID] + if (!fallbackModelID) continue try { - const model = await opencodeAI.getLanguageModel(providerID, fallbackModelID); + const model = await opencodeAI.getLanguageModel(providerID, fallbackModelID) return { model, modelInfo: { providerID, modelID: fallbackModelID }, - source: 'fallback', + source: "fallback", reason: `Using ${providerID}/${fallbackModelID}`, - failedModel: failedModelInfo - }; + failedModel: failedModelInfo, + } } catch (error: any) { - continue; + continue } } - throw new Error('No available models for analysis. Please authenticate with at least one provider.'); + throw new Error( + "No available models for analysis. Please authenticate with at least one provider.", + ) } export function extractModelFromSession(sessionState: any, logger?: Logger): ModelInfo | undefined { if (sessionState?.model?.providerID && sessionState?.model?.modelID) { return { providerID: sessionState.model.providerID, - modelID: sessionState.model.modelID - }; + modelID: sessionState.model.modelID, + } } if (sessionState?.messages && Array.isArray(sessionState.messages)) { - const lastMessage = sessionState.messages[sessionState.messages.length - 1]; + const lastMessage = sessionState.messages[sessionState.messages.length - 1] if (lastMessage?.model?.providerID && lastMessage?.model?.modelID) { return { providerID: lastMessage.model.providerID, - modelID: lastMessage.model.modelID - }; + modelID: lastMessage.model.modelID, + } } } - return undefined; + return undefined } diff --git a/lib/prompt.ts b/lib/prompt.ts index 33a490fb..0f2bad39 100644 --- a/lib/prompt.ts +++ b/lib/prompt.ts @@ -6,129 +6,144 @@ export function loadPrompt(name: string, vars?: Record): string let content = readFileSync(filePath, "utf8").trim() if (vars) { for (const [key, value] of Object.entries(vars)) { - content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, 'g'), value) + content = content.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value) } } return content } -function minimizeMessages(messages: any[], alreadyPrunedIds?: string[], protectedToolCallIds?: string[]): any[] { - const prunedIdsSet = alreadyPrunedIds ? new Set(alreadyPrunedIds.map(id => id.toLowerCase())) : new Set() - const protectedIdsSet = protectedToolCallIds ? new Set(protectedToolCallIds.map(id => id.toLowerCase())) : new Set() - - return messages.map(msg => { - const minimized: any = { - role: msg.info?.role - } - - if (msg.parts) { - minimized.parts = msg.parts - .filter((part: any) => { - if (part.type === 'step-start' || part.type === 'step-finish') { - return false - } - return true - }) - .map((part: any) => { - if (part.type === 'text') { - if (part.ignored) { - return null - } - return { - type: 'text', - text: part.text +function minimizeMessages( + messages: any[], + alreadyPrunedIds?: string[], + protectedToolCallIds?: string[], +): any[] { + const prunedIdsSet = alreadyPrunedIds + ? new Set(alreadyPrunedIds.map((id) => id.toLowerCase())) + : new Set() + const protectedIdsSet = protectedToolCallIds + ? new Set(protectedToolCallIds.map((id) => id.toLowerCase())) + : new Set() + + return messages + .map((msg) => { + const minimized: any = { + role: msg.info?.role, + } + + if (msg.parts) { + minimized.parts = msg.parts + .filter((part: any) => { + if (part.type === "step-start" || part.type === "step-finish") { + return false } - } - - // TODO: This should use the opencode normalized system instead of per provider settings - if (part.type === 'reasoning') { - // Calculate encrypted content size if present - let encryptedContentLength = 0 - if (part.metadata?.openai?.reasoningEncryptedContent) { - encryptedContentLength = part.metadata.openai.reasoningEncryptedContent.length - } else if (part.metadata?.anthropic?.signature) { - encryptedContentLength = part.metadata.anthropic.signature.length - } else if (part.metadata?.google?.thoughtSignature) { - encryptedContentLength = part.metadata.google.thoughtSignature.length + return true + }) + .map((part: any) => { + if (part.type === "text") { + if (part.ignored) { + return null + } + return { + type: "text", + text: part.text, + } } - return { - type: 'reasoning', - text: part.text, - textLength: part.text?.length || 0, - encryptedContentLength, - ...(part.time && { time: part.time }), - ...(part.metadata && { metadataKeys: Object.keys(part.metadata) }) - } - } - - if (part.type === 'tool') { - const callIDLower = part.callID?.toLowerCase() - const isAlreadyPruned = prunedIdsSet.has(callIDLower) - const isProtected = protectedIdsSet.has(callIDLower) - - let displayCallID = part.callID - if (isAlreadyPruned) { - displayCallID = '' - } else if (isProtected) { - displayCallID = '' - } + // TODO: This should use the opencode normalized system instead of per provider settings + if (part.type === "reasoning") { + // Calculate encrypted content size if present + let encryptedContentLength = 0 + if (part.metadata?.openai?.reasoningEncryptedContent) { + encryptedContentLength = + part.metadata.openai.reasoningEncryptedContent.length + } else if (part.metadata?.anthropic?.signature) { + encryptedContentLength = part.metadata.anthropic.signature.length + } else if (part.metadata?.google?.thoughtSignature) { + encryptedContentLength = + part.metadata.google.thoughtSignature.length + } - const toolPart: any = { - type: 'tool', - toolCallID: displayCallID, - tool: part.tool + return { + type: "reasoning", + text: part.text, + textLength: part.text?.length || 0, + encryptedContentLength, + ...(part.time && { time: part.time }), + ...(part.metadata && { metadataKeys: Object.keys(part.metadata) }), + } } - if (part.state?.output) { - toolPart.output = part.state.output - } + if (part.type === "tool") { + const callIDLower = part.callID?.toLowerCase() + const isAlreadyPruned = prunedIdsSet.has(callIDLower) + const isProtected = protectedIdsSet.has(callIDLower) - if (part.state?.input) { - const input = part.state.input + let displayCallID = part.callID + if (isAlreadyPruned) { + displayCallID = "" + } else if (isProtected) { + displayCallID = "" + } - if (input.filePath && (part.tool === 'write' || part.tool === 'edit' || part.tool === 'multiedit' || part.tool === 'patch')) { - toolPart.input = input + const toolPart: any = { + type: "tool", + toolCallID: displayCallID, + tool: part.tool, } - else if (input.filePath) { - toolPart.input = { filePath: input.filePath } + + if (part.state?.output) { + toolPart.output = part.state.output } - else if (input.tool_calls && Array.isArray(input.tool_calls)) { - toolPart.input = { - batch_summary: `${input.tool_calls.length} tool calls`, - tools: input.tool_calls.map((tc: any) => tc.tool) + + if (part.state?.input) { + const input = part.state.input + + if ( + input.filePath && + (part.tool === "write" || + part.tool === "edit" || + part.tool === "multiedit" || + part.tool === "patch") + ) { + toolPart.input = input + } else if (input.filePath) { + toolPart.input = { filePath: input.filePath } + } else if (input.tool_calls && Array.isArray(input.tool_calls)) { + toolPart.input = { + batch_summary: `${input.tool_calls.length} tool calls`, + tools: input.tool_calls.map((tc: any) => tc.tool), + } + } else { + toolPart.input = input } } - else { - toolPart.input = input - } + + return toolPart } - return toolPart - } + return null + }) + .filter(Boolean) + } - return null - }) - .filter(Boolean) - } - - return minimized - }).filter(msg => { - return msg.parts && msg.parts.length > 0 - }) + return minimized + }) + .filter((msg) => { + return msg.parts && msg.parts.length > 0 + }) } export function buildAnalysisPrompt( unprunedToolCallIds: string[], messages: any[], alreadyPrunedIds?: string[], - protectedToolCallIds?: string[] + protectedToolCallIds?: string[], ): string { const minimizedMessages = minimizeMessages(messages, alreadyPrunedIds, protectedToolCallIds) - const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, '\n') + const messagesJson = JSON.stringify(minimizedMessages, null, 2).replace(/\\n/g, "\n") return loadPrompt("on-idle-analysis", { available_tool_call_ids: unprunedToolCallIds.join(", "), - session_history: messagesJson + session_history: messagesJson, }) } diff --git a/lib/shared-utils.ts b/lib/shared-utils.ts index fe6fbd60..ce3be56a 100644 --- a/lib/shared-utils.ts +++ b/lib/shared-utils.ts @@ -1,22 +1,15 @@ import { SessionState, WithParts } from "./state" -export const isMessageCompacted = ( - state: SessionState, - msg: WithParts -): boolean => { +export const isMessageCompacted = (state: SessionState, msg: WithParts): boolean => { return msg.info.time.created < state.lastCompaction } -export const getLastUserMessage = ( - messages: WithParts[] -): WithParts | null => { +export const getLastUserMessage = (messages: WithParts[]): WithParts | null => { for (let i = messages.length - 1; i >= 0; i--) { const msg = messages[i] - if (msg.info.role === 'user') { + if (msg.info.role === "user") { return msg } } return null } - - diff --git a/lib/state/persistence.ts b/lib/state/persistence.ts index eb975511..ccd48594 100644 --- a/lib/state/persistence.ts +++ b/lib/state/persistence.ts @@ -4,110 +4,98 @@ * Storage location: ~/.local/share/opencode/storage/plugin/dcp/{sessionId}.json */ -import * as fs from "fs/promises"; -import { existsSync } from "fs"; -import { homedir } from "os"; -import { join } from "path"; +import * as fs from "fs/promises" +import { existsSync } from "fs" +import { homedir } from "os" +import { join } from "path" import type { SessionState, SessionStats, Prune } from "./types" -import type { Logger } from "../logger"; +import type { Logger } from "../logger" export interface PersistedSessionState { - sessionName?: string; + sessionName?: string prune: Prune - stats: SessionStats; - lastUpdated: string; + stats: SessionStats + lastUpdated: string } -const STORAGE_DIR = join( - homedir(), - ".local", - "share", - "opencode", - "storage", - "plugin", - "dcp" -); +const STORAGE_DIR = join(homedir(), ".local", "share", "opencode", "storage", "plugin", "dcp") async function ensureStorageDir(): Promise { if (!existsSync(STORAGE_DIR)) { - await fs.mkdir(STORAGE_DIR, { recursive: true }); + await fs.mkdir(STORAGE_DIR, { recursive: true }) } } function getSessionFilePath(sessionId: string): string { - return join(STORAGE_DIR, `${sessionId}.json`); + return join(STORAGE_DIR, `${sessionId}.json`) } export async function saveSessionState( sessionState: SessionState, logger: Logger, - sessionName?: string + sessionName?: string, ): Promise { try { if (!sessionState.sessionId) { - return; + return } - await ensureStorageDir(); + await ensureStorageDir() const state: PersistedSessionState = { sessionName: sessionName, prune: sessionState.prune, stats: sessionState.stats, - lastUpdated: new Date().toISOString() - }; + lastUpdated: new Date().toISOString(), + } - const filePath = getSessionFilePath(sessionState.sessionId); - const content = JSON.stringify(state, null, 2); - await fs.writeFile(filePath, content, "utf-8"); + const filePath = getSessionFilePath(sessionState.sessionId) + const content = JSON.stringify(state, null, 2) + await fs.writeFile(filePath, content, "utf-8") logger.info("Saved session state to disk", { sessionId: sessionState.sessionId, - totalTokensSaved: state.stats.totalPruneTokens - }); + totalTokensSaved: state.stats.totalPruneTokens, + }) } catch (error: any) { logger.error("Failed to save session state", { sessionId: sessionState.sessionId, error: error?.message, - }); + }) } } export async function loadSessionState( sessionId: string, - logger: Logger + logger: Logger, ): Promise { try { - const filePath = getSessionFilePath(sessionId); + const filePath = getSessionFilePath(sessionId) if (!existsSync(filePath)) { - return null; + return null } - const content = await fs.readFile(filePath, "utf-8"); - const state = JSON.parse(content) as PersistedSessionState; + const content = await fs.readFile(filePath, "utf-8") + const state = JSON.parse(content) as PersistedSessionState - if (!state || - !state.prune || - !Array.isArray(state.prune.toolIds) || - !state.stats - ) { + if (!state || !state.prune || !Array.isArray(state.prune.toolIds) || !state.stats) { logger.warn("Invalid session state file, ignoring", { sessionId: sessionId, - }); - return null; + }) + return null } logger.info("Loaded session state from disk", { - sessionId: sessionId - }); + sessionId: sessionId, + }) - return state; + return state } catch (error: any) { logger.warn("Failed to load session state", { sessionId: sessionId, error: error?.message, - }); - return null; + }) + return null } } diff --git a/lib/state/state.ts b/lib/state/state.ts index e33f4c8d..956ac9dd 100644 --- a/lib/state/state.ts +++ b/lib/state/state.ts @@ -8,9 +8,8 @@ export const checkSession = async ( client: any, state: SessionState, logger: Logger, - messages: WithParts[] + messages: WithParts[], ): Promise => { - const lastUserMessage = getLastUserMessage(messages) if (!lastUserMessage) { return @@ -32,7 +31,9 @@ export const checkSession = async ( state.lastCompaction = lastCompactionTimestamp state.toolParameters.clear() state.prune.toolIds = [] - logger.info("Detected compaction from messages - cleared tool cache", { timestamp: lastCompactionTimestamp }) + logger.info("Detected compaction from messages - cleared tool cache", { + timestamp: lastCompactionTimestamp, + }) } state.currentTurn = countTurns(state, messages) @@ -43,7 +44,7 @@ export function createSessionState(): SessionState { sessionId: null, isSubAgent: false, prune: { - toolIds: [] + toolIds: [], }, stats: { pruneTokenCounter: 0, @@ -53,7 +54,7 @@ export function createSessionState(): SessionState { nudgeCounter: 0, lastToolPrune: false, lastCompaction: 0, - currentTurn: 0 + currentTurn: 0, } } @@ -61,7 +62,7 @@ export function resetSessionState(state: SessionState): void { state.sessionId = null state.isSubAgent = false state.prune = { - toolIds: [] + toolIds: [], } state.stats = { pruneTokenCounter: 0, @@ -79,10 +80,10 @@ export async function ensureSessionInitialized( state: SessionState, sessionId: string, logger: Logger, - messages: WithParts[] + messages: WithParts[], ): Promise { if (state.sessionId === sessionId) { - return; + return } logger.info("session ID = " + sessionId) @@ -100,11 +101,11 @@ export async function ensureSessionInitialized( const persisted = await loadSessionState(sessionId, logger) if (persisted === null) { - return; + return } state.prune = { - toolIds: persisted.prune.toolIds || [] + toolIds: persisted.prune.toolIds || [], } state.stats = { pruneTokenCounter: persisted.stats?.pruneTokenCounter || 0, diff --git a/lib/state/tool-cache.ts b/lib/state/tool-cache.ts index bc94efef..f9d3d3cb 100644 --- a/lib/state/tool-cache.ts +++ b/lib/state/tool-cache.ts @@ -37,9 +37,10 @@ export async function syncToolCache( const turnProtectionEnabled = config.turnProtection.enabled const turnProtectionTurns = config.turnProtection.turns - const isProtectedByTurn = turnProtectionEnabled && + const isProtectedByTurn = + turnProtectionEnabled && turnProtectionTurns > 0 && - (state.currentTurn - turnCounter) < turnProtectionTurns + state.currentTurn - turnCounter < turnProtectionTurns state.lastToolPrune = part.tool === "discard" || part.tool === "extract" @@ -47,10 +48,7 @@ export async function syncToolCache( if (part.tool === "discard" || part.tool === "extract") { state.nudgeCounter = 0 - } else if ( - !allProtectedTools.includes(part.tool) && - !isProtectedByTurn - ) { + } else if (!allProtectedTools.includes(part.tool) && !isProtectedByTurn) { state.nudgeCounter++ } @@ -62,25 +60,24 @@ export async function syncToolCache( continue } - state.toolParameters.set( - part.callID, - { - tool: part.tool, - parameters: part.state?.input ?? {}, - status: part.state.status as ToolStatus | undefined, - error: part.state.status === "error" ? part.state.error : undefined, - turn: turnCounter, - } - ) + state.toolParameters.set(part.callID, { + tool: part.tool, + parameters: part.state?.input ?? {}, + status: part.state.status as ToolStatus | undefined, + error: part.state.status === "error" ? part.state.error : undefined, + turn: turnCounter, + }) logger.info(`Cached tool id: ${part.callID} (created on turn ${turnCounter})`) } } - logger.info(`Synced cache - size: ${state.toolParameters.size}, currentTurn: ${state.currentTurn}, nudgeCounter: ${state.nudgeCounter}`) + logger.info( + `Synced cache - size: ${state.toolParameters.size}, currentTurn: ${state.currentTurn}, nudgeCounter: ${state.nudgeCounter}`, + ) trimToolParametersCache(state) } catch (error) { logger.warn("Failed to sync tool parameters from OpenCode", { - error: error instanceof Error ? error.message : String(error) + error: error instanceof Error ? error.message : String(error), }) } } @@ -94,8 +91,10 @@ export function trimToolParametersCache(state: SessionState): void { return } - const keysToRemove = Array.from(state.toolParameters.keys()) - .slice(0, state.toolParameters.size - MAX_TOOL_CACHE_SIZE) + const keysToRemove = Array.from(state.toolParameters.keys()).slice( + 0, + state.toolParameters.size - MAX_TOOL_CACHE_SIZE, + ) for (const key of keysToRemove) { state.toolParameters.delete(key) diff --git a/lib/state/types.ts b/lib/state/types.ts index 04847d58..9a6de02d 100644 --- a/lib/state/types.ts +++ b/lib/state/types.ts @@ -12,7 +12,7 @@ export interface ToolParameterEntry { parameters: any status?: ToolStatus error?: string - turn: number // Which turn (step-start count) this tool was called on + turn: number // Which turn (step-start count) this tool was called on } export interface SessionStats { @@ -33,5 +33,5 @@ export interface SessionState { nudgeCounter: number lastToolPrune: boolean lastCompaction: number - currentTurn: number // Current turn count derived from step-start parts + currentTurn: number // Current turn count derived from step-start parts } diff --git a/lib/strategies/deduplication.ts b/lib/strategies/deduplication.ts index 11462a88..101e664c 100644 --- a/lib/strategies/deduplication.ts +++ b/lib/strategies/deduplication.ts @@ -13,7 +13,7 @@ export const deduplicate = ( state: SessionState, logger: Logger, config: PluginConfig, - messages: WithParts[] + messages: WithParts[], ): void => { if (!config.strategies.deduplication.enabled) { return @@ -27,7 +27,7 @@ export const deduplicate = ( // Filter out IDs already pruned const alreadyPruned = new Set(state.prune.toolIds) - const unprunedIds = allToolIds.filter(id => !alreadyPruned.has(id)) + const unprunedIds = allToolIds.filter((id) => !alreadyPruned.has(id)) if (unprunedIds.length === 0) { return @@ -86,7 +86,7 @@ function createToolSignature(tool: string, parameters?: any): string { } function normalizeParameters(params: any): any { - if (typeof params !== 'object' || params === null) return params + if (typeof params !== "object" || params === null) return params if (Array.isArray(params)) return params const normalized: any = {} @@ -99,7 +99,7 @@ function normalizeParameters(params: any): any { } function sortObjectKeys(obj: any): any { - if (typeof obj !== 'object' || obj === null) return obj + if (typeof obj !== "object" || obj === null) return obj if (Array.isArray(obj)) return obj.map(sortObjectKeys) const sorted: any = {} diff --git a/lib/strategies/on-idle.ts b/lib/strategies/on-idle.ts index 602298e3..43f481cb 100644 --- a/lib/strategies/on-idle.ts +++ b/lib/strategies/on-idle.ts @@ -21,7 +21,7 @@ export interface OnIdleResult { function parseMessages( state: SessionState, messages: WithParts[], - toolParametersCache: Map + toolParametersCache: Map, ): { toolCallIds: string[] toolMetadata: Map @@ -46,7 +46,7 @@ function parseMessages( parameters: parameters, status: part.state?.status, error: part.state?.status === "error" ? part.state.error : undefined, - turn: cachedData?.turn ?? 0 + turn: cachedData?.turn ?? 0, }) } } @@ -64,26 +64,28 @@ function replacePrunedToolOutputs(messages: WithParts[], prunedIds: string[]): W const prunedIdsSet = new Set(prunedIds) - return messages.map(msg => { + return messages.map((msg) => { if (!msg.parts) return msg return { ...msg, parts: msg.parts.map((part: any) => { - if (part.type === 'tool' && + if ( + part.type === "tool" && part.callID && prunedIdsSet.has(part.callID) && - part.state?.output) { + part.state?.output + ) { return { ...part, state: { ...part.state, - output: '[Output removed to save context - information superseded or no longer needed]' - } + output: "[Output removed to save context - information superseded or no longer needed]", + }, } } return part - }) + }), } }) as WithParts[] } @@ -100,10 +102,10 @@ async function runLlmAnalysis( unprunedToolCallIds: string[], alreadyPrunedIds: string[], toolMetadata: Map, - workingDirectory?: string + workingDirectory?: string, ): Promise { const protectedToolCallIds: string[] = [] - const prunableToolCallIds = unprunedToolCallIds.filter(id => { + const prunableToolCallIds = unprunedToolCallIds.filter((id) => { const metadata = toolMetadata.get(id) if (metadata && config.strategies.onIdle.protectedTools.includes(metadata.tool)) { protectedToolCallIds.push(id) @@ -124,7 +126,7 @@ async function runLlmAnalysis( if (model?.providerID && model?.modelID) { validModelInfo = { providerID: model.providerID, - modelID: model.modelID + modelID: model.modelID, } } } @@ -133,15 +135,19 @@ async function runLlmAnalysis( validModelInfo, logger, config.strategies.onIdle.model, - workingDirectory + workingDirectory, ) - logger.info(`OnIdle Model: ${modelSelection.modelInfo.providerID}/${modelSelection.modelInfo.modelID}`, { - source: modelSelection.source - }) + logger.info( + `OnIdle Model: ${modelSelection.modelInfo.providerID}/${modelSelection.modelInfo.modelID}`, + { + source: modelSelection.source, + }, + ) if (modelSelection.failedModel && config.strategies.onIdle.showModelErrorToasts) { - const skipAi = modelSelection.source === 'fallback' && config.strategies.onIdle.strictModelSelection + const skipAi = + modelSelection.source === "fallback" && config.strategies.onIdle.strictModelSelection try { await client.tui.showToast({ body: { @@ -150,20 +156,20 @@ async function runLlmAnalysis( ? `${modelSelection.failedModel.providerID}/${modelSelection.failedModel.modelID} failed\nAI analysis skipped (strictModelSelection enabled)` : `${modelSelection.failedModel.providerID}/${modelSelection.failedModel.modelID} failed\nUsing ${modelSelection.modelInfo.providerID}/${modelSelection.modelInfo.modelID}`, variant: "info", - duration: 5000 - } + duration: 5000, + }, }) } catch { // Ignore toast errors } } - if (modelSelection.source === 'fallback' && config.strategies.onIdle.strictModelSelection) { + if (modelSelection.source === "fallback" && config.strategies.onIdle.strictModelSelection) { logger.info("Skipping AI analysis (fallback model, strictModelSelection enabled)") return [] } - const { generateObject } = await import('ai') + const { generateObject } = await import("ai") const sanitizedMessages = replacePrunedToolOutputs(messages, alreadyPrunedIds) @@ -171,7 +177,7 @@ async function runLlmAnalysis( prunableToolCallIds, sanitizedMessages, alreadyPrunedIds, - protectedToolCallIds + protectedToolCallIds, ) const result = await generateObject({ @@ -180,19 +186,17 @@ async function runLlmAnalysis( pruned_tool_call_ids: z.array(z.string()), reasoning: z.string(), }), - prompt: analysisPrompt + prompt: analysisPrompt, }) const rawLlmPrunedIds = result.object.pruned_tool_call_ids - const llmPrunedIds = rawLlmPrunedIds.filter(id => - prunableToolCallIds.includes(id) - ) + const llmPrunedIds = rawLlmPrunedIds.filter((id) => prunableToolCallIds.includes(id)) // Always log LLM output as debug - const reasoning = result.object.reasoning.replace(/\n+/g, ' ').replace(/\s+/g, ' ').trim() + const reasoning = result.object.reasoning.replace(/\n+/g, " ").replace(/\s+/g, " ").trim() logger.debug(`OnIdle LLM output`, { pruned_tool_call_ids: rawLlmPrunedIds, - reasoning: reasoning + reasoning: reasoning, }) return llmPrunedIds @@ -207,7 +211,7 @@ export async function runOnIdle( state: SessionState, logger: Logger, config: PluginConfig, - workingDirectory?: string + workingDirectory?: string, ): Promise { try { if (!state.sessionId) { @@ -219,7 +223,7 @@ export async function runOnIdle( // Fetch session info and messages const [sessionInfoResponse, messagesResponse] = await Promise.all([ client.session.get({ path: { id: sessionId } }), - client.session.messages({ path: { id: sessionId }}) + client.session.messages({ path: { id: sessionId } }), ]) const sessionInfo = sessionInfoResponse.data @@ -233,14 +237,14 @@ export async function runOnIdle( const { toolCallIds, toolMetadata } = parseMessages(state, messages, state.toolParameters) const alreadyPrunedIds = state.prune.toolIds - const unprunedToolCallIds = toolCallIds.filter(id => !alreadyPrunedIds.includes(id)) + const unprunedToolCallIds = toolCallIds.filter((id) => !alreadyPrunedIds.includes(id)) if (unprunedToolCallIds.length === 0) { return null } // Count prunable tools (excluding protected) - const candidateCount = unprunedToolCallIds.filter(id => { + const candidateCount = unprunedToolCallIds.filter((id) => { const metadata = toolMetadata.get(id) return !metadata || !config.strategies.onIdle.protectedTools.includes(metadata.tool) }).length @@ -259,10 +263,10 @@ export async function runOnIdle( unprunedToolCallIds, alreadyPrunedIds, toolMetadata, - workingDirectory + workingDirectory, ) - const newlyPrunedIds = llmPrunedIds.filter(id => !alreadyPrunedIds.includes(id)) + const newlyPrunedIds = llmPrunedIds.filter((id) => !alreadyPrunedIds.includes(id)) if (newlyPrunedIds.length === 0) { return null @@ -271,7 +275,7 @@ export async function runOnIdle( // Log the tool IDs being pruned with their tool names for (const id of newlyPrunedIds) { const metadata = toolMetadata.get(id) - const toolName = metadata?.tool || 'unknown' + const toolName = metadata?.tool || "unknown" logger.info(`OnIdle pruning tool: ${toolName}`, { callID: id }) } @@ -301,7 +305,7 @@ export async function runOnIdle( prunedToolMetadata, undefined, // reason currentParams, - workingDirectory || "" + workingDirectory || "", ) state.stats.totalPruneTokens += state.stats.pruneTokenCounter @@ -311,7 +315,7 @@ export async function runOnIdle( // Persist state const sessionName = sessionInfo?.title - saveSessionState(state, logger, sessionName).catch(err => { + saveSessionState(state, logger, sessionName).catch((err) => { logger.error("Failed to persist state", { error: err.message }) }) diff --git a/lib/strategies/supersede-writes.ts b/lib/strategies/supersede-writes.ts index b8bb8473..327cb586 100644 --- a/lib/strategies/supersede-writes.ts +++ b/lib/strategies/supersede-writes.ts @@ -16,7 +16,7 @@ export const supersedeWrites = ( state: SessionState, logger: Logger, config: PluginConfig, - messages: WithParts[] + messages: WithParts[], ): void => { if (!config.strategies.supersedeWrites.enabled) { return @@ -31,14 +31,14 @@ export const supersedeWrites = ( // Filter out IDs already pruned const alreadyPruned = new Set(state.prune.toolIds) - const unprunedIds = allToolIds.filter(id => !alreadyPruned.has(id)) + const unprunedIds = allToolIds.filter((id) => !alreadyPruned.has(id)) if (unprunedIds.length === 0) { return } // Track write tools by file path: filePath -> [{ id, index }] // We track index to determine chronological order - const writesByFile = new Map() + const writesByFile = new Map() // Track read file paths with their index const readsByFile = new Map() @@ -55,12 +55,12 @@ export const supersedeWrites = ( continue } - if (metadata.tool === 'write') { + if (metadata.tool === "write") { if (!writesByFile.has(filePath)) { writesByFile.set(filePath, []) } writesByFile.get(filePath)!.push({ id, index: i }) - } else if (metadata.tool === 'read') { + } else if (metadata.tool === "read") { if (!readsByFile.has(filePath)) { readsByFile.set(filePath, []) } @@ -85,7 +85,7 @@ export const supersedeWrites = ( } // Check if any read comes after this write - const hasSubsequentRead = reads.some(readIndex => readIndex > write.index) + const hasSubsequentRead = reads.some((readIndex) => readIndex > write.index) if (hasSubsequentRead) { newPruneIds.push(write.id) } diff --git a/lib/strategies/tools.ts b/lib/strategies/tools.ts index 31502f8a..6e4cbb12 100644 --- a/lib/strategies/tools.ts +++ b/lib/strategies/tools.ts @@ -2,7 +2,11 @@ import { tool } from "@opencode-ai/plugin" import type { SessionState, ToolParameterEntry, WithParts } from "../state" import type { PluginConfig } from "../config" import { buildToolIdList } from "../messages/utils" -import { PruneReason, sendUnifiedNotification, sendDistillationNotification } from "../ui/notification" +import { + PruneReason, + sendUnifiedNotification, + sendDistillationNotification, +} from "../ui/notification" import { formatPruningResultForTool } from "../ui/utils" import { ensureSessionInitialized } from "../state" import { saveSessionState } from "../state/persistence" @@ -28,7 +32,7 @@ async function executePruneOperation( ids: string[], reason: PruneReason, toolName: string, - distillation?: Record + distillation?: Record, ): Promise { const { client, state, logger, config, workingDirectory } = ctx const sessionId = toolCtx.sessionID @@ -42,7 +46,7 @@ async function executePruneOperation( } const numericToolIds: number[] = ids - .map(id => parseInt(id, 10)) + .map((id) => parseInt(id, 10)) .filter((n): n is number => !isNaN(n)) if (numericToolIds.length === 0) { @@ -52,7 +56,7 @@ async function executePruneOperation( // Fetch messages to calculate tokens and find current agent const messagesResponse = await client.session.messages({ - path: { id: sessionId } + path: { id: sessionId }, }) const messages: WithParts[] = messagesResponse.data || messagesResponse @@ -62,7 +66,7 @@ async function executePruneOperation( const toolIdList: string[] = buildToolIdList(state, messages, logger) // Validate that all numeric IDs are within bounds - if (numericToolIds.some(id => id < 0 || id >= toolIdList.length)) { + if (numericToolIds.some((id) => id < 0 || id >= toolIdList.length)) { logger.debug("Invalid tool IDs provided: " + numericToolIds.join(", ")) return "Invalid IDs provided. Only use numeric IDs from the list." } @@ -73,17 +77,24 @@ async function executePruneOperation( const id = toolIdList[index] const metadata = state.toolParameters.get(id) if (!metadata) { - logger.debug("Rejecting prune request - ID not in cache (turn-protected or hallucinated)", { index, id }) + logger.debug( + "Rejecting prune request - ID not in cache (turn-protected or hallucinated)", + { index, id }, + ) return "Invalid IDs provided. Only use numeric IDs from the list." } const allProtectedTools = config.tools.settings.protectedTools if (allProtectedTools.includes(metadata.tool)) { - logger.debug("Rejecting prune request - protected tool", { index, id, tool: metadata.tool }) + logger.debug("Rejecting prune request - protected tool", { + index, + id, + tool: metadata.tool, + }) return "Invalid IDs provided. Only use numeric IDs from the list." } } - const pruneToolIds: string[] = numericToolIds.map(index => toolIdList[index]) + const pruneToolIds: string[] = numericToolIds.map((index) => toolIdList[index]) state.prune.toolIds.push(...pruneToolIds) const toolMetadata = new Map() @@ -108,44 +119,33 @@ async function executePruneOperation( toolMetadata, reason, currentParams, - workingDirectory + workingDirectory, ) if (distillation && config.tools.extract.showDistillation) { - await sendDistillationNotification( - client, - logger, - sessionId, - distillation, - currentParams - ) + await sendDistillationNotification(client, logger, sessionId, distillation, currentParams) } state.stats.totalPruneTokens += state.stats.pruneTokenCounter state.stats.pruneTokenCounter = 0 state.nudgeCounter = 0 - saveSessionState(state, logger) - .catch(err => logger.error("Failed to persist state", { error: err.message })) - - return formatPruningResultForTool( - pruneToolIds, - toolMetadata, - workingDirectory + saveSessionState(state, logger).catch((err) => + logger.error("Failed to persist state", { error: err.message }), ) + + return formatPruningResultForTool(pruneToolIds, toolMetadata, workingDirectory) } -export function createDiscardTool( - ctx: PruneToolContext, -): ReturnType { +export function createDiscardTool(ctx: PruneToolContext): ReturnType { return tool({ description: DISCARD_TOOL_DESCRIPTION, args: { - ids: tool.schema.array( - tool.schema.string() - ).describe( - "First element is the reason ('completion' or 'noise'), followed by numeric IDs as strings to discard" - ), + ids: tool.schema + .array(tool.schema.string()) + .describe( + "First element is the reason ('completion' or 'noise'), followed by numeric IDs as strings to discard", + ), }, async execute(args, toolCtx) { // Parse reason from first element, numeric IDs from the rest @@ -158,36 +158,30 @@ export function createDiscardTool( const numericIds = args.ids.slice(1) - return executePruneOperation( - ctx, - toolCtx, - numericIds, - reason as PruneReason, - "Discard" - ) + return executePruneOperation(ctx, toolCtx, numericIds, reason as PruneReason, "Discard") }, }) } -export function createExtractTool( - ctx: PruneToolContext, -): ReturnType { +export function createExtractTool(ctx: PruneToolContext): ReturnType { return tool({ description: EXTRACT_TOOL_DESCRIPTION, args: { - ids: tool.schema.array( - tool.schema.string() - ).describe( - "Numeric IDs as strings to extract from the list" - ), - distillation: tool.schema.record(tool.schema.string(), tool.schema.any()).describe( - "REQUIRED. An object mapping each ID to its distilled findings. Must contain an entry for every ID being pruned." - ), + ids: tool.schema + .array(tool.schema.string()) + .describe("Numeric IDs as strings to extract from the list"), + distillation: tool.schema + .record(tool.schema.string(), tool.schema.any()) + .describe( + "REQUIRED. An object mapping each ID to its distilled findings. Must contain an entry for every ID being pruned.", + ), }, async execute(args, toolCtx) { if (!args.distillation || Object.keys(args.distillation).length === 0) { - ctx.logger.debug("Extract tool called without distillation: " + JSON.stringify(args)) - return "Missing distillation. You must provide distillation data when using extract. Format: distillation: { \"id\": { ...findings... } }" + ctx.logger.debug( + "Extract tool called without distillation: " + JSON.stringify(args), + ) + return 'Missing distillation. You must provide distillation data when using extract. Format: distillation: { "id": { ...findings... } }' } // Log the distillation for debugging/analysis @@ -200,7 +194,7 @@ export function createExtractTool( args.ids, "consolidation" as PruneReason, "Extract", - args.distillation + args.distillation, ) }, }) diff --git a/lib/strategies/utils.ts b/lib/strategies/utils.ts index 7a675fbc..5f141cad 100644 --- a/lib/strategies/utils.ts +++ b/lib/strategies/utils.ts @@ -1,15 +1,15 @@ import { SessionState, WithParts } from "../state" import { UserMessage } from "@opencode-ai/sdk" import { Logger } from "../logger" -import { encode } from 'gpt-tokenizer' +import { encode } from "gpt-tokenizer" import { getLastUserMessage, isMessageCompacted } from "../shared-utils" export function getCurrentParams( messages: WithParts[], - logger: Logger + logger: Logger, ): { - providerId: string | undefined, - modelId: string | undefined, + providerId: string | undefined + modelId: string | undefined agent: string | undefined } { const userMsg = getLastUserMessage(messages) @@ -29,9 +29,9 @@ export function getCurrentParams( */ function estimateTokensBatch(texts: string[]): number[] { try { - return texts.map(text => encode(text).length) + return texts.map((text) => encode(text).length) } catch { - return texts.map(text => Math.round(text.length / 4)) + return texts.map((text) => Math.round(text.length / 4)) } } @@ -41,7 +41,7 @@ function estimateTokensBatch(texts: string[]): number[] { export const calculateTokensSaved = ( state: SessionState, messages: WithParts[], - pruneToolIds: string[] + pruneToolIds: string[], ): number => { try { const contents: string[] = [] @@ -50,40 +50,43 @@ export const calculateTokensSaved = ( continue } for (const part of msg.parts) { - if (part.type !== 'tool' || !pruneToolIds.includes(part.callID)) { + if (part.type !== "tool" || !pruneToolIds.includes(part.callID)) { continue } // For write and edit tools, count input content as that is all we prune for these tools // (input is present in both completed and error states) if (part.tool === "write") { const inputContent = part.state.input?.content - const content = typeof inputContent === 'string' - ? inputContent - : JSON.stringify(inputContent ?? '') + const content = + typeof inputContent === "string" + ? inputContent + : JSON.stringify(inputContent ?? "") contents.push(content) continue } if (part.tool === "edit") { const oldString = part.state.input?.oldString const newString = part.state.input?.newString - if (typeof oldString === 'string') { + if (typeof oldString === "string") { contents.push(oldString) } - if (typeof newString === 'string') { + if (typeof newString === "string") { contents.push(newString) } continue } // For other tools, count output or error based on status if (part.state.status === "completed") { - const content = typeof part.state.output === 'string' - ? part.state.output - : JSON.stringify(part.state.output) + const content = + typeof part.state.output === "string" + ? part.state.output + : JSON.stringify(part.state.output) contents.push(content) } else if (part.state.status === "error") { - const content = typeof part.state.error === 'string' - ? part.state.error - : JSON.stringify(part.state.error) + const content = + typeof part.state.error === "string" + ? part.state.error + : JSON.stringify(part.state.error) contents.push(content) } } diff --git a/lib/ui/notification.ts b/lib/ui/notification.ts index 60844e9f..80f9f871 100644 --- a/lib/ui/notification.ts +++ b/lib/ui/notification.ts @@ -8,28 +8,20 @@ export type PruneReason = "completion" | "noise" | "consolidation" export const PRUNE_REASON_LABELS: Record = { completion: "Task Complete", noise: "Noise Removal", - consolidation: "Consolidation" + consolidation: "Consolidation", } -function formatStatsHeader( - totalTokensSaved: number, - pruneTokenCounter: number -): string { +function formatStatsHeader(totalTokensSaved: number, pruneTokenCounter: number): string { const totalTokensSavedStr = `~${formatTokenCount(totalTokensSaved + pruneTokenCounter)}` - return [ - `▣ DCP | ${totalTokensSavedStr} saved total`, - ].join('\n') + return [`▣ DCP | ${totalTokensSavedStr} saved total`].join("\n") } -function buildMinimalMessage( - state: SessionState, - reason: PruneReason | undefined -): string { - const reasonSuffix = reason ? ` [${PRUNE_REASON_LABELS[reason]}]` : '' - return formatStatsHeader( - state.stats.totalPruneTokens, - state.stats.pruneTokenCounter - ) + reasonSuffix +function buildMinimalMessage(state: SessionState, reason: PruneReason | undefined): string { + const reasonSuffix = reason ? ` [${PRUNE_REASON_LABELS[reason]}]` : "" + return ( + formatStatsHeader(state.stats.totalPruneTokens, state.stats.pruneTokenCounter) + + reasonSuffix + ) } function buildDetailedMessage( @@ -37,17 +29,17 @@ function buildDetailedMessage( reason: PruneReason | undefined, pruneToolIds: string[], toolMetadata: Map, - workingDirectory?: string + workingDirectory?: string, ): string { let message = formatStatsHeader(state.stats.totalPruneTokens, state.stats.pruneTokenCounter) if (pruneToolIds.length > 0) { const pruneTokenCounterStr = `~${formatTokenCount(state.stats.pruneTokenCounter)}` - const reasonLabel = reason ? ` — ${PRUNE_REASON_LABELS[reason]}` : '' + const reasonLabel = reason ? ` — ${PRUNE_REASON_LABELS[reason]}` : "" message += `\n\n▣ Pruning (${pruneTokenCounterStr})${reasonLabel}` const itemLines = formatPrunedItemsList(pruneToolIds, toolMetadata, workingDirectory) - message += '\n' + itemLines.join('\n') + message += "\n" + itemLines.join("\n") } return message.trim() @@ -63,38 +55,39 @@ export async function sendUnifiedNotification( toolMetadata: Map, reason: PruneReason | undefined, params: any, - workingDirectory: string + workingDirectory: string, ): Promise { const hasPruned = pruneToolIds.length > 0 if (!hasPruned) { return false } - if (config.pruneNotification === 'off') { + if (config.pruneNotification === "off") { return false } - const message = config.pruneNotification === 'minimal' - ? buildMinimalMessage(state, reason) - : buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory) + const message = + config.pruneNotification === "minimal" + ? buildMinimalMessage(state, reason) + : buildDetailedMessage(state, reason, pruneToolIds, toolMetadata, workingDirectory) await sendIgnoredMessage(client, sessionId, message, params, logger) return true } function formatDistillationMessage(distillation: Record): string { - const lines: string[] = ['▣ DCP | Extracted Distillation'] + const lines: string[] = ["▣ DCP | Extracted Distillation"] for (const [id, findings] of Object.entries(distillation)) { lines.push(`\n─── ID ${id} ───`) - if (typeof findings === 'object' && findings !== null) { + if (typeof findings === "object" && findings !== null) { lines.push(JSON.stringify(findings, null, 2)) } else { lines.push(String(findings)) } } - return lines.join('\n') + return lines.join("\n") } export async function sendDistillationNotification( @@ -102,7 +95,7 @@ export async function sendDistillationNotification( logger: Logger, sessionId: string, distillation: Record, - params: any + params: any, ): Promise { if (!distillation || Object.keys(distillation).length === 0) { return false @@ -118,32 +111,36 @@ export async function sendIgnoredMessage( sessionID: string, text: string, params: any, - logger: Logger + logger: Logger, ): Promise { const agent = params.agent || undefined - const model = params.providerId && params.modelId ? { - providerID: params.providerId, - modelID: params.modelId - } : undefined + const model = + params.providerId && params.modelId + ? { + providerID: params.providerId, + modelID: params.modelId, + } + : undefined try { await client.session.prompt({ path: { - id: sessionID + id: sessionID, }, body: { noReply: true, agent: agent, model: model, - parts: [{ - type: 'text', - text: text, - ignored: true - }] - } + parts: [ + { + type: "text", + text: text, + ignored: true, + }, + ], + }, }) } catch (error: any) { logger.error("Failed to send notification", { error: error.message }) } } - diff --git a/lib/ui/utils.ts b/lib/ui/utils.ts index 11335fad..11a43638 100644 --- a/lib/ui/utils.ts +++ b/lib/ui/utils.ts @@ -3,14 +3,14 @@ import { extractParameterKey } from "../messages/utils" export function formatTokenCount(tokens: number): string { if (tokens >= 1000) { - return `${(tokens / 1000).toFixed(1)}K`.replace('.0K', 'K') + ' tokens' + return `${(tokens / 1000).toFixed(1)}K`.replace(".0K", "K") + " tokens" } - return tokens.toString() + ' tokens' + return tokens.toString() + " tokens" } export function truncate(str: string, maxLen: number = 60): string { if (str.length <= maxLen) return str - return str.slice(0, maxLen - 3) + '...' + return str.slice(0, maxLen - 3) + "..." } export function shortenPath(input: string, workingDirectory?: string): string { @@ -27,11 +27,11 @@ export function shortenPath(input: string, workingDirectory?: string): string { function shortenSinglePath(path: string, workingDirectory?: string): string { if (workingDirectory) { - if (path.startsWith(workingDirectory + '/')) { + if (path.startsWith(workingDirectory + "/")) { return path.slice(workingDirectory.length + 1) } if (path === workingDirectory) { - return '.' + return "." } } @@ -44,7 +44,7 @@ function shortenSinglePath(path: string, workingDirectory?: string): string { export function formatPrunedItemsList( pruneToolIds: string[], toolMetadata: Map, - workingDirectory?: string + workingDirectory?: string, ): string[] { const lines: string[] = [] @@ -63,13 +63,11 @@ export function formatPrunedItemsList( } } - const knownCount = pruneToolIds.filter(id => - toolMetadata.has(id) - ).length + const knownCount = pruneToolIds.filter((id) => toolMetadata.has(id)).length const unknownCount = pruneToolIds.length - knownCount if (unknownCount > 0) { - lines.push(`→ (${unknownCount} tool${unknownCount > 1 ? 's' : ''} with unknown metadata)`) + lines.push(`→ (${unknownCount} tool${unknownCount > 1 ? "s" : ""} with unknown metadata)`) } return lines @@ -81,16 +79,16 @@ export function formatPrunedItemsList( export function formatPruningResultForTool( prunedIds: string[], toolMetadata: Map, - workingDirectory?: string + workingDirectory?: string, ): string { const lines: string[] = [] lines.push(`Context pruning complete. Pruned ${prunedIds.length} tool outputs.`) - lines.push('') + lines.push("") if (prunedIds.length > 0) { lines.push(`Semantically pruned (${prunedIds.length}):`) lines.push(...formatPrunedItemsList(prunedIds, toolMetadata, workingDirectory)) } - return lines.join('\n').trim() + return lines.join("\n").trim() } diff --git a/tsconfig.json b/tsconfig.json index e4fdca1b..b30286cf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,31 +1,24 @@ { - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "target": "ES2022", - "module": "ESNext", - "lib": ["ES2022"], - "moduleResolution": "bundler", - "resolveJsonModule": true, - "allowJs": true, - "checkJs": false, - "outDir": "./dist", - "rootDir": ".", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "types": ["node"] - }, - "include": [ - "index.ts", - "lib/**/*" - ], - "exclude": [ - "node_modules", - "dist", - "logs" - ] + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "lib": ["ES2022"], + "moduleResolution": "bundler", + "resolveJsonModule": true, + "allowJs": true, + "checkJs": false, + "outDir": "./dist", + "rootDir": ".", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "types": ["node"] + }, + "include": ["index.ts", "lib/**/*"], + "exclude": ["node_modules", "dist", "logs"] } From 953d8ebc63295954d783f44ba38c928e83396711 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 02:44:00 -0500 Subject: [PATCH 32/43] feat: add debug context logging for session messages - Add saveContext method to Logger that saves transformed messages as JSON - Save to ~/.config/opencode/logs/dcp/context/{sessionId}/{timestamp}.json - Only logs when debug.enabled is true in config - Minimize output by stripping unnecessary metadata (IDs, summary, path, etc.) - Keep essential fields: role, time, tokens, text/tool parts --- lib/hooks.ts | 4 +++ lib/logger.ts | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/lib/hooks.ts b/lib/hooks.ts index b9ef006a..be9e851a 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -28,6 +28,10 @@ export function createChatMessageTransformHandler( prune(state, logger, config, output.messages) insertPruneToolContext(state, config, logger, output.messages) + + if (state.sessionId) { + await logger.saveContext(state.sessionId, output.messages) + } } } diff --git a/lib/logger.ts b/lib/logger.ts index d101c673..c86a53dc 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -107,4 +107,99 @@ export class Logger { const component = this.getCallerFile(2) return this.write("ERROR", component, message, data) } + + /** + * Strips unnecessary metadata from messages for cleaner debug logs. + * + * Removed: + * - All IDs (id, sessionID, messageID, parentID, callID on parts) + * - summary, path, cost, model, agent, mode, finish, providerID, modelID + * - step-start and step-finish parts entirely + * - snapshot fields + * - ignored text parts + * + * Kept: + * - role, time (created only), tokens (input, output, reasoning, cache) + * - text, reasoning, tool parts with content + * - tool calls with: tool, callID, input, output + */ + private minimizeForDebug(messages: any[]): any[] { + return messages.map((msg) => { + const minimized: any = { + role: msg.info?.role, + } + + if (msg.info?.time?.created) { + minimized.time = msg.info.time.created + } + + if (msg.info?.tokens) { + minimized.tokens = { + input: msg.info.tokens.input, + output: msg.info.tokens.output, + reasoning: msg.info.tokens.reasoning, + cache: msg.info.tokens.cache, + } + } + + if (msg.parts) { + minimized.parts = msg.parts + .map((part: any) => { + if (part.type === "step-start" || part.type === "step-finish") { + return null + } + + if (part.type === "text") { + if (part.ignored) return null + return { type: "text", text: part.text } + } + + if (part.type === "reasoning") { + return { + type: "reasoning", + text: part.text, + } + } + + if (part.type === "tool") { + const toolPart: any = { + type: "tool", + tool: part.tool, + callID: part.callID, + } + + if (part.state?.input) { + toolPart.input = part.state.input + } + if (part.state?.output) { + toolPart.output = part.state.output + } + + return toolPart + } + + return null + }) + .filter(Boolean) + } + + return minimized + }) + } + + async saveContext(sessionId: string, messages: any[]) { + if (!this.enabled) return + + try { + const contextDir = join(this.logDir, "context", sessionId) + if (!existsSync(contextDir)) { + await mkdir(contextDir, { recursive: true }) + } + + const minimized = this.minimizeForDebug(messages) + const timestamp = new Date().toISOString().replace(/[:.]/g, "-") + const contextFile = join(contextDir, `${timestamp}.json`) + await writeFile(contextFile, JSON.stringify(minimized, null, 2)) + } catch (error) {} + } } From 481aef970da7ebfde283c131907cd0a79820f349 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 02:49:01 -0500 Subject: [PATCH 33/43] chore: add SCHEMA_NOTES.md to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 28a0e829..9f567cb5 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ test-update.ts # Documentation (local development only) docs/ +SCHEMA_NOTES.md From 8b5cac024697677db5aaf4390e8f9f74ee03897a Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 11:49:38 -0500 Subject: [PATCH 34/43] v1.1.0-beta.2 - Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5ae4a91f..e997f399 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", + "version": "1.1.0-beta.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", + "version": "1.1.0-beta.2", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.28", diff --git a/package.json b/package.json index 04d446bd..705a6b3c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.1", + "version": "1.1.0-beta.2", "type": "module", "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", "main": "./dist/index.js", From 16b86c767deda53046bfd1b6fd982de945e87596 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 19:51:06 -0500 Subject: [PATCH 35/43] refactor: use assistant role for prunable-tools injection Switch from user role to assistant role message for injecting prunable-tools context. This reduces the likelihood of the model directly addressing the injected content as if responding to user input, improving the conversational experience. --- lib/messages/prune.ts | 31 +++++++++++++++++-------------- lib/shared-utils.ts | 10 ++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index cc386c32..241a49ce 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -3,8 +3,8 @@ import type { Logger } from "../logger" import type { PluginConfig } from "../config" import { loadPrompt } from "../prompt" import { extractParameterKey, buildToolIdList } from "./utils" -import { getLastUserMessage, isMessageCompacted } from "../shared-utils" -import { UserMessage } from "@opencode-ai/sdk" +import { getLastAssistantMessage, isMessageCompacted } from "../shared-utils" +import { AssistantMessage } from "@opencode-ai/sdk" const PRUNED_TOOL_INPUT_REPLACEMENT = "[Input removed to save context]" const PRUNED_TOOL_OUTPUT_REPLACEMENT = @@ -101,8 +101,8 @@ export const insertPruneToolContext = ( return } - const lastUserMessage = getLastUserMessage(messages) - if (!lastUserMessage) { + const lastAssistantMessage = getLastAssistantMessage(messages) + if (!lastAssistantMessage) { return } @@ -131,22 +131,25 @@ export const insertPruneToolContext = ( prunableToolsContent = prunableToolsList + nudgeString } - const userMessage: WithParts = { + const assistantInfo = lastAssistantMessage.info as AssistantMessage + const assistantMessage: WithParts = { info: { id: SYNTHETIC_MESSAGE_ID, - sessionID: lastUserMessage.info.sessionID, - role: "user", + sessionID: assistantInfo.sessionID, + role: "assistant", + parentID: assistantInfo.parentID, + modelID: assistantInfo.modelID, + providerID: assistantInfo.providerID, time: { created: Date.now() }, - agent: (lastUserMessage.info as UserMessage).agent || "build", - model: { - providerID: (lastUserMessage.info as UserMessage).model.providerID, - modelID: (lastUserMessage.info as UserMessage).model.modelID, - }, + tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }, + cost: 0, + path: assistantInfo.path, + mode: assistantInfo.mode, }, parts: [ { id: SYNTHETIC_PART_ID, - sessionID: lastUserMessage.info.sessionID, + sessionID: assistantInfo.sessionID, messageID: SYNTHETIC_MESSAGE_ID, type: "text", text: prunableToolsContent, @@ -154,7 +157,7 @@ export const insertPruneToolContext = ( ], } - messages.push(userMessage) + messages.push(assistantMessage) } export const prune = ( diff --git a/lib/shared-utils.ts b/lib/shared-utils.ts index ce3be56a..d737eb72 100644 --- a/lib/shared-utils.ts +++ b/lib/shared-utils.ts @@ -13,3 +13,13 @@ export const getLastUserMessage = (messages: WithParts[]): WithParts | null => { } return null } + +export const getLastAssistantMessage = (messages: WithParts[]): WithParts | null => { + for (let i = messages.length - 1; i >= 0; i--) { + const msg = messages[i] + if (msg.info.role === "assistant") { + return msg + } + } + return null +} From 2886029e95274344386f74a355de53e677c45213 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 21:56:15 -0500 Subject: [PATCH 36/43] feat: add reasoning model support for synthetic message injection Reasoning models expect their encrypted reasoning parts in assistant messages, which we cannot generate. This adds detection via chat.params hook and appends a synthetic user message () to close the assistant turn properly when a reasoning model is active. --- index.ts | 17 +++++++++++++++++ lib/messages/prune.ts | 33 +++++++++++++++++++++++++++++++++ lib/state/state.ts | 2 ++ lib/state/types.ts | 1 + 4 files changed, 53 insertions(+) diff --git a/index.ts b/index.ts index 2da6abee..1046a763 100644 --- a/index.ts +++ b/index.ts @@ -1,4 +1,5 @@ import type { Plugin } from "@opencode-ai/plugin" +import type { Model } from "@opencode-ai/sdk" import { getConfig } from "./lib/config" import { Logger } from "./lib/logger" import { loadPrompt } from "./lib/prompt" @@ -26,6 +27,22 @@ const plugin: Plugin = (async (ctx) => { }) return { + "chat.params": async ( + input: { sessionID: string; agent: string; model: Model; provider: any; message: any }, + _output: { temperature: number; topP: number; options: Record }, + ) => { + const isReasoning = input.model.capabilities?.reasoning ?? false + if (state.isReasoningModel !== isReasoning) { + logger.info( + `Reasoning model status changed: ${state.isReasoningModel} -> ${isReasoning}`, + { + modelId: input.model.id, + providerId: input.model.providerID, + }, + ) + } + state.isReasoningModel = isReasoning + }, "experimental.chat.system.transform": async ( _input: unknown, output: { system: string[] }, diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 241a49ce..02c36670 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -48,6 +48,14 @@ Context management was just performed. Do not use the ${toolName} again. A fresh const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345" const SYNTHETIC_PART_ID = "prt_01234567890123456789012345" +const SYNTHETIC_USER_MESSAGE_ID = "msg_01234567890123456789012346" +const SYNTHETIC_USER_PART_ID = "prt_01234567890123456789012346" + +// Content for the synthetic user message appended after the assistant message for reasoning models. +// This is required because reasoning models expect their reasoning parts in assistant messages, +// and we cannot generate those encrypted/proprietary parts. By closing the assistant turn with +// a user message, the model sees a complete conversation structure. +const REASONING_MODEL_USER_MESSAGE_CONTENT = "" const buildPrunableToolsList = ( state: SessionState, @@ -158,6 +166,31 @@ export const insertPruneToolContext = ( } messages.push(assistantMessage) + + // For reasoning models, append a synthetic user message to close the assistant turn. + // This is required because reasoning models expect their reasoning parts in the last + // assistant message, which we cannot generate. The user message signals a complete turn. + if (state.isReasoningModel) { + const userMessage: WithParts = { + info: { + id: SYNTHETIC_USER_MESSAGE_ID, + sessionID: assistantInfo.sessionID, + role: "user", + time: { created: Date.now() + 1 }, + } as any, // Using 'as any' because we're creating a minimal synthetic message + parts: [ + { + id: SYNTHETIC_USER_PART_ID, + sessionID: assistantInfo.sessionID, + messageID: SYNTHETIC_USER_MESSAGE_ID, + type: "text", + text: REASONING_MODEL_USER_MESSAGE_CONTENT, + }, + ], + } + messages.push(userMessage) + logger.debug("Appended synthetic user message for reasoning model") + } } export const prune = ( diff --git a/lib/state/state.ts b/lib/state/state.ts index 956ac9dd..826af401 100644 --- a/lib/state/state.ts +++ b/lib/state/state.ts @@ -55,6 +55,7 @@ export function createSessionState(): SessionState { lastToolPrune: false, lastCompaction: 0, currentTurn: 0, + isReasoningModel: false, } } @@ -73,6 +74,7 @@ export function resetSessionState(state: SessionState): void { state.lastToolPrune = false state.lastCompaction = 0 state.currentTurn = 0 + state.isReasoningModel = false } export async function ensureSessionInitialized( diff --git a/lib/state/types.ts b/lib/state/types.ts index 9a6de02d..c602d3f7 100644 --- a/lib/state/types.ts +++ b/lib/state/types.ts @@ -34,4 +34,5 @@ export interface SessionState { lastToolPrune: boolean lastCompaction: number currentTurn: number // Current turn count derived from step-start parts + isReasoningModel: boolean // Whether the current model has reasoning capabilities } From 2c80d037aab91ee68135bb76b244ac1dce8403b8 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 22:05:57 -0500 Subject: [PATCH 37/43] fix: update injected prompts to use first-person language for assistant messages - Nudge prompts now use 'I must/I will' instead of 'You must/You should' - Prunable tools wrapper and cooldown message use first-person - System prompts updated to correctly describe injection as assistant message --- lib/messages/prune.ts | 4 ++-- lib/prompts/nudge/nudge-both.txt | 10 +++++----- lib/prompts/nudge/nudge-discard.txt | 8 ++++---- lib/prompts/nudge/nudge-extract.txt | 8 ++++---- lib/prompts/system/system-prompt-both.txt | 4 ++-- lib/prompts/system/system-prompt-discard.txt | 4 ++-- lib/prompts/system/system-prompt-extract.txt | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 02c36670..53e88ed3 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -24,7 +24,7 @@ const getNudgeString = (config: PluginConfig): string => { } const wrapPrunableTools = (content: string): string => ` -The following tools have been invoked and are available for pruning. This list does not mandate immediate action. Consider your current goals and the resources you need before discarding valuable tool inputs or outputs. Consolidate your prunes for efficiency; it is rarely worth pruning a single tiny tool output. Keep the context free of noise. +I have the following tool outputs available for pruning. I will consider my current goals and the resources I need before discarding valuable inputs or outputs. I will consolidate prunes for efficiency; it is rarely worth pruning a single tiny tool output. ${content} ` @@ -42,7 +42,7 @@ const getCooldownMessage = (config: PluginConfig): string => { } return ` -Context management was just performed. Do not use the ${toolName} again. A fresh list will be available after your next tool use. +I just performed context management. I should not use the ${toolName} again until after my next tool use, when a fresh list will be available. ` } diff --git a/lib/prompts/nudge/nudge-both.txt b/lib/prompts/nudge/nudge-both.txt index f9fa4926..b6fd6673 100644 --- a/lib/prompts/nudge/nudge-both.txt +++ b/lib/prompts/nudge/nudge-both.txt @@ -1,10 +1,10 @@ -**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. +**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping. -2. **Noise Removal:** If you read files or ran commands that yielded no value, use `discard` to remove them. -3. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use `extract` to distill the insights and remove the raw entry. +1. **Task Completion:** If a sub-task is complete, I will decide: use `discard` if no valuable context to preserve (default), or use `extract` if insights are worth keeping. +2. **Noise Removal:** If I read files or ran commands that yielded no value, I will use `discard` to remove them. +3. **Knowledge Preservation:** If I am holding valuable raw data I'll need to reference later, I will use `extract` to distill the insights and remove the raw entry. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must perform context management. +**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must perform context management. diff --git a/lib/prompts/nudge/nudge-discard.txt b/lib/prompts/nudge/nudge-discard.txt index 1ccecf9e..8a166f37 100644 --- a/lib/prompts/nudge/nudge-discard.txt +++ b/lib/prompts/nudge/nudge-discard.txt @@ -1,9 +1,9 @@ -**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. +**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene. **Immediate Actions Required:** -1. **Task Completion:** If a sub-task is complete, use the `discard` tool to remove the tools used. -2. **Noise Removal:** If you read files or ran commands that yielded no value, use the `discard` tool to remove them. +1. **Task Completion:** If a sub-task is complete, I will use the `discard` tool to remove the tools used. +2. **Noise Removal:** If I read files or ran commands that yielded no value, I will use the `discard` tool to remove them. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must discard unneeded tool outputs. +**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must discard unneeded tool outputs. diff --git a/lib/prompts/nudge/nudge-extract.txt b/lib/prompts/nudge/nudge-extract.txt index 5bdb370f..a09528e6 100644 --- a/lib/prompts/nudge/nudge-extract.txt +++ b/lib/prompts/nudge/nudge-extract.txt @@ -1,9 +1,9 @@ -**CRITICAL CONTEXT WARNING:** Your context window is filling with tool outputs. Strict adherence to context hygiene is required. +**CRITICAL CONTEXT WARNING:** My context window is filling with tool outputs. I must adhere strictly to context hygiene. **Immediate Actions Required:** -1. **Task Completion:** If you have completed work, extract key findings from the tools used. Scale distillation depth to the value of the content. -2. **Knowledge Preservation:** If you are holding valuable raw data you'll need to reference later, use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry. +1. **Task Completion:** If I have completed work, I will extract key findings from the tools used. I will scale distillation depth to the value of the content. +2. **Knowledge Preservation:** If I am holding valuable raw data I'll need to reference later, I will use the `extract` tool with high-fidelity distillation to preserve the insights and remove the raw entry. -**Protocol:** You should prioritize this cleanup, but do not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, you must extract valuable findings from tool outputs. +**Protocol:** I should prioritize this cleanup, but I will not interrupt a critical atomic operation if one is in progress. Once the immediate step is done, I must extract valuable findings from tool outputs. diff --git a/lib/prompts/system/system-prompt-both.txt b/lib/prompts/system/system-prompt-both.txt index f1e88aa2..4ba3bfee 100644 --- a/lib/prompts/system/system-prompt-both.txt +++ b/lib/prompts/system/system-prompt-both.txt @@ -2,7 +2,7 @@ ENVIRONMENT -You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to prune. +You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` and `extract` tools. A list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to prune. TWO TOOLS FOR CONTEXT MANAGEMENT - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content. @@ -42,7 +42,7 @@ There may be tools in session context that do not appear in the -After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned. +After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned. CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: - NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears. diff --git a/lib/prompts/system/system-prompt-discard.txt b/lib/prompts/system/system-prompt-discard.txt index 796852e3..384686a6 100644 --- a/lib/prompts/system/system-prompt-discard.txt +++ b/lib/prompts/system/system-prompt-discard.txt @@ -2,7 +2,7 @@ ENVIRONMENT -You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to discard. +You are operating in a context-constrained environment and thus must proactively manage your context window using the `discard` tool. A list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to discard. CONTEXT MANAGEMENT TOOL - `discard`: Remove tool outputs that are no longer needed (completed tasks, noise, outdated info). No preservation of content. @@ -33,7 +33,7 @@ There may be tools in session context that do not appear in the -After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded. +After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded. CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: - NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears. diff --git a/lib/prompts/system/system-prompt-extract.txt b/lib/prompts/system/system-prompt-extract.txt index 2a1a0568..810cef72 100644 --- a/lib/prompts/system/system-prompt-extract.txt +++ b/lib/prompts/system/system-prompt-extract.txt @@ -2,7 +2,7 @@ ENVIRONMENT -You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A list is injected by the environment as a user message, and always contains up to date information. Use this information when deciding what to extract. +You are operating in a context-constrained environment and thus must proactively manage your context window using the `extract` tool. A list is injected by the environment as an assistant message, and always contains up to date information. Use this information when deciding what to extract. CONTEXT MANAGEMENT TOOL - `extract`: Extract key findings from tools into distilled knowledge before removing the raw content from context. Use this to preserve important information while reducing context size. @@ -33,7 +33,7 @@ There may be tools in session context that do not appear in the -After each assistant turn, the environment may inject a user message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted. +After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted. CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: - NEVER reference the extract encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the extract encouragement appears. From 74257ab3cd91a4ad2fdd3c0fca081a6612465035 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 22:26:10 -0500 Subject: [PATCH 38/43] fix: update tool specs and injected prompts for assistant-role injection --- lib/messages/prune.ts | 4 ++-- lib/prompts/discard-tool-spec.txt | 2 +- lib/prompts/extract-tool-spec.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 53e88ed3..073f74d6 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -24,7 +24,7 @@ const getNudgeString = (config: PluginConfig): string => { } const wrapPrunableTools = (content: string): string => ` -I have the following tool outputs available for pruning. I will consider my current goals and the resources I need before discarding valuable inputs or outputs. I will consolidate prunes for efficiency; it is rarely worth pruning a single tiny tool output. +I have the following tool outputs available for pruning. I should consider my current goals and the resources I need before discarding valuable inputs or outputs. I should consolidate prunes for efficiency; it is rarely worth pruning a single tiny tool output. ${content} ` @@ -42,7 +42,7 @@ const getCooldownMessage = (config: PluginConfig): string => { } return ` -I just performed context management. I should not use the ${toolName} again until after my next tool use, when a fresh list will be available. +I just performed context management. I will not use the ${toolName} again until after my next tool use, when a fresh list will be available. ` } diff --git a/lib/prompts/discard-tool-spec.txt b/lib/prompts/discard-tool-spec.txt index 4cbf50a5..bd6478e8 100644 --- a/lib/prompts/discard-tool-spec.txt +++ b/lib/prompts/discard-tool-spec.txt @@ -1,7 +1,7 @@ Discards tool outputs from context to manage conversation size and reduce noise. ## IMPORTANT: The Prunable List -A `` list is injected into user messages showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard. +A `` list is provided to you showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard. **Note:** For `write` and `edit` tools, discarding removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context. diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt index 9af5b666..037837dc 100644 --- a/lib/prompts/extract-tool-spec.txt +++ b/lib/prompts/extract-tool-spec.txt @@ -1,7 +1,7 @@ Extracts key findings from tool outputs into distilled knowledge, then removes the raw outputs from context. ## IMPORTANT: The Prunable List -A `` list is injected into user messages showing available tool outputs you can extract from when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to extract. +A `` list is provided to you showing available tool outputs you can extract from when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to extract. ## When to Use This Tool From fa47430647ba30f3ba4c144ad5f98cde1997355e Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 23:04:18 -0500 Subject: [PATCH 39/43] fix: preserve agent context in synthetic user messages and remove obsolete injected_context_handling instructions --- lib/messages/prune.ts | 16 +++++++++++----- lib/prompts/system/system-prompt-both.txt | 15 --------------- lib/prompts/system/system-prompt-discard.txt | 15 --------------- lib/prompts/system/system-prompt-extract.txt | 15 --------------- 4 files changed, 11 insertions(+), 50 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index 073f74d6..b6220fab 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -3,8 +3,8 @@ import type { Logger } from "../logger" import type { PluginConfig } from "../config" import { loadPrompt } from "../prompt" import { extractParameterKey, buildToolIdList } from "./utils" -import { getLastAssistantMessage, isMessageCompacted } from "../shared-utils" -import { AssistantMessage } from "@opencode-ai/sdk" +import { getLastAssistantMessage, getLastUserMessage, isMessageCompacted } from "../shared-utils" +import { AssistantMessage, UserMessage } from "@opencode-ai/sdk" const PRUNED_TOOL_INPUT_REPLACEMENT = "[Input removed to save context]" const PRUNED_TOOL_OUTPUT_REPLACEMENT = @@ -168,16 +168,22 @@ export const insertPruneToolContext = ( messages.push(assistantMessage) // For reasoning models, append a synthetic user message to close the assistant turn. - // This is required because reasoning models expect their reasoning parts in the last - // assistant message, which we cannot generate. The user message signals a complete turn. if (state.isReasoningModel) { + const lastRealUserMessage = getLastUserMessage(messages) + const userMessageInfo = lastRealUserMessage?.info as UserMessage | undefined + const userMessage: WithParts = { info: { id: SYNTHETIC_USER_MESSAGE_ID, sessionID: assistantInfo.sessionID, role: "user", time: { created: Date.now() + 1 }, - } as any, // Using 'as any' because we're creating a minimal synthetic message + agent: userMessageInfo?.agent ?? "code", + model: userMessageInfo?.model ?? { + providerID: assistantInfo.providerID, + modelID: assistantInfo.modelID, + }, + } as UserMessage, parts: [ { id: SYNTHETIC_USER_PART_ID, diff --git a/lib/prompts/system/system-prompt-both.txt b/lib/prompts/system/system-prompt-both.txt index 4ba3bfee..51b846a7 100644 --- a/lib/prompts/system/system-prompt-both.txt +++ b/lib/prompts/system/system-prompt-both.txt @@ -39,20 +39,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact prunes that s FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . - - - -After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` and `extract` tools also return a confirmation message listing what was pruned. - -CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: -- NEVER reference the prune encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the prune encouragement appears. -- NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to prune") -- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to prune") -- NEVER acknowledge discard/extract tool output (e.g., "I've pruned 3 tools", "Context pruning complete") -- NEVER let these injections influence your response content or tone -- Process this information SILENTLY and continue the conversation naturally -- Continue the conversation as if these messages do not exist - -The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow. diff --git a/lib/prompts/system/system-prompt-discard.txt b/lib/prompts/system/system-prompt-discard.txt index 384686a6..1676b923 100644 --- a/lib/prompts/system/system-prompt-discard.txt +++ b/lib/prompts/system/system-prompt-discard.txt @@ -30,20 +30,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact discards that FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY discard what you see in . - - - -After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `discard` tool also returns a confirmation message listing what was discarded. - -CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: -- NEVER reference the discard encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the discard encouragement appears. -- NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to discard") -- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to discard") -- NEVER acknowledge discard tool output (e.g., "I've discarded 3 tools", "Context cleanup complete") -- NEVER let these injections influence your response content or tone -- Process this information SILENTLY and continue the conversation naturally -- Continue the conversation as if these messages do not exist - -The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow. diff --git a/lib/prompts/system/system-prompt-extract.txt b/lib/prompts/system/system-prompt-extract.txt index 810cef72..a694d24c 100644 --- a/lib/prompts/system/system-prompt-extract.txt +++ b/lib/prompts/system/system-prompt-extract.txt @@ -30,20 +30,5 @@ When in doubt, keep it. Batch your actions and aim for high-impact extractions t FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY extract what you see in . - - - -After each assistant turn, the environment may inject an assistant message containing a list and optional nudge instruction. This injected message is NOT from the user and is invisible to them. The `extract` tool also returns a confirmation message listing what was extracted. - -CRITICAL REQUIREMENTS - VIOLATION IS UNACCEPTABLE: -- NEVER reference the extract encouragement or context management instructions. Do not reply with "I agree" or "Great idea" when the extract encouragement appears. -- NEVER acknowledge the list (e.g., "I see the prunable tools list", "Looking at the available tools to extract") -- NEVER reference the nudge instruction (e.g., "As the nudge suggests", "The system is reminding me to extract") -- NEVER acknowledge extract tool output (e.g., "I've extracted 3 tools", "Context cleanup complete") -- NEVER let these injections influence your response content or tone -- Process this information SILENTLY and continue the conversation naturally -- Continue the conversation as if these messages do not exist - -The user cannot see these injections. Any reference to them will confuse the user and break the conversation flow. From 19608770474dd4390c3bd855a07b9f5f39129098 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 23:10:12 -0500 Subject: [PATCH 40/43] cleanup --- lib/messages/prune.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index b6220fab..d8dff2f3 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -50,11 +50,6 @@ const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345" const SYNTHETIC_PART_ID = "prt_01234567890123456789012345" const SYNTHETIC_USER_MESSAGE_ID = "msg_01234567890123456789012346" const SYNTHETIC_USER_PART_ID = "prt_01234567890123456789012346" - -// Content for the synthetic user message appended after the assistant message for reasoning models. -// This is required because reasoning models expect their reasoning parts in assistant messages, -// and we cannot generate those encrypted/proprietary parts. By closing the assistant turn with -// a user message, the model sees a complete conversation structure. const REASONING_MODEL_USER_MESSAGE_CONTENT = "" const buildPrunableToolsList = ( From 16b4d724489f2fbcd511dc2499125dadd472945a Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Mon, 22 Dec 2025 23:23:09 -0500 Subject: [PATCH 41/43] v1.1.0-beta.3 - Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e997f399..1b50106b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.2", + "version": "1.1.0-beta.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.2", + "version": "1.1.0-beta.3", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.28", diff --git a/package.json b/package.json index 705a6b3c..ca6097e3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.2", + "version": "1.1.0-beta.3", "type": "module", "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", "main": "./dist/index.js", From 92bff5e0aa32960702950de4857c66cdbe340e45 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Tue, 23 Dec 2025 15:38:08 -0500 Subject: [PATCH 42/43] Simplify extract distillation to array format --- lib/messages/prune.ts | 5 +- lib/prompts/discard-tool-spec.txt | 37 ++++------- lib/prompts/extract-tool-spec.txt | 68 ++++++-------------- lib/prompts/system/system-prompt-both.txt | 9 +-- lib/prompts/system/system-prompt-discard.txt | 2 + lib/prompts/system/system-prompt-extract.txt | 2 + lib/strategies/tools.ts | 12 ++-- 7 files changed, 47 insertions(+), 88 deletions(-) diff --git a/lib/messages/prune.ts b/lib/messages/prune.ts index d8dff2f3..bdca0c15 100644 --- a/lib/messages/prune.ts +++ b/lib/messages/prune.ts @@ -6,7 +6,8 @@ import { extractParameterKey, buildToolIdList } from "./utils" import { getLastAssistantMessage, getLastUserMessage, isMessageCompacted } from "../shared-utils" import { AssistantMessage, UserMessage } from "@opencode-ai/sdk" -const PRUNED_TOOL_INPUT_REPLACEMENT = "[Input removed to save context]" +const PRUNED_TOOL_INPUT_REPLACEMENT = + "[content removed to save context, this is not what was written to the file, but a placeholder]" const PRUNED_TOOL_OUTPUT_REPLACEMENT = "[Output removed to save context - information superseded or no longer needed]" const getNudgeString = (config: PluginConfig): string => { @@ -50,7 +51,7 @@ const SYNTHETIC_MESSAGE_ID = "msg_01234567890123456789012345" const SYNTHETIC_PART_ID = "prt_01234567890123456789012345" const SYNTHETIC_USER_MESSAGE_ID = "msg_01234567890123456789012346" const SYNTHETIC_USER_PART_ID = "prt_01234567890123456789012346" -const REASONING_MODEL_USER_MESSAGE_CONTENT = "" +const REASONING_MODEL_USER_MESSAGE_CONTENT = "[internal: context sync - no response needed]" const buildPrunableToolsList = ( state: SessionState, diff --git a/lib/prompts/discard-tool-spec.txt b/lib/prompts/discard-tool-spec.txt index bd6478e8..68669edd 100644 --- a/lib/prompts/discard-tool-spec.txt +++ b/lib/prompts/discard-tool-spec.txt @@ -3,34 +3,29 @@ Discards tool outputs from context to manage conversation size and reduce noise. ## IMPORTANT: The Prunable List A `` list is provided to you showing available tool outputs you can discard when there are tools available for pruning. Each line has the format `ID: tool, parameter` (e.g., `20: read, /path/to/file.ts`). You MUST only use numeric IDs that appear in this list to select which tools to discard. -**Note:** For `write` and `edit` tools, discarding removes the input content (the code being written/edited) while preserving the output confirmation. This is useful after completing a file modification when you no longer need the raw content in context. - ## When to Use This Tool -Use `discard` for removing tool outputs that are no longer needed **without preserving their content**: - -### 1. Task Completion (Clean Up) -**When:** You have successfully completed a specific unit of work (e.g., fixed a bug, wrote a file, answered a question). -**Action:** Discard the tools used for that task with reason `completion`. +Use `discard` for removing tool content that is no longer needed -### 2. Removing Noise (Garbage Collection) -**When:** You have read files or run commands that turned out to be irrelevant, unhelpful, or outdated (meaning later tools have provided fresher, more valid information). -**Action:** Discard these specific tool outputs immediately with reason `noise`. +- **Noise:** Irrelevant, unhelpful, or superseded outputs that provide no value. +- **Task Completion:** Work is complete and there's no valuable information worth preserving. ## When NOT to Use This Tool -- **If you need to preserve information:** Keep the raw output in context rather than discarding it. -- **If you'll need the output later:** Don't discard files you plan to edit, or context you'll need for implementation. +- **If the output contains useful information:** Use `extract` instead to preserve key findings. +- **If you'll need the output later:** Don't discard files you plan to edit or context you'll need for implementation. ## Best Practices - **Strategic Batching:** Don't discard single small tool outputs (like short bash commands) unless they are pure noise. Wait until you have several items to perform high-impact discards. - **Think ahead:** Before discarding, ask: "Will I need this output for an upcoming task?" If yes, keep it. ## Format -The `ids` parameter is an array where the first element is the reason, followed by numeric IDs: -`ids: ["reason", "id1", "id2", ...]` -## Examples +- `ids`: Array where the first element is the reason, followed by numeric IDs from the `` list + +Reasons: `noise` | `completion` + +## Example Assistant: [Reads 'wrong_file.ts'] @@ -40,17 +35,7 @@ This file isn't relevant to the auth system. I'll remove it to clear the context Assistant: [Runs tests, they pass] -The tests passed. I'll clean up now. +The tests passed and I don't need to preserve any details. I'll clean up now. [Uses discard with ids: ["completion", "20", "21"]] - -Assistant: [Reads 'auth.ts' to understand the login flow] -I've understood the auth flow. I'll need to modify this file to add the new validation, so I'm keeping this read in context rather than discarding. - - - -Assistant: [Edits 'auth.ts' to add validation] -The edit was successful. I no longer need the raw edit content in context. -[Uses discard with ids: ["completion", "15"]] - diff --git a/lib/prompts/extract-tool-spec.txt b/lib/prompts/extract-tool-spec.txt index 037837dc..79862247 100644 --- a/lib/prompts/extract-tool-spec.txt +++ b/lib/prompts/extract-tool-spec.txt @@ -7,70 +7,38 @@ A `` list is provided to you showing available tool outputs you Use `extract` when you have gathered useful information that you want to **preserve in distilled form** before removing the raw outputs: -### 1. Task Completion -**When:** You have completed a unit of work and want to preserve key findings. -**Action:** Extract with distillation scaled to the value of the content. High-value insights require comprehensive capture; routine completions can use lighter distillation. - -### 2. Knowledge Preservation -**When:** You have read files, run commands, or gathered context that contains valuable information you'll need to reference later, but the full raw output is too large to keep. -**Action:** Convert raw data into distilled knowledge. This allows you to remove large outputs (like full file reads) while keeping only the specific parts you need (like a single function signature or constant). - -## CRITICAL: Distillation Requirements - -You MUST provide distilled findings in the `distillation` parameter. This is not optional. - -- **Comprehensive Capture:** Distillation is not just a summary. It must be a high-fidelity representation of the technical details. If you read a file, the distillation should include function signatures, specific logic flows, constant values, and any constraints or edge cases discovered. -- **Task-Relevant Verbosity:** Be as verbose as necessary to ensure that the "distilled" version is a complete substitute for the raw output for the task at hand. If you will need to reference a specific algorithm or interface later, include it in its entirety within the distillation. -- **Extract Per-ID:** When extracting from multiple tools, your `distillation` object MUST contain a corresponding entry for EVERY ID being extracted. You must capture high-fidelity findings for each tool individually to ensure no signal is lost. -- **Structure:** Map EVERY `ID` from the `ids` array to its specific distilled findings. - Example: `{ "20": { ... }, "21": { ... } }` -- Capture all relevant details (function names, logic, constraints) to ensure no signal is lost. -- Prioritize information that is essential for the immediate next steps of your plan. +- **Task Completion:** You completed a unit of work and want to preserve key findings. +- **Knowledge Preservation:** You have context that contains valuable information, but also a lot of unnecessary detail - you only need to preserve some specifics. ## When NOT to Use This Tool -- **If you need precise syntax:** If you'll need to edit a file, grep for exact strings, or reference precise syntax, keep the raw output. Distillation works for understanding; implementation often requires the original. -- **If uncertain:** Prefer keeping over re-fetching. The cost of retaining context is lower than the cost of redundant tool calls. +- **If you need precise syntax:** If you'll edit a file or grep for exact strings, keep the raw output. +- **If uncertain:** Prefer keeping over re-fetching. + ## Best Practices -- **Technical Fidelity:** Ensure that types, parameters, and return values are preserved if they are relevant to upcoming implementation steps. - **Strategic Batching:** Wait until you have several items or a few large outputs to extract, rather than doing tiny, frequent extractions. Aim for high-impact extractions that significantly reduce context size. - **Think ahead:** Before extracting, ask: "Will I need the raw output for an upcoming task?" If you researched a file you'll later edit, do NOT extract it. ## Format -The `ids` parameter is an array of numeric IDs as strings: -`ids: ["id1", "id2", ...]` -The `distillation` parameter is an object mapping each ID to its distilled findings: -`distillation: { "id1": { ...findings... }, "id2": { ...findings... } }` +- `ids`: Array of numeric IDs as strings from the `` list +- `distillation`: Array of strings, one per ID (positional: distillation[0] is for ids[0], etc.) + +Each distillation string should capture the essential information you need to preserve - function signatures, logic, constraints, values, etc. Be as detailed as needed for your task. ## Example -Assistant: [Reads service implementation, types, and config] -I'll preserve the full technical specification and implementation logic before extracting. -[Uses extract with ids: ["10", "11", "12"], distillation: { - "10": { - "file": "src/services/auth.ts", - "signatures": [ - "async function validateToken(token: string): Promise", - "function hashPassword(password: string): string" - ], - "logic": "The validateToken function first checks the local cache before calling the external OIDC provider. It uses a 5-minute TTL for cached tokens.", - "dependencies": ["import { cache } from '../utils/cache'", "import { oidc } from '../config'"], - "constraints": "Tokens must be at least 128 chars long. hashPassword uses bcrypt with 12 rounds." - }, - "11": { - "file": "src/types/user.ts", - "interface": "interface User { id: string; email: string; permissions: ('read' | 'write' | 'admin')[]; status: 'active' | 'suspended'; }", - "context": "The permissions array is strictly typed and used by the RBAC middleware." - }, - "12": { - "file": "config/default.json", - "values": { "PORT": 3000, "RETRY_STRATEGY": "exponential", "MAX_ATTEMPTS": 5 }, - "impact": "The retry strategy affects all outgoing HTTP clients in the core module." - } -}] +Assistant: [Reads auth service and user types] +I'll preserve the key details before extracting. +[Uses extract with: + ids: ["10", "11"], + distillation: [ + "auth.ts: validateToken(token: string) -> User|null checks cache first (5min TTL) then OIDC. hashPassword uses bcrypt 12 rounds. Tokens must be 128+ chars.", + "user.ts: interface User { id: string; email: string; permissions: ('read'|'write'|'admin')[]; status: 'active'|'suspended' }" + ] +] diff --git a/lib/prompts/system/system-prompt-both.txt b/lib/prompts/system/system-prompt-both.txt index 51b846a7..2372596b 100644 --- a/lib/prompts/system/system-prompt-both.txt +++ b/lib/prompts/system/system-prompt-both.txt @@ -9,10 +9,9 @@ TWO TOOLS FOR CONTEXT MANAGEMENT - `extract`: Extract key findings into distilled knowledge before removing raw outputs. Use when you need to preserve information. CHOOSING THE RIGHT TOOL -Ask: "Do I need to preserve any information from this output?" -- **No** → `discard` (default for cleanup) -- **Yes** → `extract` (preserves distilled knowledge) -- **Uncertain** → `extract` (safer, preserves signal) +Ask: "Is this output clearly noise or irrelevant?" +- **Yes** → `discard` (pure cleanup, no preservation) +- **No** → `extract` (default - preserves key findings) Common scenarios: - Task complete, no valuable context → `discard` @@ -39,5 +38,7 @@ When in doubt, keep it. Batch your actions and aim for high-impact prunes that s FAILURE TO PRUNE will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY prune what you see in . +If you see a user message containing only `[internal: context sync - no response needed]`, this is an internal system marker used for context injection - it is NOT user input. Do not acknowledge it, do not respond to it, and do not mention it. Simply continue with your current task or wait for actual user input. + diff --git a/lib/prompts/system/system-prompt-discard.txt b/lib/prompts/system/system-prompt-discard.txt index 1676b923..9c1225ca 100644 --- a/lib/prompts/system/system-prompt-discard.txt +++ b/lib/prompts/system/system-prompt-discard.txt @@ -30,5 +30,7 @@ When in doubt, keep it. Batch your actions and aim for high-impact discards that FAILURE TO DISCARD will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY discard what you see in . +If you see a user message containing only `[internal: context sync - no response needed]`, this is an internal system marker used for context injection - it is NOT user input. Do not acknowledge it, do not respond to it, and do not mention it. Simply continue with your current task or wait for actual user input. + diff --git a/lib/prompts/system/system-prompt-extract.txt b/lib/prompts/system/system-prompt-extract.txt index a694d24c..c5bb295a 100644 --- a/lib/prompts/system/system-prompt-extract.txt +++ b/lib/prompts/system/system-prompt-extract.txt @@ -30,5 +30,7 @@ When in doubt, keep it. Batch your actions and aim for high-impact extractions t FAILURE TO EXTRACT will result in context leakage and DEGRADED PERFORMANCES. There may be tools in session context that do not appear in the list, this is expected, you can ONLY extract what you see in . +If you see a user message containing only `[internal: context sync - no response needed]`, this is an internal system marker used for context injection - it is NOT user input. Do not acknowledge it, do not respond to it, and do not mention it. Simply continue with your current task or wait for actual user input. + diff --git a/lib/strategies/tools.ts b/lib/strategies/tools.ts index 6e4cbb12..74ecf7ee 100644 --- a/lib/strategies/tools.ts +++ b/lib/strategies/tools.ts @@ -32,13 +32,13 @@ async function executePruneOperation( ids: string[], reason: PruneReason, toolName: string, - distillation?: Record, + distillation?: string[], ): Promise { const { client, state, logger, config, workingDirectory } = ctx const sessionId = toolCtx.sessionID logger.info(`${toolName} tool invoked`) - logger.info(JSON.stringify({ ids, reason })) + logger.info(JSON.stringify(reason ? { ids, reason } : { ids })) if (!ids || ids.length === 0) { logger.debug(`${toolName} tool called but ids is empty or undefined`) @@ -171,17 +171,17 @@ export function createExtractTool(ctx: PruneToolContext): ReturnType list"), distillation: tool.schema - .record(tool.schema.string(), tool.schema.any()) + .array(tool.schema.string()) .describe( - "REQUIRED. An object mapping each ID to its distilled findings. Must contain an entry for every ID being pruned.", + "REQUIRED. Array of strings, one per ID (positional: distillation[0] is for ids[0], etc.)", ), }, async execute(args, toolCtx) { - if (!args.distillation || Object.keys(args.distillation).length === 0) { + if (!args.distillation || args.distillation.length === 0) { ctx.logger.debug( "Extract tool called without distillation: " + JSON.stringify(args), ) - return 'Missing distillation. You must provide distillation data when using extract. Format: distillation: { "id": { ...findings... } }' + return "Missing distillation. You must provide a distillation string for each ID." } // Log the distillation for debugging/analysis From a8bec375c6e1f9bce72769d2b4f3298e620db2d7 Mon Sep 17 00:00:00 2001 From: Daniel Smolsky Date: Tue, 23 Dec 2025 15:57:22 -0500 Subject: [PATCH 43/43] v1.1.1-beta.1 - Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b50106b..f4c40169 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.3", + "version": "1.1.1-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.3", + "version": "1.1.1-beta.1", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.28", diff --git a/package.json b/package.json index ca6097e3..15883997 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@tarquinen/opencode-dcp", - "version": "1.1.0-beta.3", + "version": "1.1.1-beta.1", "type": "module", "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", "main": "./dist/index.js",