Skip to content

[PR] feat(web): compression structure tab — tier tree, lazy originals, mNNNNN locate, JSON export - #3942

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-20_web-cstruct-tab
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-20_web-cstruct-tab

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Adds a compression structure card to the web UI session detail page (/__bili/<id>):

  • Tier tree — blocks rendered as a parent→child tree derived from directBlockIds (the kernel has no parentBlockId; children are the edge source). Each node shows block id, tier badge, topic, compressed tokens, age, ref span and active/external badges; open a node for its summary markdown.
  • Lazy originals — per-node buttons load that block's originals from a new endpoint in two views: one (direct messages + nested child summaries) and full (every original message). A 2 MiB response guard truncates oversized views with a marker; a one view persisted as byte-identical to full (sessions 存储三重膨胀:叶块 blockContents 逐字节重复 50%、零 GC、每次启动两遍全量同步解析(实测 387MB/+60MB 每天/2s 起步) #401 single copy) is served with an identicalToFull flag.
  • mNNNNN / raw-id locate — type any mNNNNN ref or raw message id; lookup is EXACT membership over each block's effectiveMessageIds (no span guessing), so every containing block (leaf + all ancestors) is reported with the deepest one marked as owner. Matched nodes highlight and auto-expand along the root→owner chain.
  • Export — downloads the current view (all block details + whatever originals you loaded) as .json.

API surface (additive only, read-only)

  • GET /__bili/sessions/:id/block-content?block=bN&mode=one|full → { blockId, mode, count?, text?, truncated?, identicalToFull? } or { missing: true }; 404 unknown session/block, 400 bad mode/params. Sits behind the existing loopback/trusted-origin/tunnel gates like every other /__bili/* route.
  • GET /__bili/sessions/:id/block-ref?q=m00042|raw-id → { query, kind, owner?, matches[] }; 404 unknown session, 400 empty q.
  • WebSessionDetail.blockDetails[] gains children: string[] (child block ids). Sparse legacy block records missing directBlockIds render as leaves instead of throwing the detail page.

No proxying/wire/config/persistence changes; no kernel changes.

Tests

Targeted additions in tests/web-sessions.test.ts: tier-tree wiring in the detail payload, buildBlockContent (both modes, identical-to-full, missing content, unknown session/block, bad-mode precedence, 2 MiB truncation), buildRefLookup (ref + raw kinds, leaf+ancestor chains, owner = smallest id set, honest empty sets, bad-query) and HTTP-level status coverage for both endpoints (200/400/404). The i18n parity suite covers the 12 new keys.

Closes #3917

@ranxianglei ranxianglei changed the title feat(web): compression structure tab — tier tree, lazy originals, mNNNNN locate, JSON export [PR] feat(web): compression structure tab — tier tree, lazy originals, mNNNNN locate, JSON export Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-20_web-cstruct-tab (42843ec)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4753-pr.3942.68397c8

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-pr3942.tgz
npm install -g package

Install instructions are refreshed on each push.

…ate (#3942)

resolveSessionForWeb / BlockContentMode / WebRefMatch are referenced only inside sessions-data.ts; the gate's INTERNAL_ONLY verdict prescribes dropping the leading export. No behavior change.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 修复:unused-exports 门禁已修,已推回 PR 分支(auto-fix 第 1/2 次)。

失败检查:unused-exports(head 1e4f5bc),报告 3 个 INTERNAL_ONLY 导出(src/web/sessions-data.ts)。

八问:

  1. 是什么问题:CI 的未用导出门禁在 src/web/sessions-data.ts 发现 3 个带 export 但仓库内没有任何外部引用的符号:resolveSessionForWeb、BlockContentMode、WebRefMatch,job 直接红。
  2. 什么原因导致的:本 PR 的功能提交给这三个新符号都加了 export,但它们全部只被同文件内的 detail / block-content / ref-lookup 三个端点使用——是纯文件内部符号,误标成了模块导出。
  3. 影响范围与严重程度:零运行时影响——去掉 export 只收窄模块可见性,不改任何行为。严重度仅为「CI 红挡住合并」,无用户面影响。
  4. 怎么修复的:按门禁自带的处置规则(INTERNAL_ONLY → 去掉行首 export;DEAD → 删声明),三者均被文件内引用所以保留声明、只摘 export。单文件 3 行,无其他改动。
  5. 是否有回归问题:全仓 grep(src/ + tests/)确认无外部导入这三个符号;npm run typecheck 干净;定向套件 tests/web-sessions.test.ts 28/28 通过(即本 PR 的测试面)。摘导出在语义上不可能改变运行时行为,高危模式(语义漂移/吞错/阈值时序漂移)逐项不涉及。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向:没有。
  8. 是否引入了新的配置:没有。

本地验证:node scripts/check-unused-exports.mjs → ✓ unused-export gate: clean (5 waived)。修复 commit 42843ecf3 已推到 2026-10-20_web-cstruct-tab,等 CI 复跑确认即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

关闭原因:与 #3924 重复(先来后到,保留外部贡献)。

本 PR 与 #3924 是同一个功能请求(#3917:会话详情页「压缩结构」tab)的两份实现:同一页面、同一数据源(directBlockIds 反推层级)、同一机制族(块原文 one/full 懒加载 + 只读 /__bili 端点),且改的是完全相同的一组文件(src/server/admin.ts、src/web/client.ts、src/web/sessions-data.ts、src/web/i18n.ts、src/web/styles.ts + 测试)——物理上只能合入一个。

按项目规则(先来后到保留先到者;agent PR 不得以新 PR 替换外部贡献),保留先到的 #3924(vegetable86 提交,上一轮已审:质量达标、无回归、CI 全绿),关闭本后到 PR。

本 PR 的独有部分不丢弃,已记录在 #3917 作为后续项:

  1. mNNNNN/raw-id 反查(/block-ref 端点:消息 → 所有包含块 + owner 块,精确集合成员判定而非区间猜测);
  2. 当前视图导出(.json);
  3. identicalToFull 标记(one 视图与 full 字节相同时显式告知前端)。

如后续需要这些能力,移植进 #3924 分支(additive commit)即可,不再重开本 PR。

CI 备注:本 PR 主 CI lane 为红——unused-exports gate 报 3 个 INTERNAL_ONLY 导出(resolveSessionForWeb / BlockContentMode / WebRefMatch,均在 src/web/sessions-data.ts);移植时去掉 export 修饰即可。

@ranxianglei ranxianglei added duplicate This issue or pull request already exists p3 scope/ui labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists p3 scope/ui

Projects

None yet

1 participant