From 6d79228fc111c7298ae2629c051cd54fcd828682 Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Thu, 17 Sep 2026 12:13:32 +0800 Subject: [PATCH] fix(agent): show the idle notice on first opencode v2 /acp before any model request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before the conversation's first model request the proxy knows no ACP session; handlePluginStatus answers that with HTTP 404 {ok:false}. shared.fetchStatus() soft-fails every non-2xx into undefined, so the v2 renderer fell through both the panel and the ok===false branches and printed 'proxy returned no status panel' instead of the friendly idle line. Handle the undefined result explicitly: probe the manifest, and when it answers render 'billion-context@ — proxy connected, no ACP session yet…'; when nothing answers, say the proxy is unreachable. Second-and-later calls were already correct (panel or ok:false path). Same soft-fail contract as v1's inline fetch, without changing the endpoint's wire semantics. --- src/agent/opencode-v2.ts | 8 ++++++++ tests/opencode-v2.test.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/agent/opencode-v2.ts b/src/agent/opencode-v2.ts index ecf496dbb8..7ae0ed6bb8 100644 --- a/src/agent/opencode-v2.ts +++ b/src/agent/opencode-v2.ts @@ -249,6 +249,14 @@ export function createOpencodeV2Setup(options: OpencodeV2SetupOptions = {}): (ct text = version !== undefined ? `billion-context@${version} — proxy connected, no ACP session yet. Send a model request, then run /acp again.` : "bili: no ACP session yet (send a model request first, then run /acp)"; + } else if (!status) { + // fetchStatus soft-fails to undefined both when the proxy 404s an absent or + // never-seen conversation and when the proxy is unreachable. Probe the + // manifest to claim "connected" only when it answers. + const version = await fetchProxyVersion(base).catch(() => undefined); + text = version !== undefined + ? `billion-context@${version} — proxy connected, no ACP session yet. Send a model request, then run /acp again.` + : "bili: cannot reach the bili proxy (run `bili start`, then run /acp again)"; } else { const errText = status?.error; text = typeof errText === "string" && errText.length > 0 diff --git a/tests/opencode-v2.test.ts b/tests/opencode-v2.test.ts index 40427433c7..3661ac5c06 100644 --- a/tests/opencode-v2.test.ts +++ b/tests/opencode-v2.test.ts @@ -43,11 +43,21 @@ function startFakeProxyV2(): Promise<{ origin: string; toolCalls: Array<{ conver return; } if ((req.url ?? "").startsWith("/__bili/plugin/status")) { + if ((req.url ?? "").includes("ses_acp_idle")) { + res.writeHead(404, { "content-type": "application/json" }); + res.end(JSON.stringify({ ok: false, error: "unknown plugin conversation" })); + return; + } res.writeHead(200, { "content-type": "application/json" }); const panel = (req.url ?? "").includes("ses_acp_long") ? "X".repeat(1500) : "ACP-PANEL-OK"; res.end(JSON.stringify({ ok: true, panel })); return; } + if ((req.url ?? "") === "/__bili/plugin/manifest") { + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify({ version: "9.9.9-test" })); + return; + } res.writeHead(404); res.end("{}"); }); @@ -385,6 +395,29 @@ test("v2 setup: /acp reports no proxy detected via synthetic when no proxy", asy }); }); +test("v2 setup: first /acp before any model request shows the idle notice (proxy 404s the conversation)", async () => { + const proxy = await startFakeProxyV2(); + const fake = makeFakeCtx(); + try { + await withEnv({ BILLION_CONTEXT_PROXY: proxy.origin, BILLION_CONTEXT_PLUGIN: undefined }, async () => { + const cleanup = await biliOpencodePlugin.setup(fake.ctx as never); + try { + const acp = fake.addedCommands.find((c) => c.name === "acp")!; + await acp.execute({ sessionID: "ses_acp_idle" }); + await until(() => fake.syntheticCalls.length === 1); + assert.match(fake.syntheticCalls[0].description!, /billion-context@9\.9\.9-test \u2014 proxy connected, no ACP session yet/); + assert.match(fake.syntheticCalls[0].text, /not an instruction/); + assert.equal(fake.syntheticCalls[0].resume, false); + } finally { + cleanup(); + } + }); + } finally { + await proxy.close(); + } +}); + + test("v2 setup: /acp truncates long panels to the TUI notice cap", async () => { const proxy = await startFakeProxyV2(); const fake = makeFakeCtx();