@hasna/hooks 0.0.1 → 0.0.2

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 (62) hide show
  1. package/dist/index.js +366 -0
  2. package/hooks/hook-agentmessages/bin/cli.ts +125 -0
  3. package/package.json +2 -2
  4. package/hooks/hook-agentmessages/src/check-messages.ts +0 -151
  5. package/hooks/hook-agentmessages/src/install.ts +0 -126
  6. package/hooks/hook-agentmessages/src/session-start.ts +0 -255
  7. package/hooks/hook-agentmessages/src/uninstall.ts +0 -89
  8. package/hooks/hook-branchprotect/src/cli.ts +0 -126
  9. package/hooks/hook-branchprotect/src/hook.ts +0 -88
  10. package/hooks/hook-branchprotect/tsconfig.json +0 -25
  11. package/hooks/hook-checkbugs/src/cli.ts +0 -628
  12. package/hooks/hook-checkbugs/src/hook.ts +0 -335
  13. package/hooks/hook-checkbugs/tsconfig.json +0 -15
  14. package/hooks/hook-checkdocs/src/cli.ts +0 -628
  15. package/hooks/hook-checkdocs/src/hook.ts +0 -310
  16. package/hooks/hook-checkdocs/tsconfig.json +0 -15
  17. package/hooks/hook-checkfiles/src/cli.ts +0 -545
  18. package/hooks/hook-checkfiles/src/hook.ts +0 -321
  19. package/hooks/hook-checkfiles/tsconfig.json +0 -15
  20. package/hooks/hook-checklint/src/cli-patch.ts +0 -32
  21. package/hooks/hook-checklint/src/cli.ts +0 -667
  22. package/hooks/hook-checklint/src/hook.ts +0 -473
  23. package/hooks/hook-checklint/tsconfig.json +0 -15
  24. package/hooks/hook-checkpoint/src/cli.ts +0 -191
  25. package/hooks/hook-checkpoint/src/hook.ts +0 -207
  26. package/hooks/hook-checkpoint/tsconfig.json +0 -25
  27. package/hooks/hook-checksecurity/src/cli.ts +0 -601
  28. package/hooks/hook-checksecurity/src/hook.ts +0 -334
  29. package/hooks/hook-checksecurity/tsconfig.json +0 -15
  30. package/hooks/hook-checktasks/src/cli.ts +0 -578
  31. package/hooks/hook-checktasks/src/hook.ts +0 -308
  32. package/hooks/hook-checktasks/tsconfig.json +0 -20
  33. package/hooks/hook-checktests/src/cli.ts +0 -627
  34. package/hooks/hook-checktests/src/hook.ts +0 -334
  35. package/hooks/hook-checktests/tsconfig.json +0 -15
  36. package/hooks/hook-contextrefresh/src/cli.ts +0 -152
  37. package/hooks/hook-contextrefresh/src/hook.ts +0 -148
  38. package/hooks/hook-contextrefresh/tsconfig.json +0 -25
  39. package/hooks/hook-gitguard/src/cli.ts +0 -159
  40. package/hooks/hook-gitguard/src/hook.ts +0 -129
  41. package/hooks/hook-gitguard/tsconfig.json +0 -25
  42. package/hooks/hook-packageage/src/cli.ts +0 -165
  43. package/hooks/hook-packageage/src/hook.ts +0 -177
  44. package/hooks/hook-packageage/tsconfig.json +0 -25
  45. package/hooks/hook-phonenotify/src/cli.ts +0 -196
  46. package/hooks/hook-phonenotify/src/hook.ts +0 -139
  47. package/hooks/hook-phonenotify/tsconfig.json +0 -25
  48. package/hooks/hook-precompact/src/cli.ts +0 -168
  49. package/hooks/hook-precompact/src/hook.ts +0 -122
  50. package/hooks/hook-precompact/tsconfig.json +0 -25
  51. package/src/cli/components/App.tsx +0 -191
  52. package/src/cli/components/CategorySelect.tsx +0 -37
  53. package/src/cli/components/DataTable.tsx +0 -133
  54. package/src/cli/components/Header.tsx +0 -18
  55. package/src/cli/components/HookSelect.tsx +0 -29
  56. package/src/cli/components/InstallProgress.tsx +0 -105
  57. package/src/cli/components/SearchView.tsx +0 -86
  58. package/src/cli/index.tsx +0 -218
  59. package/src/index.ts +0 -31
  60. package/src/lib/installer.ts +0 -288
  61. package/src/lib/registry.ts +0 -205
  62. package/tsconfig.json +0 -17
