You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feat: Add Context Level Selection and Configurable Token Limits #342
Description
We need to restore the ability for users to select the context size used for planning (Minimal, Balanced, Max).
Currently, token limits are hardcoded constants (e.g., 100k or 150k), but models have varying capacities (200k for standard Anthropic, up to 1M for some tiers).
Requirements
Model Limits Configuration: Create a central configuration to define context limits for different model IDs.
Context Level Option: Add a 'contextLevel' field to the 'TaskDraftConfig'.
'minimal': Uses a small portion of the context (e.g., 10%).
'balanced': Uses a moderate portion (e.g., 30-40% or fixed ~50k).
'max': Uses the full model capacity minus a safety buffer (e.g., 95% of limit).
Dynamic Limit Calculation: Update 'taskPlanningService.ts' to calculate the 'tokenLimit' passed to 'generateContext' based on the selected level and the specific model's limit.
Backend Integration: Ensure 'generatePlan' and 'generateContextPreview' use these dynamic values instead of hardcoded constants.
Note: Do not confuse this with 'Granularity' (which controls how tasks are split). This controls how much code is read into the prompt.
exporttypeContextLevel='minimal'|'balanced'|'max';exportconstMODEL_LIMITS: Record<string,number>={'default': 200000,// Map specific model IDs to their context window'claude-3-5-sonnet-20240620': 200000,'claude-3-opus-20240229': 200000,// Add other models as needed};exportconstCONTEXT_RATIOS: Record<ContextLevel,number>={minimal: 0.1,// 10% of contextbalanced: 0.50,// 50% of contextmax: 0.95// 95% (leaving 5% breathing room)};exportfunctiongetEffectiveTokenLimit(modelId: string|undefined,level: ContextLevel): number{constlimit=MODEL_LIMITS[modelId||'default']||MODEL_LIMITS['default'];returnMath.floor(limit*CONTEXT_RATIOS[level]);}
Then, update the planning service to use these configurations:
packages/core/src/services/taskPlanningService.ts
import{getEffectiveTokenLimit,ContextLevel}from'../config/modelLimits.js';// ... imports// Update interfaceexportinterfaceTaskDraftConfig{baseBranch: string;granularity: 'single'|'balanced'|'granular';contextLevel: ContextLevel;// New fieldmanualFiles: string[];autoFiles: string[];}// In generatePlan functionexportasyncfunctiongeneratePlan(options: GeneratePlanOptions): Promise<Plan>{// ... existing setupconstcontextConfig=draft.context_configasTaskDraftConfig|null;constcontextLevel=contextConfig?.contextLevel||'balanced';// TODO: Get actual model ID from config or draft if available, currently defaultingconsttokenLimit=getEffectiveTokenLimit('claude-3-5-sonnet-20240620',contextLevel);// ... checkout branch logicconstcontextResult=awaitgenerateContext({repoPath: worktreePath,filesToInclude: relevantFilePaths.length>0 ? relevantFilePaths : undefined,
tokenLimit,// Use dynamic limit
correlationId
});// ... rest of function}// Update generateContextPreview similarlyexportasyncfunctiongenerateContextPreview(options: GenerateContextPreviewOptions): Promise<PreviewResult>{// ... setup// Extract contextLevel if it is passed in options (you might need to update GenerateContextPreviewOptions interface too)constcontextLevel='balanced';// Default or from optionsconsttokenLimit=getEffectiveTokenLimit('claude-3-5-sonnet-20240620',contextLevel);// ... constcontextResult=awaitgenerateContext({repoPath: worktreePath,filesToInclude: combinedFiles.length>0 ? combinedFiles : undefined,
tokenLimit,
correlationId
});// ... rest of function}
Activity
integry commentedon Dec 10, 2025
Here is the suggested implementation plan.
First, create a new config file for model limits:
packages/core/src/config/modelLimits.ts
Then, update the planning service to use these configurations:
packages/core/src/services/taskPlanningService.ts
propr-dev commentedon Dec 10, 2025
🤖 AI processing has started for this issue using claude-opus-4-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claude-opus-4-5ai-fix/342-feat-add-context-level-se-20251210-1919-claude-opus-4-5-e0umainissue-342-20251210-1919-claude-opus-4-5-e0ufix(ai): Resolve issue #342 - Feat: Add Context Level Selection and C…
Merge pull request #345 from integry/ai-fix/342-feat-add-context-leve…