diff --git a/README.md b/README.md index eef2f56f..6460527d 100644 --- a/README.md +++ b/README.md @@ -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": [], > }, @@ -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, > }, diff --git a/dcp.schema.json b/dcp.schema.json index 28019dd0..e25f09b1 100644 --- a/dcp.schema.json +++ b/dcp.schema.json @@ -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+)?%$" } ] } diff --git a/lib/config.ts b/lib/config.ts index e2e6da61..1a60307f 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -27,7 +27,7 @@ export interface ToolSettings { nudgeEnabled: boolean nudgeFrequency: number protectedTools: string[] - contextLimit: number | "model" + contextLimit: number | `${number}%` } export interface Tools { @@ -290,13 +290,15 @@ function validateConfigTypes(config: Record): 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), }) } @@ -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: { diff --git a/lib/messages/inject.ts b/lib/messages/inject.ts index f1b56025..3f0c60b1 100644 --- a/lib/messages/inject.ts +++ b/lib/messages/inject.ts @@ -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 ` @@ -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 } diff --git a/lib/prompts/prune.md b/lib/prompts/prune.md index be18b009..97c239f4 100644 --- a/lib/prompts/prune.md +++ b/lib/prompts/prune.md @@ -4,7 +4,7 @@ THE PRUNABLE TOOLS LIST A `` 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.