MCPcopy Create free account
hub / github.com/Noumena-Network/code / getAutoCompactThreshold

Function getAutoCompactThreshold

src/services/compact/autoCompact.ts:80–99  ·  view source on GitHub ↗
(model: string)

Source from the content-addressed store, hash-verified

78const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3
79
80export 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
101export function calculateTokenWarningState(
102 tokenUsage: number,

Callers 5

runInProcessTeammateFunction · 0.85
shouldAutoCompactFunction · 0.85
autoCompactIfNeededFunction · 0.85

Calls 1

Tested by

no test coverage detected