Repository navigation
feat(desktop): 输入框上下文用量胶囊 + 逐对话压缩阈值面板 / context usage chip and per-chat compaction threshold - #62
Merged
sqfcyily merged 1 commit intoNov 17, 2026
Conversation
…at compaction threshold 在输入框工具条模型贴片左侧加一枚胶囊,显示本对话的窗口占用与上一轮提示缓存 命中率;点开可拖动自动压缩的触发比例并查看压缩记录。用量走压缩判定的同一套 口径,故显示的百分比就是压缩的实际依据。 - 主进程新增 chat:context-usage / chat:set-compact-ratio 两个 IPC,与压缩判定共用 contextWindowFor / triggerTokens,避免界面与引擎两套口径各算各的。 - 会话新增 compactRatio / compactLog / lastPromptParts 三个字段(纯观测,不参与判定; 旧版读到未知键会忽略,不影响兼容)。 - 压缩发生的那一刻就推一次用量快照(轮前与轮中两处),否则长回合要跑十几分钟, 胶囊和面板会一直停在压缩前的读数上,表现为「明明已压缩却显示还没压过」。 - 两个百分比分母不同,故胶囊只显示窗口占用(分母=生效窗口),压缩线进度放进悬停 提示并决定转红:越过压缩线就红,避免和滑块读数重复。 - 提示词构成(系统提示词 / 工具定义 / 对话消息)取本地字符估算,再按「真实总量 / 估算总量」等比缩放展示,三项之和恒等于真实总量。 参考来源(取舍依据,非代码照搬): - DSH 插件 dsh-compaction-threshold(MIT,npm):阈值滑块写 thresholdRatio、滑块范围 20%–95%、压缩记录「压后」读数延后到下一次 usage 回报才定稿。 - 触发线算式(窗口 − 输出上限 − 余量)对齐 Claude Code;保留尾部上限参照 Codex 与 OpenCode(见 compaction.ts 内注释)。 --- Add a context-usage chip to the left of the model picker in the composer toolbar, showing window usage and the last turn's prompt-cache hit rate. Clicking it opens a panel with a drag-to-set auto-compaction threshold slider and the chat's compaction log. Usage shares the exact same calculation as the compaction trigger, so the displayed percentage is what the engine actually acts on. - New IPC channels chat:context-usage / chat:set-compact-ratio reusing contextWindowFor / triggerTokens from compaction.ts, so the UI and the engine cannot drift apart. - Session gains compactRatio / compactLog / lastPromptParts (observation only, never used for decisions; older builds ignore unknown keys). - Emit a usage snapshot the moment compaction happens (both before a turn and mid-turn), otherwise a long turn keeps showing pre-compaction numbers for minutes. - The two percentages have different denominators, so the chip shows window usage only; the compaction-line progress lives in the tooltip and drives the red state. - Prompt composition (system prompt / tool definitions / messages) is estimated locally, then scaled so the three parts always sum to the real total. References (rationale only, no code copied): - DSH plugin dsh-compaction-threshold (MIT, npm): thresholdRatio slider, the 20%–95% range, and deferring the post-compaction reading until the next usage report. - Trigger formula (window − output budget − headroom) follows Claude Code; tail retention limits follow Codex and OpenCode (see comments in compaction.ts).
moxuyio1024
force-pushed
the
feat/context-usage-chip
branch
from
November 16, 2026 11:37
1e90cb1 to
2d6ee65
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
在输入框工具条模型贴片左侧加一枚胶囊,显示本对话的窗口占用与上一轮提示缓存命中率;点开可拖动自动压缩的触发比例并查看压缩记录。用量走压缩判定的同一套口径,故显示的百分比就是压缩的实际依据。
chat:context-usage/chat:set-compact-ratio两个 IPC,与压缩判定共用contextWindowFor/triggerTokens,避免界面与引擎两套口径各算各的。compactRatio/compactLog/lastPromptParts三个字段(纯观测,不参与判定;旧版读到未知键会忽略,不影响兼容)。参考来源(取舍依据,非代码照搬):
dsh-compaction-threshold(MIT,npm):阈值滑块写thresholdRatio、滑块范围 20%–95%、压缩记录「压后」读数延后到下一次 usage 回报才定稿。compaction.ts内注释)。验证
corepack pnpm typecheck、corepack pnpm build(与 CI 相同的两步)通过。说明
记忆系统的改动(遗忘区归档 +
memory_merge/memory_check/memory_tidy)另开一帖 #61 附补丁,与本提交无关,可分别评审。若上游另有更合适的呈现方式,欢迎直接改。