Skip to content

Commit 2cc6fd9

Browse files
Merge remote-tracking branch 'origin/main' into fix/history-compaction-worker
2 parents 6374015 + 08b1cbe commit 2cc6fd9

15 files changed

Lines changed: 168 additions & 56 deletions

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
cursorUsageWindowDetails,
1010
displayLimitWindows,
1111
formatResetsIn,
12+
paceRemainingPercent,
1213
remainingPercent,
1314
type LimitAccount,
1415
type LimitPoolWindow,
@@ -146,22 +147,38 @@ function PoolWindowCard({
146147
if (!member.window)
147148
return <View key={member.account.key} className="h-7 min-w-0 flex-1" />;
148149
const { account, window } = member;
150+
const timeLeft = paceRemainingPercent(window, now);
149151
return (
150152
<Pressable
151153
key={account.key}
152154
accessibilityRole="button"
153-
accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left`}
155+
accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
154156
accessibilityHint="Show account details"
155157
onPress={() => openAccount(account)}
156-
className="h-7 min-w-0 flex-1 overflow-hidden rounded-md bg-subtle"
158+
className="h-7 min-w-0 flex-1 rounded-md bg-subtle"
157159
>
158-
<AccountSegment
159-
remaining={remainingPercent(window)}
160-
color={color}
161-
refillPercent={window.resetsAt ? member.refillPercent : 0}
162-
/>
163-
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
164-
<Text className="text-xs font-t3-medium tabular-nums text-foreground">
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}
174+
<View
175+
pointerEvents="none"
176+
className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"
177+
>
178+
<Text
179+
numberOfLines={1}
180+
className="max-w-full shrink text-xs font-t3-medium tabular-nums text-foreground"
181+
>
165182
{index + 1}
166183
</Text>
167184
</View>
@@ -370,6 +387,7 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
370387
.find((candidate) => candidate.driver === account?.driver)
371388
?.windows.find((candidate) => candidate.id === windowId && candidate.kind === windowKind);
372389
const window = pool?.members.find((member) => member.account.key === accountKey)?.window;
390+
const evenPace = window ? paceRemainingPercent(window, now) : null;
373391
const reset = pool?.resets.find((candidate) => candidate.member.account.key === accountKey);
374392
const [revealed, setRevealed] = useState(false);
375393
return (
@@ -424,6 +442,11 @@ export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
424442
})}
425443
</Text>
426444
) : null}
445+
{evenPace !== null ? (
446+
<Text className="text-sm text-foreground-muted">
447+
Even pace: {evenPace}% left by now
448+
</Text>
449+
) : null}
427450
{reset && reset.restoresPercent > 0 ? (
428451
<Text className="text-sm text-foreground-muted">
429452
Restores {reset.restoresPercent}% of the pool

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
type ServerProviderUsageWindow,
1111
} from "@t3tools/contracts";
1212
import {
13-
elapsedShare,
1413
formatDuration,
1514
formatResetsIn,
1615
limitsNotice,
1716
paceOf,
17+
paceRemainingPercent,
1818
remainingPercent,
1919
} from "@t3tools/shared/usageLimits";
2020
import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from "react";
@@ -46,8 +46,7 @@ function WindowRow(props: {
4646
}) {
4747
const { window, now } = props;
4848
const remaining = remainingPercent(window);
49-
const elapsed = elapsedShare(window, now);
50-
const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
49+
const timeLeft = paceRemainingPercent(window, now);
5150
const pace = paceOf(window, now);
5251
const resetsIn = formatResetsIn(window, now);
5352
return (

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,10 +5218,10 @@ export default function ChatView(props: ChatViewProps) {
52185218
<span className="whitespace-nowrap">
52195219
<InlineButton
52205220
tone="muted"
5221-
aria-label={`Open subagent ${item.label}`}
5221+
aria-label={`${presentation.items.length === 1 ? "Show" : "Open"} subagent ${item.label}`}
52225222
onClick={() => onOpenRelatedThreadStable(childThreadId)}
52235223
>
5224-
{item.label}
5224+
{presentation.items.length === 1 ? "Show" : item.label}
52255225
</InlineButton>
52265226
{separator}
52275227
</span>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
} from "@t3tools/contracts";
1111
import { useAtomValue } from "@effect/atom-react";
1212
import {
13-
elapsedShare,
1413
formatDuration,
1514
formatResetsIn,
1615
type LimitPace,
1716
paceOf,
17+
paceRemainingPercent,
1818
remainingPercent,
1919
} from "@t3tools/shared/usageLimits";
2020
import { GaugeIcon, TrendingDownIcon, TrendingUpIcon } from "lucide-react";
@@ -84,8 +84,7 @@ function WindowBar({
8484
}) {
8585
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
8686
const remaining = remainingPercent(window);
87-
const elapsed = elapsedShare(window, now);
88-
const timeLeft = elapsed === null ? null : Math.round((1 - elapsed) * 100);
87+
const timeLeft = paceRemainingPercent(window, now);
8988
const resetsIn = formatResetsIn(window, now);
9089
const resetsAt = window.resetsAt
9190
? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type LimitPool,
1212
type LimitPoolMember,
1313
type LimitPoolWindow,
14+
paceRemainingPercent,
1415
remainingPercent,
1516
} from "@t3tools/shared/usageLimits";
1617
import { AlertTriangleIcon, ExternalLinkIcon, TicketIcon } from "lucide-react";
@@ -137,6 +138,7 @@ function SegmentPopover({
137138
}) {
138139
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
139140
const remaining = remainingPercent(window);
141+
const timeLeft = paceRemainingPercent(window, now);
140142
const resetsIn = formatResetsIn(window, now);
141143
const where =
142144
account.environments.length > 0
@@ -177,6 +179,7 @@ function SegmentPopover({
177179
{resetsIn ? ` · ${resetsIn.replace("resets in ", "in ")}` : ""}
178180
</Row>
179181
) : null}
182+
{timeLeft !== null ? <Row label="Even pace">{timeLeft}% left by now</Row> : null}
180183
{reset && reset.restoresPercent > 0 ? (
181184
<Row label="Restores">+{reset.restoresPercent}% of pool</Row>
182185
) : null}
@@ -226,6 +229,7 @@ function PoolSegment({
226229
}) {
227230
const [open, setOpen] = useState(false);
228231
const remaining = remainingPercent(window);
232+
const timeLeft = paceRemainingPercent(window, now);
229233
const resetsIn = formatResetsIn(window, now);
230234
const credits = account.limits.resetCredits?.availableCount ?? 0;
231235
return (
@@ -236,33 +240,42 @@ function PoolSegment({
236240
<button
237241
type="button"
238242
style={{ gridColumn: index, gridRow: 1 }}
239-
aria-label={`${account.displayName ?? (account.email ? accountInitials(account.email) : account.driver)}: ${remaining}% left${resetsIn ? `, ${resetsIn}` : ""}${credits ? `, ${credits} reset ${credits === 1 ? "credit" : "credits"} banked` : ""}`}
240-
className="relative h-5 min-w-0 cursor-pointer overflow-hidden 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"
243+
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` : ""}`}
244+
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"
241245
/>
242246
}
243247
>
244-
<div
245-
aria-hidden
246-
className="absolute inset-y-0 left-0 rounded-md opacity-35"
247-
style={{ width: `${remaining}%`, backgroundColor: color }}
248-
/>
249-
{remaining < 100 && reset && refillPercent > 0 ? (
248+
<div aria-hidden className="absolute inset-0 overflow-hidden rounded-md">
250249
<div
251250
aria-hidden
252-
className="absolute inset-y-0 right-0 opacity-20"
253-
style={{
254-
width: `${Math.min(100 - remaining, refillPercent)}%`,
255-
backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
256-
}}
251+
className="absolute inset-y-0 left-0 rounded-md opacity-35"
252+
style={{ width: `${remaining}%`, backgroundColor: color }}
253+
/>
254+
{remaining < 100 && reset && refillPercent > 0 ? (
255+
<div
256+
aria-hidden
257+
className="absolute inset-y-0 right-0 opacity-20"
258+
style={{
259+
width: `${Math.min(100 - remaining, refillPercent)}%`,
260+
backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
261+
}}
262+
/>
263+
) : null}
264+
</div>
265+
{timeLeft !== null ? (
266+
<span
267+
aria-hidden
268+
className="absolute -inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-muted-foreground"
269+
style={{ left: `${timeLeft}%` }}
257270
/>
258271
) : null}
259272
<span
260273
aria-hidden
261-
className="absolute inset-0 flex items-center justify-center text-3xs leading-none font-semibold text-foreground/80 tabular-nums @2xl/pool:hidden"
274+
className="absolute inset-0 flex items-center justify-center overflow-hidden rounded-md text-3xs leading-none font-semibold text-foreground/80 tabular-nums @2xl/pool:hidden"
262275
>
263276
{index}
264277
</span>
265-
<div className="relative hidden h-full min-w-0 items-center gap-1.5 px-2 text-xs @2xl/pool:flex">
278+
<div className="relative hidden h-full min-w-0 items-center gap-1.5 overflow-hidden rounded-md px-2 text-xs @2xl/pool:flex">
266279
{showAccountName ? (
267280
<AccountName
268281
account={account}
@@ -271,7 +284,7 @@ function PoolSegment({
271284
) : null}
272285
<span className="shrink-0 font-semibold text-foreground tabular-nums">{remaining}%</span>
273286
{resetsIn || credits ? (
274-
<span className="ms-auto flex shrink-0 items-center gap-1.5 rounded-sm bg-background/85 px-1.5 py-0.5 text-2xs text-foreground tabular-nums">
287+
<span className="ms-auto flex min-w-0 items-center gap-1.5 overflow-hidden rounded-sm bg-background/85 px-1.5 py-0.5 text-2xs whitespace-nowrap text-foreground tabular-nums">
275288
{resetsIn?.replace("resets in ", "↻ ") ?? ""}
276289
{credits ? (
277290
<>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface UsageChartWindow {
3030
readonly resolution: "day" | "hour";
3131
readonly timeZone: string;
3232
readonly referenceTime: string | undefined;
33+
readonly hour12: boolean;
3334
}
3435

3536
export function UsageModelDialog({
@@ -107,6 +108,7 @@ export function UsageModelDialog({
107108
referenceTime={chartWindow.referenceTime}
108109
resolution={chartWindow.resolution}
109110
timeZone={chartWindow.timeZone}
111+
hour12={chartWindow.hour12}
110112
/>
111113

112114
<div className="grid gap-x-10 gap-y-8 sm:grid-cols-2">

‎apps/web/src/components/usage/UsagePage.refresh.browser.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const setPresentations = (entries: ReadonlyArray<readonly [EnvironmentId, object
124124
act(async () => appAtomRegistry.set(state.presentations, new Map(entries) as Presentations));
125125
const setNow = (iso: string) => vi.mocked(Date.now).mockReturnValue(Date.parse(iso));
126126
const resetsIn = (countdown: string) =>
127-
page.getByRole("button", { name: `codex: 60% left, resets in ${countdown}` });
127+
page.getByRole("button", { name: `codex: 60% left, resets in ${countdown}`, exact: false });
128128
const refreshButton = () => page.getByRole("button", { name: "Refresh limits" });
129129
const selectMetric = (label: string) => userEvent.click(page.getByRole("button", { name: label }));
130130

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535

3636
import { isElectron } from "../../env";
3737
import { cn } from "../../lib/utils";
38+
import { usePrimarySettings } from "../../hooks/useSettings";
39+
import { resolveHour12 } from "../../timestampFormat";
3840
import { appAtomRegistry } from "~/rpc/atomRegistry";
3941
import { environmentPresentations } from "../../state/presentation";
4042
import { primaryServerKeybindingsAtom, serverEnvironment } from "../../state/server";
@@ -180,6 +182,7 @@ export function UsagePage() {
180182
const [preferences, setPreferences] = useState(readUsagePagePreferences);
181183
useEscapeToGoBack();
182184
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
185+
const hour12 = usePrimarySettings((settings) => resolveHour12(settings.timestampFormat));
183186
const shortcutTitle = (
184187
option: (typeof METRIC_OPTIONS)[number] | (typeof WINDOW_OPTIONS)[number],
185188
) => {
@@ -356,7 +359,7 @@ export function UsagePage() {
356359

357360
const windowLabel =
358361
shownHourly && shownWindow.sinceTime !== undefined && shownWindow.untilTime !== undefined
359-
? `${formatDateTimeShort(shownWindow.sinceTime, shownWindow.timeZone)} to ${formatDateTimeShort(shownWindow.untilTime, shownWindow.timeZone)}`
362+
? `${formatDateTimeShort(shownWindow.sinceTime, shownWindow.timeZone, hour12)} to ${formatDateTimeShort(shownWindow.untilTime, shownWindow.timeZone, hour12)}`
360363
: `${formatDayShort(shownWindow.sinceDay)} to ${formatDayShort(shownWindow.untilDay)}`;
361364
const topbarContent = (
362365
<div className="grid w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 py-2 xl:flex">
@@ -546,6 +549,7 @@ export function UsagePage() {
546549
<UsageOverview
547550
merged={merged}
548551
shownWindow={shownWindow}
552+
hour12={hour12}
549553
days={days}
550554
hours={hours}
551555
showingKept={showingKept}
@@ -576,6 +580,7 @@ export function UsagePage() {
576580
resolution: shownHourly ? "hour" : "day",
577581
timeZone: shownWindow.timeZone,
578582
referenceTime: shownWindow.untilTime,
583+
hour12,
579584
}}
580585
onSetPrice={(model) => setPriceDialog({ model })}
581586
/>
@@ -597,6 +602,7 @@ export function UsagePage() {
597602
function UsageOverview({
598603
merged,
599604
shownWindow,
605+
hour12,
600606
days,
601607
hours,
602608
showingKept,
@@ -611,6 +617,7 @@ function UsageOverview({
611617
}: {
612618
readonly merged: MergedUsage;
613619
readonly shownWindow: UsageSummaryInput;
620+
readonly hour12: boolean;
614621
readonly days: readonly string[];
615622
readonly hours: readonly string[];
616623
readonly showingKept: boolean;
@@ -826,6 +833,7 @@ function UsageOverview({
826833
referenceTime={shownWindow.untilTime}
827834
resolution={shownHourly ? "hour" : "day"}
828835
timeZone={shownWindow.timeZone}
836+
hour12={hour12}
829837
/>
830838
</div>
831839
</section>
@@ -1027,7 +1035,7 @@ function UsageOverview({
10271035
>
10281036
<td className="py-2 text-foreground">
10291037
{"hourStart" in period
1030-
? formatHourShort(period.hourStart, shownWindow.timeZone)
1038+
? formatHourShort(period.hourStart, shownWindow.timeZone, hour12)
10311039
: formatDayShort(period.day)}
10321040
</td>
10331041
{activeProviders.map((provider) => (

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface UsageProviderChartProps {
3333
readonly referenceTime: string | undefined;
3434
readonly resolution: "day" | "hour";
3535
readonly timeZone: string;
36+
readonly hour12: boolean;
3637
}
3738

3839
export interface DayColumn {
@@ -417,6 +418,7 @@ export function UsageProviderChart({
417418
referenceTime,
418419
resolution,
419420
timeZone,
421+
hour12,
420422
}: UsageProviderChartProps) {
421423
const periods = resolution === "hour" ? hours : days;
422424
const totals: readonly (DailyTotals | HourlyTotals)[] = resolution === "hour" ? hourly : daily;
@@ -436,10 +438,10 @@ export function UsageProviderChart({
436438
cn("transition-opacity", loading && "opacity-40 delay-150");
437439
const format = metric === "tokens" ? formatTokens : formatUsd;
438440
const formatPeriod = (period: string) =>
439-
resolution === "hour" ? formatHourShort(period, timeZone) : formatDayShort(period);
441+
resolution === "hour" ? formatHourShort(period, timeZone, hour12) : formatDayShort(period);
440442
const formatTooltipPeriod = (period: string) =>
441443
resolution === "hour" && referenceTime !== undefined
442-
? formatRelativeHourShort(period, referenceTime, timeZone)
444+
? formatRelativeHourShort(period, referenceTime, timeZone, hour12)
443445
: formatPeriod(period);
444446

445447
return (

‎apps/web/src/timestampFormat.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatHourShort } from "@t3tools/shared/usageFormat";
12
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
23

34
import {
@@ -40,17 +41,20 @@ describe("formatShortTimestamp", () => {
4041
});
4142

4243
it.each([
43-
["en-GB", "15:44"],
44-
["en-US", "3:44 PM"],
45-
])("honors %s and the explicit hour-cycle settings", async (locale, localTime) => {
44+
["en-GB", "15:44", "15:00"],
45+
["en-US", "3:44 PM", "3 PM"],
46+
])("honors %s and the explicit hour-cycle settings", async (locale, localTime, localHour) => {
4647
vi.stubGlobal("window", { desktopBridge: { getSystemLocale: () => locale } });
4748
vi.resetModules();
48-
const { formatShortTimestamp: format } = await import("./timestampFormat");
49+
const { formatShortTimestamp: format, resolveHour12 } = await import("./timestampFormat");
4950
const date = new Date(2026, 3, 7, 15, 44).toISOString();
5051
// ICU can separate the day period with a narrow no-break space.
5152
expect(format(date, "locale").replace(/[  ]/g, " ")).toBe(localTime);
5253
expect(format(date, "12-hour").replace(/[  ]/g, " ")).toMatch(/^3:44 [ap]m$/i);
5354
expect(format(date, "24-hour")).toBe("15:44");
55+
expect(formatHourShort(date, undefined, resolveHour12("locale"))).toBe(localHour);
56+
expect(formatHourShort(date, undefined, resolveHour12("12-hour"))).toBe("3 PM");
57+
expect(formatHourShort(date, undefined, resolveHour12("24-hour"))).toBe("15:00");
5458
});
5559
});
5660

0 commit comments

Comments
 (0)