Repository navigation
[PR] feat: dsh client Context tab with accurate post-compression stats (#3862) - #3886
Conversation
#3862) Host-side meters (dsh-context and kin) anchor on dsh's local event stream, which never sees bili's folds, so their bars stay on the pre-compression caliber forever (dsh-context#173). bili knows the exact post-fold sent bytes, so it publishes them two ways: - GET /__bili/plugin/status gains an additive contextView field: the machine-readable twin of the /acp panel breakdown (sentTotal vs limit, category segments mirroring buildStatusPanel math exactly, the usage-grade anchor from displayContextBest on its own labeled scale, fold/switch trails mapped from the cache ledger). The route echoes access-control-allow-origin for origins the existing trusted-origin gate already admitted, so a cross-origin browser reader can consume it; the gate itself is untouched, no access widening. - The dsh native plugin registers a session-scoped Context tab (conversation.view slot, id bili-context) rendering that view with plain React from dsh's own runtime (no iframe, no new dependencies): stacked bar, legend, events list, 10s poll, honest degraded/stale/waiting states, open-Web-UI escape hatch.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4611-pr.3886.28e14fcThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3886.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。本 PR 是实现 #3862(dsh 客户端 Context 标签页 + 标签: dsh + scope/ui + p3(新增功能,dsh 客户端界面域,非缺陷故不打 bug;p3 = 功能类无用户损害)。 当前状态(初审):
|
The five ContextView* shapes and ModelSwitchStats are consumed structurally (buildContextView's return value / cache-ledger internals); nothing outside their own files names them, so the #1440 P6 gate flags them as INTERNAL_ONLY. Drop the leading export keyword only - no behavior change. The remaining local gate hit (src/log-mask.ts maskUrlForPublish) is pre-existing master drift tracked by #3870 with fixes in flight (#3871/#3887); deliberately not bundled here.
The #1357 chain-advisory response carries a panel string exactly like the stale-running-build case, so the Context tab's degraded ladder misdiagnosed it as 'the running proxy predates this install — restart fixes it' when the real state is simply 'no session exists yet for this conversation'. The phase check routes it to the neutral not-yet notice; adds the negative test row pinning both directions.
Stray leading space before the closing brace of an unrelated test (#3100 embed pre-flight, tests/dsh-settings-ui.test.ts) and in CLIENTS.md (trailing-space blank line plus a leading space before the Kimi Code heading) — none of it related to the feature; keeps every diff line on-purpose.
(ai: vllm-qwen/qwen3.8-27b) Review 完成,已在分支上补了 2 个修复 commit 并推送( 1. 是什么问题:功能 PR(#3862)——dsh 客户端新增会话级 Context 标签页, 2. 什么原因导致的:红门分两层——①PR 自己引入 6 个类型导出(context-view.ts 五个接口 + cache-ledger.ts 的 ModelSwitchStats)在仓库内无任何跨文件引用,触发 unused-exports 门禁;②docs-sync 失败是 master 既有漂移(CONFIGURATION.md 两行被 #3788/#3818 取代的过期行),与本 PR 无关,#3871/#3887 两个在途 PR 已认领。另:审查中发现一个 PR 自身的准确性缺陷——#1357 的 chain-advisory 响应和「旧版代理」响应一样带 panel 字符串,Context 标签页的降级阶梯会把「该会话还没有本地 session」误诊成「运行中的 bili 比安装配置旧,重启即可」。 3. 影响范围与严重程度:功能面=dsh 客户端用户多一个标签页、status 路由消费方多一个字段;CORS 回显只作用于已通过既有管理门禁(loopback + trusted-origin + anti-tunnel,admin.ts:189-206)的 origin。无用户损害(p3 功能类);CI 红曾阻塞合并。chain-advisory 误诊是边缘态下的 UX 文案错误(提示用户无谓重启),已修。 4. 怎么修复的:①6 个导出的修法(去掉 leading export,保留定义处命名,消费方经 5. 是否有回归问题:逐项过完触碰路径的既有行为——status 响应:纯增量字段,早退路径(chain-advisory/pre-first-request)不带该字段(JSON 省略),消费方按可选处理即可;集成测试逐字段断言既有字段仍在; 6. 是否破坏缓存:不涉及。未触碰缓存/重试/游标/去重逻辑; 7. 是否改了设计方向:不转向。全部沿用既有模式:#3100 的 ACAO 回显先例、cache-report 的按需报告构建、slots.inject 注册、原生 DOM(owner 指令)。 8. 是否引入了新的配置:不涉及。无新 env/config key/CLI flag(PR 正文 config-surface: none,核实属实)。 有意行为变更披露(旧→新 + 原因):
CI 现状与合并判定:推送后本分支 判定:代码审查通过,可合——唯一前置是 #3871/#3887 落 master 后 rebase 让静态门禁转绿(合并动作留给人,我不代合)。 |
#3811 exported it, but its only reference is maskUrlsForPublish in the same file (INTERNAL_ONLY), which has kept the master unused-exports lane red. Drop the export keyword instead of deleting: the function is live internal code.
Committed CONFIGURATION.md/CONFIGURATION.zh-CN.md carried both the pre-#3818 'unset (shadow)' storage.unified row and the pre-#3788 sqliteAutoDownload row alongside their replacements, so docs-sync's git-diff-after-generate could never be clean. Regenerated from the current seeds; the diff removes exactly those four stale rows.
(ai: vllm-qwen/qwen3.8-27b) CI 红已修复并推回分支
备注:这两处修复是本 PR 里明确标注的顺手小修(fix(ci)/fix(docs),各自独立 commit);PR 合入后 master 的同名红会一并治好。 |
(ai: vllm-qwen/qwen3.8-27b) 判定:本次 CI 告警是过期/重复触发,当前分支无需再修。 未推送任何新 commit。 核对结果(全部取自 GitHub API,非本地猜测):
结论:这是同一失败在旧 commit 上的重复自动触发。按本 lane「每 PR 至多 2 次尝试」的约束,我不再对已消失的失败做第二次修复/推送,避免无意义的重复 commit。等活 head |
(ai: vllm-qwen/qwen3.8-27b) 判定:又是过期触发,无需修复。 与上一条判定相同,补录证据:本条引用 run |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.630-master.55d1bd0 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…-drawing a card The dsh conversation.view tab shipped in #3886 as a native re-rendering of the proxy's contextView payload (categories bar + anchor + event trail). It works, but the same data now lives in TWO places: the web UI session page (compression tree, fold ledger, switch attribution) and this second hand-drawn card that must be kept in lockstep with the kernel's buildStatusPanel categorization and the cache-ledger fold trail forever. Per owner direction, embed the web UI's own session page instead: ?embed=1&lang=..&theme=..#/session/<id> in the shared EMBED_HEIGHT frame — one place for the data, zero duplicated rendering to maintain. - session id resolved from the SAME status URL the /acp command uses server-side (/__bili/plugin/status sessionId field), so the tab can never frame a different session than the lane; string-nonempty guard, older or foreign builds answering without one fall through to honest hints - full pre-flight discipline shared with the settings panel(): probeOrigin (+per-origin embed verdict cache, mid-session re-binds re-probe), #2559 host-theme pin into the frame URL, #3816 remote-blocked notice extracted to renderRemoteBlock() so fix text/relay snippet/jump target cannot drift between the two placements - state tree stays honest end-to-end: degraded (no proxy) / remote-blocked / stale-build (frozen pre-embed proxy) / waiting-first-request / connecting / not-yet; chain-advisory reads as not-yet, never as 'restart fixes it'; first paint before verdict+id never frames anything - i18n: card-only keys removed from both dictionaries (EN/ZH sets stay equal); remaining keys are the shared set - tests: the #3862 pin is rewritten for the embedded face — happy path asserts the exact iframe src/title, 10s single poller, refresh click re-polls without duplicating the interval, unmount cancels; every degraded sub-state pinned (waiting / chain-advisory-not-stale / stale-route / unparseable-body→degraded / all-throws→degraded)
Closes #3862
What
A native Context tab in the dsh client (per-session, next to Chat/Trajectory) that shows billion-context's own post-compression view, plus the machine-readable data behind it: a structured
contextViewfield onGET /__bili/plugin/status.Owner directive (#3862): reference dsh-context's basic functionality, guarantee the data is accurate, integrate part of dsh's native UI code — and (follow-up comment) dig a small hole in the official client instead of bringing react/iframes into bili. So the UI runs ONLY inside dsh's own client runtime (react resolved by dsh, same pattern as every other dsh client plugin); bili contributes a small tsup entry (
dist/agent/dsh-native-client.js, react stays external) and one JSON field on a route it already serves.Why this fixes #3862: dsh-context computes its bar from DSH's local event stream, where bili's folds never appear (
storage: shadow), so its segments stay pre-compression forever (the #3303 diagnosis). Here the numbers come from the proxy that PERFORMED the fold: the same live recompute that drives the existing panel breakdown, published verbatim. Post-compression, the tab shows the smaller number — by construction.Surfaces
src/context-view.ts(new) —buildContextView({nudge, systemPromptTokens, limit, session}):[sysprompt, tool, text, code, summaries, system](zero rows omitted);sentTotal = classified + systemPromptTokens; pct rounded — mirrorskernel/src/panel/panel.tsmath exactly, so bar and panel can never disagree;anchor=displayContextBest(usage > usage-anchored estimate > upper bound), carried with its OWN scale label — never mixed with the estimate-scale bar (release v0.1.6 #18/[Bug] host-plugin notice 文案过宽:实测 dsh-context 头部与 contextTokens 相符(14 ms 内),只有分段构成条是压缩前口径 #3303 discipline);foldstrail (newest 20: folded originals S, summary sigma, reclaimed, saved-so-far, paid-back flag via kernel fold economics) andswitchestrail (model/key/prompt/restart events with attributed missed tokens) from the existing cache ledger — additive read, no ledger changes beyond exporting two types.src/plugin.ts/src/server/admin.ts—contextViewadded to the/__bili/plugin/statusJSON (null until the session's first request; built from the nudge recompute the handler already performs — zero extra processTurn calls). The route now echoesaccess-control-allow-originback for origins the existing admin gate already trusts (loopback names regardless of port, configured trusted hostnames) so a cross-origin browser reader (the dsh client page) can fetch it. The gate itself is untouched: untrusted origins still get 403 before dispatch; the echo never widens access.src/agent/dsh-native-client.ts— new deferred mount on the dshconversation.viewslot (verified present in dsh 0.1.1-rc.2; built-ins register chat@0/trajectory@10, so order 30 sits right of any installed Context tab): header sent/limit + billed anchor chip, horizontal stacked bar (deterministic palette), legend, merged fold/switch event list, 10 s poll with swap-not-stack refresh and honest degraded states (waiting / stale build / no data / no proxy). Reuses the file's existing origin-discovery machinery; the Web-UI opener button is now a single module-level builder shared with the settings embed. No package.json change needed (deferred slots.inject fails open where the face doesn't exist).CLIENTS.md— paragraph documenting the tab and its two scales.Behavior changes (explicit)
GET /__bili/plugin/statusJSONcontextViewcontextViewfield (null pre-first-request)Originwhen it passes the EXISTING admin gateVerification
npm run typecheckclean on rebased head (master @ 39fb841).tests/issue3862-context-view.test.ts(new: unit math incl. exact category-sum invariant, anchor ladder, seeded-ledger fold/switch mapping; integration through real server: additive regression, CORS echo trusted-only, 403 untrusted),tests/dsh-settings-ui.test.ts(tab render/poll/degraded states + existing embed pins),tests/dsh-acp.test.ts,tests/anthropic-pck-identity.test.ts,tests/update-notes.test.ts,tests/advisory-panel.test.ts,tests/issue404-restore-timestamps.test.ts,tests/issue2029-status-baseline-provenance.test.ts— 50/50 pass. Full suite delegated to CI per local-testing discipline.npm run buildclean;dist/agent/dsh-native-client.jschecked: react external, loader idbillion-contextintact, tab mount + status path present.Config surface: none (no new config fields, env vars, or CLI flags).
kernel-change: none (kernel consumed read-only; fold economics come from its existing report).