cc-safe-setup 11.7.0 → 12.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.
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env -S npx tsx
2
- /**
3
- * destructive-guard.ts — Claude Code PreToolUse hook in TypeScript
4
- *
5
- * Blocks rm -rf /, git reset --hard, git clean -fd, and similar
6
- * destructive commands. Exit code 2 = block, 0 = allow.
7
- *
8
- * Run with: npx tsx destructive-guard.ts
9
- * Or compile: npx tsc destructive-guard.ts && node destructive-guard.js
10
- */
11
-
12
- interface HookInput {
13
- tool_input: {
14
- command?: string;
15
- };
16
- }
17
-
18
- const DANGEROUS_PATTERNS: RegExp[] = [
19
- /\brm\s+.*-rf\s+(\/|~\/?\s*$|\.\.\/)/,
20
- /\bgit\s+reset\s+--hard/,
21
- /\bgit\s+clean\s+-[a-zA-Z]*f/,
22
- /\bgit\s+checkout\s+--force/,
23
- /\bchmod\s+(-R\s+)?777\s+\//,
24
- /\bfind\s+\/\s+-delete/,
25
- /Remove-Item.*-Recurse.*-Force/,
26
- /--no-preserve-root/,
27
- /\bsudo\s+mkfs\b/,
28
- ];
29
-
30
- async function main(): Promise<void> {
31
- let data = '';
32
- for await (const chunk of process.stdin) {
33
- data += chunk;
34
- }
35
-
36
- let input: HookInput;
37
- try {
38
- input = JSON.parse(data);
39
- } catch {
40
- process.exit(0); // Don't block on parse error
41
- }
42
-
43
- const cmd = input.tool_input?.command;
44
- if (!cmd) {
45
- process.exit(0);
46
- }
47
-
48
- // Skip echo/printf context
49
- const trimmed = cmd.trimStart().toLowerCase();
50
- if (trimmed.startsWith('echo ') || trimmed.startsWith('printf ')) {
51
- process.exit(0);
52
- }
53
-
54
- for (const pattern of DANGEROUS_PATTERNS) {
55
- if (pattern.test(cmd)) {
56
- process.stderr.write(`BLOCKED: Dangerous command detected\nCommand: ${cmd}\n`);
57
- process.exit(2);
58
- }
59
- }
60
-
61
- process.exit(0);
62
- }
63
-
64
- main();