Skip to content

[PR] (ai: anthropic/claude-opus-4-6) Manage custom compressed prompt packs on the web: Create / Edit / Delete | (ai: anthropic/claude-opus-4-6) 网页端管理自定义压缩提示词包:新建 / 编辑 / 删除 - #5331

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-31_web-user-packs
Oct 31, 2026

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Closes #5328
Refs #5319(pack 总需求)、#5325(面板动态列表)

这是什么

compress.promptPack 早就支持从 ~/.config/billion-context/packs/ 加载自定义包,但网页端只有"选"没有"管"——新建一个包、改一句规则、删一个旧包都得退出页面找文件手改 JSON。本 PR 在选择器旁加了一行 新建 / 编辑当前所选 / 删除当前所选 按钮和一个内联 JSON 编辑器:填包名、写 JSON、保存,文件原子落盘到 ~/.config/billion-context/packs/<name>.json 并自动切换为它。内置 default/lean/chat 与项目目录包在这里只读,界面给出对应指引(内置用同名用户包覆盖)。

改动

文件 内容
src/web/api.ts 新端点 GET/PUT/DELETE /__bili/packs/user/<name>。名字过路由正则 + 内核 isValidPackName 双校验;payload 按 dir-pack 同款解析+sanitize,坏 JSON / 非对象顶层 / 无任何有效字段的包在写盘前拒绝;未知顶层键(host adapter 用)原样保留;写盘走既有 temp-file+rename 原子范式
src/server/admin.ts 挂三条路由;GET /__bili/packs 增加 userDir 字段(服务端说了算,面板据此判断哪些条目可编辑)
src/web/client.ts 选择器下方一行按钮 + JSON 编辑器;保存后自动选中;编辑/删除仅限用户目录条目
src/web/i18n.ts zh-CN/en 各 16 键
CONFIGURATION.md / .zh-CN.md promptPack 节补一句面板管理能力
tests/web-user-packs.test.ts 建/读/删回环、拒绝项不留文件、点号/穿越名全拒、userDir 断言

Kernel Boundary

