Skip to main content
Glama
README.md
# Agy Usage

A native **Antigravity MCP App plugin** for tracking local token consumption, prompt cache efficiency, 5-hour & weekly rolling quota windows, model/workspace/tool breakdowns, per-conversation context growth, and customizable cost estimates.

100% local, zero external network requests, and theme-native (automatically matches Antigravity light/dark themes across the sidebar, side pane, and inline chat views).

---

## Features

- **Native Antigravity Surfaces**:
  - **Left Sidebar (`global`)**: Full-page analytics view.
  - **Right Side Pane (`aux_pane`)**: Compact responsive view for live monitoring alongside active chats.
  - **Inline Chat**: Triggered by asking the agent to open your usage dashboard.
- **5-Hour & Weekly Rolling Quota Windows**:
  - Percentage-first progress bars (`XX% used`) with green/amber/red thresholds, remaining `%`, burn-rate warnings, and exact roll-off / reset countdowns.
  - Hover for a quick summary or click any bar to expand exact figures (tokens, calls, cost, pace, and `Zoom 5H` / `Edit Cap` actions).
  - Supports tracking **Total Tokens**, **Uncached + Output Tokens**, **Model Calls**, or **Estimated Cost (USD)** across **Rolling 7 Days (168h)** or **Calendar Week (Mon–Sun)**.
- **Interactive Analytics**:
  - **Token Usage Trend**: Stacked bar chart toggleable between *By Token Type* (Uncached Input / Cache Read / Output) and *By Model*, with `5H` (15-min buckets), `24H` (hourly), `7D`, `30D`, `90D`, and `All` ranges.
  - **12-Week Activity Heatmap**: GitHub-style daily usage intensity calendar.
  - **Breakdowns**: Model share, Workspace/Project share (click a project to filter), and Top Tool Calls frequency.
- **Conversation Inspector & Subagent Rollup**:
  - Searchable, sortable conversation table with toggleable **Subagent Rollup** (merges child subagent usage into root conversations).
  - Click any conversation to inspect its **Context Window Growth** chart and step-by-step token & tool call timeline.
- **Configurable Limits & Pricing**:
  - Customize 5h/weekly caps and per-model `$/1M tokens` rates (persisted in `${PLUGIN_DATA}`).
- **Live Auto-Refresh & CSV Export**:
  - Configurable live polling (`Off` / `5s` / `15s` / `30s`) with `mtime + size` transcript caching, plus one-click CSV export.

---

## Requirements

- **Antigravity** (Desktop App or CLI)
- **Node.js `>= 22.5`** (uses built-in `node:sqlite`, so no native C++ compilation is required)
- **macOS, Linux, or Windows** (`mcp_config.json` launches `node` directly — no `bash` or `npm install` needed)

---

## Installation

### Option 1: Install via GitHub URL (Recommended for Users)

Once pushed to GitHub, any Antigravity user can install directly without cloning or building (pre-built `dist/` artifacts are included in the repository):

**Antigravity CLI:**

```bash
agy plugin install https://github.com/ballballsun/agy-usage
```

**Antigravity App:** Open **Customizations → Plugins**, choose **Install from URL**, and paste `https://github.com/ballballsun/agy-usage`.

### Option 2: Build & Install Locally from Source

```bash
npm install
npm run typecheck
npm test
npm run build
npm run install-plugin
```

`npm run install-plugin` copies the self-contained plugin into:

```text
~/.gemini/config/plugins/agy-usage/
```

Antigravity automatically discovers plugins in `~/.gemini/config/plugins/` without requiring a restart.

### Option 3: Share as a Zip Archive

To share your built plugin directly (no `node_modules` needed, ~1.6 MB total):

```bash
cd ~/.gemini/config/plugins && zip -r ~/Desktop/agy-usage-plugin.zip agy-usage
```

The recipient unzips `agy-usage/` into their own `~/.gemini/config/plugins/agy-usage/` directory.

---

## Usage

Once installed and enabled:

1. **Full Page**: Click **Agy Usage** in Antigravity's left sidebar.
2. **Side Pane**: Click `+` in the right auxiliary pane and select **Agy Usage** (pair with `Live: 5s` or `15s` auto-refresh while running agents).
3. **From Chat**: Ask Antigravity *"Open my Agy Usage dashboard"* or *"Show my usage for the last 7 days"*.

---

## Data Sources, Accuracy & Privacy

- **Strictly Local & Read-Only**: The server reads only local Antigravity files and makes zero outbound network requests:
  - `~/.gemini/antigravity/brain/<conversation-id>/.system_generated/logs/transcript.jsonl` — exact per-step `created_at`, `model`, `input_tokens`, `cache_read_tokens`, `output_tokens`, and `tool_calls`.
  - `~/.gemini/antigravity/conversation_summaries.db` — opened read-only for conversation titles, workspace paths, and parent/subagent relationships.
- **Persistent Settings**: Custom pricing (`pricing.json`) and quota caps (`limits.json`) are stored inside Antigravity's `${PLUGIN_DATA}` directory, completely separate from the plugin bundle.
- **About Limits & Estimated Costs**: Antigravity does not expose a documented local API for official server-side account quota ceilings or billing amounts. The 5-hour/weekly caps and USD costs shown in the dashboard are **local configurable estimates** that you can tune in the **Limits & Pricing** tab.

---

## Project Structure

```text
.
├── plugin.json              # Antigravity plugin manifest (repo root = installable plugin)
├── mcp_config.json          # Cross-platform MCP server config (`node dist/server.mjs`)
├── assets/logo.svg          # Plugin icon
├── dist/                    # Pre-built standalone server & single-file UI (committed for zero-build Git installs)
│   ├── server.mjs
│   └── ui/index.html
├── scripts/
│   └── install-plugin.mjs   # Copies plugin files into ~/.gemini/config/plugins/agy-usage
├── src/
│   ├── shared/types.ts      # Shared server/UI TypeScript contracts
│   ├── server/
│   │   ├── index.ts         # MCP server (resources + model & app-only tools)
│   │   ├── usageParser.ts   # SQLite & JSONL parser, rollup, rolling windows, heatmap, CSV
│   │   ├── pricingStore.ts  # Per-model USD pricing persistence & cost calculation
│   │   ├── limitsStore.ts   # 5h & weekly limit cap persistence
│   │   └── usageParser.test.ts
│   └── ui/
│       ├── App.tsx          # Main MCP App React component
│       ├── styles.css       # Theme-native CSS using Antigravity host variables
│       ├── utils/format.ts
│       └── components/
│           ├── RollingLimitsCard.tsx
│           ├── TokenTrendChart.tsx
│           ├── ActivityHeatmap.tsx
│           ├── ConversationDrawer.tsx
│           └── PricingTab.tsx
├── vite.config.ts           # Single-file HTML bundle config (vite-plugin-singlefile)
└── vitest.config.ts
```

## Development Scripts

| Command | Description |
| --- | --- |
| `npm run typecheck` | Run TypeScript strict type-checking (`tsc --noEmit`) |
| `npm test` | Run Vitest unit test suite |
| `npm run build` | Build single-file UI (`dist/ui/index.html`) and standalone MCP server (`dist/server.mjs`) |
| `npm run install-plugin` | Install built plugin files into `~/.gemini/config/plugins/agy-usage` |