Skip to content

[PR] feat(web): Web dropdown lists all available compression prompt packs (including built-in chat) (#5319) | feat(web): 网页下拉列出全部可用压缩提示包(含内置 chat)(#5319) - #5325

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-31_web-pack-picker
Oct 31, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-31_web-pack-picker

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: sglang-gpu0/qwen3.8-27b)

Refs #5319 · 网页端可配置/可选 —— m00066 四项之第 2 项(#5320 是第 1 项,已合并)

What changed

  • src/server/admin.ts:新读端点 GET /__bili/packs——返回解析链(项目 > 用户 > 随包自带 > kernel 内置,同名先到者胜)当前能看到的全部压缩提示包:name / version / description / source。与现有所有 /__bili/ 端点同走 loopback + trusted-origin 门控(gate 在 dispatch 前)。
  • src/compress-settings.ts:把 PR1 里的解析链构造提成内部 packResolver(dirs),新增导出 listResolvedPacks(dirs?)——picker 库存与每请求解析共用同一条链,不可能漂移。
  • src/web/client.ts:loadConfig() 顺带拉一次 /__bili/packs;promptPack 下拉从硬编码 ["default","lean"] 改为渲染服务端清单(拉取失败回退旧两项);chat 选中时显示专用说明行。
  • src/web/i18n.ts:zh+en 各加 cfg.q_pack_chat_desc。
  • tests/web-pack-picker.test.ts:真实 server(port 0)验证清单内容、四个 provenance 标签(builtin:default / builtin:lean / shipped:chat / file:*)、用户目录文件包被发现。

Why

第 1 项之后 chat 包已可用但网页下拉看不到;自定义包(第 3 项)落地后清单必然是动态的,picker 先动态化,后续 editor 直接复用同一端点刷新。

Kernel Boundary

