Commit Graph
10 Commits
Author SHA1 Message Date
yetone 2e77e646c8 agy-cli 0.1.36: the last model list agy gave is served after a restart (#1086)
After a restart, models() handed out the static Gemini-only fallback until
agy answered again. offeredFilter also hid every non-Gemini model until a
session or probe told it what agy offers. So the first requests after a
restart saw no Claude models.

The bridge now keeps the last list agy gave, and the set it offered, in
models.json beside the session state file. The file has one entry per agy
path, is written under the state lock through temp-and-rename (mode 0600),
and is trusted for 14 days. A half-written or invalid file, another agy
path, or a stale entry all give the static fallback, as before. A saved
list is not treated as an answer from this agy: the offered probe still
waits for a real listing.

Run (WSL magpie-desktop, Bun 1.4.2, Node 22):
- bun test in packages/agy-cli: 20 pass.
- node --test test/catalog.mjs: 24 pass.
- bun scripts/check.mjs agy-cli: ok.
Windows (xiaomi-gpu): node --test test/catalog.mjs 12 times, 11 green.
The one red is the existing wall-clock test "#1064 登录检查不为探测等太久",
filed as #1089. I haven't shown whether it is red on origin/main too.

Broken by hand: readSavedCatalog returning null turns the new #1086 test
red; skipping the offered restore turns it red too.

Not tried: real agy on any OS; a restart with a real signed-in agy.

Reported-by: yinbing-666
2026-11-13 17:29:06 +08:00
yetone 7bccaae910 agy-cli 0.1.35: a client tool's ide-tools permission request is allowed once (#1082)
Newer agy asks before an MCP call, and the bridge refused every
session/request_permission, so each client tool failed with "user
denied permission for mcp(ide-tools/exec_command)". A request whose
title (or name) is exactly mcp(ide-tools/<tool>), mcp "ide-tools/<tool>",
ide-tools/<tool> or mcp_ide-tools_<tool>, with <tool> among the tools
the client declared, now gets allow_once. Those tools run in the client
under its own permissions. agy's own tools (shell, edits, browser) are
still denied, as is a title that only contains such a name somewhere
(a shell command's text can be in its title), an undeclared tool and
another server's tool. rawInput is never read.

Run (WSL magpie-desktop, HOME=$(mktemp -d)): bun test in
packages/agy-cli, 20 pass; bun scripts/check.mjs agy-cli ok. Broken by
hand: with the allow branch off, smoke.mjs has 2 failures, the two
#1082 allow checks.

Not tried: a real agy that asks for MCP permission. The title agy
sends for an MCP call isn't known from its strings, so the forms above
come from its rule and error text; the reporter is asked to confirm.

Reported-by: Saramanda9988
2026-11-13 16:08:40 +08:00
yetone b40a853c20 agy-cli 0.1.34: agy isn't run in the background without a sign-in, so it stops opening the browser (JZGiVvkSOA75376 on X)
On Windows 11, a signed-out agy opened Google's sign-in page 235 times
in one day. The usage refresh ran `agy` about every 3 minutes, and agy
opens the browser through ShellExecuteW, so the BROWSER=open.cmd guard
can't stop it.

New signin.mjs reads agy's stored sign-in without running agy. agy keeps
it through go-keyring, service "gemini" and user "antigravity":
- macOS: `security find-generic-password`;
- Windows: CredReadW from PowerShell, on the credential
  "gemini:antigravity".
It reads only whether a sign-in is stored, whether it has a refresh
token, and when the access token ends. The token itself never leaves
the function; a hash tells one sign-in from the next. Setting
GEMINI_API_KEY, GOOGLE_API_KEY, AGY_ADC_AUTH or GOOGLE_GENAI_USE_VERTEXAI
means agy signs in some other way, so nothing is concluded from the
keyring. AGY_BRIDGE_STORED_SIGNIN=skip turns the read off.

An access token that has ended is not "needs sign-in". The owner's
working agy has one that ended 11 hours ago and is renewed from its
refresh token. agy counts as unable to sign in when:
- no sign-in is stored;
- the access token has ended and there is no refresh token;
- or agy already failed on this stored sign-in: it said it needs a
  sign-in, or it hung with an ended token and printed nothing or
  sign-in talk, the way an agy waiting on its browser does. This holds
  until another sign-in is stored.

What changes:
- Usage: in those cases agy isn't run. The read says signIn "expired",
  and magpie shows the account's sign-in as expired. After the next good
  read it says "renewed", and magpie clears that.
- Other usage failures wait 10 minutes before the next run, doubling up
  to 6 hours. Before, they ran again on every refresh.
- The model listing (`agy models`) isn't run in the background in those
  cases either. The catalog it has stays.
- Signing in from magpie skips the `agy models` probe and goes straight
  to magpie's own sign-in link. A finished sign-in clears what was
  marked dead.
- A request answers 401 with X-Magpie-Sign-In: expired when no sign-in
  is stored. This uses the last read, so a request never waits for
  PowerShell.
- `agy --version` hanging is never read as a sign-in wait.

Run:
- mote, rebased on a02d5912: `bun scripts/check.mjs` ok and
  `bun test` in packages/agy-cli (20 pass, 0 fail).
- mote, root `HOME=<temp> bun test` at the pre-rebase head (e90d6f01
  base): 7588 pass, 427 fail, none in agy-cli. The reds named in the
  kept tail are OAuth callback-port and loopback page-service tests
  (mote at load ~35-40); main's own CI test job passes them, so this
  push's CI test job is the record for the whole suite.
- win-run on xiaomi-gpu: test/signin.mjs and test/usage.mjs (21 pass,
  3 skip on Windows), plus the PowerShell script for real. Over SSH,
  CredReadW answers 1312 (no logon session), which the script turns into
  "unknown". So the struct read was tried on a CREDENTIALW built in
  memory with a UTF-8 blob: the bytes round-trip and the sign-in parses.
Broken by hand:
- with the usage gate, the backoff hold and the dead mark removed, 5
  usage tests go red;
- with listAgyModels' gate and the request gate removed, the new catalog
  test goes red;
- with the request gate alone removed, it goes red too.
Not tried:
- a real signed-out agy, by the rule against running a real agy sign-in
  or a browser;
- CredReadW in an interactive Windows session (none was logged on);
- agy on Windows at all (xiaomi-gpu has no agy).
On Linux the keyring isn't read ("unknown"): agy runs as before, with
the backoff, and the xdg-open shim already stops the browser there.
2026-11-13 13:45:25 +08:00
yetone 00892c80e3 agy-cli 0.1.33: DSH's @-path paragraph goes reworded, as antigravity sends it (#1028) (LeeTengLong on X)
agy-cli's cloak.mjs copied only antigravity's TURNED_AWAY break-up (#980),
not the REWORDED rewrite antigravity 0.1.7 added for #1028, so DeepSeek
Harness's "Tokens prefixed with @ are paths…" paragraph reached agy word
for word, the text that got gemini-4-argon answering fast, without thinking
and shallow.

cloak.mjs now carries REWORDED, reword and outgoing (reword after cloak),
a copy of antigravity/index.mjs's, and every place agy-cli hands system text
to agy uses outgoing: the session's systemPrompt.append,
<external_system_instructions>, a later system/developer message and the
notices beside a tool result. Only that exact paragraph changes; a prompt
that merely mentions @ paths, and what the user wrote, go as written.
instructionsIdentity still keys on the prompt as the client wrote it. The
packages ship on their own, so the code is a copy; cloak.test.mjs holds it to
antigravity's shape() output for each REWORDED entry and the samples.

Run on mote (Bun 1.4.2, temp HOME): bun test packages/agy-cli
packages/antigravity 118 pass 0 fail; bun scripts/check.mjs exit 0.
Broken by hand: outgoing without reword turns 3 tests red (cloak.test.mjs
2, and smoke.mjs's #1028 session, external_system_instructions and later
system message checks).
Not tried: a real agy with a real Antigravity account and DSH; the
rewording's effect rests on #1028's replays. No magpie min names agy-cli.

Reported-by: LeeTengLong
2026-11-13 13:14:51 +08:00
yetone 5341ac1e70 agy-cli 0.1.19: every client tool is listed always loaded, so agy no longer hides large ones from the model (#989)
agy loads an MCP tool on demand, outside the model's function list,
unless the server's tools/list marks it with
_meta {"antigravity/alwaysLoad": true} (agy's changelog, 1.3.5; the key is
in the 1.5.5 binary next to SplitEnabledToolsByEagerLazy and
McpServerSpec.force_all_tools_eager). The bridge's agent has tools: [],
so the model had no working way to load them: on klarkxy's 72-tool
catalog, tools from ~691 tokens up (bash, grep, task, ask_user) were
never offered while read, glob and write were. listTools now adds the
key to every tool it hands agy; the stored catalog and its signature
are unchanged.

Ran: wsl-run (magpie-desktop) with HOME=$(mktemp -d): bun test
packages/agy-cli (13 pass), bun scripts/check.mjs (ok), root bun test
(8207 pass, 19 skip, 0 fail) at base 017cd73e; after the rebase onto
02fe223d, packages/agy-cli + packages/astudio (95 pass) and check again.

Broken by hand: listTools returning this.tools as before makes the new
smoke check red ("1 FAILURES (334 checks)", _meta null on all three).

Not tried: a real agy turn on Gemini 4 Carbon (no Google contact from
here), so that agy now puts the large tools in gen_metadata is from its
changelog and strings, not a run. The report gives sizes, not schemas;
the fixture is sized to them (bash ~7KB, read ~140B).

Reported-by: klarkxy
2026-11-11 19:20:59 +08:00
yetone 9ec696258d agy-cli 0.1.18: turned-away system lines are broken up before agy sends them, and a 429 to one is not a quota (#980)
Antigravity answers 429 "Resource has been exhausted" to a few system
prompt lines whatever quota is left (Claude Code's billing line, the Claude
Agent SDK, Codex's and Hermes Agent's identities, oh-my-pi's RFC 2119
line). The antigravity provider breaks them up with zero-width spaces
(TURNED_AWAY / breakUp / cloak); agy-cli sent the client's system prompt
to agy as written, and called the 429 an exhausted quota
(rate_limit_error), so a client or routing group retried a prompt that
fails every time.

- cloak.mjs is a copy of antigravity's TURNED_AWAY, cloak and hint (the
  two-zero-width-space break-up of 11-11). Each package ships on its own,
  so cloak.test.mjs imports packages/antigravity's _internal and fails
  when the two give a different answer for any line or sample.
- Every route the system text reaches agy is cloaked: the session's
  systemPrompt.append (session/new and session/resume),
  <external_system_instructions> when agy can't append, a later system
  or developer message in the turn or the replayed history
  (renderTurnMessageParts), and a system/developer notice delivered
  beside a tool result (extractToolResults).
- What the bridge keys and hashes on is unchanged: proc.instructions,
  sameInstructions, instructionsIdentity, stripVolatileSystem and the
  session store keep the prompt as the client wrote it; cloak is applied
  only where the text is sent. User text is not touched.
- #formatAgentError: a "code 429 ... Resource has been exhausted" with a
  turned-away line in the session's instructions is an
  invalid_request_error, "Antigravity answered 429 to this system prompt:
  <detail> — <hint>", with the antigravity provider's hint. Any other 429
  stays rate_limit_error.
- READMEs (en, zh) say so under the minimal-agent section.

Run (wsl-run, magpie-desktop, HOME=$(mktemp -d), at f85f9ad0 + this change):
- bun test packages/agy-cli: 13 pass 0 fail (smoke ALL OK, 333 checks)
- bun scripts/check.mjs: exit 0
- root bun test: 8189 pass, 19 skip, 0 fail (580 files, 408s)
- rebased on 84ee9b88 (day-card, autoclaw, sap-aicore only): bun test packages/agy-cli
  13 pass 0 fail and bun scripts/check.mjs exit 0 again at this head

Broken by hand (each red, then restored):
- append: this.instructions uncloaked -> "#980 ... session instructions" BAD
- <external_system_instructions> uncloaked -> its #980 check BAD
- later system message uncloaked -> "#980 a later system message" BAD
- tool-result notice uncloaked -> "#980 ... system notice beside a tool
  result" BAD
- the turned-away branch of #formatAgentError off -> the 429 came back
  rate_limit_error, "#980 a 429 ... prompt rejection" BAD
- cloak.mjs back to one zero-width space after the first letter -> both
  cloak.test.mjs tests red

Not tried: against real Antigravity or a real agy (no vendor API was
reached; the fake agy in test/smoke.mjs stands in). Whether agy's own
request puts the appended instructions where Google matches them is
taken from the report and the antigravity provider, not measured here.
A turned-away line the user pastes into their own message is sent as
written, as the antigravity provider does.

Reported-by: shaohongwu
2026-11-11 17:54:13 +08:00
Qtlz a5a63a109f agy-cli 0.1.3: an assistant prefill tail is continued, not refused (#904)
A request ending in a text-only assistant turn (SillyTavern prefill,
"continue"/"impersonate", bot frameworks) was refused with a 400. That
trailing run now stays in the tail, after the session ledger's newest
entry, so the agy session is reused across prefill turns, and it is
rendered as a continuation of the model's own reply. A prefill beside a
live tool_result, or with no user turn before it, is still a 400.
AGY_BRIDGE_PREFILL=0 brings the old refusal back.

Reviewed at f7b249cec9e827b7ef49197a207180f3f7085cfe, run on mote:
bun test ./agy-cli.test.mjs 8 pass / 0 fail; bun scripts/check.mjs ok.
Broken by hand: with main's index.mjs and these tests, test/prefill.mjs
and the smoke test fail (6 pass / 2 fail).
Checked: renderTurnMessagesParts only gets the current turn's tail, never
history, so a finished reply is never taken for a prefill.
Not tried: a real agy account.
2026-11-09 20:12:15 +08:00
yetoneandyulong-ge 03ab6d66f4 agy-cli 0.1.2: list what agy acp offers before the first request (#854)
Until a request had opened an ACP session, agy-cli listed Gemini only
(offeredFilter), so a user who hadn't sent a Gemini request yet saw no
Opus (chriskan666 on Discord). provider.models() now asks agy's ACP
server itself, as yulong-ge's antigravity-official-acp (#854) does:
a short `agy acp` with the plugin's own clientInfo, initialize and
session/new (no prompt), reading the session's model option and
models.availableModels into the same offered set a request's session
fills. The session is closed when agy says it can be, and the process
and its temp folder are removed.

- Only provider.models() probes; a request opens its own session.
- It runs once `agy models` has answered (agy is signed in), at most
  once a minute while the offer is unknown, and not at all once known.
- models() waits for it as briefly as for the listing (500ms) and
  never longer; a failed or timed-out probe (30s) keeps Gemini only.
- An agy older than 1.4.12 gets no session.

#854's own code reads session/new's availableModels, not `agy models`
(its body says `agy models`); agy-cli already parsed `agy models`, so
nothing of that parser changed.

Run at origin/main ae518836 plus this diff (this commit's tree) on mote (macOS), HOME=$(mktemp -d), under suite.lock:

- `bun test packages/agy-cli`: 6 of 7 suites pass; test/usage.mjs was red
  once ("version/report hangs time out", 1239ms), a timing test this
  change doesn't touch: filed as #856. It then passed 5 of 5 alone.
  catalog 17 pass, smoke ALL OK (314 checks).
- `bun scripts/check.mjs agy-cli`: registry.json and agy-cli ok.
- repo-root `bun test`: 6878 pass, 0 fail (6898 tests, 500 files).

Broken by hand: models() with the probe off. catalog.mjs went 2 red
(the probe lists Opus with no request; a failed probe is tried again
after a minute) and smoke.mjs 1 BAD ("listing models learns what agy's
ACP server offers, before any request").

Not tried: a real signed-in agy. This Mac's agy 1.5.3 (CLI 1.4.12) is
signed out: `agy models` says "Please sign in to view available
models", and its `agy acp` answers initialize and refuses session/new
with -32000 "Authentication required" (the fake's sign-in error is that
reply). mote has no agy. That the ACP session offers Claude and GPT-OSS
to a non-editor client rests on #854's author's run (agy 1.5.3 acp,
13 models incl. Claude and GPT-OSS).

Co-authored-by: yulong-ge <41790869+yulong-ge@users.noreply.github.com>
2026-11-08 13:17:47 +08:00
yetone ecab839688 agy-cli 0.1.1: sign in to Google from magpie, through agy's own agy acp --login
treeman_26897 (Discord #feedback, 11-08): Sign in on agy-cli opened no
browser, and asked for a field to paste the callback into.

Cause: the plugin had no sign-in of its own. Its one method only checked
whether `agy models` worked, and if not it said to run `agy` in a
terminal. magpie still showed "Finish signing in ... in your browser",
but nothing ever opened a page.

Now the method is oauth:
- Already signed in to agy (`agy models` lists models): done at once. No
  page opens and no agy login starts.
- Otherwise the plugin starts `agy acp --login` (agy 1.5 and later). That
  prints Google's link and reads the code from stdin. magpie opens the
  link on the user's machine and shows its code field (method "code").
  - The field takes the code antigravity.google/oauth-callback shows, or
    that page's whole address.
  - No loopback is involved, so it works with Remote magpie and in Docker.
- agy trades the code and keeps the token in its keyring. The plugin never
  sees the token.
- The account is saved only once `agy models` lists models afterwards. A
  wrong, empty or expired code fails, and nothing is saved. Google's
  invalid_grant is worded as "turned the code away".
- The link waits 15 minutes, then agy is stopped. A new sign-in stops the
  previous agy.
- agy 1.4.x has no --login. It gets "update with `agy update`, or run
  `agy` in a terminal".
- The login runs with auto-update off, like the plugin's other agy
  processes.

Import from a file is not added. agy keeps its credentials in the system
keyring, not in a file under ~/.gemini/antigravity-cli.

The empty account the report also describes was not reproduced on
current magpie. A failed sign-in saved nothing, in the GUI and the CLI.
This version also needs models listed before it saves anything.

Run:
- On mote (macOS, Bun 1.4.2) at this tree, `bun test` in packages/agy-cli:
  7 pass / 0 fail.
- `bun scripts/check.mjs` and `bun scripts/check.mjs agy-cli`: exit 0.
- New smoke checks, with the old index.mjs put back: red, at "signed in
  to agy already, the sign-in saves agy" (the old method has no callback).
- Real agy 1.5.3 on mote, sandbox HOME, current magpie `web`, through
  Playwright:
  - Providers > agy-cli opened Google's sign-in page, and the code field
    showed.
  - A bogus code gave "Sign-in didn't finish: Google turned the code
    away...". /api/providers had no agy row.
- `magpie plugin login agy-cli`:
  - With a bogus code, the same error.
  - With real agy 1.4.12, the update message.
- Real agy 1.5.3 on Windows 11 (win-run) and on Linux (WSL2 Ubuntu 24.04,
  wsl-run): authorize gave Google's link in about 2s, and a bogus code
  failed with the invalid_grant wording. No agy was left running.

Not tried:
- A real Google sign-in through to models. Only bogus codes were used, and
  no real account was touched.
- magpie inside a Docker container.

Reported-by: treeman_26897
2026-11-08 11:48:40 +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