Skip to content

Commit e15a251

Browse files
authored
Merge pull request #51 from Tarquinen/release/v0.3.29
Release v0.3.29 - Improved subagent handling
2 parents 0870763 + 872d37e commit e15a251

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Add to your OpenCode config:
1313
```jsonc
1414
// opencode.jsonc
1515
{
16-
"plugin": ["@tarquinen/[email protected].28"]
16+
"plugin": ["@tarquinen/[email protected].29"]
1717
}
1818
```
1919

@@ -83,6 +83,20 @@ Settings are merged in order: **Defaults** → **Global** (`~/.config/opencode/d
8383

8484
Restart OpenCode after making config changes.
8585

86+
## Subagents
87+
88+
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:
89+
90+
```jsonc
91+
// opencode.jsonc
92+
{
93+
"agent": {
94+
"general": { "tools": { "prune": false } },
95+
"explore": { "tools": { "prune": false } }
96+
}
97+
}
98+
```
99+
86100
## License
87101

88102
MIT

lib/fetch-wrapper/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function installFetchWrapper(
2828
prompts: SynthPrompts
2929
): () => void {
3030
const originalGlobalFetch = globalThis.fetch
31-
31+
3232
const ctx: FetchHandlerContext = {
3333
state,
3434
logger,
@@ -39,6 +39,14 @@ export function installFetchWrapper(
3939
}
4040

4141
globalThis.fetch = async (input: any, init?: any) => {
42+
// Skip all DCP processing for subagent sessions
43+
if (state.lastSeenSessionId && state.subagentSessions.has(state.lastSeenSessionId)) {
44+
logger.debug("fetch-wrapper", "Skipping DCP processing for subagent session", {
45+
sessionId: state.lastSeenSessionId.substring(0, 8)
46+
})
47+
return originalGlobalFetch(input, init)
48+
}
49+
4250
if (init?.body && typeof init.body === 'string') {
4351
try {
4452
const body = JSON.parse(init.body)
@@ -74,14 +82,12 @@ export function installFetchWrapper(
7482
init.body = JSON.stringify(body)
7583
}
7684
} catch (e) {
77-
// Silently ignore parsing errors - pass through to original fetch
7885
}
7986
}
8087

8188
return originalGlobalFetch(input, init)
8289
}
8390

84-
// Return cleanup function to restore original fetch
8591
return () => {
8692
globalThis.fetch = originalGlobalFetch
8793
}

lib/hooks.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export function createChatParamsHandler(
7272
providerID = input.message.model.providerID
7373
}
7474

75+
// Track the last seen session ID for fetch wrapper correlation
76+
state.lastSeenSessionId = sessionId
77+
78+
// Check if this is a subagent session
79+
if (!state.checkedSessions.has(sessionId)) {
80+
state.checkedSessions.add(sessionId)
81+
const isSubagent = await isSubagentSession(client, sessionId)
82+
if (isSubagent) {
83+
state.subagentSessions.add(sessionId)
84+
}
85+
}
86+
7587
// Cache model info for the session
7688
if (providerID && modelID) {
7789
state.model.set(sessionId, {

lib/state.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export interface PluginState {
2222
googleToolCallMapping: Map<string, Map<string, string>>
2323
/** Set of session IDs that have been restored from disk */
2424
restoredSessions: Set<string>
25+
/** Set of session IDs we've already checked for subagent status (to avoid redundant API calls) */
26+
checkedSessions: Set<string>
27+
/** Set of session IDs that are subagents (have a parentID) - used to skip fetch wrapper processing */
28+
subagentSessions: Set<string>
29+
/** The most recent session ID seen in chat.params - used to correlate fetch requests */
30+
lastSeenSessionId: string | null
2531
}
2632

2733
export interface ToolParameterEntry {
@@ -45,6 +51,9 @@ export function createPluginState(): PluginState {
4551
model: new Map(),
4652
googleToolCallMapping: new Map(),
4753
restoredSessions: new Set(),
54+
checkedSessions: new Set(),
55+
subagentSessions: new Set(),
56+
lastSeenSessionId: null,
4857
}
4958
}
5059

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "@tarquinen/opencode-dcp",
4-
"version": "0.3.28",
4+
"version": "0.3.29",
55
"type": "module",
66
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
77
"main": "./dist/index.js",

0 commit comments

Comments
 (0)