Skip to content

Commit f6addd7

Browse files
committed
refactor(usage): keep this PR to the even-pace marks
1 parent 6693d58 commit f6addd7

5 files changed

Lines changed: 32 additions & 75 deletions

File tree

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
collectLimitPools,
99
cursorUsageWindowDetails,
1010
displayLimitWindows,
11-
formatPaceHeadroom,
1211
formatResetsIn,
1312
paceRemainingPercent,
1413
remainingPercent,
@@ -33,6 +32,7 @@ const DRIVER_LABEL: Partial<Record<string, string>> = {
3332
claudeAgent: "Claude",
3433
antigravity: "Antigravity",
3534
};
35+
const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace" } as const;
3636

3737
function accountName(account: LimitAccount) {
3838
if (account.displayName) return account.displayName;
@@ -99,7 +99,6 @@ function PoolWindowCard({
9999
readonly description?: string;
100100
}) {
101101
const navigation = useNavigation();
102-
// The soonest reset that hands anything back; an untouched account resets to no effect.
103102
const nextRefill = pool.resets.find((reset) => reset.restoresPercent > 0);
104103
const openAccount = (account: LimitAccount) =>
105104
navigation.navigate("SettingsSheet", {
@@ -125,28 +124,21 @@ function PoolWindowCard({
125124
{pool.remainingPercent}%
126125
</Text>
127126
<Text className="text-sm text-foreground-muted">left</Text>
128-
{nextRefill ? (
129-
<Text
130-
accessibilityLabel={`Pooled usage +${nextRefill.restoresPercent}% ${formatResetsIn(
131-
nextRefill.member.window,
132-
now,
133-
)
134-
?.replace("resets in ", "in ")
135-
.replace("resets now", "now")}`}
136-
className="text-xs tabular-nums text-foreground-muted"
137-
>
138-
↻ +{nextRefill.restoresPercent}%
139-
</Text>
140-
) : null}
141127
</View>
142128
</View>
143-
{pool.paceHeadroomPercent !== null ? (
144-
<Text className="text-xs tabular-nums text-foreground-tertiary">
145-
{formatPaceHeadroom(pool.paceHeadroomPercent)}
146-
</Text>
129+
{pool.pace ? (
130+
<Text className="text-xs text-foreground-tertiary">{PACE_LABEL[pool.pace]}</Text>
147131
) : null}
148132
</View>
149133
{description ? <Text className="text-xs text-foreground-muted">{description}</Text> : null}
134+
{nextRefill ? (
135+
<Text className="text-xs tabular-nums text-foreground-muted">
136+
↻ +{nextRefill.restoresPercent}%{" "}
137+
{formatResetsIn(nextRefill.member.window, now)
138+
?.replace("resets in ", "in ")
139+
.replace("resets now", "now")}
140+
</Text>
141+
) : null}
150142
<View className="flex-row gap-1">
151143
{pool.columns.map(({ account, window }, index) => {
152144
if (!window) return <View key={account.key} className="h-7 min-w-0 flex-1" />;

‎apps/web/src/components/usage/UsageLimits.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function barColor(driver: ServerProvider["driver"]): string {
6060
}
6161

6262
/** Pace as a glyph with the words on hover. */
63-
function PaceIcon({ pace }: { readonly pace: LimitPace }) {
63+
export function PaceIcon({ pace }: { readonly pace: LimitPace }) {
6464
const Icon = PACE[pace].icon;
6565
return (
6666
<Tooltip>

‎apps/web/src/components/usage/UsageLimitsPooled.tsx‎

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
collectLimitPools,
77
cursorUsageWindowDetails,
88
displayLimitWindows,
9-
formatPaceHeadroom,
109
formatResetsIn,
1110
type LimitAccount,
1211
type LimitPool,
@@ -29,8 +28,13 @@ import { Button } from "../ui/button";
2928
import { OpenAI } from "../Icons";
3029
import { Alert, AlertTitle } from "../ui/alert";
3130
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
32-
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
33-
import { ResetCreditDialog, barColor, resetCreditsSummary, useResetCredit } from "./UsageLimits";
31+
import {
32+
PaceIcon,
33+
ResetCreditDialog,
34+
barColor,
35+
resetCreditsSummary,
36+
useResetCredit,
37+
} from "./UsageLimits";
3438

3539
/** `[email protected]` → `SE`: enough to tell accounts apart, too little to identify one. */
3640
function accountInitials(email: string): string {
@@ -499,8 +503,7 @@ function PoolBar({
499503

500504
/**
501505
* Big pooled number and the segment bar. Accounts keep the same column across
502-
* windows; each segment's popover shows its own reset time and share restored,
503-
* and the refill beside the number says what the next reset hands back.
506+
* windows; each segment's popover shows its own reset time and share restored.
504507
*/
505508
function PoolWindowCard({
506509
pool,
@@ -521,35 +524,18 @@ function PoolWindowCard({
521524
<div className="grid items-center gap-x-6 gap-y-3 rounded-lg border border-border/60 p-4 md:grid-cols-[11rem_minmax(0,1fr)]">
522525
<div className="flex flex-col gap-1">
523526
<span className="text-sm font-medium text-foreground">{label ?? pool.label}</span>
524-
<span className="flex flex-wrap items-baseline gap-x-2">
527+
<span className="flex items-baseline gap-2">
525528
<span className="text-3xl font-semibold text-foreground tabular-nums">
526529
{pool.remainingPercent}%
527530
</span>
528-
<span className="text-sm text-muted-foreground">left</span>
529-
{nextRefill ? (
530-
<Tooltip>
531-
<TooltipTrigger
532-
render={
533-
<span
534-
tabIndex={0}
535-
className="rounded-sm text-xs text-muted-foreground tabular-nums outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
536-
/>
537-
}
538-
>
539-
↻ +{nextRefill.restoresPercent}%
540-
</TooltipTrigger>
541-
<TooltipPopup side="top">
542-
Pooled usage +{nextRefill.restoresPercent}%{" "}
543-
{formatResetsIn(nextRefill.member.window, now)
544-
?.replace("resets in ", "in ")
545-
.replace("resets now", "now")}
546-
</TooltipPopup>
547-
</Tooltip>
548-
) : null}
531+
<span className="inline-flex items-center gap-2 text-sm text-muted-foreground">
532+
<span>left</span>
533+
{pool.pace ? <PaceIcon pace={pool.pace} /> : null}
534+
</span>
549535
</span>
550-
{pool.paceHeadroomPercent !== null ? (
551-
<span className="text-xs text-muted-foreground tabular-nums">
552-
{formatPaceHeadroom(pool.paceHeadroomPercent)}
536+
{nextRefill && pool.columns.length > 1 ? (
537+
<span className="text-xs font-medium text-foreground tabular-nums">
538+
↻ +{nextRefill.restoresPercent}%
553539
</span>
554540
) : null}
555541
</div>

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
collectLimitPools,
2020
displayLimitWindows,
2121
elapsedShare,
22-
formatPaceHeadroom,
2322
formatResetsIn,
2423
limitsNotice,
2524
paceOf,
@@ -87,12 +86,6 @@ describe("pace", () => {
8786
expect(formatResetsIn({ ...window, resetsAt: undefined }, now)).toBeNull();
8887
});
8988

90-
it("phrases distance from even spending", () => {
91-
expect(formatPaceHeadroom(24)).toBe("24% behind pace");
92-
expect(formatPaceHeadroom(-7)).toBe("7% ahead of pace");
93-
expect(formatPaceHeadroom(0)).toBe("On pace");
94-
});
95-
9689
it("phrases the reset as a countdown", () => {
9790
expect(formatResetsIn(window, now)).toBe("resets in 2h 0m");
9891
expect(formatResetsIn({ ...window, resetsAt: "2026-09-06T15:30:00.000Z" }, now)).toBe(
@@ -795,13 +788,13 @@ describe("pools", () => {
795788
now,
796789
);
797790
// Only a votes: 80% used, 80% elapsed.
798-
expect(untimed[0]?.windows[0]?.paceHeadroomPercent).toBe(0);
791+
expect(untimed[0]?.windows[0]?.pace).toBe("on");
799792
// a is 80% through its window and b 60%: the pool is 70% elapsed, 60% used.
800793
expect(session).toMatchObject({
801794
id: "five_hour",
802795
remainingPercent: 40,
803796
usedPercent: 60,
804-
paceHeadroomPercent: 10,
797+
pace: "under",
805798
});
806799
expect(
807800
session?.resets.map((reset) => [reset.member.account.key, reset.restoresPercent]),

‎packages/shared/src/usageLimits.ts‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,7 @@ export interface LimitPoolWindow {
380380
}>;
381381
readonly remainingPercent: number;
382382
readonly usedPercent: number;
383-
/**
384-
* Points between what is left and what even spending would leave by now:
385-
* positive is quota to spare, negative is spending faster than the clock.
386-
* Null when no member reports a window length and reset.
387-
*/
388-
readonly paceHeadroomPercent: number | null;
383+
readonly pace: LimitPace | null;
389384
readonly resets: ReadonlyArray<{
390385
readonly member: LimitPoolMember;
391386
readonly at: number;
@@ -516,8 +511,6 @@ function poolWindows(accounts: readonly LimitAccount[], now: number): readonly L
516511
const timedUsed = timed.reduce((sum, t) => sum + t.used, 0) / timed.length;
517512
const meanElapsed =
518513
timed.length > 0 ? timed.reduce((sum, t) => sum + t.elapsed, 0) / timed.length : null;
519-
// Headroom is taken between rounded figures so it agrees with the bar's pace marks.
520-
const paceRemaining = meanElapsed === null ? null : Math.round(100 - meanElapsed * 100);
521514
const resets = members
522515
.flatMap((member) => {
523516
const at = resetMillis(member.window);
@@ -542,8 +535,7 @@ function poolWindows(accounts: readonly LimitAccount[], now: number): readonly L
542535
),
543536
usedPercent: Math.round(usedPercent),
544537
remainingPercent: Math.round(100 - usedPercent),
545-
paceHeadroomPercent:
546-
paceRemaining === null ? null : Math.round(100 - timedUsed) - paceRemaining,
538+
pace: meanElapsed === null ? null : paceOfShares(timedUsed, meanElapsed),
547539
resets,
548540
};
549541
});
@@ -609,12 +601,6 @@ function paceOfShares(usedPercent: number, elapsed: number): LimitPace {
609601
return "on";
610602
}
611603

612-
/** Distance from even spending: `24% behind pace`, `8% ahead of pace`, or `On pace`. */
613-
export function formatPaceHeadroom(headroomPercent: number): string {
614-
if (headroomPercent === 0) return "On pace";
615-
return `${Math.abs(headroomPercent)}% ${headroomPercent > 0 ? "behind" : "ahead of"} pace`;
616-
}
617-
618604
/** `2h 13m`, `3d 4h`, `12m`. */
619605
export function formatDuration(ms: number): string {
620606
const remaining = Math.max(0, ms);

0 commit comments

Comments
 (0)