Skip to content
Closed
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
5 changes: 5 additions & 0 deletions dcp.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
"pattern": "^\\d+(?:\\.\\d+)?%$"
}
]
},
"contextLimitFallback": {
"description": "Fallback token limit when model context window is unknown and percentage-based contextLimit is used (defaults to 100000)",
"type": "number",
"default": 100000
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ToolSettings {
nudgeFrequency: number
protectedTools: string[]
contextLimit: number | `${number}%`
contextLimitFallback?: number
}

export interface Tools {
Expand Down Expand Up @@ -107,6 +108,7 @@ export const VALID_CONFIG_KEYS = new Set([
"tools.settings.nudgeFrequency",
"tools.settings.protectedTools",
"tools.settings.contextLimit",
"tools.settings.contextLimitFallback",
"tools.distill",
"tools.distill.permission",
"tools.distill.showDistillation",
Expand Down Expand Up @@ -303,6 +305,15 @@ function validateConfigTypes(config: Record<string, any>): ValidationError[] {
})
}
}
if (tools.settings.contextLimitFallback !== undefined) {
if (typeof tools.settings.contextLimitFallback !== "number") {
errors.push({
key: "tools.settings.contextLimitFallback",
expected: "number",
actual: typeof tools.settings.contextLimitFallback,
})
}
}
}
if (tools.distill) {
if (tools.distill.permission !== undefined) {
Expand Down Expand Up @@ -684,6 +695,8 @@ function mergeTools(
]),
],
contextLimit: override.settings?.contextLimit ?? base.settings.contextLimit,
contextLimitFallback:
override.settings?.contextLimitFallback ?? base.settings.contextLimitFallback,
},
distill: {
permission: override.distill?.permission ?? base.distill.permission,
Expand Down
5 changes: 4 additions & 1 deletion lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ 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
const contextLimitFallback = config.tools.settings.contextLimitFallback
const DEFAULT_FALLBACK = 100_000 // 100k tokens hardcoded fallback

if (typeof configLimit === "string") {
if (configLimit.endsWith("%")) {
if (state.modelContextLimit === undefined) {
return undefined
const fallback = contextLimitFallback ?? DEFAULT_FALLBACK
return parsePercentageString(configLimit, fallback)
}
return parsePercentageString(configLimit, state.modelContextLimit)
}
Expand Down