@hasna/hooks 0.0.1

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 (110) hide show
  1. package/.npmrc.example +2 -0
  2. package/AGENTS.md +54 -0
  3. package/CLAUDE.md +70 -0
  4. package/CONTRIBUTING.md +45 -0
  5. package/README.md +232 -0
  6. package/bin/index.js +5171 -0
  7. package/hooks/hook-agentmessages/CLAUDE.md +79 -0
  8. package/hooks/hook-agentmessages/LICENSE +21 -0
  9. package/hooks/hook-agentmessages/README.md +107 -0
  10. package/hooks/hook-agentmessages/package.json +31 -0
  11. package/hooks/hook-agentmessages/src/check-messages.ts +151 -0
  12. package/hooks/hook-agentmessages/src/install.ts +126 -0
  13. package/hooks/hook-agentmessages/src/session-start.ts +255 -0
  14. package/hooks/hook-agentmessages/src/uninstall.ts +89 -0
  15. package/hooks/hook-branchprotect/CLAUDE.md +23 -0
  16. package/hooks/hook-branchprotect/README.md +25 -0
  17. package/hooks/hook-branchprotect/package.json +42 -0
  18. package/hooks/hook-branchprotect/src/cli.ts +126 -0
  19. package/hooks/hook-branchprotect/src/hook.ts +88 -0
  20. package/hooks/hook-branchprotect/tsconfig.json +25 -0
  21. package/hooks/hook-checkbugs/LICENSE +21 -0
  22. package/hooks/hook-checkbugs/README.md +140 -0
  23. package/hooks/hook-checkbugs/package.json +58 -0
  24. package/hooks/hook-checkbugs/src/cli.ts +628 -0
  25. package/hooks/hook-checkbugs/src/hook.ts +335 -0
  26. package/hooks/hook-checkbugs/tsconfig.json +15 -0
  27. package/hooks/hook-checkdocs/README.md +137 -0
  28. package/hooks/hook-checkdocs/package.json +57 -0
  29. package/hooks/hook-checkdocs/src/cli.ts +628 -0
  30. package/hooks/hook-checkdocs/src/hook.ts +310 -0
  31. package/hooks/hook-checkdocs/tsconfig.json +15 -0
  32. package/hooks/hook-checkfiles/LICENSE +21 -0
  33. package/hooks/hook-checkfiles/README.md +141 -0
  34. package/hooks/hook-checkfiles/package.json +56 -0
  35. package/hooks/hook-checkfiles/src/cli.ts +545 -0
  36. package/hooks/hook-checkfiles/src/hook.ts +321 -0
  37. package/hooks/hook-checkfiles/tsconfig.json +15 -0
  38. package/hooks/hook-checklint/LICENSE +21 -0
  39. package/hooks/hook-checklint/README.md +147 -0
  40. package/hooks/hook-checklint/package.json +57 -0
  41. package/hooks/hook-checklint/src/cli-patch.ts +32 -0
  42. package/hooks/hook-checklint/src/cli.ts +667 -0
  43. package/hooks/hook-checklint/src/hook.ts +473 -0
  44. package/hooks/hook-checklint/tsconfig.json +15 -0
  45. package/hooks/hook-checkpoint/CLAUDE.md +23 -0
  46. package/hooks/hook-checkpoint/README.md +37 -0
  47. package/hooks/hook-checkpoint/package.json +58 -0
  48. package/hooks/hook-checkpoint/src/cli.ts +191 -0
  49. package/hooks/hook-checkpoint/src/hook.ts +207 -0
  50. package/hooks/hook-checkpoint/tsconfig.json +25 -0
  51. package/hooks/hook-checksecurity/LICENSE +21 -0
  52. package/hooks/hook-checksecurity/README.md +158 -0
  53. package/hooks/hook-checksecurity/package.json +57 -0
  54. package/hooks/hook-checksecurity/src/cli.ts +601 -0
  55. package/hooks/hook-checksecurity/src/hook.ts +334 -0
  56. package/hooks/hook-checksecurity/tsconfig.json +15 -0
  57. package/hooks/hook-checktasks/README.md +144 -0
  58. package/hooks/hook-checktasks/package.json +55 -0
  59. package/hooks/hook-checktasks/src/cli.ts +578 -0
  60. package/hooks/hook-checktasks/src/hook.ts +308 -0
  61. package/hooks/hook-checktasks/tsconfig.json +20 -0
  62. package/hooks/hook-checktests/LICENSE +21 -0
  63. package/hooks/hook-checktests/README.md +137 -0
  64. package/hooks/hook-checktests/package.json +57 -0
  65. package/hooks/hook-checktests/src/cli.ts +627 -0
  66. package/hooks/hook-checktests/src/hook.ts +334 -0
  67. package/hooks/hook-checktests/tsconfig.json +15 -0
  68. package/hooks/hook-contextrefresh/CLAUDE.md +23 -0
  69. package/hooks/hook-contextrefresh/README.md +42 -0
  70. package/hooks/hook-contextrefresh/package.json +42 -0
  71. package/hooks/hook-contextrefresh/src/cli.ts +152 -0
  72. package/hooks/hook-contextrefresh/src/hook.ts +148 -0
  73. package/hooks/hook-contextrefresh/tsconfig.json +25 -0
  74. package/hooks/hook-gitguard/CLAUDE.md +22 -0
  75. package/hooks/hook-gitguard/README.md +30 -0
  76. package/hooks/hook-gitguard/package.json +57 -0
  77. package/hooks/hook-gitguard/src/cli.ts +159 -0
  78. package/hooks/hook-gitguard/src/hook.ts +129 -0
  79. package/hooks/hook-gitguard/tsconfig.json +25 -0
  80. package/hooks/hook-packageage/CLAUDE.md +23 -0
  81. package/hooks/hook-packageage/README.md +33 -0
  82. package/hooks/hook-packageage/package.json +42 -0
  83. package/hooks/hook-packageage/src/cli.ts +165 -0
  84. package/hooks/hook-packageage/src/hook.ts +177 -0
  85. package/hooks/hook-packageage/tsconfig.json +25 -0
  86. package/hooks/hook-phonenotify/CLAUDE.md +25 -0
  87. package/hooks/hook-phonenotify/README.md +44 -0
  88. package/hooks/hook-phonenotify/package.json +42 -0
  89. package/hooks/hook-phonenotify/src/cli.ts +196 -0
  90. package/hooks/hook-phonenotify/src/hook.ts +139 -0
  91. package/hooks/hook-phonenotify/tsconfig.json +25 -0
  92. package/hooks/hook-precompact/CLAUDE.md +23 -0
  93. package/hooks/hook-precompact/README.md +36 -0
  94. package/hooks/hook-precompact/package.json +42 -0
  95. package/hooks/hook-precompact/src/cli.ts +168 -0
  96. package/hooks/hook-precompact/src/hook.ts +122 -0
  97. package/hooks/hook-precompact/tsconfig.json +25 -0
  98. package/package.json +61 -0
  99. package/src/cli/components/App.tsx +191 -0
  100. package/src/cli/components/CategorySelect.tsx +37 -0
  101. package/src/cli/components/DataTable.tsx +133 -0
  102. package/src/cli/components/Header.tsx +18 -0
  103. package/src/cli/components/HookSelect.tsx +29 -0
  104. package/src/cli/components/InstallProgress.tsx +105 -0
  105. package/src/cli/components/SearchView.tsx +86 -0
  106. package/src/cli/index.tsx +218 -0
  107. package/src/index.ts +31 -0
  108. package/src/lib/installer.ts +288 -0
  109. package/src/lib/registry.ts +205 -0
  110. package/tsconfig.json +17 -0
@@ -0,0 +1,545 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * @hasnaxyz/hook-checkfiles CLI
5
+ *
6
+ * Usage:
7
+ * hook-checkfiles install Auto-detect location, configure options
8
+ * hook-checkfiles install --global Force global install
9
+ * hook-checkfiles install /path Install to specific path
10
+ * hook-checkfiles config Update configuration
11
+ * hook-checkfiles uninstall Remove hook
12
+ * hook-checkfiles run Execute hook (called by Claude Code)
13
+ * hook-checkfiles status Show installation status
14
+ */
15
+
16
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "fs";
17
+ import { join, dirname, resolve } from "path";
18
+ import { homedir } from "os";
19
+ import * as readline from "readline";
20
+
21
+ const PACKAGE_NAME = "@hasnaxyz/hook-checkfiles";
22
+ const CONFIG_KEY = "checkFilesConfig";
23
+
24
+ // Colors
25
+ const c = {
26
+ red: (s: string) => `\x1b[31m${s}\x1b[0m`,
27
+ green: (s: string) => `\x1b[32m${s}\x1b[0m`,
28
+ yellow: (s: string) => `\x1b[33m${s}\x1b[0m`,
29
+ cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
30
+ dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
31
+ bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
32
+ };
33
+
34
+ interface CheckFilesConfig {
35
+ taskListId?: string;
36
+ editThreshold?: number;
37
+ keywords?: string[];
38
+ reviewPrompt?: string;
39
+ enabled?: boolean;
40
+ }
41
+
42
+ function printUsage() {
43
+ console.log(`
44
+ ${c.bold("hook-checkfiles")} - Runs headless Claude agent to review files and create tasks
45
+
46
+ ${c.bold("USAGE:")}
47
+ hook-checkfiles install [path] Install the hook
48
+ hook-checkfiles config [path] Update configuration
49
+ hook-checkfiles uninstall [path] Remove the hook
50
+ hook-checkfiles status Show hook status
51
+ hook-checkfiles run Execute hook ${c.dim("(called by Claude Code)")}
52
+
53
+ ${c.bold("OPTIONS:")}
54
+ ${c.dim("(no args)")} Auto-detect: if in git repo -> install there, else -> prompt
55
+ --global, -g Apply to ~/.claude/settings.json
56
+ /path/to/repo Apply to specific project path
57
+
58
+ ${c.bold("EXAMPLES:")}
59
+ hook-checkfiles install ${c.dim("# Install with config prompts")}
60
+ hook-checkfiles install --global ${c.dim("# Global install")}
61
+ hook-checkfiles config ${c.dim("# Update threshold, task list")}
62
+ hook-checkfiles status ${c.dim("# Check what's installed")}
63
+
64
+ ${c.bold("CONFIGURATION:")}
65
+ editThreshold Run review after this many edits (3-7, default: 3)
66
+ taskListId Task list for dispatching tasks (auto-detected if not set)
67
+ keywords Only run for sessions matching keywords (default: dev)
68
+ reviewPrompt Custom prompt for the headless agent
69
+
70
+ ${c.bold("HOW IT WORKS:")}
71
+ 1. Tracks file edits (Edit, Write, NotebookEdit)
72
+ 2. After N edits, spawns headless Claude agent
73
+ 3. Agent reviews files and creates tasks via service-implementation
74
+ 4. Tasks are dispatched to the configured task list
75
+
76
+ ${c.bold("GLOBAL CLI INSTALL:")}
77
+ bun add -g ${PACKAGE_NAME}
78
+ `);
79
+ }
80
+
81
+ function isGitRepo(path: string): boolean {
82
+ return existsSync(join(path, ".git"));
83
+ }
84
+
85
+ function getSettingsPath(targetPath: string | "global"): string {
86
+ if (targetPath === "global") {
87
+ return join(homedir(), ".claude", "settings.json");
88
+ }
89
+ return join(targetPath, ".claude", "settings.json");
90
+ }
91
+
92
+ function readSettings(path: string): Record<string, unknown> {
93
+ if (!existsSync(path)) return {};
94
+ try {
95
+ return JSON.parse(readFileSync(path, "utf-8"));
96
+ } catch {
97
+ return {};
98
+ }
99
+ }
100
+
101
+ function writeSettings(path: string, settings: Record<string, unknown>) {
102
+ mkdirSync(dirname(path), { recursive: true });
103
+ writeFileSync(path, JSON.stringify(settings, null, 2) + "\n");
104
+ }
105
+
106
+ function getHookCommand(): string {
107
+ return `bunx ${PACKAGE_NAME}@latest run`;
108
+ }
109
+
110
+ function hookExists(settings: Record<string, unknown>): boolean {
111
+ const hooks = settings.hooks as Record<string, unknown[]> | undefined;
112
+ if (!hooks?.PostToolUse) return false;
113
+ const postToolHooks = hooks.PostToolUse as Array<{ hooks?: Array<{ command?: string }> }>;
114
+ return postToolHooks.some((group) =>
115
+ group.hooks?.some((h) => h.command?.includes(PACKAGE_NAME))
116
+ );
117
+ }
118
+
119
+ function getConfig(settings: Record<string, unknown>): CheckFilesConfig {
120
+ return (settings[CONFIG_KEY] as CheckFilesConfig) || {};
121
+ }
122
+
123
+ function setConfig(settings: Record<string, unknown>, config: CheckFilesConfig): Record<string, unknown> {
124
+ settings[CONFIG_KEY] = config;
125
+ return settings;
126
+ }
127
+
128
+ function addHook(settings: Record<string, unknown>): Record<string, unknown> {
129
+ const hookConfig = {
130
+ type: "command",
131
+ command: getHookCommand(),
132
+ timeout: 120,
133
+ async: true, // Run async (non-blocking)
134
+ };
135
+
136
+ // Match only Edit, Write, NotebookEdit tools
137
+ const matcher = {
138
+ tool_name: "^(Edit|Write|NotebookEdit)$",
139
+ };
140
+
141
+ if (!settings.hooks) settings.hooks = {};
142
+ const hooks = settings.hooks as Record<string, unknown[]>;
143
+
144
+ if (!hooks.PostToolUse) {
145
+ hooks.PostToolUse = [{ matcher, hooks: [hookConfig] }];
146
+ } else {
147
+ const postToolHooks = hooks.PostToolUse as Array<{ matcher?: unknown; hooks?: unknown[] }>;
148
+ // Check if there's already a group for our matcher
149
+ const existingGroup = postToolHooks.find((g) =>
150
+ JSON.stringify(g.matcher) === JSON.stringify(matcher)
151
+ );
152
+ if (existingGroup?.hooks) {
153
+ existingGroup.hooks.push(hookConfig);
154
+ } else {
155
+ postToolHooks.push({ matcher, hooks: [hookConfig] });
156
+ }
157
+ }
158
+ return settings;
159
+ }
160
+
161
+ function removeHook(settings: Record<string, unknown>): Record<string, unknown> {
162
+ const hooks = settings.hooks as Record<string, unknown[]> | undefined;
163
+ if (!hooks?.PostToolUse) return settings;
164
+
165
+ const postToolHooks = hooks.PostToolUse as Array<{ hooks?: Array<{ command?: string }> }>;
166
+ for (const group of postToolHooks) {
167
+ if (group.hooks) {
168
+ group.hooks = group.hooks.filter((h) => !h.command?.includes(PACKAGE_NAME));
169
+ }
170
+ }
171
+ hooks.PostToolUse = postToolHooks.filter((g) => g.hooks && g.hooks.length > 0);
172
+ if (hooks.PostToolUse.length === 0) delete hooks.PostToolUse;
173
+
174
+ // Also remove config
175
+ delete settings[CONFIG_KEY];
176
+
177
+ return settings;
178
+ }
179
+
180
+ async function prompt(question: string): Promise<string> {
181
+ const rl = readline.createInterface({
182
+ input: process.stdin,
183
+ output: process.stdout,
184
+ });
185
+ return new Promise((resolve) => {
186
+ rl.question(question, (answer) => {
187
+ rl.close();
188
+ resolve(answer.trim());
189
+ });
190
+ });
191
+ }
192
+
193
+ function getAllTaskLists(): string[] {
194
+ const tasksDir = join(homedir(), ".claude", "tasks");
195
+ if (!existsSync(tasksDir)) return [];
196
+ try {
197
+ return readdirSync(tasksDir, { withFileTypes: true })
198
+ .filter((d) => d.isDirectory())
199
+ .map((d) => d.name);
200
+ } catch {
201
+ return [];
202
+ }
203
+ }
204
+
205
+ function getProjectTaskLists(projectPath: string): string[] {
206
+ const allLists = getAllTaskLists();
207
+ const dirName = projectPath.split("/").filter(Boolean).pop() || "";
208
+
209
+ return allLists.filter((list) => {
210
+ const listLower = list.toLowerCase();
211
+ const dirLower = dirName.toLowerCase();
212
+ if (listLower.startsWith(dirLower + "-")) return true;
213
+ if (listLower.includes(dirLower)) return true;
214
+ return false;
215
+ });
216
+ }
217
+
218
+ async function resolveTarget(
219
+ args: string[]
220
+ ): Promise<{ path: string | "global"; label: string } | null> {
221
+ if (args.includes("--global") || args.includes("-g")) {
222
+ return { path: "global", label: "global (~/.claude/settings.json)" };
223
+ }
224
+
225
+ const pathArg = args.find((a) => !a.startsWith("-"));
226
+ if (pathArg) {
227
+ const fullPath = resolve(pathArg);
228
+ if (!existsSync(fullPath)) {
229
+ console.log(c.red("X"), `Path does not exist: ${fullPath}`);
230
+ return null;
231
+ }
232
+ return { path: fullPath, label: `project (${fullPath})` };
233
+ }
234
+
235
+ const cwd = process.cwd();
236
+ if (isGitRepo(cwd)) {
237
+ console.log(c.green("V"), `Detected git repo: ${c.cyan(cwd)}`);
238
+ return { path: cwd, label: `project (${cwd})` };
239
+ }
240
+
241
+ console.log(c.yellow("!"), `Current directory: ${c.cyan(cwd)}`);
242
+ console.log(c.dim(" (not a git repository)\n"));
243
+ console.log("Where would you like to install?\n");
244
+ console.log(" 1. Here", c.dim(`(${cwd})`));
245
+ console.log(" 2. Global", c.dim("(~/.claude/settings.json)"));
246
+ console.log(" 3. Enter a different path\n");
247
+
248
+ const choice = await prompt("Choice (1/2/3): ");
249
+
250
+ if (choice === "1") {
251
+ return { path: cwd, label: `project (${cwd})` };
252
+ } else if (choice === "2") {
253
+ return { path: "global", label: "global (~/.claude/settings.json)" };
254
+ } else if (choice === "3") {
255
+ const inputPath = await prompt("Path: ");
256
+ if (!inputPath) {
257
+ console.log(c.red("X"), "No path provided");
258
+ return null;
259
+ }
260
+ const fullPath = resolve(inputPath);
261
+ if (!existsSync(fullPath)) {
262
+ console.log(c.red("X"), `Path does not exist: ${fullPath}`);
263
+ return null;
264
+ }
265
+ return { path: fullPath, label: `project (${fullPath})` };
266
+ } else {
267
+ console.log(c.red("X"), "Invalid choice");
268
+ return null;
269
+ }
270
+ }
271
+
272
+ async function promptForConfig(existingConfig: CheckFilesConfig = {}, projectPath?: string): Promise<CheckFilesConfig> {
273
+ const config: CheckFilesConfig = { ...existingConfig };
274
+
275
+ console.log(`\n${c.bold("Configuration")}\n`);
276
+
277
+ // Edit threshold
278
+ const currentThreshold = config.editThreshold || 3;
279
+ console.log(c.bold("Edit Threshold:"));
280
+ console.log(c.dim(" Run review after this many file edits (3-7)"));
281
+ const thresholdInput = await prompt(`Threshold [${c.cyan(currentThreshold.toString())}]: `);
282
+
283
+ if (thresholdInput) {
284
+ const num = parseInt(thresholdInput, 10);
285
+ if (!isNaN(num) && num >= 3 && num <= 7) {
286
+ config.editThreshold = num;
287
+ } else {
288
+ console.log(c.yellow("!"), "Invalid threshold, using default (3)");
289
+ config.editThreshold = 3;
290
+ }
291
+ } else if (!existingConfig.editThreshold) {
292
+ config.editThreshold = 3;
293
+ }
294
+
295
+ // Task list
296
+ const availableLists = projectPath ? getProjectTaskLists(projectPath) : getAllTaskLists();
297
+ const bugfixLists = availableLists.filter((l) => l.toLowerCase().includes("bugfix"));
298
+
299
+ console.log();
300
+ console.log(c.bold("Task List ID:"));
301
+ if (bugfixLists.length > 0) {
302
+ console.log(c.dim(" Bugfix lists for this project:"));
303
+ bugfixLists.forEach((list, i) => {
304
+ console.log(c.dim(` ${i + 1}. ${list}`));
305
+ });
306
+ } else if (availableLists.length > 0) {
307
+ console.log(c.dim(" Available lists:"));
308
+ availableLists.slice(0, 5).forEach((list, i) => {
309
+ console.log(c.dim(` ${i + 1}. ${list}`));
310
+ });
311
+ }
312
+ console.log(c.dim(" Leave empty to auto-detect (prefers *-bugfixes list)"));
313
+
314
+ const currentList = config.taskListId || "(auto-detect)";
315
+ const listInput = await prompt(`Task list ID [${c.cyan(currentList)}]: `);
316
+
317
+ if (listInput) {
318
+ const num = parseInt(listInput, 10);
319
+ const selectableLists = bugfixLists.length > 0 ? bugfixLists : availableLists;
320
+ if (!isNaN(num) && num > 0 && num <= selectableLists.length) {
321
+ config.taskListId = selectableLists[num - 1];
322
+ } else {
323
+ config.taskListId = listInput;
324
+ }
325
+ } else if (!existingConfig.taskListId) {
326
+ config.taskListId = undefined;
327
+ }
328
+
329
+ // Keywords
330
+ const currentKeywords = config.keywords?.join(", ") || "dev";
331
+ console.log();
332
+ console.log(c.bold("Keywords:"));
333
+ console.log(c.dim(" Only run review for sessions matching these keywords"));
334
+ const keywordsInput = await prompt(`Keywords (comma-separated) [${c.cyan(currentKeywords)}]: `);
335
+
336
+ if (keywordsInput) {
337
+ config.keywords = keywordsInput.split(",").map((k) => k.trim().toLowerCase()).filter(Boolean);
338
+ } else if (!existingConfig.keywords) {
339
+ config.keywords = ["dev"];
340
+ }
341
+
342
+ config.enabled = true;
343
+
344
+ return config;
345
+ }
346
+
347
+ async function install(args: string[]) {
348
+ console.log(`\n${c.bold("hook-checkfiles install")}\n`);
349
+
350
+ const target = await resolveTarget(args);
351
+ if (!target) return;
352
+
353
+ const settingsPath = getSettingsPath(target.path);
354
+ let settings = readSettings(settingsPath);
355
+
356
+ if (hookExists(settings)) {
357
+ console.log(c.yellow("!"), `Hook already installed in ${target.label}`);
358
+ const update = await prompt("Update configuration? (y/n): ");
359
+ if (update.toLowerCase() !== "y") return;
360
+ } else {
361
+ settings = addHook(settings);
362
+ }
363
+
364
+ // Configure
365
+ const existingConfig = getConfig(settings);
366
+ const projectPath = target.path === "global" ? undefined : target.path;
367
+ const config = await promptForConfig(existingConfig, projectPath);
368
+ settings = setConfig(settings, config);
369
+
370
+ writeSettings(settingsPath, settings);
371
+
372
+ console.log();
373
+ console.log(c.green("V"), `Installed to ${target.label}`);
374
+ console.log();
375
+ console.log(c.bold("Configuration:"));
376
+ console.log(` Threshold: ${config.editThreshold || 3} edits`);
377
+ console.log(` Task list: ${config.taskListId || c.cyan("(auto-detect)")}`);
378
+ console.log(` Keywords: ${config.keywords?.join(", ") || "dev"}`);
379
+ console.log(` Async: ${c.green("yes")} (non-blocking)`);
380
+ console.log();
381
+ console.log(c.bold("Requires:"));
382
+ console.log(` - service-implementation CLI (for task dispatch)`);
383
+ console.log(` - claude CLI (for headless agent)`);
384
+ console.log();
385
+ }
386
+
387
+ async function configure(args: string[]) {
388
+ console.log(`\n${c.bold("hook-checkfiles config")}\n`);
389
+
390
+ const target = await resolveTarget(args);
391
+ if (!target) return;
392
+
393
+ const settingsPath = getSettingsPath(target.path);
394
+
395
+ if (!existsSync(settingsPath)) {
396
+ console.log(c.red("X"), `No settings file at ${settingsPath}`);
397
+ console.log(c.dim(" Run 'hook-checkfiles install' first"));
398
+ return;
399
+ }
400
+
401
+ let settings = readSettings(settingsPath);
402
+
403
+ if (!hookExists(settings)) {
404
+ console.log(c.red("X"), `Hook not installed in ${target.label}`);
405
+ console.log(c.dim(" Run 'hook-checkfiles install' first"));
406
+ return;
407
+ }
408
+
409
+ const existingConfig = getConfig(settings);
410
+ const projectPath = target.path === "global" ? undefined : target.path;
411
+ const config = await promptForConfig(existingConfig, projectPath);
412
+ settings = setConfig(settings, config);
413
+
414
+ writeSettings(settingsPath, settings);
415
+
416
+ console.log();
417
+ console.log(c.green("V"), `Configuration updated`);
418
+ console.log();
419
+ console.log(c.bold("New configuration:"));
420
+ console.log(` Threshold: ${config.editThreshold || 3} edits`);
421
+ console.log(` Task list: ${config.taskListId || c.cyan("(auto-detect)")}`);
422
+ console.log(` Keywords: ${config.keywords?.join(", ") || "dev"}`);
423
+ console.log();
424
+ }
425
+
426
+ async function uninstall(args: string[]) {
427
+ console.log(`\n${c.bold("hook-checkfiles uninstall")}\n`);
428
+
429
+ const target = await resolveTarget(args);
430
+ if (!target) return;
431
+
432
+ const settingsPath = getSettingsPath(target.path);
433
+
434
+ if (!existsSync(settingsPath)) {
435
+ console.log(c.yellow("!"), `No settings file at ${settingsPath}`);
436
+ return;
437
+ }
438
+
439
+ const settings = readSettings(settingsPath);
440
+
441
+ if (!hookExists(settings)) {
442
+ console.log(c.yellow("!"), `Hook not found in ${target.label}`);
443
+ return;
444
+ }
445
+
446
+ const updated = removeHook(settings);
447
+ writeSettings(settingsPath, updated);
448
+
449
+ console.log(c.green("V"), `Removed from ${target.label}`);
450
+ }
451
+
452
+ function status() {
453
+ console.log(`\n${c.bold("hook-checkfiles status")}\n`);
454
+
455
+ // Global
456
+ const globalPath = getSettingsPath("global");
457
+ const globalSettings = readSettings(globalPath);
458
+ const globalInstalled = hookExists(globalSettings);
459
+ const globalConfig = getConfig(globalSettings);
460
+
461
+ console.log(
462
+ globalInstalled ? c.green("V") : c.red("X"),
463
+ "Global:",
464
+ globalInstalled ? "Installed" : "Not installed",
465
+ c.dim(`(${globalPath})`)
466
+ );
467
+ if (globalInstalled) {
468
+ console.log(c.dim(` Threshold: ${globalConfig.editThreshold || 3}, List: ${globalConfig.taskListId || "(auto)"}`));
469
+ }
470
+
471
+ // Current directory
472
+ const cwd = process.cwd();
473
+ const projectPath = getSettingsPath(cwd);
474
+ if (existsSync(projectPath)) {
475
+ const projectSettings = readSettings(projectPath);
476
+ const projectInstalled = hookExists(projectSettings);
477
+ const projectConfig = getConfig(projectSettings);
478
+
479
+ console.log(
480
+ projectInstalled ? c.green("V") : c.red("X"),
481
+ "Project:",
482
+ projectInstalled ? "Installed" : "Not installed",
483
+ c.dim(`(${projectPath})`)
484
+ );
485
+ if (projectInstalled) {
486
+ console.log(c.dim(` Threshold: ${projectConfig.editThreshold || 3}, List: ${projectConfig.taskListId || "(auto)"}`));
487
+ }
488
+ } else {
489
+ console.log(c.dim("."), "Project:", c.dim("No .claude/settings.json"));
490
+ }
491
+
492
+ // Check dependencies
493
+ console.log();
494
+ console.log(c.bold("Dependencies:"));
495
+
496
+ try {
497
+ const { execSync } = require("child_process");
498
+ execSync("which service-implementation", { stdio: "pipe" });
499
+ console.log(c.green("V"), "service-implementation CLI");
500
+ } catch {
501
+ console.log(c.red("X"), "service-implementation CLI", c.dim("(required for task dispatch)"));
502
+ }
503
+
504
+ try {
505
+ const { execSync } = require("child_process");
506
+ execSync("which claude", { stdio: "pipe" });
507
+ console.log(c.green("V"), "claude CLI");
508
+ } catch {
509
+ console.log(c.red("X"), "claude CLI", c.dim("(required for headless review)"));
510
+ }
511
+
512
+ console.log();
513
+ }
514
+
515
+ // Main
516
+ const args = process.argv.slice(2);
517
+ const command = args[0];
518
+ const commandArgs = args.slice(1);
519
+
520
+ switch (command) {
521
+ case "install":
522
+ install(commandArgs);
523
+ break;
524
+ case "config":
525
+ configure(commandArgs);
526
+ break;
527
+ case "uninstall":
528
+ uninstall(commandArgs);
529
+ break;
530
+ case "run":
531
+ import("./hook.js").then((m) => m.run());
532
+ break;
533
+ case "status":
534
+ status();
535
+ break;
536
+ case "--help":
537
+ case "-h":
538
+ case undefined:
539
+ printUsage();
540
+ break;
541
+ default:
542
+ console.error(c.red(`Unknown command: ${command}`));
543
+ printUsage();
544
+ process.exit(1);
545
+ }