@yagyeshvyas/vibeguard 1.3.0 → 1.11.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 (167) hide show
  1. package/.vibeguard-mcp.example.json +51 -0
  2. package/CHANGELOG.md +604 -216
  3. package/MCP-FIREWALL.md +296 -0
  4. package/README.md +355 -31
  5. package/bin/cli.js +355 -27
  6. package/bin/cmd-agent-monitor.js +45 -0
  7. package/bin/cmd-agent-risk.js +64 -0
  8. package/bin/cmd-gif.js +62 -0
  9. package/bin/cmd-git-scan.js +74 -0
  10. package/bin/cmd-llm-proxy.js +164 -0
  11. package/bin/cmd-mcp-firewall.js +191 -0
  12. package/bin/cmd-pentest.js +103 -0
  13. package/bin/cmd-platform.js +137 -0
  14. package/bin/cmd-pr-scan.js +135 -0
  15. package/bin/cmd-sbom-diff.js +38 -0
  16. package/bin/cmd-skill-scan.js +35 -0
  17. package/docs/AISVS.md +25 -0
  18. package/docs/ARCHITECTURE.md +81 -0
  19. package/docs/INSTALLATION.md +139 -0
  20. package/docs/WINDOWS.md +74 -0
  21. package/docs/security-policy.strict.example.json +134 -0
  22. package/docs/security-policy.strict.example.pub.pem +3 -0
  23. package/package.json +45 -7
  24. package/src/.vibeguard/cache/file-hashes.json +60 -0
  25. package/src/.vibeguard/latest-snapshot.json +36 -0
  26. package/src/.vibeguard/mcp-pins.json +1 -0
  27. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +428 -0
  28. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +344 -0
  29. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +279 -0
  30. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +297 -0
  31. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +151 -0
  32. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +299 -0
  33. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +65 -0
  34. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +2051 -0
  35. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +168 -0
  36. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +362 -0
  37. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +150 -0
  38. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +1611 -0
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +164 -0
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +292 -0
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +144 -0
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +220 -0
  43. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +428 -0
  44. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +344 -0
  45. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +297 -0
  46. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +299 -0
  47. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +37 -0
  48. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +2055 -0
  49. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +168 -0
  50. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +362 -0
  51. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +220 -0
  52. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +428 -0
  53. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +344 -0
  54. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +279 -0
  55. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +297 -0
  56. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +151 -0
  57. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +299 -0
  58. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +65 -0
  59. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +2055 -0
  60. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +168 -0
  61. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +362 -0
  62. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +150 -0
  63. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +1611 -0
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +164 -0
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +292 -0
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +144 -0
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +220 -0
  68. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +428 -0
  69. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +344 -0
  70. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +279 -0
  71. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +297 -0
  72. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +151 -0
  73. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +299 -0
  74. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +65 -0
  75. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +2054 -0
  76. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +168 -0
  77. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +362 -0
  78. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +150 -0
  79. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +1611 -0
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +164 -0
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +292 -0
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +144 -0
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +220 -0
  84. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +428 -0
  85. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +344 -0
  86. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +297 -0
  87. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +299 -0
  88. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +37 -0
  89. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +2055 -0
  90. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +168 -0
  91. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +362 -0
  92. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +220 -0
  93. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +428 -0
  94. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +344 -0
  95. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +297 -0
  96. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +33 -0
  97. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +2055 -0
  98. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +1611 -0
  99. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +292 -0
  100. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +220 -0
  101. package/src/.vibeguard-baseline.json +5226 -0
  102. package/src/action-guard.js +84 -6
  103. package/src/agent-monitor.js +262 -0
  104. package/src/agent-policy.js +642 -0
  105. package/src/agent-risk.js +271 -0
  106. package/src/agentic.js +1513 -0
  107. package/src/ast.js +165 -7
  108. package/src/audit-trail.js +212 -67
  109. package/src/auto.js +427 -427
  110. package/src/autofix.js +11 -4
  111. package/src/bundles.js +198 -0
  112. package/src/daemon.js +343 -343
  113. package/src/dashboard.js +278 -278
  114. package/src/engine.js +3 -0
  115. package/src/entropy.js +187 -0
  116. package/src/firewall.js +19 -3
  117. package/src/gif.js +134 -0
  118. package/src/gitscan.js +282 -0
  119. package/src/hook.js +151 -151
  120. package/src/injection-decode.js +136 -0
  121. package/src/install.js +298 -280
  122. package/src/integrity.js +16 -1
  123. package/src/integrity.json +43 -13
  124. package/src/interceptor.js +12 -9
  125. package/src/llm-proxy.js +986 -0
  126. package/src/mcp-audit.js +61 -5
  127. package/src/mcp-firewall.js +971 -0
  128. package/src/mcp-server.js +2500 -2047
  129. package/src/obfuscation.js +315 -0
  130. package/src/owasp-agentic.js +314 -0
  131. package/src/pentest.js +589 -0
  132. package/src/pii.js +4 -0
  133. package/src/platform/aisvs.js +38 -0
  134. package/src/platform/approval.js +187 -0
  135. package/src/platform/canonical.js +73 -0
  136. package/src/platform/contracts.js +158 -0
  137. package/src/platform/delegation.js +73 -0
  138. package/src/platform/http-gateway.js +177 -0
  139. package/src/platform/identity.js +253 -0
  140. package/src/platform/jwt.js +86 -0
  141. package/src/platform/mcp-http-bridge.js +199 -0
  142. package/src/platform/memory-guard.js +64 -0
  143. package/src/platform/os-sandbox.js +144 -0
  144. package/src/platform/policy.js +332 -0
  145. package/src/platform/sandbox-manager.js +92 -0
  146. package/src/platform/signed-audit.js +357 -0
  147. package/src/platform/ssrf.js +129 -0
  148. package/src/plugin.js +182 -168
  149. package/src/pre-deploy.js +170 -55
  150. package/src/privacy-audit.js +272 -272
  151. package/src/repl.js +150 -150
  152. package/src/report.js +7 -1
  153. package/src/routes.js +1210 -0
  154. package/src/rules-2026.js +1407 -0
  155. package/src/rules-pack.js +3068 -3019
  156. package/src/rules.js +376 -60
  157. package/src/sandbox.js +200 -10
  158. package/src/sbom.js +193 -164
  159. package/src/scanner.js +189 -33
  160. package/src/shell-guard.js +11 -0
  161. package/src/skill-scan.js +477 -0
  162. package/src/slopsquat.js +144 -144
  163. package/src/surface.js +408 -0
  164. package/src/taint-ast.js +204 -37
  165. package/src/taint.js +15 -3
  166. package/src/tokenlean.js +579 -0
  167. package/src/trace.js +220 -220
