Skip to content

feat(agents): add Google Gemini and Antigravity usage provider - #9766

Closed
edgseu wants to merge 5 commits into
omacom:quattrofrom
edgseu:feat-agent-usage-gemini
Closed

edgseu wants to merge 5 commits into
omacom:quattrofrom
edgseu:feat-agent-usage-gemini

Conversation

@edgseu

@edgseu edgseu commented Sep 2, 2026 •

Copy link
Copy Markdown

Summary

Expands the built-in omarchy.agents bar widget and collector ecosystem with official support for Google Gemini / Antigravity.

Previously, the agents panel supported Claude Code, Codex, and Fireworks. This PR adds Gemini rate-limit monitoring, plan tier detection, session token tracking, and per-model breakdowns.

Changes

  • bin/omarchy-agent-usage-gemini: New usage collector adhering to the sibling collector contract (--force, --limits-only, versioned JSON). Probes the Google Cloud Code (Antigravity) API for 5-hour and weekly quota windows and reset timestamps; parses session files from ~/.pi/agent/sessions/ and ~/.omp/agent/sessions/ for google/gemini/antigravity providers; scans ~/.gemini/antigravity-cli/history.jsonl for prompt counts (assistant/response rows skipped); queries local opencode.db read-only for assistant token metrics including reasoning and cache reads/writes.
  • shell/plugins/agents/manifest.json: Added gemini provider default.
  • shell/plugins/agents/Main.qml: Model name prefix handling and token counting support (google-antigravity/gemini-2.5-pro → Gemini 2.5 Pro).
  • shell/plugins/agents/assets/gemini.svg: Branded vector asset.
  • test/shell.d/agent-usage-gemini-scanner-test.sh: Scanner, cache, security-contract, and quota-parser tests.

Security

Carries the review hardening from @Klebiano, now pinned by tests: cache files written owner-only (0600, atomic replace), the keyring is strictly read-only (secret-tool lookup, never store), the quota endpoint falls back from the canary host to production, and the scan lock opens in append mode so active flock handles survive.

Robustness

  • One malformed or NaN quota bucket no longer discards every limit an endpoint returned — the bucket is skipped and valid ones render.
  • An ok probe with no quota buckets (error-shaped 200, API change) no longer wipes cached limits with an empty list; cached limits keep serving and the cached tier wins over one derived from an error body.
  • Open-ended cached limits (no reset time) expire after 24 hours instead of rendering indefinitely when probing stops succeeding.
  • ready matches the sibling collectors' contract (local stats or limits), and dead code from the security hardening was removed.

Notes for reviewers

  • write_json/read_fresh_json are duplicated across the sibling collectors; a shared helper module is a sensible follow-up across all of them.
  • opencode.db resolution ignores XDG_DATA_HOME — same as the claude sibling; worth fixing cross-cutting later.

Verification

  • test/shell.d/agent-usage-gemini-scanner-test.sh — 11/11 assertions pass (including quota-parser unit tests with a stubbed endpoint and cache-permission checks).
  • test/shell.d/agent-usage-update-test.sh, test/shell.d/agents-panel-test.sh, test/shell.d/agent-usage-claude-scanner-test.sh — pass.
  • test/cli — passes (116 assertions).

edgseu and others added 3 commits September 2, 2026 12:31
…endpoint fallback

- Restrict cache write permissions to 0600 (owner only)
- Make Secret Service token retrieval read-only to avoid corrupting keyring
- Eliminate ambient environment variable OAuth refresh flow
- Add dual endpoint fallback (daily-cloudcode-pa and cloudcode-pa)
- Fix race condition during advisory lock file open
@Klebiano

Klebiano commented Sep 5, 2026

Copy link
Copy Markdown

Great PR! During security testing on an active Omarchy system, we identified a few security and reliability improvements in bin/omarchy-agent-usage-gemini:

  1. Cache File Permissions: write_json was setting 0o644 on gemini-limits.json and gemini-scan.json. Changing this to 0o600 restricts cache access strictly to the owner.
  2. Keyring Non-Mutation: Removed secret-tool store from get_auth_token(). The collector is a telemetry widget for the status bar; keeping it strictly read-only avoids race conditions or corrupting the user's master Antigravity keyring entry.
  3. Endpoint Redundancy: Added fallback from daily-cloudcode-pa.googleapis.com to the production cloudcode-pa.googleapis.com endpoint in case the canary endpoint is unavailable.
  4. Advisory Lock Truncation: Opened the scan lock file with mode "a" instead of "w" to avoid truncating active flock handles.

Submitted these fixes as a PR to your branch at edgseu#1 so you can easily pull them in!

security(agent-usage): harden token handling, cache permissions, and endpoint fallback
@edgseu

edgseu commented Sep 6, 2026

Copy link
Copy Markdown
Author

Thanks for the patch @Klebiano, updated the pr.

One malformed or NaN quota bucket discarded every limit the endpoint
returned and could leak NaN into the JSON output; buckets are now skipped
individually. An ok probe with no quota buckets (error-shaped 200 or an API
change) wiped previously good limits from the cache; the cache now keeps
serving and the cached tier wins over one derived from an error body.
Open-ended cached limits (no reset time) expire after 24 hours instead of
rendering indefinitely. Antigravity CLI history counts prompts only,
skipping assistant/response rows. ready matches the sibling collectors'
contract, and dead code from the security hardening was removed.

Tests: quota-parser unit tests with a stubbed endpoint (malformed/NaN
buckets, canary-to-production fallback), cache preservation and open-ended
expiry, the owner-only cache permission, keyring read-only and append-mode
lock pins, and the documented test header.
@bjarneo

bjarneo commented Sep 20, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #8479, which covers the same Antigravity usage collector. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

@bjarneo bjarneo closed this Sep 20, 2026
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.

3 participants