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:
parent
0358128b24
commit
c01a4decbf
2 changed files with 13 additions and 15 deletions
|
|
@ -12,9 +12,9 @@ import { type LeafNode, resolveFontSize, type LeafShellSpec } from "./tree";
|
||||||
import { useOrchestration } from "./orchestration";
|
import { useOrchestration } from "./orchestration";
|
||||||
import {
|
import {
|
||||||
contextLabel,
|
contextLabel,
|
||||||
contextPercent,
|
|
||||||
contextColor,
|
contextColor,
|
||||||
contextFraction,
|
contextFraction,
|
||||||
|
formatTokens,
|
||||||
} from "../../lib/usage";
|
} from "../../lib/usage";
|
||||||
import XtermPane from "../../components/XtermPane";
|
import XtermPane from "../../components/XtermPane";
|
||||||
import type { SpawnSpec } from "../../ipc";
|
import type { SpawnSpec } from "../../ipc";
|
||||||
|
|
@ -597,12 +597,12 @@ export default function LeafPane({ leaf }: { leaf: LeafNode }) {
|
||||||
<span
|
<span
|
||||||
className="pane-ctx-fill"
|
className="pane-ctx-fill"
|
||||||
style={{
|
style={{
|
||||||
width: `${contextPercent(ctx)}%`,
|
width: `${Math.round(contextFraction(ctx) * 100)}%`,
|
||||||
background: contextColor(contextFraction(ctx)),
|
background: contextColor(contextFraction(ctx)),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
<span className="pane-ctx-pct">{contextPercent(ctx)}%</span>
|
<span className="pane-ctx-pct">{formatTokens(ctx.contextTokens)}</span>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,18 @@
|
||||||
|
|
||||||
import type { SessionContext } from "../ipc";
|
import type { SessionContext } from "../ipc";
|
||||||
|
|
||||||
const WINDOW_STANDARD = 200_000;
|
|
||||||
const WINDOW_LARGE = 1_000_000;
|
const WINDOW_LARGE = 1_000_000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context-window size for a session. The transcript's model id doesn't encode
|
* Assumed context window. The transcript does NOT record whether a session
|
||||||
* the 200k-vs-1M variant, so we infer: a session whose prompt has already
|
* runs the 200k or 1M window (the model id is bare, e.g. `claude-opus-4-7` —
|
||||||
* exceeded 200k must be running the 1M-context window. Approximate near the
|
* the `[1m]` that claude's /context shows is display-only), so the % can't be
|
||||||
* boundary, but correct for the cases that matter (a small session reads
|
* computed reliably. We assume 1M (the common case here) for the fill bar, and
|
||||||
* against 200k; a large one against 1M).
|
* 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 {
|
export function contextWindow(_contextTokens: number): number {
|
||||||
return contextTokens > WINDOW_STANDARD ? WINDOW_LARGE : WINDOW_STANDARD;
|
return WINDOW_LARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fraction (0..1) of the inferred window currently occupied. */
|
/** Fraction (0..1) of the inferred window currently occupied. */
|
||||||
|
|
@ -41,9 +41,7 @@ export function formatTokens(n: number): string {
|
||||||
return String(n);
|
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 {
|
export function contextLabel(s: SessionContext): string {
|
||||||
const w = contextWindow(s.contextTokens);
|
return `${formatTokens(s.contextTokens)} tokens · ~${contextPercent(s)}% of 1M (last turn)`;
|
||||||
const wLabel = w >= 1_000_000 ? "1M" : "200k";
|
|
||||||
return `~${formatTokens(s.contextTokens)} / ${wLabel}`;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue