From 0356f4bb6daea05466a3740fb73caf692c587700 Mon Sep 17 00:00:00 2001 From: wxy <2398249916@qq.com> Date: Wed, 21 Oct 2026 08:47:53 +0800 Subject: [PATCH 1/2] feat(pi): fold ACP block details with Ctrl+O (#4064) --- src/agent/pi.ts | 34 ++++++++++++++++++++++++++++ tests/plugin-agent.test.ts | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/agent/pi.ts b/src/agent/pi.ts index d6d6c931b0..f8feb71038 100644 --- a/src/agent/pi.ts +++ b/src/agent/pi.ts @@ -5,6 +5,8 @@ // minimal structural declarations — the bundled artifact imports NOTHING // from the host at runtime (the host duck-types us in). +import type { MessageRenderer } from "@earendil-works/pi-coding-agent"; +import { Box, Markdown, Spacer, Text } from "@earendil-works/pi-tui"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -76,6 +78,7 @@ type ExtensionAPI = { on: (event: string, handler: (event: never, ctx: Ctx) => unknown) => void; registerTool: (tool: ToolDefinition) => void; registerCommand?: (name: string, options: { description?: string; handler: (args: string, ctx: CommandCtx) => void | Promise }) => void; + registerMessageRenderer?: (customType: string, renderer: MessageRenderer) => void; // #2186: acp_delegate (inlined from billion-context-pi-subagents) injects // completion notifications through the host's persistent transcript // channel; optional because older hosts and non-pi hosts lack it. @@ -1035,6 +1038,37 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM pi.on("session_start", (_event, ctx) => repin(ctx)); pi.on("session_switch", (_event, ctx) => repin(ctx)); } + if (agent === "pi" && typeof pi.registerMessageRenderer === "function") { + pi.registerMessageRenderer("bili-acp-status", (message, { expanded, outputPad }, theme) => { + if (expanded) return undefined; + const text = typeof message.content === "string" ? message.content + : message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n"); + const lines = text.split("\n"); + const collapsed = lines.filter((line) => !/^ \[b\d+\] T\d+ /.test(line)); + if (collapsed.length === lines.length) return undefined; + const box = new Box(outputPad ?? 1, 1, (line) => theme.bg("customMessageBg", line)); + box.addChild(new Text(theme.fg("customMessageLabel", "\x1b[1m[bili-acp-status]\x1b[22m"), 0, 0)); + box.addChild(new Spacer(1)); + box.addChild(new Markdown(collapsed.join("\n"), 0, 0, { + heading: (value) => theme.fg("mdHeading", value), + link: (value) => theme.fg("mdLink", value), + linkUrl: (value) => theme.fg("mdLinkUrl", value), + code: (value) => theme.fg("mdCode", value), + codeBlock: (value) => theme.fg("mdCodeBlock", value), + codeBlockBorder: (value) => theme.fg("mdCodeBlockBorder", value), + quote: (value) => theme.fg("mdQuote", value), + quoteBorder: (value) => theme.fg("mdQuoteBorder", value), + hr: (value) => theme.fg("mdHr", value), + listBullet: (value) => theme.fg("mdListBullet", value), + bold: (value) => theme.bold(value), + italic: (value) => theme.italic(value), + underline: (value) => theme.underline(value), + strikethrough: (value) => theme.strikethrough(value), + }, { color: (value) => theme.fg("customMessageText", value) })); + box.addChild(new Text(theme.fg("dim", "Ctrl+O to expand full ACP report"), 0, 0)); + return box; + }); + } if (typeof pi.registerCommand === "function") { pi.registerCommand("acp", { description: "Show ACP context-compression status for this session", diff --git a/tests/plugin-agent.test.ts b/tests/plugin-agent.test.ts index a97be2de14..9985cc153d 100644 --- a/tests/plugin-agent.test.ts +++ b/tests/plugin-agent.test.ts @@ -1513,6 +1513,52 @@ test("/acp emits a persistent custom message via pi.sendMessage when available ( } }); +test("/acp renderer collapses large reports and restores every block when expanded", () => { + type Renderer = NonNullable>[0]["registerMessageRenderer"]>; + let render: Parameters[1] | undefined; + biliPlugin({ on() {}, registerTool() {}, registerMessageRenderer: (name, renderer) => { + assert.equal(name, "bili-acp-status"); + render = renderer; + } }); + assert.ok(render, "register a renderer so Ctrl+O can control the report"); + const text = ["╭─────────────────────────────────────────────╮", "│ ACP Context Analysis │", + "╰─────────────────────────────────────────────╯", "billion-context@0.1.202", "storage: full", "", + "Context (session accounting): 50%", "", "Sent to LLM (after compression, est.): 50k", + "Prompt cache (provider-reported): 90%", "", "Blocks: 250 active / 250 total", + ...Array.from({ length: 250 }, (_, i) => ` [b${i}] T1 10k→1k: topic ${i}`), + "Web UI: http://127.0.0.1:8787/__bili/", "Tag visibility: footer"].join("\n"); + const message = { role: "custom" as const, customType: "bili-acp-status", content: text, display: true, timestamp: 0 }; + const backgrounds: string[] = []; + const theme = { + fg: (_color: string, value: string) => value, + bg: (color: string, value: string) => { backgrounds.push(color); return value; }, + bold: (value: string) => value, + italic: (value: string) => value, + underline: (value: string) => value, + strikethrough: (value: string) => value, + } as Parameters[2]; + const collapsed = render(message, { expanded: false, outputPad: 1 }, theme)!.render(120).join("\n"); + assert.ok(collapsed.split("\n").length < 25); + assert.match(collapsed, /╭─/); + assert.match(collapsed, /ACP Context Analysis/); + assert.match(collapsed, /storage: full/); + assert.match(collapsed, /storage: full[^\n]*\n\s*\n/); + assert.match(collapsed, /Tag visibility: footer/); + assert.match(collapsed, /Blocks: 250 active/); + assert.match(collapsed, /Context .*50%/); + assert.match(collapsed, /Prompt cache .*90%/); + assert.match(collapsed, /Web UI:/); + assert.match(collapsed, /Ctrl\+O/); + assert.ok(!collapsed.includes("topic 249")); + assert.match(collapsed, /\[bili-acp-status\]/); + assert.ok(backgrounds.length > 0 && backgrounds.every((color) => color === "customMessageBg")); + assert.equal(render(message, { expanded: true, outputPad: 1 }, theme), undefined, + "expanded reports use pi's original styled Markdown renderer"); + assert.equal(message.content, text, "display folding must preserve persisted report content"); + assert.equal(render({ ...message, content: "Context: 0%\n\nBlocks: none" }, { expanded: false, outputPad: 1 }, theme), + undefined, "reports without block details keep pi's original renderer"); +}); + test("/acp sends renderAcpStatus fallback content via sendMessage when no panel string", async () => { const server = http.createServer((req, res) => { if (req.url?.startsWith("/__bili/plugin/status")) { From a7c4cfbf4ad7753da6a9b28f95d11cf838f27006 Mon Sep 17 00:00:00 2001 From: awork Date: Wed, 21 Oct 2026 09:03:16 +0800 Subject: [PATCH 2/2] docs(pi): note kernel-owned block-line shape behind /acp folding (#4064) --- src/agent/pi.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/agent/pi.ts b/src/agent/pi.ts index f8feb71038..251a86a613 100644 --- a/src/agent/pi.ts +++ b/src/agent/pi.ts @@ -1044,6 +1044,8 @@ export function createBiliPlugin(agentOverride?: string, opts?: { retryIntervalM const text = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n"); const lines = text.split("\n"); + // Block-detail line shape is owned by the kernel's buildStatusPanel + // (kernel/src/panel/panel.ts); if it ever changes, folding degrades to full display. const collapsed = lines.filter((line) => !/^ \[b\d+\] T\d+ /.test(line)); if (collapsed.length === lines.length) return undefined; const box = new Box(outputPad ?? 1, 1, (line) => theme.bg("customMessageBg", line));