Skip to content

Commit 12331c6

Browse files
authored
Merge pull request #110 from spoons-and-mirrors/feat/add-prune-to-primary-tools
Feat/add-prune-to-primary-tools
2 parents c2a05b5 + 1d2809e commit 12331c6

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ Add to your OpenCode config:
1313
```jsonc
1414
// opencode.jsonc
1515
{
16-
"plugin": ["@tarquinen/opencode-dcp@latest"],
17-
"experimental": {
18-
"primary_tools": ["prune"]
19-
}
16+
"plugin": ["@tarquinen/opencode-dcp@latest"]
2017
}
2118
```
2219

23-
The `experimental.primary_tools` setting ensures the `prune` tool is only available to the primary agent (not subagents).
24-
2520
Using `@latest` ensures you always get the newest version automatically when OpenCode starts.
2621

2722
Restart OpenCode. The plugin will automatically start optimizing your sessions.

index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ const plugin: Plugin = (async (ctx) => {
7575
}
7676

7777
return {
78+
config: async (opencodeConfig) => {
79+
// Add prune to primary_tools by mutating the opencode config
80+
// This works because config is cached and passed by reference
81+
if (config.strategies.onTool.length > 0) {
82+
const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? []
83+
opencodeConfig.experimental = {
84+
...opencodeConfig.experimental,
85+
primary_tools: [...existingPrimaryTools, "prune"],
86+
}
87+
logger.info("plugin", "Added 'prune' to experimental.primary_tools via config mutation")
88+
}
89+
},
7890
event: createEventHandler(ctx.client, janitorCtx, logger, config, toolTracker),
7991
"chat.params": createChatParamsHandler(ctx.client, state, logger, toolTracker),
8092
tool: config.strategies.onTool.length > 0 ? {

lib/pruning-tool.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { PluginConfig } from "./config"
44
import type { ToolTracker } from "./fetch-wrapper/tool-tracker"
55
import type { ToolMetadata, PruneReason } from "./fetch-wrapper/types"
66
import { resetToolTrackerCount } from "./fetch-wrapper/tool-tracker"
7-
import { isSubagentSession, findCurrentAgent } from "./hooks"
7+
import { findCurrentAgent } from "./hooks"
88
import { getActualId } from "./state/id-mapping"
99
import { sendUnifiedNotification, type NotificationContext } from "./ui/notification"
1010
import { formatPruningResultForTool } from "./ui/display-utils"
@@ -51,10 +51,6 @@ export function createPruningTool(
5151
const { client, state, logger, config, notificationCtx } = ctx
5252
const sessionId = toolCtx.sessionID
5353

54-
if (await isSubagentSession(client, sessionId)) {
55-
return "Pruning is unavailable in subagent sessions. Do not call this tool again. Continue with your current task - if you were in the middle of work, proceed with your next step. If you had just finished, provide your final summary/findings to return to the main agent."
56-
}
57-
5854
if (!args.ids || args.ids.length === 0) {
5955
return "No IDs provided. Check the <prunable-tools> list for available IDs to prune."
6056
}

package-lock.json

Lines changed: 8 additions & 8 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
@@ -47,7 +47,7 @@
4747
"zod": "^4.1.13"
4848
},
4949
"devDependencies": {
50-
"@opencode-ai/plugin": ">=0.13.7",
50+
"@opencode-ai/plugin": "^1.0.143",
5151
"@types/node": "^24.10.1",
5252
"tsx": "^4.21.0",
5353
"typescript": "^5.9.3"

0 commit comments

Comments
 (0)