fix(tui): compact statusline token chip#2405
Conversation
There was a problem hiding this comment.
Code Review
This pull request simplifies the session token-usage chip in the TUI footer by displaying a single, compact total of input and output tokens instead of a detailed breakdown of input, cache-hit, and output tokens. A corresponding unit test has been added to verify this new behavior. There are no review comments, and I have no feedback to provide.
| fn footer_session_tokens_chip_uses_single_compact_total() { | ||
| let mut app = create_test_app(); | ||
| app.session.total_input_tokens = 1_400_000; | ||
| app.session.total_cache_hit_tokens = 1_200_000; | ||
| app.session.total_cache_miss_tokens = 200_000; | ||
| app.session.total_output_tokens = 7_600; | ||
|
|
||
| let text = spans_text(&footer_session_tokens_spans(&app)); | ||
|
|
||
| assert_eq!(text, "tok 1.4M"); | ||
| assert!(!text.contains(" cch ")); | ||
| assert!(!text.contains(" out")); | ||
| } |
There was a problem hiding this comment.
Test values don't distinguish input-only from input+output sum
The chosen values (total_input_tokens = 1_400_000, total_output_tokens = 7_600) both round to "1.4M" at one decimal place, so this assertion would still pass even if total_output_tokens were silently dropped from the sum in footer_session_tokens_spans. A value pair where output tokens shift the display unit—e.g. total_input_tokens = 900_000 + total_output_tokens = 600_000 expecting "1.5M"—would make the test fail if only input is summed, actually locking the full input + output contract the PR intends.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Thanks @axobase001 — this is a tiny, clean UI polish slice and the full visible CI matrix is green. I’m leaving it unmerged only because it is still marked draft. If it’s ready, please flip it to ready for review and I’ll treat it as harvestable. |
Harvested from #2405 with thanks to @axobase001.\n\nCompacts the statusline token chip to use the short label while preserving the existing token detail and adding focused coverage for the rendered label.\n\nPartially addresses #2309.
|
Thanks @axobase001 — your contribution landed in
Closing this PR now that the code is on If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the |
|
Thanks again @axobase001. I landed the compact statusline token chip via #2411 as I’m going to close this draft as superseded so the queue reflects what still needs attention. #2309 stays open because the broader picker-discovery behavior still has more work beyond this compact chip slice. |
Summary
tokensstatusline chip to a single cumulative token count liketok 1.4Mcachechipcch/outdetails stay out of the token chipPartially addresses #2309
Validation
cargo test -p codewhale-tui --bin codewhale-tui footer_session_tokens_chip_uses_single_compact_total --lockedcargo check -p codewhale-tui --lockedgit diff --checkGreptile Summary
This PR compacts the footer token chip from a verbose
in · cch · outbreakdown down to a singletok 1.4Mcumulative figure, delegating cache detail to the dedicatedcachechip. A regression test locks the new format and asserts the oldcch/outsubstrings no longer appear.footer_session_tokens_spansnow sumstotal_input_tokens + total_output_tokensviasaturating_addand formats the result with the existingformat_token_count_compacthelper, removing all cache-specific branches.footer_session_tokens_chip_uses_single_compact_totalverifies the exact output string and negatively asserts against the legacy format tokens.Confidence Score: 4/5
Safe to merge; the implementation correctly sums input and output tokens (cache tokens are already a subset of input, not additive), and the format change is purely cosmetic.
The core logic is sound and the refactor is narrow. The only observation is that the new regression test uses token values that happen to collapse to the same display string whether or not output tokens are included, so it doesn't fully lock the input + output contract it was written to guard.
crates/tui/src/tui/ui/tests.rs — the new test's input values could be improved to actually verify the output-token contribution.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["footer_session_tokens_spans(app)"] --> B{"input == 0 AND output == 0?"} B -- yes --> C["return Vec::new() (chip hidden)"] B -- no --> D["total = total_input_tokens.saturating_add(total_output_tokens)"] D --> E["format_token_count_compact(total)"] E --> F{{"total >= 1_000_000?"}} F -- yes --> G["format: '{:.1}M'"] F -- no --> H{{"total >= 1_000?"}} H -- yes --> I["format: '{:.1}k'"] H -- no --> J["format: raw number"] G & I & J --> K["Span::styled('tok {result}', TEXT_MUTED)"] K --> L["render in footer Tokens chip slot"]Reviews (1): Last reviewed commit: "fix(tui): compact statusline token chip" | Re-trigger Greptile