Skip to content

Commit 4cc05c6

Browse files
authored
Merge pull request #133 from Opencode-DCP/fix/nudge-counter-reset
fix: properly reset nudge counter after prune tool is used
2 parents 5ae736d + b323912 commit 4cc05c6

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

lib/state/tool-cache.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SessionState, ToolStatus, WithParts } from "./index"
22
import type { Logger } from "../logger"
33
import { PluginConfig } from "../config"
44

5-
const MAX_TOOL_CACHE_SIZE = 500
5+
const MAX_TOOL_CACHE_SIZE = 1000
66

77
/**
88
* Sync tool parameters from OpenCode's session.messages() API.
@@ -16,13 +16,24 @@ export async function syncToolCache(
1616
try {
1717
logger.info("Syncing tool parameters from OpenCode messages")
1818

19+
state.nudgeCounter = 0
20+
1921
for (const msg of messages) {
2022
for (const part of msg.parts) {
21-
if (part.type !== "tool" || !part.callID || state.toolParameters.has(part.callID)) {
23+
if (part.type !== "tool" || !part.callID) {
2224
continue
2325
}
2426

25-
const alreadyPruned = state.prune.toolIds.includes(part.callID)
27+
if (part.tool === "prune") {
28+
state.nudgeCounter = 0
29+
} else if (!config.strategies.pruneTool.protectedTools.includes(part.tool)) {
30+
state.nudgeCounter++
31+
}
32+
state.lastToolPrune = part.tool === "prune"
33+
34+
if (state.toolParameters.has(part.callID)) {
35+
continue
36+
}
2637

2738
state.toolParameters.set(
2839
part.callID,
@@ -34,16 +45,11 @@ export async function syncToolCache(
3445
compacted: part.state.status === "completed" && !!part.state.time.compacted,
3546
}
3647
)
37-
38-
if (!alreadyPruned && !config.strategies.pruneTool.protectedTools.includes(part.tool)) {
39-
state.nudgeCounter++
40-
}
41-
42-
state.lastToolPrune = part.tool === "prune"
43-
logger.info("lastToolPrune=" + String(state.lastToolPrune))
4448
}
4549
}
4650

51+
// logger.info(`nudgeCounter=${state.nudgeCounter}, lastToolPrune=${state.lastToolPrune}`)
52+
4753
trimToolParametersCache(state)
4854
} catch (error) {
4955
logger.warn("Failed to sync tool parameters from OpenCode", {

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.4.17",
4+
"version": "1.0.0-beta.1",
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)