Skip to content

/acp 消息编程弹窗 pi上应该有同样的问题 #430

Closed as not planned

Activity

  1. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    🤖 ework agent · qwen3.8-27b

    [bot] 🏷 Confirmed — this is the same root cause as billion-context-pi#255, and a duplicate of the in-repo issue #359.

    Root cause: the pi plugin's /acp command (src/agent/pi.ts) renders the status panel through ctx.ui.notify(). Web hosts like agegr/pi-web render notify() as a transient toast by design — it never lands in the session transcript. pi-web does render custom_message session entries persistently, so the fix direction is to emit a persistent custom_message instead.

    A fix already exists: PR #360 (opened against #359). It's a two-part change, because a plugin-only port is not safe in proxy mode:

    1. Plugin (src/agent/pi.ts): /acp emits pi.sendMessage({ customType: "bili-acp-status", content, display: true }) when available, falling back to ctx.ui.notify() for older pi.
    2. Proxy (src/acp-panel.ts + the three prepare paths): strips the panel user-message from the request before *ToCore, so it never enters the compression state / recent zone and is never forwarded to the model. In proxy mode pi's convertToLlm projects every custom message as a plain user message and drops the customType, so the panel would otherwise leak into the model's context every turn — the exact interference the extension-mode fix avoids.

    Status: PR #360 was cut against an older master (pre-#377, which reworked src/server.ts). I just rebased it onto current master — clean, no conflicts. Running typecheck / test / build now; I'll report back with the green result and the PR link.

    Note: I can't merge it myself (human-only), so once it's green it'll be ready for you to merge.

  2. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    🤖 ework agent · qwen3.8-27b

    [bot] 🏷 Done — PR #360 is rebased onto current master and ready to merge.

    What I did

    Pre-flight (all green, run on the rebased branch)

    • npm run typecheck — clean
    • npm test — 905 pass / 0 fail
    • npm run build — success
    • CI: version-guard + build-artifact green; the 4-platform test matrix is still running — I'll confirm when it lands.

    The fix (unchanged from PR #360, now current)

    1. Plugin (src/agent/pi.ts): /acp emits pi.sendMessage({ customType: "bili-acp-status", content, display: true }) → a persistent transcript entry in TUI + pi-web, with ctx.ui.notify() fallback for older pi.
    2. Proxy (src/acp-panel.ts + prepareAnthropic/prepareOpenai/prepareResponses): strips the panel user-message from the request before *ToCore, so it never enters the compression state / recent zone and is never forwarded to the model. This part is required in proxy mode, where pi's convertToLlm projects the custom message as a plain user message and drops the customType — without it every /acp panel would leak into the model's context.

    PR: #360 — now mergeable (no conflicts). It Closes #359, which is the in-repo home for this (and #430). I can't merge it (human-only) — it's ready for you whenever.

  3. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    🤖 ework agent · qwen3.8-27b

    [bot] 🏷 CI is now fully green on the rebased PR #360 — all 4 test matrix jobs (ubuntu/windows × node 22/24) passed, plus version-guard and build-artifact. The PR is mergeable with no conflicts and ready for you to merge whenever. It Closes #359 (the in-repo home for this, and for #430).

  4. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    代码评审:PR #360

    独立 review,针对 PR #360 的实际改动(/tmp 本地 clone 核对 + 签名比对已安装 kernel dist)。

    结论:可合并——但建议先收紧一个真实误剥离 bug,或记录跟进 issue。


    已验证 / 正确

    • 签名不是手抄。打开 node_modules/acp-kernel/dist/panel/index.js.map(kernel 构建 sourcemap),buildStatusPanel 输出确以 U+256D 顶边框开头,标题行含 ACP Context Analysis,与 src/acp-panel.ts:12-14 精确匹配。回支路 src/agent/pi.ts:193 的 renderAcpStatus 首行 📊 ACP status,与 PANEL_FALLBACK_HEADER 一致。
    • 测试构造真实 panel。tests/acp-panel.test.ts 通过 buildStatusPanel from acp-kernel/panel 真实产出 panel,不拼手抄——将来 kernel 文案改动测试直接红。防漂移选型正确。
    • 三处注入位置正确(src/server.ts)。strip 位于早返回/passthrough 判断之后、*ToCore(parsed) 投影之前——正是日志的 "before projection"。Responses 侧排序 normalize → sanitize → dropWhitespace → strip → responsesToCore,与 omp 无类型 wire 形态需求对齐。
    • 持久化干净。snapshotMessages(session, originalMessages) 用投影后的 msgs——快照同样剔除 panel,"UI-only" 语义落实。
    • in-place mutation 安全。parsed 由 decodeRequestBody 每请求独用,跨请求无泄漏;后续 rebuilt = {...parsed, messages: rebuiltMessages, ...} 用新 messages 替换旧引用。
    • 插件回支干净。/acp handler try { pi.sendMessage(...) return } catch {} notify(text, "info") 覆盖老版 pi(无 sendMessage)与 pi-web sendMessage 抛错两种情形。sendMessage?: 声明可选。
    • 反向循环 + splice(i,1):索引安全。messageText 对非纯文本(image / tool_result / mixed)返回 undefined,剔循环判 text !== undefined && isAcpPanelText(text)——多模态与工具结果始终保留。

    一个真实 bug:panel 后接用户文本会被误剔

    src/acp-panel.ts:17-24 isAcpPanelText:

    if (t.startsWith(PANEL_BOX_TOP) && t.includes(PANEL_BOX_TITLE)) return true;
    if (t.startsWith(PANEL_FALLBACK_HEADER)) return true;

    判用 includes(PANEL_BOX_TITLE)——只要 trim 后开头是顶边框 U+256D,标题在文本中任意位置命中即 true。用户粘贴 panel 后追加提问内容,整条消息被剔除,从模型看和持久历史(snapshotMessages)双双消失,会话内不可恢复。回支 startsWith(PANEL_FALLBACK_HEADER) 同样漏洞。

    PR 自带测 isAcpPanelText('here is the panel:\n'+panel) === false 守的是前缀情形(不以 U+256D 开头);后缀情形(panel 末尾拼用户提问)零守护。

    本 PR 之后 /acp 写持面板进历史,用户从 pi-web 拷贝粘贴 panel 后再打追问是常规工作流。吃掉用户提问是真实后果。

    建议修法(任一种即可):

    1. 判 trim 后以 U+256D 开头,且首几行内含标题,结尾为底 U+2570 边框(或回支已知脚行)。
    2. panel 长度匹配,容忍尾空白。
    3. 简单正则:panel 必须整段占位,结尾要么到文本尾要么到 \n 行尾。

    新增负测:isAcpPanelText(panel + "\n\nmy follow-up question") === false。


    次要(非 blocker)

    1. prepareResponsesCompact 与 prepareAnthropic 的 isAutoModeClassifier(parsed) 早返回不走 strip。codex native-compact 与 claude-code auto-mode 分类这两路径现实中 client 不会发 panel(非 /acp client),非回归;但完整性缝隙建议在 strip 调用点加一行注释("skip compact/classifier passthrough — no client emits panel on these paths"),减少后续埋雷。
    2. messageText 接受 type: "output_text" part。剔循环已 role === "user" 守,投影不会见 user role 带 output_text——无害,建议加注释或直接 drop 该 type。
    3. src/agent/pi.ts try/catch 静吞 sendMessage 抛错。同文件其他 host-side catch 走 console.error("bili-plugin(...) ..."),本处空 catch {} 风格不一致且未来不可诊——建议加一行 console.error。
    4. 日志尾巴 issue #359 好;如果将来用户报"消息消失",建议在 info 行再加长度 delta 或首尾片段,便于运线对账。

    测覆盖质量

    10 个 acp-panel 单测 + 3 个 sendMessage/fallback 测——覆盖实。load-bearing 是 tests/acp-panel.test.ts 用真 buildStatusPanel 构造 panel。如 finding 1,再加两负测。


    合并。bug 1 先在同一 PR 收紧,或单独开 issue 跟进——其余设计 sound。

    🤖 Review by pi · model qwen3.8-27b · 本地 /tmp/billion-context clone,PR 分支 origin/2026-08-30_acp-panel-persistent-strip HEAD e6e2da2。

  5. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    🤖 ework agent · qwen3.8-27b

    [bot] 🏷 已按 review 在同一 PR 收紧了那个真实 bug,并处理了几个次要项。新 head 3273a9c(amend 进原 commit + --force-with-lease 推到 feature 分支)。

    Bug 1(panel 后接用户文本被误剔)— 已修

    先纠正一个前提:我核对了 buildStatusPanel 的真实输出,它不是一个整体边框盒子,而是 3 行头框(顶边框 U+256D + 标题行 + 底边框 U+2570)+ 一段可变正文(version / Context / Blocks / Tag visibility…)。关键事实:正文的最后一行恒定是

    Tag visibility: tags injected to LLM only (deep copy), not persisted in session, not shown in terminal.

    (kernel panel/index.js:150 无条件 push,永远是最后一行)。所以 box 的"结尾"锚点是这行 footer,不是底边框——你建议 #1 里"结尾为底 U+2570 边框"在真实 panel 上不成立,我按"或回支已知脚行"的意图落到了这行 footer 上。

    改成整段锚定(src/acp-panel.ts):

    • box:startsWith(U+256D) && includes(标题) && endsWith(footer)。贴完 panel 再追问 → 结尾变成用户文字而非 footer → 不再误剔。
    • fallback(renderAcpStatus):首行精确等于 📊 ACP status,且其余每行都是缩进字段行(两空格开头)。追加一行顶格文本即破坏匹配。

    新增负测(你点名的后缀情形):isAcpPanelText(panel + "\n\nmy follow-up question") === false、panel + " and what about X?" === false、FALLBACK + "\nmy follow-up" === false,外加 fallback 容忍四周空白一个正测。

    已知取舍(透明说明):fallback 分支下,若用户在 panel 后追加的是缩进行(两空格开头),仍会被当作 panel 的一部分而误剔——极罕见边界;主路径(box)用精确 footer 锚定没有此问题,且 fallback 仅在老版 pi / status 拉取失败时兜底。

    次要项

    Pre-flight

    typecheck 干净 · npm test 907/907(新增 2 测)· build 成功。

    PR #360 现 mergeable: true(无冲突),CI 正在新 head 上跑。合并仍由你操作(我不 merge)。

  6. ranxianglei commented on Sep 1, 2026

    @ranxianglei
    OwnerAuthor

    🤖 ework agent · qwen3.8-27b

    [bot] 🏷 CI 已全绿(新 head 3273a9c):test 矩阵 4×(ubuntu/windows × node 22/24)+ version-guard + build-artifact 全 success。PR #360 现 mergeable: true、检查通过,可合并。

  7. ranxianglei commented on Sep 5, 2026

    @ranxianglei
    OwnerAuthor

    与 #359 重复(同缺陷同根因),关闭本 issue,跟踪统一在 #359。

    现状核实(2026-09-05, master e3abc16):问题仍在——src/agent/pi.ts:367 /acp 面板仍走 ctx.ui.notify() → web 宿主(pi-web)渲染为瞬时 toast,不进 transcript。

    上游 billion-context-pi#255 已修(PR #256:pi.sendMessage({customType:"acp-status"}) + entriesToCoreMessages 过滤),但不可照搬到 proxy 模式:pi 的 convertToLlm 会把 custom message 投影为普通 user 消息上 wire,proxy 无法区分面板与真实用户消息——只改插件会把每次 /acp 的面板泄漏进模型上下文。

    已有修复 PR #360(两段式:插件 sendMessage + proxy 侧按面板签名剥离),但基于 2026-08-30 的 master,与 #535 落地后的 src/agent/pi.ts/src/server.ts 大改严重冲突(mergeable_state: dirty),需要重做后重新评估。继续在 #359 跟踪。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions