@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +34 -17
  3. package/bin/cli.js +2753 -2753
  4. package/bin/cmd-mcp-firewall.js +1 -0
  5. package/bin/cmd-platform.js +3 -0
  6. package/ci/vibeguard.yml +42 -42
  7. package/package.json +2 -2
  8. package/scripts/counts.js +93 -93
  9. package/scripts/postinstall.js +26 -26
  10. package/src/auto.js +427 -427
  11. package/src/daemon.js +343 -343
  12. package/src/dashboard.js +278 -278
  13. package/src/engine.js +297 -297
  14. package/src/hook.js +151 -151
  15. package/src/install.js +298 -298
  16. package/src/integrity.js +1 -0
  17. package/src/integrity.json +9 -6
  18. package/src/mcp-firewall.js +11 -0
  19. package/src/platform/approval-service.js +124 -0
  20. package/src/platform/approval.js +16 -0
  21. package/src/platform/oauth-server.js +89 -0
  22. package/src/platform/os-sandbox.js +52 -1
  23. package/src/platform/runtime-monitor.js +69 -0
  24. package/src/platform/sandbox-manager.js +5 -0
  25. package/src/plugin.js +182 -182
  26. package/src/privacy-audit.js +272 -272
  27. package/src/repl.js +150 -150
  28. package/src/report.js +331 -331
  29. package/src/rules-pack.js +3068 -3068
  30. package/src/rules.js +1822 -1822
  31. package/src/sbom.js +193 -193
  32. package/src/scanner.js +1032 -1032
  33. package/src/shell-guard.js +302 -302
  34. package/src/slopsquat.js +144 -144
  35. package/src/trace.js +220 -220
  36. package/src/.vibeguard/cache/file-hashes.json +0 -60
  37. package/src/.vibeguard/latest-snapshot.json +0 -36
  38. package/src/.vibeguard/mcp-pins.json +0 -1
  39. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/auto.js +0 -428
  40. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/daemon.js +0 -344
  41. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/dashboard.js +0 -279
  42. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/engine.js +0 -297
  43. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/hook.js +0 -151
  44. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/install.js +0 -299
  45. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/manifest.json +0 -65
  46. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/mcp-server.js +0 -2051
  47. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/plugin.js +0 -168
  48. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/pre-deploy.js +0 -362
  49. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/repl.js +0 -150
  50. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/rules.js +0 -1611
  51. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/sbom.js +0 -164
  52. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/shell-guard.js +0 -292
  53. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/slopsquat.js +0 -144
  54. package/src/.vibeguard/snapshots/2026-08-05T16-23-50-635Z/trace.js +0 -220
  55. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/auto.js +0 -428
  56. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/daemon.js +0 -344
  57. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/engine.js +0 -297
  58. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/install.js +0 -299
  59. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/manifest.json +0 -37
  60. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/mcp-server.js +0 -2055
  61. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/plugin.js +0 -168
  62. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/pre-deploy.js +0 -362
  63. package/src/.vibeguard/snapshots/2026-08-05T16-26-26-074Z/trace.js +0 -220
  64. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/auto.js +0 -428
  65. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/daemon.js +0 -344
  66. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/dashboard.js +0 -279
  67. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/engine.js +0 -297
  68. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/hook.js +0 -151
  69. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/install.js +0 -299
  70. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/manifest.json +0 -65
  71. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/mcp-server.js +0 -2055
  72. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/plugin.js +0 -168
  73. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/pre-deploy.js +0 -362
  74. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/repl.js +0 -150
  75. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/rules.js +0 -1611
  76. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/sbom.js +0 -164
  77. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/shell-guard.js +0 -292
  78. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/slopsquat.js +0 -144
  79. package/src/.vibeguard/snapshots/2026-08-05T16-35-06-272Z/trace.js +0 -220
  80. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/auto.js +0 -428
  81. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/daemon.js +0 -344
  82. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/dashboard.js +0 -279
  83. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/engine.js +0 -297
  84. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/hook.js +0 -151
  85. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/install.js +0 -299
  86. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/manifest.json +0 -65
  87. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/mcp-server.js +0 -2054
  88. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/plugin.js +0 -168
  89. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/pre-deploy.js +0 -362
  90. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/repl.js +0 -150
  91. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/rules.js +0 -1611
  92. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/sbom.js +0 -164
  93. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/shell-guard.js +0 -292
  94. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/slopsquat.js +0 -144
  95. package/src/.vibeguard/snapshots/2026-08-05T18-08-40-613Z/trace.js +0 -220
  96. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/auto.js +0 -428
  97. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/daemon.js +0 -344
  98. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/engine.js +0 -297
  99. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/install.js +0 -299
  100. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/manifest.json +0 -37
  101. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/mcp-server.js +0 -2055
  102. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/plugin.js +0 -168
  103. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/pre-deploy.js +0 -362
  104. package/src/.vibeguard/snapshots/2026-08-05T18-11-32-644Z/trace.js +0 -220
  105. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/auto.js +0 -428
  106. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/daemon.js +0 -344
  107. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/engine.js +0 -297
  108. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/manifest.json +0 -33
  109. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/mcp-server.js +0 -2055
  110. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/rules.js +0 -1611
  111. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/shell-guard.js +0 -292
  112. package/src/.vibeguard/snapshots/2026-08-05T18-16-47-635Z/trace.js +0 -220
  113. package/src/.vibeguard-baseline.json +0 -5226
