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