package/src/install.js CHANGED
@@ -1,280 +1,298 @@
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 installCopilotCLI(spec) {
222
- // GitHub Copilot CLI uses ~/.copilot/config.json with mcpServers key
223
- const dir = path.join(HOME, '.copilot');
224
- if (!exists(dir)) return { client: 'Copilot CLI', status: 'skipped', detail: 'not detected (~/.copilot missing)' };
225
- const file = path.join(dir, 'config.json');
226
- writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
227
- return { client: 'Copilot CLI', status: 'installed', detail: file };
228
- }
229
-
230
- function installAmazonQ(spec) {
231
- // Amazon Q Developer CLI uses ~/.aws/amazonq/config.json
232
- const dir = path.join(HOME, '.aws', 'amazonq');
233
- if (!exists(dir)) return { client: 'Amazon Q', status: 'skipped', detail: 'not detected (~/.aws/amazonq missing)' };
234
- const file = path.join(dir, 'config.json');
235
- writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
236
- return { client: 'Amazon Q', status: 'installed', detail: file };
237
- }
238
-
239
- function installCody(spec) {
240
- // Sourcegraph Cody uses ~/.config/cody/config.json
241
- const dir = process.platform === 'win32'
242
- ? path.join(HOME, 'AppData', 'Roaming', 'Sourcegraph', 'Cody')
243
- : path.join(HOME, '.config', 'cody');
244
- if (!exists(dir)) return { client: 'Sourcegraph Cody', status: 'skipped', detail: 'not detected (cody config dir missing)' };
245
- const file = path.join(dir, 'config.json');
246
- writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
247
- return { client: 'Sourcegraph Cody', status: 'installed', detail: file };
248
- }
249
-
250
- function pasteBlock(spec) {
251
- return JSON.stringify(
252
- { mcpServers: { vibeguard: { command: spec.command, args: spec.args } } },
253
- null,
254
- 2
255
- );
256
- }
257
-
258
- function install(opts = {}) {
259
- const spec = serverSpec(opts.local);
260
- const results = [
261
- installClaudeCode(spec),
262
- installCursor(spec),
263
- installWindsurf(spec),
264
- installCodex(spec),
265
- installAntigravity(spec),
266
- installContinue(spec),
267
- installCline(spec),
268
- installAider(spec),
269
- installGeminiCLI(spec),
270
- installRooCode(spec),
271
- installOpenHands(spec),
272
- installVSCode(spec),
273
- installCopilotCLI(spec),
274
- installAmazonQ(spec),
275
- installCody(spec),
276
- ];
277
- return { spec, results, paste: pasteBlock(spec) };
278
- }
279
-
280
- module.exports = { install, serverSpec, pasteBlock, writeJsonMcp };
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
+ // Pin the package+version: an unpinned `npx -y vibeguard` can resolve an
26
+ // unrelated/older package and makes the MCP config non-reproducible.
27
+ return { command: 'npx', args: ['-y', `@yagyeshvyas/vibeguard@${require('../package.json').version}`, 'mcp'] };
28
+ }
29
+
30
+ function exists(p) {
31
+ try {
32
+ return fs.existsSync(p);
33
+ } catch {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ function backup(file) {
39
+ try {
40
+ if (exists(file)) fs.copyFileSync(file, file + '.vibeguard-bak');
41
+ } catch {
42
+ /* best effort */
43
+ }
44
+ }
45
+
46
+ function readJson(file) {
47
+ try {
48
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
49
+ } catch {
50
+ return {};
51
+ }
52
+ }
53
+
54
+ function ensureDir(file) {
55
+ fs.mkdirSync(path.dirname(file), { recursive: true });
56
+ }
57
+
58
+ // Merge a server entry into a JSON config using the given top-level key
59
+ // ("mcpServers" for most, "servers" for VS Code).
60
+ function writeJsonMcp(file, key, spec, name) {
61
+ ensureDir(file);
62
+ backup(file);
63
+ const cfg = readJson(file);
64
+ if (!cfg[key] || typeof cfg[key] !== 'object') cfg[key] = {};
65
+ cfg[key][name] = { command: spec.command, args: spec.args };
66
+ fs.writeFileSync(file, JSON.stringify(cfg, null, 2) + '\n');
67
+ return file;
68
+ }
69
+
70
+ // -------- Per-client handlers ----------------------------------------------
71
+ // Each returns { client, status: 'installed'|'skipped'|'manual'|'error', detail }.
72
+
73
+ function installClaudeCode(spec) {
74
+ // Write the project-scoped .mcp.json (Claude Code's documented config file) in
75
+ // the current directory. No shelling out, no global side effects — this repo
76
+ // gets the server, and we also print the global `claude mcp add` command.
77
+ const file = path.join(process.cwd(), '.mcp.json');
78
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
79
+ return {
80
+ client: 'Claude Code',
81
+ status: 'installed',
82
+ detail: `${file} (project). Global: claude mcp add -s user vibeguard -- ${[spec.command, ...spec.args].join(' ')}`,
83
+ };
84
+ }
85
+
86
+ function installCursor(spec) {
87
+ const dir = path.join(HOME, '.cursor');
88
+ if (!exists(dir)) return { client: 'Cursor', status: 'skipped', detail: 'not detected (~/.cursor missing)' };
89
+ const file = path.join(dir, 'mcp.json');
90
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
91
+ return { client: 'Cursor', status: 'installed', detail: file };
92
+ }
93
+
94
+ function installWindsurf(spec) {
95
+ const dir = path.join(HOME, '.codeium', 'windsurf');
96
+ if (!exists(path.join(HOME, '.codeium')))
97
+ return { client: 'Windsurf', status: 'skipped', detail: 'not detected (~/.codeium missing)' };
98
+ const file = path.join(dir, 'mcp_config.json');
99
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
100
+ return { client: 'Windsurf', status: 'installed', detail: file };
101
+ }
102
+
103
+ function installCodex(spec) {
104
+ const dir = path.join(HOME, '.codex');
105
+ if (!exists(dir)) return { client: 'Codex CLI', status: 'skipped', detail: 'not detected (~/.codex missing)' };
106
+ const file = path.join(dir, 'config.toml');
107
+ let content = '';
108
+ try {
109
+ content = fs.readFileSync(file, 'utf8');
110
+ } catch {
111
+ content = '';
112
+ }
113
+ if (/\[mcp_servers\.vibeguard\]/.test(content)) {
114
+ return { client: 'Codex CLI', status: 'installed', detail: 'already present in ' + file };
115
+ }
116
+ backup(file);
117
+ const argsToml = spec.args.map((a) => JSON.stringify(a)).join(', ');
118
+ const block =
119
+ `\n[mcp_servers.vibeguard]\n` +
120
+ `command = ${JSON.stringify(spec.command)}\n` +
121
+ `args = [${argsToml}]\n`;
122
+ ensureDir(file);
123
+ fs.writeFileSync(file, (content && !content.endsWith('\n') ? content + '\n' : content) + block);
124
+ return { client: 'Codex CLI', status: 'installed', detail: file };
125
+ }
126
+
127
+ function installVSCode(spec) {
128
+ // VS Code (Copilot agent) reads workspace .vscode/mcp.json with a "servers" key.
129
+ const file = path.join(process.cwd(), '.vscode', 'mcp.json');
130
+ // Only write if a .vscode folder exists here (i.e. this is a VS Code project).
131
+ if (!exists(path.join(process.cwd(), '.vscode'))) {
132
+ return { client: 'VS Code', status: 'skipped', detail: 'no ./.vscode in this project' };
133
+ }
134
+ writeJsonMcp(file, 'servers', spec, 'vibeguard');
135
+ return { client: 'VS Code', status: 'installed', detail: file };
136
+ }
137
+
138
+ function installAntigravity(spec) {
139
+ // Google Antigravity uses ~/.antigravity/config.json with mcpServers key
140
+ const dir = path.join(HOME, '.antigravity');
141
+ if (!exists(dir)) return { client: 'Antigravity', status: 'skipped', detail: 'not detected (~/.antigravity missing)' };
142
+ const file = path.join(dir, 'config.json');
143
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
144
+ return { client: 'Antigravity', status: 'installed', detail: file };
145
+ }
146
+
147
+ function installContinue(spec) {
148
+ // Continue.dev uses ~/.continue/config.json with mcpServers key
149
+ const dir = path.join(HOME, '.continue');
150
+ if (!exists(dir)) return { client: 'Continue', status: 'skipped', detail: 'not detected (~/.continue missing)' };
151
+ const file = path.join(dir, 'config.json');
152
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
153
+ return { client: 'Continue', status: 'installed', detail: file };
154
+ }
155
+
156
+ function installCline(spec) {
157
+ // Cline (VS Code extension) uses cline_mcp_settings.json in VS Code user dir
158
+ const dir = path.join(HOME, '.vscode', 'extensions');
159
+ if (!exists(path.join(HOME, '.vscode')) && !exists(path.join(HOME, 'AppData', 'Roaming', 'Code')))
160
+ return { client: 'Cline', status: 'skipped', detail: 'not detected (VS Code not found)' };
161
+ // Cline stores MCP config in the VS Code userData directory
162
+ const userDataDir = process.platform === 'win32'
163
+ ? path.join(HOME, 'AppData', 'Roaming', 'Code', 'User')
164
+ : path.join(HOME, '.vscode', 'User');
165
+ if (!exists(userDataDir)) return { client: 'Cline', status: 'skipped', detail: 'VS Code User dir not found' };
166
+ const file = path.join(userDataDir, 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json');
167
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
168
+ return { client: 'Cline', status: 'installed', detail: file };
169
+ }
170
+
171
+ function installAider(spec) {
172
+ // Aider uses ~/.aider.conf.yml — MCP via command launch
173
+ const file = path.join(HOME, '.aider.conf.yml');
174
+ if (!exists(file)) return { client: 'Aider', status: 'manual', detail: 'add --mcp to your aider launch or ~/.aider.conf.yml' };
175
+ let content = '';
176
+ try { content = fs.readFileSync(file, 'utf8'); } catch {}
177
+ if (/vibeguard/.test(content)) return { client: 'Aider', status: 'installed', detail: 'already present' };
178
+ backup(file);
179
+ const block = `\n# VibeGuard MCP server\nmcp-command: ${spec.command}\nmcp-args: ${spec.args.join(' ')}\n`;
180
+ fs.writeFileSync(file, content + block);
181
+ return { client: 'Aider', status: 'installed', detail: file };
182
+ }
183
+
184
+ function installGeminiCLI(spec) {
185
+ // Google Gemini CLI uses ~/.gemini/config.json with mcpServers key
186
+ const dir = path.join(HOME, '.gemini');
187
+ if (!exists(dir)) return { client: 'Gemini CLI', status: 'skipped', detail: 'not detected (~/.gemini missing)' };
188
+ const file = path.join(dir, 'config.json');
189
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
190
+ return { client: 'Gemini CLI', status: 'installed', detail: file };
191
+ }
192
+
193
+ function installRooCode(spec) {
194
+ // Roo Code (VS Code extension) uses roo_cline_mcp_settings.json
195
+ const userDataDir = process.platform === 'win32'
196
+ ? path.join(HOME, 'AppData', 'Roaming', 'Code', 'User')
197
+ : path.join(HOME, '.vscode', 'User');
198
+ if (!exists(userDataDir)) return { client: 'Roo Code', status: 'skipped', detail: 'VS Code User dir not found' };
199
+ const file = path.join(userDataDir, 'globalStorage', 'rooveterinaryinc.roo-cline', 'settings', 'roo_cline_mcp_settings.json');
200
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
201
+ return { client: 'Roo Code', status: 'installed', detail: file };
202
+ }
203
+
204
+ function installOpenHands(spec) {
205
+ // OpenHands uses ~/.openhands/config.toml similar to Codex
206
+ const dir = path.join(HOME, '.openhands');
207
+ if (!exists(dir)) return { client: 'OpenHands', status: 'skipped', detail: 'not detected (~/.openhands missing)' };
208
+ const file = path.join(dir, 'config.toml');
209
+ let content = '';
210
+ try { content = fs.readFileSync(file, 'utf8'); } catch {}
211
+ if (/\[mcp_servers\.vibeguard\]/.test(content)) return { client: 'OpenHands', status: 'installed', detail: 'already present' };
212
+ backup(file);
213
+ const argsToml = spec.args.map((a) => JSON.stringify(a)).join(', ');
214
+ const block = `\n[mcp_servers.vibeguard]\ncommand = ${JSON.stringify(spec.command)}\nargs = [${argsToml}]\n`;
215
+ ensureDir(file);
216
+ fs.writeFileSync(file, (content && !content.endsWith('\n') ? content + '\n' : content) + block);
217
+ return { client: 'OpenHands', status: 'installed', detail: file };
218
+ }
219
+
220
+ function installCopilotCLI(spec) {
221
+ // GitHub Copilot CLI uses ~/.copilot/config.json with mcpServers key
222
+ const dir = path.join(HOME, '.copilot');
223
+ if (!exists(dir)) return { client: 'Copilot CLI', status: 'skipped', detail: 'not detected (~/.copilot missing)' };
224
+ const file = path.join(dir, 'config.json');
225
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
226
+ return { client: 'Copilot CLI', status: 'installed', detail: file };
227
+ }
228
+
229
+ function installAmazonQ(spec) {
230
+ // Amazon Q Developer CLI uses ~/.aws/amazonq/config.json
231
+ const dir = path.join(HOME, '.aws', 'amazonq');
232
+ if (!exists(dir)) return { client: 'Amazon Q', status: 'skipped', detail: 'not detected (~/.aws/amazonq missing)' };
233
+ const file = path.join(dir, 'config.json');
234
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
235
+ return { client: 'Amazon Q', status: 'installed', detail: file };
236
+ }
237
+
238
+ function installCody(spec) {
239
+ // Sourcegraph Cody uses ~/.config/cody/config.json
240
+ const dir = process.platform === 'win32'
241
+ ? path.join(HOME, 'AppData', 'Roaming', 'Sourcegraph', 'Cody')
242
+ : path.join(HOME, '.config', 'cody');
243
+ if (!exists(dir)) return { client: 'Sourcegraph Cody', status: 'skipped', detail: 'not detected (cody config dir missing)' };
244
+ const file = path.join(dir, 'config.json');
245
+ writeJsonMcp(file, 'mcpServers', spec, 'vibeguard');
246
+ return { client: 'Sourcegraph Cody', status: 'installed', detail: file };
247
+ }
248
+
249
+ function installHermes(spec) {
250
+ // Hermes Agent (Nous Research) reads MCP servers from $HERMES_HOME/config.yaml
251
+ // (default ~/.hermes/config.yaml) under `mcp_servers:`. We never hand-edit the
252
+ // YAML (a bad write can break the live gateway); we detect it and emit the
253
+ // exact, safe commands using Hermes' own config CLI instead.
254
+ const hermesHome = process.env.HERMES_HOME || path.join(HOME, '.hermes');
255
+ const cfg = path.join(hermesHome, 'config.yaml');
256
+ if (!exists(cfg)) {
257
+ return { client: 'Hermes Agent', status: 'skipped', detail: `not detected (${cfg} missing)` };
258
+ }
259
+ const argsStr = spec.args.map((a) => JSON.stringify(a)).join(', ');
260
+ return {
261
+ client: 'Hermes Agent',
262
+ status: 'instructions',
263
+ detail: `${cfg} — add under \`mcp_servers:\`, or run:\n hermes config set mcp_servers.vibeguard.command ${spec.command}\n hermes config set mcp_servers.vibeguard.args '[${argsStr}]'\n hermes config set mcp_servers.vibeguard.timeout 120`,
264
+ };
265
+ }
266
+
267
+ function pasteBlock(spec) {
268
+ return JSON.stringify(
269
+ { mcpServers: { vibeguard: { command: spec.command, args: spec.args } } },
270
+ null,
271
+ 2
272
+ );
273
+ }
274
+
275
+ function install(opts = {}) {
276
+ const spec = serverSpec(opts.local);
277
+ const results = [
278
+ installClaudeCode(spec),
279
+ installCursor(spec),
280
+ installWindsurf(spec),
281
+ installCodex(spec),
282
+ installAntigravity(spec),
283
+ installContinue(spec),
284
+ installCline(spec),
285
+ installAider(spec),
286
+ installGeminiCLI(spec),
287
+ installRooCode(spec),
288
+ installOpenHands(spec),
289
+ installVSCode(spec),
290
+ installCopilotCLI(spec),
291
+ installAmazonQ(spec),
292
+ installCody(spec),
293
+ installHermes(spec),
294
+ ];
295
+ return { spec, results, paste: pasteBlock(spec) };
296
+ }
297
+
298
+ module.exports = { install, serverSpec, pasteBlock, writeJsonMcp };