@yagyeshvyas/vibeguard 0.1.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.
Files changed (52) hide show
  1. package/README.md +600 -0
  2. package/bin/cli.js +1640 -0
  3. package/ci/vibeguard.yml +41 -0
  4. package/ci-templates/Jenkinsfile +26 -0
  5. package/ci-templates/azure-pipelines.yml +29 -0
  6. package/ci-templates/circleci.yml +24 -0
  7. package/ci-templates/gitlab.yml +19 -0
  8. package/hooks/pre-commit +31 -0
  9. package/package.json +94 -0
  10. package/src/ai-guard.js +205 -0
  11. package/src/ast.js +319 -0
  12. package/src/audit-trail.js +154 -0
  13. package/src/autofix.js +524 -0
  14. package/src/badge.js +42 -0
  15. package/src/behavior.js +205 -0
  16. package/src/compliance.js +151 -0
  17. package/src/crosstaint.js +324 -0
  18. package/src/cve-intel.js +136 -0
  19. package/src/dashboard.js +279 -0
  20. package/src/deps.js +159 -0
  21. package/src/doctor.js +111 -0
  22. package/src/engine.js +234 -0
  23. package/src/external.js +160 -0
  24. package/src/firewall.js +517 -0
  25. package/src/history.js +87 -0
  26. package/src/hook.js +151 -0
  27. package/src/install.js +248 -0
  28. package/src/interceptor.js +476 -0
  29. package/src/mcp-server.js +1804 -0
  30. package/src/net-audit.js +208 -0
  31. package/src/pii.js +212 -0
  32. package/src/plugin.js +80 -0
  33. package/src/policy-gen.js +288 -0
  34. package/src/pre-deploy.js +282 -0
  35. package/src/presets.js +113 -0
  36. package/src/privacy-audit.js +273 -0
  37. package/src/repl.js +150 -0
  38. package/src/report.js +312 -0
  39. package/src/rules-pack.js +2753 -0
  40. package/src/rules.js +1446 -0
  41. package/src/sandbox.js +139 -0
  42. package/src/scanner.js +651 -0
  43. package/src/secure-prompt.js +140 -0
  44. package/src/slopsquat.js +144 -0
  45. package/src/supply-firewall.js +243 -0
  46. package/src/suppress.js +89 -0
  47. package/src/taint.js +168 -0
  48. package/src/trace.js +220 -0
  49. package/src/urlscan.js +142 -0
  50. package/src/vault.js +145 -0
  51. package/src/verify.js +98 -0
  52. package/src/verifykeys.js +87 -0
