@andares/pi-toolkits 0.3.0 → 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 +103 -7
- 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 +19 -54
- package/src/features/review/prompt.ts +6 -12
- package/src/features/review/review.test.ts +5 -24
- 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
|
|
|
@@ -36,7 +38,8 @@ pi -e ./src/index.ts
|
|
|
36
38
|
- `/ask` → footer 出现灰色 `ask` 状态,`write`/`edit` 被硬禁用
|
|
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)
|
|
@@ -63,7 +67,8 @@ pi -e ./src/index.ts
|
|
|
63
67
|
| 🛡️ **ask** 只读咨询模式 | `/ask` | 进入只读问答模式,`write`/`edit` 硬禁用,`bash` 只读沙箱 |
|
|
64
68
|
| ⭐ **favorites** 模型收藏 | `/model` 内 `ctrl+F` / `ctrl+J` | 收藏常用模型(加粗亮黄标记),`ctrl+p` 仅在收藏间循环 |
|
|
65
69
|
| 📥 **stash** 提示词暂存 | `ctrl+alt+y` | 一段提示词的暂存槽,按键交换 / 连按两次暂存并清空输入框 |
|
|
66
|
-
| 🔎 **review** 第三方代码评审 |
|
|
70
|
+
| 🔎 **review** 第三方代码评审 | `/third-review` | 召唤配置的评审模型,对刚完成的任务做查+修,重点检查「本轮需求实现 / 是否有遗漏 / 是否有错误」 |
|
|
71
|
+
| 🗜️ **compact** 独立压缩模型 | `/compact-model` | 给 `/compact` 与 auto-compact 配一个便宜快模型做总结,主模型专注对话;未配置零开销、任何异常回落 pi 默认 |
|
|
67
72
|
|
|
68
73
|
---
|
|
69
74
|
|
|
@@ -144,7 +149,9 @@ pi -e ./src/index.ts
|
|
|
144
149
|
|
|
145
150
|
<a name="review"></a>
|
|
146
151
|
|
|
147
|
-
开发任务完成后,输入
|
|
152
|
+
开发任务完成后,输入 `/third-review` 指令召唤**另一个模型**以第三方身份,对刚完成的代码做「查 + 修」:评审模型拥有**完整工具权限**,确认的问题直接改,不是只读审计。评审回合留在当前会话记录里,评审完成后**会话保持评审模型**(不自动切回)。
|
|
153
|
+
|
|
154
|
+
> **仅指令触发**:只有 `/third-review` 能发起评审。聊天中直接输入 `third-review` 不会触发(作为普通消息发给模型),避免误发。
|
|
148
155
|
|
|
149
156
|
**评审提示词重点检查三点**(逐项给出结论):
|
|
150
157
|
|
|
@@ -152,6 +159,8 @@ pi -e ./src/index.ts
|
|
|
152
159
|
2. **是否有遗漏** —— 功能点、边界情况、异常处理、兼容性、测试等
|
|
153
160
|
3. **是否有错误** —— 逻辑错误、潜在 bug、类型/编译错误、安全与性能隐患等
|
|
154
161
|
|
|
162
|
+
**范围强约束** —— 评审仅限**当前本轮修改内容**,避免扩大范围;本轮改动范围内确认的问题才直接修复,范围外的历史遗留/无关问题只记录提示、不动手改。
|
|
163
|
+
|
|
155
164
|
**评审模型配置**(`<agent-dir>/pi-toolkits-review.json`,默认 `~/.pi/agent/`):
|
|
156
165
|
|
|
157
166
|
```json
|
|
@@ -165,6 +174,88 @@ pi -e ./src/index.ts
|
|
|
165
174
|
|
|
166
175
|
---
|
|
167
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
|
+
|
|
168
259
|
## 🛠️ 开发 Development
|
|
169
260
|
|
|
170
261
|
<a name="development"></a>
|
|
@@ -182,10 +273,14 @@ pnpm test # vitest (all feature unit tests)
|
|
|
182
273
|
```text
|
|
183
274
|
src/
|
|
184
275
|
├── index.ts # entry point: aggregates feature modules
|
|
185
|
-
├── lib/ # shared infrastructure (tool-set snapshot/restore
|
|
276
|
+
├── lib/ # shared infrastructure (tool-set snapshot/restore,
|
|
277
|
+
│ # model-key resolution shared by review & compact)
|
|
186
278
|
└── features/ # feature modules — one directory per feature
|
|
187
279
|
├── ask/ # ask mode: command + state machine, bash sandbox,
|
|
188
280
|
│ # system prompt banner, tests
|
|
281
|
+
├── compact/ # dedicated compaction model: session_before_compact
|
|
282
|
+
│ # takeover + /compact-model, store, prompts,
|
|
283
|
+
│ # tests
|
|
189
284
|
├── favorites/ # model favorites: selector + cycle patches,
|
|
190
285
|
│ # persisted store, tests
|
|
191
286
|
├── review/ # third-party review: input/command triggers,
|
|
@@ -218,6 +313,7 @@ PRs and issues welcome. A few conventions:
|
|
|
218
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/`
|
|
219
314
|
- **Tests** — every feature ships vitest cases; keep them deterministic (injectable clocks/state), no writes to the real agent dir
|
|
220
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
|
|
221
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
|
|
222
318
|
- **Quality gate** — `pnpm typecheck && pnpm test` must pass before submitting
|
|
223
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
|
},
|