Skip to content

Commit 50614f1

Browse files
feat(antigravity): add Antigravity CLI usage adapter (#1544)
* feat(antigravity): add Antigravity CLI usage adapter Antigravity stores usage in per-conversation SQLite databases under `~/.gemini/antigravity-cli/conversations/`, with the token counts held in protobuf blobs. Antigravity publishes no `.proto` files, so `proto.rs` decodes them by field number, recovered from the `FileDescriptorProto` blobs embedded in the `agy` binary rather than guessed from the data. Decoding by number is safe here because Antigravity has to read the same blobs back after an upgrade, so it cannot renumber a field without breaking its own persistence. A hand-rolled wire reader keeps `prost` and its build-time codegen out of the dependency graph; only the fields ccusage needs are decoded. Token mapping follows `ModelUsageStats`. `input_tokens` and `cache_read_tokens` are disjoint, which a real record proves by carrying an `input_tokens` of 4050 against a `cache_read_tokens` of 16275, so neither needs adjusting to fit ccusage's split. `output_tokens` already contains `thinking_output_tokens`, so the thinking count is only used to rebuild a missing total. Usage comes from two tables. `steps` is primary and holds one row per invocation, including the background calls nothing else records. `gen_metadata` is read because it is the only place a human-readable model name appears, and because it keeps usage visible for a step that has since been pruned. Every invocation is deduplicated on `response_id`, falling back to `provider_assigned_message_id` then `message_id`. One call can be recorded in more than one place: `retry_infos` repeats the attempt that succeeded alongside those that failed, and a sub-conversation may repeat a call its parent already recorded. Deduplicating on the server-assigned id counts the failed attempts, which consumed tokens of their own, without recounting the successful one β€” and it holds whether or not Antigravity repeats the successful attempt in its retry list. Antigravity leaves `model_cost`, `credit_cost` and `consumed_credits` unset on consumer accounts, so cost is calculated from LiteLLM rates and is an equivalent public API cost rather than a billed amount. Invocations `gen_metadata` never named are reported under `antigravity-model-<id>`: the model id is opaque and the shipped descriptor only names those as `MODEL_PLACEHOLDER_M<n>`, so their tokens are counted while they surface as missing pricing. Tests synthesise their protobuf blobs. A captured conversation database would embed absolute paths, user prompts and Antigravity's own system prompt, none of which belong in this repository. * feat(antigravity): expose ccusage antigravity commands Wires the adapter into the CLI: `ccusage antigravity daily|monthly| session`, the `--last` window, and the unified report, which now picks Antigravity up whenever conversation databases are detected. Antigravity takes the next index in `BUILT_IN_AGENT_NAMES` so the all-agents loader spec, the agent label lookup, and the parser's allowlists stay in step with each other. * feat(config): add the antigravity configuration namespace Lets `ccusage.json` set Antigravity defaults and per-report overrides the same way the other sources can, and regenerates the published schema. * docs(antigravity): document the data source and its accuracy limits Adds the Antigravity guide and lists the source across the READMEs, the getting-started and all-reports pages, the environment variable reference, and the VitePress sidebar. The guide states the limitations rather than leaving them implied: cost is an equivalent public API cost and never a billed amount, unnamed model ids cannot be priced, `--offline` has no Gemini rates to use, and the retry, subagent and model-comparison paths are handled by design but have not yet been exercised against real data. Antigravity was previously listed as investigated and unsupported, because it stored conversations as opaque `.pb` payloads that needed an unpublished schema. It now writes SQLite databases whose protobuf field numbers can be recovered from the descriptors in its own binary, so that entry moves to a new section recording how the blocker was resolved. * fix(antigravity): accept comma-separated ANTIGRAVITY_DATA_DIR The docs state that every source-specific path variable can hold comma-separated directories, so a current profile and an archive can be reported together. Antigravity was taking the whole value as a single path, which made that claim untrue for this source. * perf(antigravity): open each conversation database once `collect_records` reads two tables, and each read was opening its own read-only connection. Opening once and sharing it halves the connections per conversation, which matters because Antigravity writes one database per conversation rather than one for the whole history. * docs(antigravity): list Antigravity across the shared inventories The guide inventories that enumerate every source still stopped at Copilot CLI and Gemini CLI, so the introduction, the unified-report source list, the focused-command examples and the data directory export examples contradicted the tables that already listed Antigravity. Also drops report::report_from_rows from the adapter README's public surface; it is re-exported as pub(crate) and only used by run. Co-authored-by: Codesmith <[email protected]> * test(antigravity): pin HOME for the blank override fallback ignores_a_blank_data_dir_override only overrode ANTIGRAVITY_DATA_DIR, so the fallback still read the real HOME and the assertion failed wherever it is unset. Pinning it at a fixture also lets the test assert the fallback finds no databases rather than merely that it returned Ok. Both variables go through one EnvVarsGuard because EnvVarGuard holds the same non-reentrant global env lock, so taking a second guard in one test deadlocks. Co-authored-by: Codesmith <[email protected]> * fix(antigravity): report session activity and project path The session branch grouped by key and then moved the group key into session_id, which left last_activity, first_activity and project_path unset: the session table had no Last Activity column and the JSON exposed none of the session metadata every other timestamped adapter reports. Accumulating with SessionAccumulator, as qwen, pi, opencode and openclaw already do, carries the activity range and project path onto the row, and the JSON report now asks for session metadata for the session kind. Co-authored-by: Codesmith <[email protected]> * fix(antigravity): discard out-of-range timestamp nanos google.protobuf.Timestamp constrains nanos to a single second, but a corrupt blob carrying more than that was normalized into the millisecond total, which reported the invocation up to four seconds late and near midnight moved it into the next day's report. The seconds field is still trusted, so the invocation is kept rather than dropped along with its tokens. Co-authored-by: Codesmith <[email protected]> * docs(antigravity): document multi-root and nested database discovery ANTIGRAVITY_DATA_DIR accepts comma-separated roots and discovery walks below conversations/, neither of which the guide's single-root, direct-children wording described. Co-authored-by: Codesmith <[email protected]> * docs(antigravity): document recursive database discovery in the crate README Co-authored-by: Codesmith <[email protected]> * docs(antigravity): list antigravity as a config namespace The config namespaces list stopped at `gemini`, so the page did not mention the namespace the schema already accepts. * docs(antigravity): add commands and guide links to the crate README The crate README described internals only, so anyone landing there had no route to the commands or to the guide that documents what the numbers mean. Found by CodeRabbit on #1544. --------- Co-authored-by: Codesmith <[email protected]>
1 parent 615f460 commit 50614f1

37 files changed

Lines changed: 2861 additions & 83 deletions

β€Žapps/ccusage/README.mdβ€Ž

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,24 @@ npx ccusage@latest
6161

6262
ccusage reads local usage data from coding agent CLIs and turns it into daily, weekly, monthly, and session reports.
6363

64-
| Source | Focused command example |
65-
| ------------------ | ------------------------ |
66-
| Claude Code | `ccusage claude daily` |
67-
| Codex | `ccusage codex daily` |
68-
| OpenCode | `ccusage opencode daily` |
69-
| Amp | `ccusage amp daily` |
70-
| Droid | `ccusage droid daily` |
71-
| Codebuff | `ccusage codebuff daily` |
72-
| Hermes Agent | `ccusage hermes daily` |
73-
| pi-agent | `ccusage pi daily` |
74-
| Goose | `ccusage goose daily` |
75-
| OpenClaw | `ccusage openclaw daily` |
76-
| Kilo | `ccusage kilo daily` |
77-
| Kimi | `ccusage kimi daily` |
78-
| Qwen | `ccusage qwen daily` |
79-
| GitHub Copilot CLI | `ccusage copilot daily` |
80-
| Gemini CLI | `ccusage gemini daily` |
64+
| Source | Focused command example |
65+
| ------------------ | --------------------------- |
66+
| Claude Code | `ccusage claude daily` |
67+
| Codex | `ccusage codex daily` |
68+
| OpenCode | `ccusage opencode daily` |
69+
| Amp | `ccusage amp daily` |
70+
| Droid | `ccusage droid daily` |
71+
| Codebuff | `ccusage codebuff daily` |
72+
| Hermes Agent | `ccusage hermes daily` |
73+
| pi-agent | `ccusage pi daily` |
74+
| Goose | `ccusage goose daily` |
75+
| OpenClaw | `ccusage openclaw daily` |
76+
| Kilo | `ccusage kilo daily` |
77+
| Kimi | `ccusage kimi daily` |
78+
| Qwen | `ccusage qwen daily` |
79+
| GitHub Copilot CLI | `ccusage copilot daily` |
80+
| Gemini CLI | `ccusage gemini daily` |
81+
| Antigravity | `ccusage antigravity daily` |
8182

8283
Use `ccusage daily`, `ccusage weekly`, `ccusage monthly`, or `ccusage session` to include every detected source in one report.
8384

@@ -132,6 +133,7 @@ bunx ccusage kimi daily
132133
bunx ccusage qwen daily
133134
bunx ccusage copilot daily
134135
bunx ccusage gemini daily
136+
bunx ccusage antigravity daily
135137
bunx ccusage pi daily --pi-path /path/to/sessions
136138
bunx ccusage pi daily --pi-path /path/to/sessions,/archive/pi/sessions
137139

@@ -164,7 +166,7 @@ bunx ccusage monthly --compact # Compact monthly report
164166
- πŸ“Š **Daily Report**: View token usage and costs aggregated by date
165167
- πŸ“… **Monthly Report**: View token usage and costs aggregated by month
166168
- πŸ’¬ **Session Report**: View usage grouped by conversation sessions
167-
- πŸ€– **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI usage from one CLI
169+
- πŸ€– **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, Gemini CLI, and Antigravity usage from one CLI
168170
- ⏰ **5-Hour Blocks Report**: Track usage within Claude's billing windows with active block monitoring
169171
- πŸš€ **Statusline Integration**: Compact usage display for Claude Code status bar hooks (Beta)
170172
- πŸ€– **Model Tracking**: See which models are used across supported sources

0 commit comments

Comments
Β (0)