Yaraill/antigravity-quota-guard
About
Local-first quota autopsy, cold-start config auditor, and zero-dependency hooks to curb Google Antigravity Orchestrator cache-miss burn.
Developer ToolsMeasured star growth
- in 24h
- Collecting history
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalantigravity-quota-guard (agy-guard)
Local-first Quota Autopsy, Cold-Start Config Auditor, and zero-dependency lifecycle hooks to curb Google Antigravity Orchestrator cache-miss burn.
Node.js >= 20 · Zero npm dependencies · Zero MCP token overhead · Zero network calls · Fail-open by design.
Why Orchestrator Mode Drains Quota Faster Than Expected
Measured across 107 real Antigravity sessions (4,023 modern turns with per-turn model telemetry):
| Pattern | Measured Sample (n = 4,023 turns) |
Why It Hurts Quota |
|---|---|---|
| Model-Swap KV Cache Misses | Same-model turns (3,721): 90.6% cache hit (18.9K avg uncached) vs. model-swap turns (195): 30.4% cache hit (192.9K avg, 0.0% median) |
Every swap re-processes active context as uncached input (~10.2x spike) |
| Frontier Return Penalty | Returning from executor to planner (hydrogen -> neon, flash-worker -> orch-neon) at 150K–590K context |
Higher-tier models absorb the cold-cache hit disproportionately |
| High-Context × Ping-Pong | 78.5% of swaps occurred above 150K context; 34.4% occurred <= 3 turns apart |
Context bloat multiplies every swap penalty by 5–10x |
| Serial Turns & Repeated Reads | 53.0% single-tool turns + repeated identical read requests in the same compaction epoch | Extra turns inflate context and create more swap points |
| Hidden Cold-Start Tax | Legacy ~/.gemini/GEMINI.md + current ~/.gemini/config/GEMINI.md both loaded + heavy active MCP & skill indexes |
Paid on turn 1 and re-paid on every 0%-cache model swap |
What antigravity-quota-guard Does (and Does Not Do)
Honest engineering boundary: Antigravity hooks cannot directly override server-side Orchestrator model routing. Instead, agy-guard gives you hard telemetry and controls the multipliers you can fix:
- Read-Only First:
agy-guard autopsy- Scans local Antigravity
transcript.jsonlfiles (antigravity,antigravity-cli,antigravity-ide). - Filters
--days Nat both file and event-timestamp level (--days 0or--allfor full history). - Separates raw uncached input tokens from estimated weighted quota impact, invalidates pre-edit reads when files are modified, and flags telemetry gaps (oversized
> 4 MBlines or delta skips). - Privacy-safe by default: Anonymizes session IDs (
session-#1) and workspace names (project-#1) for safe screenshot/text sharing (pass--verbosefor local IDs/names).
- Scans local Antigravity
- Before/After Comparison:
agy-guard compare- Compares N-day windows before vs. after plugin install (or
--since YYYY-MM-DD) in a side-by-side table: average active context, same-model & swap cache hit %, uncached/swap, ping-pong rate, and repeated reads (anonymized).
- Compares N-day windows before vs. after plugin install (or
- Cold-Start & Dead-MCP Auditor:
agy-guard audit&agy-guard doctorauditdetects duplicated legacy (~/.gemini/GEMINI.md) vs. current (~/.gemini/config/GEMINI.md) global rules (>= 40%line overlap), distinguishes active vs. cached MCP schemas, scans 30 days of transcripts to flag 0-call unused active MCP servers, and ranks top 5<skills>token sources.doctorturns audit + config diagnostics into an actionable checklist. Read-only by default; with--fix --yes, safely archives duplicate legacy~/.gemini/GEMINI.mdto.bak.<timestamp>and backs up/repairs invalidagy-guard.json(never touches MCP configs).
- Anonymous Guard Telemetry:
agy-guard stats&observeOnlyMode- Enable
"observeOnly": true(or runagy-guard mode observe) to log what would trigger (duplicate reads, swarm gates, loop stops, alerts) without blocking or modifying any tool call. - Run
agy-guard statsto inspect anonymous lifecycle counters, estimated avoided read tokens, and transcript telemetry gaps (--resetto clear).
- Enable
- Zero-Dependency Live Hooks (
hooks.json)PreInvocation(metadata.user_markdown): Uses Antigravity's officialsystemMessage: ""+metadata.user_markdowncontract to surface inline notices when context crosses thresholds, when cumulative session uncached tokens crosssessionWarnUncachedTokens(default 500K, persists across compactions), when a heavy model swap fires, or when an unprogressed error loop repeats.PreToolUse+PostToolUseDuplicate Read Guard: Tracks only confirmed-successful reads (includingByteOffset,StartLine..EndLine,mtime,size, andpayload.cwdpath resolution), never falsely blocks continuation slices after truncated (> 46 KB/> 800lines) unbounded reads, automatically resets onCHECKPOINT/implicit compaction and after 12 turns, and includes an automatic retry escape hatch.PreToolUseNarrow Read-Only Command Allowlist (overwrite, opt-in): Disabled by default ("commandOverwrite": false); enable manually or viasavermode to add--stat/-n 20 --onelineonly to baregit diff,git log, andgit show <ref>calls with zero pipes/redirects.PreToolUseSwarm Gate: Usesdecision: "ask"before spawning>= 2parallel/swarmworkers (configurable per profile).PostToolUseProgress-Aware Loop Tracker: Resets error streaks on file edits, passing commands, and new user prompts—never interrupting normal TDD cycles.
Quick Start
1. Run Read-Only Diagnosis First (Zero Changes to Antigravity)
# Instant read-only run via npx (no clone or install required)
npx antigravity-quota-guard autopsy --days 7
npx antigravity-quota-guard audit
# Or install the CLI globally (`agy-guard`)
npm i -g antigravity-quota-guard
Or run directly from a local clone:
git clone https://github.com/Yaraill/antigravity-quota-guard.git
cd antigravity-quota-guard
# Last 7 days (anonymized for sharing)
node ./bin/agy-guard.mjs autopsy --days 7
# Full history
node ./bin/agy-guard.mjs autopsy --all
# Inspect cold-start rule, MCP & top skill-source bloat
node ./bin/agy-guard.mjs audit
# Read-only actionable diagnostics (or `--fix --yes` to archive duplicate legacy rule with backup)
node ./bin/agy-guard.mjs doctor
# Compare 7 days before vs. after install (or pass `--since YYYY-MM-DD`)
node ./bin/agy-guard.mjs compare --days 7
2. Install as a Native Antigravity Plugin
# Option A: Install directly via Antigravity CLI
agy plugin install https://github.com/Yaraill/antigravity-quota-guard
# Option B: Curated staged install from a local clone
node ./bin/agy-guard.mjs install
# Check install & Antigravity enabled status
node ./bin/agy-guard.mjs status
# Cleanly remove anytime (preserves user config if created)
node ./bin/agy-guard.mjs uninstall
Restart Antigravity (or reload plugins) to activate hooks, the ultra-lean rules/AGENTS.md (< 450 tokens), and the quota-autopsy / quota-diet skills.
3. Profiles, Thresholds & Workspace Overrides (.agy-guard.json)
# Switch preset profile globally (~/.gemini/config/agy-guard.json)
node ./bin/agy-guard.mjs mode observe # dry-run counters only (never blocks)
node ./bin/agy-guard.mjs mode balanced # default safe warnings + duplicate read guard
node ./bin/agy-guard.mjs mode saver # tighter thresholds + opt-in commandOverwrite + hardLoop=5
node ./bin/agy-guard.mjs mode performance # 200K ctx warning + swarmAsk>=4
# Or write a project-specific override in the current repo (.agy-guard.json)
node ./bin/agy-guard.mjs mode saver --workspace
# Inspect anonymous guard counters & estimated avoided read tokens
node ./bin/agy-guard.mjs stats
# Or generate default global config for manual tuning
node ./bin/agy-guard.mjs config --init
Global settings live in ~/.gemini/config/agy-guard.json; project-level .agy-guard.json files (discovered upward from cwd to repo root) override them cleanly. Invalid numeric bounds automatically emit a warning and fall back to safe defaults.
Metric Transparency (lib/pricing.mjs)
Google does not publish official internal quota multipliers per model. Accordingly:
autopsyalways reports exact raw uncached input tokens first.- Weighted quota impact is explicitly labeled as a relative tier estimate driven by customizable
modelTierWeightsin~/.gemini/config/agy-guard.json(defaults:carbon/opus: 4.0,argon: 2.5,orchestrator: 2.2,neon/sonnet/pro: 2.0,hydrogen: 0.75,flash: 0.5). Adjust these weights anytime to match your plan and observations.
Security & Performance Architecture (2-Minute Audit)
- Zero dependencies & zero network calls: Uses only Node.js built-ins (
node:fs,node:os,node:path,node:crypto). - Private session cache: Stored in a per-user
0700directory insideos.tmpdir()with0600files, auto-expiring after 24h. Stores only SHA-256 path hashes and argument-free executable labels—never raw file paths, command arguments, or secrets. - Serialized + atomic writes: Uses a per-session lockfile (
wxwith stale-lock recovery) plus<file>.<pid>.<rand>.tmp+renameSync(with short WindowsEBUSYretries). - Bounded incremental parsing: Tracks file identity + byte offset with a 4 MB cap per delta read so 100 MB+ transcripts stay well within the 5-second hook timeout.
- Strict fail-open: Any error, lock contention, or failed state persistence returns
{"decision":"allow"}(PreToolUse) or{}and exits0.
Running Tests
npm test
# or
node --test
Companion UI
- Companion UI:
agy-studio— pixel office & multi-agent live monitor side pane for Antigravity.
License
Explore related projects
Loading…