Repository navigation
feat(shell): visual context progress bar with color coding - #1972
xiaoye5200 wants to merge 8 commits into
Conversation
| bounded = max(0.0, min(self._context_usage, 1.0)) | ||
| bar_width = 10 | ||
| filled = math.ceil(bounded * bar_width) if bounded > 0 else 0 | ||
| pct = int(bounded * 100) | ||
| if bounded >= 0.85: | ||
| color = "red" | ||
| elif bounded >= 0.70: | ||
| color = "yellow" | ||
| else: | ||
| color = "green" | ||
| self.text = Text("Context ", justify="right") | ||
| self.text.append("█" * filled, style=color) | ||
| self.text.append("░" * (bar_width - filled), style=f"dim {color}") | ||
| self.text.append(f" {pct}%", style=color) | ||
| if self._max_context_tokens > 0: | ||
| used = format_token_count(self._context_tokens) | ||
| total = format_token_count(self._max_context_tokens) | ||
| self.text.append(f" ({used}/{total})") |
There was a problem hiding this comment.
🔴 Stale tests: _StatusBlock percentage format changed from 42.0% to 42% but tests not updated
The _StatusBlock.update() method in _blocks.py:626-643 now formats the percentage as int(bounded * 100) (producing "42%") instead of using format_context_status which produced "42.0%". Two assertions in tests/ui_and_conv/test_status_block.py will fail: line 16 checks "42.0%" in block.text.plain and line 32 checks "50.0%" in block.text.plain, but the new output contains "42%" and "50%" respectively. These substrings no longer match.
Prompt for agents
Update tests/ui_and_conv/test_status_block.py to match the new percentage format. At line 16, change '42.0%' to '42%'. At line 32, change '50.0%' to '50%'. The new _StatusBlock uses int(bounded * 100) which produces integer percentages without a decimal point.
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Hi @liruifengv @RealKai42 @tempurai @wbxl2000 👋 This PR replaces the plain-text A tracking issue has been created at #2188. Would appreciate a review when you have a moment — happy to adjust anything! Thanks 🙏 |
Replace the plain text `context: 0.0%` status bar indicator with a block-style progress bar: `Context █░░░░░░░░░ 10%`. The bar uses 10 Unicode block characters (█ filled, ░ empty) to give an at-a-glance sense of context usage, followed by an integer percentage. Token counts are preserved when available: `Context █████░░░░░ 50% (5.0k/10.0k)`.
Apply green/yellow/red coloring to the context progress bar and percentage text based on usage thresholds: - < 70% → green (Context ██░░░░░░░░ 20%) - 70–85% → yellow (Context ███████░░░ 70%) - ≥ 85% → red (Context █████████░ 90%) Both the bar characters and the percentage digits share the same color. The "Context" label and optional token counts (e.g. 5.0k/10.0k) remain in the default toolbar color. Changes: - theme.py: add context_ok/warn/critical color fields to ToolbarColors - prompt.py: _render_right_span now returns FormattedText fragments so individual spans can carry independent styles; width calculation updated accordingly - _blocks.py: rebuild Rich Text with styled append instead of setting .plain, so Rich renders the color in the streaming agent view
Split the progress bar into two separately styled spans so the filled blocks (█) use the context color while the empty blocks (░) are dimmed, matching claude-hud's coloredBar behavior exactly. Also moves the percentage digit into its own colored span so the full visual is: Context [colored █…][dim ░…][colored N%] [(tokens)].
Replace fixed grey dim color with per-state dim variants so the empty
░ blocks appear as dark green / dark amber / dark red instead of grey,
matching claude-hud's behavior of dimming within the same color family.
- theme.py: replace context_dim with context_dim_ok/warn/critical
- prompt.py: select matching dim_color alongside color
- _blocks.py: use Rich 'dim {color}' style for empty blocks
04df66e to
142ae60
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 142ae60a98
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| total = format_token_count(max_context_tokens) | ||
| return f"context: {bounded:.1%} ({used}/{total})" | ||
| return f"context: {bounded:.1%}" | ||
| return f"Context {bar} {pct}% ({used}/{total})" |
There was a problem hiding this comment.
Preserve format_context_status contract or update dependent tests
This changes format_context_status from the previous plain string (context: 42.0% ...) to a new bar format (Context █...), but tests/core/test_status_formatting.py::test_format_context_status_uses_compact_token_counts still asserts the old output. That means this commit introduces a deterministic test-suite regression and will fail make test until the dependent assertions/callers are updated in the same change.
Useful? React with 👍 / 👎.
…in live view - Replace math.ceil with max(1, round(...)) so 91-99% usage shows 9/10 blocks instead of appearing 100% full - Mutate self.text in-place instead of reassigning, so Rich Group keeps a stable reference and context bar updates correctly in live mode without requiring a full recomposition - Update tests to match new integer percentage format and new bar output
|
Addressed all review comments from Devin and CodeX: P1 - Test suite regression (format_context_status format change) BUG - Stale _StatusBlock percentage format in tests BUG - Toolbar tests asserting old P2 - math.ceil overfills bar at 91-99% P2 - self.text reassignment breaks Rich live-view updates @liruifengv @RealKai42 @tempurai @wbxl2000 happy to make any further adjustments! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a584ecd56
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return [("", current_toast.message)] | ||
| bounded = max(0.0, min(status.context_usage, 1.0)) | ||
| bar_width = 10 | ||
| filled = max(1, round(bounded * bar_width)) if bounded > 0 else 0 |
There was a problem hiding this comment.
Replace half-even rounding in context bar block calculation
Using round(bounded * bar_width) makes block fill counts depend on Python’s half-even rounding, so exact x5% values under-report (e.g. 25%→2 blocks, 45%→4 blocks, 85%→8 blocks). This creates a misleading bar progression where adjacent percentages can jump inconsistently and 85% (already critical/red) still shows only 8/10 filled blocks. The issue is user-visible in the toolbar and can miscommunicate how close the session is to context exhaustion.
Useful? React with 👍 / 👎.
Related Issue
N/A (new feature, no prior issue)
Description
Replace the plain-text
context: 0.0%status bar indicator with a color-coded Unicode block progress bar, matching the visual style of the claude-hud plugin.Changes
src/kimi_cli/soul/__init__.pyformat_context_statusnow rendersContext █░░░░░░░░░ 4%instead ofcontext: 4.0%math.ceilso any non-zero usage always shows at least 1 filled blocksrc/kimi_cli/ui/theme.pycontext_ok / context_warn / context_criticalcolor fields toToolbarColors(bright green / amber / red, with dark/light theme variants)context_dim_ok / context_dim_warn / context_dim_criticalfor the empty block color (same hue, darker shade)src/kimi_cli/ui/shell/prompt.py_render_right_spannow returnslist[tuple[str, str]](FormattedText fragments) so each span can carry its own color█, empty blocks░, and percentage text each get independent color spanssrc/kimi_cli/ui/shell/visualize/_blocks.pyself.text.plain = format_context_status(...)with styledText.append()calls for Rich live-view renderingColor thresholds (same as claude-hud)
█░Empty blocks use a dimmed variant of the same hue, matching claude-hud's behavior of applying
DIMafter setting the color.Example output
Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.