Repository navigation
feat(clients): show a compaction divider's before and estimated after token counts - #789
Merged
Merged
Conversation
… token counts
The agent has always reported both halves of a committed checkpoint
(`tokens_before` in the `compaction_committed` event and the checkpoint entry's
`tokens_before`/`tokens_after`), and the TUI has shown them as
"Context compacted: 670217 → 35437 tokens (estimated)" since it was written.
The desktop and mobile dividers only ever read `tokens_before`, so the two
clients that draw the divider as a hairline label showed what the turn was
about to send and nothing about what the compaction bought.
Carry `tokensAfter` through the shared thread projection (segment model, the
durable entry projection, the live run projector) and render the pair on both
dividers. `tokensAfter` is an estimate, not provider usage: it is the local
per-message estimate of the kept history plus the fixed system/tools overhead,
so the labels say so — matching the TUI's wording.
Mobile uses a terser sentence than the desktop when the pair is present. The
divider row is ~350px wide at 12px, and the desktop sentence plus the pair
("你手动压缩了此对话的上下文 · 33,064 → 9,250 tokens(预估)", 346px) wraps onto
two lines, leaving the tail "估)" alone on the second. Measured in the harness:
the shorter phrasing is 286px, one line, with the pair intact.
The two shot mocks that emit a compaction gain the second number (the real
agent always sends it), and the mobile/desktop scenarios now assert the pair
rather than the bare label.
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.
What
After a context compaction commits, the desktop and mobile dividers now show both numbers the agent already reports: the pre-compaction token count and its estimate for the next turn's prompt.
The TUI has shown this pair ("Context compacted: 670217 → 35437 tokens (estimated)") since it was written; the two clients that draw the compaction marker as a hairline divider only read
tokens_before.Why nothing had to change in the agent
The pair is already on the wire in both paths:
compaction_committedcarriestokens_before+tokens_after(agent/src/rpc/prompt_helpers.rs);future_rpc::message::checkpoint_metadata.tokens_afteris an estimate (history_after + fixed_input_tokensincompaction/finalize), not provider usage — hence the "(estimated)" / "(预估)" qualifier, matching the TUI.Changes
packages/thread-projection:tokensAfteron the compactionMessageSegment; read from the durable entry projection (entry.checkpoint.tokensAfter) and from the live projector (compaction_committed/compaction_endpayload).CompactionDividerrenders the pair (automatic and manual), the standalone/manual live path passes it through, en/zh copy.TimelineSegment.tokensAfter.tokensAfter(a released run journal'scompaction_end, a legacy row) keeps today's before-only label.Mobile uses a terser sentence when the pair is present
The divider row is ~350px wide at 12px, and the desktop sentence plus the pair (
你手动压缩了此对话的上下文 · 33,064 → 9,250 tokens(预估), measured 346px) wraps onto two lines, leaving the tail估)alone on the second. The shorter phrasing measures 286px — one line — with the pair, the unit and the estimate marker intact.Verification
desktop:tsc --noEmit,eslint, fullvitest run(144 files / 1233 tests) — green; newMessageBlock.compaction.test.tsxrenders the real divider and asserts the exact label in en and zh, the manual variant, the before-only fallback and that running/failed dividers carry no counts.mobile:tsc --noEmit,eslint, fulljest(121 suites / 1840 tests) — green; new divider unit tests plustokensBefore/tokensAftercoverage in all three projector paths (single/batch/replay) and in the durable timeline.compact-resume/compact-context-outcome/compact-context-delayedscenarios assert the pair instead of the bare label. Captured and measured in the harness on both platforms: the label is one line,scrollWidth == clientWidth, no clipping (mobile 286px in a 334px slot; desktop 272px in a 768px column).