Skip to content

Add Antigravity CLI (agy) usage collector and limit tracking - #14149

Closed
stpoa wants to merge 6 commits into
omacom:quattrofrom
stpoa:feat/agent-usage-agy
Closed

stpoa wants to merge 6 commits into
omacom:quattrofrom
stpoa:feat/agent-usage-agy

Conversation

@stpoa

@stpoa stpoa commented Oct 3, 2026

Copy link
Copy Markdown

Summary

Adds support for tracking Google Antigravity CLI (agy) usage, local session stats, and live quota limits in the Omarchy agents panel (omarchy.agents).

Antigravity CLI was recently adopted as the default agent in Omarchy (omarchy-default-agent, launcher menu, keybindings), but the status panel lacked a collector to display session stats and rate limits.

Changes

  • New collector bin/omarchy-agent-usage-agy:
    • Discovers the active Google account from ~/.gemini/google_accounts.json
    • Parses local session transcripts under ~/.gemini/antigravity-cli/brain/ to extract token counts (input, output, cache read/write), prompts, models (Gemini 3.8 Flash), and daily activity
    • Probes live 5-hour session and weekly limits via agy -p "/usage" (with TTL-based caching in ~/.cache/omarchy/agent-usage/agy-limits.json)
    • Reports limits formatted for CompactLimit meters with countdown-to-reset and alarm threshold support
  • Manifest registration:
    • Adds agy to enabled default providers in shell/plugins/agents/manifest.json
  • Assets:
    • Adds agy.svg and agy-light.svg icons for the agents panel
  • Documentation:
    • Documents the agy collector in shell/plugins/agents/README.md
  • Tests:
    • Adds unit test test/shell.d/agent-usage-agy-test.sh verifying metadata, JSON record contract, manifest registration, and SVG assets.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds a new usage collector for Antigravity CLI integration.

The PR appears safe to merge, with a non-blocking stale-limit alarm issue and an existing intermittent test concern.

Findings

  1. P2 Expired limits keep alarming ▶
  2. P2 Test can fail at midnight ▶

Summary

The PR adds an Antigravity usage collector, registers it in the agents panel, supplies icons and documentation, and tests transcript and quota handling. Since the previous review, the collector retains last-known quota percentages after a failed probe rather than resetting them to an unverified zero.

Reviews (6) · Last reviewed commit: "fix(agy): preserve last-known limits as ..."

Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread test/shell.d/agent-usage-agy-test.sh Resolved
@stpoa

stpoa commented Oct 3, 2026

Copy link
Copy Markdown
Author

Pushed commit c1fd483 addressing all review findings:

  1. Account-keyed limits caching: The cached probe output now records the active Google account and verifies it on cache hits, ensuring limits are re-probed immediately when switching accounts.
  2. Local timezone date attribution: Added parse_local_date() to convert ISO-8601 UTC timestamps (Z / offsets) into the user's local timezone before determining calendar dates for sessions and daily activity.
  3. Optimized --limits-only path: main() now loads existing state as base_record when --limits-only is specified, avoiding transcript re-scans during bar panel open events.
  4. Resilient token parsing: Enclosed integer parsing of step tokens in localized try/except blocks so invalid or non-numeric token values do not abandon subsequent steps in a transcript.
  5. Fully isolated unit test: Replaced the live test suite in test/shell.d/agent-usage-agy-test.sh with a hermetic sandbox using mock fixtures (mock agy binary, accounts, and transcripts), verifying limits parsing, --limits-only fast-pathing, and cross-account cache invalidation.

Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread bin/omarchy-agent-usage-agy Resolved
@stpoa

stpoa commented Oct 3, 2026

Copy link
Copy Markdown
Author

Pushed commit 3e7947a addressing the follow-up review findings:

  1. Account identity & label preservation on limits-only refresh:
    • tierLabel and accounts identity are now always constructed from the current active Google account and its limits rather than blindly copied from a saved record.
    • Added is_valid_base_record() which validates that the active email matches the cached record's account, rejecting the cache on account switch.
  2. Local date & freshness validation on scan reuse:
    • Added cached_local_stats() with dedicated cache (agy-stats.json) tracking scan date and timestamp, adhering to the 900-second reuse window for limits-only mode.
    • Enforces calendar day matching in the local timezone: if midnight has passed, stale activity from yesterday is rejected and transcripts are rescanned so yesterday's counts never masquerade as today's.
  3. Automated tests:
    • Extended test/shell.d/agent-usage-agy-test.sh with test assertions for account switching under --limits-only and date-boundary rejection of stale activity across midnight.

