Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Usage menu: Antigravity's 5-hour and weekly limits beside the other engines

laijsg1cc087722911f
diff --git a/packages/phone-protocol/src/limit-reset.ts b/packages/phone-protocol/src/limit-reset.ts
index 715de71dba..a0b0461980 100644
--- a/packages/phone-protocol/src/limit-reset.ts
+++ b/packages/phone-protocol/src/limit-reset.ts
@@ -39,7 +39,7 @@ export interface EngineLimit {
engine: string;
/** The engine's display name ("Claude", "Codex", or the instance's own name). */
name: string;
- driver: "claude" | "codex" | "grok" | "opencode";
+ driver: "claude" | "codex" | "grok" | "opencode" | "antigravity";
/** The window that decides the reset: the fullest, or the one refusing work. */
window: LimitWindowName | null;
/** 0–100, or null when the engine reported no window. */
diff --git a/server/limit-resets.test.ts b/server/limit-resets.test.ts
index 6e9ad55b5c..0557b16c32 100644
--- a/server/limit-resets.test.ts
+++ b/server/limit-resets.test.ts
@@ -4,7 +4,8 @@ import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { codexLimitResetsAt } from "./drivers/codex-errors.ts";
-import { engineLimitFromUsage, LimitResetClock, nearLimitNote, UNNAMED_LIMIT_MS } from "./limit-resets.ts";
+import { antigravityPlanWindows, antigravitySummaryWindows } from "./drivers/antigravity-usage-limits.ts";
+import { engineLabel, engineLimitFromUsage, LimitResetClock, nearLimitNote, UNNAMED_LIMIT_MS } from "./limit-resets.ts";
import type { RuntimeEvent } from "../shared/runtime-events.ts";
import { parseClaudeUsage, parseCodexUsage, parseOpenCodeUsage, planAccountsFromInstances, type PlanProviderRow, type PlanUsageReport, type PlanWindows } from "./plan-usage.ts";
@@ -16,7 +17,7 @@ const iso = (at: number) => new Date(at).toISOString();
/** A plan-usage row for one driver, named as the usage panel names it. */
function row(id: string, driver: PlanProviderRow["driver"], windows: PlanWindows): PlanProviderRow {
- const name = driver === "claude" ? "Claude" : driver === "codex" ? "Codex" : driver === "opencode" ? "OpenCode" : "Grok";
+ const name = driver === "claude" ? "Claude" : driver === "codex" ? "Codex" : driver === "opencode" ? "OpenCode" : driver === "antigravity" ? "Antigravity" : "Grok";
return { id, name, driver, ok: true, error: null, ...windows };
}
/** As the Claude usage endpoint answers (utilization, resets_at). */
@@ -32,6 +33,18 @@ const codex = (primary: [number, number], secondary: [number, number]) => row("c
secondary_window: { used_percent: secondary[0], limit_window_seconds: 7 * 86400, reset_at: Math.floor(secondary[1] / 1000) },
},
}));
+/** As Google's quota summary answers for an Antigravity sign-in: Gemini's own windows, and the allowance Claude and GPT
+ * share. */
+const antigravity = (fiveHour: [number, number], weekly: [number, number], shared: [number, number] = [0, NOW + 3 * HOUR]) => row("antigravity", "antigravity",
+ antigravityPlanWindows(antigravitySummaryWindows({ groups: [
+ { displayName: "Gemini Models", buckets: [
+ { bucketId: "gemini-5h", window: "5h", remainingFraction: 1 - fiveHour[0] / 100, resetTime: iso(fiveHour[1]), description: "used" },
+ { bucketId: "gemini-weekly", window: "weekly", remainingFraction: 1 - weekly[0] / 100, resetTime: iso(weekly[1]), description: "used" },
+ ] },
+ { displayName: "Claude and GPT models", buckets: [
+ { bucketId: "3p-5h", window: "5h", remainingFraction: 1 - shared[0] / 100, resetTime: iso(shared[1]), description: "used" },
+ ] },
+ ] }, NOW)));
const report = (...providers: PlanProviderRow[]): PlanUsageReport => ({ fetchedAt: iso(NOW), providers });
describe("a Claude account's usage", () => {
@@ -236,16 +249,44 @@ describe("LimitResetClock", () => {
expect(load).toHaveBeenCalledTimes(1);
});
- it("does not ask for the usage of an engine whose usage holds nothing here", async () => {
- const load = vi.fn(async (_asked: Array<{ id: string }>) => report(claude([50, NOW + HOUR], [5, NOW + 90 * HOUR])));
- const antigravity = { id: "antigravity", name: "Antigravity", driver: "antigravity" as const, environment: {} };
- let current = [...accounts, antigravity];
- const instance = new LimitResetClock({ accounts: () => current, now: () => NOW, loadUsage: load });
- await instance.refresh(true);
- expect(load.mock.calls.map(([asked]) => asked.map((account) => account.id))).toEqual([["claude"]]);
- current = [antigravity];
+});
+
+describe("an Antigravity account's usage", () => {
+ const accounts = planAccountsFromInstances({ claude: { driver: "claudeAgent" }, antigravity: { driver: "antigravityAgent" } });
+
+ it("is read beside the other engines and shows Gemini's 5-hour and weekly windows", async () => {
+ const load = vi.fn(async (_asked: Array<{ id: string }>) => report(
+ claude([50, NOW + HOUR], [5, NOW + 90 * HOUR]),
+ antigravity([50, NOW + 2 * HOUR], [25, NOW + 60 * HOUR], [99, NOW + 4 * HOUR]),
+ ));
+ const instance = new LimitResetClock({ accounts: () => accounts, now: () => NOW, loadUsage: load });
await instance.refresh(true);
- expect(load).toHaveBeenCalledTimes(1);
+ expect(load.mock.calls.map(([asked]) => asked.map((account) => account.id))).toEqual([["claude", "antigravity"]]);
+ expect(instance.limit("antigravity")).toEqual({
+ engine: "antigravity", name: "Antigravity", driver: "antigravity", window: "5-hour", usedPercent: 50, resetsAt: NOW + 2 * HOUR, blocked: false,
+ windows: [{ window: "5-hour", usedPercent: 50, resetsAt: NOW + 2 * HOUR }, { window: "weekly", usedPercent: 25, resetsAt: NOW + 60 * HOUR }],
+ });
+ });
+
+ it("at Gemini's limit shows the window full and its reset, without holding the engine or routing its turns away", () => {
+ const instance = new LimitResetClock({ accounts: () => accounts, now: () => NOW });
+ instance.noteUsage(report(antigravity([100, NOW + 2 * HOUR], [60, NOW + 60 * HOUR])));
+ expect(instance.limit("antigravity")).toMatchObject({ window: "5-hour", usedPercent: 100, resetsAt: NOW + 2 * HOUR, blocked: false });
+ expect(instance.limit("antigravity")?.held).toBeUndefined();
+ expect(instance.blockedUntil("antigravity")).toBeNull();
+ expect(instance.blockedUntil("antigravity", "gemini-3-pro")).toBeNull();
+ expect(instance.resetAt("antigravity")).toBe(NOW + 2 * HOUR);
+ });
+
+ it("has no row when Google gave nothing usable, so nothing is shown for it", () => {
+ const instance = new LimitResetClock({ accounts: () => accounts, now: () => NOW });
+ instance.noteUsage(report(claude([50, NOW + HOUR], [5, NOW + 90 * HOUR])));
+ expect(instance.report().engines.map((limit) => limit.engine)).toEqual(["claude"]);
+ });
+
+ it("is named Antigravity when the instance has no name of its own", () => {
+ expect(engineLabel("antigravity", { driverKind: "antigravityAgent" })).toBe("Antigravity");
+ expect(engineLabel("antigravity", { driverKind: "antigravityAgent", displayName: "Work Google" })).toBe("Work Google");
});
});
@@ -298,6 +339,12 @@ describe("nearLimitNote", () => {
expect(nearLimitNote({ ...limit, usedPercent: 89 }, "Claude", "UTC")).toBe("");
expect(nearLimitNote(undefined, "Claude", "UTC")).toBe("");
});
+
+ it("says nothing for Antigravity, whose windows are Gemini's and not the whole engine's", () => {
+ const limit = engineLimitFromUsage(antigravity([95, NOW + 2 * HOUR], [10, NOW + 90 * HOUR]))!;
+ expect(limit.usedPercent).toBe(95);
+ expect(nearLimitNote(limit, "Antigravity", "UTC")).toBe("");
+ });
});
describe("LimitResetClock and the turns that follow a refusal", () => {
diff --git a/server/limit-resets.ts b/server/limit-resets.ts
index 3577c48a93..ef9d1cdd3c 100644
--- a/server/limit-resets.ts
+++ b/server/limit-resets.ts
@@ -17,8 +17,11 @@ const SOON_AFTER_REFUSAL_MS = 5_000;
type Driver = EngineLimit["driver"];
-/** The drivers whose plan usage gives a limit to show and to route around. */
-const REPORTED_DRIVERS: ReadonlySet<string> = new Set(["claude", "codex", "grok", "opencode"]);
+/** The drivers whose plan usage gives a limit to show. */
+const REPORTED_DRIVERS: ReadonlySet<string> = new Set(["claude", "codex", "grok", "opencode", "antigravity"]);
+/** The drivers whose usage is the whole engine's, so a window at its limit holds the engine and its turns go to another
+ * AI. Antigravity's leading windows are Gemini's alone, and its other models draw on allowances of their own. */
+const ENGINE_WIDE_DRIVERS: ReadonlySet<string> = new Set(["claude", "codex", "grok", "opencode"]);
function windowLine(name: LimitWindowName, window: PlanWindow): { window: LimitWindowName; used: number; resetsAt: number | null } | null {
if (!window.available || window.usedPercent === null) return null;
@@ -38,7 +41,7 @@ export function engineLimitFromUsage(row: PlanProviderRow): EngineLimit | null {
if (full.length) {
const latest = full.reduce((left, right) => (right.resetsAt ?? 0) > (left.resetsAt ?? 0) ? right : left);
// Claude goes on past a full window on its paid extra usage while that has room; its own refusal still holds it.
- return { ...base, window: latest.window, usedPercent: 100, resetsAt: full.some((line) => line.resetsAt === null) ? null : latest.resetsAt, blocked: !claudeHasExtraUsageRoom(row) };
+ return { ...base, window: latest.window, usedPercent: 100, resetsAt: full.some((line) => line.resetsAt === null) ? null : latest.resetsAt, blocked: ENGINE_WIDE_DRIVERS.has(row.driver) && !claudeHasExtraUsageRoom(row) };
}
const fullest = [...windows].sort((left, right) => right.used - left.used || (left.resetsAt ?? Infinity) - (right.resetsAt ?? Infinity))[0]!;
return { ...base, window: fullest.window, usedPercent: fullest.used, resetsAt: fullest.resetsAt, blocked: false };
@@ -59,7 +62,7 @@ function holdGone(row: PlanProviderRow, limit: EngineLimit, held: number | undef
return windows.every((line) => line === null || (line.resetsAt !== null && Math.abs(line.resetsAt - held) > SAME_RESET_MS));
}
-const PRODUCT_NAMES: Record<string, string> = { claudeAgent: "Claude", codex: "Codex", grokAgent: "Grok", opencodeGo: "OpenCode" };
+const PRODUCT_NAMES: Record<string, string> = { claudeAgent: "Claude", codex: "Codex", grokAgent: "Grok", opencodeGo: "OpenCode", antigravityAgent: "Antigravity" };
/** "Claude", "Codex", or the name the person gave that engine. */
export function engineLabel(engine: string, instance?: { displayName?: string; driverKind: string }): string {
@@ -68,7 +71,7 @@ export function engineLabel(engine: string, instance?: { displayName?: string; d
/** A line for the turn's text when its engine is nearly out of usage, so the bot can set up its own continuation. */
export function nearLimitNote(limit: EngineLimit | undefined, name: string, timeZone: string): string {
- if (!limit || limit.usedPercent === null || limit.usedPercent < NEAR_LIMIT_PERCENT) return "";
+ if (!limit || !ENGINE_WIDE_DRIVERS.has(limit.driver) || limit.usedPercent === null || limit.usedPercent < NEAR_LIMIT_PERCENT) return "";
let resets = "";
if (limit.resetsAt !== null) {
try { resets = `; it resets ${new Date(limit.resetsAt).toLocaleString("en-US", { weekday: "short", hour: "numeric", minute: "2-digit", timeZone })} (${timeZone})`; }
@@ -265,8 +268,7 @@ export class LimitResetClock {
async refresh(force: boolean): Promise<void> {
if (this.loading) return this.loading;
- // An engine whose usage holds nothing here (engineLimitFromUsage) is not asked for it.
- const accounts = this.options.accounts().filter((account) => REPORTED_DRIVERS.has(account.driver));
+ const accounts = this.options.accounts();
this.loading = (async () => {
try {
if (!accounts.length) { this.checkedAt = this.now(); this.failures = 0; return; }
diff --git a/src/components/ModelPicker.usage.test.ts b/src/components/ModelPicker.usage.test.ts
index 419e97c0f3..0db1a9a794 100644
--- a/src/components/ModelPicker.usage.test.ts
+++ b/src/components/ModelPicker.usage.test.ts
@@ -216,6 +216,20 @@ describe("the model menu's usage rings", () => {
expect(shownRows(menu)).toEqual(["5-hour", "weekly"]);
});
+ it("show Antigravity's full Gemini window as at its limit, with nothing to retry since it holds no turns", async () => {
+ remember([usage(38), { ...usage(100), engine: "antigravity", name: "Antigravity", driver: "antigravity",
+ windows: [{ window: "5-hour", usedPercent: 100, resetsAt: RESET }, { window: "weekly", usedPercent: 40, resetsAt: RESET }] }]);
+ const menu = await openMenu();
+ expect(rings(menu).map((ring) => [ring.dataset.usageEngine, ring.querySelector("[data-usage-ring]")?.getAttribute("data-usage-ring")]))
+ .toEqual([["claude", "fine"], ["antigravity", "out"]]);
+ flushSync(() => rings(menu)[1]!.click());
+ expect(shownRows(menu)).toEqual(["5-hour", "weekly"]);
+ expect(menu.querySelector("[data-usage-rows]")?.textContent).toContain("Antigravity usage");
+ expect(menu.querySelector("[data-usage-row='5-hour'] [data-usage-track]")?.getAttribute("class")).toContain("bg-danger");
+ expect(menu.querySelector("[data-usage-check]")).toBeNull();
+ expect(menu.querySelector("[data-usage-release]")).toBeNull();
+ });
+
it("show another AI's ring, with no rows until it is pressed, when the bot's own AI reports no usage", async () => {
remember([other("codex", "Codex", 91)]);
const menu = await openMenu();