Repository navigation
Commit 50614f1
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
File tree
- apps/ccusage
- docs
- .vitepress
- guide
- antigravity
- nix
- rust
- adapters/antigravity
- src
- crates
- ccusage-adapter-all
- src
- ccusage-cli-parser/src
- snapshots
- ccusage-cli/src
- ccusage-config/src
- snapshots
- ccusage-core/src
- ccusage
- src
- adapter
- cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| |||
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
167 | | - | |
| 169 | + | |
168 | 170 | | |
169 | 171 | | |
170 | 172 | | |
| |||
0 commit comments