agy-cli: a saved or outdated model offer is asked again, so Ultra lists Gemini 4 (0.1.91)

shenggxhz (X, 11-17) moved from a Pro account to Ultra, and the agy
provider still listed no Gemini 4 Carbon. What agy acp offered the Pro
account was kept in models.json and loaded at start as the offer, and
probeOfferedOnce never asked agy again while an offer was known. Only a
request opening a session replaced it, so Ultra's fresh `agy models`
listing (Carbon in it) was filtered down to the Pro account's offer.
With main's index.mjs the new test lists exactly the reporter's
screenshot: claude-sonnet-4-6, gemini-3.8-flash, gpt-oss-120b.

Now an offer read from models.json, or one learnt before `agy models`
listed something else (the account or plan changed outside magpie), is
served while agy acp is asked again (offeredStale), and a session's
answer makes it current. Costs one short agy acp session per run after
a restart, and one per listing change.

Tests (test/catalog.mjs): a restart after the switch lists Carbon and
probes once; a listing change mid-run probes again, an unchanged one
doesn't; #1086's restart now also expects that one probe (its timeout
raised to 15s for the 1.5s slow session). With main's index.mjs the
three are red. Run on mica: root `HOME=$(mktemp -d) bun test` and
`bun scripts/check.mjs`, results below.
Not tried: a real Pro-to-Ultra switch (no Ultra account here).

