@vibecheckai/cli 3.4.0 → 3.5.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 (166) hide show
  1. package/bin/registry.js +243 -152
  2. package/bin/runners/cli-utils.js +2 -33
  3. package/bin/runners/context/generators/cursor.js +49 -2
  4. package/bin/runners/lib/agent-firewall/learning/learning-engine.js +849 -0
  5. package/bin/runners/lib/analyzers.js +544 -19
  6. package/bin/runners/lib/audit-logger.js +532 -0
  7. package/bin/runners/lib/authority/authorities/architecture.js +364 -0
  8. package/bin/runners/lib/authority/authorities/compliance.js +341 -0
  9. package/bin/runners/lib/authority/authorities/human.js +343 -0
  10. package/bin/runners/lib/authority/authorities/quality.js +420 -0
  11. package/bin/runners/lib/authority/authorities/security.js +228 -0
  12. package/bin/runners/lib/authority/index.js +293 -0
  13. package/bin/runners/lib/authority-badge.js +425 -425
  14. package/bin/runners/lib/bundle/bundle-intelligence.js +846 -0
  15. package/bin/runners/lib/cli-charts.js +368 -0
  16. package/bin/runners/lib/cli-config-display.js +405 -0
  17. package/bin/runners/lib/cli-demo.js +275 -0
  18. package/bin/runners/lib/cli-errors.js +438 -0
  19. package/bin/runners/lib/cli-help-formatter.js +439 -0
  20. package/bin/runners/lib/cli-interactive-menu.js +509 -0
  21. package/bin/runners/lib/cli-prompts.js +441 -0
  22. package/bin/runners/lib/cli-scan-cards.js +362 -0
  23. package/bin/runners/lib/compliance-reporter.js +710 -0
  24. package/bin/runners/lib/conductor/index.js +671 -0
  25. package/bin/runners/lib/easy/README.md +123 -0
  26. package/bin/runners/lib/easy/index.js +140 -0
  27. package/bin/runners/lib/easy/interactive-wizard.js +788 -0
  28. package/bin/runners/lib/easy/one-click-firewall.js +564 -0
  29. package/bin/runners/lib/easy/zero-config-reality.js +714 -0
  30. package/bin/runners/lib/engines/accessibility-engine.js +218 -18
  31. package/bin/runners/lib/engines/api-consistency-engine.js +335 -30
  32. package/bin/runners/lib/engines/async-patterns-engine.js +444 -0
  33. package/bin/runners/lib/engines/bundle-size-engine.js +433 -0
  34. package/bin/runners/lib/engines/confidence-scoring.js +276 -0
  35. package/bin/runners/lib/engines/context-detection.js +264 -0
  36. package/bin/runners/lib/engines/cross-file-analysis-engine.js +292 -27
  37. package/bin/runners/lib/engines/database-patterns-engine.js +429 -0
  38. package/bin/runners/lib/engines/duplicate-code-engine.js +354 -0
  39. package/bin/runners/lib/engines/empty-catch-engine.js +127 -17
  40. package/bin/runners/lib/engines/env-variables-engine.js +458 -0
  41. package/bin/runners/lib/engines/error-handling-engine.js +437 -0
  42. package/bin/runners/lib/engines/false-positive-prevention.js +630 -0
  43. package/bin/runners/lib/engines/framework-adapters/index.js +607 -0
  44. package/bin/runners/lib/engines/framework-detection.js +508 -0
  45. package/bin/runners/lib/engines/import-order-engine.js +429 -0
  46. package/bin/runners/lib/engines/mock-data-engine.js +53 -10
  47. package/bin/runners/lib/engines/naming-conventions-engine.js +544 -0
  48. package/bin/runners/lib/engines/noise-reduction-engine.js +452 -0
  49. package/bin/runners/lib/engines/orchestrator.js +334 -0
  50. package/bin/runners/lib/engines/performance-issues-engine.js +176 -36
  51. package/bin/runners/lib/engines/react-patterns-engine.js +457 -0
  52. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +382 -54
  53. package/bin/runners/lib/engines/type-aware-engine.js +263 -39
  54. package/bin/runners/lib/engines/vibecheck-engines/index.js +122 -13
  55. package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +806 -0
  56. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +373 -73
  57. package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +577 -0
  58. package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +543 -0
  59. package/bin/runners/lib/engines/vibecheck-engines.js +514 -0
  60. package/bin/runners/lib/enhanced-features/index.js +305 -0
  61. package/bin/runners/lib/enhanced-output.js +631 -0
  62. package/bin/runners/lib/enterprise.js +300 -0
  63. package/bin/runners/lib/entitlements-v2.js +103 -11
  64. package/bin/runners/lib/firewall/command-validator.js +351 -0
  65. package/bin/runners/lib/firewall/config.js +341 -0
  66. package/bin/runners/lib/firewall/content-validator.js +519 -0
  67. package/bin/runners/lib/firewall/index.js +101 -0
  68. package/bin/runners/lib/firewall/path-validator.js +256 -0
  69. package/bin/runners/lib/html-proof-report.js +350 -700
  70. package/bin/runners/lib/intelligence/cross-repo-intelligence.js +817 -0
  71. package/bin/runners/lib/mcp-utils.js +425 -0
  72. package/bin/runners/lib/missions/plan.js +46 -6
  73. package/bin/runners/lib/missions/templates.js +232 -0
  74. package/bin/runners/lib/output/index.js +1022 -0
  75. package/bin/runners/lib/policy-engine.js +652 -0
  76. package/bin/runners/lib/polish/autofix/accessibility-fixes.js +333 -0
  77. package/bin/runners/lib/polish/autofix/async-handlers.js +273 -0
  78. package/bin/runners/lib/polish/autofix/dead-code.js +280 -0
  79. package/bin/runners/lib/polish/autofix/imports-optimizer.js +344 -0
  80. package/bin/runners/lib/polish/autofix/index.js +200 -0
  81. package/bin/runners/lib/polish/autofix/remove-consoles.js +209 -0
  82. package/bin/runners/lib/polish/autofix/strengthen-types.js +245 -0
  83. package/bin/runners/lib/polish/backend-checks.js +148 -0
  84. package/bin/runners/lib/polish/documentation-checks.js +111 -0
  85. package/bin/runners/lib/polish/frontend-checks.js +168 -0
  86. package/bin/runners/lib/polish/index.js +71 -0
  87. package/bin/runners/lib/polish/infrastructure-checks.js +131 -0
  88. package/bin/runners/lib/polish/library-detection.js +175 -0
  89. package/bin/runners/lib/polish/performance-checks.js +100 -0
  90. package/bin/runners/lib/polish/security-checks.js +148 -0
  91. package/bin/runners/lib/polish/utils.js +203 -0
  92. package/bin/runners/lib/prompt-builder.js +540 -0
  93. package/bin/runners/lib/proof-certificate.js +634 -0
  94. package/bin/runners/lib/reality/accessibility-audit.js +946 -0
  95. package/bin/runners/lib/reality/api-contract-validator.js +1012 -0
  96. package/bin/runners/lib/reality/chaos-engineering.js +1084 -0
  97. package/bin/runners/lib/reality/performance-tracker.js +1077 -0
  98. package/bin/runners/lib/reality/scenario-generator.js +1404 -0
  99. package/bin/runners/lib/reality/visual-regression.js +852 -0
  100. package/bin/runners/lib/reality-profiler.js +717 -0
  101. package/bin/runners/lib/replay/flight-recorder-viewer.js +1160 -0
  102. package/bin/runners/lib/review/ai-code-review.js +832 -0
  103. package/bin/runners/lib/rules/custom-rule-engine.js +985 -0
  104. package/bin/runners/lib/sbom-generator.js +641 -0
  105. package/bin/runners/lib/scan-output-enhanced.js +512 -0
  106. package/bin/runners/lib/scan-output.js +47 -0
  107. package/bin/runners/lib/security/owasp-scanner.js +939 -0
  108. package/bin/runners/lib/terminal-ui.js +113 -1
  109. package/bin/runners/lib/unified-cli-output.js +603 -430
  110. package/bin/runners/lib/validators/contract-validator.js +283 -0
  111. package/bin/runners/lib/validators/dead-export-detector.js +279 -0
  112. package/bin/runners/lib/validators/dep-audit.js +245 -0
  113. package/bin/runners/lib/validators/env-validator.js +319 -0
  114. package/bin/runners/lib/validators/index.js +120 -0
  115. package/bin/runners/lib/validators/license-checker.js +252 -0
  116. package/bin/runners/lib/validators/route-validator.js +290 -0
  117. package/bin/runners/runAIAgent.js +5 -10
  118. package/bin/runners/runAgent.js +3 -0
  119. package/bin/runners/runApprove.js +1233 -1200
  120. package/bin/runners/runAuth.js +22 -1
  121. package/bin/runners/runAuthority.js +528 -0
  122. package/bin/runners/runCheckpoint.js +4 -24
  123. package/bin/runners/runClassify.js +862 -859
  124. package/bin/runners/runConductor.js +772 -0
  125. package/bin/runners/runContainer.js +366 -0
  126. package/bin/runners/runContext.js +3 -0
  127. package/bin/runners/runDoctor.js +28 -41
  128. package/bin/runners/runEasy.js +410 -0
  129. package/bin/runners/runFirewall.js +3 -0
  130. package/bin/runners/runFirewallHook.js +3 -0
  131. package/bin/runners/runFix.js +76 -66
  132. package/bin/runners/runGuard.js +411 -18
  133. package/bin/runners/runIaC.js +372 -0
  134. package/bin/runners/runInit.js +10 -60
  135. package/bin/runners/runMcp.js +11 -12
  136. package/bin/runners/runPolish.js +240 -64
  137. package/bin/runners/runPromptFirewall.js +5 -12
  138. package/bin/runners/runProve.js +20 -55
  139. package/bin/runners/runReality.js +68 -59
  140. package/bin/runners/runReport.js +31 -5
  141. package/bin/runners/runRuntime.js +5 -8
  142. package/bin/runners/runScan.js +194 -1286
  143. package/bin/runners/runShip.js +695 -47
  144. package/bin/runners/runTruth.js +3 -0
  145. package/bin/runners/runValidate.js +7 -11
  146. package/bin/runners/runVibe.js +791 -0
  147. package/bin/runners/runWatch.js +14 -23
  148. package/bin/vibecheck.js +175 -56
  149. package/mcp-server/index.js +190 -14
  150. package/mcp-server/package.json +1 -1
  151. package/mcp-server/tools-v3.js +397 -64
  152. package/mcp-server/tools.js +495 -0
  153. package/package.json +1 -1
  154. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +0 -164
  155. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +0 -291
  156. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +0 -83
  157. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +0 -198
  158. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +0 -275
  159. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +0 -167
  160. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +0 -217
  161. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +0 -140
  162. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +0 -164
  163. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +0 -234
  164. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +0 -217
  165. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +0 -78
  166. package/mcp-server/index-v1.js +0 -698
