Skip to content

feat(antigravity): plan-usage chip rows for the 5-hour and weekly limits - #870

Open
henriqueleite42 wants to merge 1 commit into
Ark0N:masterfrom
henriqueleite42:feat/antigravity-plan-usage
Open

henriqueleite42 wants to merge 1 commit into
Ark0N:masterfrom
henriqueleite42:feat/antigravity-plan-usage

Conversation

@henriqueleite42

Copy link
Copy Markdown

Adds Antigravity to the header plan-usage chip, next to the Claude, Codex and Copilot rows. It follows the shape of the Copilot row from #662. I didn't find an existing issue or PR for this, so I'm opening the PR directly and I'm happy to move the design question to a Discussion if you'd rather.

What it shows

Antigravity meters its models in two groups, and each group has its own 5-hour and weekly limit. That maps onto the chip's existing 5h/7d windows, so the chip gets up to two rows:

AG GEMINI  5H 39% · 7D 88%   AG CLAUDE/GPT  5H 0% · 7D 55%

The tooltip gives the reset time of each window. The labels are fixed literals (AG Gemini, AG Claude/GPT, short forms AG/AC). Server-supplied group names are never rendered.

Where the numbers come from

agy has no scriptable usage command. It also refreshes its sign-in token only in memory, so ~/.gemini/jetski-standalone-oauth-token on disk is normally expired. Renewing that token would mean shipping Antigravity's private OAuth client credentials, so this PR doesn't touch it.

Instead it asks a running Antigravity language server, which already holds a live sign-in:

  • Each hub (the Antigravity app or its editor extension) registers ~/.gemini/<appDataDir>/daemon/hub_<port>.json with { pid, httpPort, csrfToken }. Hubs leave the file behind when they exit, so findAntigravityHubs() keeps only files whose pid is alive, sorts newest first and bounds the scan.
  • readAntigravityPlanUsage() POSTs Connect JSON to http://127.0.0.1:<httpPort>/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary with that hub's X-Codeium-Csrf-Token. It uses redirect: 'error' and a 5 s timeout, and tries at most three hubs. This is the same snapshot the Antigravity app's own usage view reads.
  • parseAntigravityQuotaSummary() (pure, in usage-telemetry.ts) maps buckets by id prefix (gemini-*, 3p-*), falling back to the group name, into antigravity.{gemini,thirdParty}. Each value is a normal 5h/7d StatusTelemetry. proto3 JSON omits a zero, so an exhausted bucket arrives with no remainingFraction. When it still has a resetTime, the parser reads it as 100% used.

Nothing leaves the host: the request goes to loopback only, and the CSRF token is never logged, stored or broadcast. The FAQ and Security "no phone-home" text therefore stays accurate.

Wiring

  • refreshAntigravityPlanUsage() in server.ts polls every 5 minutes. Like the Codex and Copilot polls, it is off under testMode.
  • readAntigravityPlanUsageIfEnabled() checks showPlanUsageLimits first, then looks for a live hub. A null result clears the rows.
  • plan-usage-latest.ts carries the antigravity key across Claude statusline samples. It reuses the existing session:statusTelemetry event and init snapshot, so the multi-user admin-only routing applies unchanged.

Limitation

Rows appear only while an Antigravity hub is running. The agy CLI on its own keeps its language server private to each run: the port appears only in its log, and there is no token file. A CLI-only host therefore shows no Antigravity rows. This is documented in the wiki's Antigravity section.

Testing

  • New test/antigravity-plan-usage.test.ts. It covers the parser (fixture taken from a live agy 1.5.19 hub), hub discovery against a temp dir, the loopback reader with an injected fetch, and the order of the gates.
  • Chip and latest-store tests were added to plan-usage-chip.test.ts and plan-usage-latest.test.ts.
  • typecheck, lint, format:check, check:frontend-syntax, check:frontend-dead, check:browser-excludes and knip are clean, and npm test passes.
  • Ran it for real: an isolated dev instance against live Antigravity hubs. The SSE init snapshot carried the antigravity rows, and Playwright loaded the page and found both rows rendered with the right values and tooltip, with no page errors.

Docs: README, wiki (Agent CLIs, Keeping Agents Running, The Dashboard), CLAUDE.md and architecture-invariants.md. A minor changeset is included.

🤖 Generated with Claude Code

The header plan-usage chip gains up to two Antigravity rows, AG Gemini and
AG Claude/GPT: Antigravity meters its models in those two groups, each with
its own 5-hour and weekly window, which map onto the chip's 5h/7d slots.

The numbers come from a running Antigravity language server on this host,
over loopback only. Each hub (the Antigravity app or editor extension)
registers ~/.gemini/<appDataDir>/daemon/hub_<port>.json with its pid, HTTP
port and CSRF token; findAntigravityHubs() keeps the live ones and
readAntigravityPlanUsage() asks the first that answers for
LanguageServerService/RetrieveUserQuotaSummary, the same snapshot the app's
own usage view shows. Codeman never touches the Google sign-in: agy only
refreshes its on-disk token in memory, so that file is normally expired, and
renewing it would need Antigravity's private OAuth client.

Polled every 5 minutes, gated by showPlanUsageLimits like the Codex and
Copilot polls, and silent on any failure (no hub, refused, changed shape).
parseAntigravityQuotaSummary() is pure and handles proto3 JSON omitting a
zero remainingFraction on an exhausted bucket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ark0N

Ark0N commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Thank you for this, @henriqueleite42, and welcome to Codeman. This PR adds Antigravity's per-group 5-hour and weekly limits to the header plan-usage chip, reading them from a running Antigravity hub on loopback. It follows the Copilot row closely, and the gates, the pure parser with its fixture, and the docs updated alongside the code made it easy to review. The wire routing stays admin-only, as it should.

Two things need fixing before it can go in.

  1. Hub discovery drops the live hub once 64 or more stale hub files have piled up (src/utils/antigravity-plan-usage.ts:96). findAntigravityHubs() keeps the first 64 hub_*.json names in readdir order, and only after that stats them and sorts by mtime. readdir order is not age order. On ext4 a small directory lists in insertion order, so the newest file (the live hub) comes last, and that is the one the slice drops. I reproduced it with your isAlive injection: with 120 stale files plus one live hub written last, the live hub was missed in 20 of 20 runs. Hubs never delete their file, so a long-lived install gets there eventually, and then the rows vanish for good. Please filter by HUB_FILE_RE, stat every match (a much larger safety bound such as 1024 is fine), sort newest first, and only then read and check liveness, stopping after MAX_HUBS_TRIED live hubs. The MAX_APP_DATA_DIRS slice at line 86 has the same problem (Gemini CLI keeps its own folders in ~/.gemini), so count only entries that have a daemon/ folder, or raise that bound. Please also add a test with more than 64 stale files and one newer live file, and update the bounds sentence in docs/architecture-invariants.md.

  2. The labels overflow in the classic header style (src/web/public/app.js:3901, column width at src/web/public/styles.css:13552). Classic gives .pu-provider a fixed 46px column. In Chromium, AG GEMINI runs 8px past it and AG CLAUDE/GPT runs 31px past it, so both are drawn over the 5H values. Classic is the forced style below 768px and in a detached session window, so people will see this. Either labels that fit the column or a classic-only column wide enough for the longest label would fix it.

One optional change: defaultIsAlive (line 49) treats EPERM as alive. The hub file lives in the server user's own home, so EPERM means another account reused the pid and the hub is gone. Returning false there skips a pointless request.

Everything else passed here: typecheck, lint, format, the frontend checks and the full npm test. Once both fixes are pushed, the PR is ready for another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants