Skip to content

feat(antigravity-cli): support independent client with correct token mapping and pricing - #703

Closed
ddarkr wants to merge 1 commit into
junhoyeo:mainfrom
ddarkr:fix/antigravity-cli-token-pricing
Closed

feat(antigravity-cli): support independent client with correct token mapping and pricing#703
ddarkr wants to merge 1 commit into
junhoyeo:mainfrom
ddarkr:fix/antigravity-cli-token-pricing

Conversation

@ddarkr

@ddarkr ddarkr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This PR adds independent client support for the antigravity-cli client, ensuring accurate token usage mapping and custom pricing calculations.

Key Changes

  1. New Independent Client Support: Registers antigravity-cli as a dedicated client alongside existing clients, defining scan paths and database parsing pipelines.
  2. Correct Protobuf Token Field Mappings: Resolves field mapping for the metadata protobuf parser in antigravity_cli.rs (Field 5 for cached_tokens and Field 9 for thoughts_tokens), correcting cache read and reasoning token counts.
  3. Exclusive Reasoning Token Pricing: Subtracts reasoning tokens (thoughts_tokens) from total completion tokens (candidates_token_count) to prevent double-charging on reasoning models.
  4. Dynamic Model Resolution: Extracts human-readable display names from metadata blobs to dynamically map preview models to proper tier slugs (gemini-3.5-flash-high and gemini-3.5-flash-medium).
  5. Custom Model Pricing: Configures dedicated pricing rates ($1.50/M input, $9.00/M output) for google/gemini-3.5-flash variants.
  6. Monotonic Timestamps: Utilizes index-based offsets during SQLite scanning to assign distinct monotonic timestamps to message sequences, preventing deduplication conflicts.
  7. Implementation Cleanup: Refactors parser helper functions with safer try_from casting, clarifies token field overlapping layout with code documentation, and tests new model aliases.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview Jun 10, 2026 7:15am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 14 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid β€” if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".asw/plans/antigravity-cli-migration.md">

<violation number="1" location=".asw/plans/antigravity-cli-migration.md:43">
P2: Documentation uses machine-local absolute file URIs that are non-portable for other environments</violation>

<violation number="2" location=".asw/plans/antigravity-cli-migration.md:48">
P2: Migration plan contains ambiguity about whether to remove or keep the combined `*.json|*.jsonl|*.db` matcher in `scan_directory`, which could result in overlapping file match paths and duplicate/misattributed session processing.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/tokscale-core/src/sessions/antigravity_cli.rs Outdated
Comment thread crates/tokscale-core/src/sessions/antigravity_cli.rs Outdated
Comment thread crates/tokscale-core/src/pricing/aliases.rs
Comment thread crates/tokscale-core/src/sessions/antigravity_cli.rs Outdated
Comment thread .asw/plans/antigravity-cli-migration.md Outdated
### Task 1: Gemini ν΄λΌμ΄μ–ΈνŠΈ λ‘€λ°± 및 Antigravity ν΄λΌμ΄μ–ΈνŠΈ ν™•μž₯
- **λͺ©ν‘œ**: `ClientId::Gemini`λ₯Ό λ‘€λ°±ν•˜κ³  `ClientId::Antigravity`κ°€ `.db` νŒŒμΌμ„ νƒμƒ‰ν•˜λ„λ‘ μŠ€μΊλ„ˆμ™€ ν΄λΌμ΄μ–ΈνŠΈ μ •μ˜λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.
- **μˆ˜μ • 파일**:
- [clients.rs](file:///Users/doda/workspace/tokscale/crates/tokscale-core/src/clients.rs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Documentation uses machine-local absolute file URIs that are non-portable for other environments

Prompt for AI agents
Check if this issue is valid β€” if so, understand the root cause and fix it. At .asw/plans/antigravity-cli-migration.md, line 43:

<comment>Documentation uses machine-local absolute file URIs that are non-portable for other environments</comment>

<file context>
@@ -0,0 +1,87 @@
+### Task 1: Gemini ν΄λΌμ΄μ–ΈνŠΈ λ‘€λ°± 및 Antigravity ν΄λΌμ΄μ–ΈνŠΈ ν™•μž₯
+- **λͺ©ν‘œ**: `ClientId::Gemini`λ₯Ό λ‘€λ°±ν•˜κ³  `ClientId::Antigravity`κ°€ `.db` νŒŒμΌμ„ νƒμƒ‰ν•˜λ„λ‘ μŠ€μΊλ„ˆμ™€ ν΄λΌμ΄μ–ΈνŠΈ μ •μ˜λ₯Ό μˆ˜μ •ν•©λ‹ˆλ‹€.
+- **μˆ˜μ • 파일**:
+  - [clients.rs](file:///Users/doda/workspace/tokscale/crates/tokscale-core/src/clients.rs)
+  - [scanner.rs](file:///Users/doda/workspace/tokscale/crates/tokscale-core/src/scanner.rs)
+- **μž‘μ—… λ‚΄μš©**:
</file context>

Comment thread .asw/plans/antigravity-cli-migration.md Outdated
- **μž‘μ—… λ‚΄μš©**:
- `clients.rs`: `Gemini` νŒ¨ν„΄μ„ λ‹€μ‹œ `*.json|*.jsonl`둜 λ‘€λ°±ν•˜κ³ , `Antigravity` νŒ¨ν„΄μ„ `*.jsonl|*.db` 둜 λ³€κ²½ν•©λ‹ˆλ‹€.
- `scanner.rs`: `built_in_extra_scan_paths_for`μ—μ„œ `ClientId::Gemini` λΆ„κΈ°λ₯Ό μ œκ±°ν•˜κ³ , `ClientId::Antigravity` λΆ„κΈ°λ‘œ `~/.gemini/antigravity-cli/conversations` 경둜λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.
- `scanner.rs`: `scan_directory` νŒ¨ν„΄ 맀치 λΆ„κΈ°μ—μ„œ `*.json|*.jsonl|*.db`λ₯Ό μ œκ±°ν•˜κ³ (λ˜λŠ” 놔두고), `*.jsonl|*.db` 맀치 λΆ„κΈ°λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Migration plan contains ambiguity about whether to remove or keep the combined *.json|*.jsonl|*.db matcher in scan_directory, which could result in overlapping file match paths and duplicate/misattributed session processing.

Prompt for AI agents
Check if this issue is valid β€” if so, understand the root cause and fix it. At .asw/plans/antigravity-cli-migration.md, line 48:

<comment>Migration plan contains ambiguity about whether to remove or keep the combined `*.json|*.jsonl|*.db` matcher in `scan_directory`, which could result in overlapping file match paths and duplicate/misattributed session processing.</comment>

<file context>
@@ -0,0 +1,87 @@
+- **μž‘μ—… λ‚΄μš©**:
+  - `clients.rs`: `Gemini` νŒ¨ν„΄μ„ λ‹€μ‹œ `*.json|*.jsonl`둜 λ‘€λ°±ν•˜κ³ , `Antigravity` νŒ¨ν„΄μ„ `*.jsonl|*.db` 둜 λ³€κ²½ν•©λ‹ˆλ‹€.
+  - `scanner.rs`: `built_in_extra_scan_paths_for`μ—μ„œ `ClientId::Gemini` λΆ„κΈ°λ₯Ό μ œκ±°ν•˜κ³ , `ClientId::Antigravity` λΆ„κΈ°λ‘œ `~/.gemini/antigravity-cli/conversations` 경둜λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.
+  - `scanner.rs`: `scan_directory` νŒ¨ν„΄ 맀치 λΆ„κΈ°μ—μ„œ `*.json|*.jsonl|*.db`λ₯Ό μ œκ±°ν•˜κ³ (λ˜λŠ” 놔두고), `*.jsonl|*.db` 맀치 λΆ„κΈ°λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.
+- **RED Test**: `cargo test test_scan_all_clients_gemini_antigravity_cli_db`κ°€ κΉ¨μ§€λŠ”μ§€ ν™•μΈν•˜κ³ , 이λ₯Ό `ClientId::Antigravity` 용 ν…ŒμŠ€νŠΈ(`test_scan_all_clients_antigravity_cli_db`)둜 μˆ˜μ •ν•˜μ—¬ RED μƒνƒœλ₯Ό ν™•μΈν•©λ‹ˆλ‹€.
+- **GREEN Check**: `cargo test test_scan_all_clients_antigravity_cli_db` ν…ŒμŠ€νŠΈκ°€ ν†΅κ³Όν•˜λŠ” 것을 ν™•μΈν•©λ‹ˆλ‹€.
</file context>

@ddarkr ddarkr changed the title fix(antigravity-cli): correct token mapping, display names and cost calculation feat(antigravity-cli): support independent client with correct token mapping and pricing Jun 10, 2026
@ddarkr
ddarkr force-pushed the fix/antigravity-cli-token-pricing branch 4 times, most recently from 677a98d to 13fba72 Compare June 10, 2026 07:10
@junhoyeo

Copy link
Copy Markdown
Owner

Thanks for the detailed protobuf reverse-engineering here! We're landing the Antigravity CLI source via #713, which independently arrived at the same feature with byte-identical verification against real databases and the full frontend registry wiring. The gemini-3-flash-a pricing need is handled there with a targeted exact-key alias.

One important note for the record: the pricing/lookup.rs changes in this PR would revert the #707 brand-token fuzzy-match protection β€” they remove claude/anthropic/model/router from the fuzzy blocklist, flip is_fuzzy_eligible("claude") back to true, and delete the #707/#634 regression tests. That guard prevents real mispricing (e.g. a retired claude-2.1 eroding to bare claude and billing at an opus-fast rate), so we can't take those.

Closing in favor of #713 β€” your reverse-engineering work and the pricing direction were genuinely helpful in validating it. πŸ™

@junhoyeo junhoyeo closed this Jun 17, 2026
@junhoyeo

Copy link
Copy Markdown
Owner

Hi @ddarkr β€” thank you for this work! To be transparent about the decision: we're landing Antigravity CLI support via @haunchen's #713, which independently implemented the same SQLite source with byte-identical verification against real databases plus the full frontend registry wiring. Your gemini-3-flash-a pricing direction is preserved there via a targeted exact-key alias.

For the record (and for anyone who finds this later): the pricing/lookup.rs changes in this PR would have reverted the #707 brand-token fuzzy-match protection β€” removing claude/anthropic/model/router from the fuzzy blocklist and dropping the #707/#634 regression tests β€” which guards against real mispricing, so we couldn't take those.

Closing in favor of #713. Your reverse-engineering genuinely helped validate the field mapping β€” thank you, and please keep the contributions coming! πŸ™

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants