@zhushanwen/pi-unified-hooks 0.0.3 → 0.0.5
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/package.json
CHANGED
|
@@ -36,12 +36,23 @@ function detectNetworkCommand(command: string): string | null {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Subset of `BashToolCallEvent` fields used by this hook.
|
|
41
|
+
* Local interface because the SDK's full event type is not re-exported
|
|
42
|
+
* by the CI ambient type stubs in `shared/types/mariozechner/index.d.ts`.
|
|
43
|
+
*/
|
|
44
|
+
interface BashToolCallLikeEvent {
|
|
45
|
+
toolName: string;
|
|
46
|
+
input: { command: string; timeout?: number };
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
export function setupNetworkTimeoutGuard(pi: ExtensionAPI): void {
|
|
40
|
-
pi.on("tool_call", async (event:
|
|
50
|
+
pi.on("tool_call", async (event: unknown) => {
|
|
41
51
|
// Only intercept bash tool calls
|
|
42
|
-
|
|
52
|
+
const e = event as BashToolCallLikeEvent;
|
|
53
|
+
if (e.toolName !== "bash") return;
|
|
43
54
|
|
|
44
|
-
const { command, timeout } =
|
|
55
|
+
const { command, timeout } = e.input;
|
|
45
56
|
|
|
46
57
|
// No network command detected — let it through
|
|
47
58
|
const networkLabel = detectNetworkCommand(command);
|
|
@@ -71,11 +71,22 @@ function detectTestCommand(command: string): string | null {
|
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Subset of `BashToolCallEvent` fields used by this hook.
|
|
76
|
+
* Local interface because the SDK's full event type is not re-exported
|
|
77
|
+
* by the CI ambient type stubs in `shared/types/mariozechner/index.d.ts`.
|
|
78
|
+
*/
|
|
79
|
+
interface BashToolCallLikeEvent {
|
|
80
|
+
toolName: string;
|
|
81
|
+
input: { command: string; timeout?: number };
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
export function setupTestTimeoutGuard(pi: ExtensionAPI): void {
|
|
75
|
-
pi.on("tool_call", async (event:
|
|
76
|
-
|
|
85
|
+
pi.on("tool_call", async (event: unknown) => {
|
|
86
|
+
const e = event as BashToolCallLikeEvent;
|
|
87
|
+
if (e.toolName !== "bash") return;
|
|
77
88
|
|
|
78
|
-
const { command, timeout } =
|
|
89
|
+
const { command, timeout } = e.input;
|
|
79
90
|
|
|
80
91
|
const testLabel = detectTestCommand(command);
|
|
81
92
|
if (!testLabel) return;
|
|
@@ -7,9 +7,24 @@
|
|
|
7
7
|
|
|
8
8
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Subset of `ToolExecutionEndEvent` fields used by this hook.
|
|
12
|
+
* Local interface because the SDK's full event type is not re-exported
|
|
13
|
+
* by the CI ambient type stubs in `shared/types/mariozechner/index.d.ts`.
|
|
14
|
+
*/
|
|
15
|
+
interface ToolExecutionEndLikeEvent {
|
|
16
|
+
isError: boolean;
|
|
17
|
+
toolName: string;
|
|
18
|
+
toolCallId: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
export function setupToolErrorHandler(pi: ExtensionAPI): void {
|
|
11
|
-
pi.on("tool_execution_end", async (event:
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
pi.on("tool_execution_end", async (event: unknown) => {
|
|
23
|
+
const e = event as ToolExecutionEndLikeEvent;
|
|
24
|
+
if (!e.isError) return;
|
|
25
|
+
// Tool error diagnostics are internal — surfacing to the terminal
|
|
26
|
+
// would leak to the input area. ctx.ui.notify is unnecessary because
|
|
27
|
+
// tool errors are already surfaced by Pi's own error rendering.
|
|
28
|
+
console.warn(`[unified-hooks] ${e.toolName} error (callId=${e.toolCallId})`);
|
|
14
29
|
});
|
|
15
30
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
9
9
|
|
|
10
10
|
// Re-export hook modules for easy access
|
|
11
|
-
export { setupToolErrorHandler } from "./hooks/tool-error-handler";
|
|
12
11
|
export { setupNetworkTimeoutGuard } from "./hooks/network-timeout-guard";
|
|
13
12
|
export { setupTestTimeoutGuard } from "./hooks/test-timeout-guard";
|
|
13
|
+
export { setupToolErrorHandler } from "./hooks/tool-error-handler";
|
|
14
14
|
|
|
15
|
-
import { setupToolErrorHandler } from "./hooks/tool-error-handler";
|
|
16
15
|
import { setupNetworkTimeoutGuard } from "./hooks/network-timeout-guard";
|
|
17
16
|
import { setupTestTimeoutGuard } from "./hooks/test-timeout-guard";
|
|
17
|
+
import { setupToolErrorHandler } from "./hooks/tool-error-handler";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Extension factory - registers all unified hooks
|
|
@@ -41,11 +41,13 @@ export default function unifiedHooksExtension(pi: ExtensionAPI): void {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// Hook status is an internal diagnostic — surfacing to the terminal
|
|
45
|
+
// would leak to the input area. Use console.warn (stderr) for
|
|
46
|
+
// development debugging; production should be silent.
|
|
45
47
|
pi.on("session_start", () => {
|
|
46
48
|
const enabled = hooks.filter((h) => h.enabled).map((h) => h.name);
|
|
47
49
|
const disabled = hooks.filter((h) => !h.enabled).map((h) => h.name);
|
|
48
|
-
console.
|
|
50
|
+
console.warn(
|
|
49
51
|
`[unified-hooks] Loaded: ${enabled.join(", ") || "(none)"}${
|
|
50
52
|
disabled.length ? ` | Failed: ${disabled.join(", ")}` : ""
|
|
51
53
|
}`
|