Skip to content

feat: show remaining context headroom in TUI badge#33

Open
siolyn wants to merge 2 commits into
LiuMengxuan04:mainfrom
siolyn:feat/context-headroom-badge
Open

feat: show remaining context headroom in TUI badge#33
siolyn wants to merge 2 commits into
LiuMengxuan04:mainfrom
siolyn:feat/context-headroom-badge

Conversation

@siolyn

@siolyn siolyn commented Jun 8, 2026

Copy link
Copy Markdown

Summary

This PR adds remaining effective-input headroom to the existing TUI context badge.

The badge already shows context utilization and token accounting source. This change makes the remaining input budget visible as a compact value, for example:

ctx 68% ▓▓▓▓▓▓▓░░░ 59K left usage+est

Part of #1.

Why

MiniCode already has model-aware context stats, including contextWindow, outputReserve, effectiveInput, and provider/estimate-based token accounting. However, the TUI only showed utilization percentage, so users could not quickly tell how much usable input budget remained before context pressure became more serious.

Showing remaining effective-input tokens makes long-session context pressure easier to understand without changing the existing compaction behavior.

Changes

  • add remainingTokens to ContextStats, computed from effectiveInput - totalTokens
  • show compact remaining headroom in renderContextBadge
  • keep the badge source label (usage, usage+est, est) unchanged
  • align TUI context stats typing with ContextStats and update related test fixtures
  • add tests for normal, small, million-scale, and blocked headroom display

Scope

This is intentionally a small visibility follow-up. It does not implement the remaining full context compaction work in #1, and it does not change:

  • auto-compact trigger behavior
  • provider usage ingestion
  • session persistence
  • model adapter behavior
  • public CLI commands

Validation

  • npm run check — passed
  • npm test — passed, 205 tests
  • npx eslint src/tui/chrome.ts src/utils/token-estimator.ts test/context-badge.test.ts test/token-estimator.test.ts test/session.test.ts test/snip-compact.test.ts — passed
  • git diff --check — passed

npm run lint currently reports pre-existing no-undef errors in test/run-tests.mjs, unrelated to this change.

@siolyn siolyn closed this Jun 8, 2026
@siolyn siolyn reopened this Jun 8, 2026
@siolyn siolyn marked this pull request as ready for review June 8, 2026 16:15
@GateJustice

Copy link
Copy Markdown
Collaborator

Thanks for the PR! I think this is a meaningful and necessary improvement. Showing the remaining input headroom makes the context badge more useful, especially in long sessions. Appreciate the contribution!

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