不涉及 kernel/**。仅调用 kernel 已导出的 isValidPackName / sanitizePackSurface(与 dir-pack 加载同一套语义),未改动任何 kernel 行为。

Config surface

无新配置字段。compress.promptPack 本身不变;新增的是对"用户目录里那个包文件"的管理通道,保存后的效果等价于用户自己手写该文件。

双模式推理(proxy / plugin)

  • proxy 模式:面板改的文件下次 pack 链解析即生效(每次 resolve 现读文件),无需重启;PUT 与并发 resolve 之间靠既有原子 rename 保证不读到半截文件。
  • plugin 模式:宿主侧同样通过 pack 链读文件,行为一致;本 PR 的 web 端点只是文件的另一种编辑器,不引入 plugin 侧新表面。

Preflight / 验证

  • npm run typecheck clean;node --check 校验内嵌 WEB_CLIENT 语法通过(模板字面量里的反斜杠陷阱已按 :2311 注释约定规避)。
  • 测试:web-routing(9) + web-user-packs(1) + web-pack-picker(1) + chat-pack(4) = 15/15 pass,真实 server on port 0 + XDG 隔离环境。
  • 构建产物确认:dist/index.js 含新端点。

分支说明

分支直接堆在 #5325 的原提交 171417cd 上(非 cherry-pick):先合 #5325 则本 PR diff 只剩这一层;两者一起合也干净。请按序合并。

已知边界(v1)

补遗(按 #5328 验收标准复核,分支顶端两个补充提交)

  • 行为变更披露:fix(web) 提交起,GET /__bili/packs 返回的 userDir 字段与每个条目的 source 字段统一改为正斜杠路径(此前为平台原生分隔符)。原因:面板用 source.startsWith(userDir + "/") 判断条目是否属于用户目录;Windows 上 path.join 产生反斜杠,该比较恒不成立 → 用户目录包永远显示只读指引、编辑/删除按钮实际不可用(功能在 Windows 整体失效)。归一化在 admin 映射层完成(仅宿主侧;kernel 与 resolver 内部 Pack 对象不受影响),已确认这两个字段的唯一消费方是面板自身。测试断言同步钉住归一化契约。
  • refactor(web) 提交:picker refresh 遗留的一行缩进错位(12→8 空格),纯空白无行为变化。
  • 注:补充提交信息里的编号是 ework 平台工单号,对应本仓库 GitHub 工单为 (ai: anthropic/claude-opus-4-6) | (ai: anthropic/claude-opus-4-6) 网页端管理自己的压缩提示词包:新建 / 编辑 / 删除 #5328。

rebase 到当前分支头后验证:typecheck clean;web-routing(9)+web-user-packs(1)+web-pack-picker(1)+chat-pack(4)+pack-install(6)=21/21 pass;build 绿。

ranxianglei and others added 2 commits October 31, 2026 16:07
…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>
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 (#5325, web half of #5319);
#5325 merges first or together, both orderings stay conflict-free.
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-31_web-user-packs (b9218e8)

Latest build — install this exact version

npm install -g billion-context@0.0.7482-pr.5331.9b581b6

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

Recent builds (commit → version)

commit version build
b9218e8 billion-context@0.0.7482-pr.5331.9b581b6 build
164b10e billion-context@0.0.7462-pr.5331.78ca669 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title (ai: anthropic/claude-opus-4-6) 网页端管理自定义压缩提示词包:新建 / 编辑 / 删除 [PR] (ai: anthropic/claude-opus-4-6) 网页端管理自定义压缩提示词包:新建 / 编辑 / 删除 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.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.956-master.d108df3 (rolling master tag).

npm install -g billion-context@0.0.956-master.d108df3  # 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 added a commit that referenced this pull request Oct 31, 2026
…used-export gate)

Upstream PR #5331 (merged 09:35Z today) introduced src/pack-install.ts with an export nobody references outside the defining file — installPackFromNpm's callers pass options structurally, so the guard verdict is INTERNAL_ONLY and its own suggested remedy applies: drop the leading `export`. This merge-ref regression would fail every open PR's unused-exports job (and master's next push CI); fixing it here so the suite goes fully green. Content otherwise byte-identical to master.
@ranxianglei ranxianglei changed the title [PR] (ai: anthropic/claude-opus-4-6) 网页端管理自定义压缩提示词包:新建 / 编辑 / 删除 [PR] (ai: anthropic/claude-opus-4-6) Manage custom compressed prompt packs on the web: Create / Edit / Delete | (ai: anthropic/claude-opus-4-6) 网页端管理自定义压缩提示词包:新建 / 编辑 / 删除 Oct 31, 2026
ranxianglei added a commit that referenced this pull request Oct 31, 2026
Previous head conflicted (add/add on src/pack-install.ts): this branch pre-dated PR #5331, which added that file to master while the branch carried its own copy. Sandbox cannot clone full objects, so the branch is reconstructed as one clean commit on today's master via the Git data API. Contents unchanged from the reviewed work:

workflows
- ci-janitor: feed the sweep loop its run list (it was never wired up — zombie cancels were dead code since 10-30); add backlog breaker (starvedQueueLimit warn + starvedQueuedMaxMinutes pruning, push-to-master exempt)
- concurrency groups: master-build, release, release-kernel (no-cancel), theorem (skip-lane suffix per house rules)
- timeout-minutes on six workflows left on the 6h default (release 90, release-kernel 90, release-bugfix 90, release-manual 90, advisories 30, pages 30, ci-gate-plugins 30)

master-reds fixed here so every gate passes
- LIFECYCLE.md: register BILI_SPAWN_FINGERPRINT (#5303/#4125) and BILI_SESSION_CONTENT_STORE_PIN (#5292 phase2)
- src/codex-models.ts: drop unused `export` on CodexWindowSource (zero named references; tsconfig has no declaration emit)
- CONFIGURATION{,.zh-CN}.md: restore promptPack row to generator output ("chat" is host-shipped, not builtin; follow-up for #5320: add chat to website/config-reference/compress.yaml and regenerate)
- src/pack-install.ts: PackInstallOptions -> internal (callers pass options structurally)

latent test fixes (surfaced once gates went green)
- src/launcher.ts: #4125 rewrite dropped the phrase tests/issue5103 asserts verbatim; restored
- tests/store.test.ts: move fault injection to the real write point so adopt() runs before the disk sabotage
ranxianglei added a commit that referenced this pull request Oct 31, 2026
…E rows

Previous head shadowed ~20 lines of #5331's pack-install docs section inside the two configuration tables and duplicated two BILI_* ledger rows master has since registered itself. Restore all three files onto today's master text: only the promptPack table row reverts to generator output ("chat" is host-shipped, not builtin); LIFECYCLE.md back to exact master bytes.
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.

(ai: anthropic/claude-opus-4-6) | (ai: anthropic/claude-opus-4-6) 网页端管理自己的压缩提示词包:新建 / 编辑 / 删除

1 participant