fix(host-service): count Antigravity CLI usage from real agy transcripts

Merged
HA
20h ago
+120-31

Fixes PARA-3582: Antigravity usage never appears in Settings → Usage.

Root cause

collectAgyEntries reads ~/.gemini/antigravity-cli/brain/<id>/.system_generated/logs/transcript_full.jsonl, but parseAgyTranscriptLine only looked for a nested usage / usageMetadata object. Real agy step lines put the counts at the top level:

{"step_index":3,"source":"MODEL","type":"PLANNER_RESPONSE","status":"DONE","created_at":"2026-10-14T03:03:40Z","input_tokens":3013,"cache_read_tokens":14973,"output_tokens":1518}

So every line returned null and Antigravity contributed nothing.

Fix

  • Read top-level input_tokens / cache_read_tokens / output_tokens first, falling back to the nested Gemini-style object.
  • Add cache_read_tokens to cached input. agy counts it outside input_tokens (step 2 above has more cache reads than input), unlike Gemini's cachedContentTokenCount.

Verification

  • Unit tests for the real line shape, top-level precedence over a nested usage key, and non-object lines. Pricing and provider tests for model-less agy rows. bun test src/trpc/router/usage/: 161 pass. Typecheck and biome pass.
  • End to end in the dev desktop app (cloud box, CDP): seeded two realistic agy transcripts, opened Settings → Usage. Before: only Claude Code shows. After: Antigravity shows (3.2M tokens), which matches collectAgyEntries on the same files.

Known limits / follow-ups

  • agy step lines carry no model id, so rows show model antigravity. They are priced at the Gemini 3.1 Pro rate, marked approximate (~), and attributed to Google. A session on Flash or a Claude/GPT model is mispriced until we can read the model (protobuf conversation DB).
  • Step lines have no cwd, so agy usage is not attributed to a workspace.
  • The Antigravity IDE app (~/.gemini/antigravity/conversations/*.db, protobuf in SQLite) is still not read. If the customer used the IDE and not agy, this PR does not cover them.
  • Transcripts from older agy versions (≈ before 1.5) have no token fields at all, so that history cannot be recovered.

Summary by CodeRabbit

  • Bug Fixes
    • Improved usage-history parsing to recognize token counts from both top-level and nested usage data, including cache-read tokens.
    • Corrected provider attribution for agy model usage and applied Gemini Pro pricing to unknown agy models. Estimates remain marked approximate.
    • Invalid transcript entries and non-finite or negative token values are no longer counted.