Skip to content

feat(tui): add /usage context and token charts - #5705

Merged
chengyongru merged 2 commits into
HKUDS:mainfrom
chengyongru:feat/tui-usage-chart
Sep 9, 2026
Merged

feat(tui): add /usage context and token charts#5705
chengyongru merged 2 commits into
HKUDS:mainfrom
chengyongru:feat/tui-usage-chart

Conversation

@chengyongru

@chengyongru chengyongru commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a TUI-local /usage panel for the context meter and recent model-round usage already available in the WebUI.

  • Show the latest request's context occupancy and up to eight logical model rounds from the latest history page, with cached, uncached, and unknown-cache input bars.
  • Use Left/Right for per-round input/output, cache hit rate, generation time, and estimated-usage details; Esc returns to chat. Collapse details in short terminals.
  • Reuse the existing authenticated thread endpoint and reauthentication flow. Preserve the successful-compaction boundary, distinguish unknown usage from zero, and ignore late responses after dismissal or session changes. Refresh the open panel on turn completion.
  • Coalesce overlapping refresh events into one trailing request, abort usage fetches on dismissal, session attachment, or shutdown without cancelling shared reauthentication, and skip rebuilding hidden chart content.
  • Quantize input and cache boundaries independently to eighths of a character row, using foreground/background colors for mixed full cells.
  • Keep recognized local commands out of the active-turn prompt queue so /usage cannot be dispatched to the gateway through the Tab queue path.

No Python backend, wire-schema, configuration, or dependency changes.

Verification

  • cd tui && bun run check
  • cd tui && bun test — 233 passed
  • cd tui && bun run build — Windows x64 build succeeded
  • Real CLI through Windows ConPTY and an isolated local mock gateway — 32 checks passed, including open/navigation/resize/Esc, subcell foreground/background values, unknown cache, empty/error/retry states, stale-response dismissal, request coalescing, transport cancellation, hidden-panel event handling, and clean shutdown. The fixture recorded zero agent messages or mutations; no real model provider was called.
  • Real loopback WebSocketChannel HTTP endpoint with isolated persisted transcripts — TUI usage matched the current WebUI selectors before compaction, after successful compaction, and after later usage restored context; 401 reauthentication passed.
  • Mounted TUI lifecycle checks — opening during an active turn, foreign-session event filtering, compaction/completion refresh, pending-response dismissal, and renderer shutdown passed with zero agent sends.

Display limits

The chart is a character-grid approximation, not a pixel graphic. If a partial top cell would require empty space plus both cache colors, preserve its height and use its larger token category's color. Exact token counts remain in the numeric details. The bounded latest history page may contain fewer than eight rounds.

@chengyongru chengyongru added feature priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test labels Sep 8, 2026
@chengyongru
chengyongru marked this pull request as draft September 9, 2026 03:49
@chengyongru
chengyongru marked this pull request as ready for review September 9, 2026 05:04
@chengyongru
chengyongru merged commit 7d84504 into HKUDS:main Sep 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant