The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 20:45 UTC
fix(web,mobile): Limits bars show the even-pace mark as a tick in a gap (#22408)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 20, 2026 at 11:32 UTC
5d4c202e3f5be0993efea751ca0f0bd4dedb64d4
10 files changed
+912
-64
apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+58
-15
@@ -41,6 +41,53 @@ function accountName(account: LimitAccount) {
41
return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase() || "Account";
42
}
43
44
+// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
45
+function PaceGap({
46
+ timeLeft,
47
+ children,
48
+}: {
49
+ readonly timeLeft: number | null;
50
+ readonly children: ReactNode;
51
+}) {
52
+ const [width, setWidth] = useState(0);
53
+ const tickX =
54
+ timeLeft === null || width < 6
55
+ ? null
56
+ : Math.min(Math.max((width * timeLeft) / 100, 3), width - 3);
57
+ return (
58
+ <View
59
+ pointerEvents="none"
60
+ className="absolute inset-0"
61
+ onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
62
+ >
63
+ {tickX === null
64
+ ? children
65
+ : (
66
+ [
67
+ [0, tickX - 3],
68
+ [tickX + 3, width],
69
+ ] as const
70
+ ).map(([start, end]) => (
71
+ <View
72
+ key={start}
73
+ className="absolute top-0 bottom-0 overflow-hidden"
74
+ style={{ left: start, width: end - start }}
75
+ >
76
+ <View className="absolute top-0 bottom-0" style={{ left: -start, width }}>
77
+ {children}
78
+ </View>
79
+ </View>
80
+ ))}
81
+ {tickX !== null ? (
82
+ <View
83
+ className="absolute top-0.5 bottom-0.5 w-0.5 rounded-full bg-foreground"
84
+ style={{ left: tickX - 1 }}
85
+ />
86
+ ) : null}
87
+ </View>
88
+ );
89
+}
90
+
91
function AccountSegment({
92
remaining,
93
color,
@@ -155,22 +202,18 @@ function PoolWindowCard({
202
accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
203
accessibilityHint="Show account details"
204
onPress={() => openAccount(account)}
158
- className="h-7 min-w-0 flex-1 rounded-md bg-subtle"
205
+ className="h-7 min-w-0 flex-1 rounded-md"
206
>
160
- <View className="absolute inset-0 overflow-hidden rounded-md">
161
- <AccountSegment
162
- remaining={remainingPercent(window)}
163
- color={color}
164
- refillPercent={window.resetsAt ? member.refillPercent : 0}
165
- />
166
- </View>
167
- {timeLeft !== null ? (
168
- <View
169
- pointerEvents="none"
170
- className="absolute -top-1 -bottom-1 w-0.5 -translate-x-px rounded-full bg-foreground-muted"
171
- style={{ left: `${timeLeft}%` }}
172
- />
173
- ) : null}
207
+ <PaceGap timeLeft={timeLeft}>
208
+ <View className="absolute inset-0 rounded-md bg-subtle" />
209
+ <View className="absolute inset-0 overflow-hidden rounded-md">
210
+ <AccountSegment
211
+ remaining={remainingPercent(window)}
212
+ color={color}
213
+ refillPercent={window.resetsAt ? member.refillPercent : 0}
214
+ />
215
+ </View>
216
+ </PaceGap>
217
<View
218
pointerEvents="none"
219
className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"
apps/mobile/src/features/usage/UsageLimitsSection.tsx
+54
-20
@@ -49,6 +49,32 @@ function WindowRow(props: {
49
const timeLeft = paceRemainingPercent(window, now);
50
const pace = paceOf(window, now);
51
const resetsIn = formatResetsIn(window, now);
52
+ const [barWidth, setBarWidth] = useState(0);
53
+ const tickX =
54
+ timeLeft === null || barWidth < 6
55
+ ? null
56
+ : Math.min(Math.max((barWidth * timeLeft) / 100, 3), barWidth - 3);
57
+ const bar = (
58
+ <View
59
+ className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle"
60
+ style={barWidth > 0 ? { width: barWidth } : undefined}
61
+ >
62
+ <View
63
+ className={
64
+ remaining <= 10
65
+ ? "h-full rounded-full bg-red-500"
66
+ : remaining <= 30
67
+ ? "h-full rounded-full bg-amber-500"
68
+ : "h-full rounded-full bg-foreground"
69
+ }
70
+ style={[
71
+ { flex: remaining },
72
+ remaining > 30 && props.color ? { backgroundColor: props.color } : null,
73
+ ]}
74
+ />
75
+ <View style={{ flex: 100 - remaining }} />
76
+ </View>
77
+ );
78
return (
79
<View className="gap-1">
80
<View className="flex-row items-baseline justify-between gap-3">
@@ -57,27 +83,35 @@ function WindowRow(props: {
83
{remaining}% left
84
</Text>
85
</View>
60
- <View className="h-3 justify-center">
61
- <View className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle">
62
- <View
63
- className={
64
- remaining <= 10
65
- ? "h-full rounded-full bg-red-500"
66
- : remaining <= 30
67
- ? "h-full rounded-full bg-amber-500"
68
- : "h-full rounded-full bg-foreground"
69
- }
70
- style={[
71
- { flex: remaining },
72
- remaining > 30 && props.color ? { backgroundColor: props.color } : null,
73
- ]}
74
- />
75
- <View style={{ flex: 100 - remaining }} />
76
- </View>
77
- {timeLeft !== null ? (
86
+ <View
87
+ className="h-3 justify-center"
88
+ onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
89
+ >
90
+ {tickX === null ? (
91
+ bar
92
+ ) : (
93
+ <View className="h-1.5">
94
+ {/* Clip the same full-width bar so neither fill proportions nor corner radii change. */}
95
+ {(
96
+ [
97
+ [0, tickX - 3],
98
+ [tickX + 3, barWidth],
99
+ ] as const
100
+ ).map(([start, end]) => (
101
+ <View
102
+ key={start}
103
+ className="absolute top-0 bottom-0 overflow-hidden"
104
+ style={{ left: start, width: end - start }}
105
+ >
106
+ <View style={{ marginLeft: -start }}>{bar}</View>
107
+ </View>
108
+ ))}
109
+ </View>
110
+ )}
111
+ {tickX !== null ? (
112
<View
79
- className="absolute top-0 bottom-0 w-px bg-foreground"
80
- style={{ left: `${timeLeft}%`, opacity: 0.6 }}
113
+ className="absolute top-px bottom-px w-0.5 rounded-full bg-foreground"
114
+ style={{ left: tickX - 1 }}
115
/>
116
) : null}
117
</View>
apps/web/src/components/usage/UsageLimits.browser.test.tsx
new
+89
@@ -0,0 +1,89 @@
1
+import { render } from "../../../test/render";
2
+import { ProviderDriverKind, type ServerProviderUsageWindow } from "@t3tools/contracts";
3
+import { expect, it, vi } from "vite-plus/test";
4
+import { page } from "vite-plus/test/browser";
5
+
6
+import "~/index.css";
7
+
8
+vi.mock("../../state/session", () => ({
9
+ useEnvironmentScope: () => true,
10
+ readEnvironmentScope: () => true,
11
+}));
12
+vi.mock("../../state/server", () => ({ serverEnvironment: { consumeResetCredit: null } }));
13
+vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
14
+vi.mock("../../hooks/useSettings", () => ({ usePrimarySettings: () => "24h" }));
15
+
16
+import { LimitWindows } from "./UsageLimits";
17
+
18
+const codex = ProviderDriverKind.make("codex");
19
+const now = Date.parse("2026-09-03T12:00:00Z");
20
+
21
+const sessionWindow = (minutesUntilReset: number | null): ServerProviderUsageWindow => ({
22
+ id: "five_hour",
23
+ kind: "session",
24
+ label: "Session",
25
+ usedPercent: 40,
26
+ ...(minutesUntilReset === null
27
+ ? {}
28
+ : {
29
+ windowDurationMins: 300,
30
+ resetsAt: new Date(now + minutesUntilReset * 60_000).toISOString(),
31
+ }),
32
+});
33
+
34
+const sized = (width: string) => {
35
+ const container = document.createElement("div");
36
+ container.style.width = width;
37
+ return container;
38
+};
39
+
40
+const bar = () => {
41
+ const element = page.getByRole("img", { name: /^Session:/ }).element();
42
+ const mark = element.querySelector(":scope > span[aria-hidden]");
43
+ return {
44
+ rect: element.getBoundingClientRect(),
45
+ mark: mark?.getBoundingClientRect(),
46
+ clip: getComputedStyle(element.querySelector(":scope > div")!).clipPath,
47
+ };
48
+};
49
+
50
+it("places the even-pace tick in a gap at the share of the window left", async () => {
51
+ await using _screen = await render(
52
+ <LimitWindows driver={codex} windows={[sessionWindow(90)]} now={now} />,
53
+ { container: sized("640px") },
54
+ );
55
+ const { rect, mark, clip } = bar();
56
+ expect(mark!.left + mark!.width / 2 - rect.left).toBeCloseTo(rect.width * 0.3, 0);
57
+ expect(clip).toMatch(/^polygon/);
58
+});
59
+
60
+it("keeps the tick inside the bar at both ends of the window", async () => {
61
+ for (const minutesUntilReset of [0, 300]) {
62
+ await using _screen = await render(
63
+ <LimitWindows driver={codex} windows={[sessionWindow(minutesUntilReset)]} now={now} />,
64
+ { container: sized("640px") },
65
+ );
66
+ const { rect, mark } = bar();
67
+ expect(mark!.left).toBeGreaterThanOrEqual(rect.left);
68
+ expect(mark!.right).toBeLessThanOrEqual(rect.right);
69
+ }
70
+});
71
+
72
+it("draws a continuous bar when the window timing is unknown", async () => {
73
+ await using _screen = await render(
74
+ <LimitWindows driver={codex} windows={[sessionWindow(null)]} now={now} />,
75
+ { container: sized("640px") },
76
+ );
77
+ expect(bar()).toMatchObject({ mark: undefined, clip: "none" });
78
+});
79
+
80
+it("draws neither gap nor tick on a bar narrower than 6px", async () => {
81
+ // 11rem + 1rem + 3.5px + 1rem + 7rem: the bar column gets 3.5px.
82
+ await using _screen = await render(
83
+ <LimitWindows driver={codex} windows={[sessionWindow(300)]} now={now} />,
84
+ { container: sized("323.5px") },
85
+ );
86
+ const { rect, mark, clip } = bar();
87
+ expect(rect.width).toBeCloseTo(3.5, 1);
88
+ expect({ mark, clip }).toEqual({ mark: undefined, clip: "none" });
89
+});
apps/web/src/components/usage/UsageLimits.tsx
+54
-11
@@ -18,9 +18,10 @@ import {
18
remainingPercent,
19
} from "@t3tools/shared/usageLimits";
20
import { GaugeIcon, TrendingDownIcon, TrendingUpIcon } from "lucide-react";
21
-import { Fragment, type ReactNode, useState } from "react";
21
+import { Fragment, type ReactNode, useLayoutEffect, useState } from "react";
22
23
import { usePrimarySettings } from "../../hooks/useSettings";
24
+import { observeResize } from "../../lib/observeResize";
25
import { environmentPresentations } from "../../state/presentation";
26
import { useEnvironmentScope, readEnvironmentScope } from "../../state/session";
27
import { serverEnvironment } from "../../state/server";
@@ -73,6 +74,43 @@ export function PaceIcon({ pace }: { readonly pace: LimitPace }) {
74
);
75
}
76
77
+// The tick sits in a transparent gap cut from the bar, clamped so it stays inside at 0% and 100%.
78
+// The gap is a clip-path slot rather than a mask: a mask composites its layer and re-antialiases
79
+// the bar's rounded ends, and the polygon reaches 1px past the box so only the slot edges clip.
80
+function paceMarkStyles(timeLeft: number | null) {
81
+ if (timeLeft === null) return null;
82
+ const at = `clamp(3px, ${timeLeft}%, calc(100% - 3px))`;
83
+ const [left, right] = [`calc(${at} - 3px)`, `calc(${at} + 3px)`];
84
+ const [near, far] = ["-1px", "calc(100% + 1px)"];
85
+ return {
86
+ tick: { left: at },
87
+ gap: {
88
+ clipPath: `polygon(${near} ${near}, ${left} ${near}, ${left} ${far}, ${right} ${far}, ${right} ${near}, ${far} ${near}, ${far} ${far}, ${near} ${far})`,
89
+ },
90
+ // For a track painted on an element that also draws focus rings, which a clip would cut.
91
+ gappedTrack: {
92
+ backgroundColor: "transparent",
93
+ backgroundImage: `linear-gradient(to right, var(--color-muted) ${left}, transparent ${left}, transparent ${right}, var(--color-muted) ${right})`,
94
+ },
95
+ };
96
+}
97
+
98
+/**
99
+ * Pace mark styles for the bar given the returned ref. Below 6px there is no room for the gap
100
+ * and tick, so the bar draws neither, as the mobile bars do.
101
+ */
102
+export function usePaceMark(timeLeft: number | null) {
103
+ const [bar, setBar] = useState<HTMLElement | null>(null);
104
+ const [roomy, setRoomy] = useState(false);
105
+ useLayoutEffect(() => {
106
+ if (!bar) return;
107
+ const measure = () => setRoomy(bar.getBoundingClientRect().width >= 6);
108
+ measure();
109
+ return observeResize(bar, measure);
110
+ }, [bar]);
111
+ return [setBar, roomy ? paceMarkStyles(timeLeft) : null] as const;
112
+}
113
+
114
function WindowBar({
115
color,
116
window,
@@ -85,6 +123,7 @@ function WindowBar({
123
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
124
const remaining = remainingPercent(window);
125
const timeLeft = paceRemainingPercent(window, now);
126
+ const [barRef, paceMark] = usePaceMark(timeLeft);
127
const resetsIn = formatResetsIn(window, now);
128
const resetsAt = window.resetsAt
129
? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)
@@ -98,6 +137,7 @@ function WindowBar({
137
<TooltipTrigger
138
render={
139
<div
140
+ ref={barRef}
141
role="img"
142
aria-label={summary}
143
tabIndex={0}
@@ -105,18 +145,21 @@ function WindowBar({
145
/>
146
}
147
>
108
- <div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
109
- {remaining > 0 ? (
110
- <div
111
- className="absolute inset-y-1.5 left-0 rounded-full"
112
- style={{ width: `${remaining}%`, backgroundColor: color }}
113
- />
114
- ) : null}
115
- {timeLeft !== null ? (
148
+ {/* Clip both layers so the gap exposes even a translucent composer surface. */}
149
+ <div className="absolute inset-0" style={paceMark?.gap}>
150
+ <div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
151
+ {remaining > 0 ? (
152
+ <div
153
+ className="absolute inset-y-1.5 left-0 rounded-full"
154
+ style={{ width: `${remaining}%`, backgroundColor: color }}
155
+ />
156
+ ) : null}
157
+ </div>
158
+ {paceMark ? (
159
<span
160
aria-hidden
118
- className="absolute inset-y-0.5 w-px -translate-x-1/2 bg-foreground/60"
119
- style={{ left: `${timeLeft}%` }}
161
+ className="absolute inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
162
+ style={paceMark.tick}
163
/>
164
) : null}
165
</TooltipTrigger>
apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
+17
@@ -177,6 +177,23 @@ it("omits an empty reset plate but keeps countdowns and banked credits visible",
177
expect(plate()?.textContent).toBe("1");
178
});
179
180
+it("cuts the pace gap through the segment track and keeps the tick inside it", async () => {
181
+ setup();
182
+ // Five hours before the reset is the start of the window, the right-hand end of the bar.
183
+ await using _screen = await render(
184
+ <UsageLimitsPooled
185
+ presentations={presentations("2026-09-03T14:00:00Z", 0)}
186
+ now={Date.parse("2026-09-03T09:00:00Z")}
187
+ />,
188
+ );
189
+ const segment = page.getByRole("button", { name: /^Alpha:/ }).element();
190
+ const tick = segment.querySelector(':scope > span[style*="left"]')!.getBoundingClientRect();
191
+ const rect = segment.getBoundingClientRect();
192
+ expect(getComputedStyle(segment).backgroundImage).toMatch(/^linear-gradient/);
193
+ expect(tick.left).toBeGreaterThanOrEqual(rect.left);
194
+ expect(tick.right).toBeLessThanOrEqual(rect.right);
195
+});
196
+
197
it("moves the one limit popover between windows on hover", async () => {
198
setup();
199
await using screen = await render(initial());
apps/web/src/components/usage/UsageLimitsPooled.tsx
+22
-16
@@ -42,6 +42,7 @@ import {
42
PaceIcon,
43
ResetCreditDialog,
44
barColor,
45
+ usePaceMark,
46
resetCreditsSummary,
47
useResetCredit,
48
} from "./UsageLimits";
@@ -342,6 +343,7 @@ function SegmentTriggers({
343
const payload: SegmentPayload = { account, window, reset, redeem };
344
const remaining = remainingPercent(window);
345
const timeLeft = paceRemainingPercent(window, now);
346
+ const [segmentRef, paceMark] = usePaceMark(timeLeft);
347
const resetsIn = formatResetsIn(window, now);
348
const credits = account.limits.resetCredits?.availableCount ?? 0;
349
return (
@@ -352,35 +354,39 @@ function SegmentTriggers({
354
openOnHover
355
render={
356
<button
357
+ ref={segmentRef}
358
type="button"
356
- style={{ gridColumn: index, gridRow: 1 }}
359
+ style={{ gridColumn: index, gridRow: 1, ...paceMark?.gappedTrack }}
360
aria-label={`${account.displayName ?? (account.email ? accountInitials(account.email) : account.driver)}: ${remaining}% left${resetsIn ? `, ${resetsIn}` : ""}${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}${credits ? `, ${credits} reset ${credits === 1 ? "credit" : "credits"} banked` : ""}`}
361
className="relative h-5 min-w-0 cursor-pointer rounded-md bg-muted text-start outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[popup-open]:ring-1 data-[popup-open]:ring-inset data-[popup-open]:ring-border @2xl/pool:h-8"
362
/>
363
}
364
>
365
<div aria-hidden className="absolute inset-0 overflow-hidden rounded-md">
363
- <div
364
- aria-hidden
365
- className="absolute inset-y-0 left-0 rounded-md opacity-35"
366
- style={{ width: `${remaining}%`, backgroundColor: color }}
367
- />
368
- {remaining < 100 && reset && refillPercent > 0 ? (
366
+ {/* Clipped inside the rounded clip so the bar's own corners keep their antialiasing. */}
367
+ <div className="absolute inset-0" style={paceMark?.gap}>
368
<div
369
aria-hidden
371
- className="absolute inset-y-0 right-0 opacity-20"
372
- style={{
373
- width: `${Math.min(100 - remaining, refillPercent)}%`,
374
- backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
375
- }}
370
+ className="absolute inset-y-0 left-0 rounded-md opacity-35"
371
+ style={{ width: `${remaining}%`, backgroundColor: color }}
372
/>
377
- ) : null}
373
+ {remaining < 100 && reset && refillPercent > 0 ? (
374
+ <div
375
+ aria-hidden
376
+ className="absolute inset-y-0 right-0 opacity-20"
377
+ style={{
378
+ width: `${Math.min(100 - remaining, refillPercent)}%`,
379
+ backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
380
+ }}
381
+ />
382
+ ) : null}
383
+ </div>
384
</div>
379
- {timeLeft !== null ? (
385
+ {paceMark ? (
386
<span
387
aria-hidden
382
- className="absolute -inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-muted-foreground"
383
- style={{ left: `${timeLeft}%` }}
388
+ className="absolute inset-y-0.5 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
389
+ style={paceMark.tick}
390
/>
391
) : null}
392
<span
apps/web/test/fixtures/usage-limits-hub/README.md
new
+8
@@ -0,0 +1,8 @@
1
+# Usage limits hub fixture
2
+
3
+A fake CLIProxyAPI hub that serves the Limits evidence scenarios in `scenarios.json`
4
+(A mixed, B one account per provider, C six long-named Codex accounts, L named accounts,
5
+T forty accounts). Run `node hub.mjs state.json 18517` with `state.json` set to
6
+`{"scenario": "A", "n0": <epoch ms>}`, add `http://127.0.0.1:18517` with any management key
7
+under Settings → Usage limit sources in a dev server, and freeze the browser clock at `n0`.
8
+Edit `state.json` and press Refresh limits to switch scenarios.
apps/web/test/fixtures/usage-limits-hub/hub.mjs
new
+91
@@ -0,0 +1,91 @@
1
+// Fake CLIProxyAPI management API serving the Limits scenarios in scenarios.json.
2
+// Usage: node hub.mjs <state.json> [port]. state.json is {"scenario": "A", "n0": <epoch ms>};
3
+// it is re-read on every request, so edit it and press Refresh limits to switch scenarios.
4
+import * as NodeFS from "node:fs";
5
+import * as NodeHttp from "node:http";
6
+
7
+const [statePath, port = "18517"] = process.argv.slice(2);
8
+if (!statePath) throw new Error("usage: node hub.mjs <state.json> [port]");
9
+const scenarios = JSON.parse(
10
+ NodeFS.readFileSync(new URL("./scenarios.json", import.meta.url), "utf8"),
11
+);
12
+const MINUTE = 60_000;
13
+
14
+// A window is [usedPercent, minutesFromN0 | null]; null is unknown reset timing.
15
+const at = (n0, minutes) => (minutes === null ? null : n0 + minutes * MINUTE);
16
+const usage = (account, n0) => {
17
+ const [session, weekly, fable] = account.windows;
18
+ if (account.provider === "codex") {
19
+ const window = ([used, minutes], seconds) => ({
20
+ used_percent: used,
21
+ reset_at: at(n0, minutes) === null ? null : Math.floor(at(n0, minutes) / 1000),
22
+ limit_window_seconds: seconds,
23
+ });
24
+ return {
25
+ plan_type: "pro",
26
+ rate_limit: {
27
+ primary_window: window(session, 18_000),
28
+ secondary_window: window(weekly, 604_800),
29
+ },
30
+ };
31
+ }
32
+ const window = ([used, minutes]) => ({
33
+ utilization: used,
34
+ resets_at: at(n0, minutes) === null ? null : new Date(at(n0, minutes)).toISOString(),
35
+ });
36
+ return {
37
+ five_hour: window(session),
38
+ seven_day: window(weekly),
39
+ limits: fable
40
+ ? [
41
+ {
42
+ kind: "weekly_scoped",
43
+ percent: fable[0],
44
+ resets_at: window(fable).resets_at,
45
+ scope: { model: { display_name: "Fable" } },
46
+ },
47
+ ]
48
+ : [],
49
+ };
50
+};
51
+
52
+const json = (response, body) => {
53
+ response.writeHead(200, { "content-type": "application/json" });
54
+ response.end(JSON.stringify(body));
55
+};
56
+
57
+NodeHttp.createServer((request, response) => {
58
+ let raw = "";
59
+ request.on("data", (chunk) => (raw += chunk));
60
+ request.on("end", () => {
61
+ const { scenario, n0 } = JSON.parse(NodeFS.readFileSync(statePath, "utf8"));
62
+ const accounts = scenarios[scenario];
63
+ if (!accounts) return json(response, { files: [] });
64
+ if (request.url.endsWith("/v0/management/auth-files")) {
65
+ return json(response, {
66
+ files: Object.entries(accounts).map(([id, account]) => ({
67
+ id,
68
+ auth_index: id,
69
+ provider: account.provider,
70
+ ...(account.email ? { email: account.email } : {}),
71
+ })),
72
+ });
73
+ }
74
+ if (request.url.endsWith("/v0/management/api-call")) {
75
+ const call = JSON.parse(raw);
76
+ const account = accounts[call.auth_index];
77
+ if (!account) return json(response, { status_code: 404, body: "{}" });
78
+ if (call.url.endsWith("/rate-limit-reset-credits")) {
79
+ const credits = Array.from({ length: account.credits ?? 0 }, (_, index) => ({
80
+ id: `${call.auth_index}-credit-${index}`,
81
+ status: "available",
82
+ reset_type: "codex_rate_limits",
83
+ expires_at: new Date(n0 + 3 * 24 * 60 * MINUTE).toISOString(),
84
+ }));
85
+ return json(response, { status_code: 200, body: JSON.stringify({ credits }) });
86
+ }
87
+ return json(response, { status_code: 200, body: JSON.stringify(usage(account, n0)) });
88
+ }
89
+ response.writeHead(404).end();
90
+ });
91
+}).listen(Number(port), "127.0.0.1", () => console.log(`usage limits hub on ${port}`));
apps/web/test/fixtures/usage-limits-hub/scenarios.json
new
+516
@@ -0,0 +1,516 @@
1
+{
2
+ "A": {
3
+ "c1": {
4
+ "provider": "codex",
5
+ "email": "c1.codex.owner@example.com",
6
+ "windows": [
7
+ [30, 120],
8
+ [60, 7560.0]
9
+ ]
10
+ },
11
+ "c2": {
12
+ "provider": "codex",
13
+ "email": "c2.codex.owner@example.com",
14
+ "windows": [
15
+ [0, 310],
16
+ [40, null]
17
+ ]
18
+ },
19
+ "c3": {
20
+ "provider": "codex",
21
+ "email": "c3.codex.owner@example.com",
22
+ "windows": [
23
+ [20, -1],
24
+ [50, 5040.0]
25
+ ],
26
+ "credits": 2
27
+ },
28
+ "a1": {
29
+ "provider": "claude",
30
+ "email": "a1.claude.owner@example.com",
31
+ "windows": [
32
+ [50, 150.0],
33
+ [10, 9273.6],
34
+ [0, 10140]
35
+ ]
36
+ },
37
+ "a2": {
38
+ "provider": "claude",
39
+ "email": "a2.claude.owner@example.com",
40
+ "windows": [
41
+ [100, 60],
42
+ [92, 5040.0],
43
+ [75, 7200]
44
+ ]
45
+ },
46
+ "a3": {
47
+ "provider": "claude",
48
+ "email": "a3.claude.owner@example.com",
49
+ "windows": [
50
+ [30, 180],
51
+ [100, 120]
52
+ ]
53
+ }
54
+ },
55
+ "B": {
56
+ "c1": {
57
+ "provider": "codex",
58
+ "email": "c1.codex.owner@example.com",
59
+ "windows": [
60
+ [30, 120],
61
+ [60, 7560.0]
62
+ ]
63
+ },
64
+ "a1": {
65
+ "provider": "claude",
66
+ "email": "a1.claude.owner@example.com",
67
+ "windows": [
68
+ [50, 150.0],
69
+ [10, 9273.6],
70
+ [0, 10140]
71
+ ]
72
+ }
73
+ },
74
+ "C": {
75
+ "m1": {
76
+ "provider": "codex",
77
+ "email": "firstname1.lastname.contractor@example-company.com",
78
+ "windows": [
79
+ [0, 310],
80
+ [0, 10140]
81
+ ]
82
+ },
83
+ "m2": {
84
+ "provider": "codex",
85
+ "email": "firstname2.lastname.contractor@example-company.com",
86
+ "windows": [
87
+ [100, -1],
88
+ [100, 60]
89
+ ]
90
+ },
91
+ "m3": {
92
+ "provider": "codex",
93
+ "email": "firstname3.lastname.contractor@example-company.com",
94
+ "windows": [
95
+ [45, 165.0],
96
+ [30, 7200]
97
+ ]
98
+ },
99
+ "m4": {
100
+ "provider": "codex",
101
+ "email": "firstname4.lastname.contractor@example-company.com",
102
+ "windows": [
103
+ [10, 30.0],
104
+ [80, 8640]
105
+ ]
106
+ },
107
+ "m5": {
108
+ "provider": "codex",
109
+ "email": "firstname5.lastname.contractor@example-company.com",
110
+ "windows": [
111
+ [40, null],
112
+ [40, null]
113
+ ]
114
+ },
115
+ "m6": {
116
+ "provider": "codex",
117
+ "email": "firstname6.lastname.contractor@example-company.com",
118
+ "windows": [
119
+ [60, 240],
120
+ [5, 1440]
121
+ ]
122
+ }
123
+ },
124
+ "L": {
125
+ "platform-team-primary": {
126
+ "provider": "codex",
127
+ "windows": [
128
+ [30, 120],
129
+ [60, 7560.0]
130
+ ]
131
+ },
132
+ "platform-team-backup": {
133
+ "provider": "codex",
134
+ "windows": [
135
+ [0, 310],
136
+ [40, null]
137
+ ]
138
+ },
139
+ "contractor-shared-pool": {
140
+ "provider": "codex",
141
+ "windows": [
142
+ [20, -1],
143
+ [50, 9072.0]
144
+ ],
145
+ "credits": 2
146
+ },
147
+ "research-lab-claude-seat-1": {
148
+ "provider": "claude",
149
+ "windows": [
150
+ [50, 150.0],
151
+ [10, 9273.6],
152
+ [0, 10140]
153
+ ]
154
+ },
155
+ "research-lab-claude-seat-2": {
156
+ "provider": "claude",
157
+ "windows": [
158
+ [100, 60],
159
+ [92, 5040.0],
160
+ [75, 7200]
161
+ ]
162
+ },
163
+ "research-lab-claude-seat-3": {
164
+ "provider": "claude",
165
+ "windows": [
166
+ [30, 180],
167
+ [100, 120]
168
+ ]
169
+ },
170
+ "research-lab-claude-seat-4": {
171
+ "provider": "claude",
172
+ "windows": [
173
+ [50, 150.0],
174
+ [10, 9273.6],
175
+ [0, 10140]
176
+ ]
177
+ },
178
+ "research-lab-claude-seat-5": {
179
+ "provider": "claude",
180
+ "windows": [
181
+ [100, 60],
182
+ [92, 5040.0],
183
+ [75, 7200]
184
+ ]
185
+ },
186
+ "research-lab-claude-seat-6": {
187
+ "provider": "claude",
188
+ "windows": [
189
+ [30, 180],
190
+ [100, 120]
191
+ ]
192
+ }
193
+ },
194
+ "T": {
195
+ "t01": {
196
+ "provider": "codex",
197
+ "email": "t01@example.com",
198
+ "windows": [
199
+ [7, 37],
200
+ [13, 697]
201
+ ]
202
+ },
203
+ "t02": {
204
+ "provider": "codex",
205
+ "email": "t02@example.com",
206
+ "windows": [
207
+ [14, 44],
208
+ [26, 794]
209
+ ]
210
+ },
211
+ "t03": {
212
+ "provider": "codex",
213
+ "email": "t03@example.com",
214
+ "windows": [
215
+ [21, 51],
216
+ [39, 891]
217
+ ]
218
+ },
219
+ "t04": {
220
+ "provider": "codex",
221
+ "email": "t04@example.com",
222
+ "windows": [
223
+ [28, 58],
224
+ [52, 988]
225
+ ]
226
+ },
227
+ "t05": {
228
+ "provider": "codex",
229
+ "email": "t05@example.com",
230
+ "windows": [
231
+ [35, 65],
232
+ [65, 1085]
233
+ ]
234
+ },
235
+ "t06": {
236
+ "provider": "codex",
237
+ "email": "t06@example.com",
238
+ "windows": [
239
+ [42, 72],
240
+ [78, 1182]
241
+ ]
242
+ },
243
+ "t07": {
244
+ "provider": "codex",
245
+ "email": "t07@example.com",
246
+ "windows": [
247
+ [49, 79],
248
+ [91, 1279]
249
+ ]
250
+ },
251
+ "t08": {
252
+ "provider": "codex",
253
+ "email": "t08@example.com",
254
+ "windows": [
255
+ [56, 86],
256
+ [4, 1376]
257
+ ]
258
+ },
259
+ "t09": {
260
+ "provider": "codex",
261
+ "email": "t09@example.com",
262
+ "windows": [
263
+ [63, 93],
264
+ [17, 1473]
265
+ ]
266
+ },
267
+ "t10": {
268
+ "provider": "codex",
269
+ "email": "t10@example.com",
270
+ "windows": [
271
+ [70, 100],
272
+ [30, 1570]
273
+ ]
274
+ },
275
+ "t11": {
276
+ "provider": "codex",
277
+ "email": "t11@example.com",
278
+ "windows": [
279
+ [77, 107],
280
+ [43, 1667]
281
+ ]
282
+ },
283
+ "t12": {
284
+ "provider": "codex",
285
+ "email": "t12@example.com",
286
+ "windows": [
287
+ [84, 114],
288
+ [56, 1764]
289
+ ]
290
+ },
291
+ "t13": {
292
+ "provider": "codex",
293
+ "email": "t13@example.com",
294
+ "windows": [
295
+ [91, 121],
296
+ [69, 1861]
297
+ ]
298
+ },
299
+ "t14": {
300
+ "provider": "codex",
301
+ "email": "t14@example.com",
302
+ "windows": [
303
+ [98, 128],
304
+ [82, 1958]
305
+ ]
306
+ },
307
+ "t15": {
308
+ "provider": "codex",
309
+ "email": "t15@example.com",
310
+ "windows": [
311
+ [5, 135],
312
+ [95, 2055]
313
+ ]
314
+ },
315
+ "t16": {
316
+ "provider": "codex",
317
+ "email": "t16@example.com",
318
+ "windows": [
319
+ [12, 142],
320
+ [8, 2152]
321
+ ]
322
+ },
323
+ "t17": {
324
+ "provider": "codex",
325
+ "email": "t17@example.com",
326
+ "windows": [
327
+ [19, 149],
328
+ [21, 2249]
329
+ ]
330
+ },
331
+ "t18": {
332
+ "provider": "codex",
333
+ "email": "t18@example.com",
334
+ "windows": [
335
+ [26, 156],
336
+ [34, 2346]
337
+ ]
338
+ },
339
+ "t19": {
340
+ "provider": "codex",
341
+ "email": "t19@example.com",
342
+ "windows": [
343
+ [33, 163],
344
+ [47, 2443]
345
+ ]
346
+ },
347
+ "t20": {
348
+ "provider": "codex",
349
+ "email": "t20@example.com",
350
+ "windows": [
351
+ [40, 170],
352
+ [60, 2540]
353
+ ]
354
+ },
355
+ "t21": {
356
+ "provider": "codex",
357
+ "email": "t21@example.com",
358
+ "windows": [
359
+ [47, 177],
360
+ [73, 2637]
361
+ ]
362
+ },
363
+ "t22": {
364
+ "provider": "codex",
365
+ "email": "t22@example.com",
366
+ "windows": [
367
+ [54, 184],
368
+ [86, 2734]
369
+ ]
370
+ },
371
+ "t23": {
372
+ "provider": "codex",
373
+ "email": "t23@example.com",
374
+ "windows": [
375
+ [61, 191],
376
+ [99, 2831]
377
+ ]
378
+ },
379
+ "t24": {
380
+ "provider": "codex",
381
+ "email": "t24@example.com",
382
+ "windows": [
383
+ [68, 198],
384
+ [12, 2928]
385
+ ]
386
+ },
387
+ "t25": {
388
+ "provider": "codex",
389
+ "email": "t25@example.com",
390
+ "windows": [
391
+ [75, 205],
392
+ [25, 3025]
393
+ ]
394
+ },
395
+ "t26": {
396
+ "provider": "codex",
397
+ "email": "t26@example.com",
398
+ "windows": [
399
+ [82, 212],
400
+ [38, 3122]
401
+ ]
402
+ },
403
+ "t27": {
404
+ "provider": "codex",
405
+ "email": "t27@example.com",
406
+ "windows": [
407
+ [89, 219],
408
+ [51, 3219]
409
+ ]
410
+ },
411
+ "t28": {
412
+ "provider": "codex",
413
+ "email": "t28@example.com",
414
+ "windows": [
415
+ [96, 226],
416
+ [64, 3316]
417
+ ]
418
+ },
419
+ "t29": {
420
+ "provider": "codex",
421
+ "email": "t29@example.com",
422
+ "windows": [
423
+ [3, 233],
424
+ [77, 3413]
425
+ ]
426
+ },
427
+ "t30": {
428
+ "provider": "codex",
429
+ "email": "t30@example.com",
430
+ "windows": [
431
+ [10, 240],
432
+ [90, 3510]
433
+ ]
434
+ },
435
+ "t31": {
436
+ "provider": "codex",
437
+ "email": "t31@example.com",
438
+ "windows": [
439
+ [17, 247],
440
+ [3, 3607]
441
+ ]
442
+ },
443
+ "t32": {
444
+ "provider": "codex",
445
+ "email": "t32@example.com",
446
+ "windows": [
447
+ [24, 254],
448
+ [16, 3704]
449
+ ]
450
+ },
451
+ "t33": {
452
+ "provider": "codex",
453
+ "email": "t33@example.com",
454
+ "windows": [
455
+ [31, 261],
456
+ [29, 3801]
457
+ ]
458
+ },
459
+ "t34": {
460
+ "provider": "codex",
461
+ "email": "t34@example.com",
462
+ "windows": [
463
+ [38, 268],
464
+ [42, 3898]
465
+ ]
466
+ },
467
+ "t35": {
468
+ "provider": "codex",
469
+ "email": "t35@example.com",
470
+ "windows": [
471
+ [45, 275],
472
+ [55, 3995]
473
+ ]
474
+ },
475
+ "t36": {
476
+ "provider": "codex",
477
+ "email": "t36@example.com",
478
+ "windows": [
479
+ [52, 282],
480
+ [68, 4092]
481
+ ]
482
+ },
483
+ "t37": {
484
+ "provider": "codex",
485
+ "email": "t37@example.com",
486
+ "windows": [
487
+ [59, 289],
488
+ [81, 4189]
489
+ ]
490
+ },
491
+ "t38": {
492
+ "provider": "codex",
493
+ "email": "t38@example.com",
494
+ "windows": [
495
+ [66, 296],
496
+ [94, 4286]
497
+ ]
498
+ },
499
+ "t39": {
500
+ "provider": "codex",
501
+ "email": "t39@example.com",
502
+ "windows": [
503
+ [73, 33],
504
+ [7, 4383]
505
+ ]
506
+ },
507
+ "t40": {
508
+ "provider": "codex",
509
+ "email": "t40@example.com",
510
+ "windows": [
511
+ [80, 40],
512
+ [20, 4480]
513
+ ]
514
+ }
515
+ }
516
+}
knip.jsonc
+3
-2
@@ -69,8 +69,9 @@
69
"ignoreDependencies": ["playwright-core", "electron-builder"],
70
},
71
"apps/web": {
72
- // Worktree setup (scripts/setup-worktree.ts) runs this directly.
73
- "entry": ["scripts/warm-dep-cache.ts"],
72
+ // Worktree setup (scripts/setup-worktree.ts) runs this directly, and evidence
73
+ // fixtures run under node.
74
+ "entry": ["scripts/warm-dep-cache.ts", "test/fixtures/**/*.mjs"],
75
// UI component modules are copied and adapted as cohesive sets. Keep their
76
// named subcomponents even before they have callers; the file audit still
77
// reports an entire component module when nothing imports it.