@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 CHANGED
@@ -1,55 +1,42 @@
1
- # unified-hooks — Unified Hooks Extension
1
+ # unified-hooks
2
2
 
3
- Collect scattered hooks in one place for easy maintenance. Each hook is a self-contained module that can be enabled/disabled independently.
3
+ 统一 hooks 管理器 — 将散落的 hooks 收集到一个扩展中统一维护,每个 hook 可独立启用/禁用。
4
4
 
5
- ## Installation
5
+ ## 功能
6
6
 
7
- ```bash
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
- **Trigger patterns:**
18
- - `Could not find the exact text`
19
- - `oldText must match exactly`
20
- - `Could not find edits[`
9
+ | Hook | 说明 |
10
+ |------|------|
11
+ | `edit-whitespace-autofix` | edit 工具因空白字符不匹配失败时,自动注入 steering 让 AI 修复空白并重试 |
12
+ | `tool-error-handler` | 记录所有工具执行错误到控制台,方便调试 |
21
13
 
22
- **Behavior:**
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
- ### tool-error-handler
16
+ 在 `src/hooks/` 下新建 hook 模块,然后在 `src/index.ts` 的 `hookModules` 数组中注册即可。
29
17
 
30
- Logs all tool execution errors to console for debugging.
18
+ ## 安装
31
19
 
32
- ## Adding New Hooks
33
-
34
- 1. Create `src/hooks/my-hook.ts`:
35
- ```typescript
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
- export function setupMyHook(pi: ExtensionAPI): void {
39
- pi.on("tool_execution_end", async (event) => {
40
- if (event.toolName === "edit" && event.isError) {
41
- // Your logic
42
- }
43
- });
44
- }
45
- ```
25
+ # npm 方式(正式)
26
+ pi install npm:@zhushanwen/pi-unified-hooks
27
+ ```
46
28
 
47
- 2. Register in `src/index.ts` hookModules array
29
+ ## 使用
48
30
 
49
- 3. Type check: `npx tsc --noEmit`
31
+ 安装后自动生效。edit 空白修复无需配置,工具错误日志自动输出到控制台。
50
32
 
51
- ## Important API Notes
33
+ ## 文件结构
52
34
 
53
- - Use `pi.sendUserMessage()` in event handlers, **not** `ctx.sendUserMessage()` (only available in command context)
54
- - `tool_execution_end` event has `{ toolCallId, toolName, args, result, isError }`
55
- - Inject direct instructions in steer messages, don't try to invoke `/skill-name` via text
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.1",
3
+ "version": "0.0.2",
4
4
  "description": "Unified hooks extension - collect scattered hooks in one place for easy maintenance",
5
- "main": "index.js",
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
  });