cc-hooks-ts 0.0.6 → 0.1.0
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 +3 -0
- package/dist/index.d.mts +56 -117
- package/dist/index.mjs +16 -21
- package/package.json +15 -13
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
+
import { BashInput, FileEditInput, FileReadInput, FileWriteInput, GlobInput, GrepInput, NotebookEditInput, TodoWriteInput, WebFetchInput, WebSearchInput } from "@anthropic-ai/claude-code/sdk-tools.js";
|
|
2
3
|
|
|
3
|
-
//#region src/hook-types/index.d.ts
|
|
4
|
-
type ClaudeCodeTodo = {
|
|
5
|
-
activeForm: string;
|
|
6
|
-
content: string;
|
|
7
|
-
status: "completed" | "in_progress" | "pending";
|
|
8
|
-
};
|
|
9
|
-
//#endregion
|
|
10
4
|
//#region src/utils/types.d.ts
|
|
11
5
|
type Awaitable<T> = Promise<T> | T;
|
|
12
6
|
type AutoComplete<T extends string> = Record<string, never> & T;
|
|
13
7
|
//#endregion
|
|
14
8
|
//#region src/event.d.ts
|
|
15
|
-
declare const SUPPORTED_HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "
|
|
9
|
+
declare const SUPPORTED_HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStop", "PreCompact"];
|
|
16
10
|
/**
|
|
17
11
|
* @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#hook-events}
|
|
18
12
|
*/
|
|
@@ -30,7 +24,7 @@ type HookOutput = {
|
|
|
30
24
|
PreCompact: CommonHookOutputs;
|
|
31
25
|
SessionEnd: CommonHookOutputs;
|
|
32
26
|
};
|
|
33
|
-
type ExtractHookOutput<TEvent extends SupportedHookEvent> = HookOutput extends Record<SupportedHookEvent, unknown> ? HookOutput[TEvent] : never;
|
|
27
|
+
type ExtractHookOutput<TEvent$1 extends SupportedHookEvent> = HookOutput extends Record<SupportedHookEvent, unknown> ? HookOutput[TEvent$1] : never;
|
|
34
28
|
/**
|
|
35
29
|
* Common fields of hook outputs
|
|
36
30
|
*
|
|
@@ -60,6 +54,18 @@ type CommonHookOutputs = {
|
|
|
60
54
|
* Optional warning message shown to the user
|
|
61
55
|
*/
|
|
62
56
|
systemMessage?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Use `hookSpecificOutput` in appropriate hook events instead.
|
|
59
|
+
*
|
|
60
|
+
* @deprecated
|
|
61
|
+
*/
|
|
62
|
+
reason?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Use `hookSpecificOutput` in appropriate hook events instead.
|
|
65
|
+
*
|
|
66
|
+
* @deprecated
|
|
67
|
+
*/
|
|
68
|
+
decision?: "approve" | "block";
|
|
63
69
|
};
|
|
64
70
|
/**
|
|
65
71
|
* @see {@link https://docs.anthropic.com/en/docs/claude-code/hooks#pretooluse-decision-control}
|
|
@@ -72,8 +78,8 @@ interface PreToolUseHookOutput extends CommonHookOutputs {
|
|
|
72
78
|
* - `deny` prevents the tool call from executing. `permissionDecisionReason` is shown to Claude.
|
|
73
79
|
* - `ask` asks the user to confirm the tool call in the UI. `permissionDecisionReason` is shown to the user but not to Claude.
|
|
74
80
|
*/
|
|
75
|
-
permissionDecision
|
|
76
|
-
permissionDecisionReason
|
|
81
|
+
permissionDecision?: "allow" | "ask" | "deny";
|
|
82
|
+
permissionDecisionReason?: string;
|
|
77
83
|
};
|
|
78
84
|
}
|
|
79
85
|
/**
|
|
@@ -81,10 +87,10 @@ interface PreToolUseHookOutput extends CommonHookOutputs {
|
|
|
81
87
|
*/
|
|
82
88
|
interface PostToolUseHookOutput extends CommonHookOutputs {
|
|
83
89
|
/**
|
|
90
|
+
* - `approve` has no effect; the tool response is processed normally.
|
|
84
91
|
* - `block` automatically prompts Claude with `reason`.
|
|
85
|
-
* - `undefined` does nothing. `reason` is ignored.
|
|
86
92
|
*/
|
|
87
|
-
decision
|
|
93
|
+
decision?: "approve" | "block";
|
|
88
94
|
hookSpecificOutput?: {
|
|
89
95
|
hookEventName: "PostToolUse";
|
|
90
96
|
/**
|
|
@@ -99,12 +105,11 @@ interface PostToolUseHookOutput extends CommonHookOutputs {
|
|
|
99
105
|
*/
|
|
100
106
|
interface UserPromptSubmitHookOutput extends CommonHookOutputs {
|
|
101
107
|
/**
|
|
108
|
+
* - `approve` has no effect; the tool response is processed normally.
|
|
102
109
|
* - `block` prevents the prompt from being processed.
|
|
103
110
|
* The submitted prompt is erased from context. `reason` is shown to the user but not added to context.
|
|
104
|
-
*
|
|
105
|
-
* - `undefined` allows the prompt to proceed normally. `reason` is ignored.
|
|
106
111
|
*/
|
|
107
|
-
decision?: "
|
|
112
|
+
decision?: "approve" | "block";
|
|
108
113
|
hookSpecificOutput?: {
|
|
109
114
|
hookEventName: "UserPromptSubmit";
|
|
110
115
|
/**
|
|
@@ -119,11 +124,10 @@ interface UserPromptSubmitHookOutput extends CommonHookOutputs {
|
|
|
119
124
|
*/
|
|
120
125
|
interface StopHookOutput extends CommonHookOutputs {
|
|
121
126
|
/**
|
|
127
|
+
* - `approve` has no effect; the tool response is processed normally.
|
|
122
128
|
* - `block` prevents Claude from stopping. You must populate `reason` for Claude to know how to proceed.
|
|
123
|
-
*
|
|
124
|
-
* - `undefined` allows Claude to stop. `reason` is ignored.
|
|
125
129
|
*/
|
|
126
|
-
decision
|
|
130
|
+
decision?: "approve" | "block";
|
|
127
131
|
/**
|
|
128
132
|
* Reason for the decision.
|
|
129
133
|
*/
|
|
@@ -134,11 +138,9 @@ interface StopHookOutput extends CommonHookOutputs {
|
|
|
134
138
|
*/
|
|
135
139
|
interface SubagentStopHookOutput extends CommonHookOutputs {
|
|
136
140
|
/**
|
|
141
|
+
* - `approve` has no effect; the tool response is processed normally.
|
|
137
142
|
* - `block` prevents Claude from stopping. You must populate `reason` for Claude to know how to proceed.
|
|
138
|
-
*
|
|
139
|
-
* - `undefined` allows Claude to stop. `reason` is ignored.
|
|
140
143
|
*/
|
|
141
|
-
decision: "block" | undefined;
|
|
142
144
|
/**
|
|
143
145
|
* Reason for the decision.
|
|
144
146
|
*/
|
|
@@ -162,6 +164,7 @@ declare const HookInputSchemas: {
|
|
|
162
164
|
readonly PreToolUse: v.ObjectSchema<{
|
|
163
165
|
readonly hook_event_name: v.LiteralSchema<"PreToolUse", undefined>;
|
|
164
166
|
readonly cwd: v.StringSchema<undefined>;
|
|
167
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
165
168
|
readonly session_id: v.StringSchema<undefined>;
|
|
166
169
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
167
170
|
} & {
|
|
@@ -171,6 +174,7 @@ declare const HookInputSchemas: {
|
|
|
171
174
|
readonly PostToolUse: v.ObjectSchema<{
|
|
172
175
|
readonly hook_event_name: v.LiteralSchema<"PostToolUse", undefined>;
|
|
173
176
|
readonly cwd: v.StringSchema<undefined>;
|
|
177
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
174
178
|
readonly session_id: v.StringSchema<undefined>;
|
|
175
179
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
176
180
|
} & {
|
|
@@ -181,14 +185,17 @@ declare const HookInputSchemas: {
|
|
|
181
185
|
readonly Notification: v.ObjectSchema<{
|
|
182
186
|
readonly hook_event_name: v.LiteralSchema<"Notification", undefined>;
|
|
183
187
|
readonly cwd: v.StringSchema<undefined>;
|
|
188
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
184
189
|
readonly session_id: v.StringSchema<undefined>;
|
|
185
190
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
186
191
|
} & {
|
|
187
|
-
message: v.
|
|
192
|
+
message: v.StringSchema<undefined>;
|
|
193
|
+
title: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
188
194
|
}, undefined>;
|
|
189
195
|
readonly UserPromptSubmit: v.ObjectSchema<{
|
|
190
196
|
readonly hook_event_name: v.LiteralSchema<"UserPromptSubmit", undefined>;
|
|
191
197
|
readonly cwd: v.StringSchema<undefined>;
|
|
198
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
192
199
|
readonly session_id: v.StringSchema<undefined>;
|
|
193
200
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
194
201
|
} & {
|
|
@@ -197,39 +204,44 @@ declare const HookInputSchemas: {
|
|
|
197
204
|
readonly Stop: v.ObjectSchema<{
|
|
198
205
|
readonly hook_event_name: v.LiteralSchema<"Stop", undefined>;
|
|
199
206
|
readonly cwd: v.StringSchema<undefined>;
|
|
207
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
200
208
|
readonly session_id: v.StringSchema<undefined>;
|
|
201
209
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
202
210
|
} & {
|
|
203
|
-
stop_hook_active: v.
|
|
211
|
+
stop_hook_active: v.BooleanSchema<undefined>;
|
|
204
212
|
}, undefined>;
|
|
205
213
|
readonly SubagentStop: v.ObjectSchema<{
|
|
206
214
|
readonly hook_event_name: v.LiteralSchema<"SubagentStop", undefined>;
|
|
207
215
|
readonly cwd: v.StringSchema<undefined>;
|
|
216
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
208
217
|
readonly session_id: v.StringSchema<undefined>;
|
|
209
218
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
210
219
|
} & {
|
|
211
|
-
stop_hook_active: v.
|
|
220
|
+
stop_hook_active: v.BooleanSchema<undefined>;
|
|
212
221
|
}, undefined>;
|
|
213
222
|
readonly PreCompact: v.ObjectSchema<{
|
|
214
223
|
readonly hook_event_name: v.LiteralSchema<"PreCompact", undefined>;
|
|
215
224
|
readonly cwd: v.StringSchema<undefined>;
|
|
225
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
216
226
|
readonly session_id: v.StringSchema<undefined>;
|
|
217
227
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
218
228
|
} & {
|
|
219
|
-
custom_instructions: v.StringSchema<undefined>;
|
|
229
|
+
custom_instructions: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
220
230
|
trigger: v.UnionSchema<[v.LiteralSchema<"manual", undefined>, v.LiteralSchema<"auto", undefined>], undefined>;
|
|
221
231
|
}, undefined>;
|
|
222
232
|
readonly SessionStart: v.ObjectSchema<{
|
|
223
233
|
readonly hook_event_name: v.LiteralSchema<"SessionStart", undefined>;
|
|
224
234
|
readonly cwd: v.StringSchema<undefined>;
|
|
235
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
225
236
|
readonly session_id: v.StringSchema<undefined>;
|
|
226
237
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
227
238
|
} & {
|
|
228
|
-
source: v.
|
|
239
|
+
source: v.UnionSchema<[v.LiteralSchema<"startup", undefined>, v.LiteralSchema<"resume", undefined>, v.LiteralSchema<"clear", undefined>, v.LiteralSchema<"compact", undefined>], undefined>;
|
|
229
240
|
}, undefined>;
|
|
230
241
|
readonly SessionEnd: v.ObjectSchema<{
|
|
231
242
|
readonly hook_event_name: v.LiteralSchema<"SessionEnd", undefined>;
|
|
232
243
|
readonly cwd: v.StringSchema<undefined>;
|
|
244
|
+
readonly permission_mode: v.ExactOptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
233
245
|
readonly session_id: v.StringSchema<undefined>;
|
|
234
246
|
readonly transcript_path: v.StringSchema<undefined>;
|
|
235
247
|
} & {
|
|
@@ -273,7 +285,7 @@ type HookInputs = { [EventKey in SupportedHookEvent]: EventKey extends "PreToolU
|
|
|
273
285
|
* ```
|
|
274
286
|
* @package
|
|
275
287
|
*/
|
|
276
|
-
type ExtractAllHookInputsForEvent<TEvent extends SupportedHookEvent> = { [K in keyof HookInputs[TEvent]]: HookInputs[TEvent][K] }[keyof HookInputs[TEvent]];
|
|
288
|
+
type ExtractAllHookInputsForEvent<TEvent$1 extends SupportedHookEvent> = { [K in keyof HookInputs[TEvent$1]]: HookInputs[TEvent$1][K] }[keyof HookInputs[TEvent$1]];
|
|
277
289
|
/**
|
|
278
290
|
* Extracts the hook input type for a specific tool within a given event type.
|
|
279
291
|
* This type utility is used to get strongly-typed inputs for tool-specific hook handlers.
|
|
@@ -294,11 +306,11 @@ type ExtractAllHookInputsForEvent<TEvent extends SupportedHookEvent> = { [K in k
|
|
|
294
306
|
* ```
|
|
295
307
|
* @package
|
|
296
308
|
*/
|
|
297
|
-
type ExtractSpecificHookInputForEvent<TEvent extends SupportedHookEvent, TSpecificKey extends ExtractExtendedSpecificKeys<TEvent>> = { [K in keyof HookInputs[TEvent]]: K extends TSpecificKey ? HookInputs[TEvent][K] : never }[keyof HookInputs[TEvent]];
|
|
309
|
+
type ExtractSpecificHookInputForEvent<TEvent$1 extends SupportedHookEvent, TSpecificKey extends ExtractExtendedSpecificKeys<TEvent$1>> = { [K in keyof HookInputs[TEvent$1]]: K extends TSpecificKey ? HookInputs[TEvent$1][K] : never }[keyof HookInputs[TEvent$1]];
|
|
298
310
|
/**
|
|
299
311
|
* @package
|
|
300
312
|
*/
|
|
301
|
-
type ExtractExtendedSpecificKeys<TEvent extends SupportedHookEvent> = Exclude<keyof HookInputs[TEvent], "default">;
|
|
313
|
+
type ExtractExtendedSpecificKeys<TEvent$1 extends SupportedHookEvent> = Exclude<keyof HookInputs[TEvent$1], "default">;
|
|
302
314
|
type BaseHookInputs = { [EventKey in SupportedHookEvent]: v.InferOutput<(typeof HookInputSchemas)[EventKey]> };
|
|
303
315
|
type ToolSpecificPreToolUseInput = { [K in keyof ToolSchema]: Omit<BaseHookInputs["PreToolUse"], "tool_input" | "tool_name"> & {
|
|
304
316
|
tool_input: ToolSchema[K]["input"];
|
|
@@ -550,15 +562,7 @@ declare function runHook<THookTrigger extends HookTrigger = HookTrigger>(def: Ho
|
|
|
550
562
|
*/
|
|
551
563
|
interface ToolSchema {
|
|
552
564
|
Bash: {
|
|
553
|
-
input:
|
|
554
|
-
command: string;
|
|
555
|
-
description?: string;
|
|
556
|
-
run_in_background?: boolean;
|
|
557
|
-
/**
|
|
558
|
-
* Timeout in milliseconds for the process (ignored if run_in_background is true).
|
|
559
|
-
*/
|
|
560
|
-
timeout?: number;
|
|
561
|
-
};
|
|
565
|
+
input: BashInput;
|
|
562
566
|
response: {
|
|
563
567
|
interrupted: boolean;
|
|
564
568
|
isImage: boolean;
|
|
@@ -567,15 +571,7 @@ interface ToolSchema {
|
|
|
567
571
|
};
|
|
568
572
|
};
|
|
569
573
|
Edit: {
|
|
570
|
-
input:
|
|
571
|
-
file_path: string;
|
|
572
|
-
new_string: string;
|
|
573
|
-
old_string: string;
|
|
574
|
-
/**
|
|
575
|
-
* @default false
|
|
576
|
-
*/
|
|
577
|
-
replace_all?: boolean;
|
|
578
|
-
};
|
|
574
|
+
input: FileEditInput;
|
|
579
575
|
response: {
|
|
580
576
|
filePath: string;
|
|
581
577
|
newString: string;
|
|
@@ -593,13 +589,7 @@ interface ToolSchema {
|
|
|
593
589
|
};
|
|
594
590
|
};
|
|
595
591
|
Glob: {
|
|
596
|
-
input:
|
|
597
|
-
/**
|
|
598
|
-
* @default process.cwd()
|
|
599
|
-
*/
|
|
600
|
-
path?: string;
|
|
601
|
-
pattern: string;
|
|
602
|
-
};
|
|
592
|
+
input: GlobInput;
|
|
603
593
|
response: {
|
|
604
594
|
durationMs: number;
|
|
605
595
|
filenames: string[];
|
|
@@ -608,23 +598,7 @@ interface ToolSchema {
|
|
|
608
598
|
};
|
|
609
599
|
};
|
|
610
600
|
Grep: {
|
|
611
|
-
input:
|
|
612
|
-
"-A"?: number;
|
|
613
|
-
"-B"?: number;
|
|
614
|
-
"-C"?: number;
|
|
615
|
-
"-i"?: boolean;
|
|
616
|
-
"-n"?: boolean;
|
|
617
|
-
glob?: string;
|
|
618
|
-
head_limit?: number;
|
|
619
|
-
multiline?: boolean;
|
|
620
|
-
/**
|
|
621
|
-
* @default "files_with_matches"
|
|
622
|
-
*/
|
|
623
|
-
output_mode?: "content" | "count" | "files_with_matches";
|
|
624
|
-
path?: string;
|
|
625
|
-
pattern: string;
|
|
626
|
-
type?: string;
|
|
627
|
-
};
|
|
601
|
+
input: GrepInput;
|
|
628
602
|
response: {
|
|
629
603
|
content: string;
|
|
630
604
|
mode: "content" | "count" | "files_with_matches";
|
|
@@ -672,27 +646,7 @@ interface ToolSchema {
|
|
|
672
646
|
};
|
|
673
647
|
};
|
|
674
648
|
NotebookEdit: {
|
|
675
|
-
|
|
676
|
-
* @default edit_mode: "replace"
|
|
677
|
-
*/
|
|
678
|
-
input: {
|
|
679
|
-
cell_id: string;
|
|
680
|
-
edit_mode: "delete";
|
|
681
|
-
new_source: string;
|
|
682
|
-
notebook_path: string;
|
|
683
|
-
} | {
|
|
684
|
-
cell_id: string;
|
|
685
|
-
cell_type?: "code" | "markdown";
|
|
686
|
-
edit_mode: "replace";
|
|
687
|
-
new_source: string;
|
|
688
|
-
notebook_path: string;
|
|
689
|
-
} | {
|
|
690
|
-
cell_id?: string;
|
|
691
|
-
cell_type: "code" | "markdown";
|
|
692
|
-
edit_mode: "insert";
|
|
693
|
-
new_source: string;
|
|
694
|
-
notebook_path: string;
|
|
695
|
-
};
|
|
649
|
+
input: NotebookEditInput;
|
|
696
650
|
response: {
|
|
697
651
|
cell_type: "code" | "markdown";
|
|
698
652
|
edit_mode: "delete" | "insert" | "replace";
|
|
@@ -702,11 +656,7 @@ interface ToolSchema {
|
|
|
702
656
|
};
|
|
703
657
|
};
|
|
704
658
|
Read: {
|
|
705
|
-
input:
|
|
706
|
-
file_path: string;
|
|
707
|
-
limit?: number;
|
|
708
|
-
offset?: number;
|
|
709
|
-
};
|
|
659
|
+
input: FileReadInput;
|
|
710
660
|
response: {
|
|
711
661
|
file: {
|
|
712
662
|
cells: Array<{
|
|
@@ -760,23 +710,11 @@ interface ToolSchema {
|
|
|
760
710
|
};
|
|
761
711
|
};
|
|
762
712
|
TodoWrite: {
|
|
763
|
-
input:
|
|
764
|
-
|
|
765
|
-
};
|
|
766
|
-
response: {
|
|
767
|
-
newTodos: ClaudeCodeTodo[];
|
|
768
|
-
oldTodos: ClaudeCodeTodo[];
|
|
769
|
-
};
|
|
713
|
+
input: TodoWriteInput;
|
|
714
|
+
response: unknown;
|
|
770
715
|
};
|
|
771
716
|
WebFetch: {
|
|
772
|
-
input:
|
|
773
|
-
/**
|
|
774
|
-
* @default 100
|
|
775
|
-
*/
|
|
776
|
-
charThreshold?: number;
|
|
777
|
-
prompt: string;
|
|
778
|
-
url: string;
|
|
779
|
-
};
|
|
717
|
+
input: WebFetchInput;
|
|
780
718
|
response: {
|
|
781
719
|
bytes: number;
|
|
782
720
|
code: number;
|
|
@@ -786,11 +724,12 @@ interface ToolSchema {
|
|
|
786
724
|
url: string;
|
|
787
725
|
};
|
|
788
726
|
};
|
|
727
|
+
WebSearch: {
|
|
728
|
+
input: WebSearchInput;
|
|
729
|
+
response: unknown;
|
|
730
|
+
};
|
|
789
731
|
Write: {
|
|
790
|
-
input:
|
|
791
|
-
content: string;
|
|
792
|
-
file_path: string;
|
|
793
|
-
};
|
|
732
|
+
input: FileWriteInput;
|
|
794
733
|
response: {
|
|
795
734
|
content: string;
|
|
796
735
|
filePath: string;
|
package/dist/index.mjs
CHANGED
|
@@ -28,20 +28,9 @@ function createContext(input) {
|
|
|
28
28
|
})
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
const SUPPORTED_HOOK_EVENTS = [
|
|
32
|
-
"PreToolUse",
|
|
33
|
-
"PostToolUse",
|
|
34
|
-
"Notification",
|
|
35
|
-
"UserPromptSubmit",
|
|
36
|
-
"Stop",
|
|
37
|
-
"SubagentStop",
|
|
38
|
-
"PreCompact",
|
|
39
|
-
"SessionStart",
|
|
40
|
-
"SessionEnd"
|
|
41
|
-
];
|
|
42
31
|
const baseHookInputSchema = v.object({
|
|
43
32
|
cwd: v.string(),
|
|
44
|
-
|
|
33
|
+
permission_mode: v.exactOptional(v.string()),
|
|
45
34
|
session_id: v.string(),
|
|
46
35
|
transcript_path: v.string()
|
|
47
36
|
});
|
|
@@ -62,15 +51,23 @@ const HookInputSchemas = {
|
|
|
62
51
|
tool_input: v.unknown(),
|
|
63
52
|
tool_response: v.unknown()
|
|
64
53
|
}),
|
|
65
|
-
Notification: buildHookInputSchema("Notification", {
|
|
54
|
+
Notification: buildHookInputSchema("Notification", {
|
|
55
|
+
message: v.string(),
|
|
56
|
+
title: v.exactOptional(v.string())
|
|
57
|
+
}),
|
|
66
58
|
UserPromptSubmit: buildHookInputSchema("UserPromptSubmit", { prompt: v.string() }),
|
|
67
|
-
Stop: buildHookInputSchema("Stop", { stop_hook_active: v.
|
|
68
|
-
SubagentStop: buildHookInputSchema("SubagentStop", { stop_hook_active: v.
|
|
59
|
+
Stop: buildHookInputSchema("Stop", { stop_hook_active: v.boolean() }),
|
|
60
|
+
SubagentStop: buildHookInputSchema("SubagentStop", { stop_hook_active: v.boolean() }),
|
|
69
61
|
PreCompact: buildHookInputSchema("PreCompact", {
|
|
70
|
-
custom_instructions: v.string(),
|
|
62
|
+
custom_instructions: v.nullable(v.string()),
|
|
71
63
|
trigger: v.union([v.literal("manual"), v.literal("auto")])
|
|
72
64
|
}),
|
|
73
|
-
SessionStart: buildHookInputSchema("SessionStart", { source: v.
|
|
65
|
+
SessionStart: buildHookInputSchema("SessionStart", { source: v.union([
|
|
66
|
+
v.literal("startup"),
|
|
67
|
+
v.literal("resume"),
|
|
68
|
+
v.literal("clear"),
|
|
69
|
+
v.literal("compact")
|
|
70
|
+
]) }),
|
|
74
71
|
SessionEnd: buildHookInputSchema("SessionEnd", { reason: v.string() })
|
|
75
72
|
};
|
|
76
73
|
function isNonEmptyString(value) {
|
|
@@ -80,8 +77,7 @@ async function runHook(def) {
|
|
|
80
77
|
const { run, shouldRun = true, trigger } = def;
|
|
81
78
|
let eventName = null;
|
|
82
79
|
try {
|
|
83
|
-
|
|
84
|
-
if (!proceed) return handleHookResult(eventName, {
|
|
80
|
+
if (!(typeof shouldRun === "function" ? await shouldRun() : shouldRun)) return handleHookResult(eventName, {
|
|
85
81
|
kind: "success",
|
|
86
82
|
payload: {}
|
|
87
83
|
});
|
|
@@ -89,8 +85,7 @@ async function runHook(def) {
|
|
|
89
85
|
const rawInput = readFileSync(process.stdin.fd, "utf-8");
|
|
90
86
|
const parsed = v.parse(inputSchema, JSON.parse(rawInput));
|
|
91
87
|
eventName = parsed.hook_event_name;
|
|
92
|
-
const
|
|
93
|
-
const result = await run(context);
|
|
88
|
+
const result = await run(createContext(parsed));
|
|
94
89
|
handleHookResult(eventName, result);
|
|
95
90
|
} catch (error) {
|
|
96
91
|
handleHookResult(eventName, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-hooks-ts",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Write claude code hooks with type safety",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,22 +42,24 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
+
"@anthropic-ai/claude-code": "2.0.0",
|
|
45
46
|
"@arethetypeswrong/core": "0.18.2",
|
|
46
|
-
"@biomejs/biome": "2.
|
|
47
|
-
"@types/node": "24.
|
|
48
|
-
"@virtual-live-lab/eslint-config": "2.
|
|
47
|
+
"@biomejs/biome": "2.3.4",
|
|
48
|
+
"@types/node": "24.10.0",
|
|
49
|
+
"@virtual-live-lab/eslint-config": "2.3.1",
|
|
49
50
|
"@virtual-live-lab/tsconfig": "2.1.21",
|
|
50
|
-
"eslint": "9.
|
|
51
|
+
"eslint": "9.39.1",
|
|
51
52
|
"eslint-plugin-import-access": "3.0.0",
|
|
52
|
-
"pkg-pr-new": "0.0.
|
|
53
|
-
"publint": "0.3.
|
|
54
|
-
"release-it": "19.0.
|
|
53
|
+
"pkg-pr-new": "0.0.60",
|
|
54
|
+
"publint": "0.3.15",
|
|
55
|
+
"release-it": "19.0.6",
|
|
55
56
|
"release-it-pnpm": "4.6.6",
|
|
56
|
-
"tsdown": "0.
|
|
57
|
-
"
|
|
58
|
-
"typescript
|
|
59
|
-
"
|
|
60
|
-
"
|
|
57
|
+
"tsdown": "0.16.0",
|
|
58
|
+
"type-fest": "5.2.0",
|
|
59
|
+
"typescript": "5.9.3",
|
|
60
|
+
"typescript-eslint": "8.46.3",
|
|
61
|
+
"unplugin-unused": "0.5.5",
|
|
62
|
+
"vitest": "4.0.7"
|
|
61
63
|
},
|
|
62
64
|
"dependencies": {
|
|
63
65
|
"valibot": "^1.1.0"
|