Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ Add to your OpenCode config:
```jsonc
// opencode.jsonc
{
"plugin": ["@tarquinen/opencode-dcp@latest"],
"experimental": {
"primary_tools": ["prune"]
}
"plugin": ["@tarquinen/opencode-dcp@latest"]
}
```

The `experimental.primary_tools` setting ensures the `prune` tool is only available to the primary agent (not subagents).

Using `@latest` ensures you always get the newest version automatically when OpenCode starts.

Restart OpenCode. The plugin will automatically start optimizing your sessions.
Expand Down
12 changes: 12 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ const plugin: Plugin = (async (ctx) => {
}

return {
config: async (opencodeConfig) => {
// Add prune to primary_tools by mutating the opencode config
// This works because config is cached and passed by reference
if (config.strategies.onTool.length > 0) {
const existingPrimaryTools = opencodeConfig.experimental?.primary_tools ?? []
opencodeConfig.experimental = {
...opencodeConfig.experimental,
primary_tools: [...existingPrimaryTools, "prune"],
}
logger.info("plugin", "Added 'prune' to experimental.primary_tools via config mutation")
}
},
event: createEventHandler(ctx.client, janitorCtx, logger, config, toolTracker),
"chat.params": createChatParamsHandler(ctx.client, state, logger, toolTracker),
tool: config.strategies.onTool.length > 0 ? {
Expand Down
6 changes: 1 addition & 5 deletions lib/pruning-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PluginConfig } from "./config"
import type { ToolTracker } from "./fetch-wrapper/tool-tracker"
import type { ToolMetadata, PruneReason } from "./fetch-wrapper/types"
import { resetToolTrackerCount } from "./fetch-wrapper/tool-tracker"
import { isSubagentSession, findCurrentAgent } from "./hooks"
import { findCurrentAgent } from "./hooks"
import { getActualId } from "./state/id-mapping"
import { sendUnifiedNotification, type NotificationContext } from "./ui/notification"
import { formatPruningResultForTool } from "./ui/display-utils"
Expand Down Expand Up @@ -51,10 +51,6 @@ export function createPruningTool(
const { client, state, logger, config, notificationCtx } = ctx
const sessionId = toolCtx.sessionID

if (await isSubagentSession(client, sessionId)) {
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."
}

if (!args.ids || args.ids.length === 0) {
return "No IDs provided. Check the <prunable-tools> list for available IDs to prune."
}
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"zod": "^4.1.13"
},
"devDependencies": {
"@opencode-ai/plugin": ">=0.13.7",
"@opencode-ai/plugin": "^1.0.143",
"@types/node": "^24.10.1",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
Expand Down