Skip to main content
Glama
README.md
# Context Meter (`agy-ct`)

[![CI](https://github.com/nhanhehehe/agy-ct/actions/workflows/ci.yml/badge.svg)](https://github.com/nhanhehehe/agy-ct/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
[![Node.js >= 22](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen.svg)](https://nodejs.org/)

Live context window observer plugin & MCP App for **Antigravity IDE**, **Antigravity 2.0 (App)**, and **Antigravity CLI**.

Inspect real-time token consumption, model context limit percentage, cache hit rate, compaction events, and per-turn growth directly inside Antigravity's Side Pane, Global Sidebar, or inline in chat via `/context`.

---

## Features

- **Live Context Meter (MCP App UI)**:
  - Tracks current context tokens (`input_tokens + cache_read_tokens`), limit percentage, and health status (`Healthy`, `Warning`, `Near Limit`).
  - Segmented meter showing **Cache Read** vs **New Input** vs **Remaining** capacity, plus `75%` and `90%` markers and quick limit overrides (`Auto`, `200K`, `1M`, `2M`).
  - Interactive SVG **Turn-by-Turn Context Growth** chart with compaction (`↓ Compact`) detection and per-turn tool-call inspection.
  - **Per-Turn Ledger** preserving scroll position across `2.5s` live polling updates.
  - Surface filter (`All`, `IDE`, `App`, `CLI`) and conversation picker displaying real Antigravity conversation titles (`annotations.title` via `ConversationService` and `.pbtxt` annotations).
- **`/context` Slash Command**:
  - Registers `/context` in the chat slash menu (`skills/context/SKILL.md`).
  - Pairs with a `PreInvocation` hook (`hooks.json` -> `dist/hook-context.mjs`) to render a compact single-line Context Window bar inline with **zero model tokens**.
- **Zero External Runtime Dependencies**:
  - Single-file bundled MCP server (`dist/server.mjs`), hook (`dist/hook-context.mjs`), and CSP-compliant single-file HTML app (`dist/app.html`).

---

## Requirements

- **Node.js** `>= 22.0.0` (used both to run the plugin MCP server/hook and to run native TypeScript tests)
- **Antigravity IDE**, **Antigravity 2.0**, or **Antigravity CLI**

---

## Installation

Clone, build, and install into `~/.gemini/config/plugins/context-meter/`:

```bash
git clone https://github.com/nhanhehehe/agy-ct.git
cd agy-ct
npm ci
npm run build
npm run install:plugin
```

Antigravity automatically discovers plugins in `~/.gemini/config/plugins/context-meter/` (on Windows: `%USERPROFILE%\.gemini\config\plugins\context-meter\`).

### Uninstall

```bash
npm run uninstall:plugin
```

---

## Usage

- **Side Pane**: Click `+` in Antigravity's Side Pane and select **Context Meter**.
- **Global Sidebar**: Open **Context Meter** from the left sidebar.
- **Chat**: Ask the agent *"Open the Context Meter to inspect my current context window"* or type `/context` in the chat input.

---

## Architecture

```text
agy-ct/
├── plugin.json                # Antigravity plugin manifest
├── mcp_config.json            # MCP stdio server definition
├── hooks.json                 # PreInvocation hook for /context
├── assets/logo.svg            # Plugin icon
├── skills/context/SKILL.md    # /context slash skill definition
├── src/
│   ├── core/
│   │   ├── models.ts          # Context window limits per model family
│   │   ├── scanner.ts         # Scans ~/.gemini/{antigravity,antigravity-ide,antigravity-cli}/brain
│   │   ├── parser.ts          # JSONL transcript parser, cache/compaction metrics
│   │   └── titles.ts          # ConversationService & .pbtxt annotation title resolver
│   ├── hook-context.ts        # /context PreInvocation hook logic
│   ├── hook-cli.ts            # Async stdin/stdout CLI entrypoint for hook
│   ├── server.ts              # MCP server (open_context_meter, get_context_snapshot, ui:// resource)
│   └── ui/                    # Single-file Vite MCP App (@modelcontextprotocol/ext-apps)
├── scripts/
│   ├── install-plugin.mjs     # Copies built bundle to ~/.gemini/config/plugins/context-meter/
│   └── uninstall-plugin.mjs   # Removes installed plugin directory
└── tests/                     # Unit & MCP stdio smoke tests (node --test)
```

---

## Development

```bash
npm ci
npm run typecheck
npm run build
npm test
```

See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on submitting pull requests.

---

## Security & Privacy

Context Meter reads **only local files** under `~/.gemini/` (and optionally queries the local Antigravity Language Server on `ANTIGRAVITY_LS_ADDRESS` for conversation titles). It makes zero external network requests. See [SECURITY.md](./SECURITY.md) for reporting vulnerabilities.

---

## License

[MIT](./LICENSE) © 2026 Nguyễn Thiện Nhân