package/src/hook.js ADDED
@@ -0,0 +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 };
package/src/install.js ADDED
@@ -0,0 +1,248 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * One-command installer: `vibeguard install`.
5
+ *
6
+ * Detects which AI coding clients are present and wires the VibeGuard MCP server
7
+ * into each. It only WRITES config for clients whose config format/location is
8
+ * known and stable; for anything else it prints a ready-to-paste block so you can
9
+ * add it by hand (we don't write to guessed paths).
10
+ *
11
+ * Default server command is `npx -y @yagyeshvyas/vibeguard mcp` (works once published).
12
+ * Use --local to point at this checkout's absolute mcp-server.js for dev.
13
+ */
14
+
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+
19
+ const HOME = os.homedir();
20
+
21
+ function serverSpec(local) {
22
+ if (local) {
23
+ return { command: process.execPath, args: [path.resolve(__dirname, 'mcp-server.js')] };
24
+ }
25
+ // `npx -y @yagyeshvyas/vibeguard mcp` — resolves the published `vibeguard` package and runs
26
+ // its `mcp` subcommand. (npx -y @yagyeshvyas/vibeguard-mcp would look for a package by that
27
+ // name, which doesn't exist — the mcp bin lives inside the vibeguard package.)
28
+ return { command: 'npx', args: ['-y', 'vibeguard', 'mcp'] };
29
+ }
30
+
31
+ function exists(p) {
32
+ try {
33
+ return fs.existsSync(p);
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ function backup(file) {
40
+ try {
41
+ if (exists(file)) fs.copyFileSync(file, file + '.vibeguard-bak');
42
+ } catch {
43
+ /* best effort */
44
+ }
45
+ }
46
+
47
+ function readJson(file) {
48
+ try {
49
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
50
+ } catch {
51
+ return {};
52
+ }
53
+ }
54
+
55
+ function ensureDir(file) {
56
+ fs.mkdirSync(path.dirname(file), { recursive: true });
57
+ }
58
+
59
+ // Merge a server entry into a JSON config using the given top-level key
60
+ // ("mcpServers" for most, "servers" for VS Code).
61
+ function writeJsonMcp(file, key, spec, name) {
62
+ ensureDir(file);
63
+ backup(file);
64
+ const cfg = readJson(file);
65
+ if (!cfg[key] || typeof cfg[key] !== 'object') cfg[key] = {};
66
+ cfg[key][name] = { command: spec.command, args: spec.args };
67
+ fs.writeFileSync(file, JSON.stringify(cfg, null, 2) + '\n');
68
+ return file;
69
+ }
70
+
71
+ // -------- Per-client handlers ----------------------------------------------
72
+ // Each returns { client, status: 'installed'|'skipped'|'manual'|'error', detail }.
73
+
74
+ function installClaudeCode(spec) {
75
+ // Write the project-scoped .mcp.json (Claude Code's documented config file) in
76
+ // the current directory. No shelling out, no global side effects — this repo
77
+ // gets the server, and we also print the global `claude mcp add` command.
78
+ const file = path.join(process.cwd(), '.mcp.json');
79
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
80
+ return {
81
+ client: 'Claude Code',
82
+ status: 'installed',
83
+ detail: `${file} (project). Global: claude mcp add -s user vibeguard -- ${[spec.command, ...spec.args].join(' ')}`,
84
+ };
85
+ }
86
+
87
+ function installCursor(spec) {
88
+ const dir = path.join(HOME, '.cursor');
89
+ if (!exists(dir)) return { client: 'Cursor', status: 'skipped', detail: 'not detected (~/.cursor missing)' };
90
+ const file = path.join(dir, 'mcp.json');
91
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
92
+ return { client: 'Cursor', status: 'installed', detail: file };
93
+ }
94
+
95
+ function installWindsurf(spec) {
96
+ const dir = path.join(HOME, '.codeium', 'windsurf');
97
+ if (!exists(path.join(HOME, '.codeium')))
98
+ return { client: 'Windsurf', status: 'skipped', detail: 'not detected (~/.codeium missing)' };
99
+ const file = path.join(dir, 'mcp_config.json');
100
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
101
+ return { client: 'Windsurf', status: 'installed', detail: file };
102
+ }
103
+
104
+ function installCodex(spec) {
105
+ const dir = path.join(HOME, '.codex');
106
+ if (!exists(dir)) return { client: 'Codex CLI', status: 'skipped', detail: 'not detected (~/.codex missing)' };
107
+ const file = path.join(dir, 'config.toml');
108
+ let content = '';
109
+ try {
110
+ content = fs.readFileSync(file, 'utf8');
111
+ } catch {
112
+ content = '';
113
+ }
114
+ if (/\[mcp_servers\.vibeguard\]/.test(content)) {
115
+ return { client: 'Codex CLI', status: 'installed', detail: 'already present in ' + file };
116
+ }
117
+ backup(file);
118
+ const argsToml = spec.args.map((a) => JSON.stringify(a)).join(', ');
119
+ const block =
120
+ `\n[mcp_servers.vibeguard]\n` +
121
+ `command = ${JSON.stringify(spec.command)}\n` +
122
+ `args = [${argsToml}]\n`;
123
+ ensureDir(file);
124
+ fs.writeFileSync(file, (content && !content.endsWith('\n') ? content + '\n' : content) + block);
125
+ return { client: 'Codex CLI', status: 'installed', detail: file };
126
+ }
127
+
128
+ function installVSCode(spec) {
129
+ // VS Code (Copilot agent) reads workspace .vscode/mcp.json with a "servers" key.
130
+ const file = path.join(process.cwd(), '.vscode', 'mcp.json');
131
+ // Only write if a .vscode folder exists here (i.e. this is a VS Code project).
132
+ if (!exists(path.join(process.cwd(), '.vscode'))) {
133
+ return { client: 'VS Code', status: 'skipped', detail: 'no ./.vscode in this project' };
134
+ }
135
+ writeJsonMcp(file, 'servers', spec, 'vibeguard');
136
+ return { client: 'VS Code', status: 'installed', detail: file };
137
+ }
138
+
139
+ function installAntigravity(spec) {
140
+ // Google Antigravity uses ~/.antigravity/config.json with mcpServers key
141
+ const dir = path.join(HOME, '.antigravity');
142
+ if (!exists(dir)) return { client: 'Antigravity', status: 'skipped', detail: 'not detected (~/.antigravity missing)' };
143
+ const file = path.join(dir, 'config.json');
144
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
145
+ return { client: 'Antigravity', status: 'installed', detail: file };
146
+ }
147
+
148
+ function installContinue(spec) {
149
+ // Continue.dev uses ~/.continue/config.json with mcpServers key
150
+ const dir = path.join(HOME, '.continue');
151
+ if (!exists(dir)) return { client: 'Continue', status: 'skipped', detail: 'not detected (~/.continue missing)' };
152
+ const file = path.join(dir, 'config.json');
153
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
154
+ return { client: 'Continue', status: 'installed', detail: file };
155
+ }
156
+
157
+ function installCline(spec) {
158
+ // Cline (VS Code extension) uses cline_mcp_settings.json in VS Code user dir
159
+ const dir = path.join(HOME, '.vscode', 'extensions');
160
+ if (!exists(path.join(HOME, '.vscode')) && !exists(path.join(HOME, 'AppData', 'Roaming', 'Code')))
161
+ return { client: 'Cline', status: 'skipped', detail: 'not detected (VS Code not found)' };
162
+ // Cline stores MCP config in the VS Code userData directory
163
+ const userDataDir = process.platform === 'win32'
164
+ ? path.join(HOME, 'AppData', 'Roaming', 'Code', 'User')
165
+ : path.join(HOME, '.vscode', 'User');
166
+ if (!exists(userDataDir)) return { client: 'Cline', status: 'skipped', detail: 'VS Code User dir not found' };
167
+ const file = path.join(userDataDir, 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json');
168
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
169
+ return { client: 'Cline', status: 'installed', detail: file };
170
+ }
171
+
172
+ function installAider(spec) {
173
+ // Aider uses ~/.aider.conf.yml — MCP via command launch
174
+ const file = path.join(HOME, '.aider.conf.yml');
175
+ if (!exists(file)) return { client: 'Aider', status: 'manual', detail: 'add --mcp to your aider launch or ~/.aider.conf.yml' };
176
+ let content = '';
177
+ try { content = fs.readFileSync(file, 'utf8'); } catch {}
178
+ if (/vibeguard/.test(content)) return { client: 'Aider', status: 'installed', detail: 'already present' };
179
+ backup(file);
180
+ const block = `\n# VibeGuard MCP server\nmcp-command: ${spec.command}\nmcp-args: ${spec.args.join(' ')}\n`;
181
+ fs.writeFileSync(file, content + block);
182
+ return { client: 'Aider', status: 'installed', detail: file };
183
+ }
184
+
185
+ function installGeminiCLI(spec) {
186
+ // Google Gemini CLI uses ~/.gemini/config.json with mcpServers key
187
+ const dir = path.join(HOME, '.gemini');
188
+ if (!exists(dir)) return { client: 'Gemini CLI', status: 'skipped', detail: 'not detected (~/.gemini missing)' };
189
+ const file = path.join(dir, 'config.json');
190
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
191
+ return { client: 'Gemini CLI', status: 'installed', detail: file };
192
+ }
193
+
194
+ function installRooCode(spec) {
195
+ // Roo Code (VS Code extension) uses roo_cline_mcp_settings.json
196
+ const userDataDir = process.platform === 'win32'
197
+ ? path.join(HOME, 'AppData', 'Roaming', 'Code', 'User')
198
+ : path.join(HOME, '.vscode', 'User');
199
+ if (!exists(userDataDir)) return { client: 'Roo Code', status: 'skipped', detail: 'VS Code User dir not found' };
200
+ const file = path.join(userDataDir, 'globalStorage', 'rooveterinaryinc.roo-cline', 'settings', 'roo_cline_mcp_settings.json');
201
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
202
+ return { client: 'Roo Code', status: 'installed', detail: file };
203
+ }
204
+
205
+ function installOpenHands(spec) {
206
+ // OpenHands uses ~/.openhands/config.toml similar to Codex
207
+ const dir = path.join(HOME, '.openhands');
208
+ if (!exists(dir)) return { client: 'OpenHands', status: 'skipped', detail: 'not detected (~/.openhands missing)' };
209
+ const file = path.join(dir, 'config.toml');
210
+ let content = '';
211
+ try { content = fs.readFileSync(file, 'utf8'); } catch {}
212
+ if (/\[mcp_servers\.vibeguard\]/.test(content)) return { client: 'OpenHands', status: 'installed', detail: 'already present' };
213
+ backup(file);
214
+ const argsToml = spec.args.map((a) => JSON.stringify(a)).join(', ');
215
+ const block = `\n[mcp_servers.vibeguard]\ncommand = ${JSON.stringify(spec.command)}\nargs = [${argsToml}]\n`;
216
+ ensureDir(file);
217
+ fs.writeFileSync(file, (content && !content.endsWith('\n') ? content + '\n' : content) + block);
218
+ return { client: 'OpenHands', status: 'installed', detail: file };
219
+ }
220
+
221
+ function pasteBlock(spec) {
222
+ return JSON.stringify(
223
+ { mcpServers: { vibeguard: { command: spec.command, args: spec.args } } },
224
+ null,
225
+ 2
226
+ );
227
+ }
228
+
229
+ function install(opts = {}) {
230
+ const spec = serverSpec(opts.local);
231
+ const results = [
232
+ installClaudeCode(spec),
233
+ installCursor(spec),
234
+ installWindsurf(spec),
235
+ installCodex(spec),
236
+ installAntigravity(spec),
237
+ installContinue(spec),
238
+ installCline(spec),
239
+ installAider(spec),
240
+ installGeminiCLI(spec),
241
+ installRooCode(spec),
242
+ installOpenHands(spec),
243
+ installVSCode(spec),
244
+ ];
245
+ return { spec, results, paste: pasteBlock(spec) };
246
+ }
247
+
248
+ module.exports = { install, serverSpec, pasteBlock, writeJsonMcp };