@@ -1,334 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- /**
4
- * Claude Code Hook: check-security
5
- *
6
- * Runs security checks via Claude and Codex headless agents.
7
- * This is a BLOCKER hook on the Stop event.
8
- *
9
- * Only runs for repos matching [prefix]-[name] pattern.
10
- * Only runs once per session (state flag prevents re-runs).
11
- *
12
- * Configuration:
13
- * - taskListId: task list for dispatching security tasks
14
- * - keywords: keywords that trigger the check (default: ["dev"])
15
- * - enabled: enable/disable the hook
16
- */
17
-
18
- import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
19
- import { join } from "path";
20
- import { homedir } from "os";
21
- import { spawnSync, execSync } from "child_process";
22
-
23
- interface CheckSecurityConfig {
24
- taskListId?: string;
25
- keywords?: string[];
26
- enabled?: boolean;
27
- }
28
-
29
- interface HookInput {
30
- session_id: string;
31
- transcript_path: string;
32
- cwd: string;
33
- }
34
-
35
- interface SessionState {
36
- securityChecked: boolean;
37
- lastCheckRun: number;
38
- }
39
-
40
- const CONFIG_KEY = "checkSecurityConfig";
41
- const STATE_DIR = join(homedir(), ".claude", "hook-state");
42
-
43
- /**
44
- * Sanitize ID to prevent path traversal and injection attacks
45
- */
46
- function sanitizeId(id: string): string {
47
- if (!id || typeof id !== 'string') return 'default';
48
- return id.replace(/[^a-zA-Z0-9_-]/g, '-').slice(0, 100) || 'default';
49
- }
50
-
51
- const SECURITY_PROMPT = `You are a security reviewer. Analyze the codebase in the current directory for security vulnerabilities.
52
-
53
- For each security issue found, create a task using the service-implementation CLI:
54
- service-implementation task dispatch "{taskListId}" -s "SECURITY: [severity] - [brief description]" -d "[detailed description with file:line reference and remediation advice]"
55
-
56
- Severity levels: CRITICAL, HIGH, MEDIUM, LOW
57
-
58
- Focus on:
59
- - Injection vulnerabilities (SQL, XSS, command injection)
60
- - Authentication/authorization issues
61
- - Sensitive data exposure
62
- - Insecure configurations
63
- - Dependency vulnerabilities
64
- - Hardcoded secrets or credentials
65
- - Input validation issues
66
- - CSRF vulnerabilities
67
- - Insecure deserialization
68
-
69
- If no security issues are found, do not create any tasks.
70
- Only create tasks for real security concerns.
71
- Limit to max 10 most critical security issues.`;
72
-
73
- function isValidRepoPattern(cwd: string): boolean {
74
- const dirName = cwd.split("/").filter(Boolean).pop() || "";
75
- // Match: hook-checklint, skill-installhook, iapp-mail, etc.
76
- return /^[a-z]+-[a-z0-9-]+$/i.test(dirName);
77
- }
78
-
79
- function readStdinJson(): HookInput | null {
80
- try {
81
- const stdin = readFileSync(0, "utf-8");
82
- return JSON.parse(stdin);
83
- } catch {
84
- return null;
85
- }
86
- }
87
-
88
- function readSettings(path: string): Record<string, unknown> {
89
- if (!existsSync(path)) return {};
90
- try {
91
- return JSON.parse(readFileSync(path, "utf-8"));
92
- } catch {
93
- return {};
94
- }
95
- }
96
-
97
- function getConfig(cwd: string): CheckSecurityConfig {
98
- // Try project settings first
99
- const projectSettings = readSettings(join(cwd, ".claude", "settings.json"));
100
- if (projectSettings[CONFIG_KEY]) {
101
- return projectSettings[CONFIG_KEY] as CheckSecurityConfig;
102
- }
103
-
104
- // Fall back to global settings
105
- const globalSettings = readSettings(join(homedir(), ".claude", "settings.json"));
106
- if (globalSettings[CONFIG_KEY]) {
107
- return globalSettings[CONFIG_KEY] as CheckSecurityConfig;
108
- }
109
-
110
- // Default config
111
- return {
112
- keywords: ["dev"],
113
- enabled: true,
114
- };
115
- }
116
-
117
- function getStateFile(sessionId: string): string {
118
- mkdirSync(STATE_DIR, { recursive: true });
119
- const safeSessionId = sanitizeId(sessionId);
120
- return join(STATE_DIR, `checksecurity-${safeSessionId}.json`);
121
- }
122
-
123
- function getSessionState(sessionId: string): SessionState {
124
- const stateFile = getStateFile(sessionId);
125
- if (existsSync(stateFile)) {
126
- try {
127
- return JSON.parse(readFileSync(stateFile, "utf-8"));
128
- } catch {
129
- // Corrupted state, reset
130
- }
131
- }
132
- return { securityChecked: false, lastCheckRun: 0 };
133
- }
134
-
135
- function saveSessionState(sessionId: string, state: SessionState): void {
136
- const stateFile = getStateFile(sessionId);
137
- writeFileSync(stateFile, JSON.stringify(state, null, 2));
138
- }
139
-
140
- function getSessionName(transcriptPath: string): string | null {
141
- if (!existsSync(transcriptPath)) return null;
142
-
143
- try {
144
- const content = readFileSync(transcriptPath, "utf-8");
145
- let lastTitle: string | null = null;
146
- let searchStart = 0;
147
-
148
- while (true) {
149
- const titleIndex = content.indexOf('"custom-title"', searchStart);
150
- if (titleIndex === -1) break;
151
-
152
- const lineStart = content.lastIndexOf("\n", titleIndex) + 1;
153
- const lineEnd = content.indexOf("\n", titleIndex);
154
- const line = content.slice(lineStart, lineEnd === -1 ? undefined : lineEnd);
155
-
156
- try {
157
- const entry = JSON.parse(line);
158
- if (entry.type === "custom-title" && entry.customTitle) {
159
- lastTitle = entry.customTitle;
160
- }
161
- } catch {
162
- // Skip malformed lines
163
- }
164
-
165
- searchStart = titleIndex + 1;
166
- }
167
-
168
- return lastTitle;
169
- } catch {
170
- return null;
171
- }
172
- }
173
-
174
- function getProjectTaskListId(cwd: string): string | null {
175
- const dirName = cwd.split("/").filter(Boolean).pop() || "";
176
- return `${dirName}-dev`;
177
- }
178
-
179
- function isClaudeAvailable(): boolean {
180
- try {
181
- execSync("which claude", { stdio: "pipe" });
182
- return true;
183
- } catch {
184
- return false;
185
- }
186
- }
187
-
188
- function isCodexAvailable(): boolean {
189
- try {
190
- execSync("which codex", { stdio: "pipe" });
191
- return true;
192
- } catch {
193
- return false;
194
- }
195
- }
196
-
197
- function runClaudeSecurityCheck(cwd: string, taskListId: string): void {
198
- const safeTaskListId = sanitizeId(taskListId);
199
- const prompt = SECURITY_PROMPT.replace("{taskListId}", safeTaskListId);
200
-
201
- console.error(`[hook-checksecurity] Running Claude security check...`);
202
-
203
- spawnSync(
204
- "claude",
205
- [
206
- "-p",
207
- prompt,
208
- "--permission-mode",
209
- "acceptEdits",
210
- "--allowedTools",
211
- "Bash,Read,Glob,Grep",
212
- "--no-session-persistence",
213
- ],
214
- {
215
- cwd,
216
- stdio: "inherit",
217
- }
218
- );
219
- }
220
-
221
- function runCodexSecurityCheck(cwd: string, taskListId: string): void {
222
- const safeTaskListId = sanitizeId(taskListId);
223
- const prompt = SECURITY_PROMPT.replace("{taskListId}", safeTaskListId);
224
-
225
- console.error(`[hook-checksecurity] Running Codex security check...`);
226
-
227
- spawnSync(
228
- "codex",
229
- [
230
- "exec",
231
- prompt,
232
- ],
233
- {
234
- cwd,
235
- stdio: "inherit",
236
- }
237
- );
238
- }
239
-
240
- function approve() {
241
- console.log(JSON.stringify({ decision: "approve" }));
242
- process.exit(0);
243
- }
244
-
245
- function block(reason: string) {
246
- console.log(JSON.stringify({ decision: "block", reason }));
247
- process.exit(0);
248
- }
249
-
250
- export function run() {
251
- const hookInput = readStdinJson();
252
- if (!hookInput) {
253
- approve();
254
- return;
255
- }
256
-
257
- const { session_id, cwd, transcript_path } = hookInput;
258
-
259
- // Check repo pattern - only run for [prefix]-[name] folders
260
- if (!isValidRepoPattern(cwd)) {
261
- approve();
262
- return;
263
- }
264
-
265
- const config = getConfig(cwd);
266
-
267
- // Check if hook is disabled
268
- if (config.enabled === false) {
269
- approve();
270
- return;
271
- }
272
-
273
- // Check keywords match
274
- const sessionName = transcript_path ? getSessionName(transcript_path) : null;
275
- const nameToCheck = sessionName || config.taskListId || "";
276
- const keywords = config.keywords || ["dev"];
277
-
278
- const matchesKeyword = keywords.some((keyword) =>
279
- nameToCheck.toLowerCase().includes(keyword.toLowerCase())
280
- );
281
-
282
- // If keywords are configured and we have a session name, check for match
283
- if (keywords.length > 0 && nameToCheck && !matchesKeyword) {
284
- approve();
285
- return;
286
- }
287
-
288
- // Check session state - only run once per session
289
- const state = getSessionState(session_id);
290
- if (state.securityChecked) {
291
- // Already ran security check this session
292
- approve();
293
- return;
294
- }
295
-
296
- // Mark as checked before running (prevent re-runs)
297
- state.securityChecked = true;
298
- state.lastCheckRun = Date.now();
299
- saveSessionState(session_id, state);
300
-
301
- const taskListId = config.taskListId || getProjectTaskListId(cwd) || "default-dev";
302
-
303
- // Run security checks
304
- const claudeAvailable = isClaudeAvailable();
305
- const codexAvailable = isCodexAvailable();
306
-
307
- if (!claudeAvailable && !codexAvailable) {
308
- console.error(`[hook-checksecurity] Neither Claude nor Codex CLI available, skipping security check`);
309
- approve();
310
- return;
311
- }
312
-
313
- console.error(`[hook-checksecurity] Running security checks for ${cwd}`);
314
-
315
- // Run Claude security check
316
- if (claudeAvailable) {
317
- runClaudeSecurityCheck(cwd, taskListId);
318
- }
319
-
320
- // Run Codex security check
321
- if (codexAvailable) {
322
- runCodexSecurityCheck(cwd, taskListId);
323
- }
324
-
325
- console.error(`[hook-checksecurity] Security checks completed`);
326
-
327
- // After running checks, approve (let checktasks handle blocking if tasks exist)
328
- approve();
329
- }
330
-
331
- // Allow direct execution
332
- if (import.meta.main) {
333
- run();
334
- }
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "strict": true,
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "outDir": "./dist",
10
- "declaration": true,
11
- "declarationMap": true
12
- },
13
- "include": ["src/**/*"],
14
- "exclude": ["node_modules", "dist"]
15
- }