qwen-code/docs/users
Zqc 8daeb5b1f9
Some checks are pending
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
feat(core): add configurable auto-compact threshold and Stop hook context usage (#4025) (#5868)
* feat(core): add configurable auto-compact threshold and Stop hook context usage (#4025)

Add two features requested in issue #4025:

1. Configurable auto-compact threshold via settings.json
   - Add context.autoCompactThreshold setting (0-1, default 0.7)
   - Extend computeThresholds(window, pct?) to accept optional pct parameter
   - Wire all 4 call sites (chatCompressionService, geminiChat, contextCommand, useContextualTips)
   - Large windows (>110K) dominated by absolute branch, custom threshold mainly affects small windows

2. Stop hook stdin payload includes context usage data
   - Add ContextUsageData interface and buildContextUsage helper
   - Extend StopInput with context_usage, context_limit, input_tokens fields
   - Wire 3 callers (Session.ts, client.ts, config.ts)
   - Enables hook scripts to observe context usage and suggest compact strategies

* fix(test): add getAutoCompactThreshold mock to geminiChat.test.ts, add NaN guard to buildContextUsage

* fix(review): address round 4 findings — schema constraints, Partial<ContextUsageData>, buildContextUsage validation

* docs: add context.autoCompactThreshold and Stop hook context usage fields documentation

* fix(review): add contextWindowSize fallback, pct clamp, doc accuracy, threshold propagation test

* fix: correct warn value in contextCommand test comment

* test(chatCompressionService): fix misleading pct=1 test name and assertion

* fix(chatCompressionService): prevent negative warn threshold for low pct values

* docs(chatCompressionService): update JSDoc warn formula to include max(0, ...) floor

* test(chatCompressionService): add pct clamping tests and fix NaN handling

Add tests for out-of-range pct values (-0.5, 1.5, NaN) to verify
computeThresholds clamping behavior. Fix implementation to use
Number.isFinite() check so NaN falls back to DEFAULT_PCT instead
of propagating through Math.max(0, NaN) which yields NaN.

* test(config): add MCP Stop dispatch validation tests

Add tests for buildContextUsage runtime validation in MCP Stop dispatch path:
- Valid numeric inputs produce correct ContextUsageData
- Missing/undefined fields return undefined
- String values rejected by Number.isFinite validation
- Negative values return undefined

Also add Number.isFinite check for contextWindowSize in buildContextUsage
to properly validate MCP input types at runtime.

* fix(chatCompressionService): fix TypeScript type narrowing for pct parameter

Use explicit undefined check before Number.isFinite to properly narrow
the number | undefined type in the ternary expression.

---------

Co-authored-by: 俊良 <zzj542558@alibaba-inc.com>
2026-06-28 10:17:57 +00:00
..
configuration feat(core): add configurable auto-compact threshold and Stop hook context usage (#4025) (#5868) 2026-06-28 10:17:57 +00:00
extension fix(core): Align MCP OAuth guidance and docs (#5589) 2026-06-24 07:09:53 +08:00
features feat(core): add configurable auto-compact threshold and Stop hook context usage (#4025) (#5868) 2026-06-28 10:17:57 +00:00
ide-integration update documentation 2025-12-19 18:16:59 +08:00
reference docs(cli): document tmux scroll workaround (#5248) 2026-06-19 02:18:12 +08:00
support docs: add vertex-ai auth, missing commands, and qc-helper index entries (#5727) 2026-06-25 06:58:10 +00:00
_meta.ts feat(daemon): merge daemon-mode feature batch into main (#4490) 2026-06-12 00:34:49 +08:00
common-workflow.md docs: fix stale defaults, CLI syntax, and tool naming drift (#5158) 2026-06-15 20:06:34 +08:00
integration-github-action.md fix(core): Align MCP OAuth guidance and docs (#5589) 2026-06-24 07:09:53 +08:00
integration-jetbrains.md docs(integration): use CDN URLs for images and fix formatting 2026-03-16 14:12:48 +08:00
integration-vscode.md fix: docs 2026-01-14 10:30:03 +08:00
integration-zed.md docs(integration): use CDN URLs for images and fix formatting 2026-03-16 14:12:48 +08:00
overview.md docs: fix config/command/auth drift and surface the model-providers page (#5735) 2026-06-24 06:06:01 +08:00
quickstart.md docs: fix config/command/auth drift and surface the model-providers page (#5735) 2026-06-24 06:06:01 +08:00
qwen-serve-deploy-local.md feat(daemon): merge daemon-mode feature batch into main (#4490) 2026-06-12 00:34:49 +08:00
qwen-serve.md feat(serve): query a single session's status by id (#5857) 2026-06-25 17:14:42 +00:00