From 7e9b77eeaf4211fa6295505986c577ea98d23a19 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 12:04:33 -0400 Subject: [PATCH 1/2] webview: keep plan gauges with their engine --- packages/core/test/webview-rate-limit.spec.js | 36 +++++++++++++++++++ surfaces/webview/src/chat/Composer.tsx | 35 +++++++++--------- surfaces/webview/src/state/store.tsx | 18 +++++----- 3 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 packages/core/test/webview-rate-limit.spec.js diff --git a/packages/core/test/webview-rate-limit.spec.js b/packages/core/test/webview-rate-limit.spec.js new file mode 100644 index 00000000..3a1532f9 --- /dev/null +++ b/packages/core/test/webview-rate-limit.spec.js @@ -0,0 +1,36 @@ +import { describe, expect, it } from "vitest"; +import { initialState, reducer } from "../../../surfaces/webview/src/state/store"; + +describe("webview plan limits", () => { + const claude = { type: "rateLimit", cli: "claude", utilization: 73, window: "five_hour", status: "allowed" }; + + it("keeps a plan reading with its engine through local and host switches", () => { + let state = reducer(initialState, claude); + state = reducer(state, { type: "__switchEngine", cli: "codex" }); + expect(state.rateLimits[state.cli]).toBeUndefined(); + state = reducer(state, { type: "clear" }); + state = reducer(state, { type: "usage", contextTokens: 24_000 }); + expect(state.contextTokens).toBe(24_000); + expect(state.rateLimits[state.cli]).toBeUndefined(); + state = reducer(state, { type: "platform", cli: "claude" }); + expect(state.rateLimits[state.cli]?.utilization).toBe(73); + }); + + it("files a late Claude frame under Claude while Codex is selected", () => { + let state = reducer(initialState, { type: "platform", cli: "codex" }); + state = reducer(state, claude); + expect(state.rateLimits.codex).toBeUndefined(); + expect(state.rateLimits.claude?.utilization).toBe(73); + }); + + it("preserves status-only readings within the reporting engine", () => { + let state = reducer(initialState, claude); + state = reducer(state, { type: "rateLimit", cli: "codex", status: "allowed_warning" }); + expect(state.rateLimits.codex?.utilization).toBeUndefined(); + state = reducer(state, { type: "rateLimit", cli: "claude", status: "allowed_warning" }); + expect(state.rateLimits.claude?.utilization).toBe(73); + expect(state.rateLimits.claude?.status).toBe("allowed_warning"); + state = reducer(state, { ...claude, status: "rejected", utilization: 100 }); + expect(state.rateLimits.claude?.utilization).toBe(100); + }); +}); diff --git a/surfaces/webview/src/chat/Composer.tsx b/surfaces/webview/src/chat/Composer.tsx index 0b285e4d..d42e65e5 100644 --- a/surfaces/webview/src/chat/Composer.tsx +++ b/surfaces/webview/src/chat/Composer.tsx @@ -36,7 +36,7 @@ function CtxDot({ tokens, window: win, compacting }: { tokens: number; window: n return ( {open && ( @@ -223,6 +223,7 @@ function ChipGroup({ label, value, options, onPick, accent = "green" }: { // Input + engine tabs + model/effort pickers. FROZEN while an approval is pending. export function Composer() { const { state, send, selectEngine, switchEngine, queueCount, markCompacting } = useStore(); + const limit = state.rateLimits[state.cli]; const [text, setText] = useState(""); const [effort, setEffort] = useState("default"); const [model, setModel] = useState("default"); @@ -537,7 +538,7 @@ export function Composer() { > {/* engine segmented control + a single "controls" disclosure (model/effort/mode live in the popover so the bar stays clean on a phone) */} -
+
{(["claude", "codex"] as Cli[]).map((c) => { const on = state.cli === c; @@ -565,21 +566,21 @@ export function Composer() { {MODES[state.cli].find((m) => m.value === mode)?.label ?? mode} - {state.limitPct !== undefined && state.limitPct >= 50 && ( - - - - )} - {(state.contextTokens !== undefined || state.isCompacting) && (() => { - const tokens = state.contextTokens ?? 0; - const win = state.contextWindow ?? (state.cli === "codex" ? 256_000 : 200_000); - return ; - })()} - {queueCount > 0 && ( - - ⏳ {queueCount} queued - - )} + + {limit?.utilization !== undefined && limit.utilization >= 50 && ( + + )} + {(state.contextTokens !== undefined || state.isCompacting) && (() => { + const tokens = state.contextTokens ?? 0; + const win = state.contextWindow ?? (state.cli === "codex" ? 256_000 : 200_000); + return ; + })()} + {queueCount > 0 && ( + + ⏳ {queueCount} queued + + )} + {controlsOpen && ( <> diff --git a/surfaces/webview/src/state/store.tsx b/surfaces/webview/src/state/store.tsx index 96e12bad..d7df271c 100644 --- a/surfaces/webview/src/state/store.tsx +++ b/surfaces/webview/src/state/store.tsx @@ -136,10 +136,7 @@ export interface State { contextWindow?: number; // account-wide plan rate-limit utilization (claude.ai), for the "running low" gauge. // Unlike context, this is NOT reset on a new chat — it tracks the plan, not the session. - limitPct?: number; // 0-100 utilization of the active window - limitWindow?: string; // 'five_hour' | 'seven_day' | ... - limitResetsAt?: number; // epoch ms when the active window resets - limitStatus?: string; // 'allowed' | 'allowed_warning' | 'rejected' + rateLimits: Partial>>; isCompacting: boolean; currentModel?: string; // live model catalog per engine, seeded from the static baseline and upgraded when the @@ -165,7 +162,8 @@ export function isApprovalForView(a: { sessionId?: string }, activeSessionId?: s return !a.sessionId || !activeSessionId || a.sessionId === activeSessionId; } -const initialState: State = { +export const initialState: State = { + rateLimits: {}, phase: "connecting", walletAddress: null, cli: "claude", @@ -313,7 +311,7 @@ type LocalAction = | { type: "__clearCelebrate" }; type Action = ServerMessage | LocalAction; -function reducer(state: State, ev: Action): State { +export function reducer(state: State, ev: Action): State { switch (ev.type) { case "__typing": return { ...state, typing: true }; @@ -396,10 +394,10 @@ function reducer(state: State, ev: Action): State { // percentage so the gauge never unmounts on a status change. return { ...state, - limitPct: ev.utilization ?? state.limitPct, - limitWindow: ev.window, - limitResetsAt: ev.resetsAt, - limitStatus: ev.status, + rateLimits: { + ...state.rateLimits, + [ev.cli]: { ...ev, utilization: ev.utilization ?? state.rateLimits[ev.cli]?.utilization }, + }, }; case "__compactStart": return { ...state, isCompacting: true }; From 2d1704901f81c4568d2ea93232e0961e53631e3f Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:31:58 -0400 Subject: [PATCH 2/2] test: keep late Claude quota isolated from custom engines --- packages/core/test/webview-rate-limit.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/test/webview-rate-limit.spec.js b/packages/core/test/webview-rate-limit.spec.js index 3a1532f9..6f37df76 100644 --- a/packages/core/test/webview-rate-limit.spec.js +++ b/packages/core/test/webview-rate-limit.spec.js @@ -34,3 +34,10 @@ describe("webview plan limits", () => { expect(state.rateLimits.claude?.utilization).toBe(100); }); }); + +it("keeps a late Claude quota out of Custom when that engine is available", () => { + let state = reducer(initialState, { type: "platform", cli: "custom" }); + state = reducer(state, { type: "rateLimit", cli: "claude", utilization: 91, status: "allowed" }); + expect(state.rateLimits[state.cli]).toBeUndefined(); + expect(state.rateLimits.claude.utilization).toBe(91); +});