Skip to content

feat(antigravity): read usage limits via agy usage --json - #493

Open
Satya-Siba-Nayak wants to merge 1 commit into
DuskBotAI:devfrom
Satya-Siba-Nayak:feat/antigravity-agy-usage
Open

Satya-Siba-Nayak wants to merge 1 commit into
DuskBotAI:devfrom
Satya-Siba-Nayak:feat/antigravity-agy-usage

Conversation

@Satya-Siba-Nayak

Copy link
Copy Markdown
Contributor

Closes #492.

Summary

Replaces dusk bot's direct Google internal API calls (v1internal:retrieveUserQuotaSummary, v1internal:fetchAvailableModels, v1internal:loadCodeAssist) and manual Google OAuth token refresh for Antigravity plan usage with Google's official agy usage --json subcommand (Antigravity CLI 1.5.22+).

Changes

  • server/drivers/antigravity-usage.ts (new):
    • Runs agy usage --json per Antigravity profile in an isolated usage-home directory (HOME / USERPROFILE) because agy usage ignores GEMINI_HOME and reads $HOME/.gemini/antigravity-cli/antigravity-oauth-token.
    • Copies the profile's current token into usage-home under withAntigravitySignInGate with AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1, AGY_ACP_FORCE_FILE_STORAGE=1, AGY_CLI_DISABLE_AUTO_UPDATE=1, and SSH_CONNECTION, strips foreign Google/Antigravity env vars, and uses the per-instance Windows temp directory + sweep (antigravityTempDir / scheduleAntigravityTempSweep).
    • Gates on agy >= 1.5.22 (returning "Update Antigravity to 1.5.22 or newer to see usage limits." on older versions or when an unknown-version custom binary rejects usage) instead of falling back to v1internal:*.
    • Clears any stale usage-home token copy when the profile has no stored sign-in.
  • server/drivers/antigravity-acp.ts & server/drivers/antigravity-signin.ts:
    • Adds antigravityUsageHome / antigravityUsageTokenPath and clears the staged usage token copy during removeAntigravitySignIn and logoutAntigravity.
    • Reuses isRemovedAntigravityEnvKey and resolveLinuxCaBundle.
  • server/plan-usage-parsers.ts:
    • Replaces parseAntigravitySummary, parseAntigravityModels, parseAntigravityPlan, and antigravityWeeklyResets with parseAntigravityCliUsage for agy usage --json (command.data.groups[].buckets[]).
    • Normalizes Unix-epoch reset_time (<= 0) on untouched buckets to null so unstarted windows are not pruned as expired.
  • server/plan-usage.ts, server/plan-usage-types.ts, server/plan-usage-credentials.ts, server/plan-usage-renewal.ts:
    • Routes Antigravity plan usage through AntigravityUsageProbe with a 5-minute per-profile cache on non-refresh reads (ANTIGRAVITY_USAGE_CACHE_MS) so routine polls do not repeatedly unpack the ~1 GB PyInstaller binary on Windows; explicit refresh: true bypasses the cache.
    • Passes configured config.cli through PlanAccount and includes it in cache keys.
    • Removes all direct cloudcode-pa.googleapis.com / daily-cloudcode-pa.googleapis.com v1internal:* calls, renewAntigravityToken, antigravityUserAgent, and Antigravity's embedded OAuth client credentials from plan usage.
  • Tests:
    • Added server/drivers/antigravity-usage.test.ts (real subprocess execution, env scrubbing, token staging, version gate, unexpected argument "usage", stale token cleanup on sign-out, auth/rate-limit/setup/timeout handling).
    • Updated server/plan-usage.test.ts (CLI usage parser, 5-minute cache vs explicit refresh, transient/auth fallback, zero googleapis.com HTTP calls) and server/drivers/antigravity-signin.test.ts (usage token cleanup on sign-out).

Trade-offs & Notes

  • plan tier badges (Pro / Ultra / Free) previously came from v1internal:loadCodeAssist; parseAntigravityCliUsage reads command.data.plan / command.data.tier if present and otherwise returns null to avoid calling internal APIs.
  • server/drivers/antigravity-account.ts (display email lookup) is intentionally untouched to keep this PR scoped to plan usage limits.

Verification

  • pnpm typecheck
  • pnpm lint (0 warnings, 0 errors)
  • pnpm exec vitest run server/drivers/antigravity-usage.test.ts server/drivers/antigravity-signin.test.ts server/drivers/antigravity-lifecycle.test.ts server/drivers/antigravity.test.ts server/plan-usage.test.ts server/engine-limits.test.ts server/limit-resets.test.ts scripts/testing/file-size-ratchet.test.ts

@SiddDevZ

SiddDevZ commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the thorough tests. Using the official agy usage --json instead of the internal API is a direction we like. I'm not merging it today because it is a bigger swap than it looks: usage would work only on agy 1.5.22 or newer (older installs lose the usage display instead of falling back), and it stages a copy of the sign-in token in a second home folder. That is a product and credentials call for the maintainer, so I'm leaving it open for that decision. If you want to help it along, a fallback to the current path on older agy versions would make it much easier to take.

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