@zhushanwen/pi-unified-hooks 0.2.7 → 0.2.9

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
@@ -12,7 +12,7 @@
12
12
  >
13
13
  > 迁移指引:`pi uninstall npm:@zhushanwen/pi-unified-hooks` 后 `pi install npm:@zhushanwen/pi-base-tool-enhance`。两者同时安装会对 bash 产生双重拦截,务必先卸载本包。
14
14
 
15
- 统一 hooks 管理器 — 将散落的 hooks 收集到一个扩展中统一维护,每个 hook 可独立启用/禁用。
15
+ 统一 hooks 管理器 — 将散落的 hooks 收集到一个扩展中统一维护。hook 为自包含模块,全部注册;setup 失败的 hook 标记为 disabled,并在 session_start 时提醒。
16
16
 
17
17
  ## 功能
18
18
 
@@ -20,27 +20,17 @@
20
20
 
21
21
  | Hook | 说明 |
22
22
  |------|------|
23
- | `edit-whitespace-autofix` | edit 工具因空白字符不匹配失败时,自动注入 steering AI 修复空白并重试 |
24
- | `tool-error-handler` | 记录所有工具执行错误到控制台,方便调试 |
23
+ | `tool-error-handler` | 工具执行错误经 appendEntry 写入 session JSONL(customType `unified-hooks:tool-error`),便于事后排查 |
24
+ | `network-timeout-guard` | 网络类 bash 命令未设 timeout 时 block,提示 AI 补 timeout 或开代理 |
25
+ | `test-timeout-guard` | 测试类 bash 命令未设 timeout 时 block,提示 AI 补 timeout |
25
26
 
26
27
  ### 扩展方式
27
28
 
28
29
  在 `src/hooks/` 下新建 hook 模块,然后在 `src/index.ts` 的 `hookModules` 数组中注册即可。
29
30
 
30
- ## 安装
31
-
32
- ```bash
33
- # symlink 方式(开发推荐;globalExtDir 平铺布局,目标不带分组层)
34
- ln -s /path/to/xyz-pi-extensions-workspace/main/packages/unified-hooks \
35
- ~/.pi/agent/extensions/unified-hooks
36
-
37
- # npm 方式(正式)
38
- pi install npm:@zhushanwen/pi-unified-hooks
39
- ```
40
-
41
31
  ## 使用
42
32
 
43
- 安装后自动生效。edit 空白修复无需配置,工具错误日志自动输出到控制台。
33
+ 加载后自动生效,无需配置。工具错误经 appendEntry 写入 session JSONL(customType `unified-hooks:tool-error`),不弹 TUI 通知;各 hook 的注册结果(enabled/disabled)记录在 `unified-hooks:loaded` customEntry。
44
34
 
45
35
  ## 文件结构
46
36
 
@@ -50,5 +40,7 @@ unified-hooks/
50
40
  └── src/
51
41
  ├── index.ts # 入口 — hook 注册
52
42
  └── hooks/
53
- └── tool-error-handler.ts # 工具错误处理
43
+ ├── tool-error-handler.ts # 工具错误处理(appendEntry 审计)
44
+ ├── network-timeout-guard.ts # 网络命令超时守卫
45
+ └── test-timeout-guard.ts # 测试命令超时守卫
54
46
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-unified-hooks",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "[DEPRECATED] Unified hooks extension - collect scattered hooks in one place for easy maintenance",
5
5
  "deprecated": "Superseded by @zhushanwen/pi-base-tool-enhance — install that instead; test-command guarding, tool-error audit and configurable timeouts are all covered.",
6
6
  "main": "index.ts",
@@ -20,10 +20,10 @@
20
20
  ],
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@zhushanwen/pi-extension-logger": "0.3.0"
23
+ "@zhushanwen/pi-extension-logger": "0.4.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@earendil-works/pi-coding-agent": "^0.84.1"
26
+ "@earendil-works/pi-coding-agent": "^0.84.4"
27
27
  },
28
28
  "peerDependenciesMeta": {},
29
29
  "devDependencies": {
@@ -131,6 +131,7 @@ describe("session_start handler", () => {
131
131
 
132
132
  it("does not throw when ctx.ui is undefined (headless / RPC session)", () => {
133
133
  // [HISTORICAL] headless 会话 ctx.ui 为 undefined,旧实现直接 ctx.ui.notify 会 NPE。
134
+ // pi 现版本 ctx.ui 恒为对象(runner 默认 noOpUIContext),本用例仅保留防御。
134
135
  const pi = createMockPi();
135
136
  const ctx = { ui: undefined } as unknown as HookContext;
136
137
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Intercepts bash tool calls that involve network operations.
5
5
  * Blocks execution if no timeout is set and the command appears to be network-bound,
6
- * prompting the AI to add timeout or use async mode.
6
+ * prompting the AI to add a timeout (or enable a proxy for overseas access).
7
7
  */
8
8
 
9
9
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
package/src/index.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  * Unified Hooks Extension
3
3
  *
4
4
  * Collects scattered hooks in one place for easy maintenance.
5
- * Each hook is a self-contained module that can be enabled/disabled independently.
5
+ * Each hook is a self-contained module. All hooks are registered unconditionally;
6
+ * a hook whose setup throws is marked disabled (reported via session_start).
6
7
  */
7
8
 
8
9
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";