(model: string)
| 78 | const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3 |
| 79 | |
| 80 | export function getAutoCompactThreshold(model: string): number { |
| 81 | const effectiveContextWindow = getEffectiveContextWindowSize(model) |
| 82 | |
| 83 | const autocompactThreshold = |
| 84 | effectiveContextWindow - AUTOCOMPACT_BUFFER_TOKENS |
| 85 | |
| 86 | // Override for easier testing of autocompact |
| 87 | const envPercent = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
| 88 | if (envPercent) { |
| 89 | const parsed = parseFloat(envPercent) |
| 90 | if (!isNaN(parsed) && parsed > 0 && parsed <= 100) { |
| 91 | const percentageThreshold = Math.floor( |
| 92 | effectiveContextWindow * (parsed / 100), |
| 93 | ) |
| 94 | return Math.min(percentageThreshold, autocompactThreshold) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return autocompactThreshold |
| 99 | } |
| 100 | |
| 101 | export function calculateTokenWarningState( |
| 102 | tokenUsage: number, |
no test coverage detected