@goodfoot/claude-code-hooks 1.0.9 → 1.0.11

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.
@@ -18,12 +18,12 @@
18
18
  * Options for scaffolding a new hook project.
19
19
  */
20
20
  export interface ScaffoldOptions {
21
- /** Directory path where the project will be created. */
22
- directory: string;
23
- /** Array of hook event names to generate (e.g., ['Stop', 'SubagentStop']). */
24
- hooks: string[];
25
- /** Relative path for hooks.json output in the build script. */
26
- outputPath: string;
21
+ /** Directory path where the project will be created. */
22
+ directory: string;
23
+ /** Array of hook event names to generate (e.g., ['Stop', 'SubagentStop']). */
24
+ hooks: string[];
25
+ /** Relative path for hooks.json output in the build script. */
26
+ outputPath: string;
27
27
  }
28
28
  /**
29
29
  * Scaffolds a new Claude Code hook project.
@@ -18,7 +18,7 @@
18
18
  * const filePath = getFilePath(input);
19
19
  * if (!filePath || !isTsFile(filePath)) return preToolUseOutput({});
20
20
  *
21
- * const result = checkContentForPattern(input, /@ts-ignore/g);
21
+ * const result = checkContentForPattern(input, /@ts-expect-error/g);
22
22
  * if (result?.isAddition) {
23
23
  * return preToolUseOutput({
24
24
  * hookSpecificOutput: {
@@ -34,18 +34,7 @@
34
34
  * @see https://code.claude.com/docs/en/hooks
35
35
  * @module
36
36
  */
37
- import type { PreToolUseInput, PostToolUseInput, PostToolUseFailureInput, PermissionRequestInput } from './inputs.js';
38
- import type {
39
- WriteToolInput,
40
- EditToolInput,
41
- MultiEditToolInput,
42
- ReadToolInput,
43
- BashToolInput,
44
- GlobToolInput,
45
- GrepToolInput,
46
- FileModifyingToolInput,
47
- FileModifyingToolName
48
- } from './tool-inputs.js';
37
+ import type { AgentInput, AskUserQuestionInput, BashInput, ExitPlanModeInput, FileEditInput, FileModifyingToolInput, FileModifyingToolName, FileReadInput, FileWriteInput, GlobInput, GrepInput, KillShellInput, MultiEditToolInput, NotebookEditInput, PermissionRequestInput, PostToolUseFailureInput, PostToolUseInput, PreToolUseInput, TaskOutputInput, TodoWriteInput, WebFetchInput, WebSearchInput } from "./types.js";
49
38
  /**
50
39
  * Union of all hook input types that include tool_input.
51
40
  */
@@ -65,11 +54,9 @@ export type ToolUseInput = PreToolUseInput | PostToolUseInput | PostToolUseFailu
65
54
  * }
66
55
  * ```
67
56
  */
68
- export declare function isWriteTool<T extends ToolUseInput>(
69
- input: T
70
- ): input is T & {
71
- tool_name: 'Write';
72
- tool_input: WriteToolInput;
57
+ export declare function isWriteTool<T extends ToolUseInput>(input: T): input is T & {
58
+ tool_name: "Write";
59
+ tool_input: FileWriteInput;
73
60
  };
74
61
  /**
75
62
  * Type guard for Edit tool inputs.
@@ -85,11 +72,9 @@ export declare function isWriteTool<T extends ToolUseInput>(
85
72
  * }
86
73
  * ```
87
74
  */
88
- export declare function isEditTool<T extends ToolUseInput>(
89
- input: T
90
- ): input is T & {
91
- tool_name: 'Edit';
92
- tool_input: EditToolInput;
75
+ export declare function isEditTool<T extends ToolUseInput>(input: T): input is T & {
76
+ tool_name: "Edit";
77
+ tool_input: FileEditInput;
93
78
  };
94
79
  /**
95
80
  * Type guard for MultiEdit tool inputs.
@@ -106,11 +91,9 @@ export declare function isEditTool<T extends ToolUseInput>(
106
91
  * }
107
92
  * ```
108
93
  */
109
- export declare function isMultiEditTool<T extends ToolUseInput>(
110
- input: T
111
- ): input is T & {
112
- tool_name: 'MultiEdit';
113
- tool_input: MultiEditToolInput;
94
+ export declare function isMultiEditTool<T extends ToolUseInput>(input: T): input is T & {
95
+ tool_name: "MultiEdit";
96
+ tool_input: MultiEditToolInput;
114
97
  };
115
98
  /**
116
99
  * Type guard for any file-modifying tool (Write, Edit, or MultiEdit).
@@ -125,11 +108,9 @@ export declare function isMultiEditTool<T extends ToolUseInput>(
125
108
  * }
126
109
  * ```
127
110
  */
128
- export declare function isFileModifyingTool<T extends ToolUseInput>(
129
- input: T
130
- ): input is T & {
131
- tool_name: FileModifyingToolName;
132
- tool_input: FileModifyingToolInput;
111
+ export declare function isFileModifyingTool<T extends ToolUseInput>(input: T): input is T & {
112
+ tool_name: FileModifyingToolName;
113
+ tool_input: FileModifyingToolInput;
133
114
  };
134
115
  /**
135
116
  * Type guard for Read tool inputs.
@@ -145,11 +126,9 @@ export declare function isFileModifyingTool<T extends ToolUseInput>(
145
126
  * }
146
127
  * ```
147
128
  */
148
- export declare function isReadTool<T extends ToolUseInput>(
149
- input: T
150
- ): input is T & {
151
- tool_name: 'Read';
152
- tool_input: ReadToolInput;
129
+ export declare function isReadTool<T extends ToolUseInput>(input: T): input is T & {
130
+ tool_name: "Read";
131
+ tool_input: FileReadInput;
153
132
  };
154
133
  /**
155
134
  * Type guard for Bash tool inputs.
@@ -165,11 +144,9 @@ export declare function isReadTool<T extends ToolUseInput>(
165
144
  * }
166
145
  * ```
167
146
  */
168
- export declare function isBashTool<T extends ToolUseInput>(
169
- input: T
170
- ): input is T & {
171
- tool_name: 'Bash';
172
- tool_input: BashToolInput;
147
+ export declare function isBashTool<T extends ToolUseInput>(input: T): input is T & {
148
+ tool_name: "Bash";
149
+ tool_input: BashInput;
173
150
  };
174
151
  /**
175
152
  * Type guard for Glob tool inputs.
@@ -185,11 +162,9 @@ export declare function isBashTool<T extends ToolUseInput>(
185
162
  * }
186
163
  * ```
187
164
  */
188
- export declare function isGlobTool<T extends ToolUseInput>(
189
- input: T
190
- ): input is T & {
191
- tool_name: 'Glob';
192
- tool_input: GlobToolInput;
165
+ export declare function isGlobTool<T extends ToolUseInput>(input: T): input is T & {
166
+ tool_name: "Glob";
167
+ tool_input: GlobInput;
193
168
  };
194
169
  /**
195
170
  * Type guard for Grep tool inputs.
@@ -205,11 +180,165 @@ export declare function isGlobTool<T extends ToolUseInput>(
205
180
  * }
206
181
  * ```
207
182
  */
208
- export declare function isGrepTool<T extends ToolUseInput>(
209
- input: T
210
- ): input is T & {
211
- tool_name: 'Grep';
212
- tool_input: GrepToolInput;
183
+ export declare function isGrepTool<T extends ToolUseInput>(input: T): input is T & {
184
+ tool_name: "Grep";
185
+ tool_input: GrepInput;
186
+ };
187
+ /**
188
+ * Type guard for Task tool inputs.
189
+ *
190
+ * Narrows the input type to include a typed AgentInput.
191
+ * @param input - The hook input to check
192
+ * @returns True if the input is for a Task tool
193
+ * @example
194
+ * ```typescript
195
+ * if (isTaskTool(input)) {
196
+ * console.log(input.tool_input.prompt);
197
+ * console.log(input.tool_input.subagent_type);
198
+ * }
199
+ * ```
200
+ */
201
+ export declare function isTaskTool<T extends ToolUseInput>(input: T): input is T & {
202
+ tool_name: "Task";
203
+ tool_input: AgentInput;
204
+ };
205
+ /**
206
+ * Type guard for TaskOutput tool inputs.
207
+ *
208
+ * Narrows the input type to include a typed TaskOutputInput.
209
+ * @param input - The hook input to check
210
+ * @returns True if the input is for a TaskOutput tool
211
+ * @example
212
+ * ```typescript
213
+ * if (isTaskOutputTool(input)) {
214
+ * console.log(input.tool_input.task_id);
215
+ * }
216
+ * ```
217
+ */
218
+ export declare function isTaskOutputTool<T extends ToolUseInput>(input: T): input is T & {
219
+ tool_name: "TaskOutput";
220
+ tool_input: TaskOutputInput;
221
+ };
222
+ /**
223
+ * Type guard for ExitPlanMode tool inputs.
224
+ *
225
+ * Narrows the input type to include a typed ExitPlanModeInput.
226
+ * @param input - The hook input to check
227
+ * @returns True if the input is for an ExitPlanMode tool
228
+ * @example
229
+ * ```typescript
230
+ * if (isExitPlanModeTool(input)) {
231
+ * console.log(input.tool_input.allowedPrompts);
232
+ * }
233
+ * ```
234
+ */
235
+ export declare function isExitPlanModeTool<T extends ToolUseInput>(input: T): input is T & {
236
+ tool_name: "ExitPlanMode";
237
+ tool_input: ExitPlanModeInput;
238
+ };
239
+ /**
240
+ * Type guard for KillShell tool inputs.
241
+ *
242
+ * Narrows the input type to include a typed KillShellInput.
243
+ * @param input - The hook input to check
244
+ * @returns True if the input is for a KillShell tool
245
+ * @example
246
+ * ```typescript
247
+ * if (isKillShellTool(input)) {
248
+ * console.log(input.tool_input.shell_id);
249
+ * }
250
+ * ```
251
+ */
252
+ export declare function isKillShellTool<T extends ToolUseInput>(input: T): input is T & {
253
+ tool_name: "KillShell";
254
+ tool_input: KillShellInput;
255
+ };
256
+ /**
257
+ * Type guard for NotebookEdit tool inputs.
258
+ *
259
+ * Narrows the input type to include a typed NotebookEditInput.
260
+ * @param input - The hook input to check
261
+ * @returns True if the input is for a NotebookEdit tool
262
+ * @example
263
+ * ```typescript
264
+ * if (isNotebookEditTool(input)) {
265
+ * console.log(input.tool_input.notebook_path);
266
+ * console.log(input.tool_input.new_source);
267
+ * }
268
+ * ```
269
+ */
270
+ export declare function isNotebookEditTool<T extends ToolUseInput>(input: T): input is T & {
271
+ tool_name: "NotebookEdit";
272
+ tool_input: NotebookEditInput;
273
+ };
274
+ /**
275
+ * Type guard for TodoWrite tool inputs.
276
+ *
277
+ * Narrows the input type to include a typed TodoWriteInput.
278
+ * @param input - The hook input to check
279
+ * @returns True if the input is for a TodoWrite tool
280
+ * @example
281
+ * ```typescript
282
+ * if (isTodoWriteTool(input)) {
283
+ * console.log(input.tool_input.todos);
284
+ * }
285
+ * ```
286
+ */
287
+ export declare function isTodoWriteTool<T extends ToolUseInput>(input: T): input is T & {
288
+ tool_name: "TodoWrite";
289
+ tool_input: TodoWriteInput;
290
+ };
291
+ /**
292
+ * Type guard for WebFetch tool inputs.
293
+ *
294
+ * Narrows the input type to include a typed WebFetchInput.
295
+ * @param input - The hook input to check
296
+ * @returns True if the input is for a WebFetch tool
297
+ * @example
298
+ * ```typescript
299
+ * if (isWebFetchTool(input)) {
300
+ * console.log(input.tool_input.url);
301
+ * console.log(input.tool_input.prompt);
302
+ * }
303
+ * ```
304
+ */
305
+ export declare function isWebFetchTool<T extends ToolUseInput>(input: T): input is T & {
306
+ tool_name: "WebFetch";
307
+ tool_input: WebFetchInput;
308
+ };
309
+ /**
310
+ * Type guard for WebSearch tool inputs.
311
+ *
312
+ * Narrows the input type to include a typed WebSearchInput.
313
+ * @param input - The hook input to check
314
+ * @returns True if the input is for a WebSearch tool
315
+ * @example
316
+ * ```typescript
317
+ * if (isWebSearchTool(input)) {
318
+ * console.log(input.tool_input.query);
319
+ * }
320
+ * ```
321
+ */
322
+ export declare function isWebSearchTool<T extends ToolUseInput>(input: T): input is T & {
323
+ tool_name: "WebSearch";
324
+ tool_input: WebSearchInput;
325
+ };
326
+ /**
327
+ * Type guard for AskUserQuestion tool inputs.
328
+ *
329
+ * Narrows the input type to include a typed AskUserQuestionInput.
330
+ * @param input - The hook input to check
331
+ * @returns True if the input is for an AskUserQuestion tool
332
+ * @example
333
+ * ```typescript
334
+ * if (isAskUserQuestionTool(input)) {
335
+ * console.log(input.tool_input.questions);
336
+ * }
337
+ * ```
338
+ */
339
+ export declare function isAskUserQuestionTool<T extends ToolUseInput>(input: T): input is T & {
340
+ tool_name: "AskUserQuestion";
341
+ tool_input: AskUserQuestionInput;
213
342
  };
214
343
  /**
215
344
  * Extracts the file path from a tool input.
@@ -259,23 +388,23 @@ export declare function isTsFile(filePath: string): boolean;
259
388
  * Result of checking content for a pattern.
260
389
  */
261
390
  export interface PatternCheckResult {
262
- /** True if the pattern was found in any content. */
263
- found: boolean;
264
- /** True if the pattern is being added (not present in old content, present in new). */
265
- isAddition: boolean;
266
- /** All matches found across all content (deduplicated). */
267
- matches: string[];
268
- /** Per-edit details for MultiEdit operations. */
269
- details?: Array<{
270
- /** Index of the edit (for MultiEdit) or 0 for Write/Edit. */
271
- index: number;
272
- /** True if found in this edit. */
391
+ /** True if the pattern was found in any content. */
273
392
  found: boolean;
274
- /** True if this edit adds the pattern. */
393
+ /** True if the pattern is being added (not present in old content, present in new). */
275
394
  isAddition: boolean;
276
- /** Matches in this edit. */
395
+ /** All matches found across all content (deduplicated). */
277
396
  matches: string[];
278
- }>;
397
+ /** Per-edit details for MultiEdit operations. */
398
+ details?: Array<{
399
+ /** Index of the edit (for MultiEdit) or 0 for Write/Edit. */
400
+ index: number;
401
+ /** True if found in this edit. */
402
+ found: boolean;
403
+ /** True if this edit adds the pattern. */
404
+ isAddition: boolean;
405
+ /** Matches in this edit. */
406
+ matches: string[];
407
+ }>;
279
408
  }
280
409
  /**
281
410
  * Checks if a pattern exists in the content being written or edited.
@@ -288,8 +417,8 @@ export interface PatternCheckResult {
288
417
  * @returns Result object, or null if not a file-modifying tool
289
418
  * @example
290
419
  * ```typescript
291
- * // Block @ts-ignore being added
292
- * const result = checkContentForPattern(input, /@ts-ignore/g);
420
+ * // Block @ts-expect-error being added
421
+ * const result = checkContentForPattern(input, /@ts-expect-error/g);
293
422
  * if (result?.isAddition) {
294
423
  * return preToolUseOutput({
295
424
  * hookSpecificOutput: {
@@ -305,14 +434,14 @@ export declare function checkContentForPattern(input: PreToolUseInput, pattern:
305
434
  * Context passed to the forEachContent callback.
306
435
  */
307
436
  export interface ContentContext {
308
- /** The new content being written or replacing old content. */
309
- newContent: string;
310
- /** The old content being replaced (null for Write). */
311
- oldContent: string | null;
312
- /** Index of the edit (0 for Write/Edit, index for MultiEdit). */
313
- index: number;
314
- /** True if this is a Write operation (not Edit/MultiEdit). */
315
- isWrite: boolean;
437
+ /** The new content being written or replacing old content. */
438
+ newContent: string;
439
+ /** The old content being replaced (null for Write). */
440
+ oldContent: string | null;
441
+ /** Index of the edit (0 for Write/Edit, index for MultiEdit). */
442
+ index: number;
443
+ /** True if this is a Write operation (not Edit/MultiEdit). */
444
+ isWrite: boolean;
316
445
  }
317
446
  /**
318
447
  * Iterates over content in Write/Edit/MultiEdit operations.