agy-cli 0.1.98: with Antigravity's app wired to magpie, the provider lists the Google account's models, not magpie's
@canlee886 on X: Antigravity was wired to magpie, and agy-cli as a
provider then listed magpie's own models (its routing groups, "GPT-6
Astra · routing group (Low…Max)"). That is a loop: magpie -> plugin ->
agy -> magpie.
Cause: magpie wires Antigravity's desktop app through the gateway block
in ~/.gemini/config/config.json, and agy 1.5.10 reads that same file. An
agy on ~/.gemini then lists and offers the gateway's models, whatever its
settings.json says. --settings '{"modelProvider":""}' doesn't help.
- The catalog's model probe ran `agy acp` with no --gemini-dir, so it was
offered magpie's models, and the catalog keeps to what a session offers.
- `agy models` (the listing, the sign-in check, refusalNow) can't be
given a --gemini-dir at all. It also answered from the gateway, and so
took magpie's listing for a Google sign-in.
- Turns already ran on the bridge's own folder, and agy reads no app
gateway there.
Fix:
- The probe runs on the folder a turn runs on (geminiDirArgs), so it is
offered what a turn is served.
- With the app's gateway on (appGatewayOn: gateway.enabled true, or a
file that isn't JSON), the listing and the sign-in check come from that
session instead of `agy models`. refusalNow doesn't read the gateway's
listing either.
- A gateway turned off, a missing file, an account home or no own
folder: `agy models` is used as before.
Run:
- Real agy 1.5.10 in a sandbox HOME, with the real Google sign-in and
the app's gateway pointing at a fake magpie on 127.0.0.1:
- old index.mjs listed rg/gpt-6-astra and rg/gpt-6-luna, with three
requests to the fake;
- new listed claude-sonnet-4-6, claude-opus-4-6-thinking, gemini-3.8-
flash and gpt-oss-120b, with no request to the fake.
- A real turn went to Google, with 0 requests to the fake. Google
answered 403: this test account is disabled for Antigravity.
- Four new tests in test/catalog.mjs. On the old index.mjs all 4 are red.
With only the probe's --gemini-dir taken out by hand, the two listing
tests are red ("magpie's own models were listed").
- On mote: bun scripts/check.mjs ok; agy-cli bun test 41 pass, 0 fail, in
a temp HOME.
Not tried: an agy with no keyring (fileSignIn) or AGY_BRIDGE_GEMINI_DIR=
default. Its turns run on ~/.gemini and still follow the app's gateway;
filed separately.
This commit is contained in:
@@ -443,10 +443,68 @@ function execOnce(file, args, opts = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
// Antigravity's desktop app keeps its gateway in ~/.gemini/config/config.json
|
||||
// ({"gateway":{"enabled":true,"url":…}}), and agy reads the same file: an agy
|
||||
// on ~/.gemini lists and serves the gateway's models, not the Google
|
||||
// account's. When magpie has wired the app to itself, that gateway is
|
||||
// magpie, so this provider listed magpie's own models and a turn would go
|
||||
// back into magpie (canlee886 on X, agy 1.5.10). agy acp on the bridge's own
|
||||
// folder (geminiDirArgs) reads no such file; `agy models` takes no
|
||||
// --gemini-dir, so with the app's gateway on, the catalog and the sign-in
|
||||
// check come from an agy acp session on that folder instead. A file that
|
||||
// can't be read as JSON counts as on: the session route is right either way.
|
||||
export function appGatewayOn(home = currentHome() ?? os.homedir()) {
|
||||
let text
|
||||
try {
|
||||
text = fs.readFileSync(path.join(home, ".gemini", "config", "config.json"), "utf8")
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const gateway = JSON.parse(text)?.gateway
|
||||
return gateway?.enabled === true
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// gatewayListed: `agy models` would answer from the app's gateway, and a
|
||||
// turn's agy (the bridge's folder) would not.
|
||||
async function gatewayListed(agyPath) {
|
||||
if (!appGatewayOn()) return false
|
||||
return Boolean((await geminiDirArgs(agyPath)).dir)
|
||||
}
|
||||
|
||||
// offeredList is what the last agy acp session offered, as parseAgyModels
|
||||
// rows: a session's model option names a family ("gemini-3.8-flash") beside
|
||||
// its levels ("gemini-3.8-flash-high"), and only the levels are kept.
|
||||
function offeredList() {
|
||||
const offered = ms().acpOfferedModels
|
||||
if (!offered?.size) return null
|
||||
const ids = [...offered.keys()]
|
||||
const families = new Set(ids.filter(id => ids.some(other => other.startsWith(id + "-") &&
|
||||
EFFORT_ORDER.includes(other.slice(id.length + 1).toLowerCase()))))
|
||||
const out = []
|
||||
for (const [id, name] of offered) {
|
||||
if (families.has(id)) continue
|
||||
const effort = /-(high|medium|low|minimal|xhigh|max)$/i.exec(id)?.[1]?.toLowerCase()
|
||||
out.push({ id, name, effort })
|
||||
}
|
||||
return out.length ? out : null
|
||||
}
|
||||
|
||||
// listOffered asks agy acp, on the bridge's folder, what it offers now.
|
||||
async function listOffered(agyPath) {
|
||||
ms().offeredStale = true
|
||||
await probeOfferedOnce(agyPath)
|
||||
return ms().offeredStale ? null : offeredList()
|
||||
}
|
||||
|
||||
async function listAgyModels(agyPath) {
|
||||
// a listing nobody asked for doesn't run an agy that would start its own
|
||||
// Google sign-in (signin.mjs); the catalog it has stays
|
||||
if (await backgroundBlocked()) return null
|
||||
if (await gatewayListed(agyPath)) return listOffered(agyPath)
|
||||
const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, await modelsArgs(agyPath), { timeoutMs: 15_000, unrefTimer: true })
|
||||
// null, not FALLBACK_MODELS: a failed listing must not overwrite a dynamic catalog.
|
||||
if (err || timedOut || code !== 0) {
|
||||
@@ -478,6 +536,8 @@ function refusalOf() {
|
||||
async function refusalNow(agyPath) {
|
||||
if (refusals.has(currentHome() ?? "")) return refusalOf()
|
||||
if (!agyPath || await backgroundBlocked()) return ""
|
||||
// the gateway's listing says nothing of the Google account
|
||||
if (await gatewayListed(agyPath)) return ""
|
||||
const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, await modelsArgs(agyPath), { timeoutMs: 15_000 })
|
||||
if (err || timedOut || code === 0) return ""
|
||||
const why = agyRefusal(`${stderr}\n${stdout}`)
|
||||
@@ -514,6 +574,13 @@ async function probeSignedIn(agy) {
|
||||
// caller goes on to magpie's own sign-in link instead
|
||||
const blocked = await backgroundBlocked({ fresh: true })
|
||||
if (blocked) return { ok: false, why: blocked }
|
||||
if (await gatewayListed(agy)) {
|
||||
const list = await listOffered(agy)
|
||||
if (!list) return { ok: false, why: "agy acp offered no model: agy is not signed in to Google" }
|
||||
useAgyPath(agy)
|
||||
storeListedCatalog(agy, list, Date.now())
|
||||
return { ok: true }
|
||||
}
|
||||
const probe = await execOnce(agy, await modelsArgs(agy), { timeoutMs: 15_000 })
|
||||
const listed = !probe.err && !probe.timedOut && probe.code === 0 &&
|
||||
probe.stdout.split("\n").some(line => /^\S+\s+\S/.test(line.trim()))
|
||||
@@ -674,8 +741,11 @@ async function probeOfferedModels(agyPath) {
|
||||
let conn = null
|
||||
let timer
|
||||
try {
|
||||
// on the folder a turn runs on, so it offers what a turn is served
|
||||
// (appGatewayOn: on ~/.gemini it would offer the app's gateway's)
|
||||
const own = await geminiDirArgs(agyPath)
|
||||
workspace = await fs.promises.mkdtemp(path.join(os.tmpdir(), "magpie-agy-models-"))
|
||||
child = spawnAgy(agyPath, ["acp"], { cwd: workspace, stdio: ["pipe", "pipe", "pipe"], windowsHide: true })
|
||||
child = spawnAgy(agyPath, ["acp", ...own.args], { cwd: workspace, stdio: ["pipe", "pipe", "pipe"], windowsHide: true })
|
||||
child.on("error", () => conn?.close(new Error("agy acp failed to start")))
|
||||
child.on("close", () => conn?.close(new Error("agy acp exited")))
|
||||
child.stdin?.on("error", () => {})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.97",
|
||||
"version": "0.1.98",
|
||||
"description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
@@ -823,3 +823,81 @@ test("shenggxhz 运行中换了账号:agy models 列表变了就重新探测
|
||||
assert.equal(kit.acpSpawns.length, 2, "列表没变不该再起探测会话")
|
||||
})
|
||||
})
|
||||
|
||||
// canlee886 on X: magpie wired Antigravity's app to itself
|
||||
// (~/.gemini/config/config.json's gateway), and agy reads that file too: an
|
||||
// agy on ~/.gemini lists and offers magpie's own models, and a turn on one
|
||||
// would go back into magpie. The provider lists the Google account's.
|
||||
const APP_GATEWAY_ACP_HELP = "Usage of acp:\n --gemini-dir\n \tPath where Gemini files are stored (default .gemini)\n"
|
||||
const MAGPIE_ROWS = [["rg/gpt-6-astra", "GPT-6 Astra · routing group"], ["rg/gpt-6-astra:low", "GPT-6 Astra · routing group (Low)"], ["gemini-4-argon-high", "Gemini 4 Argon (High)"]]
|
||||
const ACCOUNT_OFFERED = [
|
||||
["gemini-3.8-flash", "Gemini 3.8 Flash"],
|
||||
["gemini-3.8-flash-high", "Gemini 3.8 Flash (High)"], ["gemini-3.8-flash-low", "Gemini 3.8 Flash (Low)"],
|
||||
["claude-opus-4-6-thinking", "Claude Opus 4.6 (Thinking)"],
|
||||
]
|
||||
function appGatewayKit(extra = {}) {
|
||||
const onOwnFolder = (args) => args.includes("--gemini-dir")
|
||||
return {
|
||||
acpHelp: APP_GATEWAY_ACP_HELP,
|
||||
topHelp: AGY_159_TOP_HELP,
|
||||
// `agy models` has no --gemini-dir: it always reads the app's gateway
|
||||
modelsBehavior: { stdout: modelsOutput(MAGPIE_ROWS) },
|
||||
offeredModels: (_home, args) => onOwnFolder(args) ? ACCOUNT_OFFERED : MAGPIE_ROWS,
|
||||
...extra,
|
||||
}
|
||||
}
|
||||
function wireAppGateway(home, body = { gateway: { enabled: true, url: "http://127.0.0.1:3425", apiKey: "mk", wireProtocol: "openai" } }) {
|
||||
fs.mkdirSync(path.join(home, ".gemini", "config"), { recursive: true })
|
||||
fs.writeFileSync(path.join(home, ".gemini", "config", "config.json"), typeof body === "string" ? body : JSON.stringify(body))
|
||||
}
|
||||
function assertAccountListed(listed) {
|
||||
const all = ids(listed)
|
||||
assert.ok(!all.some(id => id.startsWith("rg/")), `magpie's own models were listed: ${all.join(", ")}`)
|
||||
assert.ok(listed["gemini-3.8-flash"], `the account's models should be listed, got ${all.join(", ")}`)
|
||||
assert.deepEqual(Object.keys(listed["gemini-3.8-flash"].variants ?? {}).sort(), ["high", "low"])
|
||||
assert.ok(listed["claude-opus-4-6-thinking"], `got ${all.join(", ")}`)
|
||||
}
|
||||
|
||||
test("canlee886 Antigravity 的 app 接到 magpie 时,目录列 Google 账号的型号,不列 magpie 自己的", async () => {
|
||||
await withKit(appGatewayKit(), async (kit) => {
|
||||
wireAppGateway(kit.home)
|
||||
await kit.models()
|
||||
await warmed(kit)
|
||||
assertAccountListed(await kit.models())
|
||||
assert.ok(kit.acpSpawns.length >= 1)
|
||||
for (const spawn of kit.acpSpawns) assert.ok(spawn.args.includes("--gemini-dir"), `agy acp ran on ~/.gemini: ${spawn.args.join(" ")}`)
|
||||
})
|
||||
})
|
||||
|
||||
test("canlee886 app 接到 magpie 时,登录检查和它读到的目录都来自账号的会话", async () => {
|
||||
await withKit(appGatewayKit(), async (kit) => {
|
||||
wireAppGateway(kit.home)
|
||||
const started = await kit.plugin.auth.methods[0].authorize()
|
||||
assert.equal((await started.callback()).type, "success")
|
||||
assertAccountListed(await kit.models())
|
||||
assert.equal(kit.modelsSpawns.length, 0, "agy models lists the app's gateway, not the account")
|
||||
})
|
||||
})
|
||||
|
||||
test("canlee886 app 接到 magpie、agy 没登录 Google 时,登录检查不因 gateway 的列表说已登录", async () => {
|
||||
await withKit(appGatewayKit({ sessionNewError: { code: -32000, message: "Authentication required" } }), async (kit) => {
|
||||
wireAppGateway(kit.home)
|
||||
const started = await kit.plugin.auth.methods[0].authorize()
|
||||
// signed in, authorize ends at once ("auto"); here it starts Google's sign-in
|
||||
assert.notEqual(started.method, "auto", "the gateway's listing was taken for a Google sign-in")
|
||||
})
|
||||
})
|
||||
|
||||
test("canlee886 app 的 gateway 关着、读不成 JSON 时各按关、开处理", async () => {
|
||||
await withKit(appGatewayKit({ offeredModels: ACCOUNT_OFFERED, modelsBehavior: { stdout: modelsOutput(ACCOUNT_OFFERED.slice(1)) } }), async (kit) => {
|
||||
wireAppGateway(kit.home, { gateway: { enabled: false, url: "http://127.0.0.1:3425" } })
|
||||
assert.equal(kit.module.appGatewayOn(kit.home), false)
|
||||
await kit.models()
|
||||
await warmed(kit)
|
||||
assert.ok(kit.modelsSpawns.length >= 1, "a gateway turned off leaves agy models as it was")
|
||||
wireAppGateway(kit.home, "{not json")
|
||||
assert.equal(kit.module.appGatewayOn(kit.home), true)
|
||||
fs.rmSync(path.join(kit.home, ".gemini", "config", "config.json"))
|
||||
assert.equal(kit.module.appGatewayOn(kit.home), false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -225,7 +225,9 @@ class FakeAgy {
|
||||
child.onStdin = (chunk) => this.onStdin(chunk)
|
||||
// offeredModels may be a function of the agy's HOME: accounts on
|
||||
// different plans are offered different models (#1229).
|
||||
this.offered = () => typeof kit.offeredModels === "function" ? kit.offeredModels(this.env.HOME ?? "") : kit.offeredModels
|
||||
// and of its args: an agy on ~/.gemini is offered what the app's
|
||||
// gateway lists, one on --gemini-dir its Google account's
|
||||
this.offered = () => typeof kit.offeredModels === "function" ? kit.offeredModels(this.env.HOME ?? "", child.args) : kit.offeredModels
|
||||
// Whether this agy reaches the bridge's MCP server and lists the tools;
|
||||
// listTools(env) false stands in for an `nc` agy never runs (nc.cmd
|
||||
// under agy 1.5 on Windows, plugins#1239).
|
||||
|
||||
Reference in New Issue
Block a user