mica, at this tree (parent 34edf938): root bun test 9041 pass, 0 fail
(9061 tests, 634 files); bun scripts/check.mjs exit 0.
This commit is contained in:
yetone
2026-11-17 23:59:29 +08:00
parent 34edf938da
commit 677329db24
5 changed files with 87 additions and 5 deletions
+3 -1
View File
@@ -72,7 +72,9 @@ MCP server. The control port listens on loopback only, with a token per process.
left out. To list models, the plugin opens one session with `agy acp` (no
prompt is sent) and reads what it offers; until it has, only Gemini is listed.
The last list agy gave and offered is kept in `models.json` beside the session
state file, so after a restart that list is served while agy is asked again.
state file, so after a restart that list is served while agy is asked again:
both what it lists and what a session offers, and again whenever the list
changes (another account or plan).
Models and thinking levels can be switched mid-conversation without losing
history.
`agy models` runs with `--settings '{"modelProvider":""}'`, so a
+1 -1
View File
@@ -52,7 +52,7 @@ agy 连接 `--ide-mcp-port` 时会运行 `nc 127.0.0.1 <端口>`。插件在 agy
模型如果没有在会话里向本客户端开放(agy 可能只向它认可的客户端开放 Claude、GPT-OSS),
就不会出现在列表里。列模型时插件会先用 `agy acp` 开一个会话(不发 prompt)问 agy 开放了哪些,
问到之前只列 Gemini。上次 agy 列出并开放的模型存在会话状态文件旁边的 `models.json`,
重启后先列它,同时再问一次 agy。模型和思考等级可以在会话中切换,
重启后先列它,同时再问一次 agy:列出的和会话开放的都再问,列表变了(换了账号或套餐)也再问。模型和思考等级可以在会话中切换,
历史保留。`agy models` 带 `--settings '{"modelProvider":""}'` 运行,所以
settings.json 里的 `"modelProvider": "gemini"`(AI Studio 密钥)不影响这里的列表,
列出的是 Google 账号的模型;AI Studio 密钥请在 Magpie 的 Providers 页加成 Google Gemini。
+18 -1
View File
@@ -539,6 +539,11 @@ const MODEL_CATALOG_RETRY_MS = 5_000
// session's model option (and its models.availableModels) says which;
// the catalog keeps to that. Before any session has said, only Gemini
// models are served.
// - offeredStale: acpOfferedModels is what agy acp offered before (saved in
// models.json by an earlier run, or before `agy models` listed something
// else): served until agy acp is asked again, never believed for good.
// shenggxhz (X, 11-17) moved from Pro to Ultra and kept the Pro account's
// offer, which filtered Gemini 4 out of Ultra's listing.
// - offeredProbePromise, offeredProbeAt, offeredGen: the probe below.
const modelStates = new Map()
@@ -552,6 +557,7 @@ function ms() {
wantOfferedProbe: false,
acpOfferedModels: null,
acpOfferedKey: "",
offeredStale: false,
offeredProbePromise: null,
offeredProbeAt: null,
offeredGen: 0,
@@ -575,6 +581,7 @@ function offeredModelsOf(configOptions, models) {
function noteOfferedModels(configOptions, models) {
const offered = offeredModelsOf(configOptions, models)
if (!offered.length) return
ms().offeredStale = false
const names = new Map(offered.map(model => [model.id, typeof model.name === "string" && model.name ? model.name : model.id]))
const key = [...names.keys()].sort().join("\n")
if (key === ms().acpOfferedKey) return
@@ -609,6 +616,7 @@ const OFFERED_PROBE_RETRY_MS = 60_000
function forgetOffered() {
ms().acpOfferedModels = null
ms().acpOfferedKey = ""
ms().offeredStale = false
ms().offeredProbePromise = null
ms().offeredProbeAt = null
ms().offeredGen++
@@ -684,7 +692,7 @@ async function probeOfferedModels(agyPath) {
}
function probeOfferedOnce(agyPath) {
if (ms().acpOfferedModels || ms().offeredProbePromise) return ms().offeredProbePromise
if ((ms().acpOfferedModels && !ms().offeredStale) || ms().offeredProbePromise) return ms().offeredProbePromise
const now = Date.now()
if (ms().offeredProbeAt !== null && now - ms().offeredProbeAt < OFFERED_PROBE_RETRY_MS) return null
ms().offeredProbeAt = now
@@ -871,6 +879,7 @@ function startingModelCatalog(agyPath) {
if (saved.offered && !ms().acpOfferedModels) {
ms().acpOfferedModels = new Map(saved.offered.map(({ id, name }) => [id, name]))
ms().acpOfferedKey = [...ms().acpOfferedModels.keys()].sort().join("\n")
ms().offeredStale = true
}
// The usage reader names ids on its windows from the catalog being served.
storeCatalogRows(saved.list)
@@ -887,7 +896,15 @@ function useAgyPath(agyPath) {
ms().modelCatalogRefreshPromise = null
}
function listKey(list) {
return list.map(model => model.id).sort().join("\n")
}
function storeListedCatalog(agyPath, list, lastAttemptAt) {
// Another listing (the account changed outside magpie, or its plan did):
// what agy acp offered before is asked again.
const before = ms().cachedModelCatalog
if (before?.agyPath === agyPath && !before.isFallback && listKey(before.list) !== listKey(list)) ms().offeredStale = true
saveCatalog(agyPath, { list })
// The usage reader names ids on its windows from the catalog being served.
storeCatalogRows(list)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-agy-cli-auth",
"version": "0.1.90",
"version": "0.1.91",
"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",
+64 -1
View File
@@ -231,7 +231,8 @@ test("#1064 慢 agy:第一次 models() 给静态目录,后台热身后的第
})
// #1086(yinbing-666):重启后在 agy 再次回答前,也该列出上次的完整目录,而不是只有 Gemini。
test("#1086 重启后第一次 models() 就给上次 agy 列出并开放的目录,坏文件和别的 agy 仍给静态目录", async () => {
// 重启后 agy 回答了也要再探测一次保存的开放型号(shenggxhz),多一次 1.5s 的慢会话,所以给 15s。
test("#1086 重启后第一次 models() 就给上次 agy 列出并开放的目录,坏文件和别的 agy 仍给静态目录", { timeout: 15_000 }, async () => {
const shared = fs.mkdtempSync(path.join(os.tmpdir(), "agy-catalog-saved-"))
try {
const agy = path.join(shared, process.platform === "win32" ? "agy.exe" : "agy")
@@ -254,6 +255,7 @@ test("#1086 重启后第一次 models() 就给上次 agy 列出并开放的目
assert.equal(kit.acpSpawns.length, 0, "agy models 回答前不该起探测会话")
assert.equal(kit.modelsSpawns.length, 1, "保存的目录也要再问一次 agy")
await warmed(kit)
assert.equal(kit.acpSpawns.length, 1, "agy 回答后,保存的开放型号也要再探测一次")
})
// 另一个 agy 可执行文件不用这份目录。
@@ -760,3 +762,64 @@ test("#1229 每个账号列自己开放的型号,互不覆盖", async () => {
assert.ok(kit.acpSpawns.some(spawn => /otheracct1$/.test(spawn.env?.HOME ?? "")), "另一个账号该在自己的 HOME 里探测")
})
})
// shenggxhz (X, 11-17): moved from a Pro account to Ultra, and the agy
// provider still listed no Gemini 4. What agy acp offered the Pro account
// was saved in models.json and believed until a request opened a session,
// so Ultra's fresh `agy models` (Carbon in it) was filtered down to the Pro
// account's offer. A saved offer is asked again once agy answers, and a
// listing that changes asks again too.
const PRO_ROWS = [
["gemini-3.8-flash-high", "Gemini 3.8 Flash (High)"], ["gemini-3.8-flash-low", "Gemini 3.8 Flash (Low)"],
["claude-sonnet-4-6", "Claude Sonnet 4.6"], ["gpt-oss-120b-medium", "GPT-OSS 120B (Medium)"],
]
const PRO_OFFERED = [["gemini-3.8-flash", "Gemini 3.8 Flash"], ["claude-sonnet-4-6", "Claude Sonnet 4.6"], ["gpt-oss-120b-medium", "GPT-OSS 120B (Medium)"]]
const ULTRA_ROWS = [["gemini-4-carbon-high", "Gemini 4 Carbon (High)"], ["gemini-4-carbon-low", "Gemini 4 Carbon (Low)"], ...PRO_ROWS]
const ULTRA_OFFERED = [["gemini-4-carbon-high", "Gemini 4 Carbon (High)"], ["gemini-4-carbon-low", "Gemini 4 Carbon (Low)"], ...PRO_OFFERED]
test("shenggxhz 换到 Ultra 账号后重启:保存的旧开放型号不挡住 Gemini 4,agy 回答后重新探测", async () => {
const shared = fs.mkdtempSync(path.join(os.tmpdir(), "agy-catalog-ultra-"))
try {
const agy = path.join(shared, process.platform === "win32" ? "agy.exe" : "agy")
fs.writeFileSync(agy, "#!/bin/sh\nexit 99\n", { mode: 0o755 })
const env = { XDG_STATE_HOME: path.join(shared, "state") }
await withKit({ agyPath: agy, env, modelsBehavior: { stdout: modelsOutput(PRO_ROWS) }, offeredModels: PRO_OFFERED }, async (kit) => {
await kit.models()
await warmed(kit)
const pro = await kit.models()
assert.ok(pro["claude-sonnet-4-6"])
assert.equal(pro["gemini-4-carbon"], undefined)
})
await withKit({ agyPath: agy, env, modelsBehavior: { stdout: modelsOutput(ULTRA_ROWS) }, offeredModels: ULTRA_OFFERED }, async (kit) => {
await kit.models()
await warmed(kit)
const ultra = await kit.models()
assert.ok(ultra["gemini-4-carbon"], `Ultra 的 Gemini 4 Carbon 没列出:${ids(ultra).join(", ")}`)
assert.equal(kit.acpSpawns.length, 1, "保存的开放型号要在这次运行里再问一次 agy acp")
})
} finally {
fs.rmSync(shared, { recursive: true, force: true })
}
})
test("shenggxhz 运行中换了账号:agy models 列表变了就重新探测开放型号", async () => {
await withKit({ modelsBehavior: { stdout: modelsOutput(PRO_ROWS) }, offeredModels: PRO_OFFERED }, async (kit) => {
await kit.models()
await warmed(kit)
assert.equal((await kit.models())["gemini-4-carbon"], undefined)
assert.equal(kit.acpSpawns.length, 1)
kit.modelsBehavior = { stdout: modelsOutput(ULTRA_ROWS) }
kit.offeredModels = ULTRA_OFFERED
kit.clock.advance(CATALOG_TTL_MS)
await kit.models()
await warmed(kit)
const after = await kit.models()
assert.ok(after["gemini-4-carbon"], `换账号后 Gemini 4 Carbon 没列出:${ids(after).join(", ")}`)
assert.equal(kit.acpSpawns.length, 2, "列表变了该再探测一次")
// 列表没变时不再探测
kit.clock.advance(CATALOG_TTL_MS)
await kit.models()
await warmed(kit)
assert.equal(kit.acpSpawns.length, 2, "列表没变不该再起探测会话")
})
})