Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased (master, since v0.1.38)
- **refactor(packs): prompt-pack 机制下沉 acp-kernel 0.0.66,删除本地实现——单一事实源(#401,由 #403 合并关闭)** — PR #397 的包体系是适配器本地代码(src/packs/{types,sanitize,lean,builtin,dir}.ts),acp-kernel #259/#260 已把整层下沉并发布 0.0.66(Pack/PackSource/PackResolver 契约、sanitizePackSurface、builtin 注册表 default+lean、createDirPackSource/createPackResolver/defaultPackSources;billion-context 代理侧已消费同一 API),两份分叉副本并存。本改动删除 src/packs/* 全部五个文件,src/prompt-pack.ts 改写为内核导出之上的薄层:对外表面不变(mergeSurface / readToolSurfaceWithPacks / resolveActivePack / packResolver,另重新导出 leanPack/defaultPack/builtinSource/createDirPackSource/createPackResolver/defaultPackSources/isValidPackName/sanitizePackSurface 与 Pack/PackSource/PackResolver/PackSurface/PromptPackFile 类型)。pi 专属数据改经不透明命名空间 `surface.adapters.pi` 承载(promptSections 全 13 键三态 / toolExtras 的 promptSnippet+promptGuidelines / delegatePrompt),pi 侧用既有 sanitizer(sanitizePromptSections/sanitizeToolPrompts)验证——内核视 adapters 为不透明数据原样透传。合并优先级:inline > adapters.pi > 通用顶层(toolPrompts 逐工具→逐字段→逐参数,extras 胜通用;通用顶层保留的共享 section 键 acpTags/tools/summariesInContext 在 pi 侧同样生效,与重构前行为一致)。行为差异三点:① 旧格式包文件把 pi 专属 section 键(tier2/whenToCompress 等)写在顶层的,现会被内核 sanitizer 丢弃——须移入 adapters.pi.promptSections(文档已注明);② 内核 toolPrompts 不按工具名过滤(bash 等未知工具名保留在 surface 中,消费端只读四个 ACP 工具,无功能影响);③ delegatePrompt 不再是包文件顶层字段,位于 adapters.pi.delegatePrompt。主体已由 #403 落地(含 acp-kernel 0.0.65→0.0.66 精确 pin 与 lockfile);本 PR 对齐合并语义修复——#403 版 mergeSurface 静默丢弃通用顶层共享键 section,且把签名从 PackSurface 改成了 Pack——并补文档与测试。测试全绿(786 pass / 0 fail;tests/prompt-pack.test.ts 14 例覆盖新形状:adapters.pi 定位、三层合并优先级、未知工具名保留、adapters 原样透传、pi extras 清洗、home/cwd 配置级联、发现/遮蔽/回退、风险门);lean 行为与改动前一致(对齐规则、null sections、工具单行,测试断言)。CONFIGURATION.md(+zh-CN) Prompt Packs 节更新:adapters.pi schema、双层合并语义、机制归属内核
- **feat(prompts): 提示词包(prompt pack)——一行切换整套表面,包选择复用 compress 三级级联(extends #252 / 改编自 #410 调研)** —— 把 `promptSections`/`nudgeSections`/`toolPrompts`/`delegatePrompt`/四条压缩规则打包为命名 JSON 包,`compress.promptPack` 一行选中;包选择与其它 `compress.*` 字段同走 `models > providers > global` 三级级联(逐回合按当前模型解析,切模型自动切包,零新配置机制)。内置 `default`(无覆盖)与 `lean`(token 精简表面:八条单行 acpTags 块 + 工具单行 description,snippet/guidelines 全空,实测 5422→1312 字节省 76%;压缩规则保持内核默认由 nudge 按需送达)。查找顺序:项目 `.pi/acp/packs/N.json` 遮蔽用户 `~/.pi/acp/packs/N.json` 遮蔽内置;包名白名单 `[A-Za-z0-9][A-Za-z0-9._-]*` 防路径逃逸,非法名/坏 JSON 回退内置绝不崩溃。合并语义:**包为基础层,`acp.json` 内联逐字段优先**(sections 逐键含 null;toolPrompts 逐工具→逐字段→逐参数;delegatePrompt 内联含 null 胜);包内 `prompts` 四规则与内联同受 `acknowledgePromptsRisk` 风险门(未设则忽略并告警,标志不可随包分发)。实现:新 `src/prompt-pack.ts`(LEAN_PROMPT/LEAN_PACK/BUILTIN_PACKS/discoverPack/resolvePackName/resolveActivePack/packSurface/mergeSurface/readToolSurfaceWithPacks),`src/config.ts` CompressSettings 增 `promptPack` + mergeCompress 三级链,`src/system-prompt.ts` PiPromptSections 增 4 规则槽键并从内核 defaultPrompts 取默认,`src/index.ts` before_agent_start/context 四处接线(工具注册用 readToolSurfaceWithPacks 工厂时读盘,nudge/系统提示词逐回合 resolveActivePack)。测试 `tests/prompt-pack.test.ts` 10 例;文档 CONFIGURATION.md(+zh-CN) 增 `compress.promptPack` + 「Prompt Packs/提示词包」整节。**包体系面向接口重构**:`Pack`/`PackSource`/`PackResolver` 契约(src/packs/{types,sanitize,lean,builtin,dir}.ts),`lean` 独立模块导出 `leanPack`(内置包与用户文件包同一条路径,不再硬编码于解析器);解析链 [project > user > builtin] 可前置自定义 source 遮蔽一切,`listPacks()` 列包——未来 `bili-pi install` 式包管理器只需写文件或前置一个 managed source,核心零改动;内嵌宿主可自建 resolver 传给 `resolveActivePack`。测试增至 12 例(+自定义 source 遮蔽链、目录 list 容错)
- **fix(host): Pi-fork 宿主(Prime)可加载 + 可识别(#364 验收补充)** — Prime 0.9.4 实测两个启动阻断:① Prime loader 把 `@earendil-works/pi-coding-agent` alias 到自身构建,公共入口不导出 `CONFIG_DIR_NAME`,ESM interop 下缺失命名导出在运行时表现为 `undefined`(而非链接错误)→ `path.join()` 直接抛 "The path argument must be of type string"。新增 `src/config-dir.ts`:feature-detect 缺失/非法导出时回退 Pi 规范值 `.pi`,五个路径使用点(log/index/user-config/setup-subagent-tools/update)全部收敛到该常量;责任边界写入 docs/host-adapter.md §4(导出归宿主、回退归适配器)。② `isOmpHost = !isPiHost` 把一切无 `buildContextEntries()` 的宿主(含 Prime)一律判为 OMP 并禁用 ACP——但 OMP 与 Prime 同为 Pi fork、同为 getBranch-only 形状,形状本身无法区分。新 `src/host.ts`:`entrySourceOf`(buildContextEntries > getBranch)、`isDeclaredForkHost`(`PI_ACP_FORK_HOST=1/true`,调用时读取)、`isUnsupportedHost = !isPiHost && !declared`;OMP 默认保护不变(不声明即拒绝),声明的 fork 走既有 `!isPiHost` live-merge 补偿 getBranch 落后一条消息;delegate-tool 的 CLI flag 语义保持严格 isPiHost(fork 宿主不会用 pi-only flag 拉起子进程)。`OMP_UNSUPPORTED_MESSAGE` → `UNSUPPORTED_HOST_MESSAGE`,文案同时指向两条出路(fork opt-in / billion-context proxy);docs/omp.md(+zh)同步;CONFIGURATION(+zh)env 表增 `PI_ACP_FORK_HOST`。测试:`tests/host-detection.test.ts`(Prime-shaped fixture 矩阵)+ `tests/omp-refuse.test.ts` 增 opt-in 用例。③ 回合谓词同步收紧(验收项 c):空内容 `custom_message`(纯控制信号)不再开启新回合——与投影共用同一 `extractText` 判据,`isCustomMessageEntry` 因此移回 `src/messages.ts` 与投影同源(经 type-only import 保持无环),非空 agent_message 开启新回合、UI/control/synthetic 策略在 host-adapter §1 写明

Expand Down
31 changes: 21 additions & 10 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ A **prompt pack** is a named JSON file bundling surface overrides — prompt sec
{ "compress": { "promptPack": "lean" } }
```

The pack mechanism itself — contracts, sanitization, built-in registry (`default`, `lean`), directory sources, resolver — ships in **acp-kernel ≥ 0.0.66**. The adapter resolves the active pack per turn and merges its surface into the pi session; pi-specific fields ride under the opaque `adapters.pi` namespace (see schema below) and are validated pi-side.

Pack selection rides the standard `compress` three-level cascade (`models > providers > global`, deepest-wins per turn), so different models can use different packs with zero extra config plumbing:

```json
Expand All @@ -732,9 +734,9 @@ Pack selection rides the standard `compress` three-level cascade (`models > prov

For pack name `N`, the first match wins:

1. `<project>/.pi/acp/packs/N.json` — project-local (checked last, wins — shadows both)
1. `<project>/.pi/acp/packs/N.json` — project-local (wins — shadows user-global and built-ins)
2. `~/.pi/acp/packs/N.json` — user-global
3. Built-in packs: `default`, `lean`
3. Built-in packs (shipped by acp-kernel): `default`, `lean`

Names must match `[A-Za-z0-9][A-Za-z0-9._-]*` (no `..`, no path separators); invalid names and unreadable/invalid-JSON files fall back to built-ins — the adapter never crashes on a bad pack.

Expand All @@ -751,22 +753,29 @@ Names must match `[A-Za-z0-9][A-Za-z0-9._-]*` (no `..`, no path separators); inv
"tier2DistillRules": "...",
"tier3CondenseRules": "..."
},
"promptSections": { "acpTags": "...", "tier2": null }, // same schema as acp.json promptSections
"promptSections": { "acpTags": "...", "tools": null }, // generic level: shared keys only (acpTags, tools, summariesInContext, textProtocol, textTools, functionTools)
"nudgeSections": { "efficiencyNote": "..." }, // same schema as acp.json nudgeSections
"toolPrompts": { "compress": { "description": "..." } }, // same schema as acp.json toolPrompts
"delegatePrompt": "..." // string replaces, null removes
"toolPrompts": { "compress": { "description": "..." } }, // description + paramDescriptions, any tool name
"adapters": {
"pi": { // pi-specific extras — opaque to the kernel, validated by the adapter
"promptSections": { "tier2": null, "whenToCompress": "..." }, // full 13-key tri-state schema of acp.json promptSections
"toolExtras": { "compress": { "promptSnippet": "...", "promptGuidelines": ["..."] } },
"delegatePrompt": "..." // string replaces, null removes
}
}
}
```

Every field is optional; each uses the same sanitizer as its `acp.json` counterpart, and every key in each section is tri-state (`string` replaces, `null` deletes, absent keeps the pack/built-in value).
Every field is optional, and every key in each section is tri-state (`string` replaces, `null` deletes, absent keeps the pack/built-in value). Two levels coexist: the **generic level** (`promptSections`, `toolPrompts`) is sanitized by acp-kernel and shared with other ACP hosts; the **pi level** under `adapters.pi` carries everything pi-specific (the extended section keys, `promptSnippet`/`promptGuidelines` tool extras, `delegatePrompt`) using the same sanitizers as their `acp.json` counterparts. Note the kernel only recognizes the shared keys at the top level — pi-only section keys such as `tier2` or `whenToCompress` must live under `adapters.pi.promptSections`, not at the top level (same for pi-only tool fields: `promptSnippet`/`promptGuidelines` belong in `adapters.pi.toolExtras`; top-level `toolPrompts` keeps only `description` + `paramDescriptions`).

### Merge semantics — pack base, inline wins

The effective surface for a turn = **pack defaults ⊕ inline `acp.json` overrides**, field by field:

- `promptSections` / `nudgeSections`: inline key beats pack key (including `null`).
- `toolPrompts`: per-tool, then per-field (`description`, `promptSnippet`, `promptGuidelines`), then per-param inside `paramDescriptions`.
- `delegatePrompt`: inline wins if present (including `null`).
- `promptSections`: inline key beats `adapters.pi.promptSections` key beats the generic top-level key (including `null`).
- `nudgeSections`: inline key beats pack key (including `null`).
- `toolPrompts`: per-tool, then per-field (`description`, `paramDescriptions`, `promptSnippet`, `promptGuidelines`); within the pack, `adapters.pi.toolExtras` beats the generic `toolPrompts`; inline beats both.
- `delegatePrompt`: inline wins if present (including `null`), otherwise `adapters.pi.delegatePrompt` applies.

### Programmatic sources (hosts & future installers)

Expand All @@ -780,14 +789,16 @@ interface PackSource {
}
```

Built-in packs, directory packs, and any managed registry all flow through one `createPackResolver([...sources])` — first match wins, so a **prepended source shadows everything**. That is the intended integration point for a future `bili-pi install`-style pack manager: write pack files into the user dir (zero code), or register a managed source ahead of the defaults — no core changes either way. Hosts embedding the adapter can build their own resolver and pass it to `resolveActivePack`.
Built-in packs, directory packs, and any managed registry all flow through one `createPackResolver([...sources])` — first match wins, so a **prepended source shadows everything**. That is the intended integration point for a future `bili-pi install`-style pack manager: write pack files into the user dir (zero code), or register a managed source ahead of the defaults — no core changes either way. The whole mechanism (`createPackResolver`, `createDirPackSource`, `defaultPackSources`, `builtinSource`, `sanitizePackSurface`, plus the `Pack`/`PackSource`/`PackResolver` types) is exported by acp-kernel and re-exported from this adapter's prompt-pack module, so hosts and installers depend on one implementation. Hosts embedding the adapter can build their own resolver and pass it to `resolveActivePack`.

### Risk gating

A pack's `prompts` block overrides the compression rule strings, exactly like inline `prompts` — so it is gated by the same [`acknowledgePromptsRisk`](#acknowledgepromptsrisk) switch. Without that flag set in `acp.json`, the pack's `prompts` block is ignored (everything else in the pack still applies); a warning is logged. The flag cannot be shipped inside a pack — it must be an explicit local choice.

### Built-in packs

Both built-ins are defined in acp-kernel — the adapter ships no local copies, so there is a single source of truth for every ACP host.

| Name | Purpose |
|------|---------|
| `default` | No overrides — the full built-in surface. |
Expand Down
Loading
Loading