Repository navigation
feat(prompts): prompt packs — one-line surface switching via compress.promptPack - #397
Conversation
….promptPack (closes #396) Pack selection reuses the compress three-level cascade (models > providers > global) — no new providers mechanism. Discovery: project .pi/acp/packs/N.json shadows ~/.pi/acp/packs/N.json shadows built-ins (default, lean). Merge: pack base layer, inline acp.json wins per field (sections per key incl null; toolPrompts per tool/field/param; delegatePrompt inline incl null). Pack prompts gated by acknowledgePromptsRisk like inline prompts. Built-in lean pack: eight one-line acpTags rules + one-line tool descriptions, snippets/guidelines blanked — 5422→1312 bytes (~76% smaller surface), compression rules stay kernel defaults via nudges (from #410). - src/prompt-pack.ts: LEAN_PROMPT/LEAN_PACK/BUILTIN_PACKS, discoverPack, resolvePackName/resolveActivePack, packSurface/mergeSurface, readToolSurfaceWithPacks - src/config.ts: CompressSettings.promptPack + mergeCompress cascade - src/system-prompt.ts: 4 rule-slot keys with kernel defaultPrompts defaults - src/index.ts: tool registration (factory-time pack-aware read), nudge and system-prompt sites resolve pack per turn via ctx.model - tests/prompt-pack.test.ts: 10 cases - CONFIGURATION.md(+zh-CN): compress.promptPack + Prompt Packs section
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-397Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr397.tgz
pi install ./packageThis comment is automatically updated on each push. |
…acks from ctx.cwd Review fix for the prompt-packs wiring (found in #397 review): - wireSystemPrompt resolved prompts only when merged.prompts was non-empty, so switching from a model whose pack ships prompt overrides to one without left the previous pack's rules stuck in runtime.prompts. Resolve unconditionally: resolvePrompts({}) returns kernel defaults, so switch-away resets correctly. On risk-gate failure fall back to defaultPrompts (same as session_start) and dedupe the warning by the gated key set instead of logging every turn. - Pack discovery in before_agent_start / activeNudgeSections now uses ctx.cwd (process.cwd() fallback), matching reloadConfig(ctx.cwd): project acp.json and .pi/acp/packs/ resolve from the same directory. - tests/prompt-pack.test.ts: +2 wiring-level regression tests — per-model pack prompt application with switch-away reset (fails on the pre-fix code, verified by stash), and risk gating of pack prompts without acknowledgePromptsRisk.
[bot] 🏷 Review complete — 已在 PR 分支直接补修复 commit Diff 整洁度(第一道关) ✅ 单 commit 本地验证(分支上实跑): 设计审核结论(均通过):发现顺序 project > home > built-in ✓;包名白名单 + 发现并已修的问题(2 个,commit
补了 2 个 wiring 级回归测试(per-model 应用 + 切走回默认;无 risk flag 时 pack prompts 被丢弃)。用 stash 在修复前代码上验证过:switch-away 测试确实 fail,修复后 11/11 全绿。 小观察(未改,供参考):nudge 渲染路径每次调用都会 关于留痕:问题 1 只存在于本 PR 未合并的代码中(从未发布),完整记录在本回复 + 修复 commit message 里,按"minor → report only"未另开 issue;若你希望单独建 issue 留档,说一声我就开。 中文摘要:审查 prompt packs(PR #397)时发现一个真 bug——从带压缩规则的 pack 切到无 pack 的模型后旧规则残留在 runtime 中不重置(另有 pack 发现目录与配置加载目录不一致的小问题),已直接在 PR 分支补了无条件重置 + cwd 对齐 + 2 个回归测试(验证过修复前必挂),typecheck/785 测试/build 全绿,可以合并。 |
…ource/PackResolver - src/packs/types.ts: Pack (name+sanitized surface+provenance), PackSource (resolve/list), PackSurface, PromptPackFile, isValidPackName - src/packs/lean.ts: leanPack exported as a standalone Pack module - src/packs/builtin.ts: defaultPack + builtinSource (registry map) - src/packs/dir.ts: createDirPackSource(id, dir) — same factory serves project/user/any future installer-managed dir - src/prompt-pack.ts: createPackResolver / defaultPackSources ([project > user > builtin]) / listPacks; prepended sources shadow everything — the integration point for a future bili-pi install pack manager (write files or register a managed source, zero core rewrite) - index.ts/resolveActivePack now consume Pack.surface directly - tests: 12 cases incl. custom-source shadowing and dir list() resilience
|
Rebased on top of 78f6f0f (review fix) — both intents merged. Refactor: packs are now a pluggable source chain (per review feedback on the architecture)
// src/packs/types.ts
interface Pack { name; version?; description?; surface: PackSurface; source: string }
interface PackSource { id: string; resolve(name): Pack | null; list?(): Pack[] }
Integration point for a future Review-fix commit preserved through the refactor: unconditional Tests: 12 → 14 (kept the two wiring regressions; added custom-source shadowing + dir |
…acks from ctx.cwd Review fix for the prompt-packs wiring (found in ranxianglei#397 review): - wireSystemPrompt resolved prompts only when merged.prompts was non-empty, so switching from a model whose pack ships prompt overrides to one without left the previous pack's rules stuck in runtime.prompts. Resolve unconditionally: resolvePrompts({}) returns kernel defaults, so switch-away resets correctly. On risk-gate failure fall back to defaultPrompts (same as session_start) and dedupe the warning by the gated key set instead of logging every turn. - Pack discovery in before_agent_start / activeNudgeSections now uses ctx.cwd (process.cwd() fallback), matching reloadConfig(ctx.cwd): project acp.json and .pi/acp/packs/ resolve from the same directory. - tests/prompt-pack.test.ts: +2 wiring-level regression tests — per-model pack prompt application with switch-away reset (fails on the pre-fix code, verified by stash), and risk gating of pack prompts without acknowledgePromptsRisk.
…-packs-396 feat(prompts): prompt packs — one-line surface switching via compress.promptPack
Closes #396. Extends #252 (shipped in #395);
leanpack adapted from the #410 investigation.What
compress.promptPack: "<name>"selects a named bundle of surface overrides — promptSections, nudgeSections, toolPrompts, delegatePrompt, and the 4 load-bearing compression rules — as the base layer under inlineacp.jsonoverrides.No new providers mechanism: pack selection rides the standard
compressthree-level cascade (models > providers > global, deepest wins, resolved per turn from the active model). Switching models switches packs automatically;mergeCompressalready did the plumbing.{ "compress": { "promptPack": "lean" } } { "compress": { "providers": { "zhipu": { "promptPack": "lean" } } } }Discovery
<project>/.pi/acp/packs/N.json>~/.pi/acp/packs/N.json> built-ins (default,lean). Name whitelist[A-Za-z0-9][A-Za-z0-9._-]*(no.., no separators); invalid names and bad JSON fall back to built-ins — never crash.Merge semantics — pack base, inline wins
null)paramDescriptionsnull)prompts(4 compression rules): gated byacknowledgePromptsRiskexactly like inlineprompts; flag cannot ship inside a pack — explicit local choice onlyBuilt-in
leanpackToken-lean surface: eight one-line acpTags rules (refs / what to compress / what to preserve verbatim / recall tools / renumbering recovery / decompress-to-file / throttle resume / summaries-are-history), one-line tool descriptions, snippets/guidelines blanked. Measured 5422 → 1312 bytes (~76% smaller) vs the default surface; compression rules stay kernel defaults, delivered by nudges on demand.
Implementation
src/prompt-pack.ts(new):LEAN_PROMPT,LEAN_PACK,BUILTIN_PACKS,discoverPack,resolvePackName/resolveActivePack,packSurface,mergeSurface,readToolSurfaceWithPackssrc/config.ts:CompressSettings.promptPack+ cascade inmergeCompresssrc/system-prompt.ts: 4 rule-slot keys with kerneldefaultPromptsdefaultssrc/index.ts: tool registration uses pack-aware factory-time read; nudge + system-prompt sites resolve the pack per turn viactx.modeltests/prompt-pack.test.ts: 10 cases (surface shape, lean collapse, cascade, discovery/shadowing, traversal rejection, merge precedence, risk-gate keys, sanitization, tool-surface stack)compress.promptPackreference + full Prompt Packs sectionValidation
npm run typecheck✅npm test: 783 pass / 0 fail (3 env skips) ✅npm run build✅