-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(core): add configurable auto-compact threshold and Stop hook context usage (#4025) #5868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wenshao
merged 12 commits into
QwenLM:main
from
ZijianZhang989:feat/configurable-compact-threshold
Jun 28, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5ff13d
feat(core): add configurable auto-compact threshold and Stop hook con…
4fa164b
fix(test): add getAutoCompactThreshold mock to geminiChat.test.ts, ad…
6122695
fix(review): address round 4 findings — schema constraints, Partial<C…
e5a2bbf
docs: add context.autoCompactThreshold and Stop hook context usage fi…
b15b234
fix(review): add contextWindowSize fallback, pct clamp, doc accuracy,…
7234694
fix: correct warn value in contextCommand test comment
c047c9a
test(chatCompressionService): fix misleading pct=1 test name and asse…
b66a713
fix(chatCompressionService): prevent negative warn threshold for low …
4e58826
docs(chatCompressionService): update JSDoc warn formula to include ma…
ec99962
test(chatCompressionService): add pct clamping tests and fix NaN hand…
762f5d9
test(config): add MCP Stop dispatch validation tests
e75ada9
fix(chatCompressionService): fix TypeScript type narrowing for pct pa…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { buildContextUsage } from './context-usage.js'; | ||
|
|
||
| describe('buildContextUsage', () => { | ||
| it('returns context usage data when both values are valid', () => { | ||
| const result = buildContextUsage(200_000, 140_000); | ||
| expect(result).toEqual({ | ||
| context_usage: 0.7, | ||
| context_limit: 200_000, | ||
| input_tokens: 140_000, | ||
| }); | ||
| }); | ||
|
|
||
| it('returns undefined when contextWindowSize is undefined', () => { | ||
| expect(buildContextUsage(undefined, 140_000)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when contextWindowSize is 0', () => { | ||
| expect(buildContextUsage(0, 140_000)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when inputTokens is 0', () => { | ||
| expect(buildContextUsage(200_000, 0)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when inputTokens is negative', () => { | ||
| expect(buildContextUsage(200_000, -5)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when inputTokens is NaN', () => { | ||
| expect(buildContextUsage(200_000, NaN)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when contextWindowSize is negative', () => { | ||
| expect(buildContextUsage(-1, 140_000)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('handles ratio > 1 (tokens exceed window)', () => { | ||
| const result = buildContextUsage(100_000, 120_000); | ||
| expect(result?.context_usage).toBe(1.2); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { ContextUsageData } from './types.js'; | ||
|
|
||
| export function buildContextUsage( | ||
| contextWindowSize: number | undefined, | ||
| inputTokens: number, | ||
| ): ContextUsageData | undefined { | ||
| if ( | ||
| !contextWindowSize || | ||
| !Number.isFinite(contextWindowSize) || | ||
| contextWindowSize <= 0 || | ||
| !Number.isFinite(inputTokens) || | ||
| inputTokens <= 0 | ||
| ) { | ||
| return undefined; | ||
| } | ||
| return { | ||
| context_usage: inputTokens / contextWindowSize, | ||
| context_limit: contextWindowSize, | ||
| input_tokens: inputTokens, | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.