Skip to content
المشاريع

Yaraill/antigravity-quota-guard

عرض على GitHub

حول

Local-first quota autopsy, cold-start config auditor, and zero-dependency hooks to curb Google Antigravity Orchestrator cache-miss burn.

أدوات التطوير

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
جارٍ جمع السجل
خلال 7 أيام
جارٍ جمع السجل
خلال 15 يومًا
جارٍ جمع السجل
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل
Code_Generated_Image

antigravity-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:

  1. Read-Only First: agy-guard autopsy
    • Scans local Antigravity transcript.jsonl files (antigravity, antigravity-cli, antigravity-ide).
    • Filters --days N at both file and event-timestamp level (--days 0 or --all for 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 MB lines or delta skips).
    • Privacy-safe by default: Anonymizes session IDs (session-#1) and workspace names (project-#1) for safe screenshot/text sharing (pass --verbose for local IDs/names).
  2. 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).
  3. Cold-Start & Dead-MCP Auditor: agy-guard audit & agy-guard doctor
    • audit detects 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.
    • doctor turns audit + config diagnostics into an actionable checklist. Read-only by default; with --fix --yes, safely archives duplicate legacy ~/.gemini/GEMINI.md to .bak.<timestamp> and backs up/repairs invalid agy-guard.json (never touches MCP configs).
  4. Anonymous Guard Telemetry: agy-guard stats & observeOnly Mode
    • Enable "observeOnly": true (or run agy-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 stats to inspect anonymous lifecycle counters, estimated avoided read tokens, and transcript telemetry gaps (--reset to clear).
  5. Zero-Dependency Live Hooks (hooks.json)
    • PreInvocation (metadata.user_markdown): Uses Antigravity's official systemMessage: "" + metadata.user_markdown contract to surface inline notices when context crosses thresholds, when cumulative session uncached tokens cross sessionWarnUncachedTokens (default 500K, persists across compactions), when a heavy model swap fires, or when an unprogressed error loop repeats.
    • PreToolUse + PostToolUse Duplicate Read Guard: Tracks only confirmed-successful reads (including ByteOffset, StartLine..EndLine, mtime, size, and payload.cwd path resolution), never falsely blocks continuation slices after truncated (> 46 KB / > 800 lines) unbounded reads, automatically resets on CHECKPOINT/implicit compaction and after 12 turns, and includes an automatic retry escape hatch.
    • PreToolUse Narrow Read-Only Command Allowlist (overwrite, opt-in): Disabled by default ("commandOverwrite": false); enable manually or via saver mode to add --stat / -n 20 --oneline only to bare git diff, git log, and git show <ref> calls with zero pipes/redirects.
    • PreToolUse Swarm Gate: Uses decision: "ask" before spawning >= 2 parallel /swarm workers (configurable per profile).
    • PostToolUse Progress-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:

  • autopsy always reports exact raw uncached input tokens first.
  • Weighted quota impact is explicitly labeled as a relative tier estimate driven by customizable modelTierWeights in ~/.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 0700 directory inside os.tmpdir() with 0600 files, 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 (wx with stale-lock recovery) plus <file>.<pid>.<rand>.tmp + renameSync (with short Windows EBUSY retries).
  • 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 exits 0.

Running Tests

npm test
# or
node --test

Companion UI

  • Companion UI: agy-studio — pixel office & multi-agent live monitor side pane for Antigravity.

License

MIT

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…