agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)

On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.

What changed:
- packages/agy-cli/index.mjs:
  - The offered-model probe now starts in listAgyModels' .then, as soon as
    a non-empty list arrives and a caller asked for probeOffered. It no
    longer waits for the next models() call. A hung or failed `agy models`
    still never spawns the probe.
  - probeSignedIn reuses the `agy models` stdout it already has. The same
    parser (parseAgyModels, split out of listAgyModels) fills
    cachedModelCatalog, and the probe starts. Sign-in waits for the probe
    for at most 3s.
  - The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
    in-flight probe) is forgotten when agyPath changes and after a new
    sign-in finishes. A generation counter drops the answer of a probe
    that started before the reset.
  - provider.warming() returns a promise while a list or probe is still
    running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
  packages/*/opencode2.mjs: after the first background refresh, the
  adapter awaits hooks.provider.warming() once, for at most 60s, and then
  refreshes once more. It does not loop. Plugins without warming() behave
  as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.

Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.

Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
  GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
  runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
  about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.

Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.

Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
  copy-identity check.

Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.

Reported-by: hiee3
This commit is contained in:
yetone
2026-11-13 10:59:13 +08:00
parent 89a54951cc
commit 0135b7b0ea
49 changed files with 1356 additions and 74 deletions
+60
View File
@@ -271,3 +271,63 @@ test("a 1.x code sign-in is a 2.x code sign-in", async () => {
const again = await f.methods[0].authorize({})
await expect(again.callback("bad")).rejects.toThrow()
})
// a plugin whose first list is its static one while it reads the real one
// in the background (agy-cli, plugins#1064): 2.x reads provider.models once
// at startup, so the adapter reads it once more when provider.warming()
// ends, and only once
function slow(state) {
return {
SlowPlugin: async () => ({
auth: { provider: "slow", methods: [{ type: "api", label: "Slow key" }] },
config: async (cfg) => {
cfg.provider.slow = { npm: "@ai-sdk/openai-compatible", name: "Slow", models: { m1: { name: "M1" } } }
},
provider: {
id: "slow",
warming: () => state.warming(),
models: async () => {
state.reads++
return state.ready ? { full: { name: "Full" } } : { stub: { name: "Stub" } }
},
},
}),
}
}
test("a list still warming when 2.x first reads it is read once more when it ends (plugins#1064)", async () => {
const { setup } = await import(join(packages, "agy-cli", "opencode2.mjs"))
let release
const state = { reads: 0, ready: false, warmings: 0 }
state.warming = () => {
state.warmings++
return state.ready ? null : new Promise((r) => (release = r))
}
const f = fakeContext()
f.conns.set("slow", { connection: { type: "credential", id: "cred_1" }, value: { type: "key", key: "sk" } })
const stop = await setup(f.ctx, slow(state))
await until(() => f.reloads.model === 1 && !!release)
expect(f.providers()[0].models.map((m) => m.name)).toEqual(["Stub"])
expect(state.reads).toBe(1)
state.ready = true
release(true)
await until(() => f.reloads.model === 2)
expect(f.providers()[0].models.map((m) => m.name)).toEqual(["Full"])
// once: the second read doesn't ask again, so nothing loops
await new Promise((r) => setTimeout(r, 20))
expect(state.reads).toBe(2)
expect(state.warmings).toBe(1)
stop()
})
test("a plugin with nothing warming is read once at startup", async () => {
const { setup } = await import(join(packages, "agy-cli", "opencode2.mjs"))
const state = { reads: 0, ready: true, warming: () => null }
const f = fakeContext()
f.conns.set("slow", { connection: { type: "credential", id: "cred_1" }, value: { type: "key", key: "sk" } })
const stop = await setup(f.ctx, slow(state))
await until(() => f.reloads.model === 1)
await new Promise((r) => setTimeout(r, 20))
expect(state.reads).toBe(1)
stop()
})