@@ -0,0 +1,519 @@
1
+ /**
2
+ * Content Validator
3
+ *
4
+ * Validates file content against:
5
+ * - Hallucination patterns (fake APIs, placeholder data)
6
+ * - Hardcoded secrets and credentials
7
+ * - Dangerous code patterns
8
+ * - AI-generated placeholder text
9
+ */
10
+
11
+ "use strict";
12
+
13
+ /**
14
+ * ContentValidator class for validating file content
15
+ */
16
+ class ContentValidator {
17
+ /**
18
+ * Create a content validator
19
+ * @param {object} config - Firewall configuration
20
+ */
21
+ constructor(config) {
22
+ this.config = config;
23
+
24
+ // Extract content configuration
25
+ const content = config.content || {};
26
+ this.hallucinationPatterns = content.hallucinations || [];
27
+ this.forbiddenPatterns = content.forbidden || [];
28
+
29
+ // Build compiled patterns
30
+ this.compiledHallucinations = this.compilePatterns(this.hallucinationPatterns);
31
+ this.compiledForbidden = this.compilePatterns(this.forbiddenPatterns);
32
+
33
+ // Additional built-in patterns
34
+ this.builtInPatterns = this.getBuiltInPatterns();
35
+ }
36
+
37
+ /**
38
+ * Compile pattern configurations to regex
39
+ * @param {Array} patterns - Pattern configurations
40
+ * @returns {Array} Compiled patterns
41
+ */
42
+ compilePatterns(patterns) {
43
+ return patterns.map(p => {
44
+ if (typeof p === "string") {
45
+ return {
46
+ pattern: new RegExp(p, "gi"),
47
+ name: p,
48
+ severity: "warn",
49
+ };
50
+ }
51
+ return {
52
+ pattern: new RegExp(p.pattern, "gi"),
53
+ name: p.name || p.pattern,
54
+ severity: p.severity || "warn",
55
+ message: p.message,
56
+ };
57
+ });
58
+ }
59
+
60
+ /**
61
+ * Get built-in hallucination/dangerous patterns
62
+ * @returns {Array} Built-in patterns
63
+ */
64
+ getBuiltInPatterns() {
65
+ return [
66
+ // Fake API patterns
67
+ {
68
+ pattern: /fetch\s*\(\s*['"]https?:\/\/example\.com/gi,
69
+ name: "fake-api-fetch",
70
+ severity: "high",
71
+ message: "Fetching from example.com - likely a hallucination",
72
+ },
73
+ {
74
+ pattern: /api\.example\.com/gi,
75
+ name: "fake-api-domain",
76
+ severity: "high",
77
+ message: "Reference to api.example.com - likely a hallucination",
78
+ },
79
+ {
80
+ pattern: /https?:\/\/jsonplaceholder\.typicode\.com/gi,
81
+ name: "placeholder-api",
82
+ severity: "warn",
83
+ message: "Using JSONPlaceholder API - replace with real API before production",
84
+ },
85
+ {
86
+ pattern: /https?:\/\/reqres\.in/gi,
87
+ name: "fake-rest-api",
88
+ severity: "warn",
89
+ message: "Using Reqres fake API - replace with real API before production",
90
+ },
91
+
92
+ // Fake API keys
93
+ {
94
+ pattern: /sk-[a-zA-Z0-9]{20,}/g,
95
+ name: "fake-openai-key",
96
+ severity: "high",
97
+ message: "Possible fake or exposed OpenAI API key",
98
+ },
99
+ {
100
+ pattern: /AKIA[0-9A-Z]{16}/g,
101
+ name: "aws-access-key",
102
+ severity: "critical",
103
+ message: "AWS access key detected - never commit credentials",
104
+ },
105
+ {
106
+ pattern: /ghp_[a-zA-Z0-9]{36}/g,
107
+ name: "github-token",
108
+ severity: "critical",
109
+ message: "GitHub personal access token detected",
110
+ },
111
+ {
112
+ pattern: /ghu_[a-zA-Z0-9]{36}/g,
113
+ name: "github-user-token",
114
+ severity: "critical",
115
+ message: "GitHub user-to-server token detected",
116
+ },
117
+ {
118
+ pattern: /xox[baprs]-[a-zA-Z0-9-]+/g,
119
+ name: "slack-token",
120
+ severity: "critical",
121
+ message: "Slack token detected",
122
+ },
123
+
124
+ // Placeholder patterns
125
+ {
126
+ pattern: /\bTODO\s*:\s*implement/gi,
127
+ name: "todo-implement",
128
+ severity: "warn",
129
+ message: "TODO: implement - incomplete implementation",
130
+ },
131
+ {
132
+ pattern: /\bFIXME\b/gi,
133
+ name: "fixme-comment",
134
+ severity: "warn",
135
+ message: "FIXME comment found - needs attention",
136
+ },
137
+ {
138
+ pattern: /placeholder.*data/gi,
139
+ name: "placeholder-data",
140
+ severity: "warn",
141
+ message: "Placeholder data detected",
142
+ },
143
+ {
144
+ pattern: /fake.*response/gi,
145
+ name: "fake-response",
146
+ severity: "warn",
147
+ message: "Fake response detected",
148
+ },
149
+ {
150
+ pattern: /mock.*api/gi,
151
+ name: "mock-api",
152
+ severity: "warn",
153
+ message: "Mock API detected - replace before production",
154
+ },
155
+
156
+ // AI placeholder values
157
+ {
158
+ pattern: /your-api-key-here/gi,
159
+ name: "placeholder-api-key",
160
+ severity: "high",
161
+ message: "Placeholder API key found",
162
+ },
163
+ {
164
+ pattern: /YOUR_[A-Z_]+_KEY/g,
165
+ name: "placeholder-env-var",
166
+ severity: "warn",
167
+ message: "Placeholder environment variable found",
168
+ },
169
+ {
170
+ pattern: /<your-[a-z-]+>/gi,
171
+ name: "template-placeholder",
172
+ severity: "warn",
173
+ message: "Template placeholder found",
174
+ },
175
+ {
176
+ pattern: /\[insert.*here\]/gi,
177
+ name: "insert-placeholder",
178
+ severity: "warn",
179
+ message: "Insert placeholder found",
180
+ },
181
+ {
182
+ pattern: /xxx+/gi,
183
+ name: "xxx-placeholder",
184
+ severity: "warn",
185
+ message: "XXX placeholder pattern found",
186
+ },
187
+
188
+ // Hardcoded credentials
189
+ {
190
+ pattern: /password\s*[=:]\s*['"][^'"]{3,}['"]/gi,
191
+ name: "hardcoded-password",
192
+ severity: "critical",
193
+ message: "Hardcoded password detected",
194
+ },
195
+ {
196
+ pattern: /secret\s*[=:]\s*['"][^'"]{3,}['"]/gi,
197
+ name: "hardcoded-secret",
198
+ severity: "critical",
199
+ message: "Hardcoded secret detected",
200
+ },
201
+ {
202
+ pattern: /api[_-]?key\s*[=:]\s*['"][^'"]{8,}['"]/gi,
203
+ name: "hardcoded-api-key",
204
+ severity: "critical",
205
+ message: "Hardcoded API key detected",
206
+ },
207
+
208
+ // Common test/default credentials
209
+ {
210
+ pattern: /password.*['"](?:test|demo|admin|123|password)['"]/gi,
211
+ name: "test-password",
212
+ severity: "high",
213
+ message: "Test/default password detected",
214
+ },
215
+ {
216
+ pattern: /admin.*admin/gi,
217
+ name: "default-admin",
218
+ severity: "high",
219
+ message: "Default admin credentials pattern detected",
220
+ },
221
+
222
+ // Dangerous code patterns
223
+ {
224
+ pattern: /eval\s*\(/g,
225
+ name: "eval-usage",
226
+ severity: "high",
227
+ message: "eval() usage detected - security risk",
228
+ },
229
+ {
230
+ pattern: /new\s+Function\s*\(/g,
231
+ name: "function-constructor",
232
+ severity: "high",
233
+ message: "Function constructor usage - similar to eval",
234
+ },
235
+ {
236
+ pattern: /document\.write\s*\(/g,
237
+ name: "document-write",
238
+ severity: "warn",
239
+ message: "document.write() is deprecated and potentially dangerous",
240
+ },
241
+ {
242
+ pattern: /innerHTML\s*=/g,
243
+ name: "innerHTML-assignment",
244
+ severity: "warn",
245
+ message: "innerHTML assignment - potential XSS risk",
246
+ },
247
+ {
248
+ pattern: /dangerouslySetInnerHTML/g,
249
+ name: "dangerous-html",
250
+ severity: "warn",
251
+ message: "dangerouslySetInnerHTML - ensure content is sanitized",
252
+ },
253
+ {
254
+ pattern: /exec\s*\(\s*['"].*\$\{/g,
255
+ name: "command-injection",
256
+ severity: "critical",
257
+ message: "Potential command injection - user input in exec",
258
+ },
259
+ {
260
+ pattern: /child_process.*exec\s*\(/g,
261
+ name: "child-exec",
262
+ severity: "warn",
263
+ message: "child_process.exec - ensure input is sanitized",
264
+ },
265
+ ];
266
+ }
267
+
268
+ /**
269
+ * Validate file content
270
+ * @param {object} params - Validation parameters
271
+ * @param {string} params.content - File content to validate
272
+ * @param {string} params.path - File path (for context)
273
+ * @returns {object} Validation result
274
+ */
275
+ validate({ content, path }) {
276
+ // Skip if no content provided
277
+ if (!content) {
278
+ return { valid: true };
279
+ }
280
+
281
+ const violations = [];
282
+
283
+ // Check user-configured hallucination patterns
284
+ for (const { pattern, name, severity, message } of this.compiledHallucinations) {
285
+ const matches = content.match(pattern);
286
+ if (matches) {
287
+ violations.push({
288
+ rule: "hallucination-detected",
289
+ type: name,
290
+ severity: severity || "warn",
291
+ message: message || `Content contains hallucination pattern: ${name}`,
292
+ matches: matches.slice(0, 5), // Limit matches shown
293
+ matchCount: matches.length,
294
+ });
295
+ }
296
+ }
297
+
298
+ // Check user-configured forbidden patterns
299
+ for (const { pattern, name, severity, message } of this.compiledForbidden) {
300
+ const matches = content.match(pattern);
301
+ if (matches) {
302
+ violations.push({
303
+ rule: "forbidden-pattern",
304
+ type: name,
305
+ severity: severity || "critical",
306
+ message: message || `Content contains forbidden pattern: ${name}`,
307
+ matches: matches.slice(0, 5),
308
+ matchCount: matches.length,
309
+ });
310
+ }
311
+ }
312
+
313
+ // Check built-in patterns
314
+ for (const { pattern, name, severity, message } of this.builtInPatterns) {
315
+ // Reset regex lastIndex for global patterns
316
+ pattern.lastIndex = 0;
317
+ const matches = content.match(pattern);
318
+ if (matches) {
319
+ violations.push({
320
+ rule: this.getRuleType(name),
321
+ type: name,
322
+ severity,
323
+ message,
324
+ matches: matches.slice(0, 5),
325
+ matchCount: matches.length,
326
+ line: this.findLineNumber(content, matches[0]),
327
+ });
328
+ }
329
+ }
330
+
331
+ // Determine overall validity based on severity
332
+ const hasCritical = violations.some(v => v.severity === "critical");
333
+ const hasHigh = violations.some(v => v.severity === "high");
334
+
335
+ if (hasCritical || hasHigh) {
336
+ // Find the most severe violation
337
+ const mostSevere = violations.find(v => v.severity === "critical")
338
+ || violations.find(v => v.severity === "high")
339
+ || violations[0];
340
+
341
+ return {
342
+ valid: false,
343
+ rule: mostSevere.rule,
344
+ severity: mostSevere.severity,
345
+ message: mostSevere.message,
346
+ violations,
347
+ details: {
348
+ path,
349
+ totalViolations: violations.length,
350
+ criticalCount: violations.filter(v => v.severity === "critical").length,
351
+ highCount: violations.filter(v => v.severity === "high").length,
352
+ warnCount: violations.filter(v => v.severity === "warn").length,
353
+ },
354
+ };
355
+ }
356
+
357
+ // Return warnings but don't fail validation
358
+ if (violations.length > 0) {
359
+ return {
360
+ valid: true,
361
+ hasWarnings: true,
362
+ warnings: violations,
363
+ details: {
364
+ path,
365
+ totalWarnings: violations.length,
366
+ },
367
+ };
368
+ }
369
+
370
+ return { valid: true };
371
+ }
372
+
373
+ /**
374
+ * Get rule type from pattern name
375
+ * @param {string} name - Pattern name
376
+ * @returns {string} Rule type
377
+ */
378
+ getRuleType(name) {
379
+ if (name.includes("api") || name.includes("placeholder") || name.includes("fake") || name.includes("mock")) {
380
+ return "hallucination-detected";
381
+ }
382
+ if (name.includes("key") || name.includes("password") || name.includes("secret") || name.includes("token")) {
383
+ return "credential-detected";
384
+ }
385
+ if (name.includes("eval") || name.includes("exec") || name.includes("injection") || name.includes("html")) {
386
+ return "dangerous-code";
387
+ }
388
+ return "content-violation";
389
+ }
390
+
391
+ /**
392
+ * Find line number of a match in content
393
+ * @param {string} content - Full content
394
+ * @param {string} match - Match to find
395
+ * @returns {number} Line number (1-indexed)
396
+ */
397
+ findLineNumber(content, match) {
398
+ const index = content.indexOf(match);
399
+ if (index === -1) return -1;
400
+
401
+ const beforeMatch = content.substring(0, index);
402
+ return (beforeMatch.match(/\n/g) || []).length + 1;
403
+ }
404
+
405
+ /**
406
+ * Analyze content for risk assessment
407
+ * @param {string} content - Content to analyze
408
+ * @returns {object} Risk assessment
409
+ */
410
+ analyzeRisk(content) {
411
+ const result = this.validate({ content });
412
+
413
+ const riskScore = this.calculateRiskScore(result);
414
+
415
+ return {
416
+ riskLevel: riskScore > 70 ? "high" : riskScore > 40 ? "medium" : riskScore > 10 ? "low" : "none",
417
+ riskScore,
418
+ violations: result.violations || [],
419
+ warnings: result.warnings || [],
420
+ summary: this.generateSummary(result),
421
+ };
422
+ }
423
+
424
+ /**
425
+ * Calculate risk score from validation result
426
+ * @param {object} result - Validation result
427
+ * @returns {number} Risk score 0-100
428
+ */
429
+ calculateRiskScore(result) {
430
+ let score = 0;
431
+
432
+ const violations = result.violations || [];
433
+ const warnings = result.warnings || [];
434
+
435
+ for (const v of violations) {
436
+ if (v.severity === "critical") score += 30;
437
+ else if (v.severity === "high") score += 20;
438
+ else if (v.severity === "warn") score += 5;
439
+ }
440
+
441
+ for (const w of warnings) {
442
+ if (w.severity === "warn") score += 3;
443
+ }
444
+
445
+ return Math.min(100, score);
446
+ }
447
+
448
+ /**
449
+ * Generate human-readable summary
450
+ * @param {object} result - Validation result
451
+ * @returns {string} Summary text
452
+ */
453
+ generateSummary(result) {
454
+ if (result.valid && !result.hasWarnings) {
455
+ return "Content passed all validation checks";
456
+ }
457
+
458
+ const parts = [];
459
+ const violations = result.violations || [];
460
+ const warnings = result.warnings || [];
461
+
462
+ if (violations.length > 0) {
463
+ parts.push(`${violations.length} violation(s) found`);
464
+ }
465
+ if (warnings.length > 0) {
466
+ parts.push(`${warnings.length} warning(s)`);
467
+ }
468
+
469
+ return parts.join(", ");
470
+ }
471
+
472
+ /**
473
+ * Check if content contains specific pattern type
474
+ * @param {string} content - Content to check
475
+ * @param {string} patternType - Pattern type to check
476
+ * @returns {boolean} True if pattern found
477
+ */
478
+ hasPattern(content, patternType) {
479
+ const patterns = this.builtInPatterns.filter(p => p.name.includes(patternType));
480
+
481
+ for (const { pattern } of patterns) {
482
+ pattern.lastIndex = 0;
483
+ if (pattern.test(content)) {
484
+ return true;
485
+ }
486
+ }
487
+
488
+ return false;
489
+ }
490
+
491
+ /**
492
+ * Get all detected patterns in content
493
+ * @param {string} content - Content to scan
494
+ * @returns {Array} Array of detected patterns
495
+ */
496
+ getDetectedPatterns(content) {
497
+ const detected = [];
498
+
499
+ for (const { pattern, name, severity, message } of this.builtInPatterns) {
500
+ pattern.lastIndex = 0;
501
+ const matches = content.match(pattern);
502
+ if (matches) {
503
+ detected.push({
504
+ name,
505
+ severity,
506
+ message,
507
+ matchCount: matches.length,
508
+ samples: matches.slice(0, 3),
509
+ });
510
+ }
511
+ }
512
+
513
+ return detected;
514
+ }
515
+ }
516
+
517
+ module.exports = {
518
+ ContentValidator,
519
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Agent Firewall - Main Entry Point
3
+ *
4
+ * Exports all firewall components:
5
+ * - Configuration loader
6
+ * - Path validator
7
+ * - Command validator
8
+ * - Content validator
9
+ */
10
+
11
+ "use strict";
12
+
13
+ const { loadFirewallConfig, getDefaultConfig, saveFirewallConfig, initFirewallConfig, DEFAULT_CONFIG } = require("./config");
14
+ const { PathValidator } = require("./path-validator");
15
+ const { CommandValidator } = require("./command-validator");
16
+ const { ContentValidator } = require("./content-validator");
17
+
18
+ /**
19
+ * Create a complete firewall instance with all validators
20
+ * @param {string} configPath - Path to configuration file
21
+ * @returns {object} Firewall instance with all validators
22
+ */
23
+ function createFirewall(configPath) {
24
+ const config = loadFirewallConfig(configPath);
25
+
26
+ return {
27
+ config,
28
+ pathValidator: new PathValidator(config),
29
+ commandValidator: new CommandValidator(config),
30
+ contentValidator: new ContentValidator(config),
31
+
32
+ /**
33
+ * Validate an action
34
+ * @param {object} params - Validation parameters
35
+ * @returns {object} Combined validation result
36
+ */
37
+ validate(params) {
38
+ const { action, path, content, command } = params;
39
+ const violations = [];
40
+
41
+ // Validate path
42
+ if (path && (action === "write" || action === "delete")) {
43
+ const pathResult = this.pathValidator.validate({ action, path });
44
+ if (!pathResult.valid) {
45
+ violations.push(pathResult);
46
+ }
47
+ }
48
+
49
+ // Validate command
50
+ if (command && action === "execute") {
51
+ const cmdResult = this.commandValidator.validate({ command });
52
+ if (!cmdResult.valid) {
53
+ violations.push(cmdResult);
54
+ }
55
+ }
56
+
57
+ // Validate content
58
+ if (content && action === "write") {
59
+ const contentResult = this.contentValidator.validate({ content, path });
60
+ if (!contentResult.valid) {
61
+ violations.push(contentResult);
62
+ }
63
+ // Include warnings
64
+ if (contentResult.hasWarnings) {
65
+ violations.push({
66
+ valid: true,
67
+ isWarning: true,
68
+ warnings: contentResult.warnings,
69
+ });
70
+ }
71
+ }
72
+
73
+ const hasViolation = violations.some(v => !v.valid && !v.isWarning);
74
+ const hasWarnings = violations.some(v => v.isWarning || v.hasWarnings);
75
+
76
+ return {
77
+ allowed: !hasViolation,
78
+ violations: violations.filter(v => !v.valid && !v.isWarning),
79
+ warnings: violations.filter(v => v.isWarning || v.hasWarnings),
80
+ mode: config.mode,
81
+ };
82
+ },
83
+ };
84
+ }
85
+
86
+ module.exports = {
87
+ // Configuration
88
+ loadFirewallConfig,
89
+ getDefaultConfig,
90
+ saveFirewallConfig,
91
+ initFirewallConfig,
92
+ DEFAULT_CONFIG,
93
+
94
+ // Validators
95
+ PathValidator,
96
+ CommandValidator,
97
+ ContentValidator,
98
+
99
+ // Factory
100
+ createFirewall,
101
+ };