feat(ui): add /tokens /context /cost commands (#224) - #281
Open
innocarpe wants to merge 1 commit into
Open
Conversation
New slash commands report token usage, context-window consumption, and estimated cost for the current session. Token usage comes from the session entry; context size is estimated from the active messages; cost uses a DeepSeek pricing table. (cherry picked from commit feaf159f38a141e1888323f6131a12478d81e87e)
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.
Summary
/tokens,/context, and/costslash commands report token usage, context-window consumption, and estimated cost for the current session.Why
Token usage was already tracked in session entries but invisible from the CLI. Users had no way to check how much context they had used, what was consuming it, or what a session cost — important for paid/reasoning models and for debugging context-limit issues.
Changes
packages/cli/src/ui/core/token-usage.ts(new): context estimation (chars/4 over active messages), DeepSeek pricing table, and report formatters.packages/cli/src/ui/core/slash-commands.ts: register/tokens,/context,/cost.packages/cli/src/ui/views/PromptInput.tsx+App.tsx: wire the commands to compute and display the report.packages/cli/src/tests/token-usage.test.ts(new) +slash-commands.test.ts: unit tests.Validation
npm run typecheck✅npm test— CLI suite passes (306/306) ✅Closes #224