Skip to content

[PR] feat: per-client compression status dashboard (#1920) - #1927

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-02_compress-status-dashboard
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-02_compress-status-dashboard

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1920

What

Every client gets a compression status dashboard on its most roomy available surface, all reading ONE proxy-rendered line so numbers never drift between clients:

  • Proxy core — GET /__bili/plugin/status gains an additive stats object plus pre-rendered statusLine.{min,med} (new src/status-line.ts: single canonical renderer — compactTokens, dual-source MAX cache-hit pattern mirrored read-only from the web sessions table, ledger net P&L vs local estimate with ~ mark, nudge growth/step from the kernel decision). min format: bili 11% 96k/869k · saved 1.7M · 35blk · cache 96% (≈60 chars; segments drop out individually when data is absent). Full detail unchanged — /acp panel / acp_status tool / web session page.
  • pi / omp — persistent bottom status bar via ctx.ui.setStatus("billion-context", …) (keyed slot, other extensions untouched), refreshed on turn_end/agent_end and after compaction, cleared synchronously on session start (gen-counter guards an in-flight refresh from resurrecting a stale line after a mid-fetch session switch); hosts without ui.setStatus degrade silently.
  • Claude Code — new bili statusline CLI (src/statusline.ts, dispatched from cli.ts) written into the claude managed settings block as statusLine: {type:"command", command:"<node> <root>/dist/index.js statusline", padding:0}. Origin resolution: explicit --origin/BILI_MCP_PROXY > ANTHROPIC_BASE_URL unwrap (kill switch honored) > claude lane sticky zone port > default 8787. Contract: NEVER fail claude — any error prints an empty line, exit 0. Installer writes statusLine only when absent or bili-owned (isOurStatusLine requires the path separator so lookalikes stay foreign); uninstall removes only bili's entry; a user's own statusLine survives install AND uninstall.
  • opencode V1/V2, dsh, codex/kimi/hermes/zcode, launcher-only clients — documented per-client matrix in CLIENTS.md + CLIENTS.zh-CN.md (on-demand /acp + acp_status + web UI; web-only where there is no plugin/MCP seam).

Deviation from the triage plan (reported per policy)

The Phase-2 "opencode transient toast" was NOT implemented: the opencode plugin API exposes tui.toast.show subscribe-side only — no verified emission API in the V1/V2 plugin context, and the 2.x API surface is explicitly version-unstable (CLIENTS.md caveats). Shipping an unverified emission call would be guesswork; opencode keeps its existing surfaces (/acp, acp_status, web deep link). dsh remains documented-only for the same closed-source reason.

Config surface

Zero new config fields. No new config.json keys, no new BILI_* env vars, no new CLI flags beyond the statusline subcommand itself (which reuses the existing --origin/BILI_MCP_PROXY override channel). The claude managed block gains one machine-owned key (statusLine) under the existing #964 never-clobber-user-config rules; the pi footer uses the host's existing keyed status-slot API. Considered alternatives (per-client rendering, new status config section) rejected: per-client formatting drift is exactly what this issue asks to eliminate, and a new section would collide with the existing compress/providers hierarchy without expressing anything they cannot.

Behavior changes (old → new)

  • /__bili/plugin/status response: purely ADDITIVE (stats, statusLine.*); every pre-existing field byte-identical, phase branches (pre-first-request / chain-advisory / 404) untouched. Existing consumers (web UI, /acp commands, MCP tools) unaffected.
  • New CLI subcommand bili statusline (stdout = one line or empty; always exit 0).
  • bili plugin install/remove claude now manages a statusLine key in ~/.claude/settings.json — foreign values are reported-and-skipped, never overwritten; removal drops only bili's own entry.
  • pi/omp plugins subscribe two more events (turn_end, agent_end) — inert on hosts that don't emit them; no change to any request-path behavior.

Tests

New: tests/status-line.test.ts (renderer: exact formats, min ≤ 60 chars, dual-source MAX, net vs estimate, negative net, nudge breakdown), tests/statusline.test.ts (origin resolution incl. kill switch, runStatusline against a fake proxy, real-spawn CLI smoke: payload→line, no-payload→empty stdout exit 0, dead proxy→empty exit 0), 2 pi footer tests (setStatus called with proxy-rendered min line, dedup, synchronous clear on session start, inert-safe without ui/old proxy), 5 claude managed-block tests (write/absent/refresh/foreign-untouched/strip-ours-only + isOurStatusLine shape matching).

Pre-flight

  • npm run typecheck — clean
  • npm run build — success (dist/index.js carries the new module via cli.ts; no tsup entry change needed)
  • Targeted suite (node --import tsx --test tests/status-line.test.ts tests/statusline.test.ts tests/plugin-agent.test.ts tests/claude-native.test.ts): 126 pass / 0 fail / 8 skipped (skips = live e2e gates, as always)
  • Note: omp identity register failure throttles and retries later (tests/plugin-agent.test.ts:2066) FAILED 4/4 locally early in development but passed on the final run and also fails intermittently on a STASHED clean master baseline — it is a pre-existing timing-sensitive test (500 ms throttle window vs per-iteration latency on this loaded shared machine), not introduced by this diff. CI is the arbiter.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #1927 审查结论(feature #1920 · 每客户端压缩状态看板)

总体判定:代码与数据质量扎实、方向正确、测试有牙。唯一拦合并项 = 分支落后 master 且有合并冲突,需 rebase 到当前 master 并重跑 CI。未合并(合并仅人工)。


结构化七问

  1. 是什么需求:让每个客户端在各自最宽裕的界面(pi/omp 底部栏、claude 原生 statusline、omp TUI)显示统一压缩看板——省了多少 token、缓存命中率、摘要块数、nudge 进度——且多客户端之间数字永不漂移。

  2. 为什么这样设计(根因):此前各客户端要么没有压缩反馈、要么各算各的导致数字不一致,根因是"渲染端各自计算"。本 PR 把数字的唯一权威源收敛到代理(复用 /__bili/plugin/status,增量新增 statusLine.min/med),客户端只打印,从机制上消除漂移。

  3. 怎么实现的(策略层):

    • 新增 src/status-line.ts 作为唯一渲染器;buildStatusLineStats 只读镜像 web 会话表 summaryOf 的双源 MAX 与净收益公式(刻意不调用会 bootstrap/mutate session.metadata 的 getCacheLedger)。
    • bili statusline 子命令(src/statusline.ts)供 claude 原生 statusline 调用,永不失败契约(任何异常 → 空串 exit 0)。
    • claude managed block 在既有 [native] claude: three-mode alignment (proxy / launcher / native plugin) + runtime-info #964 永不覆盖规则下增管 statusLine key(外部值保留、卸载只删自己的);pi/omp 用宿主 keyed slot + 订阅 turn_end/agent_end 刷新底部栏(宿主不发事件则惰性无害)。
    • /__bili/plugin/status 响应纯增量加字段,不动任何请求路径 / wire。
  4. 是否有回归:逐项过既有行为——wire/请求路径未动(纯增量 endpoint 字段);tool-call arguments 未触碰(守 [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039 verbatim 不变量);claude 外部 statusLine 在安装与卸载后均存活(never-clobber 有测试钉住);pi/omp 仅新增 2 个事件订阅,旧 proxy 无 statusLine 时优雅降级。未发现破坏。需处理的只有分支落后 master 的冲突(见判定)。

  5. 是否破坏缓存:不涉及缓存失效策略。看板是只读消费现有 cache-ledger,不写、不清、不改去重键/增量游标;且刻意避开会 mutate metadata 的入口,确保只读路径零副作用。

  6. 是否改设计方向:无转向,反而强化既有边界——代理保持唯一压缩权威,客户端降级为纯展示,数据流单向(proxy → client print),契合 native模式下自动更新问题需要解决 #991/dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196 单一写入方契约精神。

  7. 是否引入新配置:零新增用户配置字段(合规 owner-gated config-surface 纪律)。新增的仅是机器侧 CLI 子命令 bili statusline、claude managed block 内一个机器自管的 statusLine 字段、pi 一个宿主 keyed slot;--origin/BILI_MCP_PROXY 均为既有机制复用。


行为变更披露(policy 要求)

  • /__bili/plugin/status JSON 响应新增 stats + statusLine.{min,med}(additive,旧客户端忽略即可)。
  • 新增 bili statusline 子命令(CLI surface +1)。
  • claude managed block 现在会主动维护 statusLine key(此前不管)。
  • pi/omp 插件新增 2 个事件订阅(turn_end / agent_end)。

审查过程要点

  • ① 方向关:与原 issue triage 方案一致、有 owner 拍板(给每个客户端适配压缩状态看板 #1920 floor 4),单 PR 落地。✓
  • ③ 代码关:逐行核对本地 master 源码——buildStatusLineStats 的字段名、双源 MAX、净收益公式 (S−σ)×requestsAfter − T − σ、hitPct 与 src/web/sessions-data.ts:184–213 逐字节一致;NudgeDecision.breakdown.{growth,nudgeGrowthTokens} 为真实 kernel 键(server.ts:3138/3140);所有被引用函数(detectProxyBase / fetchStatus / lanePreferredPort / nudge 作用域等)均存在且签名匹配。✓
  • ④ 测试有效性:断言有牙——精确渲染字符串、负净收益、read-only(断言 metadata 不被 mutate)、外部 statusLine 存活 + lookalike 拒绝、真实 spawn CLI 冒烟(stdout 逐字节相等 / 空 payload → 空串 exit 0)。能兜住核心行为。
  • ⑤ diff 整洁:单一目的、en/zh 文档同步、无无关 churn。✓

待办 / 建议

需要的话我可以直接执行 rebase 到当前 master 并推回分支。

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。正在把分支 2026-10-02_compress-status-dashboard rebase 到当前 master(ac68a6f6)解决冲突、重推并触发 CI,完成后回报结果。

@ranxianglei
ranxianglei force-pushed the 2026-10-02_compress-status-dashboard branch from 97f6ba0 to 3dda4df Compare October 2, 2026 16:08
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-02_compress-status-dashboard (3dda4df)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1939-pr.1927.690e25a

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1927.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 冲突已解决,分支已 rebase 到当前 master。

  • 分支 2026-10-02_compress-status-dashboard 从旧 base(e60d6cd3)rebase 到当前 master(9c608fc3),新 head 3dda4df4。
  • PR 现 mergeable: true(此前的合并冲突已消除);blocked 仅因必需 CI 尚未跑完。
  • 冲突只落在 src/plugin-install.ts 两处(hook/statusline 命令构造区),其余 11 个文件自动合并干净,无残留冲突标记。

一处需你知晓的语义取舍(非纯机械 rebase):master 的 #1902 把 claude hook 命令的 node 从 process.execPath 改成裸 node(由客户端 shell 走 PATH 解析,为可移植性)。本 PR 早于 #1902,其新增的 statusLineCommand 仍写的是 process.execPath。我按「union of intent」处理:hook 保留 #1902 的裸 node(绝不回退 master 既有行为);statusline 也统一用裸 node——它与 hook 在同一 claude shell 环境执行,应沿用同一可移植规则;若照搬 PR 的 process.execPath,等于把 #1902 刚修掉的「烘焙绝对路径」脆弱性原样带进新路径。对现有 hook 零改动,仅让新 statusline 与之对齐。

CI(新 head 3dda4df4):14 项检查运行中、暂无失败。已绿:real codex / pi / opencode / dsh 四个真实客户端 lane、核心 e2e、version-guard。仍在跑:build、test 矩阵(ubuntu/windows ×22/24)、hermetic registry e2e。全绿后我回报最终结论,届时即可人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿,冲突已消除,PR 现可人工合并。

  • 新 head 3dda4df4(rebase 到当前 master 9c608fc3):14/14 检查全 success、0 失败——build、test 矩阵(ubuntu/windows ×22/24)、核心 e2e、version-guard、hermetic registry e2e(ubuntu+windows)、以及 codex / pi / opencode / dsh 四个真实客户端 lane 全部通过。
  • PR 状态:mergeable: true, state: clean——此前的合并冲突已解决、必需检查全过,具备合并条件。

按仓库规则合并仅人工操作,我不代合。请你在 #1927 点合并即可。

小结:本次仅 rebase + 解决 src/plugin-install.ts 一处语义冲突(statusline 命令沿用 #1902 的裸 node 可移植规则,不回退 hook 既有行为),未改动任何功能逻辑;CI 已验证该取舍安全。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #1920 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

给每个客户端适配压缩状态看板

1 participant