@devries-cameron20 / t3code-1 / commits / 9ff05979ee
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(mobile): Usage uses the width on iPad and unfolded phones (#26061)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 11:25 UTC 9ff05979ee7a40f21fd47db62415cc51be2fe890
2 files changed +522 -273
apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+202 -85
@@ -31,6 +31,7 @@ import { usageProviderKind, useProviderColors } from "./usageProviders";
31 const DRIVER_LABEL: Partial<Record<string, string>> = {
32 codex: "Codex",
33 claudeAgent: "Claude",
34 + grok: "Grok",
35 antigravity: "Antigravity",
36 };
37 const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace" } as const;
@@ -38,8 +39,35 @@ const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace"
39 function accountName(account: LimitAccount) {
40 if (account.displayName) return account.displayName;
41 if (!account.email) return DRIVER_LABEL[account.driver] ?? String(account.driver);
41 - const [local = "", domain = ""] = account.email.split("@");
42 - return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase() || "Account";
42 + return emailInitials(account.email) || "Account";
43 +}
44 +
45 +function emailInitials(email: string) {
46 + const [local = "", domain = ""] = email.split("@");
47 + return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase();
48 +}
49 +
50 +function accountHue(email: string) {
51 + let hash = 0;
52 + for (let index = 0; index < email.length; index += 1) {
53 + hash = (hash * 31 + email.charCodeAt(index)) | 0;
54 + }
55 + return Math.abs(hash) % 360;
56 +}
57 +
58 +// Same hashed hue as the web account chip, so an account keeps its color across clients.
59 +function AccountChip({ email }: { readonly email: string }) {
60 + const hue = accountHue(email);
61 + return (
62 + <View
63 + className="size-5 items-center justify-center rounded-full"
64 + style={{ backgroundColor: `hsl(${hue}, 45%, 82%)` }}
65 + >
66 + <Text className="text-[9px] font-t3-bold" style={{ color: `hsl(${hue}, 45%, 28%)` }}>
67 + {emailInitials(email)}
68 + </Text>
69 + </View>
70 + );
71 }
72
73 // Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
@@ -141,6 +169,7 @@ function PoolWindowCard({
169 environmentIds,
170 label,
171 description,
172 + wide,
173 }: {
174 readonly pool: LimitPoolWindow;
175 readonly color: string;
@@ -148,8 +177,15 @@ function PoolWindowCard({
177 readonly environmentIds: readonly string[] | null;
178 readonly label?: string;
179 readonly description?: string;
180 + readonly wide: boolean;
181 }) {
182 const navigation = useNavigation();
183 + const [barWidth, setBarWidth] = useState(0);
184 + // Each segment needs room for its account, percent and reset to label itself.
185 + const segmentWidth = barWidth / Math.max(pool.columns.length, 1);
186 + const inlineLabels = wide && segmentWidth >= 96;
187 + const inlineReset = wide && segmentWidth >= 150;
188 + const inlineName = wide && segmentWidth >= 220;
189 const nextRefill = pool.resets.find((reset) => reset.restoresPercent > 0);
190 const openAccount = (account: LimitAccount) =>
191 navigation.navigate("SettingsUsageAccount", {
@@ -159,9 +195,9 @@ function PoolWindowCard({
195 environmentIds,
196 now,
197 });
162 - return (
163 - <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
164 - <View className="flex-row items-start justify-between gap-3">
198 + const summary = (
199 + <>
200 + <View className={wide ? "gap-1" : "flex-row items-start justify-between gap-3"}>
201 <View className="gap-1">
202 <Text className="text-sm font-t3-medium text-foreground">{label ?? pool.label}</Text>
203 <View className="flex-row items-baseline gap-1.5">
@@ -184,31 +220,89 @@ function PoolWindowCard({
220 .replace("resets now", "now")}
221 </Text>
222 ) : null}
187 - <View className="flex-row gap-1">
188 - {pool.columns.map((member, index) => {
189 - if (!member.window)
190 - return <View key={member.account.key} className="h-7 min-w-0 flex-1" />;
191 - const { account, window } = member;
192 - const timeLeft = paceRemainingPercent(window, now);
223 + </>
224 + );
225 + const bar = (
226 + <View
227 + className="flex-row gap-1"
228 + onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
229 + >
230 + {pool.columns.map((member, index) => {
231 + if (!member.window)
232 return (
194 - <Pressable
195 - key={account.key}
196 - accessibilityRole="button"
197 - accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
198 - accessibilityHint="Show account details"
199 - onPress={() => openAccount(account)}
200 - className="h-7 min-w-0 flex-1 rounded-md"
201 - >
202 - <PaceGap timeLeft={timeLeft}>
203 - <View className="absolute inset-0 rounded-md bg-subtle" />
204 - <View className="absolute inset-0 overflow-hidden rounded-md">
205 - <AccountSegment
206 - remaining={remainingPercent(window)}
207 - color={color}
208 - refillPercent={window.resetsAt ? member.refillPercent : 0}
209 - />
233 + <View
234 + key={member.account.key}
235 + className={wide ? "h-9 min-w-0 flex-1" : "h-7 min-w-0 flex-1"}
236 + />
237 + );
238 + const { account, window } = member;
239 + const timeLeft = paceRemainingPercent(window, now);
240 + const credits = account.limits.resetCredits?.availableCount ?? 0;
241 + const resetsIn = formatResetsIn(window, now)?.replace("resets in ", "");
242 + return (
243 + <Pressable
244 + key={account.key}
245 + accessibilityRole="button"
246 + accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
247 + accessibilityHint="Show account details"
248 + onPress={() => openAccount(account)}
249 + className={wide ? "h-9 min-w-0 flex-1 rounded-md" : "h-7 min-w-0 flex-1 rounded-md"}
250 + >
251 + <PaceGap timeLeft={timeLeft}>
252 + <View className="absolute inset-0 rounded-md bg-subtle" />
253 + <View className="absolute inset-0 overflow-hidden rounded-md">
254 + <AccountSegment
255 + remaining={remainingPercent(window)}
256 + color={color}
257 + refillPercent={window.resetsAt ? member.refillPercent : 0}
258 + />
259 + </View>
260 + </PaceGap>
261 + {inlineLabels ? (
262 + <View
263 + pointerEvents="none"
264 + className="absolute inset-0 flex-row items-center justify-between gap-2 overflow-hidden rounded-md px-2"
265 + >
266 + <View className="min-w-0 shrink flex-row items-center gap-1.5">
267 + {account.email ? <AccountChip email={account.email} /> : null}
268 + {account.email && !(account.displayName && inlineName) ? null : (
269 + <Text
270 + numberOfLines={1}
271 + className="min-w-0 shrink text-xs font-t3-medium text-foreground"
272 + >
273 + {accountName(account)}
274 + </Text>
275 + )}
276 + <Text className="text-sm font-t3-bold tabular-nums text-foreground">
277 + {remainingPercent(window)}%
278 + </Text>
279 </View>
211 - </PaceGap>
280 + {inlineReset && (resetsIn || credits) ? (
281 + <View className="shrink-0 flex-row items-center gap-1 rounded bg-grouped-card/85 px-1.5 py-0.5">
282 + {resetsIn ? (
283 + <>
284 + <SymbolView
285 + name="arrow.clockwise"
286 + size={11}
287 + tintColorClassName="accent-foreground-muted"
288 + />
289 + <Text className="text-xs tabular-nums text-foreground-muted">
290 + {resetsIn}
291 + </Text>
292 + </>
293 + ) : null}
294 + {credits ? (
295 + <>
296 + <SymbolView name="ticket" size={12} tintColorClassName="accent-icon" />
297 + <Text className="text-xs font-t3-medium tabular-nums text-foreground">
298 + {credits}
299 + </Text>
300 + </>
301 + ) : null}
302 + </View>
303 + ) : null}
304 + </View>
305 + ) : (
306 <View
307 pointerEvents="none"
308 className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"
@@ -220,65 +314,85 @@ function PoolWindowCard({
314 {index + 1}
315 </Text>
316 </View>
223 - </Pressable>
224 - );
225 - })}
226 - </View>
227 - <View>
228 - {pool.columns.map(({ account, window }, index) => {
229 - if (!window) return null;
230 - const credits = account.limits.resetCredits?.availableCount ?? 0;
231 - const resetsIn = formatResetsIn(window, now);
232 - return (
233 - <Pressable
234 - key={account.key}
235 - accessibilityRole="button"
236 - accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${resetsIn ? `, ${resetsIn}` : ""}${credits ? `, ${credits} reset credits banked` : ""}`}
237 - accessibilityHint="Show account details"
238 - onPress={() => openAccount(account)}
239 - className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"
240 - >
241 - <View className="size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">
242 - <Text className="text-xs font-t3-medium tabular-nums text-foreground">
243 - {index + 1}
244 - </Text>
245 - </View>
246 - <Text
247 - numberOfLines={1}
248 - className="min-w-0 flex-1 text-sm font-t3-medium text-foreground"
249 - >
250 - {accountName(account)}
251 - </Text>
252 - <Text className="text-sm font-t3-medium tabular-nums text-foreground">
253 - {remainingPercent(window)}%
317 + )}
318 + </Pressable>
319 + );
320 + })}
321 + </View>
322 + );
323 + const legend = (
324 + <View>
325 + {pool.columns.map(({ account, window }, index) => {
326 + if (!window) return null;
327 + const credits = account.limits.resetCredits?.availableCount ?? 0;
328 + const resetsIn = formatResetsIn(window, now);
329 + return (
330 + <Pressable
331 + key={account.key}
332 + accessibilityRole="button"
333 + accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${resetsIn ? `, ${resetsIn}` : ""}${credits ? `, ${credits} reset credits banked` : ""}`}
334 + accessibilityHint="Show account details"
335 + onPress={() => openAccount(account)}
336 + className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"
337 + >
338 + <View className="size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">
339 + <Text className="text-xs font-t3-medium tabular-nums text-foreground">
340 + {index + 1}
341 </Text>
255 - <View className="flex-row items-center gap-1">
256 - {resetsIn ? (
257 - <>
258 - <SymbolView
259 - name="arrow.clockwise"
260 - size={12}
261 - tintColorClassName="accent-foreground-muted"
262 - />
263 - <Text className="text-xs tabular-nums text-foreground-muted">
264 - {resetsIn.replace("resets in ", "")}
265 - </Text>
266 - </>
267 - ) : null}
268 - {credits ? (
269 - <>
270 - {resetsIn ? <Text className="text-xs text-foreground-tertiary">·</Text> : null}
271 - <SymbolView name="ticket" size={13} tintColorClassName="accent-icon" />
272 - <Text className="text-xs font-t3-medium tabular-nums text-foreground">
273 - {credits}
274 - </Text>
275 - </>
276 - ) : null}
277 - </View>
278 - </Pressable>
279 - );
280 - })}
342 + </View>
343 + <Text
344 + numberOfLines={1}
345 + className="min-w-0 flex-1 text-sm font-t3-medium text-foreground"
346 + >
347 + {accountName(account)}
348 + </Text>
349 + <Text className="text-sm font-t3-medium tabular-nums text-foreground">
350 + {remainingPercent(window)}%
351 + </Text>
352 + <View className="flex-row items-center gap-1">
353 + {resetsIn ? (
354 + <>
355 + <SymbolView
356 + name="arrow.clockwise"
357 + size={12}
358 + tintColorClassName="accent-foreground-muted"
359 + />
360 + <Text className="text-xs tabular-nums text-foreground-muted">
361 + {resetsIn.replace("resets in ", "")}
362 + </Text>
363 + </>
364 + ) : null}
365 + {credits ? (
366 + <>
367 + {resetsIn ? <Text className="text-xs text-foreground-tertiary">·</Text> : null}
368 + <SymbolView name="ticket" size={13} tintColorClassName="accent-icon" />
369 + <Text className="text-xs font-t3-medium tabular-nums text-foreground">
370 + {credits}
371 + </Text>
372 + </>
373 + ) : null}
374 + </View>
375 + </Pressable>
376 + );
377 + })}
378 + </View>
379 + );
380 + if (wide) {
381 + return (
382 + <View className="flex-row items-center gap-6 rounded-[24px] border-continuous bg-grouped-card p-4">
383 + <View className="w-44 gap-1">{summary}</View>
384 + <View className="min-w-0 flex-1 gap-1">
385 + {bar}
386 + {inlineLabels ? null : legend}
387 + </View>
388 </View>
389 + );
390 + }
391 + return (
392 + <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
393 + {summary}
394 + {bar}
395 + {legend}
396 </View>
397 );
398 }
@@ -288,11 +402,13 @@ export function UsageLimitsSection({
402 failedLabels,
403 selectedEnvironmentIds,
404 cursorPrompt,
405 + wide = false,
406 }: {
407 readonly now: number;
408 readonly failedLabels: readonly string[];
409 readonly selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
410 readonly cursorPrompt?: ReactNode;
411 + readonly wide?: boolean;
412 }) {
413 const presentations = useAtomValue(environmentPresentations.presentationsWithProvidersAtom);
414 const selected =
@@ -347,6 +463,7 @@ export function UsageLimitsSection({
463 }
464 label={details?.label}
465 description={details?.description}
466 + wide={wide}
467 />
468 );
469 })}
apps/mobile/src/features/usage/UsageRouteScreen.tsx
+320 -188
@@ -54,11 +54,12 @@ import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";
54 import type { UsageChartMetric } from "./usageChartData";
55 import { PROVIDER_LABEL, useProviderColors, useUsageMixColors } from "./usageProviders";
56
57 -type UsageTab = "usage" | "limits";
58 -const TAB_OPTIONS = [
59 - { value: "usage", label: "Usage" },
57 +type UsageView = UsageChartMetric | "limits";
58 +const VIEW_OPTIONS = [
59 + { value: "cost", label: "Cost" },
60 + { value: "tokens", label: "Tokens" },
61 { value: "limits", label: "Limits" },
61 -] as const satisfies readonly { value: UsageTab; label: string }[];
62 +] as const satisfies readonly { value: UsageView; label: string }[];
63
64 const WINDOW_OPTIONS = [
65 { value: 1, label: "24h", accessibilityLabel: "Past 24 hours" },
@@ -67,12 +68,11 @@ const WINDOW_OPTIONS = [
68 { value: 90, label: "90d", accessibilityLabel: "Past 90 days" },
69 ] as const;
70
70 -const METRIC_OPTIONS = [
71 - { value: "cost", label: "Cost" },
72 - { value: "tokens", label: "Tokens" },
73 -] as const satisfies readonly { value: UsageChartMetric; label: string }[];
74 -
71 const CHART_HEIGHT = 180;
72 +const WIDE_CHART_HEIGHT = 260;
73 +// Below this the page keeps the phone's single column.
74 +const WIDE_WIDTH = 600;
75 +const MAX_CONTENT_WIDTH = 1080;
76 const providerLabel = (provider: UsageProviderKind) => PROVIDER_LABEL[provider];
77 const CURSOR_KEYCHAIN_COPY = "Requires access to your Cursor login in macOS Keychain.";
78
@@ -88,21 +88,22 @@ function UsageScreen(props: {
88 const insets = useSafeAreaInsets();
89 const [selection, setSelection] = useState(() => ({
90 params: props.tabParam,
91 - tab: (props.tabParam === "usage" ? "usage" : "limits") as UsageTab,
91 + view: (props.tabParam === "usage" ? "cost" : "limits") as UsageView,
92 }));
93 if (selection.params !== props.tabParam) {
94 setSelection({
95 params: props.tabParam,
96 - tab: props.tabParam === "usage" ? "usage" : "limits",
96 + view: props.tabParam === "usage" ? "cost" : "limits",
97 });
98 }
99 - const { tab } = selection;
100 - const setTab = (tab: UsageTab) => setSelection({ params: props.tabParam, tab });
99 + const { view } = selection;
100 + const setView = (view: UsageView) => setSelection({ params: props.tabParam, view });
101 + const [width, setWidth] = useState(0);
102 + const wide = width >= WIDE_WIDTH;
103 const [windowSelection, setWindowSelection] = useState(() => ({
104 days: 30,
105 window: makeWindow(30),
106 }));
105 - const [metric, setMetric] = useState<UsageChartMetric>("cost");
107 const { days: windowDays, window } = windowSelection;
108 const isPast24Hours = windowDays === 1;
109 const [selectedEnvironmentIds, setSelectedEnvironmentIds] =
@@ -112,7 +113,7 @@ function UsageScreen(props: {
113 selectedEnvironmentIds,
114 );
115 const isFocused = useIsFocused();
115 - const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && tab === "limits");
116 + const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && view === "limits");
117 const cursorAccessEnvironments = cursorKeychainAccessEnvironments(selectedEnvironments);
118 const refreshAfterCursorEnable = () => {
119 void refresh();
@@ -154,7 +155,8 @@ function UsageScreen(props: {
155
156 const [refreshingUsage, setRefreshingUsage] = useState(false);
157 const refreshingRef = useRef(false);
157 - const showingLimits = tab === "limits";
158 + const showingLimits = view === "limits";
159 + const metric: UsageChartMetric = view === "tokens" ? "tokens" : "cost";
160 const progress = usageProgress(selectedEnvironments, {
161 refreshing: refreshingUsage,
162 providerLabel,
@@ -184,6 +186,27 @@ function UsageScreen(props: {
186 });
187 };
188
189 + const chart = {
190 + merged,
191 + days: chartDays,
192 + daily: chartTotals,
193 + metric,
194 + sinceDay: window.sinceDay,
195 + untilDay: window.untilDay,
196 + isPast24Hours,
197 + timeZone: window.timeZone,
198 + };
199 + const providers = (
200 + <ProviderSection
201 + merged={merged}
202 + metric={metric}
203 + cursorAccessEnvironments={cursorAccessEnvironments}
204 + showCursorEnvironment={selectedEnvironments.length > 1}
205 + onCursorEnabled={refreshAfterCursorEnable}
206 + compact={wide}
207 + />
208 + );
209 +
210 const showEnvironmentFilter = environments.length > 0 || selectedEnvironmentIds !== null;
211 const filterIcon =
212 selectedEnvironmentIds === null
@@ -271,8 +294,9 @@ function UsageScreen(props: {
294 contentInsetAdjustmentBehavior="automatic"
295 showsVerticalScrollIndicator={false}
296 className="flex-1"
274 - contentContainerClassName="gap-6 px-5 pt-4"
297 + contentContainerClassName="px-5 pt-4"
298 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
299 + onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
300 refreshControl={
301 showingLimits || canReadDiagnostics ? (
302 <RefreshControl
@@ -282,107 +306,141 @@ function UsageScreen(props: {
306 ) : undefined
307 }
308 >
285 - <SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={setTab} role="tab" />
286 - <Animated.View
287 - key={tab}
288 - entering={FadeIn.duration(160).reduceMotion(ReduceMotion.System)}
289 - className="gap-6"
290 - >
291 - {showingLimits ? (
292 - <UsageLimitsSection
293 - now={limits.now}
294 - failedLabels={limits.failedLabels}
295 - selectedEnvironmentIds={selectedEnvironmentIds}
296 - cursorPrompt={
297 - cursorAccessEnvironments.length > 0 ? (
298 - <CursorEnableLimits
299 - environments={cursorAccessEnvironments}
300 - onEnabled={refreshAfterCursorEnable}
301 - />
302 - ) : null
303 - }
304 - />
305 - ) : (
306 - <>
307 - <View className="gap-3 ios:flex-row ios:items-center">
309 + <View className="w-full gap-6 self-center" style={{ maxWidth: MAX_CONTENT_WIDTH }}>
310 + {wide ? (
311 + <View className="flex-row items-center gap-3">
312 + {showingLimits ? (
313 + <View className="flex-1" />
314 + ) : (
315 <SegmentedControl
316 options={WINDOW_OPTIONS}
317 selected={windowDays}
318 onSelect={selectWindow}
319 size="compact"
313 - className="w-full ios:flex-1"
314 - />
315 - <SegmentedControl
316 - options={METRIC_OPTIONS}
317 - selected={metric}
318 - onSelect={setMetric}
319 - size="compact"
320 - className="w-full ios:w-36"
320 + className="flex-1"
321 />
322 - </View>
323 - <ChatGptUsageSummary selectedEnvironmentIds={selectedEnvironmentIds} />
324 - {merged.duplicateSources.length > 0 ? (
325 - <Text className="text-sm text-foreground-muted">
326 - Counted once across environments sharing a transcript directory:{" "}
327 - {merged.duplicateSources.join(", ")}
328 - </Text>
329 - ) : null}
330 - {isPending ? (
331 - <Text className="py-16 text-center text-base text-foreground-muted">
332 - Scanning provider transcripts…
333 - </Text>
334 - ) : selectedEnvironments.length === 0 ? (
335 - <Text className="py-16 text-center text-base text-foreground-muted">
336 - {environments.length === 0
337 - ? "Connect an environment to see usage."
338 - : "Select an environment to see usage."}
339 - </Text>
340 - ) : !canReadDiagnostics ? (
341 - <View className="gap-2 py-16">
342 - {selectedEnvironments.map((environment) => (
343 - <Text
344 - key={environment.environmentId}
345 - className="text-center text-base text-foreground-muted"
346 - >
347 - {selectedEnvironments.length > 1 ? `${environment.label}: ` : null}
348 - {environment.error}
349 - </Text>
350 - ))}
351 - </View>
352 - ) : (
353 - <>
354 - {sourceMessages.map((message) => (
355 - <Text key={message} className="text-sm text-foreground-muted">
356 - {message}
357 - </Text>
358 - ))}
359 - <UsageUpdating dimmed={progress.dimmed} label={progress.label}>
360 - <ChartCard
361 - merged={merged}
362 - days={chartDays}
363 - daily={chartTotals}
364 - metric={metric}
365 - sinceDay={window.sinceDay}
366 - untilDay={window.untilDay}
367 - isPast24Hours={isPast24Hours}
368 - timeZone={window.timeZone}
369 - />
370 - <ProviderSection
371 - merged={merged}
372 - metric={metric}
373 - cursorAccessEnvironments={cursorAccessEnvironments}
374 - showCursorEnvironment={selectedEnvironments.length > 1}
375 - onCursorEnabled={refreshAfterCursorEnable}
376 - />
377 - <TotalsSection merged={merged} isPast24Hours={isPast24Hours} />
378 - <CostSection merged={merged} />
379 - <ModelsSection merged={merged} metric={metric} />
380 - </UsageUpdating>
381 - </>
322 )}
383 - </>
323 + <SegmentedControl
324 + options={VIEW_OPTIONS}
325 + selected={view}
326 + onSelect={setView}
327 + size="compact"
328 + role="tab"
329 + className="w-60"
330 + />
331 + </View>
332 + ) : (
333 + <SegmentedControl
334 + options={VIEW_OPTIONS}
335 + selected={view}
336 + onSelect={setView}
337 + role="tab"
338 + />
339 )}
385 - </Animated.View>
340 + <Animated.View
341 + key={showingLimits ? "limits" : "usage"}
342 + entering={FadeIn.duration(160).reduceMotion(ReduceMotion.System)}
343 + className="gap-6"
344 + >
345 + {showingLimits ? (
346 + <UsageLimitsSection
347 + now={limits.now}
348 + failedLabels={limits.failedLabels}
349 + selectedEnvironmentIds={selectedEnvironmentIds}
350 + wide={wide}
351 + cursorPrompt={
352 + cursorAccessEnvironments.length > 0 ? (
353 + <CursorEnableLimits
354 + environments={cursorAccessEnvironments}
355 + onEnabled={refreshAfterCursorEnable}
356 + />
357 + ) : null
358 + }
359 + />
360 + ) : (
361 + <>
362 + {wide ? null : (
363 + <SegmentedControl
364 + options={WINDOW_OPTIONS}
365 + selected={windowDays}
366 + onSelect={selectWindow}
367 + size="compact"
368 + />
369 + )}
370 + <ChatGptUsageSummary selectedEnvironmentIds={selectedEnvironmentIds} />
371 + {merged.duplicateSources.length > 0 ? (
372 + <Text className="text-sm text-foreground-muted">
373 + Counted once across environments sharing a transcript directory:{" "}
374 + {merged.duplicateSources.join(", ")}
375 + </Text>
376 + ) : null}
377 + {isPending ? (
378 + <Text className="py-16 text-center text-base text-foreground-muted">
379 + Scanning provider transcripts…
380 + </Text>
381 + ) : selectedEnvironments.length === 0 ? (
382 + <Text className="py-16 text-center text-base text-foreground-muted">
383 + {environments.length === 0
384 + ? "Connect an environment to see usage."
385 + : "Select an environment to see usage."}
386 + </Text>
387 + ) : !canReadDiagnostics ? (
388 + <View className="gap-2 py-16">
389 + {selectedEnvironments.map((environment) => (
390 + <Text
391 + key={environment.environmentId}
392 + className="text-center text-base text-foreground-muted"
393 + >
394 + {selectedEnvironments.length > 1 ? `${environment.label}: ` : null}
395 + {environment.error}
396 + </Text>
397 + ))}
398 + </View>
399 + ) : (
400 + <>
401 + {sourceMessages.map((message) => (
402 + <Text key={message} className="text-sm text-foreground-muted">
403 + {message}
404 + </Text>
405 + ))}
406 + <UsageUpdating dimmed={progress.dimmed} label={progress.label}>
407 + {wide ? (
408 + <View className="flex-row gap-6">
409 + <View className="w-72 gap-6">
410 + <View className="rounded-[24px] border-continuous bg-grouped-card p-4">
411 + <UsageSummary merged={merged} metric={metric} />
412 + </View>
413 + {providers}
414 + </View>
415 + <View className="min-w-0 flex-1">
416 + <ChartCard
417 + {...chart}
418 + height={WIDE_CHART_HEIGHT}
419 + fill
420 + title={`${isPast24Hours ? "Hourly" : "Daily"} ${metric === "cost" ? "cost" : "processed tokens"}`}
421 + />
422 + </View>
423 + </View>
424 + ) : (
425 + <>
426 + <ChartCard {...chart} height={CHART_HEIGHT} />
427 + {providers}
428 + </>
429 + )}
430 + <TotalsSection
431 + merged={merged}
432 + isPast24Hours={isPast24Hours}
433 + columns={width >= 900 ? 6 : wide ? 3 : 2}
434 + />
435 + <CostSection merged={merged} wide={wide} />
436 + <ModelsSection merged={merged} metric={metric} columns={wide ? 2 : 1} />
437 + </UsageUpdating>
438 + </>
439 + )}
440 + </>
441 + )}
442 + </Animated.View>
443 + </View>
444 </ScrollView>
445 </SettingsScreen>
446 );
@@ -536,38 +594,46 @@ function ChartCard(props: {
594 readonly untilDay: string;
595 readonly isPast24Hours: boolean;
596 readonly timeZone: string;
597 + readonly height: number;
598 + /** Replaces the summary when it sits beside the chart. */
599 + readonly title?: string;
600 + /** Grows the chart past `height` to match a taller neighbouring column. */
601 + readonly fill?: boolean;
602 }) {
603 const { merged, metric } = props;
604 const colors = useProviderColors();
605 const hasActivity = props.daily.some((period) => period.totalTokens > 0);
606 + const [fillHeight, setFillHeight] = useState(0);
607 + const height = props.fill ? Math.max(fillHeight, props.height) : props.height;
608 + const chart = hasActivity ? (
609 + <UsageDailyChart days={props.days} daily={props.daily} metric={metric} height={height} />
610 + ) : (
611 + <View style={{ height }} className="items-center justify-center">
612 + <Text className="text-base text-foreground-muted">No activity in this window.</Text>
613 + </View>
614 + );
615
616 return (
545 - <View className="gap-4 rounded-[24px] border-continuous bg-grouped-card p-4">
546 - <View className="gap-0.5">
547 - <Text className="text-sm text-foreground-muted">
548 - {metric === "cost" ? "Raw token cost" : "Processed tokens"}
549 - </Text>
550 - <Text className="text-4xl font-t3-bold tabular-nums text-foreground">
551 - {metric === "cost" ? `${formatUsd(merged.costUsd)}*` : formatTokens(merged.totalTokens)}
552 - </Text>
553 - <Text className="text-sm text-foreground-muted">
554 - {metric === "cost"
555 - ? "* if billed at full API rate"
556 - : `Across ${formatCount(merged.sessions)} sessions`}
557 - </Text>
558 - </View>
559 -
560 - {hasActivity ? (
561 - <UsageDailyChart
562 - days={props.days}
563 - daily={props.daily}
564 - metric={metric}
565 - height={CHART_HEIGHT}
566 - />
617 + <View
618 + className={`gap-4 rounded-[24px] border-continuous bg-grouped-card p-4${props.fill ? " flex-1" : ""}`}
619 + >
620 + {props.title ? (
621 + <Text className="text-sm font-t3-medium text-foreground">{props.title}</Text>
622 ) : (
568 - <View style={{ height: CHART_HEIGHT }} className="items-center justify-center">
569 - <Text className="text-base text-foreground-muted">No activity in this window.</Text>
623 + <UsageSummary merged={merged} metric={metric} />
624 + )}
625 +
626 + {props.fill ? (
627 + // Absolute so the measured slot can shrink again when the neighbour gets shorter.
628 + <View
629 + className="flex-1"
630 + style={{ minHeight: props.height }}
631 + onLayout={(event) => setFillHeight(event.nativeEvent.layout.height)}
632 + >
633 + <View className="absolute inset-0">{chart}</View>
634 </View>
635 + ) : (
636 + chart
637 )}
638
639 <View className="gap-2">
@@ -601,12 +667,33 @@ function ChartCard(props: {
667 );
668 }
669
670 +function UsageSummary(props: { readonly merged: MergedUsage; readonly metric: UsageChartMetric }) {
671 + const { merged, metric } = props;
672 + return (
673 + <View className="gap-0.5">
674 + <Text className="text-sm text-foreground-muted">
675 + {metric === "cost" ? "Raw token cost" : "Processed tokens"}
676 + </Text>
677 + <Text className="text-4xl font-t3-bold tabular-nums text-foreground">
678 + {metric === "cost" ? `${formatUsd(merged.costUsd)}*` : formatTokens(merged.totalTokens)}
679 + </Text>
680 + <Text className="text-sm text-foreground-muted">
681 + {metric === "cost"
682 + ? "* if billed at full API rate"
683 + : `Across ${formatCount(merged.sessions)} sessions`}
684 + </Text>
685 + </View>
686 + );
687 +}
688 +
689 function ProviderSection(props: {
690 readonly merged: MergedUsage;
691 readonly metric: UsageChartMetric;
692 readonly cursorAccessEnvironments: readonly EnvironmentUsageStatus[];
693 readonly showCursorEnvironment: boolean;
694 readonly onCursorEnabled: () => void;
695 + /** Drops the share bar so the list fits beside the chart. */
696 + readonly compact: boolean;
697 }) {
698 const { merged, metric } = props;
699 const colors = useProviderColors();
@@ -654,7 +741,10 @@ function ProviderSection(props: {
741 return (
742 <View
743 key={provider.provider}
657 - className={index === 0 ? "gap-2 p-4" : "gap-2 border-t border-border-subtle p-4"}
744 + className={cn(
745 + props.compact ? "gap-0.5 px-4 py-3" : "gap-2 p-4",
746 + index > 0 && "border-t border-border-subtle",
747 + )}
748 >
749 <View className="flex-row items-baseline justify-between gap-3">
750 <View className="flex-row items-center gap-2">
@@ -662,21 +752,35 @@ function ProviderSection(props: {
752 className="size-2.5 rounded-full"
753 style={{ backgroundColor: colors[provider.provider] }}
754 />
665 - <Text className="text-lg text-foreground">{PROVIDER_LABEL[provider.provider]}</Text>
755 + <Text
756 + className={
757 + props.compact ? "text-base text-foreground" : "text-lg text-foreground"
758 + }
759 + >
760 + {PROVIDER_LABEL[provider.provider]}
761 + </Text>
762 </View>
667 - <Text className="text-lg tabular-nums text-foreground">
763 + <Text
764 + className={
765 + props.compact
766 + ? "text-base tabular-nums text-foreground"
767 + : "text-lg tabular-nums text-foreground"
768 + }
769 + >
770 {metric === "cost"
771 ? formatUsd(provider.costUsd)
772 : formatTokens(provider.totalTokens)}
773 </Text>
774 </View>
673 - <View className="h-1 flex-row overflow-hidden rounded-full bg-subtle">
674 - <View
675 - className="h-full rounded-full"
676 - style={{ flex: share, backgroundColor: colors[provider.provider] }}
677 - />
678 - <View style={{ flex: 1 - share }} />
679 - </View>
775 + {props.compact ? null : (
776 + <View className="h-1 flex-row overflow-hidden rounded-full bg-subtle">
777 + <View
778 + className="h-full rounded-full"
779 + style={{ flex: share, backgroundColor: colors[provider.provider] }}
780 + />
781 + <View style={{ flex: 1 - share }} />
782 + </View>
783 + )}
784 <Text className="text-sm text-foreground-muted">
785 {metric === "cost"
786 ? `${formatPercent(share)} of cost · ${formatTokens(provider.totalTokens)} tokens`
@@ -689,7 +793,11 @@ function ProviderSection(props: {
793 );
794 }
795
692 -function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24Hours: boolean }) {
796 +function TotalsSection(props: {
797 + readonly merged: MergedUsage;
798 + readonly isPast24Hours: boolean;
799 + readonly columns: number;
800 +}) {
801 const { merged } = props;
802 const activePeriods = (props.isPast24Hours ? merged.hourly : merged.daily).filter(
803 (period) => period.totalTokens > 0,
@@ -702,11 +810,13 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H
810 <SettingsSection title="Totals">
811 <View className="flex-row flex-wrap">
812 <MetricCell
813 + columns={props.columns}
814 label="Processed tokens"
815 value={formatTokens(merged.totalTokens)}
816 detail={`${formatTokens(periodAverage)} per active ${props.isPast24Hours ? "hour" : "day"}`}
817 />
818 <MetricCell
819 + columns={props.columns}
820 label="Cache savings"
821 value={formatUsd(merged.costQuality.cacheSavingsUsd)}
822 detail={
@@ -716,21 +826,25 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H
826 }
827 />
828 <MetricCell
829 + columns={props.columns}
830 label="Cached input"
831 value={formatTokens(merged.cachedInputTokens)}
832 detail={`${formatPercent(cachedShare)} of observed input`}
833 />
834 <MetricCell
835 + columns={props.columns}
836 label="Uncached input"
837 value={formatTokens(merged.uncachedInputTokens)}
838 detail={`${formatTokens(merged.cacheCreationTokens)} cache writes`}
839 />
840 <MetricCell
841 + columns={props.columns}
842 label="Output"
843 value={formatTokens(merged.outputTokens)}
844 detail={`incl. ${formatTokens(merged.reasoningTokens)} reasoning`}
845 />
846 <MetricCell
847 + columns={props.columns}
848 label="Unpriced"
849 value={formatPercent(merged.costQuality.unpricedShare)}
850 detail="of records, excluded from cost"
@@ -740,7 +854,7 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H
854 );
855 }
856
743 -function CostSection(props: { readonly merged: MergedUsage }) {
857 +function CostSection(props: { readonly merged: MergedUsage; readonly wide: boolean }) {
858 const { categoryCost, speedCost } = props.merged;
859 const colors = useUsageMixColors();
860 const byType = [
@@ -765,16 +879,26 @@ function CostSection(props: { readonly merged: MergedUsage }) {
879
880 return (
881 <SettingsSection title="Cost">
768 - <ShareBar label="By type" segments={byType} />
769 - {speedCost.fast + speedCost.ultrafast > 0 ? (
770 - <View className="border-t border-border-subtle">
771 - <ShareBar
772 - label="By speed"
773 - segments={bySpeed}
774 - aside={`${formatUsd(speedCost.premium)} premium`}
775 - />
882 + <View className={props.wide ? "flex-row" : undefined}>
883 + <View className={props.wide ? "min-w-0 flex-1" : undefined}>
884 + <ShareBar label="By type" segments={byType} />
885 </View>
777 - ) : null}
886 + {speedCost.fast + speedCost.ultrafast > 0 ? (
887 + <View
888 + className={
889 + props.wide
890 + ? "min-w-0 flex-1 border-l border-border-subtle"
891 + : "border-t border-border-subtle"
892 + }
893 + >
894 + <ShareBar
895 + label="By speed"
896 + segments={bySpeed}
897 + aside={`${formatUsd(speedCost.premium)} premium`}
898 + />
899 + </View>
900 + ) : null}
901 + </View>
902 </SettingsSection>
903 );
904 }
@@ -821,9 +945,10 @@ function MetricCell(props: {
945 readonly label: string;
946 readonly value: string;
947 readonly detail: string;
948 + readonly columns: number;
949 }) {
950 return (
826 - <View className="w-1/2 gap-0.5 p-4">
951 + <View className="gap-0.5 p-4" style={{ width: `${100 / props.columns}%` }}>
952 <Text className="text-sm text-foreground-muted">{props.label}</Text>
953 <Text className="text-xl font-t3-medium tabular-nums text-foreground">{props.value}</Text>
954 <Text className="text-xs text-foreground-tertiary">{props.detail}</Text>
@@ -831,7 +956,11 @@ function MetricCell(props: {
956 );
957 }
958
834 -function ModelsSection(props: { readonly merged: MergedUsage; readonly metric: UsageChartMetric }) {
959 +function ModelsSection(props: {
960 + readonly merged: MergedUsage;
961 + readonly metric: UsageChartMetric;
962 + readonly columns: 1 | 2;
963 +}) {
964 const { merged, metric } = props;
965 const colors = useProviderColors();
966 if (merged.models.length === 0) return null;
@@ -845,42 +974,45 @@ function ModelsSection(props: { readonly merged: MergedUsage; readonly metric: U
974
975 return (
976 <SettingsSection title="By model">
848 - {ordered.map((model, index) => (
849 - <View
850 - key={`${model.provider}:${model.model}`}
851 - className={
852 - index === 0
853 - ? "flex-row items-center gap-3 p-4"
854 - : "flex-row items-center gap-3 border-t border-border-subtle p-4"
855 - }
856 - >
977 + <View className="flex-row flex-wrap">
978 + {ordered.map((model, index) => (
979 <View
858 - className="size-2.5 shrink-0 rounded-full"
859 - style={{ backgroundColor: colors[model.provider] }}
860 - />
861 - <View className="min-w-0 flex-1 gap-0.5">
862 - <Text className="text-base text-foreground" numberOfLines={1}>
863 - {model.model}
864 - </Text>
865 - <Text className="text-sm text-foreground-muted">
980 + key={`${model.provider}:${model.model}`}
981 + className={cn(
982 + "flex-row items-center gap-3 p-4",
983 + index >= props.columns && "border-t border-border-subtle",
984 + index % props.columns === 1 && "border-l border-border-subtle",
985 + )}
986 + style={{ width: `${100 / props.columns}%` }}
987 + >
988 + <View
989 + className="size-2.5 shrink-0 rounded-full"
990 + style={{ backgroundColor: colors[model.provider] }}
991 + />
992 + <View className="min-w-0 flex-1 gap-0.5">
993 + <Text className="text-base text-foreground" numberOfLines={1}>
994 + {model.model}
995 + </Text>
996 + <Text className="text-sm text-foreground-muted">
997 + {metric === "tokens"
998 + ? `${formatPercent(model.tokenShare)} of tokens · ${
999 + isModelCostUnknown(model) ? "no known rates" : formatUsd(model.costUsd)
1000 + }`
1001 + : isModelCostUnknown(model)
1002 + ? `no known rates · ${formatTokens(model.totalTokens)} tokens`
1003 + : `${formatPercent(model.costShare)} of cost · ${formatTokens(model.totalTokens)} tokens`}
1004 + </Text>
1005 + </View>
1006 + <Text className="text-base tabular-nums text-foreground">
1007 {metric === "tokens"
867 - ? `${formatPercent(model.tokenShare)} of tokens · ${
868 - isModelCostUnknown(model) ? "no known rates" : formatUsd(model.costUsd)
869 - }`
1008 + ? formatTokens(model.totalTokens)
1009 : isModelCostUnknown(model)
871 - ? `no known rates · ${formatTokens(model.totalTokens)} tokens`
872 - : `${formatPercent(model.costShare)} of cost · ${formatTokens(model.totalTokens)} tokens`}
1010 + ? "Unpriced"
1011 + : formatUsd(model.costUsd)}
1012 </Text>
1013 </View>
875 - <Text className="text-base tabular-nums text-foreground">
876 - {metric === "tokens"
877 - ? formatTokens(model.totalTokens)
878 - : isModelCostUnknown(model)
879 - ? "Unpriced"
880 - : formatUsd(model.costUsd)}
881 - </Text>
882 - </View>
883 - ))}
1014 + ))}
1015 + </View>
1016 </SettingsSection>
1017 );
1018 }