Context bar: show absolute tokens, assume 1M window (% wasn't reliable)

The transcript doesn't record the 200k-vs-1M window (model id is bare,
e.g. claude-opus-4-7; the [1m] in /context is display-only), so the
<200k→200k guess overstated the % for 1M users (a 42k session read 21%
instead of 4%). Fix: the indicator label now shows the absolute token
count (accurate regardless of window), and the fill bar assumes 1M (the
common case here; a 200k-only user would just see the bar read low while
the token number stays correct).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-28 23:09:15 +01:00
parent 0358128b24
commit c01a4decbf
2 changed files with 13 additions and 15 deletions

View file

@ -12,9 +12,9 @@ import { type LeafNode, resolveFontSize, type LeafShellSpec } from "./tree";
import { useOrchestration } from "./orchestration";
import {
contextLabel,
contextPercent,
contextColor,
contextFraction,
formatTokens,
} from "../../lib/usage";
import XtermPane from "../../components/XtermPane";
import type { SpawnSpec } from "../../ipc";
@ -597,12 +597,12 @@ export default function LeafPane({ leaf }: { leaf: LeafNode }) {
<span
className="pane-ctx-fill"
style={{
width: `${contextPercent(ctx)}%`,
width: `${Math.round(contextFraction(ctx) * 100)}%`,
background: contextColor(contextFraction(ctx)),
}}
/>
</span>
<span className="pane-ctx-pct">{contextPercent(ctx)}%</span>
<span className="pane-ctx-pct">{formatTokens(ctx.contextTokens)}</span>
</span>
)}

View file

@ -4,18 +4,18 @@
import type { SessionContext } from "../ipc";
const WINDOW_STANDARD = 200_000;
const WINDOW_LARGE = 1_000_000;
/**
* Context-window size for a session. The transcript's model id doesn't encode
* the 200k-vs-1M variant, so we infer: a session whose prompt has already
* exceeded 200k must be running the 1M-context window. Approximate near the
* boundary, but correct for the cases that matter (a small session reads
* against 200k; a large one against 1M).
* Assumed context window. The transcript does NOT record whether a session
* runs the 200k or 1M window (the model id is bare, e.g. `claude-opus-4-7`
* the `[1m]` that claude's /context shows is display-only), so the % can't be
* computed reliably. We assume 1M (the common case here) for the fill bar, and
* the indicator LABEL shows the absolute token count, which is accurate
* regardless of the real window that's the figure to trust.
*/
export function contextWindow(contextTokens: number): number {
return contextTokens > WINDOW_STANDARD ? WINDOW_LARGE : WINDOW_STANDARD;
export function contextWindow(_contextTokens: number): number {
return WINDOW_LARGE;
}
/** Fraction (0..1) of the inferred window currently occupied. */
@ -41,9 +41,7 @@ export function formatTokens(n: number): string {
return String(n);
}
/** e.g. "~274k / 1M" for a tooltip. */
/** e.g. "274k tokens · ~27% of 1M (last turn)" for a tooltip. */
export function contextLabel(s: SessionContext): string {
const w = contextWindow(s.contextTokens);
const wLabel = w >= 1_000_000 ? "1M" : "200k";
return `~${formatTokens(s.contextTokens)} / ${wLabel}`;
return `${formatTokens(s.contextTokens)} tokens · ~${contextPercent(s)}% of 1M (last turn)`;
}