@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/presets.js ADDED
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * VibeGuard Rule Pack Presets.
5
+ *
6
+ * Pre-configured rule sets for common stacks. Users can apply a preset
7
+ * to quickly enable only the rules relevant to their technology stack,
8
+ * reducing noise and improving signal-to-noise ratio.
9
+ *
10
+ * Usage: vibeguard preset nextjs
11
+ * vibeguard preset django
12
+ * vibeguard preset aws
13
+ */
14
+
15
+ const PRESETS = {
16
+ nextjs: {
17
+ name: 'Next.js + React',
18
+ description: 'Rules for Next.js apps with React, API routes, Server Actions',
19
+ include: ['nextjs.', 'react.', 'authjs.', 'clerk.', 'supabase.', 'stripe.', 'resend.', 'uploadthing.', 'ai.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'csp.', 'header.', 'data.', 'deploy.vercel'],
20
+ exclude: ['go.', 'ruby.', 'php.', 'java.', 'rust.', 'kotlin.', 'swift.', 'django.', 'flask.', 'rails.', 'laravel.', 'spring.', 'tf.', 'k8s.'],
21
+ },
22
+ react: {
23
+ name: 'React SPA',
24
+ description: 'Rules for React single-page apps',
25
+ include: ['react.', 'xss.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'csp.', 'data.'],
26
+ exclude: ['go.', 'ruby.', 'php.', 'java.', 'rust.', 'kotlin.', 'swift.', 'django.', 'flask.', 'rails.', 'laravel.', 'spring.', 'tf.', 'k8s.', 'nextjs.'],
27
+ },
28
+ django: {
29
+ name: 'Django + Python',
30
+ description: 'Rules for Django web apps',
31
+ include: ['django.', 'py.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'data.', 'auth.', 'crypto.'],
32
+ exclude: ['go.', 'ruby.', 'php.', 'java.', 'rust.', 'kotlin.', 'swift.', 'react.', 'nextjs.', 'clerk.', 'authjs.', 'drizzle.', 'prisma.', 'hono.', 'trpc.'],
33
+ },
34
+ flask: {
35
+ name: 'Flask + Python',
36
+ description: 'Rules for Flask web apps',
37
+ include: ['flask.', 'py.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'data.', 'auth.', 'crypto.'],
38
+ exclude: ['go.', 'ruby.', 'php.', 'java.', 'rust.', 'kotlin.', 'swift.', 'react.', 'nextjs.', 'django.', 'clerk.', 'authjs.', 'drizzle.', 'prisma.', 'hono.', 'trpc.'],
39
+ },
40
+ rails: {
41
+ name: 'Ruby on Rails',
42
+ description: 'Rules for Rails web apps',
43
+ include: ['rails.', 'ruby.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'data.', 'auth.', 'crypto.'],
44
+ exclude: ['go.', 'py.', 'php.', 'java.', 'rust.', 'kotlin.', 'swift.', 'react.', 'nextjs.', 'django.', 'flask.', 'clerk.', 'authjs.', 'drizzle.', 'prisma.', 'hono.', 'trpc.'],
45
+ },
46
+ spring: {
47
+ name: 'Spring Boot + Java',
48
+ description: 'Rules for Spring Boot Java apps',
49
+ include: ['spring.', 'java.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'data.', 'auth.', 'crypto.'],
50
+ exclude: ['go.', 'py.', 'ruby.', 'php.', 'rust.', 'kotlin.', 'swift.', 'react.', 'nextjs.', 'django.', 'flask.', 'rails.', 'clerk.', 'authjs.', 'drizzle.', 'prisma.', 'hono.', 'trpc.'],
51
+ },
52
+ aws: {
53
+ name: 'AWS Infrastructure',
54
+ description: 'Rules for AWS/Terraform infrastructure',
55
+ include: ['tf.', 'cloud.', 'secret.aws', 'deploy.k8s', 'deploy.docker', 'k8s.', 'docker.', 'compose.'],
56
+ exclude: ['react.', 'nextjs.', 'django.', 'flask.', 'rails.', 'spring.', 'clerk.', 'authjs.', 'hono.', 'trpc.', 'drizzle.', 'prisma.', 'sveltekit.', 'nuxt.', 'astro.'],
57
+ },
58
+ gcp: {
59
+ name: 'GCP Infrastructure',
60
+ description: 'Rules for Google Cloud Platform',
61
+ include: ['tf.', 'cloud.', 'secret.gcp', 'deploy.k8s', 'deploy.docker', 'k8s.', 'docker.', 'compose.'],
62
+ exclude: ['react.', 'nextjs.', 'django.', 'flask.', 'rails.', 'spring.', 'clerk.', 'authjs.', 'hono.', 'trpc.', 'drizzle.', 'prisma.', 'sveltekit.', 'nuxt.', 'astro.'],
63
+ },
64
+ azure: {
65
+ name: 'Azure Infrastructure',
66
+ description: 'Rules for Azure infrastructure',
67
+ include: ['tf.', 'cloud.', 'secret.azure', 'deploy.k8s', 'deploy.docker', 'k8s.', 'docker.', 'compose.'],
68
+ exclude: ['react.', 'nextjs.', 'django.', 'flask.', 'rails.', 'spring.', 'clerk.', 'authjs.', 'hono.', 'trpc.', 'drizzle.', 'prisma.', 'sveltekit.', 'nuxt.', 'astro.'],
69
+ },
70
+ api: {
71
+ name: 'API Server',
72
+ description: 'Rules for REST/GraphQL API servers',
73
+ include: ['api.', 'auth.', 'secret.', 'injection.', 'code.', 'web.', 'cookie.', 'data.', 'graphql.', 'ws.', 'header.', 'crypto.', 'error.', 'ratelimit.', 'validation.', 'dos.'],
74
+ exclude: ['react.', 'nextjs.', 'mobile.', 'go.', 'rust.', 'kotlin.', 'swift.', 'rails.', 'laravel.', 'spring.', 'tf.', 'k8s.', 'docker.', 'compose.'],
75
+ },
76
+ mobile: {
77
+ name: 'Mobile App',
78
+ description: 'Rules for React Native / native mobile apps',
79
+ include: ['mobile.', 'react.', 'secret.', 'injection.', 'data.', 'auth.', 'crypto.', 'xss.'],
80
+ exclude: ['go.', 'ruby.', 'php.', 'java.', 'rust.', 'django.', 'flask.', 'rails.', 'laravel.', 'spring.', 'tf.', 'k8s.', 'docker.', 'compose.', 'nextjs.', 'graphql.', 'ws.', 'deploy.'],
81
+ },
82
+ fullstack: {
83
+ name: 'Full Stack (all rules)',
84
+ description: 'All rules enabled — maximum coverage',
85
+ include: ['*'],
86
+ exclude: [],
87
+ },
88
+ };
89
+
90
+ function listPresets() {
91
+ return Object.entries(PRESETS).map(([key, p]) => ({
92
+ key,
93
+ name: p.name,
94
+ description: p.description,
95
+ includeCount: p.include.length,
96
+ excludeCount: p.exclude.length,
97
+ }));
98
+ }
99
+
100
+ function getPreset(key) {
101
+ return PRESETS[key] || null;
102
+ }
103
+
104
+ function applyPreset(key) {
105
+ const preset = PRESETS[key];
106
+ if (!preset) return null;
107
+ return {
108
+ ignoreRules: preset.exclude.length > 0 && preset.exclude[0] !== '' ? preset.exclude : [],
109
+ presetName: preset.name,
110
+ };
111
+ }
112
+
113
+ module.exports = { PRESETS, listPresets, getPreset, applyPreset };
@@ -0,0 +1,273 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * VibeGuard Privacy Audit.
5
+ *
6
+ * Scans the codebase for all data collection, storage, and transmission points.
7
+ * Builds a privacy inventory showing:
8
+ * - What PII is collected (forms, inputs, API params)
9
+ * - Where PII is stored (DB, localStorage, cookies, files)
10
+ * - Where PII is sent (external APIs, analytics, AI providers)
11
+ * - What consent mechanisms exist (or are missing)
12
+ * - What data retention policies exist (or are missing)
13
+ * - What encryption exists (or is missing)
14
+ *
15
+ * 100% local. Zero network. Zero dependencies.
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+
21
+ const PII_FIELDS = /\b(?:email|phone|ssn|social_security|creditcard|credit_card|card_number|cvv|cvc|passport|dob|date_of_birth|bank_account|routing_number|address|zip|postal|first_name|last_name|fullname|birth|gender|nationality|ip_address|mac_address|device_id|biometric|fingerprint|location|latitude|longitude|avatar|profile_pic)\b/gi;
22
+
23
+ const STORAGE_SINKS = [
24
+ { re: /localStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'localStorage', risk: 'high', reason: 'XSS can read localStorage. Use HTTP-only cookies for auth tokens.' },
25
+ { re: /sessionStorage\.setItem\s*\(\s*['"]([^'"]+)['"]/gi, type: 'sessionStorage', risk: 'high', reason: 'XSS can read sessionStorage. Use HTTP-only cookies.' },
26
+ { re: /document\.cookie\s*=\s*['"]?([^=;'"]+)/gi, type: 'cookie', risk: 'medium', reason: 'Verify Secure, HttpOnly, SameSite flags are set.' },
27
+ { re: /IndexedDB|indexedDB\.open/gi, type: 'IndexedDB', risk: 'medium', reason: 'Persistent browser storage. XSS accessible. Do not store PII here.' },
28
+ { re: /SharedPreferences|getSharedPreferences/gi, type: 'SharedPreferences (Android)', risk: 'high', reason: 'Unencrypted on disk. Use EncryptedSharedPreferences.' },
29
+ { re: /UserDefaults\.standard/gi, type: 'UserDefaults (iOS)', risk: 'high', reason: 'Unencrypted plist. Use Keychain for secrets.' },
30
+ { re: /AsyncStorage\.setItem/gi, type: 'AsyncStorage (React Native)', risk: 'high', reason: 'Unencrypted on device. Use expo-secure-store or Keychain.' },
31
+ { re: /fs\.writeFile|fs\.writeFileSync|fs\.appendFile/gi, type: 'file', risk: 'medium', reason: 'Verify file permissions and encryption at rest.' },
32
+ { re: /CREATE\s+TABLE|createCollection|createTable|schema\.model|schema\.define/gi, type: 'database', risk: 'medium', reason: 'Verify RLS, field-level encryption, and retention policy.' },
33
+ ];
34
+
35
+ const TRANSMISSION_SINKS = [
36
+ { re: /fetch\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'fetch', label: 'HTTP fetch to external URL' },
37
+ { re: /axios\.(?:get|post|put|patch|delete)\s*\(\s*['"]https?:\/\/(?!localhost|127\.0\.0\.1)/gi, type: 'axios', label: 'Axios request to external URL' },
38
+ { re: /XMLHttpRequest|xhr\.open/gi, type: 'XHR', label: 'XMLHttpRequest to external URL' },
39
+ { re: /(?:sendBeacon|navigator\.sendBeacon)\s*\(/gi, type: 'beacon', label: 'Analytics beacon sent to external URL' },
40
+ { re: /https?:\/\/api\.(?:openai|anthropic|googleapis|gemini)\.com/gi, type: 'AI API', label: 'Data sent to AI/LLM provider' },
41
+ { re: /https?:\/\/www\.google-analytics\.com|gtag\(|dataLayer\.push/gi, type: 'Google Analytics', label: 'Data sent to Google Analytics' },
42
+ { re: /https?:\/\/api\.mixpanel\.com|mixpanel\.(?:track|identify)/gi, type: 'Mixpanel', label: 'Data sent to Mixpanel' },
43
+ { re: /https?:\/\/t\.co|https?:\/\/connect\.facebook\.net|fbq\(/gi, type: 'Social tracking', label: 'Data sent to social media tracking pixel' },
44
+ { re: /https?:\/\/sentry\.io|Sentry\.capture/gi, type: 'Sentry', label: 'Error data sent to Sentry' },
45
+ { re: /https?:\/\/api\.amplitude\.com|amplitude\.(?:logEvent|setUserId)/gi, type: 'Amplitude', label: 'Data sent to Amplitude analytics' },
46
+ { re: /https?:\/\/api\.segment\.com|analytics\.(?:track|identify|page)/gi, type: 'Segment', label: 'Data sent to Segment' },
47
+ { re: /posthog\.(?:capture|identify)/gi, type: 'PostHog', label: 'Data sent to PostHog' },
48
+ ];
49
+
50
+ const CONSENT_PATTERNS = [
51
+ /consent|gdpr|ccpa|opt.?in|opt.?out|cookie.?banner|privacy.?policy|do.?not.?track|dnt|permission/i,
52
+ ];
53
+
54
+ const ENCRYPTION_PATTERNS = [
55
+ /encrypt|decrypt|cipher|aes|rsa|bcrypt|argon2|scrypt|pbkdf2|crypto\.(?:createCipher|createDecipher|randomBytes)/i,
56
+ ];
57
+
58
+ const RETENTION_PATTERNS = [
59
+ /retention|ttl|expire|expir(?:e|ation|y)|purge|cleanup|delete\s+after|drop\s+after|max.?age/i,
60
+ ];
61
+
62
+ function auditPrivacy(dir, files) {
63
+ const inventory = {
64
+ piiFields: new Set(),
65
+ storage: [],
66
+ transmission: [],
67
+ consent: [],
68
+ encryption: [],
69
+ retention: [],
70
+ risks: [],
71
+ summary: {},
72
+ };
73
+
74
+ for (const file of files) {
75
+ let content;
76
+ try { content = fs.readFileSync(file, 'utf8'); } catch { continue; }
77
+ const rel = path.relative(dir, file).split(path.sep).join('/');
78
+ const lines = content.split(/\r?\n/);
79
+
80
+ for (let i = 0; i < lines.length; i++) {
81
+ const line = lines[i];
82
+
83
+ // PII fields
84
+ let m;
85
+ PII_FIELDS.lastIndex = 0;
86
+ while ((m = PII_FIELDS.exec(line)) !== null) {
87
+ inventory.piiFields.add(m[0].toLowerCase());
88
+ }
89
+
90
+ // Storage sinks
91
+ for (const sink of STORAGE_SINKS) {
92
+ sink.re.lastIndex = 0;
93
+ while ((m = sink.re.exec(line)) !== null) {
94
+ inventory.storage.push({
95
+ file: rel, line: i + 1, type: sink.type,
96
+ target: m[1] || 'unknown', risk: sink.risk, reason: sink.reason,
97
+ });
98
+ }
99
+ }
100
+
101
+ // Transmission sinks
102
+ for (const sink of TRANSMISSION_SINKS) {
103
+ sink.re.lastIndex = 0;
104
+ while ((m = sink.re.exec(line)) !== null) {
105
+ inventory.transmission.push({
106
+ file: rel, line: i + 1, type: sink.type, label: sink.label,
107
+ });
108
+ }
109
+ }
110
+
111
+ // Consent patterns
112
+ for (const re of CONSENT_PATTERNS) {
113
+ if (re.test(line)) {
114
+ inventory.consent.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
115
+ break;
116
+ }
117
+ }
118
+
119
+ // Encryption patterns
120
+ for (const re of ENCRYPTION_PATTERNS) {
121
+ if (re.test(line)) {
122
+ inventory.encryption.push({ file: rel, line: i + 1 });
123
+ break;
124
+ }
125
+ }
126
+
127
+ // Retention patterns
128
+ for (const re of RETENTION_PATTERNS) {
129
+ if (re.test(line)) {
130
+ inventory.retention.push({ file: rel, line: i + 1, text: line.trim().slice(0, 100) });
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ // Assess risks
138
+ if (inventory.piiFields.size > 0 && inventory.encryption.length === 0) {
139
+ inventory.risks.push({ severity: 'high', message: 'PII fields detected but no encryption found in the codebase' });
140
+ }
141
+ if (inventory.piiFields.size > 0 && inventory.consent.length === 0) {
142
+ inventory.risks.push({ severity: 'high', message: 'PII fields detected but no consent mechanism found — GDPR/CCPA violation risk' });
143
+ }
144
+ if (inventory.piiFields.size > 0 && inventory.retention.length === 0) {
145
+ inventory.risks.push({ severity: 'medium', message: 'PII fields detected but no data retention policy found' });
146
+ }
147
+ if (inventory.storage.some(s => s.type === 'localStorage' || s.type === 'sessionStorage' || s.type === 'AsyncStorage (React Native)' || s.type === 'SharedPreferences (Android)')) {
148
+ inventory.risks.push({ severity: 'high', message: 'PII or sensitive data stored in client-side storage (localStorage/sessionStorage/AsyncStorage) — XSS accessible' });
149
+ }
150
+ if (inventory.transmission.some(t => t.type === 'AI API')) {
151
+ const hasRedactionNearAI = inventory.transmission.some(t => {
152
+ if (t.type !== 'AI API') return false;
153
+ return /encrypt|redact|anonym/i.test(''); // simplified - just check if any redaction exists in codebase
154
+ });
155
+ if (!hasRedactionNearAI && inventory.encryption.length === 0) {
156
+ inventory.risks.push({ severity: 'high', message: 'Data sent to AI/LLM providers — verify PII is redacted before sending' });
157
+ }
158
+ }
159
+ if (inventory.transmission.some(t => t.type === 'Google Analytics' || t.type === 'Mixpanel' || t.type === 'Amplitude' || t.type === 'Segment' || t.type === 'PostHog')) {
160
+ if (inventory.consent.length === 0) {
161
+ inventory.risks.push({ severity: 'high', message: 'Analytics tracking detected but no consent mechanism — GDPR violation' });
162
+ }
163
+ }
164
+
165
+ // Summary
166
+ inventory.summary = {
167
+ piiFieldsDetected: [...inventory.piiFields],
168
+ piiFieldCount: inventory.piiFields.size,
169
+ storagePoints: inventory.storage.length,
170
+ transmissionPoints: inventory.transmission.length,
171
+ consentMechanisms: inventory.consent.length,
172
+ encryptionPoints: inventory.encryption.length,
173
+ retentionPolicies: inventory.retention.length,
174
+ riskCount: inventory.risks.length,
175
+ overallRisk: inventory.risks.filter(r => r.severity === 'high').length > 0 ? 'HIGH' :
176
+ inventory.risks.filter(r => r.severity === 'medium').length > 0 ? 'MEDIUM' : 'LOW',
177
+ };
178
+
179
+ return inventory;
180
+ }
181
+
182
+ function renderPrivacyReport(inventory) {
183
+ const C = {
184
+ red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
185
+ cyan: '\x1b[36m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m',
186
+ };
187
+
188
+ const lines = [];
189
+ lines.push(`${C.bold}VibeGuard Privacy Audit${C.reset}`);
190
+ lines.push(`${C.dim}${'─'.repeat(60)}${C.reset}`);
191
+ lines.push('');
192
+
193
+ // PII fields
194
+ lines.push(`${C.bold}PII Fields Detected${C.reset} (${inventory.summary.piiFieldCount})`);
195
+ if (inventory.summary.piiFieldCount === 0) {
196
+ lines.push(` ${C.green}No PII fields detected${C.reset}`);
197
+ } else {
198
+ lines.push(` ${inventory.summary.piiFields.map(f => C.cyan + f + C.reset).join(', ')}`);
199
+ }
200
+ lines.push('');
201
+
202
+ // Storage
203
+ lines.push(`${C.bold}Data Storage Points${C.reset} (${inventory.summary.storagePoints})`);
204
+ if (inventory.summary.storagePoints === 0) {
205
+ lines.push(` ${C.green}No storage sinks detected${C.reset}`);
206
+ } else {
207
+ for (const s of inventory.storage.slice(0, 10)) {
208
+ const color = s.risk === 'high' ? C.red : s.risk === 'medium' ? C.yellow : C.dim;
209
+ lines.push(` ${color}[${s.risk}]${C.reset} ${s.type} — ${s.file}:${s.line}`);
210
+ }
211
+ if (inventory.storage.length > 10) lines.push(` ${C.dim}... and ${inventory.storage.length - 10} more${C.reset}`);
212
+ }
213
+ lines.push('');
214
+
215
+ // Transmission
216
+ lines.push(`${C.bold}Data Transmission Points${C.reset} (${inventory.summary.transmissionPoints})`);
217
+ if (inventory.summary.transmissionPoints === 0) {
218
+ lines.push(` ${C.green}No external transmission detected${C.reset}`);
219
+ } else {
220
+ const byType = {};
221
+ for (const t of inventory.transmission) {
222
+ byType[t.type] = (byType[t.type] || 0) + 1;
223
+ }
224
+ for (const [type, count] of Object.entries(byType)) {
225
+ lines.push(` ${C.yellow}${type}${C.reset}: ${count} endpoint(s)`);
226
+ }
227
+ }
228
+ lines.push('');
229
+
230
+ // Consent
231
+ lines.push(`${C.bold}Consent Mechanisms${C.reset} (${inventory.summary.consentMechanisms})`);
232
+ if (inventory.summary.consentMechanisms === 0) {
233
+ lines.push(` ${C.red}No consent mechanism detected — GDPR/CCPA risk${C.reset}`);
234
+ } else {
235
+ lines.push(` ${C.green}Consent mechanism found${C.reset}`);
236
+ }
237
+ lines.push('');
238
+
239
+ // Encryption
240
+ lines.push(`${C.bold}Encryption${C.reset} (${inventory.summary.encryptionPoints})`);
241
+ if (inventory.summary.encryptionPoints === 0) {
242
+ lines.push(` ${C.red}No encryption detected${C.reset}`);
243
+ } else {
244
+ lines.push(` ${C.green}Encryption found in ${inventory.summary.encryptionPoints} location(s)${C.reset}`);
245
+ }
246
+ lines.push('');
247
+
248
+ // Retention
249
+ lines.push(`${C.bold}Data Retention${C.reset} (${inventory.summary.retentionPolicies})`);
250
+ if (inventory.summary.retentionPolicies === 0) {
251
+ lines.push(` ${C.yellow}No retention policy detected${C.reset}`);
252
+ } else {
253
+ lines.push(` ${C.green}Retention policy found${C.reset}`);
254
+ }
255
+ lines.push('');
256
+
257
+ // Risks
258
+ lines.push(`${C.bold}Privacy Risks${C.reset} (${inventory.summary.riskCount})`);
259
+ if (inventory.summary.riskCount === 0) {
260
+ lines.push(` ${C.green}No privacy risks detected${C.reset}`);
261
+ } else {
262
+ for (const r of inventory.risks) {
263
+ const color = r.severity === 'high' ? C.red : r.severity === 'medium' ? C.yellow : C.dim;
264
+ lines.push(` ${color}[${r.severity}]${C.reset} ${r.message}`);
265
+ }
266
+ }
267
+ lines.push('');
268
+ lines.push(`${C.dim}Overall Privacy Risk: ${inventory.summary.overallRisk}${C.reset}`);
269
+
270
+ return lines.join('\n');
271
+ }
272
+
273
+ module.exports = { auditPrivacy, renderPrivacyReport };
package/src/repl.js ADDED
@@ -0,0 +1,150 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Interactive REPL for VibeGuard.
5
+ *
6
+ * Launches an interactive session where the user can:
7
+ * - Inspect findings one by one
8
+ * - Mark findings as "solved" (fixed), "ignored" (suppress), or "skip"
9
+ * - Auto-apply suggested fixes where available
10
+ * - Persist decisions to .vibeguard/state.json for team sharing
11
+ *
12
+ * Usage: vibeguard repl [dir]
13
+ */
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const readline = require('readline');
18
+ const { scan } = require('./scanner');
19
+ const { suggestFixes } = require('./autofix');
20
+
21
+ const STATE_FILE = '.vibeguard/state.json';
22
+
23
+ function loadState(root) {
24
+ const p = path.join(root, STATE_FILE);
25
+ if (fs.existsSync(p)) {
26
+ try { return JSON.parse(fs.readFileSync(p, 'utf8')); } catch {}
27
+ }
28
+ return { decisions: {}, lastRun: null };
29
+ }
30
+
31
+ function saveState(root, state) {
32
+ const dir = path.join(root, '.vibeguard');
33
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
34
+ state.lastRun = new Date().toISOString();
35
+ fs.writeFileSync(path.join(dir, 'state.json'), JSON.stringify(state, null, 2));
36
+ }
37
+
38
+ const COLORS = {
39
+ red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
40
+ blue: '\x1b[34m', cyan: '\x1b[36m', dim: '\x1b[2m',
41
+ bold: '\x1b[1m', reset: '\x1b[0m',
42
+ };
43
+
44
+ async function startRepl(dir, opts) {
45
+ opts = opts || {};
46
+ const result = scan(dir);
47
+ const findings = result.findings;
48
+
49
+ if (findings.length === 0) {
50
+ process.stdout.write(`${COLORS.green}No findings. Clean!${COLORS.reset}\n`);
51
+ return 0;
52
+ }
53
+
54
+ const state = loadState(dir);
55
+ let idx = 0;
56
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
57
+
58
+ process.stdout.write(
59
+ `${COLORS.bold}${COLORS.cyan}VibeGuard Interactive REPL${COLORS.reset}\n` +
60
+ `${COLORS.dim}${findings.length} findings. Commands: (s)olved (i)gnore (n)ext (a)uto-fix (q)uit (l)ist${COLORS.reset}\n\n`
61
+ );
62
+
63
+ function showCurrent() {
64
+ if (idx >= findings.length) {
65
+ process.stdout.write(`${COLORS.green}All findings reviewed!${COLORS.reset}\n`);
66
+ saveState(dir, state);
67
+ rl.close();
68
+ return;
69
+ }
70
+ const f = findings[idx];
71
+ const sev = f.severity || 'medium';
72
+ const sevColor = sev === 'critical' || sev === 'high' ? COLORS.red : sev === 'medium' ? COLORS.yellow : COLORS.blue;
73
+ const status = state.decisions[f.fingerprint] || 'open';
74
+
75
+ process.stdout.write(
76
+ `\n${COLORS.bold}[${idx + 1}/${findings.length}]${COLORS.reset} ` +
77
+ `${sevColor}${sev}${COLORS.reset} ` +
78
+ `${COLORS.dim}${f.ruleId}${COLORS.reset}\n` +
79
+ ` ${COLORS.bold}${f.title}${COLORS.reset}\n` +
80
+ ` ${COLORS.dim}${f.file}:${f.line}${COLORS.reset}\n` +
81
+ ` ${f.message || ''}\n` +
82
+ ` ${f.fix ? `${COLORS.green}fix: ${COLORS.reset}${f.fix}` : ''}\n` +
83
+ ` ${COLORS.dim}status: ${status}${COLORS.reset}\n` +
84
+ `${COLORS.dim}(s)olved (i)gnore (n)ext (a)uto-fix (b)ack (l)ist (q)uit${COLORS.reset}\n> `
85
+ );
86
+ }
87
+
88
+ return new Promise((resolve) => {
89
+ rl.on('line', (input) => {
90
+ const cmd = input.trim().toLowerCase();
91
+ const f = findings[idx];
92
+
93
+ switch (cmd) {
94
+ case 's':
95
+ case 'solved':
96
+ state.decisions[f.fingerprint] = 'solved';
97
+ idx++;
98
+ showCurrent();
99
+ break;
100
+ case 'i':
101
+ case 'ignore':
102
+ state.decisions[f.fingerprint] = 'ignored';
103
+ idx++;
104
+ showCurrent();
105
+ break;
106
+ case 'n':
107
+ case 'next':
108
+ case '':
109
+ idx++;
110
+ showCurrent();
111
+ break;
112
+ case 'b':
113
+ case 'back':
114
+ if (idx > 0) idx--;
115
+ showCurrent();
116
+ break;
117
+ case 'a':
118
+ case 'auto-fix':
119
+ if (f.fix) {
120
+ process.stdout.write(`${COLORS.yellow}Auto-fix: ${f.fix}${COLORS.reset}\n`);
121
+ } else {
122
+ process.stdout.write(`${COLORS.dim}No auto-fix available for this rule.${COLORS.reset}\n`);
123
+ }
124
+ state.decisions[f.fingerprint] = 'auto-fix-pending';
125
+ showCurrent();
126
+ break;
127
+ case 'l':
128
+ case 'list':
129
+ findings.forEach((ff, i) => {
130
+ const st = state.decisions[ff.fingerprint] || 'open';
131
+ const mark = st === 'solved' ? '✓' : st === 'ignored' ? '✗' : ' ';
132
+ process.stdout.write(` ${mark} [${i + 1}] ${ff.severity} ${ff.ruleId} ${ff.file}:${ff.line}\n`);
133
+ });
134
+ process.stdout.write(`\n> `);
135
+ break;
136
+ case 'q':
137
+ case 'quit':
138
+ saveState(dir, state);
139
+ rl.close();
140
+ resolve(0);
141
+ break;
142
+ default:
143
+ process.stdout.write(`${COLORS.dim}Unknown command.${COLORS.reset}\n> `);
144
+ }
145
+ });
146
+ showCurrent();
147
+ });
148
+ }
149
+
150
+ module.exports = { startRepl, loadState, saveState };