@andares/pi-toolkits 0.3.1 → 0.4.0
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 +96 -4
- package/package.json +11 -5
- package/src/features/compact/compact.test.ts +661 -0
- package/src/features/compact/constants.ts +13 -0
- package/src/features/compact/index.ts +375 -0
- package/src/features/compact/prompt.ts +238 -0
- package/src/features/compact/store.ts +137 -0
- package/src/features/favorites/index.ts +5 -3
- package/src/features/favorites/patch-cycle.ts +62 -21
- package/src/features/favorites/patch-selector.ts +22 -20
- package/src/features/review/index.ts +12 -22
- package/src/features/review/review.test.ts +4 -2
- package/src/features/review/store.ts +0 -5
- package/src/index.ts +3 -0
- package/src/lib/model-config.ts +44 -0
package/README.md
CHANGED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
[](https://www.npmjs.com/package/@andares/pi-toolkits)
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://pnpm.io)
|
|
11
|
-
[](https://github.com/earendil-works/pi)
|
|
12
12
|
[](https://github.com/andares/pi-toolkits)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
Currently ships
|
|
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
|
|
|
@@ -169,6 +174,88 @@ pi -e ./src/index.ts
|
|
|
169
174
|
|
|
170
175
|
---
|
|
171
176
|
|
|
177
|
+
## 🗜️ compact — 独立压缩模型
|
|
178
|
+
|
|
179
|
+
<a name="compact"></a>
|
|
180
|
+
|
|
181
|
+
pi 的 `/compact` 与 auto-compact 默认**用当前会话模型**做上下文总结——主模型往往贵且慢,而压缩总结是典型的「便宜快模型就能干好」的任务。本功能配置一个独立模型接管**全部三种压缩触发**的总结:
|
|
182
|
+
|
|
183
|
+
| 触发 | 接管后 |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| 手动 `/compact [instructions]` | 压缩模型总结,自定义 focus 照常注入 |
|
|
186
|
+
| auto-compact 阈值触发 | 压缩模型总结 |
|
|
187
|
+
| context overflow 恢复 | 压缩模型总结,重试行为不变 |
|
|
188
|
+
|
|
189
|
+
**接管后与 pi 内建行为完全一致的部分**(逐字同步 0.87.1 内建实现,只换执行模型):
|
|
190
|
+
|
|
191
|
+
- **摘要格式** —— Goal / Progress / Key Decisions 结构化 checkpoint;已有摘要时用迭代更新版 prompt,信息延续不丢
|
|
192
|
+
- **切分行为** —— 保留最近 `keepRecentTokens` 的策略、`firstKeptEntryId` / `tokensBefore` 原样回传,不动
|
|
193
|
+
- **输出预算** —— 与内建同公式(历史段 0.8×、切分前缀段 0.5× `reserveTokens`,再按模型输出上限收敛)
|
|
194
|
+
- **文件清单尾部** —— `<read-files>` / `<modified-files>` 标签照常拼在摘要尾部,details 同形状维护
|
|
195
|
+
- **用量统计** —— 压缩模型的 token/cost 计入 session 统计
|
|
196
|
+
- **可取消** —— 压缩进行中 `Esc` 干净取消(信号透传到底层调用)
|
|
197
|
+
|
|
198
|
+
**配置**(`<agent-dir>/pi-toolkits-compact.json`,默认 `~/.pi/agent/`):
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{ "model": "google/gemini-2.5-flash" }
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
- `/compact-model` —— 查看/更换/清除:弹出可用模型列表(标题显示当前配置,首项「✕ 清除配置」),选中即写入;取消则不修改
|
|
205
|
+
- 未配置 = 功能未启用,全部走 pi 默认,零开销;footer 出现灰色 `compact` 状态 = 已配置
|
|
206
|
+
|
|
207
|
+
**无损回落**(本功能永远不会把压缩「做挂」):
|
|
208
|
+
|
|
209
|
+
| 情形 | 行为 |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| 未配置 | 直接回落 pi 默认压缩 |
|
|
212
|
+
| 配置的模型不可用(如从 models.json 删除) | warning 提示 + 回落 |
|
|
213
|
+
| 总结失败 / 摘要为空 / 命中 token 上限 | 提示 + 回落 pi 默认压缩 |
|
|
214
|
+
| 用户取消(`Esc`) | 干净取消,无错误刷屏 |
|
|
215
|
+
|
|
216
|
+
> **实现说明**:接管点是官方的 `session_before_compact` 扩展事件(三种触发都会先经过);返回压缩结果即完全接管,返回 `undefined` 即回落内建。auto-compact 路径绝不弹任何对话框(handler 内只 notify)。`/tree` 分支总结(`session_before_tree`)是另一个事件,本期不接管,留作后续迭代。
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
**pnpm is the only supported toolchain** — never use `npm install` / `npm publish` in this repo.
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pnpm install # install deps
|
|
224
|
+
pnpm typecheck # tsc --noEmit
|
|
225
|
+
pnpm test # vitest (all feature unit tests)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 项目结构 Project structure
|
|
229
|
+
|
|
230
|
+
```text
|
|
231
|
+
src/
|
|
232
|
+
├── index.ts # entry point: aggregates feature modules
|
|
233
|
+
├── lib/ # shared infrastructure (tool-set snapshot/restore)
|
|
234
|
+
└── features/ # feature modules — one directory per feature
|
|
235
|
+
├── ask/ # ask mode: command + state machine, bash sandbox,
|
|
236
|
+
│ # system prompt banner, tests
|
|
237
|
+
├── favorites/ # model favorites: selector + cycle patches,
|
|
238
|
+
│ # persisted store, tests
|
|
239
|
+
├── review/ # third-party review: input/command triggers,
|
|
240
|
+
│ # review-model config store, prompt, tests
|
|
241
|
+
└── stash/ # prompt stash: hotkey state machine + tests
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**新增功能 · adding a feature**:create `src/features/<name>/` exporting `registerXxx(pi)` and call it from `src/index.ts`. Existing modules stay untouched. Each feature ships its own `*.test.ts` (vitest) — keep them deterministic (inject clocks/state, no real agent-dir writes).
|
|
245
|
+
|
|
246
|
+
**发布 · publishing**(pnpm-only,one command):
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
pnpm release patch # 0.1.2 → 0.1.3
|
|
250
|
+
pnpm release minor # 0.1.2 → 0.2.0 (patch zeroed)
|
|
251
|
+
pnpm release major # 0.1.2 → 1.0.0 (minor + patch zeroed)
|
|
252
|
+
pnpm release patch --dry-run # preview without changing anything
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
`release` 要求且仅要求 `major | minor | patch` 之一;上级递增清零下级。执行链:校验 → `typecheck + test` 门禁 → 改版本 → git commit + `vX.Y.Z` tag → `pnpm publish`(`prepublishOnly` 二次门禁)。
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
172
259
|
## 🛠️ 开发 Development
|
|
173
260
|
|
|
174
261
|
<a name="development"></a>
|
|
@@ -186,10 +273,14 @@ pnpm test # vitest (all feature unit tests)
|
|
|
186
273
|
```text
|
|
187
274
|
src/
|
|
188
275
|
├── index.ts # entry point: aggregates feature modules
|
|
189
|
-
├── lib/ # shared infrastructure (tool-set snapshot/restore
|
|
276
|
+
├── lib/ # shared infrastructure (tool-set snapshot/restore,
|
|
277
|
+
│ # model-key resolution shared by review & compact)
|
|
190
278
|
└── features/ # feature modules — one directory per feature
|
|
191
279
|
├── ask/ # ask mode: command + state machine, bash sandbox,
|
|
192
280
|
│ # system prompt banner, tests
|
|
281
|
+
├── compact/ # dedicated compaction model: session_before_compact
|
|
282
|
+
│ # takeover + /compact-model, store, prompts,
|
|
283
|
+
│ # tests
|
|
193
284
|
├── favorites/ # model favorites: selector + cycle patches,
|
|
194
285
|
│ # persisted store, tests
|
|
195
286
|
├── review/ # third-party review: input/command triggers,
|
|
@@ -222,6 +313,7 @@ PRs and issues welcome. A few conventions:
|
|
|
222
313
|
- **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
314
|
- **Tests** — every feature ships vitest cases; keep them deterministic (injectable clocks/state), no writes to the real agent dir
|
|
224
315
|
- **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
|
|
316
|
+
- **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
317
|
- **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
318
|
- **Quality gate** — `pnpm typecheck && pnpm test` must pass before submitting
|
|
227
319
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andares/pi-toolkits",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Integrated toolkit extension for pi —
|
|
3
|
+
"version": "0.4.0",
|
|
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.
|
|
34
|
+
"@earendil-works/pi-tui": "^0.87.1"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
|
-
"@earendil-works/pi-ai": "^0.
|
|
33
|
-
"@earendil-works/pi-coding-agent": "^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
|
},
|