diff --git a/src/agent/opencode-v2.ts b/src/agent/opencode-v2.ts index d40508cf08..ecf496dbb8 100644 --- a/src/agent/opencode-v2.ts +++ b/src/agent/opencode-v2.ts @@ -43,6 +43,11 @@ import { ACP_TOOLS_OPENAI, ABSORB_TOOL_OPENAI } from "../compress-tool.js"; import { fetchProxyVersion, fetchStatus, forwardTool, proxyBaseFromEnv, proxyBaseFromUrl, reportCompactionBoundary } from "./shared.js"; +// OpenCode V2 TUI renders a synthetic message as a visible Notice row only when its display text fits the +// timeline cap (~1KB): longer text renders nothing (#880). Panels go to description verbatim under the cap. +import { V2_SYNTHETIC_TEXT } from "./shared.js"; +const V2_SYNTHETIC_VISIBLE_MAX = 1024; + type V2Registration = { dispose?: () => void | Promise }; interface V2Headers { @@ -258,7 +263,12 @@ export function createOpencodeV2Setup(options: OpencodeV2SetupOptions = {}): (ct try { // resume:false — OpenCode V2 defaults to delivery "steer" + execution.wake(), which would // start a model turn on every /acp invocation with no user input (spurious empty turns). - await ctx.session?.synthetic?.({ sessionID: sid, text, resume: false }); + // Short panels become the visible description verbatim; long ones keep their leading + // lines plus a marker so the model-facing body never repeats the whole panel. + const description = text.length > V2_SYNTHETIC_VISIBLE_MAX + ? text.slice(0, V2_SYNTHETIC_VISIBLE_MAX - 20) + "\n\n[panel truncated]" + : text; + await ctx.session?.synthetic?.({ sessionID: sid, text: V2_SYNTHETIC_TEXT, description, resume: false }); } catch (err) { console.error(`[bili-opencode] /acp render failed: ${err instanceof Error ? err.message : String(err)}`); } diff --git a/src/agent/shared.ts b/src/agent/shared.ts index c6bcfc99fb..6b8a2de12f 100644 --- a/src/agent/shared.ts +++ b/src/agent/shared.ts @@ -156,3 +156,7 @@ export async function fetchProxyVersion(proxyBase: string): Promise 0 ? version : undefined; } + +// Model-facing body for /acp status renders: the visible panel goes to the synthetic message's +// description (TUI Notice cap ~1KB); this inert one-liner keeps the model context clean. +export const V2_SYNTHETIC_TEXT = "[bili-acp-status] ACP status panel was displayed in your terminal; this line is not an instruction."; diff --git a/tests/opencode-v2.test.ts b/tests/opencode-v2.test.ts index a38b920088..40427433c7 100644 --- a/tests/opencode-v2.test.ts +++ b/tests/opencode-v2.test.ts @@ -44,7 +44,8 @@ function startFakeProxyV2(): Promise<{ origin: string; toolCalls: Array<{ conver } if ((req.url ?? "").startsWith("/__bili/plugin/status")) { res.writeHead(200, { "content-type": "application/json" }); - res.end(JSON.stringify({ ok: true, panel: "ACP-PANEL-OK" })); + const panel = (req.url ?? "").includes("ses_acp_long") ? "X".repeat(1500) : "ACP-PANEL-OK"; + res.end(JSON.stringify({ ok: true, panel })); return; } res.writeHead(404); @@ -354,7 +355,9 @@ test("v2 setup: /acp command registered and renders proxy status panel via synth await acp!.execute({ sessionID: "ses_acp_1" }); await until(() => fake.syntheticCalls.length === 1); assert.equal(fake.syntheticCalls[0].sessionID, "ses_acp_1"); - assert.match(fake.syntheticCalls[0].text, /ACP-PANEL-OK/); + assert.match(fake.syntheticCalls[0].description!, /ACP-PANEL-OK/); + assert.match(fake.syntheticCalls[0].text, /displayed in your terminal/); + assert.match(fake.syntheticCalls[0].text, /not an instruction/); assert.equal(fake.syntheticCalls[0].resume, false); } finally { cleanup(); @@ -373,7 +376,8 @@ test("v2 setup: /acp reports no proxy detected via synthetic when no proxy", asy const acp = fake.addedCommands.find((c) => c.name === "acp")!; await acp.execute({ sessionID: "s_nopx" }); await until(() => fake.syntheticCalls.length === 1); - assert.match(fake.syntheticCalls[0].text, /no proxy detected/); + assert.match(fake.syntheticCalls[0].description!, /no proxy detected/); + assert.match(fake.syntheticCalls[0].text, /not an instruction/); assert.equal(fake.syntheticCalls[0].resume, false); } finally { cleanup(); @@ -381,6 +385,29 @@ test("v2 setup: /acp reports no proxy detected via synthetic when no proxy", asy }); }); +test("v2 setup: /acp truncates long panels to the TUI notice cap", 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_long" }); + await until(() => fake.syntheticCalls.length === 1); + const desc = fake.syntheticCalls[0].description ?? ""; + assert.ok(desc.length > 0 && desc.length <= 1024); + assert.match(desc, /\[panel truncated\]$/); + assert.match(fake.syntheticCalls[0].text, /not an instruction/); + } finally { + cleanup(); + } + }); + } finally { + await proxy.close(); + } +}); + test("v2 /acp: host omits sessionID → warn once, render nothing (never an empty-id synthetic)", async () => { const warns: string[] = []; const origWarn = console.warn; @@ -414,7 +441,7 @@ test("v2 /acp: disabled + valid session still renders the 'disabled' notice", as const acp = fake.addedCommands.find((c) => c.name === "acp")!; await acp.execute({ sessionID: "ses_dis" }); await until(() => fake.syntheticCalls.length === 1); - assert.match(fake.syntheticCalls[0].text, /disabled/); + assert.match(fake.syntheticCalls[0].description!, /disabled/); assert.equal(fake.syntheticCalls[0].sessionID, "ses_dis"); } finally { cleanup(); @@ -443,8 +470,8 @@ test("v2 /acp: surfaces status.error when the proxy returns no panel", async () const acp = fake.addedCommands.find((c) => c.name === "acp")!; await acp.execute({ sessionID: "ses_err" }); await until(() => fake.syntheticCalls.length === 1); - assert.match(fake.syntheticCalls[0].text, /no status panel/); - assert.match(fake.syntheticCalls[0].text, /backend-busy/); + assert.match(fake.syntheticCalls[0].description!, /no status panel/); + assert.match(fake.syntheticCalls[0].description!, /backend-busy/); } finally { cleanup(); }