@andares/pi-toolkits 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,11 +8,13 @@
8
8
  [![npm version](https://img.shields.io/npm/v/@andares/pi-toolkits?label=npm&logo=npm)](https://www.npmjs.com/package/@andares/pi-toolkits)
9
9
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10
10
  [![Package Manager](https://img.shields.io/badge/package%20manager-pnpm-orange?logo=pnpm)](https://pnpm.io)
11
- [![pi >= 0.84](https://img.shields.io/badge/pi-%3E%3D0.84.0-blueviolet)](https://github.com/earendil-works/pi)
11
+ [![pi >= 0.87](https://img.shields.io/badge/pi-%3E%3D0.87.0-blueviolet)](https://github.com/earendil-works/pi)
12
12
  [![GitHub](https://img.shields.io/badge/github-andares%2Fpi--toolkits-181717?logo=github)](https://github.com/andares/pi-toolkits)
13
13
 
14
- 一句话介绍:目前包含四个开箱即用的功能——**只读咨询模式** `ask`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `third-review`,后续持续追加。
15
- Currently ships four ready-to-use capabilities — **ask mode**, **model favorites**, **prompt stash** and **third-party code review** — with more to come.
14
+ 一句话介绍:目前包含五个开箱即用的功能——**只读咨询模式** `ask`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `third-review`、**独立压缩模型** `compact-model`,后续持续追加。
15
+ Currently ships five ready-to-use capabilities — **ask mode**, **model favorites**, **prompt stash**, **third-party code review** and a **dedicated compaction model** — with more to come.
16
+
17
+ **版本要求 · Requirements**:pi ≥ 0.87.0(以 0.87.x 内建压缩行为为基准开发与验证;favorites 的两处运行时 patch 已对齐 0.87 的选择器布局与 `cycleModel` 语义)。
16
18
 
17
19
  ---
18
20
 
@@ -37,6 +39,7 @@ pi -e ./src/index.ts
37
39
  - `/model`(或 `ctrl+l`)→ 选择器顶部出现收藏提示行
38
40
  - 输入框内按 `ctrl+alt+y` → 当前提示词被暂存并清空输入框
39
41
  - 完成一个开发任务后输入 `/third-review` → 切换到评审模型执行查+修
42
+ - `/compact-model` 选一个便宜快模型 → 之后 `/compact` 与自动压缩的总结都由它执行(footer 出现灰色 `compact` 状态)
40
43
 
41
44
  ---
42
45
 
@@ -48,6 +51,7 @@ pi -e ./src/index.ts
48
51
  - [⭐ favorites — 模型收藏](#favorites)
49
52
  - [📥 stash — 提示词暂存](#stash)
50
53
  - [🔎 review — 第三方代码评审](#review)
54
+ - [🗜️ compact — 独立压缩模型](#compact)
51
55
  - [开发 Development](#development)
52
56
  - [贡献 Contributing](#contributing)
53
57
  - [许可 License](#license)
@@ -64,6 +68,7 @@ pi -e ./src/index.ts
64
68
  | ⭐ **favorites** 模型收藏 | `/model` 内 `ctrl+F` / `ctrl+J` | 收藏常用模型(加粗亮黄标记),`ctrl+p` 仅在收藏间循环 |
65
69
  | 📥 **stash** 提示词暂存 | `ctrl+alt+y` | 一段提示词的暂存槽,按键交换 / 连按两次暂存并清空输入框 |
66
70
  | 🔎 **review** 第三方代码评审 | `/third-review` | 召唤配置的评审模型,对刚完成的任务做查+修,重点检查「本轮需求实现 / 是否有遗漏 / 是否有错误」 |
71
+ | 🗜️ **compact** 独立压缩模型 | `/compact-model` | 给 `/compact` 与 auto-compact 配一个便宜快模型做总结,主模型专注对话;未配置零开销、任何异常回落 pi 默认 |
67
72
 
68
73
  ---
69
74
 
@@ -156,19 +161,67 @@ pi -e ./src/index.ts
156
161
 
157
162
  **范围强约束** —— 评审仅限**当前本轮修改内容**,避免扩大范围;本轮改动范围内确认的问题才直接修复,范围外的历史遗留/无关问题只记录提示、不动手改。
158
163
 
159
- **评审模型配置**(`<agent-dir>/pi-toolkits-review.json`,默认 `~/.pi/agent/`):
164
+ **评审模型选择**(每次 `/third-review` 都会弹出选择界面):
165
+
166
+ - `/third-review` → 弹出模型列表(与 `/model` 同源):**第一项 = 当前配置的模型**(默认高亮),直接**回车**即用它开始评审;也可移动到其他模型
167
+ - **换选其他模型** → 立即写回配置(**落盘 + 内存**),**下次默认使用该模型**;标题实时显示当前配置
168
+ - **取消**(Esc)→ 不执行评审,配置不变
169
+ - 配置持久化于 `<agent-dir>/pi-toolkits-review.json`(默认 `~/.pi/agent/`):
160
170
 
161
171
  ```json
162
172
  { "model": "anthropic/claude-sonnet-4" }
163
173
  ```
164
174
 
165
- - `/review-model` —— 查看/更换评审模型:弹出模型列表(标题显示当前配置),选中即写入;取消则不修改配置
166
- - **未配置 / 配置的模型已不可用**(如在 pi 的 models.json 里删掉了该模型)→ 提示「评审模型不存在」,弹出**可用模型选择列表**(与 `/model` 同源);选中后**写回配置并立即执行**
175
+ - `/review-model` —— 单独的配置入口:弹出同一列表(不改会话模型,只更新默认配置)
176
+ - **未配置 / 配置的模型已不可用**(如在 pi 的 models.json 里删掉了该模型)→ 提示后照常弹出列表(此时无默认项)
167
177
  - 任务仍在进行中(agent 未空闲)时触发 → 提示等待,不执行;同一时间只允许一个评审
168
178
  - footer 出现灰色 `review` 状态 = 已配置评审模型
169
179
 
170
180
  ---
171
181
 
182
+ ## 🗜️ compact — 独立压缩模型
183
+
184
+ <a name="compact"></a>
185
+
186
+ pi 的 `/compact` 与 auto-compact 默认**用当前会话模型**做上下文总结——主模型往往贵且慢,而压缩总结是典型的「便宜快模型就能干好」的任务。本功能配置一个独立模型接管**全部三种压缩触发**的总结:
187
+
188
+ | 触发 | 接管后 |
189
+ | --- | --- |
190
+ | 手动 `/compact [instructions]` | 压缩模型总结,自定义 focus 照常注入 |
191
+ | auto-compact 阈值触发 | 压缩模型总结 |
192
+ | context overflow 恢复 | 压缩模型总结,重试行为不变 |
193
+
194
+ **接管后与 pi 内建行为完全一致的部分**(逐字同步 0.87.1 内建实现,只换执行模型):
195
+
196
+ - **摘要格式** —— Goal / Progress / Key Decisions 结构化 checkpoint;已有摘要时用迭代更新版 prompt,信息延续不丢
197
+ - **切分行为** —— 保留最近 `keepRecentTokens` 的策略、`firstKeptEntryId` / `tokensBefore` 原样回传,不动
198
+ - **输出预算** —— 与内建同公式(历史段 0.8×、切分前缀段 0.5× `reserveTokens`,再按模型输出上限收敛)
199
+ - **文件清单尾部** —— `<read-files>` / `<modified-files>` 标签照常拼在摘要尾部,details 同形状维护
200
+ - **用量统计** —— 压缩模型的 token/cost 计入 session 统计
201
+ - **可取消** —— 压缩进行中 `Esc` 干净取消(信号透传到底层调用)
202
+
203
+ **配置**(`<agent-dir>/pi-toolkits-compact.json`,默认 `~/.pi/agent/`):
204
+
205
+ ```json
206
+ { "model": "google/gemini-2.5-flash" }
207
+ ```
208
+
209
+ - `/compact-model` —— 查看/更换/清除:弹出可用模型列表(标题显示当前配置,首项「✕ 清除配置」),选中即写入;取消则不修改
210
+ - 未配置 = 功能未启用,全部走 pi 默认,零开销;footer 出现灰色 `compact` 状态 = 已配置
211
+
212
+ **无损回落**(本功能永远不会把压缩「做挂」):
213
+
214
+ | 情形 | 行为 |
215
+ | --- | --- |
216
+ | 未配置 | 直接回落 pi 默认压缩 |
217
+ | 配置的模型不可用(如从 models.json 删除) | warning 提示 + 回落 |
218
+ | 总结失败 / 摘要为空 / 命中 token 上限 | 提示 + 回落 pi 默认压缩 |
219
+ | 用户取消(`Esc`) | 干净取消,无错误刷屏 |
220
+
221
+ > **实现说明**:接管点是官方的 `session_before_compact` 扩展事件(三种触发都会先经过);返回压缩结果即完全接管,返回 `undefined` 即回落内建。auto-compact 路径绝不弹任何对话框(handler 内只 notify)。`/tree` 分支总结(`session_before_tree`)是另一个事件,本期不接管,留作后续迭代。
222
+
223
+ ---
224
+
172
225
  ## 🛠️ 开发 Development
173
226
 
174
227
  <a name="development"></a>
@@ -186,10 +239,14 @@ pnpm test # vitest (all feature unit tests)
186
239
  ```text
187
240
  src/
188
241
  ├── index.ts # entry point: aggregates feature modules
189
- ├── lib/ # shared infrastructure (tool-set snapshot/restore)
242
+ ├── lib/ # shared infrastructure (tool-set snapshot/restore,
243
+ │ # model-key resolution shared by review & compact)
190
244
  └── features/ # feature modules — one directory per feature
191
245
  ├── ask/ # ask mode: command + state machine, bash sandbox,
192
246
  │ # system prompt banner, tests
247
+ ├── compact/ # dedicated compaction model: session_before_compact
248
+ │ # takeover + /compact-model, store, prompts,
249
+ │ # tests
193
250
  ├── favorites/ # model favorites: selector + cycle patches,
194
251
  │ # persisted store, tests
195
252
  ├── review/ # third-party review: input/command triggers,
@@ -208,7 +265,7 @@ pnpm release major # 0.1.2 → 1.0.0 (minor + patch zeroed)
208
265
  pnpm release patch --dry-run # preview without changing anything
209
266
  ```
210
267
 
211
- `release` 要求且仅要求 `major | minor | patch` 之一;上级递增清零下级。执行链:校验 → `typecheck + test` 门禁 → 改版本 → git commit + `vX.Y.Z` tag → `pnpm publish`(`prepublishOnly` 二次门禁)。
268
+ `release` 要求且仅要求 `major | minor | patch` 之一;上级递增清零下级。执行链:**工作区必须干净(有未提交变更直接中止,保证 tag 内容 == 发布内容)** → `typecheck + test` 门禁 → 改版本 → git commit + `vX.Y.Z` tag(自检 tag==HEAD 且工作区干净) → `pnpm publish`(`prepublishOnly` 二次门禁) → 只推当前分支 + 当前 tag 并校验远端哈希一致(远端 tag 不一致则跳过 Release 创建)。
212
269
 
213
270
  ---
214
271
 
@@ -222,6 +279,7 @@ PRs and issues welcome. A few conventions:
222
279
  - **Feature-module pattern** — one directory per feature (`src/features/<name>/`), export `registerXxx(pi)`, register in `src/index.ts`; shared infra goes in `src/lib/`
223
280
  - **Tests** — every feature ships vitest cases; keep them deterministic (injectable clocks/state), no writes to the real agent dir
224
281
  - **Built-in patches** (favorites) must stay **version-guarded and idempotent** — verify the target prototype members exist before patching, guard against double-apply, degrade with a `console.warn` instead of breaking the extension
282
+ - **Built-in prompt sync** (compact) — the summarization prompts in `src/features/compact/prompt.ts` are copied verbatim from pi's built-in compaction; when upgrading the pi dependency, diff `dist/core/compaction/compaction.js` (and `utils.js`) and update the strings + assembly helpers to match, keeping takeover output byte-compatible with stock
225
283
  - **Keybindings** — before picking a new shortcut, check pi defaults + reserved keys, terminal control chars, and OS/terminal-emulator grabs; prefer `ctrl+alt+<letter>` for cross-platform safety
226
284
  - **Quality gate** — `pnpm typecheck && pnpm test` must pass before submitting
227
285
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@andares/pi-toolkits",
3
- "version": "0.3.1",
4
- "description": "Integrated toolkit extension for pi — currently provides ask mode (read-only Q&A); more features to come",
3
+ "version": "0.4.1",
4
+ "description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), model favorites, prompt stash, third-party code review, and a dedicated compaction model",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -19,6 +19,11 @@
19
19
  "pi-extension",
20
20
  "ask-mode",
21
21
  "readonly",
22
+ "model-favorites",
23
+ "prompt-stash",
24
+ "code-review",
25
+ "compaction",
26
+ "compact-model",
22
27
  "toolkit"
23
28
  ],
24
29
  "peerDependencies": {
@@ -26,11 +31,12 @@
26
31
  },
27
32
  "dependencies": {
28
33
  "@dreki-gg/pi-command-sandbox": "^0.4.3",
29
- "@earendil-works/pi-tui": "^0.84.0"
34
+ "@earendil-works/pi-tui": "^0.87.1"
30
35
  },
31
36
  "devDependencies": {
32
- "@earendil-works/pi-ai": "^0.84.0",
33
- "@earendil-works/pi-coding-agent": "^0.84.0",
37
+ "@earendil-works/pi-ai": "^0.87.1",
38
+ "@earendil-works/pi-coding-agent": "^0.87.1",
39
+ "@types/node": "^26.6.2",
34
40
  "typescript": "^5.6.0",
35
41
  "vitest": "^4.1.10"
36
42
  },