feat(shell): show context token usage in status and rotate prompt tips#1322
feat(shell): show context token usage in status and rotate prompt tips#1322
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the shell UI’s status rendering by surfacing context token usage (current/max) alongside context percentage, and refreshes the prompt’s shortcut hints by replacing static strings with rotating tips.
Changes:
- Extend
StatusUpdate/StatusSnapshotto includecontext_tokensandmax_context_tokens, and propagate them through/compact,/clear, and step status updates. - Add shared formatting helpers for compact context display and use them in both the prompt toolbar and live status block.
- Add unit tests covering
_StatusBlockpartial-update behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ui_and_conv/test_status_block.py | Adds tests for _StatusBlock partial-update and no-op semantics. |
| src/kimi_cli/wire/types.py | Extends StatusUpdate wire event with token context fields. |
| src/kimi_cli/ui/shell/visualize.py | Updates _StatusBlock to preserve prior token fields and render via shared formatter. |
| src/kimi_cli/ui/shell/prompt.py | Renders context status via shared formatter; replaces static hints with rotating tips. |
| src/kimi_cli/ui/shell/init.py | Sends initial status to UI including context token fields. |
| src/kimi_cli/soul/slash.py | Ensures /compact and /clear emit full context status fields. |
| src/kimi_cli/soul/kimisoul.py | Populates context token fields in status and step status updates. |
| src/kimi_cli/soul/init.py | Introduces shared format_token_count / format_context_status helpers and expands StatusSnapshot. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/kimi_cli/soul/__init__.py
Outdated
| return f"{n / 1_000_000:.1f}m" | ||
| if n >= 1_000: | ||
| return f"{n / 1_000:.1f}k" | ||
| return str(n) | ||
|
|
||
|
|
There was a problem hiding this comment.
The format_token_count docstring examples (e.g., "128k") don’t match the current formatting logic, which always renders one decimal place for thousands/millions (e.g., "128.0k"). Either adjust the examples to match the actual output, or update the formatter to drop the trailing ".0" when the scaled value is an integer.
| return f"{n / 1_000_000:.1f}m" | |
| if n >= 1_000: | |
| return f"{n / 1_000:.1f}k" | |
| return str(n) | |
| value = n / 1_000_000 | |
| suffix = "m" | |
| elif n >= 1_000: | |
| value = n / 1_000 | |
| suffix = "k" | |
| else: | |
| return str(n) | |
| if value.is_integer(): | |
| return f"{int(value)}{suffix}" | |
| return f"{value:.1f}{suffix}" |
| initial_status=StatusUpdate( | ||
| context_usage=self.soul.status.context_usage, | ||
| context_tokens=self.soul.status.context_tokens, | ||
| max_context_tokens=self.soul.status.max_context_tokens, | ||
| ), |
There was a problem hiding this comment.
self.soul.status is accessed three times when building initial_status. Since status computes a new StatusSnapshot each access, this does redundant work and could theoretically produce inconsistent values if the context changes between reads. Consider storing snap = self.soul.status once and reading the three fields from that snapshot.
src/kimi_cli/ui/shell/prompt.py
Outdated
| "ctrl-v: paste image", | ||
| "@: mention files", | ||
| ] |
There was a problem hiding this comment.
_ALL_TIPS always includes "ctrl-v: paste image", but the Ctrl-V keybinding is only registered when is_clipboard_available() is true. On platforms/environments without clipboard support, the toolbar tip will advertise a shortcut that doesn’t work. Consider building the tips list dynamically based on is_clipboard_available() (and potentially current mode) so only supported shortcuts are shown.
| "ctrl-v: paste image", | |
| "@: mention files", | |
| ] | |
| "@: mention files", | |
| ] | |
| if is_clipboard_available(): | |
| _ALL_TIPS.append("ctrl-v: paste image") |
…_tokens and max_context_tokens
…mpact representation
…dd tests for overflow handling
Summary
context_tokensandmax_context_tokensin soul/wire status updates.42.0% (4.2k/10.0k))./compactand/clearemit full context status fields._StatusBlockpartial-update behavior.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.