@goodfoot/agent-hooks 1.0.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.
Files changed (68) hide show
  1. package/README.md +137 -0
  2. package/dist/agents/antigravity/events.js +42 -0
  3. package/dist/agents/antigravity/hooks.js +59 -0
  4. package/dist/agents/antigravity/index.js +28 -0
  5. package/dist/agents/antigravity/outputs.js +81 -0
  6. package/dist/agents/antigravity/transport.js +84 -0
  7. package/dist/agents/antigravity/types.js +11 -0
  8. package/dist/agents/claude-code/env.js +27 -0
  9. package/dist/agents/claude-code/events.js +87 -0
  10. package/dist/agents/claude-code/hooks.js +1000 -0
  11. package/dist/agents/claude-code/index.js +57 -0
  12. package/dist/agents/claude-code/outputs.js +579 -0
  13. package/dist/agents/claude-code/tool-helpers.js +840 -0
  14. package/dist/agents/claude-code/transport.js +254 -0
  15. package/dist/agents/claude-code/types.js +11 -0
  16. package/dist/agents/codex/cli-support.js +318 -0
  17. package/dist/agents/codex/constants.js +29 -0
  18. package/dist/agents/codex/events.js +68 -0
  19. package/dist/agents/codex/hooks.js +93 -0
  20. package/dist/agents/codex/index.js +21 -0
  21. package/dist/agents/codex/outputs.js +189 -0
  22. package/dist/agents/codex/scaffold.js +273 -0
  23. package/dist/agents/codex/transport.js +139 -0
  24. package/dist/agents/codex/types.js +1 -0
  25. package/dist/cli.js +1357 -0
  26. package/dist/constants.js +39 -0
  27. package/dist/core/define-hook.js +61 -0
  28. package/dist/core/env.js +186 -0
  29. package/dist/core/logger.js +508 -0
  30. package/dist/core/stdin.js +38 -0
  31. package/dist/core/transport.js +231 -0
  32. package/dist/core/types.js +10 -0
  33. package/dist/index.js +17 -0
  34. package/dist/scaffold.js +512 -0
  35. package/package.json +61 -0
  36. package/types/agents/antigravity/events.d.ts +50 -0
  37. package/types/agents/antigravity/hooks.d.ts +76 -0
  38. package/types/agents/antigravity/index.d.ts +27 -0
  39. package/types/agents/antigravity/outputs.d.ts +107 -0
  40. package/types/agents/antigravity/transport.d.ts +47 -0
  41. package/types/agents/antigravity/types.d.ts +58 -0
  42. package/types/agents/claude-code/env.d.ts +27 -0
  43. package/types/agents/claude-code/events.d.ts +69 -0
  44. package/types/agents/claude-code/hooks.d.ts +1182 -0
  45. package/types/agents/claude-code/index.d.ts +23 -0
  46. package/types/agents/claude-code/outputs.d.ts +1160 -0
  47. package/types/agents/claude-code/tool-helpers.d.ts +807 -0
  48. package/types/agents/claude-code/transport.d.ts +119 -0
  49. package/types/agents/claude-code/types.d.ts +557 -0
  50. package/types/agents/codex/cli-support.d.ts +105 -0
  51. package/types/agents/codex/constants.d.ts +10 -0
  52. package/types/agents/codex/events.d.ts +63 -0
  53. package/types/agents/codex/hooks.d.ts +135 -0
  54. package/types/agents/codex/index.d.ts +19 -0
  55. package/types/agents/codex/outputs.d.ts +190 -0
  56. package/types/agents/codex/scaffold.d.ts +14 -0
  57. package/types/agents/codex/transport.d.ts +74 -0
  58. package/types/agents/codex/types.d.ts +131 -0
  59. package/types/cli.d.ts +315 -0
  60. package/types/constants.d.ts +9 -0
  61. package/types/core/define-hook.d.ts +39 -0
  62. package/types/core/env.d.ts +150 -0
  63. package/types/core/logger.d.ts +476 -0
  64. package/types/core/stdin.d.ts +21 -0
  65. package/types/core/transport.d.ts +131 -0
  66. package/types/core/types.d.ts +137 -0
  67. package/types/index.d.ts +18 -0
  68. package/types/scaffold.d.ts +46 -0
@@ -0,0 +1,807 @@
1
+ /**
2
+ * Type guards and helper functions for Claude Code tool inputs.
3
+ *
4
+ * Provides safe type narrowing for tool inputs and utility functions
5
+ * for common patterns like file path extraction and content inspection.
6
+ * @example
7
+ * ```typescript
8
+ * import {
9
+ * preToolUseHook,
10
+ * preToolUseOutput,
11
+ * isWriteTool,
12
+ * getFilePath,
13
+ * isTsFile,
14
+ * checkContentForPattern
15
+ * } from '@goodfoot/agent-hooks/claude-code';
16
+ *
17
+ * export default preToolUseHook({ matcher: 'Write|Edit|MultiEdit' }, (input) => {
18
+ * const filePath = getFilePath(input);
19
+ * if (!filePath || !isTsFile(filePath)) return preToolUseOutput({});
20
+ *
21
+ * const result = checkContentForPattern(input, /@ts-expect-error/g);
22
+ * if (result?.isAddition) {
23
+ * return preToolUseOutput({
24
+ * hookSpecificOutput: {
25
+ * permissionDecision: 'deny',
26
+ * permissionDecisionReason: `Cannot add: ${result.matches.join(', ')}`
27
+ * }
28
+ * });
29
+ * }
30
+ *
31
+ * return preToolUseOutput({});
32
+ * });
33
+ * ```
34
+ * @see https://code.claude.com/docs/en/hooks
35
+ * @module
36
+ */
37
+ import type { AgentInput, AskUserQuestionInput, BashInput, ConfigInput, CronCreateInput, CronDeleteInput, CronListInput, EnterPlanModeInput, EnterWorktreeInput, ExitPlanModeInput, ExitWorktreeInput, FileEditInput, FileModifyingToolInput, FileModifyingToolName, FileReadInput, FileWriteInput, GlobInput, GrepInput, TaskStopInput as KillShellInput, ListMcpResourcesInput, McpInput, MonitorInput, MultiEditToolInput, NotebookEditInput, PermissionRequestInput, PushNotificationInput, REPLInput, ReadMcpResourceInput, RemoteTriggerInput, ScheduleWakeupInput, SDKPostToolUseFailureHookInput, SDKPostToolUseHookInput, SDKPreToolUseHookInput, TaskCreateInput, TaskGetInput, TaskListInput, TaskOutputInput, TaskUpdateInput, TodoWriteInput, WebFetchInput, WebSearchInput, WorkflowInput } from "./types.js";
38
+ /**
39
+ * Union of all hook input types that include tool_input.
40
+ */
41
+ export type ToolUseInput = SDKPreToolUseHookInput | SDKPostToolUseHookInput | SDKPostToolUseFailureHookInput | PermissionRequestInput;
42
+ /**
43
+ * Type guard for Write tool inputs.
44
+ *
45
+ * Narrows the input type to include a typed WriteToolInput.
46
+ * @param input - The hook input to check
47
+ * @returns True if the input is for a Write tool
48
+ * @example
49
+ * ```typescript
50
+ * if (isWriteTool(input)) {
51
+ * // input.tool_input is now typed as WriteToolInput
52
+ * console.log(input.tool_input.file_path);
53
+ * console.log(input.tool_input.content);
54
+ * }
55
+ * ```
56
+ */
57
+ export declare function isWriteTool<T extends ToolUseInput>(input: T): input is T & {
58
+ tool_name: "Write";
59
+ tool_input: FileWriteInput;
60
+ };
61
+ /**
62
+ * Type guard for Edit tool inputs.
63
+ *
64
+ * Narrows the input type to include a typed EditToolInput.
65
+ * @param input - The hook input to check
66
+ * @returns True if the input is for an Edit tool
67
+ * @example
68
+ * ```typescript
69
+ * if (isEditTool(input)) {
70
+ * console.log(input.tool_input.old_string);
71
+ * console.log(input.tool_input.new_string);
72
+ * }
73
+ * ```
74
+ */
75
+ export declare function isEditTool<T extends ToolUseInput>(input: T): input is T & {
76
+ tool_name: "Edit";
77
+ tool_input: FileEditInput;
78
+ };
79
+ /**
80
+ * Type guard for MultiEdit tool inputs.
81
+ *
82
+ * Narrows the input type to include a typed MultiEditToolInput.
83
+ * @param input - The hook input to check
84
+ * @returns True if the input is for a MultiEdit tool
85
+ * @example
86
+ * ```typescript
87
+ * if (isMultiEditTool(input)) {
88
+ * for (const edit of input.tool_input.edits) {
89
+ * console.log(`${edit.old_string} -> ${edit.new_string}`);
90
+ * }
91
+ * }
92
+ * ```
93
+ */
94
+ export declare function isMultiEditTool<T extends ToolUseInput>(input: T): input is T & {
95
+ tool_name: "MultiEdit";
96
+ tool_input: MultiEditToolInput;
97
+ };
98
+ /**
99
+ * Type guard for any file-modifying tool (Write, Edit, or MultiEdit).
100
+ *
101
+ * Use this when you need to handle all file modifications generically.
102
+ * @param input - The hook input to check
103
+ * @returns True if the input is for a Write, Edit, or MultiEdit tool
104
+ * @example
105
+ * ```typescript
106
+ * if (isFileModifyingTool(input)) {
107
+ * const filePath = getFilePath(input); // Works for all three types
108
+ * }
109
+ * ```
110
+ */
111
+ export declare function isFileModifyingTool<T extends ToolUseInput>(input: T): input is T & {
112
+ tool_name: FileModifyingToolName;
113
+ tool_input: FileModifyingToolInput;
114
+ };
115
+ /**
116
+ * Type guard for Read tool inputs.
117
+ *
118
+ * Narrows the input type to include a typed ReadToolInput.
119
+ * @param input - The hook input to check
120
+ * @returns True if the input is for a Read tool
121
+ * @example
122
+ * ```typescript
123
+ * if (isReadTool(input)) {
124
+ * console.log(input.tool_input.file_path);
125
+ * console.log(input.tool_input.offset);
126
+ * }
127
+ * ```
128
+ */
129
+ export declare function isReadTool<T extends ToolUseInput>(input: T): input is T & {
130
+ tool_name: "Read";
131
+ tool_input: FileReadInput;
132
+ };
133
+ /**
134
+ * Type guard for Bash tool inputs.
135
+ *
136
+ * Narrows the input type to include a typed BashToolInput.
137
+ * @param input - The hook input to check
138
+ * @returns True if the input is for a Bash tool
139
+ * @example
140
+ * ```typescript
141
+ * if (isBashTool(input)) {
142
+ * console.log(input.tool_input.command);
143
+ * console.log(input.tool_input.timeout);
144
+ * }
145
+ * ```
146
+ */
147
+ export declare function isBashTool<T extends ToolUseInput>(input: T): input is T & {
148
+ tool_name: "Bash";
149
+ tool_input: BashInput;
150
+ };
151
+ /**
152
+ * Type guard for Glob tool inputs.
153
+ *
154
+ * Narrows the input type to include a typed GlobToolInput.
155
+ * @param input - The hook input to check
156
+ * @returns True if the input is for a Glob tool
157
+ * @example
158
+ * ```typescript
159
+ * if (isGlobTool(input)) {
160
+ * console.log(input.tool_input.pattern);
161
+ * console.log(input.tool_input.path);
162
+ * }
163
+ * ```
164
+ */
165
+ export declare function isGlobTool<T extends ToolUseInput>(input: T): input is T & {
166
+ tool_name: "Glob";
167
+ tool_input: GlobInput;
168
+ };
169
+ /**
170
+ * Type guard for Grep tool inputs.
171
+ *
172
+ * Narrows the input type to include a typed GrepToolInput.
173
+ * @param input - The hook input to check
174
+ * @returns True if the input is for a Grep tool
175
+ * @example
176
+ * ```typescript
177
+ * if (isGrepTool(input)) {
178
+ * console.log(input.tool_input.pattern);
179
+ * console.log(input.tool_input.glob);
180
+ * }
181
+ * ```
182
+ */
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 Agent 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 an Agent 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: "Agent";
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;
342
+ };
343
+ /**
344
+ * Type guard for ListMcpResources tool inputs.
345
+ *
346
+ * Narrows the input type to include a typed ListMcpResourcesInput.
347
+ * @param input - The hook input to check
348
+ * @returns True if the input is for a ListMcpResources tool
349
+ * @example
350
+ * ```typescript
351
+ * if (isListMcpResourcesTool(input)) {
352
+ * console.log(input.tool_input.server);
353
+ * }
354
+ * ```
355
+ */
356
+ export declare function isListMcpResourcesTool<T extends ToolUseInput>(input: T): input is T & {
357
+ tool_name: "ListMcpResources";
358
+ tool_input: ListMcpResourcesInput;
359
+ };
360
+ /**
361
+ * Type guard for Mcp tool inputs.
362
+ *
363
+ * Narrows the input type to include a typed McpInput.
364
+ * @param input - The hook input to check
365
+ * @returns True if the input is for an Mcp tool
366
+ * @example
367
+ * ```typescript
368
+ * if (isMcpTool(input)) {
369
+ * // input.tool_input is now typed as McpInput
370
+ * }
371
+ * ```
372
+ */
373
+ export declare function isMcpTool<T extends ToolUseInput>(input: T): input is T & {
374
+ tool_name: "Mcp";
375
+ tool_input: McpInput;
376
+ };
377
+ /**
378
+ * Type guard for ReadMcpResource tool inputs.
379
+ *
380
+ * Narrows the input type to include a typed ReadMcpResourceInput.
381
+ * @param input - The hook input to check
382
+ * @returns True if the input is for a ReadMcpResource tool
383
+ * @example
384
+ * ```typescript
385
+ * if (isReadMcpResourceTool(input)) {
386
+ * console.log(input.tool_input.server);
387
+ * console.log(input.tool_input.uri);
388
+ * }
389
+ * ```
390
+ */
391
+ export declare function isReadMcpResourceTool<T extends ToolUseInput>(input: T): input is T & {
392
+ tool_name: "ReadMcpResource";
393
+ tool_input: ReadMcpResourceInput;
394
+ };
395
+ /**
396
+ * Type guard for Config tool inputs.
397
+ *
398
+ * Narrows the input type to include a typed ConfigInput.
399
+ * @param input - The hook input to check
400
+ * @returns True if the input is for a Config tool
401
+ * @example
402
+ * ```typescript
403
+ * if (isConfigTool(input)) {
404
+ * console.log(input.tool_input.setting);
405
+ * console.log(input.tool_input.value);
406
+ * }
407
+ * ```
408
+ */
409
+ export declare function isConfigTool<T extends ToolUseInput>(input: T): input is T & {
410
+ tool_name: "Config";
411
+ tool_input: ConfigInput;
412
+ };
413
+ /**
414
+ * Type guard for TaskCreate tool inputs.
415
+ *
416
+ * Narrows the input type to include a typed TaskCreateInput.
417
+ * @param input - The hook input to check
418
+ * @returns True if the input is for a TaskCreate tool
419
+ * @example
420
+ * ```typescript
421
+ * if (isTaskCreateTool(input)) {
422
+ * console.log(input.tool_input.subject);
423
+ * }
424
+ * ```
425
+ */
426
+ export declare function isTaskCreateTool<T extends ToolUseInput>(input: T): input is T & {
427
+ tool_name: "TaskCreate";
428
+ tool_input: TaskCreateInput;
429
+ };
430
+ /**
431
+ * Type guard for TaskGet tool inputs.
432
+ *
433
+ * Narrows the input type to include a typed TaskGetInput.
434
+ * @param input - The hook input to check
435
+ * @returns True if the input is for a TaskGet tool
436
+ * @example
437
+ * ```typescript
438
+ * if (isTaskGetTool(input)) {
439
+ * console.log(input.tool_input.taskId);
440
+ * }
441
+ * ```
442
+ */
443
+ export declare function isTaskGetTool<T extends ToolUseInput>(input: T): input is T & {
444
+ tool_name: "TaskGet";
445
+ tool_input: TaskGetInput;
446
+ };
447
+ /**
448
+ * Type guard for TaskList tool inputs.
449
+ *
450
+ * Narrows the input type to include a typed TaskListInput.
451
+ * @param input - The hook input to check
452
+ * @returns True if the input is for a TaskList tool
453
+ * @example
454
+ * ```typescript
455
+ * if (isTaskListTool(input)) {
456
+ * // input.tool_input is now typed as TaskListInput
457
+ * }
458
+ * ```
459
+ */
460
+ export declare function isTaskListTool<T extends ToolUseInput>(input: T): input is T & {
461
+ tool_name: "TaskList";
462
+ tool_input: TaskListInput;
463
+ };
464
+ /**
465
+ * Type guard for TaskUpdate tool inputs.
466
+ *
467
+ * Narrows the input type to include a typed TaskUpdateInput.
468
+ * @param input - The hook input to check
469
+ * @returns True if the input is for a TaskUpdate tool
470
+ * @example
471
+ * ```typescript
472
+ * if (isTaskUpdateTool(input)) {
473
+ * console.log(input.tool_input.taskId, input.tool_input.status);
474
+ * }
475
+ * ```
476
+ */
477
+ export declare function isTaskUpdateTool<T extends ToolUseInput>(input: T): input is T & {
478
+ tool_name: "TaskUpdate";
479
+ tool_input: TaskUpdateInput;
480
+ };
481
+ /**
482
+ * Type guard for CronCreate tool inputs.
483
+ *
484
+ * Narrows the input type to include a typed CronCreateInput.
485
+ * @param input - The hook input to check
486
+ * @returns True if the input is for a CronCreate tool
487
+ * @example
488
+ * ```typescript
489
+ * if (isCronCreateTool(input)) {
490
+ * console.log(input.tool_input.cron, input.tool_input.prompt);
491
+ * }
492
+ * ```
493
+ */
494
+ export declare function isCronCreateTool<T extends ToolUseInput>(input: T): input is T & {
495
+ tool_name: "CronCreate";
496
+ tool_input: CronCreateInput;
497
+ };
498
+ /**
499
+ * Type guard for CronDelete tool inputs.
500
+ *
501
+ * Narrows the input type to include a typed CronDeleteInput.
502
+ * @param input - The hook input to check
503
+ * @returns True if the input is for a CronDelete tool
504
+ * @example
505
+ * ```typescript
506
+ * if (isCronDeleteTool(input)) {
507
+ * console.log(input.tool_input.id);
508
+ * }
509
+ * ```
510
+ */
511
+ export declare function isCronDeleteTool<T extends ToolUseInput>(input: T): input is T & {
512
+ tool_name: "CronDelete";
513
+ tool_input: CronDeleteInput;
514
+ };
515
+ /**
516
+ * Type guard for CronList tool inputs.
517
+ *
518
+ * Narrows the input type to include a typed CronListInput.
519
+ * @param input - The hook input to check
520
+ * @returns True if the input is for a CronList tool
521
+ * @example
522
+ * ```typescript
523
+ * if (isCronListTool(input)) {
524
+ * // input.tool_input is now typed as CronListInput
525
+ * }
526
+ * ```
527
+ */
528
+ export declare function isCronListTool<T extends ToolUseInput>(input: T): input is T & {
529
+ tool_name: "CronList";
530
+ tool_input: CronListInput;
531
+ };
532
+ /**
533
+ * Type guard for ScheduleWakeup tool inputs.
534
+ *
535
+ * Narrows the input type to include a typed ScheduleWakeupInput.
536
+ * @param input - The hook input to check
537
+ * @returns True if the input is for a ScheduleWakeup tool
538
+ * @example
539
+ * ```typescript
540
+ * if (isScheduleWakeupTool(input)) {
541
+ * console.log(input.tool_input.delaySeconds);
542
+ * }
543
+ * ```
544
+ */
545
+ export declare function isScheduleWakeupTool<T extends ToolUseInput>(input: T): input is T & {
546
+ tool_name: "ScheduleWakeup";
547
+ tool_input: ScheduleWakeupInput;
548
+ };
549
+ /**
550
+ * Type guard for Monitor tool inputs.
551
+ *
552
+ * Narrows the input type to include a typed MonitorInput.
553
+ * @param input - The hook input to check
554
+ * @returns True if the input is for a Monitor tool
555
+ * @example
556
+ * ```typescript
557
+ * if (isMonitorTool(input)) {
558
+ * console.log(input.tool_input.command);
559
+ * }
560
+ * ```
561
+ */
562
+ export declare function isMonitorTool<T extends ToolUseInput>(input: T): input is T & {
563
+ tool_name: "Monitor";
564
+ tool_input: MonitorInput;
565
+ };
566
+ /**
567
+ * Type guard for RemoteTrigger tool inputs.
568
+ *
569
+ * Narrows the input type to include a typed RemoteTriggerInput.
570
+ * @param input - The hook input to check
571
+ * @returns True if the input is for a RemoteTrigger tool
572
+ * @example
573
+ * ```typescript
574
+ * if (isRemoteTriggerTool(input)) {
575
+ * console.log(input.tool_input.action);
576
+ * }
577
+ * ```
578
+ */
579
+ export declare function isRemoteTriggerTool<T extends ToolUseInput>(input: T): input is T & {
580
+ tool_name: "RemoteTrigger";
581
+ tool_input: RemoteTriggerInput;
582
+ };
583
+ /**
584
+ * Type guard for PushNotification tool inputs.
585
+ *
586
+ * Narrows the input type to include a typed PushNotificationInput.
587
+ * @param input - The hook input to check
588
+ * @returns True if the input is for a PushNotification tool
589
+ * @example
590
+ * ```typescript
591
+ * if (isPushNotificationTool(input)) {
592
+ * console.log(input.tool_input.message);
593
+ * }
594
+ * ```
595
+ */
596
+ export declare function isPushNotificationTool<T extends ToolUseInput>(input: T): input is T & {
597
+ tool_name: "PushNotification";
598
+ tool_input: PushNotificationInput;
599
+ };
600
+ /**
601
+ * Type guard for EnterPlanMode tool inputs.
602
+ *
603
+ * Narrows the input type to include a typed EnterPlanModeInput.
604
+ * @param input - The hook input to check
605
+ * @returns True if the input is for an EnterPlanMode tool
606
+ * @example
607
+ * ```typescript
608
+ * if (isEnterPlanModeTool(input)) {
609
+ * // input.tool_input is now typed as EnterPlanModeInput
610
+ * }
611
+ * ```
612
+ */
613
+ export declare function isEnterPlanModeTool<T extends ToolUseInput>(input: T): input is T & {
614
+ tool_name: "EnterPlanMode";
615
+ tool_input: EnterPlanModeInput;
616
+ };
617
+ /**
618
+ * Type guard for EnterWorktree tool inputs.
619
+ *
620
+ * Narrows the input type to include a typed EnterWorktreeInput.
621
+ * @param input - The hook input to check
622
+ * @returns True if the input is for an EnterWorktree tool
623
+ * @example
624
+ * ```typescript
625
+ * if (isEnterWorktreeTool(input)) {
626
+ * console.log(input.tool_input.name);
627
+ * }
628
+ * ```
629
+ */
630
+ export declare function isEnterWorktreeTool<T extends ToolUseInput>(input: T): input is T & {
631
+ tool_name: "EnterWorktree";
632
+ tool_input: EnterWorktreeInput;
633
+ };
634
+ /**
635
+ * Type guard for ExitWorktree tool inputs.
636
+ *
637
+ * Narrows the input type to include a typed ExitWorktreeInput.
638
+ * @param input - The hook input to check
639
+ * @returns True if the input is for an ExitWorktree tool
640
+ * @example
641
+ * ```typescript
642
+ * if (isExitWorktreeTool(input)) {
643
+ * console.log(input.tool_input.action);
644
+ * }
645
+ * ```
646
+ */
647
+ export declare function isExitWorktreeTool<T extends ToolUseInput>(input: T): input is T & {
648
+ tool_name: "ExitWorktree";
649
+ tool_input: ExitWorktreeInput;
650
+ };
651
+ /**
652
+ * Type guard for REPL tool inputs.
653
+ *
654
+ * Narrows the input type to include a typed REPLInput.
655
+ * @param input - The hook input to check
656
+ * @returns True if the input is for a REPL tool
657
+ * @example
658
+ * ```typescript
659
+ * if (isReplTool(input)) {
660
+ * console.log(input.tool_input.code);
661
+ * }
662
+ * ```
663
+ */
664
+ export declare function isReplTool<T extends ToolUseInput>(input: T): input is T & {
665
+ tool_name: "REPL";
666
+ tool_input: REPLInput;
667
+ };
668
+ /**
669
+ * Type guard for Workflow tool inputs.
670
+ *
671
+ * Narrows the input type to include a typed WorkflowInput.
672
+ * @param input - The hook input to check
673
+ * @returns True if the input is for a Workflow tool
674
+ * @example
675
+ * ```typescript
676
+ * if (isWorkflowTool(input)) {
677
+ * console.log(input.tool_input.name);
678
+ * }
679
+ * ```
680
+ */
681
+ export declare function isWorkflowTool<T extends ToolUseInput>(input: T): input is T & {
682
+ tool_name: "Workflow";
683
+ tool_input: WorkflowInput;
684
+ };
685
+ /**
686
+ * Extracts the file path from a tool input.
687
+ *
688
+ * Works with Write, Edit, MultiEdit, and Read tools.
689
+ * Returns null for other tools or if file_path is missing.
690
+ * @param input - The hook input to extract from
691
+ * @returns The file path, or null if not applicable
692
+ * @example
693
+ * ```typescript
694
+ * const filePath = getFilePath(input);
695
+ * if (filePath && isTsFile(filePath)) {
696
+ * // Handle TypeScript file
697
+ * }
698
+ * ```
699
+ */
700
+ export declare function getFilePath(input: ToolUseInput): string | null;
701
+ /**
702
+ * Checks if a file path is a JavaScript or TypeScript file.
703
+ *
704
+ * Matches .js, .jsx, .ts, .tsx, .mjs, .mts, .cjs, .cts extensions.
705
+ * @param filePath - The file path to check
706
+ * @returns True if the file is JavaScript or TypeScript
707
+ * @example
708
+ * ```typescript
709
+ * if (isJsTsFile(filePath)) {
710
+ * // Check for TypeScript-specific patterns
711
+ * }
712
+ * ```
713
+ */
714
+ export declare function isJsTsFile(filePath: string): boolean;
715
+ /**
716
+ * Checks if a file path is a TypeScript file.
717
+ *
718
+ * Matches .ts, .tsx, .mts, .cts extensions.
719
+ * @param filePath - The file path to check
720
+ * @returns True if the file is TypeScript
721
+ * @example
722
+ * ```typescript
723
+ * if (isTsFile(filePath)) {
724
+ * // Enforce TypeScript-specific rules
725
+ * }
726
+ * ```
727
+ */
728
+ export declare function isTsFile(filePath: string): boolean;
729
+ /**
730
+ * Result of checking content for a pattern.
731
+ */
732
+ export interface PatternCheckResult {
733
+ /** True if the pattern was found in any content. */
734
+ found: boolean;
735
+ /** True if the pattern is being added (not present in old content, present in new). */
736
+ isAddition: boolean;
737
+ /** All matches found across all content (deduplicated). */
738
+ matches: string[];
739
+ /** Per-edit details for MultiEdit operations. */
740
+ details?: Array<{
741
+ /** Index of the edit (for MultiEdit) or 0 for Write/Edit. */
742
+ index: number;
743
+ /** True if found in this edit. */
744
+ found: boolean;
745
+ /** True if this edit adds the pattern. */
746
+ isAddition: boolean;
747
+ /** Matches in this edit. */
748
+ matches: string[];
749
+ }>;
750
+ }
751
+ /**
752
+ * Checks if a pattern exists in the content being written or edited.
753
+ *
754
+ * For Write: checks the content being written
755
+ * For Edit: checks new_string (and old_string to detect additions)
756
+ * For MultiEdit: checks all edits and aggregates results
757
+ * @param input - The PreToolUse hook input
758
+ * @param pattern - The regex pattern to search for (global flag will be used)
759
+ * @returns Result object, or null if not a file-modifying tool
760
+ * @example
761
+ * ```typescript
762
+ * // Block @ts-expect-error being added
763
+ * const result = checkContentForPattern(input, /@ts-expect-error/g);
764
+ * if (result?.isAddition) {
765
+ * return preToolUseOutput({
766
+ * hookSpecificOutput: {
767
+ * permissionDecision: 'deny',
768
+ * permissionDecisionReason: `Cannot add: ${result.matches.join(', ')}`
769
+ * }
770
+ * });
771
+ * }
772
+ * ```
773
+ */
774
+ export declare function checkContentForPattern(input: SDKPreToolUseHookInput, pattern: RegExp): PatternCheckResult | null;
775
+ /**
776
+ * Context passed to the forEachContent callback.
777
+ */
778
+ export interface ContentContext {
779
+ /** The new content being written or replacing old content. */
780
+ newContent: string;
781
+ /** The old content being replaced (null for Write). */
782
+ oldContent: string | null;
783
+ /** Index of the edit (0 for Write/Edit, index for MultiEdit). */
784
+ index: number;
785
+ /** True if this is a Write operation (not Edit/MultiEdit). */
786
+ isWrite: boolean;
787
+ }
788
+ /**
789
+ * Iterates over content in Write/Edit/MultiEdit operations.
790
+ *
791
+ * Provides a unified way to inspect content regardless of operation type.
792
+ * Return false from the callback to stop iteration early.
793
+ * @param input - The PreToolUse hook input
794
+ * @param callback - Function called for each content piece, return false to stop
795
+ * @returns True if all callbacks returned true, false if stopped early or not applicable
796
+ * @example
797
+ * ```typescript
798
+ * // Check all content for sensitive data
799
+ * const hasSensitive = !forEachContent(input, ({ newContent }) => {
800
+ * if (/password|secret|api.?key/i.test(newContent)) {
801
+ * return false; // Stop - found sensitive data
802
+ * }
803
+ * return true; // Continue
804
+ * });
805
+ * ```
806
+ */
807
+ export declare function forEachContent(input: SDKPreToolUseHookInput, callback: (ctx: ContentContext) => boolean): boolean;