Replace token-usage panel with per-pane context-fill indicator

For a subscription user, lifetime token totals + a $ estimate aren't
actionable; how full each session's context window is right now is. So:

- Removed the UsagePanel, the titlebar 💰 chip, and Ctrl+Shift+U.
- Repurposed the transcript reader (src-tauri/src/usage.rs): get_pane_context
  returns each recent session's CURRENT context occupancy = the last
  assistant turn's input + cache_read + cache_creation tokens (the prompt
  size), instead of lifetime sums. Same UNC/$HOME/cache/recency machinery.
- src/lib/usage.ts now holds context helpers (window inference 200k vs 1M by
  whether occupancy already exceeds 200k, % , green→amber→red ramp, label).
- App polls get_pane_context (15s, visibility-gated) into a cwd→context map
  exposed via orchestration; each LeafPane looks itself up by leaf.cwd and
  renders a slim fill bar + % in its header (hidden for non-claude/unmatched
  panes).

Also fixes the narrow-pane toolbar: a ResizeObserver sets leaf--narrow /
leaf--xnarrow width tiers; the label shrinks first, split buttons / status /
secondary chips drop out by tier, and the close × + context indicator stay
pinned right and visible down to the 180px min width.

tsc clean (apart from the not-yet-installed xterm addons). Rust builds on
the Windows host; needs runtime verification.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-28 22:43:06 +01:00
parent b23f3d1ecb
commit d951c360ae
12 changed files with 235 additions and 612 deletions

View file

@ -39,33 +39,25 @@ export interface SshHost {
export const listDistros = (): Promise<string[]> => invoke("list_distros");
// ---- claude usage tracking ------------------------------------------------
// ---- claude context tracking ----------------------------------------------
/** Per-model token tally within one claude session. Mirrors Rust ModelUsage. */
export interface ModelUsage {
model: string;
inputTokens: number;
outputTokens: number;
cacheCreationTokens: number;
cacheReadTokens: number;
}
/** One claude session's usage, read from its transcript. Mirrors Rust
* SessionUsage. Cost is computed frontend-side (see src/lib/usage.ts). */
export interface SessionUsage {
/** One claude session's current context-window occupancy, read from its
* transcript. Mirrors Rust SessionContext. `contextTokens` is the prompt
* size of the last assistant turn (input + both cache buckets). */
export interface SessionContext {
sessionId: string;
cwd: string;
projectDir: string;
distro: string;
lastActiveMs: number;
models: ModelUsage[];
contextTokens: number;
model: string;
}
/** Scan ~/.claude/projects in the given WSL distros (distinct distros of
* open WSL panes) and return recent sessions' token tallies. WSL/Windows
* only returns [] otherwise. */
export const getClaudeUsage = (distros: string[]): Promise<SessionUsage[]> =>
invoke("get_claude_usage", { distros });
/** Scan ~/.claude/projects in the given WSL distros (distinct distros of open
* WSL panes) and return each recent session's current context occupancy.
* WSL/Windows only returns [] otherwise. */
export const getPaneContext = (distros: string[]): Promise<SessionContext[]> =>
invoke("get_pane_context", { distros });
export const spawnPane = (args: {
spec: SpawnSpec;