cc-hooks-ts 2.1.63 → 2.1.74
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/dist/index.d.mts +71 -9
- package/dist/index.mjs +143 -7
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
import { AgentInput, AgentOutput, AskUserQuestionInput, AskUserQuestionOutput, BashInput, BashOutput, ExitPlanModeInput, ExitPlanModeOutput, FileEditInput, FileEditOutput, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, GlobInput, GlobOutput, GrepInput, GrepOutput, ListMcpResourcesInput, ListMcpResourcesOutput, NotebookEditInput, NotebookEditOutput, ReadMcpResourceInput, ReadMcpResourceOutput, TaskOutputInput, TaskStopInput, TaskStopOutput, TodoWriteInput, TodoWriteOutput, WebFetchInput, WebFetchOutput, WebSearchInput, WebSearchOutput } from "@anthropic-ai/claude-agent-sdk/sdk-tools";
|
|
2
|
+
import { AgentInput, AgentOutput, AskUserQuestionInput, AskUserQuestionOutput, BashInput, BashOutput, ExitPlanModeInput, ExitPlanModeOutput, ExitWorktreeInput, ExitWorktreeOutput, FileEditInput, FileEditOutput, FileReadInput, FileReadOutput, FileWriteInput, FileWriteOutput, GlobInput, GlobOutput, GrepInput, GrepOutput, ListMcpResourcesInput, ListMcpResourcesOutput, NotebookEditInput, NotebookEditOutput, ReadMcpResourceInput, ReadMcpResourceOutput, TaskOutputInput, TaskStopInput, TaskStopOutput, TodoWriteInput, TodoWriteOutput, WebFetchInput, WebFetchOutput, WebSearchInput, WebSearchOutput } from "@anthropic-ai/claude-agent-sdk/sdk-tools";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/types.d.ts
|
|
5
5
|
type Awaitable<T> = Promise<T> | T;
|
|
@@ -11,6 +11,8 @@ type AutoComplete<T extends string> = Record<string, never> & T;
|
|
|
11
11
|
*/
|
|
12
12
|
declare const HookInputSchemas: {
|
|
13
13
|
readonly PreToolUse: v.ObjectSchema<{
|
|
14
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
15
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
14
16
|
readonly cwd: v.StringSchema<undefined>;
|
|
15
17
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
16
18
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -22,6 +24,8 @@ declare const HookInputSchemas: {
|
|
|
22
24
|
tool_use_id: v.StringSchema<undefined>;
|
|
23
25
|
}, undefined>;
|
|
24
26
|
readonly PostToolUse: v.ObjectSchema<{
|
|
27
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
28
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
25
29
|
readonly cwd: v.StringSchema<undefined>;
|
|
26
30
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
27
31
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -34,6 +38,8 @@ declare const HookInputSchemas: {
|
|
|
34
38
|
tool_use_id: v.StringSchema<undefined>;
|
|
35
39
|
}, undefined>;
|
|
36
40
|
readonly PostToolUseFailure: v.ObjectSchema<{
|
|
41
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
42
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
37
43
|
readonly cwd: v.StringSchema<undefined>;
|
|
38
44
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
39
45
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -47,6 +53,8 @@ declare const HookInputSchemas: {
|
|
|
47
53
|
tool_use_id: v.StringSchema<undefined>;
|
|
48
54
|
}, undefined>;
|
|
49
55
|
readonly Notification: v.ObjectSchema<{
|
|
56
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
57
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
50
58
|
readonly cwd: v.StringSchema<undefined>;
|
|
51
59
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
52
60
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -58,6 +66,8 @@ declare const HookInputSchemas: {
|
|
|
58
66
|
title: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
59
67
|
}, undefined>;
|
|
60
68
|
readonly UserPromptSubmit: v.ObjectSchema<{
|
|
69
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
70
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
61
71
|
readonly cwd: v.StringSchema<undefined>;
|
|
62
72
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
63
73
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -67,6 +77,8 @@ declare const HookInputSchemas: {
|
|
|
67
77
|
prompt: v.StringSchema<undefined>;
|
|
68
78
|
}, undefined>;
|
|
69
79
|
readonly Stop: v.ObjectSchema<{
|
|
80
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
81
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
70
82
|
readonly cwd: v.StringSchema<undefined>;
|
|
71
83
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
72
84
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -76,30 +88,37 @@ declare const HookInputSchemas: {
|
|
|
76
88
|
last_assistant_message: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
77
89
|
stop_hook_active: v.BooleanSchema<undefined>;
|
|
78
90
|
}, undefined>;
|
|
79
|
-
readonly SubagentStart: v.ObjectSchema<{
|
|
91
|
+
readonly SubagentStart: v.ObjectSchema<Omit<{
|
|
92
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
93
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
80
94
|
readonly cwd: v.StringSchema<undefined>;
|
|
81
95
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
82
96
|
readonly session_id: v.StringSchema<undefined>;
|
|
83
97
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
84
98
|
readonly hook_event_name: v.LiteralSchema<"SubagentStart", undefined>;
|
|
85
|
-
} & {
|
|
86
|
-
agent_id: v.StringSchema<undefined>;
|
|
87
|
-
agent_type: v.StringSchema<undefined>;
|
|
99
|
+
}, "agent_id" | "agent_type"> & {
|
|
100
|
+
readonly agent_id: v.StringSchema<undefined>;
|
|
101
|
+
readonly agent_type: v.StringSchema<undefined>;
|
|
88
102
|
}, undefined>;
|
|
89
|
-
readonly SubagentStop: v.ObjectSchema<{
|
|
103
|
+
readonly SubagentStop: v.ObjectSchema<Omit<{
|
|
104
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
105
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
90
106
|
readonly cwd: v.StringSchema<undefined>;
|
|
91
107
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
92
108
|
readonly session_id: v.StringSchema<undefined>;
|
|
93
109
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
94
110
|
readonly hook_event_name: v.LiteralSchema<"SubagentStop", undefined>;
|
|
95
111
|
} & {
|
|
96
|
-
agent_id: v.StringSchema<undefined>;
|
|
97
112
|
agent_transcript_path: v.StringSchema<undefined>;
|
|
98
|
-
agent_type: v.StringSchema<undefined>;
|
|
99
113
|
last_assistant_message: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
100
114
|
stop_hook_active: v.BooleanSchema<undefined>;
|
|
115
|
+
}, "agent_id" | "agent_type"> & {
|
|
116
|
+
readonly agent_id: v.StringSchema<undefined>;
|
|
117
|
+
readonly agent_type: v.StringSchema<undefined>;
|
|
101
118
|
}, undefined>;
|
|
102
119
|
readonly PreCompact: v.ObjectSchema<{
|
|
120
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
121
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
103
122
|
readonly cwd: v.StringSchema<undefined>;
|
|
104
123
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
105
124
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -110,6 +129,8 @@ declare const HookInputSchemas: {
|
|
|
110
129
|
trigger: v.PicklistSchema<["manual", "auto"], undefined>;
|
|
111
130
|
}, undefined>;
|
|
112
131
|
readonly SessionStart: v.ObjectSchema<{
|
|
132
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
133
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
113
134
|
readonly cwd: v.StringSchema<undefined>;
|
|
114
135
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
115
136
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -121,6 +142,8 @@ declare const HookInputSchemas: {
|
|
|
121
142
|
source: v.PicklistSchema<["startup", "resume", "clear", "compact"], undefined>;
|
|
122
143
|
}, undefined>;
|
|
123
144
|
readonly SessionEnd: v.ObjectSchema<{
|
|
145
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
146
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
124
147
|
readonly cwd: v.StringSchema<undefined>;
|
|
125
148
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
126
149
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -130,6 +153,8 @@ declare const HookInputSchemas: {
|
|
|
130
153
|
reason: v.PicklistSchema<["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"], undefined>;
|
|
131
154
|
}, undefined>;
|
|
132
155
|
readonly PermissionRequest: v.ObjectSchema<{
|
|
156
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
157
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
133
158
|
readonly cwd: v.StringSchema<undefined>;
|
|
134
159
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
135
160
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -177,6 +202,8 @@ declare const HookInputSchemas: {
|
|
|
177
202
|
tool_name: v.StringSchema<undefined>;
|
|
178
203
|
}, undefined>;
|
|
179
204
|
readonly Setup: v.ObjectSchema<{
|
|
205
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
206
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
180
207
|
readonly cwd: v.StringSchema<undefined>;
|
|
181
208
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
182
209
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -186,6 +213,8 @@ declare const HookInputSchemas: {
|
|
|
186
213
|
trigger: v.PicklistSchema<["init", "maintenance"], undefined>;
|
|
187
214
|
}, undefined>;
|
|
188
215
|
readonly TeammateIdle: v.ObjectSchema<{
|
|
216
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
217
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
189
218
|
readonly cwd: v.StringSchema<undefined>;
|
|
190
219
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
191
220
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -196,6 +225,8 @@ declare const HookInputSchemas: {
|
|
|
196
225
|
teammate_name: v.StringSchema<undefined>;
|
|
197
226
|
}, undefined>;
|
|
198
227
|
readonly TaskCompleted: v.ObjectSchema<{
|
|
228
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
229
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
199
230
|
readonly cwd: v.StringSchema<undefined>;
|
|
200
231
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
201
232
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -209,6 +240,8 @@ declare const HookInputSchemas: {
|
|
|
209
240
|
teammate_name: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
210
241
|
}, undefined>;
|
|
211
242
|
readonly ConfigChange: v.ObjectSchema<{
|
|
243
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
244
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
212
245
|
readonly cwd: v.StringSchema<undefined>;
|
|
213
246
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
214
247
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -219,6 +252,8 @@ declare const HookInputSchemas: {
|
|
|
219
252
|
source: v.PicklistSchema<["local_settings", "policy_settings", "project_settings", "skills", "user_settings"], undefined>;
|
|
220
253
|
}, undefined>;
|
|
221
254
|
readonly WorktreeCreate: v.ObjectSchema<{
|
|
255
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
256
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
222
257
|
readonly cwd: v.StringSchema<undefined>;
|
|
223
258
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
224
259
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -228,6 +263,8 @@ declare const HookInputSchemas: {
|
|
|
228
263
|
name: v.StringSchema<undefined>;
|
|
229
264
|
}, undefined>;
|
|
230
265
|
readonly WorktreeRemove: v.ObjectSchema<{
|
|
266
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
267
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
231
268
|
readonly cwd: v.StringSchema<undefined>;
|
|
232
269
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
233
270
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -237,6 +274,8 @@ declare const HookInputSchemas: {
|
|
|
237
274
|
worktree_path: v.StringSchema<undefined>;
|
|
238
275
|
}, undefined>;
|
|
239
276
|
readonly Elicitation: v.ObjectSchema<{
|
|
277
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
278
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
240
279
|
readonly cwd: v.StringSchema<undefined>;
|
|
241
280
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
242
281
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -251,6 +290,8 @@ declare const HookInputSchemas: {
|
|
|
251
290
|
url: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
252
291
|
}, undefined>;
|
|
253
292
|
readonly ElicitationResult: v.ObjectSchema<{
|
|
293
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
294
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
254
295
|
readonly cwd: v.StringSchema<undefined>;
|
|
255
296
|
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
256
297
|
readonly session_id: v.StringSchema<undefined>;
|
|
@@ -263,6 +304,22 @@ declare const HookInputSchemas: {
|
|
|
263
304
|
mcp_server_name: v.StringSchema<undefined>;
|
|
264
305
|
mode: v.ExactOptionalSchema<v.PicklistSchema<["form", "url"], undefined>, undefined>;
|
|
265
306
|
}, undefined>;
|
|
307
|
+
readonly InstructionsLoaded: v.ObjectSchema<{
|
|
308
|
+
readonly agent_id: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
309
|
+
readonly agent_type: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
310
|
+
readonly cwd: v.StringSchema<undefined>;
|
|
311
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
312
|
+
readonly session_id: v.StringSchema<undefined>;
|
|
313
|
+
readonly transcript_path: v.StringSchema<undefined>;
|
|
314
|
+
readonly hook_event_name: v.LiteralSchema<"InstructionsLoaded", undefined>;
|
|
315
|
+
} & {
|
|
316
|
+
file_path: v.StringSchema<undefined>;
|
|
317
|
+
globs: v.ExactOptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
318
|
+
load_reason: v.PicklistSchema<["session_start", "nested_traversal", "path_glob_match", "include"], undefined>;
|
|
319
|
+
memory_type: v.PicklistSchema<["User", "Project", "Local", "Managed"], undefined>;
|
|
320
|
+
parent_file_path: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
321
|
+
trigger_file_path: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
322
|
+
}, undefined>;
|
|
266
323
|
};
|
|
267
324
|
//#endregion
|
|
268
325
|
//#region src/hooks/event.d.ts
|
|
@@ -271,7 +328,7 @@ declare const HookInputSchemas: {
|
|
|
271
328
|
*
|
|
272
329
|
* @package
|
|
273
330
|
*/
|
|
274
|
-
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest" | "Setup" | "TeammateIdle" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult";
|
|
331
|
+
type SupportedHookEvent = "PreToolUse" | "PostToolUse" | "PostToolUseFailure" | "Notification" | "UserPromptSubmit" | "SessionStart" | "SessionEnd" | "Stop" | "SubagentStart" | "SubagentStop" | "PreCompact" | "PermissionRequest" | "Setup" | "TeammateIdle" | "TaskCompleted" | "ConfigChange" | "WorktreeCreate" | "WorktreeRemove" | "Elicitation" | "ElicitationResult" | "InstructionsLoaded";
|
|
275
332
|
//#endregion
|
|
276
333
|
//#region src/hooks/input/types.d.ts
|
|
277
334
|
/**
|
|
@@ -414,6 +471,7 @@ type HookOutput = {
|
|
|
414
471
|
Elicitation: ElicitationHookOutput;
|
|
415
472
|
ElicitationResult: ElicitationResultHookOutput;
|
|
416
473
|
ConfigChange: CommonHookOutputs;
|
|
474
|
+
InstructionsLoaded: CommonHookOutputs;
|
|
417
475
|
PreCompact: CommonHookOutputs;
|
|
418
476
|
SessionEnd: CommonHookOutputs;
|
|
419
477
|
TaskCompleted: CommonHookOutputs;
|
|
@@ -1038,6 +1096,10 @@ interface ToolSchema {
|
|
|
1038
1096
|
input: ExitPlanModeInput;
|
|
1039
1097
|
response: ExitPlanModeOutput;
|
|
1040
1098
|
};
|
|
1099
|
+
ExitWorktree: {
|
|
1100
|
+
input: ExitWorktreeInput;
|
|
1101
|
+
response: ExitWorktreeOutput;
|
|
1102
|
+
};
|
|
1041
1103
|
Glob: {
|
|
1042
1104
|
input: GlobInput;
|
|
1043
1105
|
response: GlobOutput;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,63 @@
|
|
|
1
1
|
import getStdin from "get-stdin";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import * as v from "valibot";
|
|
4
|
+
//#region src/define.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a type-safe Claude Code hook definition.
|
|
7
|
+
*
|
|
8
|
+
* This function provides a way to define hooks with full TypeScript type safety,
|
|
9
|
+
* including input validation using Valibot schemas and strongly typed context.
|
|
10
|
+
*
|
|
11
|
+
* @param definition - The hook definition object containing trigger events and handler function
|
|
12
|
+
* @returns The same hook definition, but with enhanced type safety
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Basic session start hook
|
|
17
|
+
* const sessionHook = defineHook({
|
|
18
|
+
* trigger: { SessionStart: true },
|
|
19
|
+
* run: (context) => {
|
|
20
|
+
* console.log(`Session started: ${context.input.session_id}`);
|
|
21
|
+
* return context.success({
|
|
22
|
+
* messageForUser: "Welcome to your coding session!"
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Tool-specific PreToolUse hook
|
|
28
|
+
* const readHook = defineHook({
|
|
29
|
+
* trigger: { PreToolUse: { Read: true } },
|
|
30
|
+
* run: (context) => {
|
|
31
|
+
* // context.input.tool_input is typed as { file_path: string }
|
|
32
|
+
* const { file_path } = context.input.tool_input;
|
|
33
|
+
*
|
|
34
|
+
* if (file_path.includes('.env')) {
|
|
35
|
+
* return context.blockingError('Cannot read environment files');
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* return context.success();
|
|
39
|
+
* }
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Multiple event triggers with conditional logic
|
|
43
|
+
* const multiEventHook = defineHook({
|
|
44
|
+
* trigger: {
|
|
45
|
+
* PreToolUse: { Read: true, WebFetch: true },
|
|
46
|
+
* PostToolUse: { Read: true }
|
|
47
|
+
* },
|
|
48
|
+
* shouldRun: () => process.env.NODE_ENV === 'development',
|
|
49
|
+
* run: (context) => {
|
|
50
|
+
* // Handle different events and tools based on context.input
|
|
51
|
+
* return context.success();
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
4
56
|
function defineHook(definition) {
|
|
5
57
|
return definition;
|
|
6
58
|
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/context.ts
|
|
7
61
|
function createContext(input) {
|
|
8
62
|
return {
|
|
9
63
|
defer: (handler, options) => ({
|
|
@@ -33,6 +87,8 @@ function createContext(input) {
|
|
|
33
87
|
})
|
|
34
88
|
};
|
|
35
89
|
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/hooks/permission.ts
|
|
36
92
|
const permissionBehaviorSchema = v.picklist([
|
|
37
93
|
"allow",
|
|
38
94
|
"deny",
|
|
@@ -49,6 +105,9 @@ const permissionRuleValueSchema = v.object({
|
|
|
49
105
|
ruleContent: v.exactOptional(v.string()),
|
|
50
106
|
toolName: v.string()
|
|
51
107
|
});
|
|
108
|
+
/**
|
|
109
|
+
* @package
|
|
110
|
+
*/
|
|
52
111
|
const permissionUpdateSchema = v.variant("type", [
|
|
53
112
|
v.object({
|
|
54
113
|
behavior: permissionBehaviorSchema,
|
|
@@ -90,7 +149,11 @@ const permissionUpdateSchema = v.variant("type", [
|
|
|
90
149
|
type: v.literal("removeDirectories")
|
|
91
150
|
})
|
|
92
151
|
]);
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/hooks/input/schemas.ts
|
|
93
154
|
const baseHookInputSchema = v.object({
|
|
155
|
+
agent_id: v.exactOptional(v.string()),
|
|
156
|
+
agent_type: v.exactOptional(v.string()),
|
|
94
157
|
cwd: v.string(),
|
|
95
158
|
permission_mode: v.exactOptional(v.string()),
|
|
96
159
|
session_id: v.string(),
|
|
@@ -103,6 +166,17 @@ function buildHookInputSchema(hook_event_name, entries) {
|
|
|
103
166
|
...entries
|
|
104
167
|
});
|
|
105
168
|
}
|
|
169
|
+
function buildSubagentInputSchema(hook_event_name, entries) {
|
|
170
|
+
const base = buildHookInputSchema(hook_event_name, entries);
|
|
171
|
+
return v.object({
|
|
172
|
+
...v.omit(base, ["agent_id", "agent_type"]).entries,
|
|
173
|
+
agent_id: v.string(),
|
|
174
|
+
agent_type: v.string()
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @package
|
|
179
|
+
*/
|
|
106
180
|
const HookInputSchemas = {
|
|
107
181
|
PreToolUse: buildHookInputSchema("PreToolUse", {
|
|
108
182
|
tool_name: v.pipe(v.string(), v.transform((s) => s)),
|
|
@@ -132,14 +206,9 @@ const HookInputSchemas = {
|
|
|
132
206
|
last_assistant_message: v.exactOptional(v.string()),
|
|
133
207
|
stop_hook_active: v.boolean()
|
|
134
208
|
}),
|
|
135
|
-
SubagentStart:
|
|
136
|
-
|
|
137
|
-
agent_type: v.string()
|
|
138
|
-
}),
|
|
139
|
-
SubagentStop: buildHookInputSchema("SubagentStop", {
|
|
140
|
-
agent_id: v.string(),
|
|
209
|
+
SubagentStart: buildSubagentInputSchema("SubagentStart", {}),
|
|
210
|
+
SubagentStop: buildSubagentInputSchema("SubagentStop", {
|
|
141
211
|
agent_transcript_path: v.string(),
|
|
142
|
-
agent_type: v.string(),
|
|
143
212
|
last_assistant_message: v.exactOptional(v.string()),
|
|
144
213
|
stop_hook_active: v.boolean()
|
|
145
214
|
}),
|
|
@@ -211,11 +280,77 @@ const HookInputSchemas = {
|
|
|
211
280
|
elicitation_id: v.exactOptional(v.string()),
|
|
212
281
|
mcp_server_name: v.string(),
|
|
213
282
|
mode: v.exactOptional(v.picklist(["form", "url"]))
|
|
283
|
+
}),
|
|
284
|
+
InstructionsLoaded: buildHookInputSchema("InstructionsLoaded", {
|
|
285
|
+
file_path: v.string(),
|
|
286
|
+
globs: v.exactOptional(v.array(v.string())),
|
|
287
|
+
load_reason: v.picklist([
|
|
288
|
+
"session_start",
|
|
289
|
+
"nested_traversal",
|
|
290
|
+
"path_glob_match",
|
|
291
|
+
"include"
|
|
292
|
+
]),
|
|
293
|
+
memory_type: v.picklist([
|
|
294
|
+
"User",
|
|
295
|
+
"Project",
|
|
296
|
+
"Local",
|
|
297
|
+
"Managed"
|
|
298
|
+
]),
|
|
299
|
+
parent_file_path: v.exactOptional(v.string()),
|
|
300
|
+
trigger_file_path: v.exactOptional(v.string())
|
|
214
301
|
})
|
|
215
302
|
};
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/utils/string.ts
|
|
216
305
|
function isNonEmptyString(value) {
|
|
217
306
|
return typeof value === "string" && value.length > 0;
|
|
218
307
|
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/run.ts
|
|
310
|
+
/**
|
|
311
|
+
* Executes a Claude Code hook with runtime input validation and error handling.
|
|
312
|
+
*
|
|
313
|
+
* This function handles the complete lifecycle of hook execution including:
|
|
314
|
+
* - Reading input from stdin
|
|
315
|
+
* - Validating input against Valibot schemas
|
|
316
|
+
* - Creating typed context
|
|
317
|
+
* - Executing the hook handler
|
|
318
|
+
* - Formatting and outputting results
|
|
319
|
+
*
|
|
320
|
+
* @param definition - The hook definition to execute
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* // CLI usage: echo '{"hook_event_name":"SessionStart",...}' | node hook.js
|
|
325
|
+
* const hook = defineHook({
|
|
326
|
+
* trigger: { SessionStart: true },
|
|
327
|
+
* run: (context) => context.success()
|
|
328
|
+
* });
|
|
329
|
+
*
|
|
330
|
+
* // Execute the hook (typically called from CLI)
|
|
331
|
+
* await runHook(hook);
|
|
332
|
+
*
|
|
333
|
+
* // Hook with error handling
|
|
334
|
+
* const validationHook = defineHook({
|
|
335
|
+
* trigger: { PreToolUse: { Read: true } },
|
|
336
|
+
* run: (context) => {
|
|
337
|
+
* try {
|
|
338
|
+
* const { file_path } = context.input.tool_input;
|
|
339
|
+
*
|
|
340
|
+
* if (!file_path.endsWith('.ts')) {
|
|
341
|
+
* return context.nonBlockingError('Warning: Non-TypeScript file detected');
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* return context.success();
|
|
345
|
+
* } catch (error) {
|
|
346
|
+
* return context.blockingError(`Validation failed: ${error.message}`);
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* });
|
|
350
|
+
*
|
|
351
|
+
* await runHook(validationHook);
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
219
354
|
async function runHook(def) {
|
|
220
355
|
const { run, shouldRun = true, trigger } = def;
|
|
221
356
|
let eventName = null;
|
|
@@ -296,4 +431,5 @@ function extractInputSchemaFromTrigger(trigger) {
|
|
|
296
431
|
});
|
|
297
432
|
return v.union(schemas);
|
|
298
433
|
}
|
|
434
|
+
//#endregion
|
|
299
435
|
export { defineHook, runHook };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-hooks-ts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.74",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Write claude code hooks with type safety",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -43,26 +43,26 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@arethetypeswrong/core": "0.18.2",
|
|
46
|
-
"@types/node": "25.
|
|
47
|
-
"@typescript/native-preview": "
|
|
46
|
+
"@types/node": "25.4.0",
|
|
47
|
+
"@typescript/native-preview": "7.0.0-dev.20260311.1",
|
|
48
48
|
"@virtual-live-lab/eslint-config": "2.3.1",
|
|
49
49
|
"@virtual-live-lab/tsconfig": "2.1.21",
|
|
50
50
|
"eslint": "9.39.2",
|
|
51
51
|
"eslint-plugin-import-access": "3.1.0",
|
|
52
52
|
"oxfmt": "0.28.0",
|
|
53
|
-
"pkg-pr-new": "0.0.
|
|
54
|
-
"publint": "0.3.
|
|
53
|
+
"pkg-pr-new": "0.0.65",
|
|
54
|
+
"publint": "0.3.18",
|
|
55
55
|
"release-it": "19.2.4",
|
|
56
56
|
"release-it-pnpm": "4.6.6",
|
|
57
|
-
"tsdown": "0.
|
|
58
|
-
"type-fest": "5.4.
|
|
57
|
+
"tsdown": "0.21.2",
|
|
58
|
+
"type-fest": "5.4.4",
|
|
59
59
|
"typescript": "5.9.3",
|
|
60
|
-
"typescript-eslint": "8.
|
|
60
|
+
"typescript-eslint": "8.57.0",
|
|
61
61
|
"unplugin-unused": "0.5.7",
|
|
62
62
|
"vitest": "4.0.18"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@anthropic-ai/claude-agent-sdk": "0.2.
|
|
65
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.74",
|
|
66
66
|
"get-stdin": "10.0.0",
|
|
67
67
|
"valibot": "^1.1.0"
|
|
68
68
|
},
|