Skip to content

Commit 520370c

Browse files
committed
Refactor protectedTurns to turnProtection with enabled/turns options
Renames the flat protectedTurns config to a nested turnProtection object matching the structure of nudge. Now has: - enabled: boolean to toggle the feature - turns: number of turns to protect tools after use
1 parent 5419c04 commit 520370c

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ DCP uses its own config file:
7777
"enabled": true,
7878
// Additional tools to protect from pruning
7979
"protectedTools": [],
80-
// Protect tools from pruning for N turns after they are called (0 = disabled)
81-
"protectedTurns": 4,
80+
// Protect tools from pruning for N turns after they are called
81+
"turnProtection": {
82+
"enabled": false,
83+
"turns": 4
84+
},
8285
// Nudge the LLM to use the prune tool (every <frequency> tool results)
8386
"nudge": {
8487
"enabled": true,

lib/config.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ export interface PruneToolNudge {
2222
frequency: number
2323
}
2424

25+
export interface PruneToolTurnProtection {
26+
enabled: boolean
27+
turns: number
28+
}
29+
2530
export interface PruneTool {
2631
enabled: boolean
2732
protectedTools: string[]
28-
protectedTurns: number
33+
turnProtection: PruneToolTurnProtection
2934
nudge: PruneToolNudge
3035
}
3136

@@ -73,7 +78,9 @@ export const VALID_CONFIG_KEYS = new Set([
7378
'strategies.pruneTool',
7479
'strategies.pruneTool.enabled',
7580
'strategies.pruneTool.protectedTools',
76-
'strategies.pruneTool.protectedTurns',
81+
'strategies.pruneTool.turnProtection',
82+
'strategies.pruneTool.turnProtection.enabled',
83+
'strategies.pruneTool.turnProtection.turns',
7784
'strategies.pruneTool.nudge',
7885
'strategies.pruneTool.nudge.enabled',
7986
'strategies.pruneTool.nudge.frequency'
@@ -160,8 +167,13 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
160167
if (strategies.pruneTool.protectedTools !== undefined && !Array.isArray(strategies.pruneTool.protectedTools)) {
161168
errors.push({ key: 'strategies.pruneTool.protectedTools', expected: 'string[]', actual: typeof strategies.pruneTool.protectedTools })
162169
}
163-
if (strategies.pruneTool.protectedTurns !== undefined && typeof strategies.pruneTool.protectedTurns !== 'number') {
164-
errors.push({ key: 'strategies.pruneTool.protectedTurns', expected: 'number', actual: typeof strategies.pruneTool.protectedTurns })
170+
if (strategies.pruneTool.turnProtection) {
171+
if (strategies.pruneTool.turnProtection.enabled !== undefined && typeof strategies.pruneTool.turnProtection.enabled !== 'boolean') {
172+
errors.push({ key: 'strategies.pruneTool.turnProtection.enabled', expected: 'boolean', actual: typeof strategies.pruneTool.turnProtection.enabled })
173+
}
174+
if (strategies.pruneTool.turnProtection.turns !== undefined && typeof strategies.pruneTool.turnProtection.turns !== 'number') {
175+
errors.push({ key: 'strategies.pruneTool.turnProtection.turns', expected: 'number', actual: typeof strategies.pruneTool.turnProtection.turns })
176+
}
165177
}
166178
if (strategies.pruneTool.nudge) {
167179
if (strategies.pruneTool.nudge.enabled !== undefined && typeof strategies.pruneTool.nudge.enabled !== 'boolean') {
@@ -245,7 +257,10 @@ const defaultConfig: PluginConfig = {
245257
pruneTool: {
246258
enabled: true,
247259
protectedTools: [...DEFAULT_PROTECTED_TOOLS],
248-
protectedTurns: 4,
260+
turnProtection: {
261+
enabled: false,
262+
turns: 4
263+
},
249264
nudge: {
250265
enabled: true,
251266
frequency: 10
@@ -343,14 +358,17 @@ function createDefaultConfig(): void {
343358
"enabled": true
344359
},
345360
// Exposes a prune tool to your LLM to call when it determines pruning is necessary
346-
"pruneTool": {
347-
"enabled": true,
361+
\"pruneTool\": {
362+
\"enabled\": true,
348363
// Additional tools to protect from pruning
349-
"protectedTools": [],
350-
// Protect tools from pruning for N turns after they are called (0 = disabled)
351-
"protectedTurns": 4,
364+
\"protectedTools\": [],
365+
// Protect tools from pruning for N turns after they are called
366+
\"turnProtection\": {
367+
\"enabled\": false,
368+
\"turns\": 4
369+
},
352370
// Nudge the LLM to use the prune tool (every <frequency> tool results)
353-
"nudge": {
371+
\"nudge\": {
354372
"enabled": true,
355373
"frequency": 10
356374
}
@@ -434,7 +452,10 @@ function mergeStrategies(
434452
...(override.pruneTool?.protectedTools ?? [])
435453
])
436454
],
437-
protectedTurns: override.pruneTool?.protectedTurns ?? base.pruneTool.protectedTurns,
455+
turnProtection: {
456+
enabled: override.pruneTool?.turnProtection?.enabled ?? base.pruneTool.turnProtection.enabled,
457+
turns: override.pruneTool?.turnProtection?.turns ?? base.pruneTool.turnProtection.turns
458+
},
438459
nudge: {
439460
enabled: override.pruneTool?.nudge?.enabled ?? base.pruneTool.nudge.enabled,
440461
frequency: override.pruneTool?.nudge?.frequency ?? base.pruneTool.nudge.frequency
@@ -461,7 +482,7 @@ function deepCloneConfig(config: PluginConfig): PluginConfig {
461482
pruneTool: {
462483
...config.strategies.pruneTool,
463484
protectedTools: [...config.strategies.pruneTool.protectedTools],
464-
protectedTurns: config.strategies.pruneTool.protectedTurns,
485+
turnProtection: { ...config.strategies.pruneTool.turnProtection },
465486
nudge: { ...config.strategies.pruneTool.nudge }
466487
},
467488
supersedeWrites: {

lib/state/tool-cache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export async function syncToolCache(
3535
continue
3636
}
3737

38-
const isProtectedByTurn = config.strategies.pruneTool.protectedTurns > 0 &&
39-
(state.currentTurn - turnCounter) < config.strategies.pruneTool.protectedTurns
38+
const isProtectedByTurn = config.strategies.pruneTool.turnProtection.enabled &&
39+
config.strategies.pruneTool.turnProtection.turns > 0 &&
40+
(state.currentTurn - turnCounter) < config.strategies.pruneTool.turnProtection.turns
4041

4142
state.lastToolPrune = part.tool === "prune"
4243

0 commit comments

Comments
 (0)