ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

feat(capacity): integrate Antigravity (agy) subscription quota tracking

Open codeaholicguy opened this issue 1 week ago • 0 comments

Summary

Integrate Antigravity (agy) subscription quota tracking into ai-devkit capacity (and @ai-devkit/agent-manager) so users can view Antigravity usage windows alongside existing providers (codex, claude, devin, openai, anthropic, zai).

Technical Background

1. Primary Method — Modern agy CLI (v1.2.2+ / >= 1.1.11) Non-Interactive JSON Print Mode

agy 1.2.2+ gates its local HTTPS server behind an unexposed CSRF token (401 missing CSRF token), so quota retrieval delegates directly to agy's non-interactive usage report (introduced in agy 1.1.11):

agy -p /usage --output-format json --print-timeout 90s
  • Version check: Run agy --version (cacheable by binary path/mtime/size/inode) to verify >= 1.1.11 before running print mode.
  • Process & environment safeguards:
    • Set AGY_CLI_DISABLE_AUTO_UPDATE=true (must be lowercase literal true; 1 is ignored) so passive probes do not trigger auto-updates.
    • Run in a private 0700 temp directory with a bounded timeout (90s) and output cap (1 MiB), reaping descendant processes on completion, timeout, or cancellation.
    • Prepend failing open and xdg-open stubs to PATH and set BROWSER to the stub so silent auth failures cannot unexpectedly launch browser OAuth tabs.
  • Response schema (snake_case JSON):
    • Expect status == "SUCCESS" and command.name == "usage".
    • command.data.groups[]: each group has display_name/name, description, and buckets[].
    • Each bucket has bucket_id/id, display_name/name, remaining_fraction (or remaining.remaining_fraction), reset_time (ISO-8601 or epoch seconds), description (reset prose), disabled, and window (cadence).
  • Quota model:
    • Two primary model families: Gemini Models and Claude and GPT models.
    • Each family typically exposes 5-hour (session) and weekly buckets (Starter tiers may expose weekly-only buckets; do not fabricate 5-hour windows when absent).
    • Note: print reports do not include account email or plan tier.
  • Optional account-scoped execution (macOS):
    • Stage OAuth tokens into a temporary 0700 HOME at .gemini/antigravity-cli/antigravity-oauth-token (0600) and set SSH_TTY to force agy's file-based token storage without touching macOS Keychain or the ambient CLI login, verifying the effective access token via Google's userinfo endpoint afterward.

2. Fallback / Alternative Methods (to evaluate during design)

  • Legacy agy CLI (< 1.2.2) & Antigravity.app Local HTTPS Server:
    • Connect/gRPC-Web JSON POST to https://127.0.0.1:<port> with Content-Type: application/json, Connect-Protocol-Version: 1 (plus X-Codeium-Csrf-Token for desktop app/IDE; omitted for legacy agy):
      1. Primary: POST /exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary ({"forceRefresh": true})
      2. Fallback 1 (and identity): POST /exa.language_server_pb.LanguageServerService/GetUserStatus
      3. Fallback 2: POST /exa.language_server_pb.LanguageServerService/GetCommandModelConfigs
        • Fallback body: {"metadata": {"ideName": "antigravity", "extensionName": "antigravity", "ideVersion": "unknown", "locale": "en"}}
  • Remote Google OAuth API (Cloud Code):
    • POST with Authorization: Bearer <accessToken>, Content-Type: application/json, and User-Agent: antigravity/hub/2.9.1 <darwin|linux>/<arm64|amd64>:
      1. POST https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist (resolve tier/plan & project ID; onboardUser if needed)
      2. POST https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary ({"project": "<projectId>"})
      3. Fallbacks: https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels and https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota

Integration Scope in ai-devkit

  • packages/agent-manager/src/capacity/: Add Antigravity capacity source/provider and export getAntigravityCapacityReport (mapping groups/buckets to CapacityReport & CapacityWindow[]).
  • packages/cli/src/commands/capacity.ts & packages/cli/src/commands/capacity/render.ts: Support antigravity (and agy alias) in ai-devkit capacity [providers...] and render multi-family quota windows cleanly in both table and --json output.

Acceptance Criteria

  • [ ] ai-devkit capacity antigravity and ai-devkit capacity agy report Antigravity subscription quota in table and --json modes.
  • [ ] ai-devkit capacity (no args) includes Antigravity and degrades gracefully when agy is not installed, below 1.1.11, or unauthenticated.
  • [ ] Probe execution enforces AGY_CLI_DISABLE_AUTO_UPDATE=true, private 0700 temp cwd, timeout/output caps, descendant process cleanup, and non-interactive browser stubs (open, xdg-open, BROWSER).
  • [ ] Multi-family buckets (Gemini Models, Claude and GPT models) and both 5-hour + weekly (and weekly-only Starter tier) windows map accurately to CapacityWindow without fabricating absent windows.
  • [ ] Unit and integration tests cover version detection, JSON parsing, error/auth states, safeguard environment setup, and CLI rendering.

codeaholicguy avatar Nov 19 '26 15:11 codeaholicguy