package/src/report.js CHANGED
@@ -1,331 +1,331 @@
1
- 'use strict';
2
-
3
- /*
4
- * Rendering: human report (colored), JSON, SARIF, and the copy-paste fix prompt.
5
- * No dependencies — colors are raw ANSI, disabled when not a TTY or NO_COLOR set.
6
- */
7
-
8
- const path = require('path');
9
-
10
- const useColor =
11
- process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== 'dumb';
12
-
13
- const C = {
14
- reset: useColor ? '\x1b[0m' : '',
15
- bold: useColor ? '\x1b[1m' : '',
16
- dim: useColor ? '\x1b[2m' : '',
17
- red: useColor ? '\x1b[31m' : '',
18
- green: useColor ? '\x1b[32m' : '',
19
- yellow: useColor ? '\x1b[33m' : '',
20
- blue: useColor ? '\x1b[34m' : '',
21
- magenta: useColor ? '\x1b[35m' : '',
22
- cyan: useColor ? '\x1b[36m' : '',
23
- gray: useColor ? '\x1b[90m' : '',
24
- };
25
-
26
- const SEV_STYLE = {
27
- critical: { color: C.red, label: 'CRITICAL' },
28
- high: { color: C.magenta, label: 'HIGH' },
29
- medium: { color: C.yellow, label: 'MEDIUM' },
30
- low: { color: C.blue, label: 'LOW' },
31
- };
32
-
33
- const GRADE_COLOR = {
34
- A: C.green, B: C.green, C: C.yellow, D: C.yellow, F: C.red,
35
- };
36
-
37
- function severityBadge(sev) {
38
- const s = SEV_STYLE[sev] || { color: C.gray, label: sev.toUpperCase() };
39
- return `${s.color}${C.bold}${s.label.padEnd(8)}${C.reset}`;
40
- }
41
-
42
- // -------- Human report -----------------------------------------------------
43
-
44
- function renderHuman(result) {
45
- const lines = [];
46
- lines.push('');
47
- lines.push(`${C.bold}${C.cyan}VibeGuard${C.reset} ${C.dim}security scan${C.reset}`);
48
- lines.push(`${C.dim}${result.root}${C.reset}`);
49
- lines.push('');
50
-
51
- if (result.findings.length === 0) {
52
- lines.push(`${C.green}${C.bold}No issues found across ${result.scannedFiles} files.${C.reset}`);
53
- } else {
54
- for (const f of result.findings) {
55
- const loc = `${f.file}:${f.line}:${f.column}`;
56
- const conf =
57
- f.confidence === 'low'
58
- ? ` ${C.yellow}⚑ review${C.reset}`
59
- : f.confidence === 'medium'
60
- ? ` ${C.dim}⚑ likely${C.reset}`
61
- : '';
62
- lines.push(
63
- `${severityBadge(f.severity)} ${C.bold}${loc}${C.reset}${conf} ${C.dim}[${f.ruleId}]${C.reset}`
64
- );
65
- lines.push(` ${f.message}`);
66
- if (f.snippet) lines.push(` ${C.gray}${f.snippet}${C.reset}`);
67
- lines.push(` ${C.green}fix:${C.reset} ${f.fix}`);
68
- lines.push('');
69
- }
70
- }
71
-
72
- lines.push(renderSummaryLine(result));
73
- lines.push('');
74
- // Baseline suppression notice
75
- if (result.baselineSuppressed && result.baselineSuppressed > 0) {
76
- lines.push(`${C.dim}${result.baselineSuppressed} known finding${result.baselineSuppressed === 1 ? '' : 's'} suppressed (baseline). Run with --all to see.${C.reset}`);
77
- }
78
- // Fix hint: show how many issues are auto-fixable
79
- if (result.findings.length > 0) {
80
- const fixable = result.findings.filter(f => f.fix && f.ruleId).length;
81
- if (fixable > 0) {
82
- lines.push(`${C.dim}Run ${C.bold}vibeguard fix${C.reset}${C.dim} to auto-fix ${fixable} issue${fixable === 1 ? '' : 's'}${C.reset}`);
83
- }
84
- }
85
- lines.push(
86
- `${C.dim}VibeGuard checks high-frequency, well-defined issues (secrets, injection, misconfig).`
87
- );
88
- lines.push(
89
- `It does not prove an app is safe and cannot catch every logic bug or backdoor.${C.reset}`
90
- );
91
- lines.push('');
92
- return lines.join('\n');
93
- }
94
-
95
- function renderSummaryLine(result) {
96
- const { counts, grade } = result;
97
- const gc = GRADE_COLOR[grade] || C.gray;
98
- const parts = [
99
- `${C.red}${counts.critical} critical${C.reset}`,
100
- `${C.magenta}${counts.high} high${C.reset}`,
101
- `${C.yellow}${counts.medium} medium${C.reset}`,
102
- `${C.blue}${counts.low} low${C.reset}`,
103
- ];
104
- return (
105
- `${C.bold}Grade ${gc}${grade}${C.reset} ` +
106
- `${C.dim}(${result.scannedFiles} files)${C.reset} ` +
107
- parts.join(' ')
108
- );
109
- }
110
-
111
- // -------- JSON -------------------------------------------------------------
112
-
113
- function renderJson(result) {
114
- return JSON.stringify(
115
- {
116
- tool: 'vibeguard',
117
- version: require('../package.json').version,
118
- root: result.root,
119
- generatedAt: result.generatedAt,
120
- grade: result.grade,
121
- counts: result.counts,
122
- scannedFiles: result.scannedFiles,
123
- engine: result.engine || null,
124
- diagnostics: result.diagnostics || null,
125
- depsInfo: result.depsInfo || null,
126
- externalInfo: result.externalInfo || null,
127
- findings: result.findings,
128
- },
129
- null,
130
- 2
131
- );
132
- }
133
-
134
- // -------- SARIF 2.1.0 ------------------------------------------------------
135
-
136
- const SARIF_LEVEL = {
137
- critical: 'error',
138
- high: 'error',
139
- medium: 'warning',
140
- low: 'note',
141
- };
142
-
143
- function renderSarif(result) {
144
- const ruleIndex = new Map();
145
- const rules = [];
146
- for (const f of result.findings) {
147
- if (!ruleIndex.has(f.ruleId)) {
148
- ruleIndex.set(f.ruleId, rules.length);
149
- rules.push({
150
- id: f.ruleId,
151
- name: f.title || f.ruleId,
152
- shortDescription: { text: f.title || f.ruleId },
153
- fullDescription: { text: f.message },
154
- helpUri: 'https://github.com/vibeguard/vibeguard#rules',
155
- properties: {
156
- security_severity: f.severity,
157
- tags: [
158
- f.cwe ? f.cwe : null,
159
- f.owasp ? f.owasp : null,
160
- f.confidence ? 'confidence:' + f.confidence : null,
161
- ].filter(Boolean),
162
- },
163
- defaultConfiguration: { level: SARIF_LEVEL[f.severity] || 'warning' },
164
- });
165
- }
166
- }
167
-
168
- const results = result.findings.map((f) => ({
169
- ruleId: f.ruleId,
170
- ruleIndex: ruleIndex.get(f.ruleId),
171
- level: SARIF_LEVEL[f.severity] || 'warning',
172
- properties: {
173
- severity: f.severity,
174
- confidence: f.confidence,
175
- // Reachability lets code-scanning dashboards triage without re-running
176
- // the scanner: 'dead' means no entrypoint imports the file.
177
- ...(f.surface && f.surface.reach ? { reach: f.surface.reach } : {}),
178
- },
179
- partialFingerprints: f.fingerprint ? { vibeguard: f.fingerprint } : undefined,
180
- message: { text: `${f.message} Fix: ${f.fix}` },
181
- locations: [
182
- {
183
- physicalLocation: {
184
- artifactLocation: { uri: f.file },
185
- region: { startLine: f.line, startColumn: f.column },
186
- },
187
- },
188
- ],
189
- }));
190
-
191
- return JSON.stringify(
192
- {
193
- $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
194
- version: '2.1.0',
195
- runs: [
196
- {
197
- tool: {
198
- driver: {
199
- name: 'VibeGuard',
200
- informationUri: 'https://github.com/vibeguard/vibeguard',
201
- version: require('../package.json').version,
202
- rules,
203
- },
204
- },
205
- results,
206
- },
207
- ],
208
- },
209
- null,
210
- 2
211
- );
212
- }
213
-
214
- // -------- Fix prompt (paste back into your AI tool) ------------------------
215
-
216
- function renderFixPrompt(result) {
217
- if (result.findings.length === 0) {
218
- return 'VibeGuard found no issues — nothing to fix.';
219
- }
220
- const lines = [];
221
- lines.push(
222
- 'You are fixing security issues found by VibeGuard. Apply the minimal, safe change for each item below. Do not change unrelated code. For any leaked secret, also tell me to rotate it.'
223
- );
224
- lines.push('');
225
- lines.push(`Overall grade: ${result.grade}.`);
226
- lines.push('');
227
-
228
- const actNow = result.findings.filter((f) => f.confidence !== 'low');
229
- const review = result.findings.filter((f) => f.confidence === 'low');
230
-
231
- let n = 1;
232
- if (actNow.length) {
233
- lines.push('APPLY THESE FIXES (high/medium confidence):');
234
- for (const f of actNow) {
235
- lines.push(`${n}. [${f.severity.toUpperCase()}] ${f.file}:${f.line} — ${f.message}`);
236
- lines.push(` Fix: ${f.fix}`);
237
- n++;
238
- }
239
- lines.push('');
240
- }
241
- if (review.length) {
242
- lines.push(
243
- 'REVIEW THESE — heuristic hints, verify before changing (do NOT blindly rewrite):'
244
- );
245
- for (const f of review) {
246
- lines.push(`${n}. [${f.severity.toUpperCase()}, review] ${f.file}:${f.line} — ${f.message}`);
247
- lines.push(` Suggested: ${f.fix}`);
248
- n++;
249
- }
250
- lines.push('');
251
- }
252
- lines.push(
253
- 'After applying fixes, I will re-run `vibeguard verify` to confirm each issue is resolved.'
254
- );
255
- return lines.join('\n');
256
- }
257
-
258
- function renderHtml(result) {
259
- const c = result.counts;
260
- const findings = result.findings || [];
261
- const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
262
- for (const f of findings) bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
263
-
264
- const gradeColor = { A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444' };
265
- const sevColor = { critical: '#ef4444', high: '#f97316', medium: '#eab308', low: '#3b82f6' };
266
-
267
- const rows = findings.map(f => ` <tr>
268
- <td><span class="sev sev-${f.severity}">${f.severity}</span></td>
269
- <td><code>${esc(f.ruleId)}</code></td>
270
- <td><code>${esc(f.file)}:${f.line}</code></td>
271
- <td>${esc(f.message || '')}</td>
272
- <td>${esc(f.fix || '')}</td>
273
- </tr>`).join('\n');
274
-
275
- return `<!DOCTYPE html>
276
- <html lang="en">
277
- <head>
278
- <meta charset="utf-8">
279
- <meta name="viewport" content="width=device-width, initial-scale=1">
280
- <title>VibeGuard Security Report</title>
281
- <style>
282
- body { font-family: -apple-system, system-ui, sans-serif; max-width: 1100px; margin: 0 auto; padding: 20px; color: #1a1a1a; }
283
- .grade { font-size: 72px; font-weight: 800; text-align: center; padding: 20px; border-radius: 12px; color: white; width: 120px; height: 120px; line-height: 120px; margin: 0 auto; }
284
- .summary { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }
285
- .stat { text-align: center; padding: 12px 24px; border-radius: 8px; background: #f3f4f6; }
286
- .stat .num { font-size: 28px; font-weight: 700; }
287
- .stat .label { font-size: 12px; color: #6b7280; text-transform: uppercase; }
288
- table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 13px; }
289
- th { text-align: left; padding: 8px 12px; background: #f9fafb; border-bottom: 2px solid #e5e7eb; }
290
- td { padding: 8px 12px; border-bottom: 1px solid #f3f4f6; }
291
- .sev { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; color: white; }
292
- .sev-critical { background: #ef4444; }
293
- .sev-high { background: #f97316; }
294
- .sev-medium { background: #eab308; }
295
- .sev-low { background: #3b82f6; }
296
- code { background: #f3f4f6; padding: 2px 4px; border-radius: 3px; font-size: 12px; }
297
- h1 { text-align: center; }
298
- .meta { text-align: center; color: #6b7280; font-size: 13px; margin-bottom: 20px; }
299
- </style>
300
- </head>
301
- <body>
302
- <h1>VibeGuard Security Report</h1>
303
- <div class="meta">${esc(result.root || '')} — ${result.scannedFiles} files scanned — ${result.generatedAt || new Date().toISOString()}</div>
304
- <div class="grade" style="background:${gradeColor[result.grade] || '#6b7280'}">${result.grade}</div>
305
- <div class="summary">
306
- <div class="stat"><div class="num" style="color:#ef4444">${bySeverity.critical}</div><div class="label">Critical</div></div>
307
- <div class="stat"><div class="num" style="color:#f97316">${bySeverity.high}</div><div class="label">High</div></div>
308
- <div class="stat"><div class="num" style="color:#eab308">${bySeverity.medium}</div><div class="label">Medium</div></div>
309
- <div class="stat"><div class="num" style="color:#3b82f6">${bySeverity.low}</div><div class="label">Low</div></div>
310
- </div>
311
- ${findings.length > 0 ? `<table>
312
- <thead><tr><th>Severity</th><th>Rule</th><th>Location</th><th>Message</th><th>Fix</th></tr></thead>
313
- <tbody>
314
- ${rows}
315
- </tbody>
316
- </table>` : '<p style="text-align:center;color:#22c55e;font-size:18px;">No findings. Clean!</p>'}
317
- </body>
318
- </html>`;
319
- }
320
-
321
- function esc(s) { return String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); }
322
-
323
- module.exports = {
324
- renderHuman,
325
- renderJson,
326
- renderSarif,
327
- renderHtml,
328
- renderFixPrompt,
329
- renderSummaryLine,
330
- C,
331
- };
1
+ 'use strict';
2
+
3
+ /*
4
+ * Rendering: human report (colored), JSON, SARIF, and the copy-paste fix prompt.
5
+ * No dependencies — colors are raw ANSI, disabled when not a TTY or NO_COLOR set.
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ const useColor =
11
+ process.stdout.isTTY && !process.env.NO_COLOR && process.env.TERM !== 'dumb';
12
+
13
+ const C = {
14
+ reset: useColor ? '\x1b[0m' : '',
15
+ bold: useColor ? '\x1b[1m' : '',
16
+ dim: useColor ? '\x1b[2m' : '',
17
+ red: useColor ? '\x1b[31m' : '',
18
+ green: useColor ? '\x1b[32m' : '',
19
+ yellow: useColor ? '\x1b[33m' : '',
20
+ blue: useColor ? '\x1b[34m' : '',
21
+ magenta: useColor ? '\x1b[35m' : '',
22
+ cyan: useColor ? '\x1b[36m' : '',
23
+ gray: useColor ? '\x1b[90m' : '',
24
+ };
25
+
26
+ const SEV_STYLE = {
27
+ critical: { color: C.red, label: 'CRITICAL' },
28
+ high: { color: C.magenta, label: 'HIGH' },
29
+ medium: { color: C.yellow, label: 'MEDIUM' },
30
+ low: { color: C.blue, label: 'LOW' },
31
+ };
32
+
33
+ const GRADE_COLOR = {
34
+ A: C.green, B: C.green, C: C.yellow, D: C.yellow, F: C.red,
35
+ };
36
+
37
+ function severityBadge(sev) {
38
+ const s = SEV_STYLE[sev] || { color: C.gray, label: sev.toUpperCase() };
39
+ return `${s.color}${C.bold}${s.label.padEnd(8)}${C.reset}`;
40
+ }
41
+
42
+ // -------- Human report -----------------------------------------------------
43
+
44
+ function renderHuman(result) {
45
+ const lines = [];
46
+ lines.push('');
47
+ lines.push(`${C.bold}${C.cyan}VibeGuard${C.reset} ${C.dim}security scan${C.reset}`);
48
+ lines.push(`${C.dim}${result.root}${C.reset}`);
49
+ lines.push('');
50
+
51
+ if (result.findings.length === 0) {
52
+ lines.push(`${C.green}${C.bold}No issues found across ${result.scannedFiles} files.${C.reset}`);
53
+ } else {
54
+ for (const f of result.findings) {
55
+ const loc = `${f.file}:${f.line}:${f.column}`;
56
+ const conf =
57
+ f.confidence === 'low'
58
+ ? ` ${C.yellow}⚑ review${C.reset}`
59
+ : f.confidence === 'medium'
60
+ ? ` ${C.dim}⚑ likely${C.reset}`
61
+ : '';
62
+ lines.push(
63
+ `${severityBadge(f.severity)} ${C.bold}${loc}${C.reset}${conf} ${C.dim}[${f.ruleId}]${C.reset}`
64
+ );
65
+ lines.push(` ${f.message}`);
66
+ if (f.snippet) lines.push(` ${C.gray}${f.snippet}${C.reset}`);
67
+ lines.push(` ${C.green}fix:${C.reset} ${f.fix}`);
68
+ lines.push('');
69
+ }
70
+ }
71
+
72
+ lines.push(renderSummaryLine(result));
73
+ lines.push('');
74
+ // Baseline suppression notice
75
+ if (result.baselineSuppressed && result.baselineSuppressed > 0) {
76
+ lines.push(`${C.dim}${result.baselineSuppressed} known finding${result.baselineSuppressed === 1 ? '' : 's'} suppressed (baseline). Run with --all to see.${C.reset}`);
77
+ }
78
+ // Fix hint: show how many issues are auto-fixable
79
+ if (result.findings.length > 0) {
80
+ const fixable = result.findings.filter(f => f.fix && f.ruleId).length;
81
+ if (fixable > 0) {
82
+ lines.push(`${C.dim}Run ${C.bold}vibeguard fix${C.reset}${C.dim} to auto-fix ${fixable} issue${fixable === 1 ? '' : 's'}${C.reset}`);
83
+ }
84
+ }
85
+ lines.push(
86
+ `${C.dim}VibeGuard checks high-frequency, well-defined issues (secrets, injection, misconfig).`
87
+ );
88
+ lines.push(
89
+ `It does not prove an app is safe and cannot catch every logic bug or backdoor.${C.reset}`
90
+ );
91
+ lines.push('');
92
+ return lines.join('\n');
93
+ }
94
+
95
+ function renderSummaryLine(result) {
96
+ const { counts, grade } = result;
97
+ const gc = GRADE_COLOR[grade] || C.gray;
98
+ const parts = [
99
+ `${C.red}${counts.critical} critical${C.reset}`,
100
+ `${C.magenta}${counts.high} high${C.reset}`,
101
+ `${C.yellow}${counts.medium} medium${C.reset}`,
102
+ `${C.blue}${counts.low} low${C.reset}`,
103
+ ];
104
+ return (
105
+ `${C.bold}Grade ${gc}${grade}${C.reset} ` +
106
+ `${C.dim}(${result.scannedFiles} files)${C.reset} ` +
107
+ parts.join(' ')
108
+ );
109
+ }
110
+
111
+ // -------- JSON -------------------------------------------------------------
112
+
113
+ function renderJson(result) {
114
+ return JSON.stringify(
115
+ {
116
+ tool: 'vibeguard',
117
+ version: require('../package.json').version,
118
+ root: result.root,
119
+ generatedAt: result.generatedAt,
120
+ grade: result.grade,
121
+ counts: result.counts,
122
+ scannedFiles: result.scannedFiles,
123
+ engine: result.engine || null,
124
+ diagnostics: result.diagnostics || null,
125
+ depsInfo: result.depsInfo || null,
126
+ externalInfo: result.externalInfo || null,
127
+ findings: result.findings,
128
+ },
129
+ null,
130
+ 2
131
+ );
132
+ }
133
+
134
+ // -------- SARIF 2.1.0 ------------------------------------------------------
135
+
136
+ const SARIF_LEVEL = {
137
+ critical: 'error',
138
+ high: 'error',
139
+ medium: 'warning',
140
+ low: 'note',
141
+ };
142
+
143
+ function renderSarif(result) {
144
+ const ruleIndex = new Map();
145
+ const rules = [];
146
+ for (const f of result.findings) {
147
+ if (!ruleIndex.has(f.ruleId)) {
148
+ ruleIndex.set(f.ruleId, rules.length);
149
+ rules.push({
150
+ id: f.ruleId,
151
+ name: f.title || f.ruleId,
152
+ shortDescription: { text: f.title || f.ruleId },
153
+ fullDescription: { text: f.message },
154
+ helpUri: 'https://github.com/vibeguard/vibeguard#rules',
155
+ properties: {
156
+ security_severity: f.severity,
157
+ tags: [
158
+ f.cwe ? f.cwe : null,
159
+ f.owasp ? f.owasp : null,
160
+ f.confidence ? 'confidence:' + f.confidence : null,
161
+ ].filter(Boolean),
162
+ },
163
+ defaultConfiguration: { level: SARIF_LEVEL[f.severity] || 'warning' },
164
+ });
165
+ }
166
+ }
167
+
168
+ const results = result.findings.map((f) => ({
169
+ ruleId: f.ruleId,
170
+ ruleIndex: ruleIndex.get(f.ruleId),
171
+ level: SARIF_LEVEL[f.severity] || 'warning',
172
+ properties: {
173
+ severity: f.severity,
174
+ confidence: f.confidence,
175
+ // Reachability lets code-scanning dashboards triage without re-running
176
+ // the scanner: 'dead' means no entrypoint imports the file.
177
+ ...(f.surface && f.surface.reach ? { reach: f.surface.reach } : {}),
178
+ },
179
+ partialFingerprints: f.fingerprint ? { vibeguard: f.fingerprint } : undefined,
180
+ message: { text: `${f.message} Fix: ${f.fix}` },
181
+ locations: [
182
+ {
183
+ physicalLocation: {
184
+ artifactLocation: { uri: f.file },
185
+ region: { startLine: f.line, startColumn: f.column },
186
+ },
187
+ },
188
+ ],
189
+ }));
190
+
191
+ return JSON.stringify(
192
+ {
193
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
194
+ version: '2.1.0',
195
+ runs: [
196
+ {
197
+ tool: {
198
+ driver: {
199
+ name: 'VibeGuard',
200
+ informationUri: 'https://github.com/vibeguard/vibeguard',
201
+ version: require('../package.json').version,
202
+ rules,
203
+ },
204
+ },
205
+ results,
206
+ },
207
+ ],
208
+ },
209
+ null,
210
+ 2
211
+ );
212
+ }
213
+
214
+ // -------- Fix prompt (paste back into your AI tool) ------------------------
215
+
216
+ function renderFixPrompt(result) {
217
+ if (result.findings.length === 0) {
218
+ return 'VibeGuard found no issues — nothing to fix.';
219
+ }
220
+ const lines = [];
221
+ lines.push(
222
+ 'You are fixing security issues found by VibeGuard. Apply the minimal, safe change for each item below. Do not change unrelated code. For any leaked secret, also tell me to rotate it.'
223
+ );
224
+ lines.push('');
225
+ lines.push(`Overall grade: ${result.grade}.`);
226
+ lines.push('');
227
+
228
+ const actNow = result.findings.filter((f) => f.confidence !== 'low');
229
+ const review = result.findings.filter((f) => f.confidence === 'low');
230
+
231
+ let n = 1;
232
+ if (actNow.length) {
233
+ lines.push('APPLY THESE FIXES (high/medium confidence):');
234
+ for (const f of actNow) {
235
+ lines.push(`${n}. [${f.severity.toUpperCase()}] ${f.file}:${f.line} — ${f.message}`);
236
+ lines.push(` Fix: ${f.fix}`);
237
+ n++;
238
+ }
239
+ lines.push('');
240
+ }
241
+ if (review.length) {
242
+ lines.push(
243
+ 'REVIEW THESE — heuristic hints, verify before changing (do NOT blindly rewrite):'
244
+ );
245
+ for (const f of review) {
246
+ lines.push(`${n}. [${f.severity.toUpperCase()}, review] ${f.file}:${f.line} — ${f.message}`);
247
+ lines.push(` Suggested: ${f.fix}`);
248
+ n++;
249
+ }
250
+ lines.push('');
251
+ }
252
+ lines.push(
253
+ 'After applying fixes, I will re-run `vibeguard verify` to confirm each issue is resolved.'
254
+ );
255
+ return lines.join('\n');
256
+ }
257
+
258
+ function renderHtml(result) {
259
+ const c = result.counts;
260
+ const findings = result.findings || [];
261
+ const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
262
+ for (const f of findings) bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
263
+
264
+ const gradeColor = { A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444' };
265
+ const sevColor = { critical: '#ef4444', high: '#f97316', medium: '#eab308', low: '#3b82f6' };
266
+
267
+ const rows = findings.map(f => ` <tr>
268
+ <td><span class="sev sev-${f.severity}">${f.severity}</span></td>
269
+ <td><code>${esc(f.ruleId)}</code></td>
270
+ <td><code>${esc(f.file)}:${f.line}</code></td>
271
+ <td>${esc(f.message || '')}</td>
272
+ <td>${esc(f.fix || '')}</td>
273
+ </tr>`).join('\n');
274
+
275
+ return `<!DOCTYPE html>
276
+ <html lang="en">
277
+ <head>
278
+ <meta charset="utf-8">
279
+ <meta name="viewport" content="width=device-width, initial-scale=1">
280
+ <title>VibeGuard Security Report</title>
281
+ <style>
282
+ body { font-family: -apple-system, system-ui, sans-serif; max-width: 1100px; margin: 0 auto; padding: 20px; color: #1a1a1a; }
283
+ .grade { font-size: 72px; font-weight: 800; text-align: center; padding: 20px; border-radius: 12px; color: white; width: 120px; height: 120px; line-height: 120px; margin: 0 auto; }
284
+ .summary { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }
285
+ .stat { text-align: center; padding: 12px 24px; border-radius: 8px; background: #f3f4f6; }
286
+ .stat .num { font-size: 28px; font-weight: 700; }
287
+ .stat .label { font-size: 12px; color: #6b7280; text-transform: uppercase; }
288
+ table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: 13px; }
289
+ th { text-align: left; padding: 8px 12px; background: #f9fafb; border-bottom: 2px solid #e5e7eb; }
290
+ td { padding: 8px 12px; border-bottom: 1px solid #f3f4f6; }
291
+ .sev { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; color: white; }
292
+ .sev-critical { background: #ef4444; }
293
+ .sev-high { background: #f97316; }
294
+ .sev-medium { background: #eab308; }
295
+ .sev-low { background: #3b82f6; }
296
+ code { background: #f3f4f6; padding: 2px 4px; border-radius: 3px; font-size: 12px; }
297
+ h1 { text-align: center; }
298
+ .meta { text-align: center; color: #6b7280; font-size: 13px; margin-bottom: 20px; }
299
+ </style>
300
+ </head>
301
+ <body>
302
+ <h1>VibeGuard Security Report</h1>
303
+ <div class="meta">${esc(result.root || '')} — ${result.scannedFiles} files scanned — ${result.generatedAt || new Date().toISOString()}</div>
304
+ <div class="grade" style="background:${gradeColor[result.grade] || '#6b7280'}">${result.grade}</div>
305
+ <div class="summary">
306
+ <div class="stat"><div class="num" style="color:#ef4444">${bySeverity.critical}</div><div class="label">Critical</div></div>
307
+ <div class="stat"><div class="num" style="color:#f97316">${bySeverity.high}</div><div class="label">High</div></div>
308
+ <div class="stat"><div class="num" style="color:#eab308">${bySeverity.medium}</div><div class="label">Medium</div></div>
309
+ <div class="stat"><div class="num" style="color:#3b82f6">${bySeverity.low}</div><div class="label">Low</div></div>
310
+ </div>
311
+ ${findings.length > 0 ? `<table>
312
+ <thead><tr><th>Severity</th><th>Rule</th><th>Location</th><th>Message</th><th>Fix</th></tr></thead>
313
+ <tbody>
314
+ ${rows}
315
+ </tbody>
316
+ </table>` : '<p style="text-align:center;color:#22c55e;font-size:18px;">No findings. Clean!</p>'}
317
+ </body>
318
+ </html>`;
319
+ }
320
+
321
+ function esc(s) { return String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); }
322
+
323
+ module.exports = {
324
+ renderHuman,
325
+ renderJson,
326
+ renderSarif,
327
+ renderHtml,
328
+ renderFixPrompt,
329
+ renderSummaryLine,
330
+ C,
331
+ };