docs(readme): refresh documentation, unify surface previews, and re-render v1.5 gallery

This commit is contained in:
fish
2026-11-17 14:01:26 +09:00
parent 6e41f016f6
commit 210e4ec785
8 changed files with 383 additions and 185 deletions
+186 -87
View File
@@ -1,95 +1,147 @@
<div align="center">
<img src="assets/logo.svg" alt="Antigravity Usage & Speed Monitor Logo" width="84" />
# Antigravity Usage & Speed Monitor
English | [简体中文](README.zh-CN.md)
Local usage, speed, context, and quota monitor for Google Antigravity 2.0, Antigravity IDE, and Antigravity CLI, with no external npm dependencies.
**Real-time usage & speed monitor for Google Antigravity 2.0, IDE, and CLI.**<br>
Track token generation speed (TPS), time-to-first-token (TTFT), context window usage, official model quotas, subagent activity, and historical token consumption — across Windows, macOS, Linux, and headless CLI servers.
[![Release](https://img.shields.io/github/v/release/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=2A5E76&label=release)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/yuhuan-dev/antigravity-usage-monitor/total?style=flat-square&color=0ea5e9)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases)
[![Stars](https://img.shields.io/github/stars/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=f59e0b)](https://github.com/yuhuan-dev/antigravity-usage-monitor/stargazers)
[![License](https://img.shields.io/github/license/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=3b82f6)](LICENSE)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20npm%20packages-10b981?style=flat-square)](#local-development)
[![Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20macOS%20%7C%20Linux-6366f1?style=flat-square)](#client-support)
![Antigravity Usage Monitor Preview](assets/preview.png)
English · [简体中文](README.zh-CN.md)
**[Download Latest Release](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest)** · **[Download ZIP (`usage-monitor.zip`)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip)**
[Features](#features) · [Screenshots](#screenshots) · [Client Support](#client-support) · [Installation](#installation) · [Usage](#usage) · [Development](#local-development)
## Features
<br />
- **Real-time Speed Monitoring** — Track live TPS, TTFT, session average generation speed, and estimated step/session API cost.
- **10-Channel Context Window Analysis** — Visualize active context usage across assistant replies, tool results, user messages, subagent notifications, compaction summaries, system prompts, system tools, MCP tools, Skills, and user rules.
- **Model Quota Tracking** — Monitor 5-hour and weekly official quotas across `Gemini`, `Gemini 4 Argon`, `Gemini 4 Carbon`, and `Claude & GPT` pools with live reset countdowns.
- **Subagent Analytics** — Inspect main-agent and subagent calls, context windows, and compaction steps independently or in aggregate.
- **Token Usage Statistics** — Explore historical consumption, cache hit efficiency & savings, interactive trend charts, and model rankings.
- **Dual-Mount Interface** — Run the compact top-bar floating capsule alongside the right-hand side-panel dashboard without modifying `app.asar`.
- **Built-in Cloud Sync & Updates** — Dynamically sync model pricing catalogs and manage 3-tier update modes (`manual` / `auto` / `off`).
<img src="assets/preview.png" alt="Antigravity Usage Monitor Preview" width="100%" />
### Token Usage Analytics
<br />
![Token Analytics](assets/analytics.png)
[Latest Release](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest) · [Download ZIP (`usage-monitor.zip`)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip)
### Context Window & Quota Monitoring
![Context Window Analysis](assets/context.png)
### Subagent & Step-by-Step Call Details
![Subagent and Step Analytics](assets/subagents.png)
</div>
---
## Panel Overview
## Features
The dashboard is organized into four tabs, with a top header to switch conversations, filter by **All / Main Agent / Subagent**, or manually refresh quotas:
- **Live Metrics & Customizable Layout**: Tracks output speed (`tok/s`), time-to-first-token (`TTFT`), session average speed, step/session USD cost, cache hit rate, tightest remaining quota, and session tokens. You can choose and reorder the overview metric cards (4 shown by default out of 9 options) and section blocks.
- **10-Category Context Breakdown**: Shows the token breakdown of the latest request across assistant replies, tool results, user messages, subagent notifications, checkpoints, system prompts, system tools, MCP tools, skills, and user rules, with a switcher between the main agent and spawned subagents.
- **Quota Pool Tracking**: Reads 5-hour and weekly quotas, reset timers, and cycle consumption across `Gemini`, `Gemini 4 Argon`, `Gemini 4 Carbon`, and `Claude & GPT` pools, preserving cached pool status with a stale badge when upstream quota data is temporarily unavailable.
- **Main Agent, Subagents & Multi-Session Views**: Merges main agent and subagent steps in chronological order (or filters by individual agent), renders optional turn rails, expands running subagent tasks inline, and provides a recent-conversation selector in the header.
- **Call Details & Custom Token Formats**: Includes **By Step** and **By Model** tabs (with multi-model throughput charts). Supports 2–14 configurable columns, optional speed color grading, preset `Ctx / Think / Reply` and `In / Out / Cache` columns, and custom token combination strings such as `context:new:cache` or `in:out:cache`.
- **Historical Usage & Breakdowns**: Summarizes tokens, uncached input vs. cache-read savings, thinking/output split, hourly/daily trend curves, model rankings, client attribution (`Desktop App` / `IDE` / `CLI`), and monthly bar charts across `Today`, `1d`, `7d`, `14d`, `30d`, `All`, or custom date/time ranges.
- **Multi-Client Capsules & Hover Popover**: Integrates as a titlebar or composer capsule and auxiliary sidebar in Antigravity 2.0, a titlebar/composer capsule in Antigravity IDE, a single-line 24-bit ANSI `statusLine` in Antigravity CLI (`agy`), and a standalone local web UI. Supports 1–5 customizable capsule slots, configurable hover cards, and `Auto Fit` or fixed (`440–1080 px`) popover widths.
- **No `app.asar` Modification**: Titlebar/composer injection and context request hooks run in memory over local CDP (`DevToolsActivePort`). On Antigravity IDE, the only host file updated is adding `"remote-debugging-port": "0"` to `~/.antigravity-ide/argv.json`; installation binaries and `app.asar` are never altered.
- **Per-Model Context Windows**: Sets context window limits per model series (across thinking levels) or follows host defaults under Settings. Desktop/IDE applies rules at runtime on outbound requests; CLI applies `AGY_CLI_AUTO_COMPACT_OVERRIDE`.
- **Appearance, Offline Storage & Cloud Updates**: Supports `zh-CN` / `en-US` / host language, `sm / md / lg / xl` font scaling, 6 theme accents plus host matching, offline reading from CLI SQLite + WAL, `annotations/*.pbtxt`, `transcript.jsonl`, and `.deep_stats_cache.json`, GitHub [`pricing-catalog.json`](pricing-catalog.json) sync, in-panel release updates (`manual` / `auto` / `off`), and cache rebuild/settings reset tools.
- **Live Overview**
- **Core Metrics**: Output speed (TPS), TTFT, average generation speed, latest step cost, and cumulative session cost (viewable per main agent, per subagent, or combined).
- **Context Window**: Switchable per agent, decomposed into 10 sources dynamically ordered by token footprint: assistant replies, tool results, user messages, subagent notifications, compaction summaries, system prompts, system tools, MCP tools, Skills, and user rules.
- **Quota Pools**: Displays 5-hour and weekly limits with reset countdowns for `Gemini`, `Gemini 4 Argon`, `Gemini 4 Carbon` (dedicated pools on Pro accounts), and `Claude & GPT`, plus live multi-session execution cards.
- **Usage Analytics**
- Filter by Today, 1d, 7d, 14d, 30d, All, or custom date-time ranges.
- Summarizes total tokens, API-equivalent cost, and cache hit rate, breaking down uncached input, cache reads (including estimated USD saved), and output + thinking usage.
- Includes an interactive usage trend chart, model rankings, client source distribution, and monthly breakdown bars.
- **Call Details**
- **By Step**: Lists every step in the selected conversation with its model, TPS, TTFT, context/output tokens, cache hit rate, and step cost.
- **By Model**: Aggregates call counts, mean speed, total tokens, and cost per model within the current session and selected agent scope.
- **Preferences**
- **Mount Mode & Popover Width**: Choose Dual-mount (Top Bar + Sidebar), Composer mount, or Sidebar only; the floating popover defaults to **Auto Fit** (expanding automatically on wide step tables within viewport bounds to avoid horizontal scrolling) or accepts a custom fixed width (`440–1080 px`).
- **Top-Bar & CLI Capsule Customization**: Independently toggle the live running-sessions indicator and the Antigravity CLI bottom status capsule (auto-provisioned via `~/.gemini/antigravity-cli/settings.json` `statusLine`), and customize 1 to 5 metric slots and their left-to-right order (defaulting to Output Speed, TTFT, and Context Usage).
- **Call Details & Custom Token Combos**: Under **Structure -> Step Table**, independently toggle main/subagent badges, the turn rail (off by default), and **Speed Multi-Color** grading (off by default); keep the default `Ctx / Think / Reply` combo column, switch to the billing-aligned `In / Out / Cache` preset (with per-segment cost breakdown on hover), or enter a custom format string such as `context:new:cache` or `in:out:cache`.
- **Model Name Format**: Choose among Compact short alias (e.g. `argon-4-high`), full raw upstream ID, or Trimmed raw ID (hiding `gemini-`, `claude-`, and `gpt-` prefixes to save single-line space, e.g. `3.8-flash-n`, `sonnet-4-6`, `5.4-mini`), with compaction suffixes (`·compact`) protected from ellipsis truncation; Orchestrator series IDs remain independently configurable.
- **Per-model context windows**: In **Other → Model Context Settings**, choose a shared limit for all thinking levels of a model or select **Follow host settings**. The model list shows the saved limit and the most recent value reported by the host. At startup, the App / IDE window bridge reads the latest model catalog and reapplies saved limits to future messages. The CLI uses `AGY_CLI_AUTO_COMPACT_OVERRIDE`.
- **Version Updates & Pricing Sync**: Dynamically sync [`pricing-catalog.json`](pricing-catalog.json) from GitHub, with three update modes: *Notify only, manual update* (default), *Auto update*, and *Off*.
---
## Model Identification & Cost Accounting
## Screenshots
Model identity is resolved directly from each step's raw usage or matching generator metadata. Automatic context compaction may use a separate model; explicitly recorded models are never overwritten. When a compaction step lacks an explicit model, it is inferred from known steps in the same conversation — preferring preceding, then following provider-compatible steps before relaxing provider constraints. Inferred models are used for display and cost estimation rather than claiming server-confirmed compaction identity; when no evidence is available, the step is marked as unknown compaction.
### IDE & CLI
When a model or its pricing cannot be confirmed, single-step cost is shown as pending while tokens are still counted; aggregate totals sum all steps with confirmed rates. Catalogued models are calculated using public API per-million-token rates for local cost reference only — this does not represent subscription quota deduction ratios.
<table>
<tr>
<td align="center">
<img src="assets/ide-preview.png" alt="Antigravity IDE Titlebar Capsule and Hover Overview" width="100%" />
<br />
<b>Antigravity IDE</b>
<br />
<sub>Titlebar capsule and hover popover showing step cost, context usage, and pool quotas</sub>
</td>
</tr>
<tr>
<td align="center">
<img src="assets/cli-preview.png" alt="Antigravity CLI Native statusLine Capsule" width="100%" />
<br />
<b>Antigravity CLI (<code>agy</code>)</b>
<br />
<sub>Single-line transparent 24-bit ANSI bottom <code>statusLine</code> with active count, TPS, TTFT, and context percentage</sub>
</td>
</tr>
</table>
On upgrade, historical cached entries are re-verified against raw trajectory records. Ambiguous default Argon labels from legacy caches remain unresolved if raw records are temporarily unavailable, while preserving token counts and valid timings. Compaction steps display full-request TPS in step tables but are excluded from session speed and TTFT averages.
### Panel Tabs
<table>
<tr>
<td align="center" width="33.3%">
<img src="assets/context.png" alt="Live Overview and Quotas" />
<br />
<b>Live Overview</b>
<br />
<sub>TPS, TTFT, 10-category context bar, quota pools, and active tasks</sub>
</td>
<td align="center" width="33.3%">
<img src="assets/analytics.png" alt="Usage Statistics" />
<br />
<b>Usage Statistics</b>
<br />
<sub>Token totals, cache hit rate, trend chart, and model breakdown</sub>
</td>
<td align="center" width="33.3%">
<img src="assets/subagents.png" alt="Call Details and Subagents" />
<br />
<b>Call Details</b>
<br />
<sub>Step-by-step agent badge, model, speed, TTFT, tokens, and cost</sub>
</td>
</tr>
</table>
---
## Client Support
| Client | Status Capsule / Bar | Panel UI | Offline SQLite &amp; Logs | Per-Model Context Limit | Modifies `app.asar` |
| :--- | :---: | :---: | :---: | :---: | :---: |
| **Antigravity 2.0 (Desktop)** | Titlebar / Composer | Popover + Right Sidebar | Yes | Window Request Hook | No |
| **Antigravity IDE** | Titlebar / Composer | Capsule Popover | Yes | Window Request Hook | No |
| **Antigravity CLI (`agy`)** | Native ANSI `statusLine` | Standalone Web (`--port`) | Yes (`node:sqlite` + `.pbtxt`) | `AGY_CLI_AUTO_COMPACT_OVERRIDE` | No |
| **Remote / Headless Linux** | Native ANSI `statusLine` | SSH Tunnel / `--token` Web | Yes | `AGY_CLI_AUTO_COMPACT_OVERRIDE` | No |
> [!NOTE]
> On **Antigravity IDE**, enabling the plugin automatically adds `"remote-debugging-port": "0"` to `~/.antigravity-ide/argv.json` (preserving comments and existing keys) via a zero-tool MCP keep-alive entry (`0` context tokens). Restart Antigravity IDE once after the first activation so the titlebar capsule can attach.
---
## Installation
Keep the plugin folder named `usage-monitor`. No `npm install` is required.
Keep the folder name as `usage-monitor`. **No `npm install` is needed.**
### Option 1: Clone via Git
### Option 1: Git Clone
**Windows (PowerShell)**
```powershell
# Windows (PowerShell)
git clone https://github.com/yuhuan-dev/antigravity-usage-monitor.git "$env:USERPROFILE\.gemini\config\plugins\usage-monitor"
```
**macOS / Linux**
```bash
# macOS / Linux
git clone https://github.com/yuhuan-dev/antigravity-usage-monitor.git ~/.gemini/config/plugins/usage-monitor
```
Or ask Antigravity directly in chat:
Or ask Antigravity directly:
```text
Clone https://github.com/yuhuan-dev/antigravity-usage-monitor to ~/.gemini/config/plugins/usage-monitor and enable the plugin
```
### Option 2: Download & Extract ZIP
### Option 2: Release ZIP
Download [`usage-monitor.zip`](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip) and extract it into `~/.gemini/config/plugins/`.
Download [`usage-monitor.zip`](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip) and extract it into `~/.gemini/config/plugins/` so the directory path is `~/.gemini/config/plugins/usage-monitor`.
<details>
<summary>Windows PowerShell command for ZIP installation</summary>
**Windows PowerShell:**
```powershell
$pluginsDir = "$env:USERPROFILE\.gemini\config\plugins"
New-Item -ItemType Directory -Path $pluginsDir -Force | Out-Null
@@ -97,57 +149,104 @@ Invoke-WebRequest -Uri "https://github.com/yuhuan-dev/antigravity-usage-monitor/
Expand-Archive -Path "$env:TEMP\usage-monitor.zip" -DestinationPath $pluginsDir -Force
```
## Enabling & Opening the Panel
</details>
---
## Usage
1. Open **Customizations → Installed** in the left sidebar and enable `usage-monitor`.
2. **Antigravity 2.0 (Desktop)**:
- Mounts a capsule in the top-right titlebar (**hover** for summary, **click** for the 4-tab popover, **right-click** to refresh), alongside the right auxiliary sidebar pane.
3. **Antigravity IDE**:
- **Restart Antigravity IDE once** after enabling for the first time. Keep **Mount Mode** on **Dual-mount** and click the top-bar capsule to open the panel.
4. **Antigravity CLI (`agy`)**:
- When `~/.gemini/antigravity-cli` exists, `statusLine` in `settings.json` is configured automatically (existing third-party `statusLine.command` entries are left untouched) to render a single-line ANSI bar (`● 1 active 38.1 t/s | 0.85s | ◎ 17%`).
- Toggle via `/statusline` in `agy` or **Preferences → Structure → Mount & Capsule Bar**.
5. **Standalone Web Server (Headless / Remote)**:
1. Open **Customizations** in the left sidebar, switch to the **Installed** tab, locate `usage-monitor`, and toggle it on.
2. **Top-Bar Floating Capsule (enabled by default on both Antigravity 2.0 & Antigravity IDE)**:
- **Antigravity 2.0 App**: Immediately mounts a live status & metric capsule in the top-right bar of the main chat window (hover for quick overview, left-click to expand the full 4-tab panel, right-click to force refresh) without modifying `app.asar`.
- **Antigravity IDE**: On first enable, the background sidecar automatically adds `"remote-debugging-port": "0"` to `~/.antigravity-ide/argv.json` (preserving comments and existing settings). **Restart Antigravity IDE once**, and the capsule will dock into the top-right IDE window titlebar on every launch. Because Antigravity IDE does not currently expose the right-hand UI Sidecar auxiliary pane, keep **Mount Mode** set to *Dual-mount* in IDE and click the top-bar capsule to open the 4-tab dashboard.
3. **Right-Hand Sidebar Panel (Antigravity 2.0)**: Open the auxiliary sidebar menu in the chat window to dock **Usage & Speed Monitor** on the right, or switch **Mount Mode** between *Top Bar + Sidebar* and *Sidebar only* in Preferences.
4. **Antigravity CLI Bottom Status Capsule & Headless Standalone Web Mode**:
- **CLI Bottom Status Capsule (`statusLine`, enabled by default)**: When `~/.gemini/antigravity-cli` is present, the plugin automatically configures native `statusLine` in `settings.json` (any existing custom third-party `statusLine.command` is strictly preserved) to render a single-line transparent 24-bit ANSI status bar at the bottom of `agy` (keeping `? for shortcuts` on the left, live metrics such as `● 1 active 38.1 t/s | 0.85s | ◎ 17%` centered, and mode/model/effort on the right). Toggle it anytime via `/statusline` in the CLI or **Preferences -> Mount & Capsule Bar**.
- **Offline Transcript Fallback & Auto-Upgrade**: On terminal-only machines or remote Linux servers, the backend automatically discovers `~/.gemini/antigravity-cli` (`daemon/hub_*.json`, SQLite `.db` trajectories, and `transcript.jsonl`). When `agy` is offline, historical sessions and token accounting still load from local records and automatically upgrade to full live RPC telemetry once `agy` starts.
- **Manual launch (recommended with SSH port forwarding)**:
```bash
# On the remote server (binds strictly to 127.0.0.1:8787 by default)
# 1. Start on the host (listens on 127.0.0.1:8787 by default)
node ~/.gemini/config/plugins/usage-monitor/sidecars/panel/standalone.mjs --port 8787
# Forward from your local machine, then open http://localhost:8787
# 2. Forward the port locally and open http://localhost:8787
ssh -L 8787:127.0.0.1:8787 user@your-server
```
- **Auto-host alongside `agy`**: Set `USAGE_MONITOR_STANDALONE_PORT=8787` or `"standalonePort": 8787` in `~/.gemini/antigravity-cli/sidecar_data/usage-monitor/panel/data/settings.json` to host the standalone Web UI automatically whenever the plugin's MCP supervisor starts.
- **Token-protected non-loopback access**: Binding to `0.0.0.0` or a LAN IP requires `--token <secret>` (or `USAGE_MONITOR_STANDALONE_TOKEN`); unauthenticated non-loopback startup is refused.
## Updating
<details>
<summary>Standalone CLI flags, background auto-start, and non-loopback token auth</summary>
The plugin includes built-in cloud version checks and one-click self-updating:
- When a new release is available, a subtle update badge appears next to the top-bar capsule and inside the panel header — click it to pull the update and reload automatically, or manage update behavior and pricing catalog sync in **Preferences -> Version Updates**.
- **Auto-start with `agy`**: Set `USAGE_MONITOR_STANDALONE_PORT=8787` or `"standalonePort": 8787` in `~/.gemini/antigravity-cli/sidecar_data/usage-monitor/panel/data/settings.json` to start the web UI together with the MCP sidecar supervisor.
- **Non-loopback auth**: Binding to `0.0.0.0` or a LAN address requires `--token <secret>` (or `USAGE_MONITOR_STANDALONE_TOKEN`); starting on a non-loopback address without a token is rejected.
- **Overrides**: Supports `--data-dir`, `--app-data-dir`, `--gemini-dir`, `--ls-addr`, and `--csrf-token`.
- **Offline fallback**: When `agy` is not running, the backend reads `~/.gemini/antigravity-cli` (`conversation_summaries.db`, `conversations/*.db`, `annotations/*.pbtxt`, and `transcript.jsonl`) and switches to live RPC once `agy` starts.
To update manually from the command line:
- **Git installations** — pull the latest fast-forward commits and toggle the plugin off/on in **Customizations -> Installed**:
</details>
```powershell
# Windows PowerShell
git -C "$env:USERPROFILE\.gemini\config\plugins\usage-monitor" pull --ff-only
```
---
```bash
# macOS / Linux
git -C ~/.gemini/config/plugins/usage-monitor pull --ff-only
```
## Configuration & Calculation Notes
- **ZIP installations** — download the new `usage-monitor.zip`, extract over the existing folder, and toggle the plugin off/on. Local caches and user settings are stored separately in `~/.gemini/antigravity/sidecar_data/usage-monitor/` (or `sidecars/panel/.data/` when run standalone), so updating never erases historical usage data.
<details>
<summary>UI options: mount mode, capsule slots, token formats, model IDs, and context limits</summary>
- **Mount Mode & Width**: Switch between **Dual-mount (Top Bar + Sidebar)**, **Composer**, and **Sidebar only**. Popover width defaults to **Auto Fit** (expands within window bounds for wide tables) or a fixed width (`440–1080 px`).
- **Capsule Slots**: Choose 1–5 metric slots and reorder them (default: Output Speed, TTFT, Context Usage), plus an optional toggle for the active-session indicator.
- **Call Details Table & Token Format**: Toggle agent badges, turn rail (off by default), and speed color grading (off by default). Choose `Ctx / Think / Reply`, `In / Out / Cache` (with per-item USD tooltips), or custom format strings like `context:new:cache` or `in:out:cache`.
- **Model Name Format**: Choose **Compact short alias** (`argon-4-high`), **Full raw ID**, or **Trimmed raw ID** (strips `gemini-` / `claude-` / `gpt-` prefixes while keeping `·compact` suffixes intact). Orchestrator series IDs have a separate setting.
- **Per-Model Context Limits**: Configure limits per model across thinking levels or follow host defaults under **Preferences → Other → Model Context Settings**. App/IDE applies saved rules at startup; CLI sets `AGY_CLI_AUTO_COMPACT_OVERRIDE`.
</details>
<details>
<summary>Model identification, compaction inference, and cost estimation rules</summary>
- **Model Resolution**: Read from each step's raw usage payload or matching generator metadata; explicit models are never overwritten. When an automatic compaction step omits the model field, it is inferred from adjacent steps in the same conversation (checking prior steps first, then following steps, preferring the same provider) for display and estimation, or shown as unknown compaction if none exist.
- **Cost Calculation**: If a model or price entry cannot be resolved, step cost is shown as pending while tokens still count toward totals; session totals sum all resolved steps. USD numbers are estimated from public per-million-token API pricing in [`pricing-catalog.json`](pricing-catalog.json) for reference only and do **not** reflect subscription quota consumption.
- **Cache & Speed Averages**: Upgrading re-checks cached entries against raw trajectory data while preserving token counts and valid timings. Compaction steps display request TPS in step tables but are excluded from session speed and TTFT averages.
</details>
<details>
<summary>Updating and data directory</summary>
- **In-Panel Update**: When a new GitHub release is available, a version badge appears next to the capsule and in the panel header. Update mode (`Manual` / `Auto` / `Off`) and price catalog sync can be configured under **Preferences → Other**.
- **Manual Git Update**:
- Windows: `git -C "$env:USERPROFILE\.gemini\config\plugins\usage-monitor" pull --ff-only`
- macOS / Linux: `git -C ~/.gemini/config/plugins/usage-monitor pull --ff-only`
- Toggle the plugin off and back on in **Customizations → Installed**.
- **Data Persistence**: Settings and parsed caches live in `~/.gemini/antigravity/sidecar_data/usage-monitor/` (or `sidecars/panel/.data/` in standalone mode), so updates keep existing history intact.
</details>
---
## Local Development
After editing frontend source files under `sidecars/panel/src/`, rebuild `app.js` and `styles.css` from `sidecars/panel`:
All backend and frontend modules use Node.js ESM and native Web Components with **no external npm dependencies** (Node.js 22.5+ is recommended for built-in `node:sqlite`).
```bash
cd sidecars/panel
# Rebuild app.js and styles.css after modifying src/
npm run build
```
Run the model identity, cache migration, quota pool, and timing regression test suite (zero external dependencies required):
```bash
# Run unit and integration tests
npm test
```
## Contributing & License
Issues and pull requests are welcome. If you modify files under `sidecars/panel/src/`, please rebuild via `npm run build` and make sure `npm test` passes.
Licensed under the [GNU General Public License v3.0](LICENSE).
## Star History
<a href="https://www.star-history.com/#yuhuan-dev/antigravity-usage-monitor&Date">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date&theme=dark" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date" />
</picture>
</a>
+190 -91
View File
@@ -1,95 +1,147 @@
<div align="center">
<img src="assets/logo.svg" alt="Antigravity Usage & Speed Monitor Logo" width="84" />
# Antigravity Usage & Speed Monitor
[English](README.md) | 简体中文
Google Antigravity 2.0、Antigravity IDE 与 Antigravity CLI 的本地用量、速率、上下文与配额监控插件,无外部 npm 依赖。
**Google Antigravity 2.0 / IDE / CLI 实时监控插件。**<br>
一站式查看生成速度(TPS)、首字延迟(TTFT)、十维上下文窗口占用、官方模型配额、子代理追踪与历史 Token 消耗(支持 Windows / macOS / Linux 及无头服务器 CLI)。
[![Release](https://img.shields.io/github/v/release/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=2A5E76&label=release)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/yuhuan-dev/antigravity-usage-monitor/total?style=flat-square&color=0ea5e9)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases)
[![Stars](https://img.shields.io/github/stars/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=f59e0b)](https://github.com/yuhuan-dev/antigravity-usage-monitor/stargazers)
[![License](https://img.shields.io/github/license/yuhuan-dev/antigravity-usage-monitor?style=flat-square&color=3b82f6)](LICENSE)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20npm%20%E4%BE%9D%E8%B5%96-10b981?style=flat-square)](#本地开发)
[![Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20macOS%20%7C%20Linux-6366f1?style=flat-square)](#客户端支持)
![Antigravity Usage Monitor 界面预览](assets/preview.png)
[English](README.md) · 简体中文
**[下载最新版本 (Releases)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest)** · **[直接下载压缩包 (`usage-monitor.zip`)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip)**
[功能](#功能) · [截图](#截图) · [客户端支持](#客户端支持) · [安装](#安装) · [使用方式](#使用方式) · [开发](#本地开发)
## 核心特性
<br />
- **实时速度监控** — 追踪实时输出速度(TPS)、首字延迟(TTFT)、会话平均速度以及单步/累计折算费用。
- **十维上下文窗口拆解** — 直观查看模型回复、工具结果、用户消息、子代理通知、压缩摘要、系统提示词、系统工具、MCP 工具、Skill 与用户规则的实时占用比例。
- **多池模型额度追踪** — 同步展示 `Gemini`、`Gemini 4 Argon`、`Gemini 4 Carbon` 与 `Claude & GPT` 模型池的 5 小时限额、每周限额及重置倒计时。
- **主代理与子代理独立统计** — 支持全局汇总或单独切换查看主代理与任意子代理的调用明细、上下文窗口及压缩步骤。
- **历史 Token 用量统计** — 按多时间维度统计 Token 消耗、缓存命中率与节省金额、交互式趋势曲线及模型费用排行。
- **顶部栏 + 侧边栏双栖挂载** — 主窗口右上角悬浮胶囊与右侧辅助栏面板协同工作,全程不修改宿主 `app.asar`。
- **内置价格同步与版本更新** — 支持云端动态同步模型价格表,并提供手动提示更新、自动更新与关闭更新三档模式。
<img src="assets/preview.png" alt="Antigravity Usage Monitor 界面预览" width="100%" />
### 历史用量与趋势统计
<br />
![历史用量与趋势统计](assets/analytics.png)
[下载最新版本 (Releases)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest) · [下载压缩包 (`usage-monitor.zip`)](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip)
### 上下文窗口与模型配额
![上下文窗口与模型配额](assets/context.png)
### 主代理与子代理调用明细
![主代理与子代理调用明细](assets/subagents.png)
</div>
---
## 功能概览
## 功能
面板分为四个标签页,顶部可切换要查看的会话、按全部/主代理/子代理筛选或手动刷新配额:
- **实时指标与版面编排**:统计单步输出速度(`tok/s`)、首字延迟(`TTFT`)、会话平均速度、单步/累计费用、缓存命中率、最紧缺配额与已用 Token;可在设置中从 9 项指标中自由勾选并拖拽排序(默认展示 4 项),并调整实时监控各模块顺序。
- **10 类上下文窗口构成**:展示最近一次请求的上下文占比,按占用列出模型回复、工具结果、用户消息、子代理通知、压缩摘要、系统提示词、系统工具、MCP 工具、Skill 与用户规则,支持在主代理与任意子代理之间切换查看。
- **配额池监控与过期提示**:追踪 `Gemini`、`Gemini 4 Argon`、`Gemini 4 Carbon` 与 `Claude & GPT` 配额池的 5 小时及每周余量、重置倒计时与周期累计用量;上游接口暂未返回新数据时保留缓存余量并显示陈旧提示。
- **主/子代理联动与多会话管理**:按时间归并展示主代理与各子代理调用步骤(也可按单一代理过滤),支持可选轮次分组导轨与运行中子代理卡片原地展开,并在顶栏切换最近会话。
- **调用明细与自定义 Token 格式**:包含「按步查看」与「按模型汇总」(含多模型拟合图);支持增删与排序 2–14 列、独立开关速度分段配色,除预设的 `上下文 / 思考 / 正文` 和 `输入 / 输出 / 缓存` 外,可通过 `context:new:cache`、`in:out:cache` 等语法自定义 Token 组合展示。
- **历史用量与来源统计**:按今天、1 天、7 天、14 天、30 天、全部或自定义起止日期时间统计总 Token、新输入与缓存读取节省金额、输出/思考拆分、按小时/按天趋势折线图、模型排行、客户端来源(App / IDE / CLI)与月度柱状图。
- **多端胶囊与悬浮速览**:支持 Antigravity 2.0 顶栏/输入框停靠胶囊与右侧辅助栏、Antigravity IDE 顶栏/输入框胶囊、Antigravity CLI(`agy`)单行 24-bit ANSI `statusLine` 与独立 Web 页面;支持自定义 1–5 个胶囊指标槽位、悬停速览卡片内容以及自动适宽(或 `440~1080 px` 固定宽度)。
- **不修改 `app.asar`**:桌面端与 IDE 的胶囊挂载及上下文请求改写均在运行时通过本地 CDP 内存注入完成(IDE 首次启用时仅向 `~/.antigravity-ide/argv.json` 写入 `"remote-debugging-port": "0"`,保留注释与原有配置),不触碰宿主安装包与 `app.asar`。
- **按模型设置上下文窗口**:支持按模型系列(跨思考档位)统一指定上下文上限或跟随宿主默认;桌面端与 IDE 在请求层生效,CLI 通过环境变量 `AGY_CLI_AUTO_COMPACT_OVERRIDE` 控制。
- **外观定制、离线读取与云端同步**:提供简体中文 / English / 自动跟随宿主语言、`sm / md / lg / xl` 字号、6 种主题强调色(含跟随宿主主题);离线支持直读 CLI SQLite + WAL、`annotations/*.pbtxt`、`transcript.jsonl` 与 `.deep_stats_cache.json`;内置 GitHub [`pricing-catalog.json`](pricing-catalog.json) 同步、压缩步骤模型推断、面板内更新(手动 / 自动 / 关闭)及缓存重建与配置重置。
- **实时监控**
- 核心指标:输出速度、首字延迟、平均速度、本次费用与会话累计费用(支持主代理与子代理独立或汇总查看)。
- 上下文窗口:支持按代理独立切换查看当前上下文窗口,并拆分为模型回复、工具结果、用户消息、子代理通知、压缩摘要、系统提示词、系统工具、MCP 工具、Skill 与用户规则十类来源(按占用量从大到小动态排列)。
- 额度概览:同步展示 `Gemini`、`Gemini 4 Argon`、`Gemini 4 Carbon`(Pro 账号独立池)与 `Claude & GPT` 模型池的 5 小时限额、每周限额及重置倒计时。
- **用量统计**
- 支持按今天、1天、7天、14天、30天、全部或自定义时间段过滤。
- 汇总所选时段的总 Token、折算费用与缓存命中率,并分列展示新输入、缓存读取(含缓存节省金额)与输出用量。
- 包含用量趋势曲线、模型排行、客户端来源以及月度统计柱状图。
- **调用明细**
- 按步查看:列出当前会话全部步骤的模型、输出速度、首字延迟、上下文/输出 Token、缓存命中率与单步费用。
- 按模型汇总:按当前所选会话(及所选主/子代理范围)统计各模型的调用次数、均速、总 Token 与费用。
- **偏好设置**
- 选择面板挂载方式与悬浮窗宽度:支持双栖挂载(顶部栏 + 侧边栏)、输入框挂载与仅侧边栏;悬浮面板默认按表格内容自动适配增宽(免水平滚动且自动受窗口边界约束),也可手动指定 `440~1080 px` 固定宽度。
- 顶部栏与 CLI 胶囊定制:独立开关实时运行会话入口与 Antigravity CLI 底部状态胶囊(自动写入 `~/.gemini/antigravity-cli/settings.json` 的 `statusLine`),并自由定义 1 至 5 个指标槽位的显示内容与排列顺序(默认为输出速度、首字延迟、上下文占用)。
- 调用明细显示与自定义 Token 组合:在「界面编排 -> 调用明细字段」可独立开关主/子代理标识、对话轮次导轨(默认关闭)与输出速度多色分级(默认关闭);默认保留 `上下文 / 思考 / 正文` 组合列,同时提供对齐计费维度的 `输入 / 输出 / 缓存` 可选组合列(悬停显示对应三项费用拆解),并支持输入 `context:new:cache`、`in:out:cache` 等自定义格式字符串自由拼装单列指标。
- 选择模型名称格式:提供精简代号(如 `argon-4-high`)、原始模型 ID 与去前缀原始 ID(自动隐藏 `gemini-` / `claude-` / `gpt-` 前缀以节省单行空间,如 `3.8-flash-n`、`sonnet-4-6`、`5.4-mini`)三档,且自动压缩尾标(`·压缩`)独立保护永不截断;Orchestrator 系列仍可独立设置精简或完整 ID。
- 按模型设置上下文:在「其他 → 模型上下文设置」为同一模型的各推理档统一设置上限,或切回「跟随宿主设置」。列表右侧显示已设置的上限和宿主最近报告的数值。App / IDE 窗口桥接在插件启动时重新读取宿主模型目录并应用已保存的设置,适用于之后发送的消息。CLI 使用 `AGY_CLI_AUTO_COMPACT_OVERRIDE`。
- 版本更新与价格表同步:支持从云端 [`pricing-catalog.json`](pricing-catalog.json) 动态同步最新模型价格表,并提供「仅提示新版本,手动更新」(默认)、「自动更新」与「关闭更新」三档更新方式。
---
## 模型识别与费用口径
## 截图
模型优先取自当前步骤的原始用量或对应生成记录。自动压缩可能使用独立模型;明确记录的模型不会被覆盖。压缩步骤缺少模型时,会从同一会话中有明确模型的步骤推断:优先查找此前、其次此后的提供方兼容步骤,找不到时再放宽提供方限制。推断结果用于模型展示和费用估算,并不代表服务端已确认压缩模型;没有可用记录时显示“模型未知·压缩”。
### IDE 与 CLI
模型或价格未能确认时,单步费用显示“待定”,Token 仍计入统计;汇总费用累加所有已确认单价的步骤。模型明确且价格表已收录的步骤继续按本地 API 单价折算;这不代表订阅额度的美元换算关系。
<table>
<tr>
<td align="center">
<img src="assets/ide-preview.png" alt="Antigravity IDE 顶栏胶囊与悬浮速览" width="100%" />
<br />
<b>Antigravity IDE</b>
<br />
<sub>顶栏悬浮胶囊与速览浮窗,显示当前步骤费用、上下文占用与配额状态</sub>
</td>
</tr>
<tr>
<td align="center">
<img src="assets/cli-preview.png" alt="Antigravity CLI 原生底部 statusLine 胶囊" width="100%" />
<br />
<b>Antigravity CLI (<code>agy</code>)</b>
<br />
<sub>终端底栏单行 24-bit ANSI 无背景色 <code>statusLine</code>,显示活跃会话数、输出速率、首字延迟与上下文占比</sub>
</td>
</tr>
</table>
升级时会重新读取旧缓存的原始记录。旧版默认填入的 Argon 标签无法与真实 Argon 区分;原始记录暂时无法读取时,该标签会暂记为未知,Token 和已有有效计时保留。压缩步骤可显示完整请求 TPS,但不进入会话均速。
### 面板标签页
<table>
<tr>
<td align="center" width="33.3%">
<img src="assets/context.png" alt="实时监控与上下文窗口" />
<br />
<b>实时监控</b>
<br />
<sub>输出速率、首字延迟、10 类上下文明细、配额池与运行中任务</sub>
</td>
<td align="center" width="33.3%">
<img src="assets/analytics.png" alt="历史用量与趋势统计" />
<br />
<b>用量统计</b>
<br />
<sub>Token 汇总、缓存命中率、趋势曲线与分模型用量排行</sub>
</td>
<td align="center" width="33.3%">
<img src="assets/subagents.png" alt="主代理与子代理调用明细" />
<br />
<b>调用明细</b>
<br />
<sub>按步列出代理归属、模型、速率、首字延迟、Token 构成与费用</sub>
</td>
</tr>
</table>
---
## 客户端支持
| 客户端 / 运行环境 | 状态胶囊 / 底栏 | 监控面板 | 离线 SQLite 与日志读取 | 按模型上下文限制 | 修改 `app.asar` |
| :--- | :---: | :---: | :---: | :---: | :---: |
| **Antigravity 2.0 桌面端** | 顶栏 / 输入框停靠 | 悬浮窗 + 右侧辅助栏 | 支持 | 请求级重写钩子 | 否 |
| **Antigravity IDE** | 顶栏 / 输入框停靠 | 点击胶囊展开面板 | 支持 | 请求级重写钩子 | 否 |
| **Antigravity CLI (`agy`)** | 终端底栏 `statusLine` | 独立 Web (`--port`) | 支持(`node:sqlite` + `.pbtxt`) | `AGY_CLI_AUTO_COMPACT_OVERRIDE` | 否 |
| **无头服务器 / SSH 远程** | 终端底栏 `statusLine` | SSH 隧道 / `--token` Web | 支持 | `AGY_CLI_AUTO_COMPACT_OVERRIDE` | 否 |
> [!NOTE]
> 在 **Antigravity IDE** 中首次启用插件时,后台会通过零工具开销的 MCP 保活入口(不消耗上下文 Token)向 `~/.antigravity-ide/argv.json` 写入 `"remote-debugging-port": "0"`(保留原有注释与配置项)。首次启用后需重启一次 IDE,顶栏胶囊才能正常挂载。
---
## 安装
插件目录名需保持为 `usage-monitor`,无需运行 `npm install`。
插件目录名需保持为 `usage-monitor`,**无需运行 `npm install`**。
### 方式一:通过 Git 克隆
### 方式一:Git 克隆
**Windows**
```powershell
# Windows PowerShell
git clone https://github.com/yuhuan-dev/antigravity-usage-monitor.git "$env:USERPROFILE\.gemini\config\plugins\usage-monitor"
```
**macOS / Linux**
```bash
# macOS / Linux
git clone https://github.com/yuhuan-dev/antigravity-usage-monitor.git ~/.gemini/config/plugins/usage-monitor
```
也可以直接在 Antigravity 对话框中让 AI 执行安装:
也可以直接在 Antigravity 对话中执行:
```text
把 https://github.com/yuhuan-dev/antigravity-usage-monitor 克隆到 ~/.gemini/config/plugins/usage-monitor 并启用插件
```
### 方式二:下载压缩包解压
### 方式二:下载 Release 压缩包
下载 [usage-monitor.zip](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip),解压到 `~/.gemini/config/plugins/` 目录下。
下载 [`usage-monitor.zip`](https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip),解压到 `~/.gemini/config/plugins/` 下并保持文件夹名为 `usage-monitor`。
<details>
<summary>Windows PowerShell 下载与解压命令</summary>
Windows PowerShell 命令:
```powershell
$pluginsDir = "$env:USERPROFILE\.gemini\config\plugins"
New-Item -ItemType Directory -Path $pluginsDir -Force | Out-Null
@@ -97,57 +149,104 @@ Invoke-WebRequest -Uri "https://github.com/yuhuan-dev/antigravity-usage-monitor/
Expand-Archive -Path "$env:TEMP\usage-monitor.zip" -DestinationPath $pluginsDir -Force
```
## 启用与打开面板
</details>
---
## 使用方式
1. 打开左侧边栏 **Customizations → Installed**,找到 `usage-monitor` 并开启。
2. **Antigravity 2.0 桌面端**:
- 主窗口右上角挂载悬浮胶囊(**悬停**查看速览,**左键**打开四标签面板,**右键**强制刷新),同时可在右侧辅助栏打开「用量监控」。
3. **Antigravity IDE**:
- 首次启用后**重启一次 Antigravity IDE**,保持挂载方式为「双栖挂载」,点击顶栏胶囊即可打开面板。
4. **Antigravity CLI (`agy`) 底部胶囊**:
- 检测到 `~/.gemini/antigravity-cli` 时自动写入原生 `statusLine` 配置(保留已有自定义 `statusLine.command`),在终端底栏单行显示当前活跃状态、输出速率、首字延迟与上下文占比(如 `● 1 运行中 38.1 t/s | 0.85s | ◎ 17%`)。
- 可在 `agy` 中通过 `/statusline` 或在面板 **偏好设置 → 界面编排 → 挂载胶囊** 开关及调整显示顺序。
5. **独立 Web 服务(纯终端 / 远程服务器)**:
1. 打开左侧边栏的 **Customizations**,进入 **Installed** 标签页,找到 `usage-monitor` 并开启。
2. **顶部栏胶囊悬浮面板(默认开启,兼容 Antigravity 2.0 与 Antigravity IDE)**:
- **Antigravity 2.0 桌面端**:开启插件后即自动在主对话窗口右上角顶部栏挂载实时状态与指标胶囊(悬停查看速览,左键展开完整四标签面板,右键强制刷新),全程不修改宿主 `app.asar`。
- **Antigravity IDE**:首次启用插件时,后台 Sidecar 会自动在 `~/.antigravity-ide/argv.json` 中补齐 `"remote-debugging-port": "0"`(保留原有注释与配置)。**完整重启一次 Antigravity IDE** 后,胶囊会自动停靠在 IDE 窗口最上方标题栏右侧。由于 Antigravity IDE 宿主暂未开放右侧 UI Sidecar 辅助栏,在 IDE 中请保持「双栖挂载」并直接点击顶部栏胶囊打开四标签面板。
3. **右侧辅助栏面板(Antigravity 2.0)**:在 Antigravity 2.0 对话窗口点击右上角菜单打开右侧辅助栏中的 **用量监控**,或在 **偏好设置 -> 面板挂载方式** 中按需切换「顶部栏 + 侧边栏」与「仅侧边栏」。
4. **Antigravity CLI 底部状态胶囊与独立 Web 模式**:
- **CLI 底部状态胶囊(`statusLine`,默认开启)**:本机存在 `~/.gemini/antigravity-cli` 时,插件会自动配置原生 `statusLine`(若你已配置自定义脚本则原样保留,绝不覆盖),在 `agy` 终端底栏单行内联展示无背景色的多会话状态与监控指标(左侧保留 `? for shortcuts`,中间显示如 `● 1 运行中 38.1 t/s | 0.85s | ◎ 17%`,右侧保留模式与模型档位),也可在 CLI 内输入 `/statusline` 或在面板 **偏好设置 -> 挂载胶囊** 中随时开关。
- **本地离线日志与自动重连**:在纯终端或远程 Linux 服务器上,插件会自动扫描 `~/.gemini/antigravity-cli`(含 `daemon/hub_*.json`、SQLite `.db` 对话轨迹与 `transcript.jsonl`);即使 `agy` 暂未运行,也会基于本地日志离线展示历史会话与 Token 消耗,并在 `agy` 启动后自动重连升级为完整遥测。
- **手动启动(推荐配合 SSH 端口转发)**:
```bash
# 在远程服务器上启动(默认仅监听 127.0.0.1:8787)
# 1. 在远程服务器上启动(默认监听 127.0.0.1:8787)
node ~/.gemini/config/plugins/usage-monitor/sidecars/panel/standalone.mjs --port 8787
# 在本地电脑转发端口后,浏览器打开 http://localhost:8787
# 2. 本地端口转发后,浏览器访问 http://localhost:8787
ssh -L 8787:127.0.0.1:8787 user@your-server
```
- **随 `agy` 后台自动托管**:设置环境变量 `USAGE_MONITOR_STANDALONE_PORT=8787`,或在 `~/.gemini/antigravity-cli/sidecar_data/usage-monitor/panel/data/settings.json` 中写入 `"standalonePort": 8787`,启用插件后即随 `agy` 自动监听该端口。
- **非回环地址受保护访问**:若需显式绑定 `0.0.0.0` 或局域网地址,必须同时指定 `--token <密钥>`(或 `USAGE_MONITOR_STANDALONE_TOKEN`),未配置令牌时服务端会拒绝非回环启动。
## 更新
<details>
<summary>独立 Web 命令行参数、随 agy 自动启动与非回环令牌校验</summary>
插件内置了云端版本检测与一键更新支持:
- 当检测到新版本时,顶部栏胶囊旁与面板顶部会显示柔和的新版本提示徽章,点击即可自动拉取更新并重启面板;也可在 **偏好设置 -> 版本更新** 中切换更新方式(仅提示新版本手动更新 / 自动更新 / 关闭更新)或手动同步价格表。
- **随 `agy` 自动启动**:设置环境变量 `USAGE_MONITOR_STANDALONE_PORT=8787`,或在 `~/.gemini/antigravity-cli/sidecar_data/usage-monitor/panel/data/settings.json` 中添加 `"standalonePort": 8787`,插件随 MCP 进程启动时会自动拉起 Web 服务。
- **非回环访问校验**:绑定 `0.0.0.0` 或局域网 IP 时必须提供 `--token <密钥>`(或环境变量 `USAGE_MONITOR_STANDALONE_TOKEN`),未设置令牌会拒绝启动。
- **常用参数**:支持 `--data-dir`、`--app-data-dir`、`--gemini-dir`、`--ls-addr` 与 `--csrf-token`。
- **离线数据读取**:在 `agy` 未运行的状态下,后台直接读取 `~/.gemini/antigravity-cli` 下的 `conversation_summaries.db`、`conversations/*.db`、`annotations/*.pbtxt` 与 `transcript.jsonl`,待 `agy` 启动后自动切换为实时 RPC 数据。
如需通过命令行手动更新:
- 通过 Git 安装时,拉取最新代码后在 **Customizations -> Installed** 中重新开关一次插件即可:
</details>
```powershell
# Windows PowerShell
git -C "$env:USERPROFILE\.gemini\config\plugins\usage-monitor" pull --ff-only
```
---
## 配置说明与计算口径
<details>
<summary>界面与字段配置(挂载方式、胶囊槽位、Token 组合格式、模型命名与上下文限制)</summary>
- **挂载模式与浮窗宽度**:支持「双栖挂载(顶部栏 + 侧边栏)」、「输入框挂载」与「仅侧边栏」;悬浮窗默认使用「自动适配」(宽表格下在窗口范围内自动加宽),也可设置为 `440~1080 px` 固定宽度。
- **胶囊槽位**:支持在 1 至 5 个指标间增删与排序(默认显示输出速度、首字延迟与上下文占用),并可单独开关运行中会话指示器。
- **调用明细与 Token 组合**:在「界面编排 → 调用明细字段」可分别开关主/子代理标识、对话轮次导轨(默认关闭)与输出速度多色分级(默认关闭);Token 列默认显示 `上下文 / 思考 / 正文`,可切换至 `输入 / 输出 / 缓存` 预设(悬停显示美元分项),或使用 `context:new:cache`、`in:out:cache` 等自定义格式字符串。
- **模型命名格式**:支持精简代号(如 `argon-4-high`)、原始模型 ID 与去前缀原始 ID(去掉 `gemini-` / `claude-` / `gpt-` 前缀并保留 `·压缩` 标记)三档;Orchestrator 系列支持单独设置。
- **按模型设置上下文窗口**:在「其他 → 模型上下文设置」中为同一模型的各推理档位设置统一上限或「跟随宿主设置」。App / IDE 会在启动后作用于后续请求;CLI 通过 `AGY_CLI_AUTO_COMPACT_OVERRIDE` 控制。
</details>
<details>
<summary>模型识别、压缩步骤推断与费用折算说明</summary>
- **模型识别规则**:直接读取当前步骤的原始用量字段与对应生成记录,已记录的模型不会被后续推断覆盖。当上下文压缩步骤缺少模型字段时,按同一会话内「先向前、后向后,优先同提供方、再放宽匹配」的顺序推断用于展示与费用估算;无可推断来源时标注为「模型未知·压缩」。
- **费用计算口径**:模型或价格项未匹配时,单步费用记为「待定」,Token 数量仍正常统计;汇总金额仅累加已确认单价的步骤。美元金额基于 [`pricing-catalog.json`](pricing-catalog.json) 中的公开 API 单价估算,仅供本地对比参考,不代表订阅配额扣减比例。
- **升级校验与均速口径**:插件升级后会按原始轨迹重新校验旧缓存,同时保留既有 Token 与有效计时;压缩步骤在调用明细中展示完整请求 TPS,但不会计入会话平均生成速度与平均首字延迟。
</details>
<details>
<summary>更新方式与本地数据目录</summary>
- **面板内检查更新**:检测到 GitHub 新版本时,胶囊旁与面板顶栏会显示更新标记,点击后拉取更新并自动重载;可在 **偏好设置 → 其他** 选择「手动提示 / 自动更新 / 关闭」,或手动同步价格表。
- **Git 手动更新**:
- Windows:`git -C "$env:USERPROFILE\.gemini\config\plugins\usage-monitor" pull --ff-only`
- macOS / Linux:`git -C ~/.gemini/config/plugins/usage-monitor pull --ff-only`
- 更新后在 **Customizations → Installed** 重新开关一次插件生效。
- **数据目录**:缓存与设置保存在 `~/.gemini/antigravity/sidecar_data/usage-monitor/`(独立模式未指定 `ANTIGRAVITY_EXECUTABLE_DATA_DIR` 时存放在 `sidecars/panel/.data/`),升级插件不会清除历史记录。
</details>
---
## 本地开发
前后端代码采用纯 Node.js ESM 与原生 Web Components 编写,**无外部 npm 依赖**(建议使用 Node.js 22.5+ 以使用内置 `node:sqlite`)。
```bash
# macOS / Linux
git -C ~/.gemini/config/plugins/usage-monitor pull --ff-only
```
cd sidecars/panel
通过压缩包安装时,下载新版 `usage-monitor.zip` 覆盖解压到原目录后重新开关插件即可。在 Antigravity 宿主内运行时,本地缓存与设置存放在 `~/.gemini/antigravity/sidecar_data/usage-monitor/`(独立启动且未传入 `ANTIGRAVITY_EXECUTABLE_DATA_DIR` 时回退至 `sidecars/panel/.data/`),更新插件不会清除历史数据。
## 本地构建
如果修改了 `sidecars/panel/src/` 下的前端源码,可在 `sidecars/panel` 目录下运行以下命令重新生成 `app.js` 与 `styles.css`:
```bash
# 修改 src/ 下源码后重新构建 app.js 与 styles.css
npm run build
```
运行模型识别、缓存迁移与计时回归测试(无需额外安装依赖):
```bash
# 运行单元测试与回归测试
npm test
```
## 参与贡献与开源协议
欢迎提交 Issue 或 Pull Request。若修改了 `sidecars/panel/src/` 下的前端源码,请先执行 `npm run build` 重新生成产物,并确保 `npm test` 全部通过。
本项目基于 [GNU General Public License v3.0](LICENSE) 开源。
## Star 趋势
<a href="https://www.star-history.com/#yuhuan-dev/antigravity-usage-monitor&Date">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date&theme=dark" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=yuhuan-dev/antigravity-usage-monitor&type=Date" />
</picture>
</a>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 291 KiB