# Task: Investigate why Antigravity Gemini quota shows 0% after a 25-turn agy run

## Problem
We ran `agy` with model "Gemini 3.5 Flash (High)" for 25 turns (audit task on ai-limit-checker codebase). The run completed successfully (exit 0, produced AUDIT_REPORT.md). But checking quota before and after shows Gemini Models group at 0.0% used — no change at all.

Peet expects the quota to decrease after real usage. He wants to know: is our quota reading correct, or did agy not actually use Gemini?

## Quota data
- BEFORE agy run: Gemini Weekly 0.0%, 5h 0.0%
- AFTER agy run:  Gemini Weekly 0.0%, 5h 0.0% (resets 2026-06-29T12:02Z)
- Claude+GPT Weekly: 1.6% (was already 1.6% before — didn't change either)

## What to investigate

### 1. Check if agy actually used Gemini 3.5 Flash (High)
The agy conversation DBs are at `~/.gemini/antigravity-cli/conversations/*.db` (SQLite with protobuf payloads). Check the most recent conversation DB:
- What model was actually used? (Look for model name/id in the protobuf or metadata)
- How many turns did it actually complete?
- How many input/output tokens were consumed?

The `agy_runner.py` script at `$HERMES_HOME/scripts/agy_runner.py` has code to parse these DBs (field 20 → field 1 extraction). You can reference it for parsing patterns.

### 2. Check if the quota API has a delay (eventual consistency)
The `retrieveUserQuotaSummary` endpoint might have a caching delay. Try:
- Call the endpoint multiple times with 30s intervals
- Compare the `resetTime` timestamps — if they keep changing, the data is live; if frozen, it's cached

### 3. Run a BIGGER agy task to force quota consumption
If 25 turns on a small codebase (6 source files, ~1500 lines) is too small to register on Ultra quota, run a bigger task:
- Use the ThaiEDA project at `C:/Users/User/Desktop/Hermes_Peet/scratch/thaieda` (44 source files, ~15K lines)
- Run 40-80 turns with `/goal` — e.g. "read all source files and write a comprehensive architecture document"
- Check quota immediately before and after
- Use `--model "Gemini 3.5 Flash (High)"` explicitly

Run the task in background with `notify_on_complete=true` if it takes >5 minutes.

### 4. Check if the Gemini group in the API maps to the model agy used
The `retrieveUserQuotaSummary` response has groups with descriptions like "Models within this group: Gemini Flash, Gemini Pro". Verify that "Gemini 3.5 Flash (High)" (modelId: `gemini-3-flash-agent`) falls under the "Gemini Models" group and not under "Claude and GPT models".

You can call `fetchAvailableModels` to see the full model list and their group assignments.

### 5. Check if Ultra quota is just very large
Ultra tier might have such high limits that 25-40 turns represents <0.01% — rounding to 0.0%. If so, the quota IS working, just the percentage is too small to display. In that case:
- Consider showing more decimal places (0.01% instead of 0.0%)
- Or show absolute token counts if the API provides them

## API endpoints (for reference)
```
POST https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
  Body: {"metadata": {"ideType": "ANTIGRAVITY"}}
  → currentTier, paidTier, cloudaicompanionProject

POST https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuotaSummary
  Body: {"project": "<project_id>"}
  → groups[] with buckets[] (displayName, window, remainingFraction, resetTime)

POST https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels
  Body: {"project": "<project_id>"}
  → models[] with quotaInfo (remainingFraction, resetTime)
```

Token: read from Windows Credential Manager `gemini:antigravity` (already handled by `read_antigravity_credentials()` in the project).

## Project location
- Repo: `C:\Users\User\Desktop\Hermes_Peet\scratch\ai-limit-checker` (main branch, up to date, v0.4.0)
- Key files:
  - `src/ai_limit_checker/antigravity.py` — API calls, `_extract_tier()`, `fetch_quota_summary()`, `parse_quota_summary()`
  - `src/ai_limit_checker/credentials.py` — token reading
  - `src/ai_limit_checker/cli.py` — output formatting
  - `tests/test_antigravity.py` — tests
- Use system Python: `python` (3.11)
- Run: `PYTHONPATH="src" python -c "from ai_limit_checker.cli import main; main(['--antigravity','--json','--no-cache'])"`
- Tests: `PYTHONPATH="src" python -m pytest tests/ -x -q`
- agy runner: `python "$HERMES_HOME/scripts/agy_runner.py" "prompt" --workdir "..." --model "Gemini 3.5 Flash (High)" --skip-perms`

## Constraints
- Zero external dependencies (stdlib only)
- Python 3.10+
- ruff clean
- All tests must pass
- Do NOT push to main — work on a branch
- If you run agy, use background mode with notify_on_complete for tasks >5 min

## Report format
1. **Did agy use Gemini?** — evidence from conversation DB (model name, token count, turn count)
2. **Is the quota API working?** — live vs cached, decimal precision
3. **Big task result** — quota before/after the bigger agy run
4. **Root cause** — why 0% (too small / API broken / wrong group / display rounding)
5. **Fix applied** (if any) — code changes to improve quota display
6. **Test results**