# Task: Fix Antigravity usage checker — API returns 100% for everything

## Problem
`aichecker --antigravity` shows 100% remaining for ALL models, but the Antigravity desktop app shows real usage:
- Weekly Limit: 93% used (refresh in 2 days 21 hours)
- Five Hour Limit: 95% used (refresh in 19 minutes)

## Root Cause Analysis (already done)

The CLI token and the desktop app use the SAME credential (`gemini:antigravity` in Windows Credential Manager), SAME Google account (`peet.wannasarnmetha@gmail.com`), and SAME agy binary.

But our API calls return wrong data:

### 1. `loadCodeAssist` returns free-tier
```
POST https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
Body: {"metadata": {"ideType": "ANTIGRAVITY"}}
```
Response: `currentTier.id = "free-tier"` — but Peet has Ultra/Google One AI Pro subscription.

The `upgradeSubscriptionUri` points to `https://accounts.google.com/AccountChooser?Email=peet.wannasarnmetha%40gmail.com&continue=https%3A%2F%2Fone.google.com%2Fai` — this is Google One AI, suggesting Ultra is managed separately.

### 2. `fetchAvailableModels` returns remainingFraction=1 for all
Every model has `quotaInfo.remainingFraction: 1` (100% remaining = 0% used).

### 3. `retrieveUserQuota` also returns remainingFraction=1 for all
```
POST https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota
Body: {"project": "melodic-component-26v41"}
```
All 20 buckets have `remainingFraction: 1`, all `tokenType: "WTUS"` (Weekly Token Usage). NO five-hour buckets, NO daily buckets.

### 4. Binary analysis
The agy binary (`C:\Users\User\AppData\Local\agy\bin\agy`, ~152MB Go binary) contains:
- `ideType` enum values: `ANTIGRAVITY`, `CLOUD_SHELL`
- `tokenType` proto enum: has `WTUS` (Weekly) and `DAILY` values
- Endpoints found: `cloudcode-pa.googleapis.com` with `loadCodeAssist`, `fetchAvailableModels`, `retrieveUserQuota`
- Also found: `getUsage`, `resetIn`, `userStatus` strings
- The binary's internal codename is "Jetski"

### 5. The desktop app is Electron
Located at `C:\Users\User\AppData\Local\Programs\Antigravity\`. It spawns the agy binary as a "language server" — so it uses the SAME backend. The app's UI strings ("Weekly Limit", "Five Hour Limit", "used some of", "fully refresh in") are NOT in the agy binary — they're in the Electron app's renderer process (Vue/React frontend loaded from a bundled web app, not in app.asar).

## What to investigate and fix

### Step 1: Find the correct API endpoint for real usage data
The `retrieveUserQuota` endpoint returns `remainingFraction: 1` for all models — this is clearly not reflecting real usage. The desktop app gets 93%/95% from somewhere.

Try these approaches:
1. **Try `ideType: CLOUD_SHELL`** in `loadCodeAssist` — this might map to a different tier/project that has real usage data
2. **Try different `retrieveUserQuota` body parameters** — maybe add `tier`, `ideType`, or other fields
3. **Search the agy binary more thoroughly** for alternative endpoints — look for patterns like `getUserUsage`, `fetchUserUsage`, `userStatus`, `getUsage`, `usageInfo`, or any endpoint with "usage" in it
4. **Check if there's a `v2internal` or different API version** — search binary for `v1internal`, `v2internal`, `v1beta`, etc.
5. **Try the `play.googleapis.com/log` endpoint** — it was found in the binary and might be a usage logging/querying endpoint
6. **Look for Google One AI endpoints** — the upgrade URI points to `one.google.com/ai`, maybe there's a `googleapis.com` endpoint for Google One AI usage

### Step 2: If the API genuinely can't provide usage data
If after thorough investigation the API truly returns 100% for free-tier CLI tokens (and the app gets its data from a different source we can't access), then:
1. **Detect the tier mismatch** — if `currentTier.id == "free-tier"`, show a clear warning: "CLI token is on free-tier. The Antigravity desktop app may show different limits if you have Google One AI Pro."
2. **Show `used_pct` instead of `remaining_pct`** — the app shows "93% used" not "7% remaining". Change the display to match.
3. **Be honest about the limitation** — don't show 100% as if everything is fine; show "free-tier: no usage data available" or similar.

### Step 3: Fix the display regardless
Even if we can't get real usage data:
1. Change from "remaining" to "used" percentage to match the app's display
2. Show tier clearly (free-tier vs standard-tier vs Ultra)
3. If all models show 100% remaining, add a note explaining what this means
4. Add the `retrieveUserQuota` endpoint as an additional data source (it has `tokenType: WTUS` which confirms weekly tracking exists)

## Project location
- Repo: `C:\Users\User\Desktop\Hermes_Peet\scratch\ai-limit-checker`
- Key files:
  - `src/ai_limit_checker/antigravity.py` — main API calls and parsing
  - `src/ai_limit_checker/credentials.py` — credential reading
  - `src/ai_limit_checker/cli.py` — CLI output formatting
  - `tests/test_antigravity.py` — tests
- No venv in this directory. Use system Python: `python` (3.11, Windows Store)
- Run: `cd "C:\Users\User\Desktop\Hermes_Peet\scratch\ai-limit-checker" && aichecker --antigravity --json --no-cache`
- Tests: `cd "C:\Users\User\Desktop\Hermes_Peet\scratch\ai-limit-checker" && python -m pytest tests/test_antigravity.py -x -q`

## Constraints
- Zero external dependencies (stdlib only) — this is a PyPI package
- Python 3.10+
- Cross-platform (Windows, macOS, Linux)
- Never print credentials/tokens in output
- ruff clean (E, F, W, I, UP, B, SIM)
- All tests must pass
- Comments/docs in English (international open-source project)
- Do NOT push to main — work on a branch

## Report format
Output:
1. **API Investigation Results** — what endpoints you tried, what worked, what didn't
2. **Root Cause** — why the API returns 100% and where the app gets its real data
3. **Fix Applied** — what code changes you made and why
4. **Test Results** — pytest output
5. **Files Changed** — list with brief description
6. **Remaining Issues** — anything that couldn't be fixed and why