measuredUsage summed field 3 (output) and field 9 (thinking) of SQLite gen_metadata, but field 3 already carries the thinking, so the SQLite path billed thinking twice. Each step now counts max(output, thinking), as promptUsage does since #1023.
Run at b3873f84 on mica (Bun, temp HOME): bun test packages/agy-cli 14 pass 0 fail; bun scripts/check.mjs exit 0.
Broken by hand: putting back item.output + item.thinking turns 4 tests red, including the PR's new one.
Not tried: a real Antigravity CLI session.
ACP's outputTokens already includes the thinking tokens, so `completion_tokens`
is outputTokens again, not output + thinking. The totalTokens shape check
compares against input + output (and input + cache + output), without
thinking.
Evidence (klarkxy, agy 1.5.4): for single-turn Flash and Carbon prompts,
ACP's totalTokens equals input + output exactly (2322 + 4728 = 7050,
2316 + 9390 = 11706). Output minus thinking is 67 and 68 tokens, which
matches the visible replies. The store's gen_metadata output (field 3)
equals ACP's outputTokens, with thinking (field 9) below it. 0.1.19 sent
9389 and 18712, double-counting.
Run at a0898318 merged onto origin/main (1199adda), on mica with a temp
HOME: bun test packages/agy-cli gave 14 pass, 0 fail, and scripts/check.mjs
exited 0. CI's test and on-npm jobs pass. Earlier, at d18f2346, putting
`output + thinking` back by hand turned five tests red.
Not tried: a live agy session here.
Co-authored-by: klarkxy <klarkxy@users.noreply.github.com>
agy 1.5.1+ reports ACP `inputTokens` as uncached prompt tokens only; `promptUsage()` tells the exclusive shape from the inclusive one by `totalTokens`, so cache reads are no longer clipped and the learned cache ratio no longer pins to 1.0. Each HTTP step of a multi-step tool loop is settled from agy's own per-call rows in `conversations/<id>.db` (`gen_metadata` on 1.5.1+, `steps` type 15 on 1.4.x-1.5.0) when they reconcile with ACP's total; same-generation tool continuations settle at 0, a cancelled or fallen-back turn stops trusting the store, and a clipped cold-start replay bounds its fallback estimate.
The reader (`step-usage.mjs`) never opens a store read-write. Under Bun it opens with `SQLITE_OPEN_READONLY | SQLITE_OPEN_URI` (Bun's SQLite on Linux and Windows parses `file:` URIs only with that flag), finalizes statements and waits on no busy timeout. A checkpointed WAL store with no `-wal`/`-shm` is read through `?immutable=1` and gains no side files; if `-wal` appears during that read it is read again live. Store paths are resolved to absolute first, and Windows `\\?\` and UNC paths get their own `file:` form. On an uncheckpointed store the only file a reader touches is SQLite's `-shm` WAL index.
Reviewed head 9054f47295d51d6f83f8585dd550312ebff8448a (base dba24067; merges cleanly onto main 7c44d027).
What ran at that head, Bun 1.4.2 everywhere, fresh temp HOME (and USERPROFILE on Windows):
- macOS (mote): `bun test packages/agy-cli` 14/14; step-usage 10/10, usage-settlement 33/33; `node --test test/step-usage.mjs` (Node 22.22) 10/10; `bun scripts/check.mjs` ok.
- Linux (WSL Ubuntu 24.04): `bun test packages/agy-cli` 14/14; step-usage 10/10, usage-settlement 33/33; Node 22.23 10/10; check.mjs ok.
- Windows 11: step-usage 10/10 (the loopback UNC share was reachable, so its branch ran), usage-settlement 33/33, Node 10/10, check.mjs ok. `bun test packages/agy-cli` 13/14: smoke's one red is "no call to the loaded tool reaches agy's validator in the old prompt", the known #973 (1 of 334 checks), not touched here.
- Root `bun test` on mica, merged onto origin/main 7c44d027, under suite.lock: 8407 pass, 20 skip, 0 fail across 593 files (fresh temp HOME).
Broken by hand (restored after each):
- Linux: SQLITE_OPEN_URI dropped -> step-usage 3 red, usage-settlement 2 red; `path.resolve` dropped -> the URI/relative-path test red (Bun and Node); the "no -wal after a failed immutable read returns null" guard dropped -> the mid-read test red (Bun and Node).
- macOS: the re-read after `-wal` appears removed, and the failed-immutable-read path returning null outright -> the mid-read test red under Bun and Node (at 262145f4; the code is unchanged since).
- Windows: the `\\` branch of `immutableUri` disabled -> the URI/UNC test red.
Not tried: a real agy session or account (fake agy and fixture stores only); Bun versions other than 1.4.2; a remote (non-loopback) UNC share.
Co-authored-by: tungloong <19512489+tungloong@users.noreply.github.com>
0.1.11 (#971) estimated an uncalibrated first prompt's tool steps by
summing every earlier settled step's whole window as the cached prefix.
Each window already holds the steps before it, so the prefix was counted
once per step: from the third step on, the step's whole window, the tool
result just added included, came back as a cache read. In the review's
probe (four Read calls, ACP reporting cachedReadTokens 0), step 4 billed
0 input and 34,456 read, and the steps claimed 56,608 cache-read tokens
that ACP never reported.
The prefix is now the largest earlier settled window (the step before),
so each step reads that from the cache and bills what was added since.
The step test that pinned the 100% clamp now checks that step 3's
uncached input covers what was added after step 2, and that its read
does not exceed step 2's window. Still an estimate until ACP reports.
Run (WSL2 Ubuntu 24.04, Bun 1.4.2, temp HOME): bun test packages/agy-cli
8 of 8 pass; bun scripts/check.mjs agy-cli passes.
Broken by hand: origin/main's index.mjs with the new test, node --test
test/usage-settlement.mjs: 25 pass, 1 fail ("第三步未缓存 input 0 应覆盖
第二步之后新增的 32"). Restored, green.
Not tried: Windows (main's smoke red there is #973), macOS (mote refused
ssh), a real agy.
Reported by ChrisJ_AI on X: Claude Code on an agy-cli model showed 268K-input turns
at 0% cache hit, turn after turn.
Two places dropped cache reuse; both are klarkxy's #971 (closes#970):
- a follow-up turn after the client filled defaults into historical
tool_use.input (Edit's replace_all) failed matchesHistory / takeParked, so
the live agy session was retired and the whole prefix replayed;
- tool steps of a fresh process's first prompt reported every token as a
cache miss until the prompt ended (no ratio learned yet).
Run at reviewed head 27245320 (win-run, xiaomi-gpu): node --test
test/usage-settlement.mjs 26/26 pass; the same file against c27ba5f7's
index.mjs fails tests 20, 21 and 24 (red on old code). bun test
packages/agy-cli: 7 of 8 pass, smoke.mjs 1 failure of 321 checks, the same
count on c27ba5f7.
Not tried: a real agy (signed out on every machine here, mote refused SSH),
so the 0% was not reproduced against Google's cache; the in-turn figure is
an estimate, not ACP usage.
Tool steps estimate their cache reads from the last ratio the proc learned,
and only a final, uncancelled response taught it, so a cancelled prompt left
the next one's tool steps reporting every token as a cache miss. agy reports
each prompt's cached reads, so recordPromptUsage now sets the ratio from them.
Test: a cancelled prompt (390k of 520k cached) then a tool step reports 0.75.
Red with the line off, green with it. Not captured from a real agy: the
owner's agy is signed out on this machine and mote was down. A fresh
conversation's first prompt still has no ratio until it ends.
Ran node --test packages/agy-cli/test (2 reds on base too: cp-hook,
version/report hangs), bun test packages/antigravity, scripts/check.mjs.
New package `@magpie-community/opencode-agy-cli-auth` (provider `agy-cli`, `packages/agy-cli`). It serves Antigravity models through the user's installed `agy` CLI over ACP (`agy acp`) and uses agy's own Google sign-in. The plugin reads and writes no Google tokens.
The bridge is gitxm's. On top of it, after review:
- **ACP identity.** The client names itself (`opencode-agy-cli-auth` and its package version) instead of `zed`.
- **Catalog.**
- Only what agy offers this client is listed: Gemini until a session says more, then the session's model option and `availableModels`.
- Requests are still routed by everything `agy models` lists.
- **Prompt.** agy keeps its own system prompt by default. The minimal agent is opt-in with `AGY_BRIDGE_MINIMAL_AGENT=1`, and the README says what turning it on sends upstream.
- **Version check.** agy older than 1.4.12 is refused at the handshake. 1.4.12 is the oldest version the `nc` MCP bridge was checked on, and the README documents the bridge.
- **Auto-update.**
- `AGY_CLI_DISABLE_AUTO_UPDATE` defaults to `true` only for the plugin's own agy processes.
- A value the user set is passed on as written.
- **Docs.** The READMEs and the registry summary say how this differs from antigravity-acp (#87).
- **Tests.** The author's tests came over under `test/` with a fake agy (an ACP stdio server). Each suite runs in its own `bun test`, and a `mock.module` preload stands in for `node:child_process`.
- **Cleanup.** A duplicate, unreachable image branch in validateBody is gone.
Run at ae5eafb0 on mote (macOS) with HOME=$(mktemp -d):
- `bun test packages/agy-cli`: 7 pass. Per suite:
- platform 14, compat 9, usage 20;
- catalog 15, usage-settlement 18, repeat-batch 14;
- smoke ALL OK (301 checks).
- `bun scripts/check.mjs`: all ok.
- Repo-wide `bun test`: 6792 pass, 0 fail (6812 tests, 492 files).
Broken by hand, and each went red:
- clientInfo set back to zed;
- the version check turned off;
- routing limited to the listed models;
- auto-update forced to true;
- the minimal agent on by default.
Not tried: a real agy, since mote has none, or a real Antigravity account.
Co-authored-by: gitxm <21175063+gitxm@users.noreply.github.com>