diff --git a/README.md b/README.md index 9d4f44f..6b29fe6 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add to your OpenCode config: ```jsonc // opencode.jsonc { - "plugin": ["@tarquinen/opencode-dcp@0.3.28"] + "plugin": ["@tarquinen/opencode-dcp@0.3.29"] } ``` @@ -83,6 +83,20 @@ Settings are merged in order: **Defaults** → **Global** (`~/.config/opencode/d Restart OpenCode after making config changes. +## Subagents + +DCP automatically skips processing for subagent sessions (`general`, `explore`, etc.), but subagents can still invoke the `prune` tool. To prevent this, disable the tool in your OpenCode config. Any custom agents you've defined should also have prune disabled: + +```jsonc +// opencode.jsonc +{ + "agent": { + "general": { "tools": { "prune": false } }, + "explore": { "tools": { "prune": false } } + } +} +``` + ## License MIT diff --git a/lib/fetch-wrapper/index.ts b/lib/fetch-wrapper/index.ts index d57bda7..0cadb56 100644 --- a/lib/fetch-wrapper/index.ts +++ b/lib/fetch-wrapper/index.ts @@ -28,7 +28,7 @@ export function installFetchWrapper( prompts: SynthPrompts ): () => void { const originalGlobalFetch = globalThis.fetch - + const ctx: FetchHandlerContext = { state, logger, @@ -39,6 +39,14 @@ export function installFetchWrapper( } globalThis.fetch = async (input: any, init?: any) => { + // Skip all DCP processing for subagent sessions + if (state.lastSeenSessionId && state.subagentSessions.has(state.lastSeenSessionId)) { + logger.debug("fetch-wrapper", "Skipping DCP processing for subagent session", { + sessionId: state.lastSeenSessionId.substring(0, 8) + }) + return originalGlobalFetch(input, init) + } + if (init?.body && typeof init.body === 'string') { try { const body = JSON.parse(init.body) @@ -74,14 +82,12 @@ export function installFetchWrapper( init.body = JSON.stringify(body) } } catch (e) { - // Silently ignore parsing errors - pass through to original fetch } } return originalGlobalFetch(input, init) } - // Return cleanup function to restore original fetch return () => { globalThis.fetch = originalGlobalFetch } diff --git a/lib/hooks.ts b/lib/hooks.ts index 6c2e807..d6d1834 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -72,6 +72,18 @@ export function createChatParamsHandler( providerID = input.message.model.providerID } + // Track the last seen session ID for fetch wrapper correlation + state.lastSeenSessionId = sessionId + + // Check if this is a subagent session + if (!state.checkedSessions.has(sessionId)) { + state.checkedSessions.add(sessionId) + const isSubagent = await isSubagentSession(client, sessionId) + if (isSubagent) { + state.subagentSessions.add(sessionId) + } + } + // Cache model info for the session if (providerID && modelID) { state.model.set(sessionId, { diff --git a/lib/state.ts b/lib/state.ts index 5145eae..3bdb422 100644 --- a/lib/state.ts +++ b/lib/state.ts @@ -22,6 +22,12 @@ export interface PluginState { googleToolCallMapping: Map> /** Set of session IDs that have been restored from disk */ restoredSessions: Set + /** Set of session IDs we've already checked for subagent status (to avoid redundant API calls) */ + checkedSessions: Set + /** Set of session IDs that are subagents (have a parentID) - used to skip fetch wrapper processing */ + subagentSessions: Set + /** The most recent session ID seen in chat.params - used to correlate fetch requests */ + lastSeenSessionId: string | null } export interface ToolParameterEntry { @@ -45,6 +51,9 @@ export function createPluginState(): PluginState { model: new Map(), googleToolCallMapping: new Map(), restoredSessions: new Set(), + checkedSessions: new Set(), + subagentSessions: new Set(), + lastSeenSessionId: null, } } diff --git a/package-lock.json b/package-lock.json index b88cb2d..d9fa587 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tarquinen/opencode-dcp", - "version": "0.3.28", + "version": "0.3.29", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tarquinen/opencode-dcp", - "version": "0.3.28", + "version": "0.3.29", "license": "MIT", "dependencies": { "@ai-sdk/openai-compatible": "^1.0.27", diff --git a/package.json b/package.json index be2e5e8..c92bc4b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@tarquinen/opencode-dcp", - "version": "0.3.28", + "version": "0.3.29", "type": "module", "description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context", "main": "./dist/index.js",