Skip to content

Commit 618f52c

Browse files
authored
Merge pull request #356 from Opencode-DCP/dev
merge dev into master
2 parents 12a422b + 451fc76 commit 618f52c

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ DCP uses its own config file:
105105
> "nudgeEnabled": true,
106106
> "nudgeFrequency": 10,
107107
> // Token limit at which the model begins actively
108-
> // compressing session context. Best kept around 40% of
108+
> // compressing session context. Best kept around 40-60% of
109109
> // the model's context window to stay in the "smart zone".
110-
> // Set to "model" to use the model's full context window.
111-
> "contextLimit": 100000,
110+
> // Accepts: number or "X%" (percentage of model's context window)
111+
> "contextLimit": "60%",
112112
> // Additional tools to protect from pruning
113113
> "protectedTools": [],
114114
> },
@@ -121,8 +121,8 @@ DCP uses its own config file:
121121
> },
122122
> // Collapses a range of conversation content into a single summary
123123
> "compress": {
124-
> // Permission mode: "ask" (prompt), "allow" (no prompt), "deny" (tool not registered)
125-
> "permission": "ask",
124+
> // Permission mode: "deny" (tool not registered), "ask" (prompt), "allow" (no prompt)
125+
> "permission": "deny",
126126
> // Show summary content as an ignored message notification
127127
> "showCompression": false,
128128
> },

dcp.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@
110110
"description": "Tool names that should be protected from automatic pruning"
111111
},
112112
"contextLimit": {
113-
"description": "When session tokens exceed this limit, a compress nudge is injected (\"model\" uses the active model's context limit)",
114-
"default": 100000,
113+
"description": "When session tokens exceed this limit, a compress nudge is injected (\"X%\" uses percentage of the model's context window)",
114+
"default": "60%",
115115
"oneOf": [
116116
{
117117
"type": "number"
118118
},
119119
{
120120
"type": "string",
121-
"enum": ["model"]
121+
"pattern": "^\\d+(?:\\.\\d+)?%$"
122122
}
123123
]
124124
}

lib/config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface ToolSettings {
2727
nudgeEnabled: boolean
2828
nudgeFrequency: number
2929
protectedTools: string[]
30-
contextLimit: number | "model"
30+
contextLimit: number | `${number}%`
3131
}
3232

3333
export interface Tools {
@@ -290,13 +290,15 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
290290
})
291291
}
292292
if (tools.settings.contextLimit !== undefined) {
293-
if (
294-
typeof tools.settings.contextLimit !== "number" &&
295-
tools.settings.contextLimit !== "model"
296-
) {
293+
const isValidNumber = typeof tools.settings.contextLimit === "number"
294+
const isPercentString =
295+
typeof tools.settings.contextLimit === "string" &&
296+
tools.settings.contextLimit.endsWith("%")
297+
298+
if (!isValidNumber && !isPercentString) {
297299
errors.push({
298300
key: "tools.settings.contextLimit",
299-
expected: 'number | "model"',
301+
expected: 'number | "${number}%"',
300302
actual: JSON.stringify(tools.settings.contextLimit),
301303
})
302304
}
@@ -502,14 +504,14 @@ const defaultConfig: PluginConfig = {
502504
nudgeEnabled: true,
503505
nudgeFrequency: 10,
504506
protectedTools: [...DEFAULT_PROTECTED_TOOLS],
505-
contextLimit: 100000,
507+
contextLimit: "60%",
506508
},
507509
distill: {
508510
permission: "allow",
509511
showDistillation: false,
510512
},
511513
compress: {
512-
permission: "ask",
514+
permission: "deny",
513515
showCompression: false,
514516
},
515517
prune: {

lib/messages/inject.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ import { getFilePathsFromParameters, isProtected } from "../protected-file-patte
1313
import { getLastUserMessage, isMessageCompacted } from "../shared-utils"
1414
import { getCurrentTokenUsage } from "../strategies/utils"
1515

16+
function parsePercentageString(value: string, total: number): number | undefined {
17+
if (!value.endsWith("%")) return undefined
18+
const percent = parseFloat(value.slice(0, -1))
19+
20+
if (isNaN(percent)) {
21+
return undefined
22+
}
23+
24+
const roundedPercent = Math.round(percent)
25+
const clampedPercent = Math.max(0, Math.min(100, roundedPercent))
26+
27+
return Math.round((clampedPercent / 100) * total)
28+
}
29+
1630
// XML wrappers
1731
export const wrapPrunableTools = (content: string): string => {
1832
return `<prunable-tools>
@@ -54,9 +68,18 @@ Context management was just performed. Do NOT use the ${toolName} again. A fresh
5468

5569
const resolveContextLimit = (config: PluginConfig, state: SessionState): number | undefined => {
5670
const configLimit = config.tools.settings.contextLimit
57-
if (configLimit === "model") {
58-
return state.modelContextLimit
71+
72+
if (typeof configLimit === "string") {
73+
if (configLimit.endsWith("%")) {
74+
if (state.modelContextLimit === undefined) {
75+
return undefined
76+
}
77+
return parsePercentageString(configLimit, state.modelContextLimit)
78+
}
79+
80+
return undefined
5981
}
82+
6083
return configLimit
6184
}
6285

lib/prompts/prune.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ THE PRUNABLE TOOLS LIST
44
A `<prunable-tools>` section surfaces in context showing outputs eligible for removal. Each line reads `ID: tool, parameter (~token usage)` (e.g., `20: read, /path/to/file.ts (~1500 tokens)`). Reference outputs by their numeric ID - these are your ONLY valid targets for pruning.
55

66
THE WAYS OF PRUNE
7-
`prune` is surgical excision - eliminating noise (irrelevant or unhelpful outputs), superseded information (older outputs replaced by newer data), or wrong targets (you accessed something that turned out to be irrelevant). Use it to keep your context lean and focused.
7+
`prune` is surgical deletion - eliminating noise (irrelevant or unhelpful outputs), superseded information (older outputs replaced by newer data), or wrong targets (you accessed something that turned out to be irrelevant). Use it to keep your context lean and focused.
88

99
BATCH WISELY! Pruning is most effective when consolidated. Don't prune a single tiny output - accumulate several candidates before acting.
1010

0 commit comments

Comments
 (0)