10 Commits
Author SHA1 Message Date
yetone 62645eceb7 agy-cli 0.1.96: a resumed session runs in its own folder again, so agy's cache still hits
@chet030714 on X: Hermes through agy-cli started near 70% cache hits and
fell all day. agy's prompt cache follows the folder its process runs in.
Every agy the bridge started had a new mkdtemp folder, so a session
resumed after the 10-minute idle reclaim, an LRU eviction or a restart
replayed its whole history uncached, and the longer a conversation got,
the more each resume cost.

Measured with real agy 1.5.10 over ACP in a sandbox HOME (one session,
~24K tokens a turn): every turn in one process hit (cachedReadTokens
19,682 to 197,710). A resume in the same folder: 213,520 cached. In
another folder: 0 cached, 219,198 uncached. Only the process's folder
counts, not session/resume's cwd. The same folder after 13 minutes
idle, or removed and made again at the same path, still hits.

Now a parked session records its workspace, and a resume starts agy in
that folder (made again if it was removed), never in a spare's. Only a
magpie-agy-bridge-XXXXXX folder directly in the temp folder is taken
from the state file. A stopped agy leaves its folder when another
already runs there, and a resume waits for a removal in progress.

Run (at 63c2ff93 + this diff):
- mica, HOME=$(mktemp -d): packages/agy-cli `bun test`: 41 pass, 0 fail.
- The new test (usage-settlement.mjs, LRU resume runs in the session's
  folder) on the old index.mjs, by hand: fails.
- The real bridge, index.mjs loaded with real agy in a sandbox HOME, two
  turns with the process reclaimed between them (AGY_BRIDGE_IDLE_MS=5000):
  old code, resumed turn 0 of 32,127 cached; this change, 29,681 of
  32,018 cached.

Not tried: Windows and Linux with real agy. A resume from a park entry
written before this version still starts in a new folder, once.
2026-11-19 01:14:23 +08:00
yetone 3238ab8518 agy-cli 0.1.54: agy runs in the bridge's own --gemini-dir, so the machine's skills stay out (#1166)
0.1.52 passed --include-default-customizations=false, but on Windows
(agy 1.5.9) agy still loaded all 120 of the reporter's skills: a 56,790 B
<skills> block in its gen_metadata, and task, shell and four more client
tools dropped over the 20,000-token budget. The reporter (kanzaki-chiya)
found that --gemini-dir pointed at an empty folder of the bridge's own
leaves the skills and global MCP servers out, with every client tool
listed and shell/task calls working end to end.

So when `agy acp --help` lists --gemini-dir, a turn's agy gets
<XDG_STATE_HOME or ~/.local/state>/magpie-agy-bridge/agy-home, made
before agy starts and kept across restarts so session/resume finds the
conversation. agy's Google sign-in is in the system keyring, not that
folder. Step usage reads the conversation DB from the same folder.
AGY_BRIDGE_GEMINI_DIR names another folder; "default" leaves agy on its
own ~/.gemini. The model probe and `agy models` are unchanged. One
`acp --help` per binary answers both flags.

What happens to old data: a session parked before this update was in
~/.gemini, so its resume fails once and falls back to session/new, as a
resume that fails does today.

Run on mote: node --test test/repeat-batch.mjs test/usage-settlement.mjs
(81 pass), bun test in packages/agy-cli (22 pass), bun scripts/check.mjs
agy-cli ok. test/smoke.mjs prints the same 29 BADs and crash at
origin/main df7d7ae0 as with this change (plugins#1070).
Real agy 1.5.9 on macOS, with the user's account: `agy acp --gemini-dir
<empty folder>` initialised, session/new listed the account's six
models, and the session's .db was written under
<folder>/antigravity-cli/conversations, not ~/.gemini.
Broken by hand: with step usage left on ~/.gemini, the new usage test
reads the machine folder's count (9999 != 1800).
Not tried: a real turn on Windows or Linux with this build; the
Windows result is the reporter's, with their own patch of 0.1.52.
2026-11-15 07:45:56 +08:00
tungloongandtungloong 753a61f85c agy-cli 0.1.31: wait for MCP commit before cancelling steered tool turns (#1061)
When a client steers a live tool turn, agy-cli now waits for agy to commit the MCP responses (a tool_call_update, the next generation, or the prompt ending; AGY_BRIDGE_MCP_COMMIT_WAIT_MS, default 5s) before sending session/cancel. Before, the cancel could beat the response, and agy recorded "Tool execution was canceled". A clean steer keeps SQLite step usage trusted, and an unpolled LONGTOOL result stays in the steered prompt. A steer in progress is not evicted or reclaimed, and a second steer gets 503.

Reviewed at 01de2cc. Run on a separate test Mac (Bun 1.4.2, temp HOME): bun scripts/check.mjs agy-cli ok; bun test ./packages/agy-cli 17 pass. Broken by hand: with no commit wait, the smoke steer case, six steer-in-session groups and usage-settlement go red. Not tried by the reviewer: a real agy (the author's live run on agy 1.5.6 is in the PR).

Co-authored-by: tungloong <tungloong@users.noreply.github.com>
2026-11-13 08:21:35 +08:00
tungloong b64dfb91cb agy-cli 0.1.23: thinking is not counted twice on the SQLite path (#1032)
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.
2026-11-12 12:03:47 +08:00
Klarkxy b829a5541e agy-cli 0.1.22: thinking is not counted twice in billed output (#1023)
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>
2026-11-12 10:52:21 +08:00
tungloongandtungloong 01eaa6dda4 agy-cli 0.1.20: each step's usage from agy's own store, and 1.5.1+ inputTokens read as uncached (#983)
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>
2026-11-12 04:30:07 +08:00
yetone 7869318d6a agy-cli 0.1.12: a tool step's estimated cache read stops at the step before it, so a new tool result is billed as input (#971 review)
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.
2026-11-11 13:31:30 +08:00
Klarkxy 73d2006444 agy-cli 0.1.11: sessions survive canonicalized tool input; a first prompt's tool steps count the settled prefix as cached (ChrisJ_AI on X, klarkxy #971)
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.
2026-11-11 13:20:37 +08:00
yetone c27ba5f700 agy-cli 0.1.6: every prompt's own cache reads set the ratio the next tool steps report (baranwang on X)
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.
2026-11-11 11:55:10 +08:00
gitxmandgitxm 0f0c4ec68f agy-cli: Antigravity on the local agy CLI over ACP (#785)
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>
2026-11-07 20:14:45 +08:00