(model: string)
| 99 | const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3 |
| 100 | |
| 101 | export function getAutoCompactThreshold(model: string): number { |
| 102 | const effectiveContextWindow = getEffectiveContextWindowSize(model) |
| 103 | |
| 104 | const autocompactThreshold = |
| 105 | effectiveContextWindow - getAutocompactBufferTokens(model) |
| 106 | |
| 107 | // Override for easier testing of autocompact |
| 108 | const envPercent = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
| 109 | if (envPercent) { |
| 110 | const parsed = parseFloat(envPercent) |
| 111 | if (!isNaN(parsed) && parsed > 0 && parsed <= 100) { |
| 112 | const percentageThreshold = Math.floor( |
| 113 | effectiveContextWindow * (parsed / 100), |
| 114 | ) |
| 115 | return Math.min(percentageThreshold, autocompactThreshold) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return autocompactThreshold |
| 120 | } |
| 121 | |
| 122 | export function calculateTokenWarningState( |
| 123 | tokenUsage: number, |
no test coverage detected