context-tally 0.0.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +206 -0
- package/CHANGELOG.ru.md +216 -0
- package/LICENSE +21 -0
- package/README.md +345 -0
- package/README.ru.md +351 -0
- package/assets/logo.svg +29 -0
- package/bin/context-tally.mjs +7 -0
- package/dist/app.html +168 -0
- package/dist/server.mjs +42900 -0
- package/mcp_config.json +8 -0
- package/package.json +59 -9
- package/plugin.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="assets/banner-en.svg" width="100%" alt="Context Tally Banner" />
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
[](https://github.com/Bileneret/context-tally/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/Bileneret/context-tally/releases/latest)
|
|
9
|
+
[](https://www.npmjs.com/package/context-tally)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://vshymanskyy.github.io/StandWithUkraine/)
|
|
12
|
+
|
|
13
|
+
**English** · [Русский](README.ru.md)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
**Official MCP App (`ui://`) context window & prompt-cache monitor — Zero-RPC, Zero-OAuth, Zero-CDP, Zero-Python.**
|
|
18
|
+
|
|
19
|
+
Context Tally is a local, read-only MCP App for the Antigravity App. It shows how full
|
|
20
|
+
your context window really is, where the prompt tokens go, and how well the prompt
|
|
21
|
+
cache is working — without a sidecar server, browser automation, OAuth proxying, or
|
|
22
|
+
any Python dependency.
|
|
23
|
+
|
|
24
|
+
It ships as one MCP server (stdio) plus one HTML bundle:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
ui://context-tally/app.html → dist/app.html (single file, inlined CSS/JS)
|
|
28
|
+
tools: show_context_usage, refresh_context_usage, save_view_settings
|
|
29
|
+
get_context_diagnostics (app-only: category | cache | what_if | env)
|
|
30
|
+
build_handoff_summary (app-only, on-demand, 0 prompt tokens)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
All five tools — `show_context_usage`, `refresh_context_usage`, `save_view_settings`,
|
|
34
|
+
`get_context_diagnostics` and `build_handoff_summary` — are **app-only**
|
|
35
|
+
(`visibility: ["app"]`): the model never sees them, so the monitor costs **0 prompt
|
|
36
|
+
tokens**. `build_handoff_summary` is invoked strictly on demand by an explicit user
|
|
37
|
+
click and never in the background. Prompt tokens are only added by the opt-in `inline`
|
|
38
|
+
card (`show_context_inline`, off by default).
|
|
39
|
+
|
|
40
|
+
## Screenshots
|
|
41
|
+
|
|
42
|
+
Synthetic captures with sample English data (no real conversation text). The auxiliary
|
|
43
|
+
pane in Light (10×10 grid) and Dark (stacked bar), followed by the full-width global
|
|
44
|
+
dashboard.
|
|
45
|
+
|
|
46
|
+
| Light — 10×10 grid | Dark — stacked bar |
|
|
47
|
+
| :---: | :---: |
|
|
48
|
+
|  |  |
|
|
49
|
+
|
|
50
|
+
Global dashboard (Dark, two-column layout):
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
### Dual Cap readout
|
|
59
|
+
Antigravity enforces two different limits, and Context Tally shows both:
|
|
60
|
+
|
|
61
|
+
- **Compaction budget** — the effective `request_budget_tokens` / checkpointer limit at
|
|
62
|
+
which history is compacted (`CHECKPOINT`).
|
|
63
|
+
- **Native window** — the model's full context window (e.g. `1M`), with a `200K`
|
|
64
|
+
long-context tier mark.
|
|
65
|
+
|
|
66
|
+
The header shows usage and percentage (e.g. `284.5K / 512K (55.6%)`) alongside a
|
|
67
|
+
`Native window` badge and lets you switch between the two scales; a tick marks where
|
|
68
|
+
compaction begins.
|
|
69
|
+
|
|
70
|
+
### Hybrid data engine (exact DB → transcript fallback)
|
|
71
|
+
- **`exact_db`** — reads the locally stored `conversations/<id>.db` **read-only** through
|
|
72
|
+
the built-in `node:sqlite` module (no npm runtime dependencies, no Python). The native
|
|
73
|
+
`TopLevelTokenGroup` breakdown, `request_budget_tokens`, checkpointer limit, usage
|
|
74
|
+
counters and the model name come straight from the database.
|
|
75
|
+
- **Transcript fallback** — if `node:sqlite` is unavailable, the file is missing, or the
|
|
76
|
+
schema changes, Context Tally falls back to `transcript.jsonl`, supporting all three
|
|
77
|
+
known generations (Gen 1 without tokens, Gen 2 without a model field, Gen 3 with
|
|
78
|
+
tokens + model).
|
|
79
|
+
- Handles `CHECKPOINT` with and without embedded tokens, compaction savings
|
|
80
|
+
(`before → after`), `post_compaction` state (updates on the next turn), empty chats
|
|
81
|
+
(`0%`), and `partial` data for logs over 4 MiB without a checkpoint.
|
|
82
|
+
|
|
83
|
+
### Two honest cache metrics
|
|
84
|
+
- **Last turn cache hit** — the hit rate of the most recent request.
|
|
85
|
+
- **Active window average** — the cache share across the active window after the last
|
|
86
|
+
`CHECKPOINT`.
|
|
87
|
+
|
|
88
|
+
### Five categories, two visualisations, Top-5 heavy steps
|
|
89
|
+
- Categories: **messages, MCP tools, skills, meta context, system base** — always
|
|
90
|
+
summing to 100%, with an **Exact (DB)** vs **Estimated** badge.
|
|
91
|
+
- **Segmented bar ↔ 10×10 dot grid** toggle; both describe the same numbers.
|
|
92
|
+
- **Top-5 heaviest steps** with redacted metadata only (step index, kind, redacted
|
|
93
|
+
label, token count).
|
|
94
|
+
|
|
95
|
+
### Category drill-down
|
|
96
|
+
- Click a category for a lazy inspector via app-only `get_context_diagnostics`
|
|
97
|
+
(**0 prompt tokens**), with **Exact** / **Est.** badges and a mismatch note.
|
|
98
|
+
- Workspace rules/instructions are detected; **Open file** uses `toggle-aux-pane` with a
|
|
99
|
+
clipboard path fallback.
|
|
100
|
+
|
|
101
|
+
### Delta, growth and burn rate
|
|
102
|
+
- **Step delta badge** (`+X` / `-X`, redacted driver tooltip) and a pure-SVG **growth
|
|
103
|
+
sparkline** with compaction/`200K` lines and spike markers.
|
|
104
|
+
- Rolling-median **burn rate**: tokens per step, tokens per turn, estimated steps left.
|
|
105
|
+
|
|
106
|
+
### Cache diagnostics and session totals
|
|
107
|
+
- Click the cache card for sharp drops (**≥ 15 pp**, or **< 50%** after a `CHECKPOINT`),
|
|
108
|
+
explained by **exact** causes (checkpoint compaction, model switch, ≥ 5-minute TTL pause)
|
|
109
|
+
or **heuristic** ones (config change, system message, prefix shift).
|
|
110
|
+
- Whole-session tokens and cache savings survive `CHECKPOINT` in the cache card and the
|
|
111
|
+
copied `/context` report.
|
|
112
|
+
|
|
113
|
+
### Fast handoff ("Fake Compact")
|
|
114
|
+
- **Standard** or **Structural (no quotes)** extraction, built locally by
|
|
115
|
+
`build_handoff_summary` with **0 LLM tokens**; `SECRET_PATTERNS` redaction shows a
|
|
116
|
+
redacted-count badge.
|
|
117
|
+
- **Copy Handoff** for any chat; **Start new chat** (aux_pane only) sends it via
|
|
118
|
+
`sendMessage` with `target: "new"` and falls back to the clipboard.
|
|
119
|
+
- **Ask chat for AI summary** with 70-85% fill guidance, while the request still fits
|
|
120
|
+
before compaction.
|
|
121
|
+
|
|
122
|
+
### What-If optimizer
|
|
123
|
+
- Read-only simulation via `get_context_diagnostics` (`kind: "what_if"`): disable whole
|
|
124
|
+
plugins (skills + MCP servers, without double-counting), individual MCP servers, skills
|
|
125
|
+
and rule/meta files, or switch Lazy ↔ Eager schemas.
|
|
126
|
+
- Instant projected savings and prompt share, plus copy-name and open-file (through
|
|
127
|
+
`toggle-aux-pane`) shortcuts. Nothing is applied; only local estimates change.
|
|
128
|
+
|
|
129
|
+
### Threshold alerts and broken-cache detector
|
|
130
|
+
- Configurable in Settings and persisted in `settings.json`: compaction warning %, the
|
|
131
|
+
200K long-context tier, heavy step delta, and a broken cache below threshold for 2+
|
|
132
|
+
consecutive steps.
|
|
133
|
+
- `AlertStrip` quick actions (**Build handoff**, **Cache details**, **Inspect messages**)
|
|
134
|
+
plus a compact alert badge in the header.
|
|
135
|
+
|
|
136
|
+
### Copy diagnostic info
|
|
137
|
+
- A one-click footer button (`get_context_diagnostics`, `kind: "env"`) copies a strictly
|
|
138
|
+
anonymized dump: versions, OS/arch, breakdown source, SQLite table names and counts.
|
|
139
|
+
- Zero paths, usernames, titles, IDs or names — ready to paste into an issue report.
|
|
140
|
+
|
|
141
|
+
The compact `inline` card hides these diagnostic blocks and keeps background polling
|
|
142
|
+
disabled.
|
|
143
|
+
|
|
144
|
+
### Three surfaces from one bundle
|
|
145
|
+
| Surface | Default | Prompt tokens | Notes |
|
|
146
|
+
| :--- | :--- | :--- | :--- |
|
|
147
|
+
| `aux_pane` (side pane, opened from `+`) | on | **0** | Supports **Attach context summary** |
|
|
148
|
+
| `global` (Plugins tab) | on | **0** | Full-width dashboard; no chat actions |
|
|
149
|
+
| `inline` (opt-in card) | off | adds one tool description | Enable in settings, then restart the MCP server and start a new chat. The compact snapshot card is **not** attached to every reply: it renders **on request** in the chat (e.g. *"show context"* → `show_context_inline`) |
|
|
150
|
+
|
|
151
|
+
In the `inline` surface every interactive panel — `Handoff`, `What-If`, the alert strip
|
|
152
|
+
and the footer diagnostic button — stays hidden, and polling stays disabled.
|
|
153
|
+
|
|
154
|
+
### Native MCP App capabilities
|
|
155
|
+
- **Copy `/context`** — a compact, redacted report for the clipboard.
|
|
156
|
+
- **Attach context summary** — uses `app.updateModelContext()` (strictly gated behind
|
|
157
|
+
`getHostCapabilities()`, therefore only in `aux_pane`) to attach the remaining tokens
|
|
158
|
+
before compaction, the breakdown, cache metrics and Top-5 heavy steps to the next
|
|
159
|
+
message. Ideal for handoff workflows before a compaction.
|
|
160
|
+
- **Strict `last_user_view_time` auto-follow** — the monitor follows the chat you
|
|
161
|
+
actually opened, not a background generation; subagents are isolated.
|
|
162
|
+
- **Pin a chat** — lock the monitor to one conversation; unpinning resumes auto-follow
|
|
163
|
+
immediately.
|
|
164
|
+
- **Idle-backoff polling** — 3 s while data changes, backing off to 15 s on `unchanged`
|
|
165
|
+
replies or transient poll errors, paused while the view is hidden, at most one request
|
|
166
|
+
in flight.
|
|
167
|
+
|
|
168
|
+
### Localisation and accessibility
|
|
169
|
+
- **EN / RU** UI, switchable in the settings drawer and persisted server-side.
|
|
170
|
+
- **Light / Dark** host theming via `applyDocumentTheme` and `applyHostStyleVariables`.
|
|
171
|
+
- WCAG AA contrast targets, keyboard navigation, `role="progressbar"` with an
|
|
172
|
+
accessible name, `aria-pressed` toggles and a `lang` attribute kept in sync.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Architecture and security comparison
|
|
177
|
+
|
|
178
|
+
The table describes the common architecture of publicly documented monitor tools.
|
|
179
|
+
Individual projects differ; the wording is factual and not a recommendation against any
|
|
180
|
+
particular tool.
|
|
181
|
+
|
|
182
|
+
| | **Context Tally** (MCP App `ui://`) | **Sidecar + LS RPC monitors** | **CDP / OAuth / proxy monitors** |
|
|
183
|
+
| :--- | :--- | :--- | :--- |
|
|
184
|
+
| Integration standard | Documented MCP App resource + app-only tools | Internal, undocumented Language Server RPC | Browser DevTools Protocol / injected scripts |
|
|
185
|
+
| Local HTTP port | **None** (MCP over stdio) | Usually a localhost HTTP endpoint | Usually a localhost proxy |
|
|
186
|
+
| Internal LS RPC | **No** | Yes | Sometimes |
|
|
187
|
+
| CDP / DOM injection | **No** | No | Yes |
|
|
188
|
+
| OAuth / proxy | **No** | No | Typically yes |
|
|
189
|
+
| Python required | **No** | Often | Sometimes |
|
|
190
|
+
| Exact DB breakdown + transcript fallback | **Yes** (`node:sqlite` read-only + Gen 1/2/3 JSONL) | Varies by implementation | No (UI scraping) |
|
|
191
|
+
| Prompt token overhead (default) | **0** | Varies | Varies |
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Requirements
|
|
196
|
+
|
|
197
|
+
- Antigravity App with MCP Apps support (`v2.34.0+`).
|
|
198
|
+
- Node.js `^20.19.0 || >=22.12.0` for building. At runtime, any Node the app can launch
|
|
199
|
+
works: `node:sqlite` is used when available (Node ≥ 22.5) and the transcript fallback
|
|
200
|
+
otherwise.
|
|
201
|
+
- No Python. No browser automation. No network access.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## npm package
|
|
206
|
+
|
|
207
|
+
The MCP server is also published as [`context-tally`](https://www.npmjs.com/package/context-tally).
|
|
208
|
+
The package ships the same `dist/server.mjs` and `ui://context-tally/app.html` bundle:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npx context-tally --data-dir=/path/to/data
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
It is intended for MCP Apps-capable hosts and local debugging. Antigravity users should
|
|
215
|
+
still install the plugin archive below: the app owns `${PLUGIN_DATA}` and the plugin
|
|
216
|
+
surfaces, which a bare npm package cannot provide.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Installation (no `curl | sh`, no `irm | iex`)
|
|
221
|
+
|
|
222
|
+
### 1. Download
|
|
223
|
+
|
|
224
|
+
Grab both files from the [Releases](https://github.com/Bileneret/context-tally/releases/latest) page of this repository:
|
|
225
|
+
|
|
226
|
+
- `context-tally-vX.Y.Z.zip`
|
|
227
|
+
- `SHA256SUMS.txt`
|
|
228
|
+
|
|
229
|
+
### 2. Verify the checksum
|
|
230
|
+
|
|
231
|
+
macOS / Linux:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
sha256sum -c SHA256SUMS.txt
|
|
235
|
+
# macOS builds without GNU coreutils:
|
|
236
|
+
shasum -a 256 -c SHA256SUMS.txt
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Windows PowerShell:
|
|
240
|
+
|
|
241
|
+
```powershell
|
|
242
|
+
$expected = (Get-Content .\SHA256SUMS.txt).Split(" ")[0]
|
|
243
|
+
$actual = (Get-FileHash .\context-tally-vX.Y.Z.zip -Algorithm SHA256).Hash.ToLower()
|
|
244
|
+
if ($actual -eq $expected) { "checksum OK" } else { "CHECKSUM MISMATCH" }
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 3. Pre-audit without executing anything (optional)
|
|
248
|
+
|
|
249
|
+
`agy plugin validate --strict` reads the manifest and bundle without installing or
|
|
250
|
+
running code:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
agy plugin validate --strict ./context-tally-vX.Y.Z.zip
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
On Windows the CLI usually lives at `%USERPROFILE%\.gemini\bin\agy.exe`.
|
|
257
|
+
|
|
258
|
+
### 4. Install
|
|
259
|
+
|
|
260
|
+
Extract the archive into the plugins directory:
|
|
261
|
+
|
|
262
|
+
| Platform | Path |
|
|
263
|
+
| :--- | :--- |
|
|
264
|
+
| macOS / Linux | `~/.gemini/config/plugins/context-tally/` |
|
|
265
|
+
| Windows | `%USERPROFILE%\.gemini\config\plugins\context-tally\` |
|
|
266
|
+
|
|
267
|
+
Or let the CLI install the extracted folder:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
agy plugin install ./context-tally
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 5. Enable and open
|
|
274
|
+
|
|
275
|
+
1. Open **Customizations → Installed**, find **Context Tally** and enable it.
|
|
276
|
+
2. Open the side pane from `+` (the `aux_pane` surface) or the **Plugins** tab
|
|
277
|
+
(`global`). Both work with an empty `{}` tool input.
|
|
278
|
+
3. To use the `inline` surface, enable it in the settings drawer inside the widget,
|
|
279
|
+
then restart the MCP server (**Customizations → Installed → Context Tally → MCP →
|
|
280
|
+
Restart**) and start a new chat. The card is not attached to every reply
|
|
281
|
+
automatically: ask the agent to show the context (for example *"show context"*),
|
|
282
|
+
which calls `show_context_inline` and renders a compact snapshot card at that
|
|
283
|
+
point in the chat.
|
|
284
|
+
|
|
285
|
+
### Build from source
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npm ci
|
|
289
|
+
npm run build # dist/server.mjs + dist/app.html
|
|
290
|
+
npm run package # release/context-tally-vX.Y.Z.zip + release/SHA256SUMS.txt
|
|
291
|
+
npm test
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
`npm run package` writes a deterministic archive and its `sha256sum`-compatible
|
|
295
|
+
`SHA256SUMS.txt` (two spaces between hash and name, LF line ending).
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## Privacy and disclaimer
|
|
300
|
+
|
|
301
|
+
Context Tally reads only what is already stored on your machine, in read-only mode:
|
|
302
|
+
|
|
303
|
+
- `~/.gemini/antigravity/brain/**` — `transcript.jsonl` and `transcript_full.jsonl`;
|
|
304
|
+
- `~/.gemini/antigravity/annotations/*.pbtxt` — conversation titles and
|
|
305
|
+
`last_user_view_time`;
|
|
306
|
+
- `~/.gemini/antigravity/conversations/<id>.db` — opened with `readOnly: true`;
|
|
307
|
+
- `~/.gemini/config/**` — `GEMINI.md`, config, skills and MCP server settings (to
|
|
308
|
+
estimate tool/skill weight).
|
|
309
|
+
|
|
310
|
+
It makes **zero network calls**, has **no telemetry**, never touches OAuth tokens or
|
|
311
|
+
cookies, and never switches accounts. The only local writes are `settings.json` (and a
|
|
312
|
+
best-effort `settings.json.bak` when salvaging a corrupt settings file) inside
|
|
313
|
+
`${PLUGIN_DATA}`. Media URI reads are strictly scoped to the conversation/`brain` root
|
|
314
|
+
(blocking UNC paths and symlink escapes). Secret-like patterns (`SECRET_PATTERNS`) are
|
|
315
|
+
redacted before any text leaves the server process. The widget iframe receives counts,
|
|
316
|
+
shares and redacted labels only — never raw message text. The clipboard report and the
|
|
317
|
+
attached model-context summary are built from the same redacted metadata.
|
|
318
|
+
|
|
319
|
+
This is an independent MIT project. It is **not affiliated with, endorsed by, or
|
|
320
|
+
supported by Google**. Antigravity is a product of Google LLC; the name is used only to
|
|
321
|
+
describe compatibility. The plugin name and assets intentionally avoid Google or
|
|
322
|
+
Antigravity branding.
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Data pipeline (short version)
|
|
327
|
+
|
|
328
|
+
1. `discovery.ts` parses `annotations/*.pbtxt` for titles and `last_user_view_time`,
|
|
329
|
+
filters subagents, and sorts chats with a strict `last_user_view_time` priority.
|
|
330
|
+
2. `transcript.ts` incrementally parses `transcript.jsonl` (Gen 1/2/3), honours
|
|
331
|
+
`CHECKPOINT` boundaries and compaction savings, and resolves `media` attachments.
|
|
332
|
+
3. `db_reader.ts` optionally enriches the snapshot from SQLite (model, budget, native
|
|
333
|
+
token groups); `config_reader.ts` estimates skills and MCP tool weight (Lazy by
|
|
334
|
+
default, Eager only for configured servers).
|
|
335
|
+
4. `breakdown.ts` merges both sources into a `schemaVersion: 1` payload: five
|
|
336
|
+
categories summing to 100%, Dual Cap limits, cache metrics, compaction stats, Top-5
|
|
337
|
+
heavy steps and a revision hash for `unchanged` polling. `handoff.ts` builds the
|
|
338
|
+
on-demand redacted Markdown handoff (≤ 12 000 chars). `diagnostics.ts` also serves the
|
|
339
|
+
`what_if` catalog and the anonymized `env` dump.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## License
|
|
344
|
+
|
|
345
|
+
MIT — see [LICENSE](LICENSE).
|