feat(tui): add persistent token usage display in session footer#19105
Closed
andrewdunndev wants to merge 1 commit into
Closed
feat(tui): add persistent token usage display in session footer#19105andrewdunndev wants to merge 1 commit into
andrewdunndev wants to merge 1 commit into
Conversation
Add cumulative input/output token counts and live tokens-per-second to the TUI session footer. Displays alongside existing LSP/MCP status items. Format: '142 tok/s · 4.5M in · 19K out · • 2 LSP · ⊙ 1 MCP' - tok/s shown during streaming (bright) and 3s after (muted) - Cumulative in/out tokens with compact K/M suffixes - Token stats computed from AssistantMessage.tokens in the sync store - TPS calculated via createEffect (no side effects in memos) - Formatting utilities in util/tokens.ts with 8 tests covering edge cases (K/M rollover, TPS threshold at 10) Closes anomalyco#17449 Relates to anomalyco#6096, anomalyco#10354, anomalyco#13003
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate/Related PRs Found:
Note: The current PR (#19105) builds on or supersedes similar earlier attempts to add token metrics to the footer. Check if PRs #14493 and #12721 are closed/merged or if they address overlapping functionality. |
Author
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.
Issue for this PR
Closes #17449
Relates to #6096, #10354, #13003
Type of change
What does this PR do?
Adds cumulative token usage and live tokens-per-second to the TUI session footer, displayed alongside existing LSP/MCP status items.
Footer format:
Three data points:
Token stats are computed from
AssistantMessage.tokensin the sync store viacreateMemo. TPS is calculated in acreateEffect(no side effects in memos) that tracks output token deltas between reactive updates during thebusysession status.Files changed:
packages/opencode/src/cli/cmd/tui/routes/session/footer.tsx-- token stats memo, TPS tracking effect, footer displaypackages/opencode/src/cli/cmd/tui/util/tokens.ts--formatTokenCount()(compact K/M suffixes with boundary rollover) andformatTps()(clean threshold at 10)packages/opencode/src/cli/cmd/tui/util/tokens.test.ts-- 8 tests, 30 assertions covering edge cases (K→M rollover at 999,500, TPS threshold at 9.95)How did you verify your code works?
bun test src/cli/cmd/tui/util/tokens.test.ts-- 8 pass, 0 fail, 30 assertionsbun run --filter opencode typecheck-- exits 0 (no new type errors)createMemowith side effects causing a reactive loop. Refactored tocreateEffectwith explicit dependency tracking before submission.SessionStatusdiscriminated union type (idle | busy | retry) against SDK v2 types to ensure correct status detectionScreenshots / recordings
TUI change. The footer gains a token stats section to the left of the existing LSP/MCP items. During streaming, shows live tok/s rate. Always shows cumulative in/out totals once the first assistant message completes. Hidden when no messages have been exchanged yet.
Checklist