Skip to content

feat(shell): show context token usage in status and rotate prompt tips#1322

Merged
RealKai42 merged 5 commits intomainfrom
kaiyi/rotating-tips
Mar 3, 2026
Merged

feat(shell): show context token usage in status and rotate prompt tips#1322
RealKai42 merged 5 commits intomainfrom
kaiyi/rotating-tips

Conversation

@RealKai42
Copy link
Copy Markdown
Collaborator

@RealKai42 RealKai42 commented Mar 3, 2026

Summary

  • Surface context_tokens and max_context_tokens in soul/wire status updates.
  • Add a shared formatter for compact context display (for example: 42.0% (4.2k/10.0k)).
  • Update shell prompt and status block to render the formatted context status consistently.
  • Ensure /compact and /clear emit full context status fields.
  • Replace static shortcut hints with rotating prompt tips.
  • Add tests for _StatusBlock partial-update behavior.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

Copilot AI review requested due to automatic review settings March 3, 2026 09:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/StatusSnapshot to include context_tokens and max_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 _StatusBlock partial-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.

Comment on lines +55 to +60
return f"{n / 1_000_000:.1f}m"
if n >= 1_000:
return f"{n / 1_000:.1f}k"
return str(n)


Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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}"

Copilot uses AI. Check for mistakes.
Comment on lines +242 to +246
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,
),
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +500 to +502
"ctrl-v: paste image",
"@: mention files",
]
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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.

Suggested change
"ctrl-v: paste image",
"@: mention files",
]
"@: mention files",
]
if is_clipboard_available():
_ALL_TIPS.append("ctrl-v: paste image")

Copilot uses AI. Check for mistakes.
devin-ai-integration[bot]

This comment was marked as resolved.

@RealKai42 RealKai42 merged commit 03be048 into main Mar 3, 2026
21 checks passed
@RealKai42 RealKai42 deleted the kaiyi/rotating-tips branch March 3, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants