Skip to main content
Glama
README.md
# Antigravity Token Monitor

[![License: MIT](https://img.shields.io/badge/License-MIT-10b981.svg)](./LICENSE)

A local, read-only plugin for **Google Antigravity** that adds live session context window visibility and historical daily token usage analytics directly inside the harness — with **zero LLM token overhead**, **zero external network calls**, and **zero runtime `npm install`** required.

Supports **English and Polish (`EN | PL`)** out of the box (auto-detected from your locale, switchable in one click).

## Screenshots

| Live Session Context Monitor (Side Pane) | Usage KPIs, Daily Heatmap & Models |
| :---: | :---: |
| ![Live Session Context Monitor](./assets/screenshots/session-view.jpg) | ![Usage KPIs and Daily Heatmap](./assets/screenshots/usage-view.jpg) |

---

## Features

### 1. Live Session Context Monitor *(Auxiliary Side Pane — Sidecar)*
- **Auto-bound to the active conversation**: tracks whichever chat tab you have open (and lets you switch to inspect any recent session).
- **Closable anytime**: lives as a native Side Pane tab (`Token Monitor`) so you can close it (`×`), switch to Files/Terminal/Swarm, or reopen it via `+` whenever you want.
- **Real-time occupancy gauge**: shows exact active context (`input_tokens + cache_read_tokens`), percentage ring + linear progress bar, and a clear **auto-compaction threshold marker (`~500k`)** with remaining tokens countdown.
- **Step-by-step trajectory chart**: interactive SVG chart plotting context growth across turns and marking `CHECKPOINT` compaction drops.
- **Session metrics & subagent rollup**: latest & cumulative cache hit rate, step/compaction counts, fresh (`in + out`) vs total tokens, plus automatic rollup of spawned subagents/swarm workers.
- **Compact Usage tab**: quick glance at 7-day, lifetime, peak day, daily average, today, and a 16-week heatmap right from the side pane.

### 2. Full-Page Usage Analytics & Daily Heatmap *(Left Sidebar — MCP App)*
- **5 KPI summary cards**:
  - **Last 7 days** (rolling 7 local calendar days + trend delta vs prior 7 days)
  - **Lifetime usage** (all-time totals, active days, main vs subagent sessions)
  - **Peak day** (most intense local calendar day, clickable to drill down)
  - **Daily average** (average per active day + average per calendar day)
  - **Today** (live running total, clickable to drill down)
- **GitHub-style daily heatmap**: 90 / 180 / 365 days bucketed in your **local timezone** with quartile-based intensity levels and hover breakdowns.
- **Day drill-down & model breakdown**: click any day cell to inspect per-model shares and every active session (main vs subagent badge, peak context mini-bar, fresh & total tokens, step count).
- **Persistent filters**: toggle **All (with cache)** vs **Fresh (`in + out`)**, **With subagents** vs **Main only**, range (`90d / 180d / 365d`), and **EN / PL** language (saved locally in `PLUGIN_DATA/prefs.json`).

---

## Requirements

- **Google Antigravity 2.0** (Desktop / CLI)
- **Node.js ≥ 22.5** (uses built-in `node:sqlite`; pre-bundled runtime requires **no `npm install`**)

---

## Installation

All runtime artifacts (`dist/mcp-server.cjs`, `dist/sidebar-app.html`, `sidecars/token-monitor/web/index.html`) are pre-built in this repository so installation is a single step.

### Option 1 — Antigravity CLI (`agy`)
```bash
agy plugin install https://github.com/vus955-gif/antigravity-token-monitor
```

### Option 2 — Manual `git clone` (macOS / Linux)
```bash
git clone https://github.com/vus955-gif/antigravity-token-monitor.git ~/.gemini/config/plugins/token-monitor
```

### Option 3 — Manual `git clone` (Windows PowerShell)
```powershell
git clone https://github.com/vus955-gif/antigravity-token-monitor.git "$env:USERPROFILE\.gemini\config\plugins\token-monitor"
```

Antigravity automatically discovers plugins placed under `~/.gemini/config/plugins/`.

---

## Usage

- **Side Pane**: open any conversation, click **`+`** in the right Auxiliary Side Pane, and select **Token Monitor**.
- **Left Sidebar**: click **Token Monitor** in the left navigation bar for the full-page heatmap and analytics dashboard.
- **Slash command**: type **`/token-monitor`** in any chat to surface a one-click toggle pill.

---

## Privacy & How It Works

- **100% local & offline**: reads Antigravity's local `transcript.jsonl` files (`~/.gemini/antigravity/brain/<id>/.system_generated/logs/transcript.jsonl`) and `conversation_summaries.db` in **strict read-only mode**.
- **Zero telemetry / zero external requests**: no analytics, no CDNs, strict CSP (`default-src 'none'`).
- **Fast mtime/size caching**: only re-parses transcripts that have changed on disk; typical warm dashboard queries take ~15–25 ms across 100+ sessions.
- **How context fill is calculated**: Antigravity records `input_tokens` (uncached prompt tokens), `cache_read_tokens` (cached prompt tokens), and `output_tokens` on each `PLANNER_RESPONSE` and `CHECKPOINT` step. Active context window occupancy is `input_tokens + cache_read_tokens`.

---

## Development & Testing

```bash
npm install
npm run build
npm test
```

- `lib/telemetry.mjs` — cached JSONL parser, read-only `node:sqlite` metadata loader, session & daily aggregators
- `lib/models.mjs` — model context limits, `~500k` compaction threshold, human-readable model formatting
- `lib/prefs.mjs` — persisted user preferences (`metric`, `scope`, `days`, `lang`)
- `sidecars/token-monitor/` — Auxiliary Side Pane sidecar server & UI (`web/template.html`, `web/styles.css`, `web/app.js`)
- `mcp/` — Left Sidebar MCP App server & UI (`mcp/server.mjs`, `mcp/ui/*`)
- `scripts/build-ui.mjs` — esbuild pipeline producing zero-dependency `dist/mcp-server.cjs`, `dist/sidebar-app.html`, and self-contained `sidecars/token-monitor/web/index.html`

---

## License

[MIT](./LICENSE) © 2026 [vus955-gif](https://github.com/vus955-gif)