Compare commits

...
Author SHA1 Message Date
Mohamed Boudra 7eec266f50 fix(usage): keep window shorthands visible in sidebar usage row (#10274)
* fix(usage): keep window shorthands visible in sidebar usage row

Antigravity usage windows emitted full group names and raw period strings (for example "Gemini Models weekly") in shortLabel, which pushed the measured labels row past the maximum sidebar width. On the app side, choosePinnedUsageLayout dropped every window on the row straight to bare percentages whenever any scoped short label overflowed the row.

Normalize Antigravity shortLabel periods (weekly -> wk, monthly -> mo) and shorten group prefixes, and add a compact period-shorthand tier between full labels and bare percentages in PinnedUsageTrigger so tight sidebar rows keep shorthands like 5h and wk visible instead of collapsing to percentages alone.

* test(usage): expect compact shorthands in usage modal sidebar summary

With the compact period-shorthand tier between full labels and bare percentages, three Weekly windows now render as "31% wk", "20% wk", "12% wk" in the 320px sidebar instead of dropping to bare percentages.
2026-11-20 13:58:45 +07:00
7 changed files with 296 additions and 19 deletions
+2 -2
View File
@@ -233,8 +233,8 @@ test.describe("usage modal", () => {
],
});
await gotoAppShell(page);
// Three windows leave no room for labels in the summary, so it reads percents.
await expectPinnedUsage(page, ["31%", "20%", "12%"]);
// Three Weekly labels overflow the summary, so it falls back to compact shorthands.
await expectPinnedUsage(page, ["31% wk", "20% wk", "12% wk"]);
await openUsageFromItem(page);
await expectUsageCardOrder(page, ["alpha:a", "beta:home", "beta:work"]);
@@ -40,6 +40,7 @@ import {
usageModal,
installTallUsageSource,
} from "../support/helpers/usage-sidebar-item";
import { seedDockedSidebarWidth } from "../support/helpers/sidebar-footer-overflow";
import { seedSidebarFooterPreferences } from "../support/helpers/sidebar-nav-settings";
import { waitForSettledPosition } from "../support/helpers/sheet-layout";
import { createTempGitRepo } from "../support/helpers/workspace";
@@ -577,3 +578,97 @@ test("visible usage summary requests reports on load", async ({ page }) => {
await expectPinnedUsage(page, ["31% 5h", "54% wk", "7% 5h", "12% wk"]);
expect(usage.listRequests()).toHaveLength(1);
});
test("sidebar usage falls back to period shorthands before dropping all labels", async ({
page,
}) => {
test.setTimeout(120_000);
const [claude, codex] = claudeAndCodexReports();
const fetchedAt = new Date().toISOString();
await installUsageReportsFixture(page, {
lists: [
() => [
{
...codex!,
report: {
status: "available",
windows: [
{ id: "weekly", label: "Weekly", shortLabel: "wk", summary: true, usedPct: 97 },
],
},
},
{
...claude!,
report: {
status: "available",
windows: [
{ id: "five_hour", label: "Session", shortLabel: "5h", summary: true, usedPct: 100 },
{ id: "weekly", label: "Weekly", shortLabel: "wk", summary: true, usedPct: 14 },
{
id: "weekly_model_opus",
label: "Weekly · Opus",
shortLabel: "wk Opus",
summary: true,
usedPct: 22,
},
],
},
},
{
id: "antigravity:default",
account: {},
fetchedAt,
sourceId: "antigravity",
sourceLabel: "Antigravity",
report: {
status: "available",
windows: [
{
id: "gemini-weekly",
label: "Gemini Models · Weekly",
shortLabel: "Gemini wk",
summary: true,
usedPct: 6,
},
{
id: "gemini-5h",
label: "Gemini Models · 5h",
shortLabel: "Gemini 5h",
summary: true,
usedPct: 20,
},
],
},
},
],
],
});
await seedSidebarFooterPreferences(page, [{ key: "usage", visible: true }]);
await seedDockedSidebarWidth(page, 432);
await page.setViewportSize(WIDE);
await gotoAppShell(page);
await expectPinnedUsage(page, ["6% wk", "20% 5h", "100% 5h", "14% wk", "22% wk", "97% wk"]);
const handle = page.getByTestId("left-sidebar-resize-handle");
const dragSidebarTo = async (targetX: number) => {
const box = (await handle.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(targetX, box.y + box.height / 2, { steps: 10 });
await page.mouse.up();
};
await dragSidebarTo(600);
await expectPinnedUsage(page, [
"6% Gemini wk",
"20% Gemini 5h",
"100% 5h",
"14% wk",
"22% wk Opus",
"97% wk",
]);
await dragSidebarTo(300);
await expectPinnedUsage(page, ["6%", "20%", "100%", "14%", "22%", "97%"]);
});
+65 -1
View File
@@ -53,7 +53,7 @@ function preferences(
}
describe("choosePinnedUsageLayout", () => {
const widths = { labelsWidth: 200, percentsWidth: 120, windowCount: 2 };
const widths = { labelsWidth: 200, compactWidth: 200, percentsWidth: 120, windowCount: 2 };
it("shows meters only when every window's meter fits beside the labels", () => {
expect(choosePinnedUsageLayout({ ...widths, available: 240 })).toBe("meters");
@@ -64,11 +64,27 @@ describe("choosePinnedUsageLayout", () => {
expect(choosePinnedUsageLayout({ ...widths, available: 199 })).toBe("percents");
});
it("uses compact period shorthands when full labels overflow but compact labels fit", () => {
const scoped = { labelsWidth: 485, compactWidth: 388, percentsWidth: 268, windowCount: 6 };
expect(choosePinnedUsageLayout({ ...scoped, available: 485 })).toBe("labels");
expect(choosePinnedUsageLayout({ ...scoped, available: 399 })).toBe("compact");
expect(choosePinnedUsageLayout({ ...scoped, available: 388 })).toBe("compact");
expect(choosePinnedUsageLayout({ ...scoped, available: 387 })).toBe("percents");
});
it("skips compact mode when no window has a compact label", () => {
const noPeriod = { labelsWidth: 220, compactWidth: 120, percentsWidth: 120, windowCount: 2 };
expect(choosePinnedUsageLayout({ ...noPeriod, available: 180 })).toBe("percents");
});
it("shows labels until the widths are measured", () => {
expect(choosePinnedUsageLayout({ ...widths, available: null })).toBe("labels");
expect(choosePinnedUsageLayout({ ...widths, available: 999, labelsWidth: null })).toBe(
"labels",
);
expect(choosePinnedUsageLayout({ ...widths, available: 999, compactWidth: null })).toBe(
"labels",
);
});
});
@@ -145,6 +161,7 @@ describe("resolvePinnedUsage", () => {
key: "claude:default/five-hour",
label: "Claude Session 31% used",
shortLabel: "5h",
compactLabel: "5h",
percent: 31,
percentText: "31%",
tone: "default",
@@ -153,6 +170,7 @@ describe("resolvePinnedUsage", () => {
key: "claude:default/weekly",
label: "Claude Weekly 80% used",
shortLabel: "wk",
compactLabel: "wk",
percent: 80,
percentText: "80%",
tone: "warning",
@@ -216,6 +234,52 @@ describe("resolvePinnedUsage", () => {
const items = windows([opencode], preferences(null));
expect(items.map((item) => item.shortLabel)).toEqual([""]);
expect(items.map((item) => item.compactLabel)).toEqual([""]);
});
it("extracts bare period tokens as compact labels for scoped or verbose short labels", () => {
const mixed = report({
sourceId: "mixed",
sourceLabel: "Mixed",
windows: [
{ id: "a", label: "Session", shortLabel: "5h", summary: true, usedPct: 10 },
{ id: "b", label: "Weekly · Opus", shortLabel: "wk Opus", summary: true, usedPct: 20 },
{
id: "c",
label: "Code review · Weekly",
shortLabel: "Code review wk",
summary: true,
usedPct: 30,
},
{
id: "d",
label: "Gemini Models · Weekly",
shortLabel: "Gemini Models weekly",
summary: true,
usedPct: 40,
},
{
id: "e",
label: "Gemini Models · 5h",
shortLabel: "Gemini Models 5h",
summary: true,
usedPct: 50,
},
{ id: "f", label: "Monthly", shortLabel: "Monthly", summary: true, usedPct: 60 },
{ id: "g", label: "Premium requests", summary: true, usedPct: 70 },
],
});
const items = windows([mixed], preferences(null));
expect(items.map((item) => [item.shortLabel, item.compactLabel])).toEqual([
["5h", "5h"],
["wk Opus", "wk"],
["Code review wk", "wk"],
["Gemini Models weekly", "wk"],
["Gemini Models 5h", "5h"],
["Monthly", "mo"],
["Premium requests", ""],
]);
});
it("formats the share left when the user reads usage as remaining", () => {
+49 -6
View File
@@ -18,6 +18,8 @@ export interface PinnedUsageWindow {
label: string;
/** The window's short name ("5h"), empty for none, or its label when the source sends none. */
shortLabel: string;
/** Bare period token ("5h", "wk", "mo") used when full short labels overflow the sidebar row. */
compactLabel: string;
/** The share shown, under the user's used/remaining preference. */
percent: number;
percentText: string;
@@ -34,28 +36,66 @@ export interface PinnedUsageSource {
}
/** How much of each window the one-line summary has room for. */
export type PinnedUsageLayout = "meters" | "labels" | "percents";
export type PinnedUsageLayout = "meters" | "labels" | "compact" | "percents";
// A meter narrower than this is a sliver that reads as noise rather than a share.
export const MIN_METER_WIDTH = 16;
/** The space between a meter and its text. */
export const METER_GAP = 4;
const DURATION_TOKEN_PATTERN = /^\d+[smhd]$/i;
function normalizePeriodToken(token: string): string | null {
const lower = token.toLowerCase();
if (lower === "wk" || lower === "weekly") return "wk";
if (lower === "mo" || lower === "monthly") return "mo";
if (DURATION_TOKEN_PATTERN.test(token)) return lower;
return null;
}
/**
* Extracts a bare period token ("5h", "wk", "mo") from a window's short label so tight sidebar
* rows can keep shorthands visible instead of dropping every label when one window is scoped.
*/
function compactShortLabel(shortLabel: string): string {
const trimmed = shortLabel.trim();
if (trimmed === "") return "";
const exact = normalizePeriodToken(trimmed);
if (exact !== null) return exact;
const parts = trimmed.split(/\s+/);
if (parts.length > 1) {
const first = normalizePeriodToken(parts[0]!);
if (first !== null) return first;
const last = normalizePeriodToken(parts[parts.length - 1]!);
if (last !== null) return last;
}
return "";
}
/**
* The richest layout that fits on one line: every window's meter, else its short label, else its
* percent alone. Meters are all or none; a line never mixes them. Until the widths are known it
* shows labels, which never flashes meters that turn out not to fit.
* bare period shorthand, else its percent alone. Meters are all or none; a line never mixes them.
* Until the widths are known it shows labels, which never flashes meters that turn out not to fit.
*/
export function choosePinnedUsageLayout(input: {
available: number | null;
labelsWidth: number | null;
compactWidth: number | null;
percentsWidth: number | null;
windowCount: number;
}): PinnedUsageLayout {
const { available, labelsWidth, percentsWidth, windowCount } = input;
if (available === null || labelsWidth === null || percentsWidth === null) return "labels";
const { available, labelsWidth, compactWidth, percentsWidth, windowCount } = input;
if (
available === null ||
labelsWidth === null ||
compactWidth === null ||
percentsWidth === null
) {
return "labels";
}
if (labelsWidth + windowCount * (MIN_METER_WIDTH + METER_GAP) <= available) return "meters";
if (labelsWidth <= available) return "labels";
if (compactWidth <= available && compactWidth > percentsWidth) return "compact";
return percentsWidth < labelsWidth ? "percents" : "labels";
}
@@ -85,10 +125,13 @@ export function resolvePinnedUsage(
.map((window) => {
const percent = displayPercent(window, preferences.displayAs) ?? 0;
const percentText = formatPct(percent);
const shortLabel =
window.shortLabel ?? formatProviderUsageLabel(window.id, window.label, t);
return {
key: `${entry.id}/${window.id}`,
label: `${describe(entry, formatProviderUsageLabel(window.id, window.label, t))} ${formatDisplayPct(percent, preferences.displayAs, undefined, t)}`,
shortLabel: window.shortLabel ?? formatProviderUsageLabel(window.id, window.label, t),
shortLabel,
compactLabel: compactShortLabel(shortLabel),
percent,
percentText,
tone: windowTone(window),
+19 -5
View File
@@ -29,6 +29,7 @@ import {
resolvePinnedUsage,
type PinnedUsageLayout,
type PinnedUsageSource,
type PinnedUsageWindow,
} from "./pinned";
import { UsageModal } from "./usage-modal";
@@ -123,8 +124,8 @@ function layoutWidth(event: LayoutChangeEvent): number {
/**
* One line: each account's icon, then per window a meter and "31% 5h". Off-screen copies measure
* the line with labels and with percents alone; the richest layout that fits is shown, and what
* it leaves out takes no space at all.
* the line with full labels, bare period shorthands, and percents alone; the richest layout that
* fits is shown, and what it leaves out takes no space at all.
*/
function PinnedUsageTrigger({
label,
@@ -139,6 +140,7 @@ function PinnedUsageTrigger({
}) {
const [available, setAvailable] = useState<number | null>(null);
const [labelsWidth, setLabelsWidth] = useState<number | null>(null);
const [compactWidth, setCompactWidth] = useState<number | null>(null);
const [percentsWidth, setPercentsWidth] = useState<number | null>(null);
const handleAvailableLayout = useCallback((event: LayoutChangeEvent) => {
setAvailable(layoutWidth(event));
@@ -146,12 +148,16 @@ function PinnedUsageTrigger({
const handleLabelsLayout = useCallback((event: LayoutChangeEvent) => {
setLabelsWidth(layoutWidth(event));
}, []);
const handleCompactLayout = useCallback((event: LayoutChangeEvent) => {
setCompactWidth(layoutWidth(event));
}, []);
const handlePercentsLayout = useCallback((event: LayoutChangeEvent) => {
setPercentsWidth(layoutWidth(event));
}, []);
const layout = choosePinnedUsageLayout({
available,
labelsWidth,
compactWidth,
percentsWidth,
windowCount: sources.reduce((count, source) => count + source.windows.length, 0),
});
@@ -177,6 +183,9 @@ function PinnedUsageTrigger({
<View style={styles.measured} onLayout={handleLabelsLayout}>
<PinnedUsageLine sources={sources} layout="labels" measuring />
</View>
<View style={styles.measured} onLayout={handleCompactLayout}>
<PinnedUsageLine sources={sources} layout="compact" measuring />
</View>
<View style={styles.measured} onLayout={handlePercentsLayout}>
<PinnedUsageLine sources={sources} layout="percents" measuring />
</View>
@@ -185,6 +194,12 @@ function PinnedUsageTrigger({
);
}
function windowSuffix(window: PinnedUsageWindow, layout: PinnedUsageLayout): string {
if (layout === "percents") return "";
if (layout === "compact") return window.compactLabel;
return window.shortLabel;
}
/**
* The line's items as direct children of one row, so every meter shares the leftover width
* equally.
@@ -215,6 +230,7 @@ function PinnedUsageLine({
</View>
{source.windows.map((window, windowIndex) => {
const leadStyle = windowIndex === 0 ? styles.iconGap : styles.windowGap;
const suffix = windowSuffix(window, layout);
return (
<Fragment key={window.key}>
{layout === "meters" ? (
@@ -228,9 +244,7 @@ function PinnedUsageLine({
testID={measuring ? undefined : "sidebar-usage-pinned-window"}
>
{window.percentText}
{layout === "percents" || window.shortLabel === "" ? null : (
<Text style={styles.windowLabel}>{` ${window.shortLabel}`}</Text>
)}
{suffix === "" ? null : <Text style={styles.windowLabel}>{` ${suffix}`}</Text>}
</Text>
</Fragment>
);
@@ -65,9 +65,46 @@ it("discovers the resolved account and maps the CLI's quota buckets", async () =
expect(await source.fetch(accounts[0]!.input)).toMatchObject({
status: "available",
windows: [
{ id: "gemini-5h", usedPct: 75, remainingPct: 25, resetsAt: "2026-11-19T14:25:08Z" },
{ id: "gemini-weekly", usedPct: expect.closeTo(30), summary: true },
{ id: "disabled", usedPct: null, remainingPct: null },
{
id: "gemini-5h",
shortLabel: "5h",
usedPct: 75,
remainingPct: 25,
resetsAt: "2026-11-19T14:25:08Z",
},
{ id: "gemini-weekly", shortLabel: "wk", usedPct: expect.closeTo(30), summary: true },
{ id: "disabled", shortLabel: "wk", usedPct: null, remainingPct: null },
],
});
});
it("uses compact group and period shorthands when multiple groups are reported", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "paseo-antigravity-usage-"));
directories.push(directory);
const cli = path.join(directory, "cli.cjs");
await writeFile(
cli,
`
console.log(JSON.stringify({ status: 'SUCCESS', command: { name: 'usage', data: { groups: [
{ name: 'Gemini Models', buckets: [
{ id: 'gemini-weekly', name: 'Weekly Limit Remaining', window: 'weekly', remaining_fraction: 0.9 },
{ id: 'gemini-5h', name: 'Five Hour Limit Remaining', window: '5h', remaining_fraction: 0.8 }
] },
{ name: 'Claude and GPT models', buckets: [
{ id: '3p-weekly', name: 'Weekly Limit Remaining', window: 'weekly', remaining_fraction: 1 }
] }
] } } }));
`,
);
const launch = { command: process.execPath, args: [cli, "acp"], env: { HOME: directory } };
const source = new Usage().registration();
const [account] = await source.discover({ kind: "global", launch });
expect(await source.fetch(account!.input)).toMatchObject({
status: "available",
windows: [
{ id: "gemini-weekly", shortLabel: "Gemini wk" },
{ id: "gemini-5h", shortLabel: "Gemini 5h" },
{ id: "3p-weekly", shortLabel: "Claude and GPT wk" },
],
});
});
+26 -2
View File
@@ -48,6 +48,28 @@ function accountKey(env: ProviderLaunch["env"]): string {
);
}
function shortWindow(window: string): string {
const trimmed = window.trim();
const normalized = trimmed.toLowerCase();
if (normalized === "weekly") return "wk";
if (normalized === "monthly") return "mo";
return trimmed;
}
function shortGroupName(name: string): string {
return name
.trim()
.replace(/\s+models$/i, "")
.trim();
}
function formatShortLabel(groupName: string, window: string, includeGroup: boolean): string {
const period = shortWindow(window);
if (!includeGroup) return period;
const scope = shortGroupName(groupName);
return scope ? `${scope} ${period}` : period;
}
export class Usage {
private readonly launches = new Map<string, ProviderLaunch>();
@@ -94,7 +116,9 @@ export class Usage {
throw new Error(data.error || data.response || `agy usage returned ${data.status}`);
}
if (!data.command) throw new Error("agy did not return usage data");
const windows = data.command.data.groups.flatMap((group) =>
const groups = data.command.data.groups;
const includeGroup = groups.length > 1;
const windows = groups.flatMap((group) =>
group.buckets.flatMap((bucket) => {
if (!bucket.disabled && bucket.remaining_fraction == null) return [];
const used = bucket.disabled ? null : (1 - bucket.remaining_fraction!) * 100;
@@ -102,7 +126,7 @@ export class Usage {
windowFromUsedPct({
id: bucket.id,
label: `${group.name} · ${bucket.name}${bucket.disabled ? " · Disabled" : ""}`,
shortLabel: `${group.name} ${bucket.window}`,
shortLabel: formatShortLabel(group.name, bucket.window, includeGroup),
summary: !bucket.disabled && bucket.window === "weekly",
utilizationPct: used,
resetsAt: bucket.disabled ? null : bucket.reset_time,