@yagyeshvyas/vibeguard 1.12.0 → 1.13.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.
- package/CHANGELOG.md +26 -0
- package/README.md +34 -17
- package/bin/cli.js +2753 -2753
- package/bin/cmd-mcp-firewall.js +1 -0
- package/bin/cmd-platform.js +3 -0
- package/ci/vibeguard.yml +42 -42
- package/package.json +2 -2
- package/scripts/counts.js +93 -93
- package/scripts/postinstall.js +26 -26
- package/src/auto.js +427 -427
- package/src/daemon.js +343 -343
- package/src/dashboard.js +278 -278
- package/src/engine.js +297 -297
- package/src/hook.js +151 -151
- package/src/install.js +298 -298
- package/src/integrity.js +1 -0
- package/src/integrity.json +9 -6
- package/src/mcp-firewall.js +11 -0
- package/src/platform/approval-service.js +124 -0
- package/src/platform/approval.js +16 -0
- package/src/platform/oauth-server.js +89 -0
- package/src/platform/os-sandbox.js +52 -1
- package/src/platform/runtime-monitor.js +69 -0
- package/src/platform/sandbox-manager.js +5 -0
- package/src/plugin.js +182 -182
- package/src/privacy-audit.js +272 -272
- package/src/repl.js +150 -150
- package/src/report.js +331 -331
- package/src/rules-pack.js +3068 -3068
- package/src/rules.js +1822 -1822
- package/src/sbom.js +193 -193
- package/src/scanner.js +1032 -1032
- package/src/shell-guard.js +302 -302
- package/src/slopsquat.js +144 -144
- package/src/trace.js +220 -220
- package/src/.vibeguard/cache/file-hashes.json +0 -60
- package/src/.vibeguard/latest-snapshot.json +0 -36
- package/src/.vibeguard/mcp-pins.json +0 -1
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +0 -279
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +0 -151
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +0 -299
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +0 -65
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +0 -2051
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +0 -168
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +0 -362
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +0 -150
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +0 -1611
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +0 -164
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +0 -292
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +0 -144
- package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +0 -220
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +0 -299
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +0 -37
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +0 -2055
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +0 -168
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +0 -362
- package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +0 -220
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +0 -279
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +0 -151
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +0 -299
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +0 -65
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +0 -2055
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +0 -168
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +0 -362
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +0 -150
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +0 -1611
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +0 -164
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +0 -292
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +0 -144
- package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +0 -220
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +0 -279
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +0 -151
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +0 -299
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +0 -65
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +0 -2054
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +0 -168
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +0 -362
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +0 -150
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +0 -1611
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +0 -164
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +0 -292
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +0 -144
- package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +0 -220
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +0 -299
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +0 -37
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +0 -2055
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +0 -168
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +0 -362
- package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +0 -220
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +0 -428
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +0 -344
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +0 -297
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +0 -33
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +0 -2055
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +0 -1611
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +0 -292
- package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +0 -220
- package/src/.vibeguard-baseline.json +0 -5226
package/src/hook.js
CHANGED
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* VibeGuard Real-Time Hook — PostToolUse auto-scan.
|
|
5
|
-
*
|
|
6
|
-
* This module provides two integration modes:
|
|
7
|
-
*
|
|
8
|
-
* 1. Claude Code hook (settings.json):
|
|
9
|
-
* Add to .claude/settings.json:
|
|
10
|
-
* {
|
|
11
|
-
* "hooks": {
|
|
12
|
-
* "PostToolUse": [{
|
|
13
|
-
* "matcher": "Edit|Write|MultiEdit",
|
|
14
|
-
* "hooks": [{ "type": "command", "command": "npx -y @yagyeshvyas/vibeguard hook-post-edit" }]
|
|
15
|
-
* }]
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* After every file edit/write by Claude Code, VibeGuard scans the changed file
|
|
19
|
-
* and prints warnings if security issues are found.
|
|
20
|
-
*
|
|
21
|
-
* 2. Generic file watcher (any AI tool):
|
|
22
|
-
* vibeguard watch-post-edit
|
|
23
|
-
* Watches the current directory for file changes and auto-scans them.
|
|
24
|
-
*
|
|
25
|
-
* 3. Git pre-commit hook (already exists via `vibeguard install-hook`).
|
|
26
|
-
*
|
|
27
|
-
* All modes are ZERO-COST — no API calls, no network, pure local scanning.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
const fs = require('fs');
|
|
31
|
-
const path = require('path');
|
|
32
|
-
const { scanFileContent } = require('./scanner');
|
|
33
|
-
const { computeGrade } = require('./scanner');
|
|
34
|
-
|
|
35
|
-
const C = {
|
|
36
|
-
red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
|
|
37
|
-
blue: '\x1b[34m', cyan: '\x1b[36m', dim: '\x1b[2m',
|
|
38
|
-
bold: '\x1b[1m', reset: '\x1b[0m',
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Called by Claude Code PostToolUse hook — reads the tool input from stdin
|
|
42
|
-
// (Claude Code pipes the tool result as JSON on stdin).
|
|
43
|
-
function handlePostEdit() {
|
|
44
|
-
let input = '';
|
|
45
|
-
process.stdin.setEncoding('utf8');
|
|
46
|
-
process.stdin.on('data', (chunk) => (input += chunk));
|
|
47
|
-
process.stdin.on('end', () => {
|
|
48
|
-
let toolInput;
|
|
49
|
-
try { toolInput = JSON.parse(input); } catch { return; }
|
|
50
|
-
|
|
51
|
-
// Claude Code PostToolUse sends { tool_name, tool_input, tool_result }
|
|
52
|
-
const toolName = toolInput.tool_name || toolInput.toolName || '';
|
|
53
|
-
const toolInputData = toolInput.tool_input || toolInput.toolInput || {};
|
|
54
|
-
const filePath = toolInputData.file_path || toolInputData.filePath || toolInputData.path || '';
|
|
55
|
-
|
|
56
|
-
if (!filePath || !fs.existsSync(filePath)) {
|
|
57
|
-
return; // no file to scan
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Only scan code files
|
|
61
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
62
|
-
const scanExts = new Set(['.js', '.jsx', '.ts', '.tsx', '.py', '.go', '.rb', '.php', '.java', '.kt', '.swift', '.m', '.sh', '.yml', '.yaml', '.json', '.toml', '.sql', '.env', '.dockerfile', '.tf']);
|
|
63
|
-
if (!scanExts.has(ext) && !/^Dockerfile/i.test(path.basename(filePath))) return;
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
67
|
-
const relPath = path.relative(process.cwd(), filePath);
|
|
68
|
-
const findings = scanFileContent(filePath, relPath, content, null);
|
|
69
|
-
|
|
70
|
-
if (findings.length === 0) return;
|
|
71
|
-
|
|
72
|
-
// Print warnings to stderr (Claude Code captures stderr and shows it)
|
|
73
|
-
const critical = findings.filter(f => f.severity === 'critical');
|
|
74
|
-
const high = findings.filter(f => f.severity === 'high');
|
|
75
|
-
const medium = findings.filter(f => f.severity === 'medium');
|
|
76
|
-
|
|
77
|
-
if (critical.length > 0 || high.length > 0) {
|
|
78
|
-
process.stderr.write(`\n${C.red}${C.bold}VibeGuard: ${critical.length} critical, ${high.length} high in ${relPath}${C.reset}\n`);
|
|
79
|
-
for (const f of [...critical, ...high].slice(0, 10)) {
|
|
80
|
-
process.stderr.write(` ${C.red}[${f.severity}]${C.reset} ${f.ruleId} ${C.dim}line ${f.line}${C.reset} — ${f.message}\n`);
|
|
81
|
-
if (f.fix) process.stderr.write(` ${C.green}fix:${C.reset} ${f.fix}\n`);
|
|
82
|
-
}
|
|
83
|
-
process.stderr.write(`${C.dim}Run 'vibeguard scan' for full report.${C.reset}\n\n`);
|
|
84
|
-
} else if (medium.length > 0) {
|
|
85
|
-
process.stderr.write(`\n${C.yellow}VibeGuard: ${medium.length} medium findings in ${relPath}${C.reset}\n`);
|
|
86
|
-
for (const f of medium.slice(0, 5)) {
|
|
87
|
-
process.stderr.write(` ${C.yellow}[medium]${C.reset} ${f.ruleId} ${C.dim}line ${f.line}${C.reset}\n`);
|
|
88
|
-
}
|
|
89
|
-
process.stderr.write(`\n`);
|
|
90
|
-
}
|
|
91
|
-
} catch {
|
|
92
|
-
// silent fail — never block the AI from working
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Install the PostToolUse hook into Claude Code's settings.json
|
|
98
|
-
function installPostEditHook(dir) {
|
|
99
|
-
const settingsDir = path.join(dir, '.claude');
|
|
100
|
-
const settingsFile = path.join(settingsDir, 'settings.json');
|
|
101
|
-
|
|
102
|
-
let settings = {};
|
|
103
|
-
try {
|
|
104
|
-
settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
|
|
105
|
-
} catch {}
|
|
106
|
-
|
|
107
|
-
if (!settings.hooks) settings.hooks = {};
|
|
108
|
-
if (!settings.hooks.PostToolUse) settings.hooks.PostToolUse = [];
|
|
109
|
-
|
|
110
|
-
// Check if already installed
|
|
111
|
-
const exists = settings.hooks.PostToolUse.some(
|
|
112
|
-
h => h.hooks && h.hooks.some(hh => hh.command && (hh.command.includes('vibeguard') || hh.command.includes('hook-post-edit')))
|
|
113
|
-
);
|
|
114
|
-
if (exists) return { installed: false, reason: 'already present' };
|
|
115
|
-
|
|
116
|
-
const cliPath = path.resolve(__dirname, '..', 'bin', 'cli.js');
|
|
117
|
-
const nodeBin = process.execPath;
|
|
118
|
-
const cmd = process.platform === 'win32'
|
|
119
|
-
? `"${nodeBin}" "${cliPath}" hook-post-edit`
|
|
120
|
-
: `node "${cliPath}" hook-post-edit`;
|
|
121
|
-
|
|
122
|
-
settings.hooks.PostToolUse.push({
|
|
123
|
-
matcher: 'Edit|Write|MultiEdit',
|
|
124
|
-
hooks: [{ type: 'command', command: cmd }],
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
fs.mkdirSync(settingsDir, { recursive: true });
|
|
128
|
-
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
129
|
-
return { installed: true, file: settingsFile };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Remove the PostToolUse hook
|
|
133
|
-
function uninstallPostEditHook(dir) {
|
|
134
|
-
const settingsFile = path.join(dir, '.claude', 'settings.json');
|
|
135
|
-
let settings;
|
|
136
|
-
try { settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8')); } catch { return { uninstalled: false, reason: 'no settings.json' }; }
|
|
137
|
-
if (!settings.hooks || !settings.hooks.PostToolUse) return { uninstalled: false, reason: 'no PostToolUse hooks' };
|
|
138
|
-
|
|
139
|
-
const before = settings.hooks.PostToolUse.length;
|
|
140
|
-
settings.hooks.PostToolUse = settings.hooks.PostToolUse.filter(
|
|
141
|
-
h => !h.hooks || !h.hooks.some(hh => hh.command && (hh.command.includes('vibeguard') || hh.command.includes('hook-post-edit')))
|
|
142
|
-
);
|
|
143
|
-
const afterLen = settings.hooks.PostToolUse ? settings.hooks.PostToolUse.length : 0;
|
|
144
|
-
if (settings.hooks.PostToolUse && settings.hooks.PostToolUse.length === 0) delete settings.hooks.PostToolUse;
|
|
145
|
-
if (settings.hooks && Object.keys(settings.hooks).length === 0) delete settings.hooks;
|
|
146
|
-
|
|
147
|
-
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
148
|
-
return { uninstalled: before > afterLen };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
module.exports = { handlePostEdit, installPostEditHook, uninstallPostEditHook };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* VibeGuard Real-Time Hook — PostToolUse auto-scan.
|
|
5
|
+
*
|
|
6
|
+
* This module provides two integration modes:
|
|
7
|
+
*
|
|
8
|
+
* 1. Claude Code hook (settings.json):
|
|
9
|
+
* Add to .claude/settings.json:
|
|
10
|
+
* {
|
|
11
|
+
* "hooks": {
|
|
12
|
+
* "PostToolUse": [{
|
|
13
|
+
* "matcher": "Edit|Write|MultiEdit",
|
|
14
|
+
* "hooks": [{ "type": "command", "command": "npx -y @yagyeshvyas/vibeguard hook-post-edit" }]
|
|
15
|
+
* }]
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* After every file edit/write by Claude Code, VibeGuard scans the changed file
|
|
19
|
+
* and prints warnings if security issues are found.
|
|
20
|
+
*
|
|
21
|
+
* 2. Generic file watcher (any AI tool):
|
|
22
|
+
* vibeguard watch-post-edit
|
|
23
|
+
* Watches the current directory for file changes and auto-scans them.
|
|
24
|
+
*
|
|
25
|
+
* 3. Git pre-commit hook (already exists via `vibeguard install-hook`).
|
|
26
|
+
*
|
|
27
|
+
* All modes are ZERO-COST — no API calls, no network, pure local scanning.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const fs = require('fs');
|
|
31
|
+
const path = require('path');
|
|
32
|
+
const { scanFileContent } = require('./scanner');
|
|
33
|
+
const { computeGrade } = require('./scanner');
|
|
34
|
+
|
|
35
|
+
const C = {
|
|
36
|
+
red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
|
|
37
|
+
blue: '\x1b[34m', cyan: '\x1b[36m', dim: '\x1b[2m',
|
|
38
|
+
bold: '\x1b[1m', reset: '\x1b[0m',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Called by Claude Code PostToolUse hook — reads the tool input from stdin
|
|
42
|
+
// (Claude Code pipes the tool result as JSON on stdin).
|
|
43
|
+
function handlePostEdit() {
|
|
44
|
+
let input = '';
|
|
45
|
+
process.stdin.setEncoding('utf8');
|
|
46
|
+
process.stdin.on('data', (chunk) => (input += chunk));
|
|
47
|
+
process.stdin.on('end', () => {
|
|
48
|
+
let toolInput;
|
|
49
|
+
try { toolInput = JSON.parse(input); } catch { return; }
|
|
50
|
+
|
|
51
|
+
// Claude Code PostToolUse sends { tool_name, tool_input, tool_result }
|
|
52
|
+
const toolName = toolInput.tool_name || toolInput.toolName || '';
|
|
53
|
+
const toolInputData = toolInput.tool_input || toolInput.toolInput || {};
|
|
54
|
+
const filePath = toolInputData.file_path || toolInputData.filePath || toolInputData.path || '';
|
|
55
|
+
|
|
56
|
+
if (!filePath || !fs.existsSync(filePath)) {
|
|
57
|
+
return; // no file to scan
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Only scan code files
|
|
61
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
62
|
+
const scanExts = new Set(['.js', '.jsx', '.ts', '.tsx', '.py', '.go', '.rb', '.php', '.java', '.kt', '.swift', '.m', '.sh', '.yml', '.yaml', '.json', '.toml', '.sql', '.env', '.dockerfile', '.tf']);
|
|
63
|
+
if (!scanExts.has(ext) && !/^Dockerfile/i.test(path.basename(filePath))) return;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
67
|
+
const relPath = path.relative(process.cwd(), filePath);
|
|
68
|
+
const findings = scanFileContent(filePath, relPath, content, null);
|
|
69
|
+
|
|
70
|
+
if (findings.length === 0) return;
|
|
71
|
+
|
|
72
|
+
// Print warnings to stderr (Claude Code captures stderr and shows it)
|
|
73
|
+
const critical = findings.filter(f => f.severity === 'critical');
|
|
74
|
+
const high = findings.filter(f => f.severity === 'high');
|
|
75
|
+
const medium = findings.filter(f => f.severity === 'medium');
|
|
76
|
+
|
|
77
|
+
if (critical.length > 0 || high.length > 0) {
|
|
78
|
+
process.stderr.write(`\n${C.red}${C.bold}VibeGuard: ${critical.length} critical, ${high.length} high in ${relPath}${C.reset}\n`);
|
|
79
|
+
for (const f of [...critical, ...high].slice(0, 10)) {
|
|
80
|
+
process.stderr.write(` ${C.red}[${f.severity}]${C.reset} ${f.ruleId} ${C.dim}line ${f.line}${C.reset} — ${f.message}\n`);
|
|
81
|
+
if (f.fix) process.stderr.write(` ${C.green}fix:${C.reset} ${f.fix}\n`);
|
|
82
|
+
}
|
|
83
|
+
process.stderr.write(`${C.dim}Run 'vibeguard scan' for full report.${C.reset}\n\n`);
|
|
84
|
+
} else if (medium.length > 0) {
|
|
85
|
+
process.stderr.write(`\n${C.yellow}VibeGuard: ${medium.length} medium findings in ${relPath}${C.reset}\n`);
|
|
86
|
+
for (const f of medium.slice(0, 5)) {
|
|
87
|
+
process.stderr.write(` ${C.yellow}[medium]${C.reset} ${f.ruleId} ${C.dim}line ${f.line}${C.reset}\n`);
|
|
88
|
+
}
|
|
89
|
+
process.stderr.write(`\n`);
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// silent fail — never block the AI from working
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Install the PostToolUse hook into Claude Code's settings.json
|
|
98
|
+
function installPostEditHook(dir) {
|
|
99
|
+
const settingsDir = path.join(dir, '.claude');
|
|
100
|
+
const settingsFile = path.join(settingsDir, 'settings.json');
|
|
101
|
+
|
|
102
|
+
let settings = {};
|
|
103
|
+
try {
|
|
104
|
+
settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
|
|
105
|
+
} catch {}
|
|
106
|
+
|
|
107
|
+
if (!settings.hooks) settings.hooks = {};
|
|
108
|
+
if (!settings.hooks.PostToolUse) settings.hooks.PostToolUse = [];
|
|
109
|
+
|
|
110
|
+
// Check if already installed
|
|
111
|
+
const exists = settings.hooks.PostToolUse.some(
|
|
112
|
+
h => h.hooks && h.hooks.some(hh => hh.command && (hh.command.includes('vibeguard') || hh.command.includes('hook-post-edit')))
|
|
113
|
+
);
|
|
114
|
+
if (exists) return { installed: false, reason: 'already present' };
|
|
115
|
+
|
|
116
|
+
const cliPath = path.resolve(__dirname, '..', 'bin', 'cli.js');
|
|
117
|
+
const nodeBin = process.execPath;
|
|
118
|
+
const cmd = process.platform === 'win32'
|
|
119
|
+
? `"${nodeBin}" "${cliPath}" hook-post-edit`
|
|
120
|
+
: `node "${cliPath}" hook-post-edit`;
|
|
121
|
+
|
|
122
|
+
settings.hooks.PostToolUse.push({
|
|
123
|
+
matcher: 'Edit|Write|MultiEdit',
|
|
124
|
+
hooks: [{ type: 'command', command: cmd }],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
fs.mkdirSync(settingsDir, { recursive: true });
|
|
128
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
129
|
+
return { installed: true, file: settingsFile };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Remove the PostToolUse hook
|
|
133
|
+
function uninstallPostEditHook(dir) {
|
|
134
|
+
const settingsFile = path.join(dir, '.claude', 'settings.json');
|
|
135
|
+
let settings;
|
|
136
|
+
try { settings = JSON.parse(fs.readFileSync(settingsFile, 'utf8')); } catch { return { uninstalled: false, reason: 'no settings.json' }; }
|
|
137
|
+
if (!settings.hooks || !settings.hooks.PostToolUse) return { uninstalled: false, reason: 'no PostToolUse hooks' };
|
|
138
|
+
|
|
139
|
+
const before = settings.hooks.PostToolUse.length;
|
|
140
|
+
settings.hooks.PostToolUse = settings.hooks.PostToolUse.filter(
|
|
141
|
+
h => !h.hooks || !h.hooks.some(hh => hh.command && (hh.command.includes('vibeguard') || hh.command.includes('hook-post-edit')))
|
|
142
|
+
);
|
|
143
|
+
const afterLen = settings.hooks.PostToolUse ? settings.hooks.PostToolUse.length : 0;
|
|
144
|
+
if (settings.hooks.PostToolUse && settings.hooks.PostToolUse.length === 0) delete settings.hooks.PostToolUse;
|
|
145
|
+
if (settings.hooks && Object.keys(settings.hooks).length === 0) delete settings.hooks;
|
|
146
|
+
|
|
147
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + '\n');
|
|
148
|
+
return { uninstalled: before > afterLen };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
module.exports = { handlePostEdit, installPostEditHook, uninstallPostEditHook };
|