diff --git a/scripts/hooks/suggest-compact.js b/scripts/hooks/suggest-compact.js index b8a163e9b..dc1a414f0 100644 --- a/scripts/hooks/suggest-compact.js +++ b/scripts/hooks/suggest-compact.js @@ -34,12 +34,11 @@ const { } = require('../lib/utils'); const { readLatestContextTokens, - resolveContextWindowTokens, + resolveContextWindow, resolveContextThreshold, resolveContextInterval, computeContextBucket, - formatWindowLabel, - isContextWindowInferred + formatWindowLabel } = require('../lib/transcript-context'); const COUNTER_FILE_PREFIX = 'claude-tool-count-'; @@ -172,7 +171,7 @@ function buildContextSuggestion(transcriptPath, bucketFile, env) { const usage = readLatestContextTokens(transcriptPath); if (!usage) return null; - const windowTokens = resolveContextWindowTokens(usage.tokens, usage.model); + const { windowTokens, inferred } = resolveContextWindow(usage.tokens, usage.model); const threshold = resolveContextThreshold(env, windowTokens); if (threshold <= 0) return null; // COMPACT_CONTEXT_THRESHOLD=0 disables @@ -189,7 +188,7 @@ function buildContextSuggestion(transcriptPath, bucketFile, env) { // Only quote a percentage when the window size was actually detected. // Against an assumed 200k default the denominator is a guess, and a // "97% of 200k window" line on a 1M session triggers needless compaction. - const scale = isContextWindowInferred(usage.tokens, usage.model) + const scale = inferred ? '' : ` (${Math.round((usage.tokens / windowTokens) * 100)}% of ${formatWindowLabel(windowTokens)} window)`; return `[StrategicCompact] Context ~${approxTokens} tokens${scale} - consider /compact at the next logical boundary`; diff --git a/tests/hooks/suggest-compact.test.js b/tests/hooks/suggest-compact.test.js index 0389f70e5..6036442d3 100644 --- a/tests/hooks/suggest-compact.test.js +++ b/tests/hooks/suggest-compact.test.js @@ -694,7 +694,7 @@ function runTests() { }; } - if (test('suggests compact when context exceeds the 200k-window threshold', () => { + if (test('omits the percentage when the context window is assumed', () => { const ctx = createContextContext(); const transcript = writeTranscriptFixture(170000); try { @@ -704,7 +704,7 @@ function runTests() { const parsed = JSON.parse(result.stdout); const context = parsed.hookSpecificOutput.additionalContext; assert.ok(context.includes('Context ~170k tokens'), `Expected token estimate. Got: ${context}`); - assert.ok(context.includes('85% of 200k window'), `Expected window percentage. Got: ${context}`); + assert.ok(!context.includes('% of'), `Expected no percentage for an assumed window. Got: ${context}`); } finally { try { fs.unlinkSync(transcript); } catch (_err) { /* ignore */ } ctx.cleanup();