Comment thread bin/omarchy-agent-usage-agy Resolved
Comment thread test/shell.d/agent-usage-agy-test.sh Resolved
Comment thread test/shell.d/agent-usage-agy-test.sh Resolved
@stpoa

stpoa commented Oct 3, 2026

Copy link
Copy Markdown
Author

Pushed commit 4e09e75 addressing round 3 review feedback:

  1. Transcript home cache isolation:
    • Stats cache path is now keyed by a hash of agy_dir (agy-stats-<hash>.json) and stores home: str(agy_dir).
    • cached_local_stats() and is_valid_base_record() explicitly validate against agy_dir, preventing cross-home stat contamination if GEMINI_DIR changes while sharing a cache directory.
  2. Date boundary test account alignment:
    • Fixed the fixture in test/shell.d/agent-usage-agy-test.sh to keep the account identity aligned with the saved record, ensuring the account check passes and the date boundary invalidation is specifically exercised and verified.
  3. Timezone-independent fixture timestamps:
    • Fixture timestamps are now created using Python datetime.now().astimezone() with explicit local timezone offsets, ensuring consistent day-boundary calculations across all timezones (verified across UTC+14, US Eastern, and UTC).
  4. New test coverage:
    • Added test 7 in agent-usage-agy-test.sh verifying cache isolation across distinct transcript homes.

echo '{"active": "alpha@example.com"}' >"$TEST_HOME_2/.gemini/google_accounts.json"

other_transcript="$TEST_HOME_2/.gemini/antigravity-cli/brain/session-other/.system_generated/logs/transcript.jsonl"
today_iso=$(python3 -c "import datetime as dt; print(dt.datetime.now().astimezone().isoformat())")

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 Test can fail at midnight If the test crosses local midnight after today_iso is generated but before the collector runs, the transcript is dated yesterday while the collector counts today's tokens. The assertion expecting 777 tokens then fails even though home isolation works. Use a fixed date for the fixture and collector to avoid this intermittent failure.

@stpoa

stpoa commented Oct 3, 2026

Copy link
Copy Markdown
Author

Pushed commit 897ebbd ensuring limits are re-probed and rolled forward whenever resetsAt has passed:

  • fetch_limits() now checks if any limit's resetsAt has elapsed (any_limit_reset_passed()). If so, it bypasses the short-term probe cache and immediately re-probes agy for the new quota window.
  • If a probe fails or times out, rolled_forward() resets expired limits to 0.0% used rather than retaining the pre-reset alarm state.
  • Added test 8 in agent-usage-agy-test.sh verifying that an expired resetsAt triggers a fresh probe and correct percentage calculation.

Comment thread bin/omarchy-agent-usage-agy Resolved
@stpoa

stpoa commented Oct 3, 2026

Copy link
Copy Markdown
Author

Pushed commit 407d9d8 addressing review feedback on unverified quota fallback:

  • Removed the rolled_forward() synthetic zeroing logic.
  • When a probe fails or times out, the collector preserves the last-known limits marked as stale (limitsStale=true) rather than synthesizing 0% usage, keeping existing alarms intact until fresh limits are confirmed.
  • Added test 9 in agent-usage-agy-test.sh verifying that a failed probe preserves last-known limits as stale without zeroing.

pass

if cached_limits:
return cached_limits, True, cached_at

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 Expired limits keep alarming When a quota reset has passed and the agy probe fails, this returns the last-known percentage as stale. If that percentage is at least 90%, the panel still uses it to trigger its near-limit alarm without checking whether the limit is stale or expired. The warning can persist until a probe succeeds, even though the displayed reset time has passed.

Knowledge Base Used: AI agent integrations

@jandrusk

jandrusk commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for this. One question before this is enabled by default: does agy -p "/usage" get handled locally as a slash command, or does print mode send /usage to the model as a prompt? If it's the latter, every 15-minute refresh would spend quota and write a new transcript under ~/.gemini/antigravity-cli/brain/, which the collector would then count as a prompt. Could you confirm against the real CLI (and maybe paste a redacted sample of its actual /usage output, since the test mock uses a tab-separated format)?

Also, #14166 (Kimchi) edits the same providers block in manifest.json, so one of the two will need a rebase.

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