kernel/** 零改动(只消费 acp-kernel 已导出的原语),无需 kernel-change: 声明、无版本 bump。

Config surface

无新增配置字段。新增一个只读管理端点 GET /__bili/packs(loopback-only,与其他 admin GET 同门控)。

双模式推理

纯管理面 UI 数据端点:不动 proxy wire、不动 plugin manifest、不动任何注入文本 → proxy/plugin 两模式下请求字节不变。picker 保存的仍是既有字段 compress.promptPack(经既有 PUT /__bili/config)。

Preflight

  • typecheck clean;新测试 1/1;相关存量(admin-probe / web-routing / chat-pack)共 15/15 全绿

…5319)

GET /__bili/packs returns every pack the resolver can see (project >
user > shipped > builtin, first-wins per name) with provenance; the
settings panel's promptPack dropdown now renders those names instead of
hardcoded default+lean, with a note line for the shipped chat pack.
Unchanged behavior until loadConfig fills the list (falls back to the
old two options on fetch failure). listResolvedPacks() shares the exact
chain builder with per-request resolution.

Co-authored-by: qwen3.8-27b <agent@billion-context.local>
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。相关条目:上游 #5319(chat 提示包规划 issue,已关——本 PR 正是其非目标节明确延后的「Web 端选择 UI」后续项,且按要求引用了该 issue)、#5320(第 1 项 chat 包本体,已合并 f096cb3)、#5331(第 3 项自定义包编辑器,在途——editor 与 picker 清单是不同面,不重复)。未发现同一端点/下拉的并行实现。

标签:pr(原有)+ scope/ui(web 配置面板面)+ p3(增量功能/体验增强,无缺陷成分)。非缺陷类不打 bug;不涉及宿主客户端车道。

Review(上游 PR #5325,head 171417c,base 870e182)

方向:正确。#5319 把「Web 端选择 UI / 自定义 pack 编辑器 / npm 安装器」列为后续 PR 并要求引用本 issue;本 PR 只做第 2 项(picker 动态化 + 只读清单端点),没夹带编辑器范围;保存仍走既有 PUT /__bili/config 的 compress.promptPack,不动任何注入文本。分支落后 master 24 个提交,但触碰的 6 个路径(client/admin/compress-settings/i18n/chat-pack/新测试)在分叉点之后零并发提交,无热文件冲突。

回归清点(逐路径):

  • src/compress-settings.ts:resolver 构造逐字提进 packResolver(dirs)——源序 [project > user > shipped > builtin]、默认目录、default/非法名在构造前的 early return,全部与旧代码一致,每请求解析行为字节级不变。两个调用点(src/server/handle.ts:842、src/server/admin.ts:470)都不传 dirs,与端点的 listResolvedPacks() 走同一条默认链——「库存与解析共用一条链、不可能漂移」的说法成立。新导出纯增量。
  • src/server/admin.ts:新路由与相邻 /__bili/pricing 同款精确匹配(req.url === "/__bili/packs"),只读、无状态写;loopback+trusted-origin+anti-tunnel 门控在 dispatch 前执行(handle.ts:281-286,audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 机制),与其他 admin GET 一致;精确匹配不遮蔽既有路由(实测 200)。
  • src/web/client.ts:packNames 模块变量 + fire-and-forget 拉取带 .catch(() => {});拉取失败/未回时回退旧 ["default","lean"] 两项,降级方向正确;updatePackNote 加 chat 一支,未知名仍落 cfg.q_pack_custom。一处观察(非缺陷、不拦):fetch 未回前打开面板会短暂显示回退两项,下次 loadConfig() 自愈——代码注释表明这是有意的 graceful degradation。
  • src/web/i18n.ts:zh/en 各一 key,命名沿用 cfg.q_pack_* 惯例,双语对齐。
  • kernel/** 零改动(diff 核实);version/lockfile 未动。

测试有效性:新测试是真测试——真实 server(port 0)+ XDG_CONFIG_HOME/BILI_CONFIG_FILE 沙箱 + t.after 清理,断言有牙(四种 provenance 标签 builtin:default / builtin:lean / shipped:chat / file: 前缀 + 用户目录文件包被发现)。端点门控由既有 admin gate 测试覆盖(test 头注释已声明,符合 #3617 纪律);picker 回退逻辑属客户端 JS,本套件不可达,可接受。

本地定向验证(branch head 实跑,非全量):tests/web-pack-picker.test.ts 1/1;相关存量 admin-probe / admin-origin / web-routing / chat-pack / compress-prompt-pack / persist-active-pack / prompt-pack-tool-prompts 合计 34/34 全绿;typecheck(kernel+pi-subagents 构建后)tsc exit 0。

CI 状态(唯一悬置项):head 上 20 个 suite 于 08:08Z 启动后整体被 cancel(3 success + 13 skipped + 84 run cancelled,零 failure),与 #4599 记录的 master 红风暴窗口(lifecycle-ledger-guard/docs-sync,哨兵已把修复收敛到 ci-fixes@0371089d)重合。当前没有有效全量结论,需要一次重触发;若重跑命中上述继承红签名,按 CI 协调政策 merge ci-fixes 即可,不要在分支侧重复修。我未向分支推任何东西——现有状态不是该 PR 代码的失败,无理由推送。

合入顺序建议:#5331(第 3 项 editor)直接复用本 PR 的 /__bili/packs 端点,建议先合本 PR,避免 src/web/client.ts 上的语义冲突。

八问

  1. 是什么问题:功能项(New built-in chat prompt pack: default compression rules for long-term companionship / multi-session memory scenarios (e | 新增内置 chat 提示压缩包:长期陪伴 / 多会话记忆场景的默认压缩规则(compress.promptPack="chat" 启用) #5319 四项之第 2)——网页设置面板的 promptPack 下拉此前硬编码 ["default","lean"],看不到已可用的内置 chat 包,也注定无法承载后续自定义包;要把它变成渲染服务端解析链的完整动态清单。
  2. 什么原因导致的:picker 数据源硬编码在前端,与服务端实际的 pack 解析链(project > user > shipped > builtin)脱节;[PR] feat: Built-in chat prompt compression package — default compression rules for long-term companionship / multi-session m | feat: 内置 chat 提示压缩包——长期陪伴 / 多会话记忆场景的默认压缩规则(#5319) #5320 让 chat 可用后这个脱节变为用户可见。
  3. 影响范围与严重程度:纯新增,不影响存量用户;受益面=用网页面板管理压缩设置的用户(chat 包此前只能手改 JSON 启用)。无缺陷成分,体验增强。
  4. 怎么修复的:服务端加只读 GET /__bili/packs(把每请求解析用的 resolver 链提成共用内部函数,库存与解析同源,first-wins per name);前端 loadConfig() 顺带拉清单渲染下拉,失败回退旧两项;chat 选中显示专用说明行。
  5. 是否有回归问题:无。逐项过:每请求 pack 解析字节级不变(仅代码上提,顺序/默认值/early-return 全保真);其他 admin 路由不受影响(精确匹配);picker 降级=旧行为;i18n 纯增;kernel/version/lockfile 未动。本地 34/34 定向测试 + typecheck 绿。
  6. 是否破坏缓存:不涉及(纯管理面数据端点,不触 wire/session/cache 路径)。
  7. 是否改了设计方向:没有。宿主侧扩展 pack 链是 kernel 原设计的 seam(packs.ts 头注释明确允许宿主扩 discovery chain,无需改 core);端点沿用既有 /__bili/ 只读门控模式。
  8. 是否引入新的配置:无新字段/env。仅新增一个 loopback-only 只读管理端点 GET /__bili/packs(PR 正文 Config surface 节已按规矩披露)。

结论:代码质量达标、回归清点干净、本地定向验证全绿;唯一缺有效 CI 全量结论(现矩阵整体被 cancel、零失败)。建议重触发 CI,转绿即可以合。

ranxianglei added a commit that referenced this pull request Oct 31, 2026
…acks (#5340)

Final piece of the pack workstream (#5319 item ④): a documented standard
pack format plus a first-class way to install other people's packs.

Convention: an npm package is installable as a prompt pack when its root
contains bili-pack.json (the same object shape as any
`~/.config/billion-context/packs/<name>.json`). `bili pack install <spec>`
delegates to the local `npm` in a throwaway sandbox and reads that one file
out — registry auth, version ranges, scoped names, git URLs and .tgz paths
all behave like a normal npm install; no tar parsing, no new dependency.

- src/pack-install.ts: installPackFromNpm/removePackFile/packDirFor.
  Kernel-shaped validation end to end (isValidPackName,
  sanitizePackSurface + non-empty surface check shared with the web
  handler via the now-exported packSurfaceHasContent), atomic
  temp-file+rename writes, default destination <configDir>/packs,
  --project targets ./.billion-context/packs/, existing files are never
  overwritten without --force.
- cli.ts: `bili pack install <npm-spec> [--project] [--force]` /
  `remove <name>` / `list` (also accepts plural `packs`); list prints
  every resolvable pack with version and provenance.
- docs: CONFIGURATION.md + zh-CN gain the full pack file format section
  (annotated example, tri-state null semantics, sanitize behavior) and
  publish/install instructions.
- tests/pack-install.test.ts: local-directory npm specs keep the suite
  offline — install→resolvable round-trip, force semantics, missing
  entry file, invalid names, empty surfaces, remove errors, dir targets.

Verified live against dist: list shows builtin/shipped packs, install
from a real package dir lands in the XDG packs dir, reinstall refuses
without --force, remove cleans up.

Branch note: stacked on #5331 (web half) and its base #5325 — the code
reuses their exported helpers; merge bottom-up.
@ranxianglei
ranxianglei merged commit b5e3155 into master Oct 31, 2026
22 of 118 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.955-master.b5e3155 (rolling master tag).

npm install -g billion-context@0.0.955-master.b5e3155  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收工核验:PR #5325 已合入 master——merge commit b5e3155fd(「Merge pull request #5325 from ranxianglei/2026-10-31_web-pack-picker」),rolling master 构建 0.0.955-master.b5e3155 已由 CI 发布(与本帖 09:35Z 的 Merged Build Published 一致)。本地 fetch 核实:PR head 171417cda 已是 origin/master 祖先。

合入顺序也按上轮建议执行了:#5331(第 3 项自定义包编辑器)紧随其后合入(d108df3),复用了本 PR 的 /__bili/packs 端点,client.ts 无冲突。master 在其后继续正常合入(#5322 等),无异常。

上轮(floor 2)的 review 结论维持不变:回归清点干净、本地定向验证全绿、唯一悬置的 CI 问题随合入解决。本工作项完毕;issue 关闭留给 owner(镜像会随上游 PR 状态同步)。

@ranxianglei ranxianglei changed the title [PR] feat(web): 网页下拉列出全部可用压缩提示包(含内置 chat)(#5319) [PR] feat(web): Web dropdown lists all available compressed prompt packs (including built-in chat) (#5319) | feat(web): 网页下拉列出全部可用压缩提示包(含内置 chat)(#5319) Oct 31, 2026
@ranxianglei ranxianglei changed the title [PR] feat(web): Web dropdown lists all available compressed prompt packs (including built-in chat) (#5319) | feat(web): 网页下拉列出全部可用压缩提示包(含内置 chat)(#5319) [PR] feat(web): Web dropdown lists all available compression prompt packs (including built-in chat) (#5319) | feat(web): 网页下拉列出全部可用压缩提示包(含内置 chat)(#5319) Oct 31, 2026
abebatista pushed a commit to abebatista/ranxianglei-billion-context that referenced this pull request Oct 31, 2026
)

Add New/Edit/Delete for custom compress prompt packs under
`~/.config/billion-context/packs/` so users never need a terminal or a
file path:

- GET/PUT/DELETE /__bili/packs/user/<name> (api.ts) — same loopback +
  trusted-origin gates as every other /__bili/ route; names shaped by the
  route regex AND re-validated with the kernel's isValidPackName;
  payloads parsed + sanitized exactly like dir-pack loading (bad JSON,
  non-object top level, or surfaces without recognized fields are
  refused before touching disk); writes go through the existing atomic
  temp-file+rename pattern.
- GET /__bili/packs gains userDir so the panel knows which listed entries
  it may edit (server authority on the directory).
- Panel picker row: name field + New/Edit/Delete + inline JSON editor;
  Edit/Delete only act on user-dir packs — builtins/shipped/project packs
  get override guidance instead; saving auto-selects the pack.
- i18n zh-CN/en; CONFIGURATION(.zh-CN).md note under promptPack.
- tests/web-user-packs.test.ts: create/read/delete round-trip, unknown
  keys preserved for host adapters, refused payloads leave no file,
  dotted/traversal names rejected.

Branch note: stacked directly on 171417c (ranxianglei#5325, web half of ranxianglei#5319);
ranxianglei#5325 merges first or together, both orderings stay conflict-free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant