@goodfoot/claude-code-hooks 1.0.10 → 1.0.15

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/types/cli.d.ts CHANGED
@@ -14,79 +14,79 @@
14
14
  * ```
15
15
  * @module
16
16
  */
17
- import type { HookEventName } from './inputs.js';
18
- import { HOOK_FACTORY_TO_EVENT } from './constants.js';
17
+ import { HOOK_FACTORY_TO_EVENT } from "./constants.js";
18
+ import type { HookEventName } from "./types.js";
19
19
  /**
20
20
  * Hook context determines how paths are resolved in hooks.json.
21
21
  *
22
22
  * - `plugin`: Uses `$CLAUDE_PLUGIN_ROOT` for plugin hooks
23
23
  * - `agent`: Uses `"$CLAUDE_PROJECT_DIR"` for agent hooks (.claude/hooks/)
24
24
  */
25
- type HookContext = 'plugin' | 'agent';
25
+ type HookContext = "plugin" | "agent";
26
26
  /**
27
27
  * Command-line arguments parsed from process.argv.
28
28
  */
29
29
  interface CliArgs {
30
- /** Glob pattern for hook source files. */
31
- input: string;
32
- /** Path for hooks.json output file. */
33
- output: string;
34
- /** Optional log file path. */
35
- log?: string;
36
- /** Show help. */
37
- help: boolean;
38
- /** Show version. */
39
- version: boolean;
40
- /** Directory path for scaffolding a new hook project. */
41
- scaffold?: string;
42
- /** Comma-separated list of hook types to generate when scaffolding. */
43
- hooks?: string;
44
- /** Node executable path to use in command output (default: "node"). */
45
- executable?: string;
30
+ /** Glob pattern for hook source files. */
31
+ input: string;
32
+ /** Path for hooks.json output file. */
33
+ output: string;
34
+ /** Optional log file path. */
35
+ log?: string;
36
+ /** Show help. */
37
+ help: boolean;
38
+ /** Show version. */
39
+ version: boolean;
40
+ /** Directory path for scaffolding a new hook project. */
41
+ scaffold?: string;
42
+ /** Comma-separated list of hook types to generate when scaffolding. */
43
+ hooks?: string;
44
+ /** Node executable path to use in command output (default: "node"). */
45
+ executable?: string;
46
46
  }
47
47
  /**
48
48
  * Metadata extracted from a hook file via TypeScript AST analysis.
49
49
  */
50
50
  interface HookMetadata {
51
- /** The hook event type (PreToolUse, SessionStart, etc.). */
52
- hookEventName: HookEventName;
53
- /** Optional matcher pattern from hook config. */
54
- matcher?: string;
55
- /** Optional timeout in milliseconds from hook config. */
56
- timeout?: number;
51
+ /** The hook event type (PreToolUse, SessionStart, etc.). */
52
+ hookEventName: HookEventName;
53
+ /** Optional matcher pattern from hook config. */
54
+ matcher?: string;
55
+ /** Optional timeout in milliseconds from hook config. */
56
+ timeout?: number;
57
57
  }
58
58
  /**
59
59
  * A compiled hook with its metadata and output path.
60
60
  */
61
61
  interface CompiledHook {
62
- /** Original source file path. */
63
- sourcePath: string;
64
- /** Compiled output file path. */
65
- outputPath: string;
66
- /** Output filename (e.g., "my-hook.abc123de.mjs"). */
67
- outputFilename: string;
68
- /** Extracted hook metadata. */
69
- metadata: HookMetadata;
62
+ /** Original source file path. */
63
+ sourcePath: string;
64
+ /** Compiled output file path. */
65
+ outputPath: string;
66
+ /** Output filename (e.g., "my-hook.abc123de.mjs"). */
67
+ outputFilename: string;
68
+ /** Extracted hook metadata. */
69
+ metadata: HookMetadata;
70
70
  }
71
71
  /**
72
72
  * Individual hook configuration within a matcher group.
73
73
  */
74
74
  interface HookConfig {
75
- /** Hook type - always "command" for compiled hooks. */
76
- type: 'command';
77
- /** Absolute path to compiled hook executable. */
78
- command: string;
79
- /** Optional timeout in seconds. */
80
- timeout?: number;
75
+ /** Hook type - always "command" for compiled hooks. */
76
+ type: "command";
77
+ /** Absolute path to compiled hook executable. */
78
+ command: string;
79
+ /** Optional timeout in seconds. */
80
+ timeout?: number;
81
81
  }
82
82
  /**
83
83
  * Matcher group entry within an event type.
84
84
  */
85
85
  interface MatcherEntry {
86
- /** Matcher pattern (tool name, regex, etc.). Optional for some event types. */
87
- matcher?: string;
88
- /** Array of hook configurations in this matcher group. */
89
- hooks: HookConfig[];
86
+ /** Matcher pattern (tool name, regex, etc.). Optional for some event types. */
87
+ matcher?: string;
88
+ /** Array of hook configurations in this matcher group. */
89
+ hooks: HookConfig[];
90
90
  }
91
91
  /**
92
92
  * The complete hooks.json structure expected by Claude Code.
@@ -94,15 +94,15 @@ interface MatcherEntry {
94
94
  * Format: { hooks: { EventType: [ { matcher?, hooks: [...] } ] } }
95
95
  */
96
96
  interface HooksJson {
97
- /** Object keyed by event type (PreToolUse, SessionStart, etc.). */
98
- hooks: Partial<Record<HookEventName, MatcherEntry[]>>;
99
- /** Generated file tracking metadata. */
100
- __generated: {
101
- /** Array of generated filenames. */
102
- files: string[];
103
- /** ISO timestamp of generation. */
104
- timestamp: string;
105
- };
97
+ /** Object keyed by event type (PreToolUse, SessionStart, etc.). */
98
+ hooks: Partial<Record<HookEventName, MatcherEntry[]>>;
99
+ /** Generated file tracking metadata. */
100
+ __generated: {
101
+ /** Array of generated filenames. */
102
+ files: string[];
103
+ /** ISO timestamp of generation. */
104
+ timestamp: string;
105
+ };
106
106
  }
107
107
  /**
108
108
  * Parses command-line arguments.
@@ -144,12 +144,12 @@ declare function discoverHookFiles(pattern: string, cwd: string): Promise<string
144
144
  * Options for compiling a hook.
145
145
  */
146
146
  interface CompileHookOptions {
147
- /** Absolute path to source file. */
148
- sourcePath: string;
149
- /** Directory for compiled output. */
150
- outputDir: string;
151
- /** Optional log file path to inject into compiled hook. */
152
- logFilePath?: string;
147
+ /** Absolute path to source file. */
148
+ sourcePath: string;
149
+ /** Directory for compiled output. */
150
+ outputDir: string;
151
+ /** Optional log file path to inject into compiled hook. */
152
+ logFilePath?: string;
153
153
  }
154
154
  /**
155
155
  * Compiles a TypeScript hook file to a self-contained ESM executable.
@@ -171,17 +171,15 @@ declare function generateContentHash(content: string): string;
171
171
  * @param compiledHooks - Array of compiled hooks
172
172
  * @returns Nested map: EventType -> Matcher -> Hooks
173
173
  */
174
- declare function groupHooksByEventAndMatcher(
175
- compiledHooks: CompiledHook[]
176
- ): Map<HookEventName, Map<string | undefined, CompiledHook[]>>;
174
+ declare function groupHooksByEventAndMatcher(compiledHooks: CompiledHook[]): Map<HookEventName, Map<string | undefined, CompiledHook[]>>;
177
175
  /**
178
176
  * Result of detecting the hook context, including the root directory.
179
177
  */
180
178
  interface HookContextInfo {
181
- /** Hook context type. */
182
- context: HookContext;
183
- /** Absolute path to the root directory (plugin root or project root). */
184
- rootDir: string;
179
+ /** Hook context type. */
180
+ context: HookContext;
181
+ /** Absolute path to the root directory (plugin root or project root). */
182
+ rootDir: string;
185
183
  }
186
184
  /**
187
185
  * Auto-detects the hook context and root directory based on directory structure.
@@ -208,12 +206,7 @@ declare function detectHookContext(outputPath: string): HookContextInfo;
208
206
  * @param executable - Node executable path (default: "node")
209
207
  * @returns The command path string
210
208
  */
211
- declare function generateCommandPath(
212
- filename: string,
213
- buildDir: string,
214
- contextInfo: HookContextInfo,
215
- executable?: string
216
- ): string;
209
+ declare function generateCommandPath(filename: string, buildDir: string, contextInfo: HookContextInfo, executable?: string): string;
217
210
  /**
218
211
  * Generates the hooks.json content in Claude Code's expected format.
219
212
  *
@@ -224,12 +217,7 @@ declare function generateCommandPath(
224
217
  * @param executable - Node executable path (default: "node")
225
218
  * @returns The hooks.json structure
226
219
  */
227
- declare function generateHooksJson(
228
- compiledHooks: CompiledHook[],
229
- buildDir: string,
230
- contextInfo: HookContextInfo,
231
- executable?: string
232
- ): HooksJson;
220
+ declare function generateHooksJson(compiledHooks: CompiledHook[], buildDir: string, contextInfo: HookContextInfo, executable?: string): HooksJson;
233
221
  /**
234
222
  * Reads an existing hooks.json file if it exists.
235
223
  * @param outputPath - Path to the hooks.json file
@@ -257,25 +245,6 @@ declare function extractPreservedHooks(existingHooksJson: HooksJson): Partial<Re
257
245
  * @param preservedHooks - Hooks to preserve from the existing hooks.json
258
246
  * @returns Merged HooksJson
259
247
  */
260
- declare function mergeHooksJson(
261
- newHooksJson: HooksJson,
262
- preservedHooks: Partial<Record<HookEventName, MatcherEntry[]>>
263
- ): HooksJson;
264
- export {
265
- parseArgs,
266
- validateArgs,
267
- analyzeHookFile,
268
- discoverHookFiles,
269
- compileHook,
270
- generateContentHash,
271
- detectHookContext,
272
- generateCommandPath,
273
- generateHooksJson,
274
- groupHooksByEventAndMatcher,
275
- readExistingHooksJson,
276
- removeOldGeneratedFiles,
277
- extractPreservedHooks,
278
- mergeHooksJson,
279
- HOOK_FACTORY_TO_EVENT
280
- };
248
+ declare function mergeHooksJson(newHooksJson: HooksJson, preservedHooks: Partial<Record<HookEventName, MatcherEntry[]>>): HooksJson;
249
+ export { parseArgs, validateArgs, analyzeHookFile, discoverHookFiles, compileHook, generateContentHash, detectHookContext, generateCommandPath, generateHooksJson, groupHooksByEventAndMatcher, readExistingHooksJson, removeOldGeneratedFiles, extractPreservedHooks, mergeHooksJson, HOOK_FACTORY_TO_EVENT, };
281
250
  export type { CliArgs, HookMetadata, CompiledHook, HookConfig, MatcherEntry, HooksJson };
@@ -2,7 +2,7 @@
2
2
  * Shared constants for the CLI and scaffold modules.
3
3
  * @module
4
4
  */
5
- import type { HookEventName } from './inputs.js';
5
+ import type { HookEventName } from "./types.js";
6
6
  /**
7
7
  * Maps hook factory function names to their event names.
8
8
  */
package/types/env.d.ts CHANGED
@@ -38,22 +38,22 @@
38
38
  * These are the environment variables that Claude Code sets when running hooks.
39
39
  */
40
40
  export declare const CLAUDE_ENV_VARS: {
41
- /**
42
- * Absolute path to the project root directory where Claude Code was started.
43
- * Available in all hooks.
44
- */
45
- readonly PROJECT_DIR: 'CLAUDE_PROJECT_DIR';
46
- /**
47
- * Path to a file where SessionStart hooks can persist environment variables.
48
- * Variables written to this file will be available in all subsequent bash commands.
49
- * Only available in SessionStart hooks.
50
- */
51
- readonly ENV_FILE: 'CLAUDE_ENV_FILE';
52
- /**
53
- * Set to "true" when running in a remote (web) environment.
54
- * Not set or empty when running in local CLI environment.
55
- */
56
- readonly REMOTE: 'CLAUDE_CODE_REMOTE';
41
+ /**
42
+ * Absolute path to the project root directory where Claude Code was started.
43
+ * Available in all hooks.
44
+ */
45
+ readonly PROJECT_DIR: "CLAUDE_PROJECT_DIR";
46
+ /**
47
+ * Path to a file where SessionStart hooks can persist environment variables.
48
+ * Variables written to this file will be available in all subsequent bash commands.
49
+ * Only available in SessionStart hooks.
50
+ */
51
+ readonly ENV_FILE: "CLAUDE_ENV_FILE";
52
+ /**
53
+ * Set to "true" when running in a remote (web) environment.
54
+ * Not set or empty when running in local CLI environment.
55
+ */
56
+ readonly REMOTE: "CLAUDE_CODE_REMOTE";
57
57
  };
58
58
  /**
59
59
  * Gets the Claude Code project directory.