@zhushanwen/pi-unified-hooks 0.0.1 → 0.0.2
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 +29 -42
- package/package.json +8 -3
- package/src/hooks/tool-error-handler.ts +1 -1
package/README.md
CHANGED
|
@@ -1,55 +1,42 @@
|
|
|
1
|
-
# unified-hooks
|
|
1
|
+
# unified-hooks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
统一 hooks 管理器 — 将散落的 hooks 收集到一个扩展中统一维护,每个 hook 可独立启用/禁用。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 功能
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
ln -s /path/to/xyz-pi-extensions/unified-hooks ~/.pi/agent/extensions/unified-hooks
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Available Hooks
|
|
12
|
-
|
|
13
|
-
### edit-whitespace-autofix
|
|
14
|
-
|
|
15
|
-
When edit tool fails due to whitespace mismatch, injects a steering message that tells the AI to fix whitespace and retry.
|
|
7
|
+
### 内置 Hooks
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
| Hook | 说明 |
|
|
10
|
+
|------|------|
|
|
11
|
+
| `edit-whitespace-autofix` | edit 工具因空白字符不匹配失败时,自动注入 steering 让 AI 修复空白并重试 |
|
|
12
|
+
| `tool-error-handler` | 记录所有工具执行错误到控制台,方便调试 |
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
1. Detect whitespace mismatch error from edit tool
|
|
24
|
-
2. Extract the file path from tool args
|
|
25
|
-
3. Inject steer message with `fix_whitespace.py --fix <file>` command
|
|
26
|
-
4. AI automatically fixes whitespace and retries the edit
|
|
14
|
+
### 扩展方式
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
在 `src/hooks/` 下新建 hook 模块,然后在 `src/index.ts` 的 `hookModules` 数组中注册即可。
|
|
29
17
|
|
|
30
|
-
|
|
18
|
+
## 安装
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
20
|
+
```bash
|
|
21
|
+
# symlink 方式(开发推荐)
|
|
22
|
+
ln -s /path/to/xyz-pi-extensions-workspace/main/packages/unified-hooks \
|
|
23
|
+
~/.pi/agent/extensions/unified-hooks
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Your logic
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
```
|
|
25
|
+
# npm 方式(正式)
|
|
26
|
+
pi install npm:@zhushanwen/pi-unified-hooks
|
|
27
|
+
```
|
|
46
28
|
|
|
47
|
-
|
|
29
|
+
## 使用
|
|
48
30
|
|
|
49
|
-
|
|
31
|
+
安装后自动生效。edit 空白修复无需配置,工具错误日志自动输出到控制台。
|
|
50
32
|
|
|
51
|
-
##
|
|
33
|
+
## 文件结构
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
|
|
35
|
+
```
|
|
36
|
+
unified-hooks/
|
|
37
|
+
├── index.ts
|
|
38
|
+
└── src/
|
|
39
|
+
├── index.ts # 入口 — hook 注册
|
|
40
|
+
└── hooks/
|
|
41
|
+
└── tool-error-handler.ts # 工具错误处理
|
|
42
|
+
```
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-unified-hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Unified hooks extension - collect scattered hooks in one place for easy maintenance",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"pi": {
|
|
8
|
+
"extensions": [
|
|
9
|
+
"./index.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
7
12
|
"keywords": [
|
|
8
|
-
"pi",
|
|
13
|
+
"pi-package",
|
|
9
14
|
"extension",
|
|
10
15
|
"hooks"
|
|
11
16
|
],
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
9
9
|
|
|
10
10
|
export function setupToolErrorHandler(pi: ExtensionAPI): void {
|
|
11
|
-
pi.on("tool_execution_end", async (event) => {
|
|
11
|
+
pi.on("tool_execution_end", async (event: any) => {
|
|
12
12
|
if (!event.isError) return;
|
|
13
13
|
console.log(`[unified-hooks] ${event.toolName} error (callId=${event.toolCallId})`);
|
|
14
14
|
});
|