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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ DCP uses its own config file:
> "nudgeEnabled": true,
> "nudgeFrequency": 10,
> // Token limit at which the model begins actively
> // compressing session context. Best kept around 40% of
> // compressing session context. Best kept around 40-60% of
> // the model's context window to stay in the "smart zone".
> // Set to "model" to use the model's full context window.
> "contextLimit": 100000,
> // Accepts: number or "X%" (percentage of model's context window)
> "contextLimit": "60%",
> // Additional tools to protect from pruning
> "protectedTools": [],
> },
Expand All @@ -121,8 +121,8 @@ DCP uses its own config file:
> },
> // Collapses a range of conversation content into a single summary
> "compress": {
> // Permission mode: "ask" (prompt), "allow" (no prompt), "deny" (tool not registered)
> "permission": "ask",
> // Permission mode: "deny" (tool not registered), "ask" (prompt), "allow" (no prompt)
> "permission": "deny",
> // Show summary content as an ignored message notification
> "showCompression": false,
> },
Expand Down
6 changes: 3 additions & 3 deletions dcp.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@
"description": "Tool names that should be protected from automatic pruning"
},
"contextLimit": {
"description": "When session tokens exceed this limit, a compress nudge is injected (\"model\" uses the active model's context limit)",
"default": 100000,
"description": "When session tokens exceed this limit, a compress nudge is injected (\"X%\" uses percentage of the model's context window)",
"default": "60%",
"oneOf": [
{
"type": "number"
},
{
"type": "string",
"enum": ["model"]
"pattern": "^\\d+(?:\\.\\d+)?%$"
}
]
}
Expand Down
18 changes: 10 additions & 8 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ToolSettings {
nudgeEnabled: boolean
nudgeFrequency: number
protectedTools: string[]
contextLimit: number | "model"
contextLimit: number | `${number}%`
}

export interface Tools {
Expand Down Expand Up @@ -290,13 +290,15 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
})
}
if (tools.settings.contextLimit !== undefined) {
if (
typeof tools.settings.contextLimit !== "number" &&
tools.settings.contextLimit !== "model"
) {
const isValidNumber = typeof tools.settings.contextLimit === "number"
const isPercentString =
typeof tools.settings.contextLimit === "string" &&
tools.settings.contextLimit.endsWith("%")

if (!isValidNumber && !isPercentString) {
errors.push({
key: "tools.settings.contextLimit",
expected: 'number | "model"',
expected: 'number | "${number}%"',
actual: JSON.stringify(tools.settings.contextLimit),
})
}
Expand Down Expand Up @@ -502,14 +504,14 @@ const defaultConfig: PluginConfig = {
nudgeEnabled: true,
nudgeFrequency: 10,
protectedTools: [...DEFAULT_PROTECTED_TOOLS],
contextLimit: 100000,
contextLimit: "60%",
},
distill: {
permission: "allow",
showDistillation: false,
},
compress: {
permission: "ask",
permission: "deny",
showCompression: false,
},
prune: {
Expand Down
27 changes: 25 additions & 2 deletions lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ import { getFilePathsFromParameters, isProtected } from "../protected-file-patte
import { getLastUserMessage, isMessageCompacted } from "../shared-utils"
import { getCurrentTokenUsage } from "../strategies/utils"

function parsePercentageString(value: string, total: number): number | undefined {
if (!value.endsWith("%")) return undefined
const percent = parseFloat(value.slice(0, -1))

if (isNaN(percent)) {
return undefined
}

const roundedPercent = Math.round(percent)
const clampedPercent = Math.max(0, Math.min(100, roundedPercent))

return Math.round((clampedPercent / 100) * total)
}

// XML wrappers
export const wrapPrunableTools = (content: string): string => {
return `<prunable-tools>
Expand Down Expand Up @@ -54,9 +68,18 @@ Context management was just performed. Do NOT use the ${toolName} again. A fresh

const resolveContextLimit = (config: PluginConfig, state: SessionState): number | undefined => {
const configLimit = config.tools.settings.contextLimit
if (configLimit === "model") {
return state.modelContextLimit

if (typeof configLimit === "string") {
if (configLimit.endsWith("%")) {
if (state.modelContextLimit === undefined) {
return undefined
}
return parsePercentageString(configLimit, state.modelContextLimit)
}

return undefined
}

return configLimit
}

Expand Down
2 changes: 1 addition & 1 deletion lib/prompts/prune.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ THE PRUNABLE TOOLS LIST
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.

THE WAYS OF PRUNE
`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.
`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.

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

Expand Down