Skip to content

[PR] (ai: anthropic/claude-opus-4-6) bili pack install: Standard format for custom compressed prompt packs + one-command npm | (ai: anthropic/claude-opus-4-6) bili pack install:自定义压缩提示词包的标准格式 + npm 一条命令安装 - #5342

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-31_pack-install
Oct 31, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #5340
Refs #5319(pack 总需求)、#5331(网页端管理)、#5325(动态列表)

这是什么

pack 工作流的最后一块。之前别人想分享一个压缩提示词包,只能手动把 JSON 文件放进 ~/.config/billion-context/packs/——既没有格式文档可查,也没有像样的分发方式。这个 PR 补上两件事:

  1. 标准格式(文档化既有行为,不改语义):CONFIGURATION.md / zh-CN 新增完整字段说明+示例——哪些字段会被 sanitize 器丢弃、section 值 null = 保留默认文本、至少要有一个识别字段;
  2. npm 约定 + 命令:npm 包根目录放一个 bili-pack.json(内容就是 pack 对象)即"是一个可安装的 pack";然后 bili pack install <名字> 完事。

新命令全套:

bili pack install <npm-spec> [--project] [--force]   # registry 名/@版本/scope/git URL/.tgz 都支持
bili pack list                                        # 列出所有可解析的包(名称/版本/来源)
bili pack remove <name>

设计要点

  • 委托本机 npm,零新依赖:install 在临时沙箱里跑 npm install --prefix <tmp> <spec>,只从结果里读那一个文件。registry 鉴权、版本范围、scoped 包、git URL、本地 .tgz 全部按普通 npm 行为工作——不自己解析 tarball。
  • 校验与网页端同一套:isValidPackName + sanitizePackSurface + 非空 surface 检查(把 web handler 的 packSurfaceHasContent 导出复用);坏 JSON、非法 name、空 surface 落盘前拒绝并给出明确报错。
  • 不静默覆盖:目标已存在同名包默认拒绝,--force 才替换;写盘走 temp-file+rename 原子范式。
  • 默认落 <configDir>/packs/,--project 指向 ./.billion-context/packs/(与解析链一致)。

Kernel Boundary

不涉及 kernel/**;只调用已导出的 isValidPackName/sanitizePackSurface/listResolvedPacks。

Config surface

无新配置字段、无新 env;纯新增 CLI 子命令与文档。

双模式推理

pack 文件每次 resolve 时现读,proxy/plugin 两条链路共用同一条解析链;本 PR 只是给这条链加了另一个写入方(CLI),行为一致。

验证

  • tsc clean;tests/pack-install.test.ts 6/6(本地目录 spec → 离线确定性)+ 相邻回归 7/7 = 13/13。
  • 真机冒烟(dist/index.js):list 显示 builtin/shipped 三包 → install 真实包目录 → 文件落 XDG packs 且 list 出现 file: 来源 → 无 --force 重装被拒 → remove 清理。

⚠️ 合并顺序(重要)

本分支堆叠在 #5325 → #5331 之上(复用了它们的导出函数)。请按序合并:#5325 → #5331 → 本 PR。前两个合并后本 PR diff 自动收缩为只剩这层改动。

已知边界

  • 安装委托本机 npm(bili 本身就跑在 node 环境,必然满足)。
  • 项目目录安装只写文件;信任门控由既有解析链统一执行,本 PR 不放宽任何门控。

ranxianglei and others added 3 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.
…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

📦 Built Package Artifact

Branch: 2026-10-31_pack-install (b9218e8)

Latest build — install this exact version

npm install -g billion-context@0.0.7485-pr.5342.a436542

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.7485-pr.5342.a436542 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit d108df3 into master Oct 31, 2026
74 of 80 checks passed
@ranxianglei ranxianglei changed the title (ai: anthropic/claude-opus-4-6) bili pack install:自定义压缩提示词包的标准格式 + npm 一条命令安装 [PR] (ai: anthropic/claude-opus-4-6) bili pack install:自定义压缩提示词包的标准格式 + npm 一条命令安装 Oct 31, 2026
@ranxianglei ranxianglei changed the title [PR] (ai: anthropic/claude-opus-4-6) bili pack install:自定义压缩提示词包的标准格式 + npm 一条命令安装 [PR] (ai: anthropic/claude-opus-4-6) bili pack install: Standard format for custom compressed prompt packs + one-command npm | (ai: anthropic/claude-opus-4-6) bili pack install:自定义压缩提示词包的标准格式 + npm 一条命令安装 Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant