@vibecheckai/cli 3.5.0 → 3.5.2

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 (224) hide show
  1. package/bin/registry.js +214 -237
  2. package/bin/runners/cli-utils.js +33 -2
  3. package/bin/runners/context/analyzer.js +52 -1
  4. package/bin/runners/context/generators/cursor.js +2 -49
  5. package/bin/runners/context/git-context.js +3 -1
  6. package/bin/runners/context/team-conventions.js +33 -7
  7. package/bin/runners/lib/analysis-core.js +25 -5
  8. package/bin/runners/lib/analyzers.js +431 -481
  9. package/bin/runners/lib/default-config.js +127 -0
  10. package/bin/runners/lib/doctor/modules/security.js +3 -1
  11. package/bin/runners/lib/engine/ast-cache.js +210 -0
  12. package/bin/runners/lib/engine/auth-extractor.js +211 -0
  13. package/bin/runners/lib/engine/billing-extractor.js +112 -0
  14. package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
  15. package/bin/runners/lib/engine/env-extractor.js +207 -0
  16. package/bin/runners/lib/engine/express-extractor.js +208 -0
  17. package/bin/runners/lib/engine/extractors.js +849 -0
  18. package/bin/runners/lib/engine/index.js +207 -0
  19. package/bin/runners/lib/engine/repo-index.js +514 -0
  20. package/bin/runners/lib/engine/types.js +124 -0
  21. package/bin/runners/lib/engines/accessibility-engine.js +18 -218
  22. package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
  23. package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
  24. package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
  25. package/bin/runners/lib/engines/mock-data-engine.js +10 -53
  26. package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
  27. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
  28. package/bin/runners/lib/engines/type-aware-engine.js +39 -263
  29. package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
  30. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
  31. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
  32. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
  33. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
  34. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
  35. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
  36. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
  37. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
  38. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
  39. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
  40. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
  41. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
  42. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
  43. package/bin/runners/lib/entitlements-v2.js +73 -97
  44. package/bin/runners/lib/error-handler.js +44 -3
  45. package/bin/runners/lib/error-messages.js +289 -0
  46. package/bin/runners/lib/evidence-pack.js +7 -1
  47. package/bin/runners/lib/finding-id.js +69 -0
  48. package/bin/runners/lib/finding-sorter.js +89 -0
  49. package/bin/runners/lib/html-proof-report.js +700 -350
  50. package/bin/runners/lib/missions/plan.js +6 -46
  51. package/bin/runners/lib/missions/templates.js +0 -232
  52. package/bin/runners/lib/next-action.js +560 -0
  53. package/bin/runners/lib/prerequisites.js +149 -0
  54. package/bin/runners/lib/route-detection.js +137 -68
  55. package/bin/runners/lib/scan-output.js +91 -76
  56. package/bin/runners/lib/scan-runner.js +135 -0
  57. package/bin/runners/lib/schemas/ajv-validator.js +464 -0
  58. package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
  59. package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
  60. package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
  61. package/bin/runners/lib/schemas/run-request.schema.json +108 -0
  62. package/bin/runners/lib/schemas/validator.js +27 -0
  63. package/bin/runners/lib/schemas/verdict.schema.json +140 -0
  64. package/bin/runners/lib/ship-output-enterprise.js +23 -23
  65. package/bin/runners/lib/ship-output.js +75 -31
  66. package/bin/runners/lib/terminal-ui.js +6 -113
  67. package/bin/runners/lib/truth.js +351 -10
  68. package/bin/runners/lib/unified-cli-output.js +430 -603
  69. package/bin/runners/lib/unified-output.js +13 -9
  70. package/bin/runners/runAIAgent.js +10 -5
  71. package/bin/runners/runAgent.js +0 -3
  72. package/bin/runners/runAllowlist.js +389 -0
  73. package/bin/runners/runApprove.js +0 -33
  74. package/bin/runners/runAuth.js +73 -45
  75. package/bin/runners/runCheckpoint.js +51 -11
  76. package/bin/runners/runClassify.js +85 -21
  77. package/bin/runners/runContext.js +0 -3
  78. package/bin/runners/runDoctor.js +41 -28
  79. package/bin/runners/runEvidencePack.js +362 -0
  80. package/bin/runners/runFirewall.js +0 -3
  81. package/bin/runners/runFirewallHook.js +0 -3
  82. package/bin/runners/runFix.js +66 -76
  83. package/bin/runners/runGuard.js +18 -411
  84. package/bin/runners/runInit.js +113 -30
  85. package/bin/runners/runLabs.js +424 -0
  86. package/bin/runners/runMcp.js +19 -25
  87. package/bin/runners/runPolish.js +64 -240
  88. package/bin/runners/runPromptFirewall.js +12 -5
  89. package/bin/runners/runProve.js +57 -22
  90. package/bin/runners/runQuickstart.js +531 -0
  91. package/bin/runners/runReality.js +59 -68
  92. package/bin/runners/runReport.js +38 -33
  93. package/bin/runners/runRuntime.js +8 -5
  94. package/bin/runners/runScan.js +1413 -190
  95. package/bin/runners/runShip.js +113 -719
  96. package/bin/runners/runTruth.js +0 -3
  97. package/bin/runners/runValidate.js +13 -9
  98. package/bin/runners/runWatch.js +23 -14
  99. package/bin/scan.js +6 -1
  100. package/bin/vibecheck.js +204 -185
  101. package/mcp-server/deprecation-middleware.js +282 -0
  102. package/mcp-server/handlers/index.ts +15 -0
  103. package/mcp-server/handlers/tool-handler.ts +554 -0
  104. package/mcp-server/index-v1.js +698 -0
  105. package/mcp-server/index.js +210 -238
  106. package/mcp-server/lib/cache-wrapper.cjs +383 -0
  107. package/mcp-server/lib/error-envelope.js +138 -0
  108. package/mcp-server/lib/executor.ts +499 -0
  109. package/mcp-server/lib/index.ts +19 -0
  110. package/mcp-server/lib/rate-limiter.js +166 -0
  111. package/mcp-server/lib/sandbox.test.ts +519 -0
  112. package/mcp-server/lib/sandbox.ts +395 -0
  113. package/mcp-server/lib/types.ts +267 -0
  114. package/mcp-server/package.json +12 -3
  115. package/mcp-server/registry/tool-registry.js +794 -0
  116. package/mcp-server/registry/tools.json +605 -0
  117. package/mcp-server/registry.test.ts +334 -0
  118. package/mcp-server/tests/tier-gating.test.js +297 -0
  119. package/mcp-server/tier-auth.js +378 -45
  120. package/mcp-server/tools-v3.js +353 -442
  121. package/mcp-server/tsconfig.json +37 -0
  122. package/mcp-server/vibecheck-2.0-tools.js +14 -1
  123. package/package.json +1 -1
  124. package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
  125. package/bin/runners/lib/audit-logger.js +0 -532
  126. package/bin/runners/lib/authority/authorities/architecture.js +0 -364
  127. package/bin/runners/lib/authority/authorities/compliance.js +0 -341
  128. package/bin/runners/lib/authority/authorities/human.js +0 -343
  129. package/bin/runners/lib/authority/authorities/quality.js +0 -420
  130. package/bin/runners/lib/authority/authorities/security.js +0 -228
  131. package/bin/runners/lib/authority/index.js +0 -293
  132. package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
  133. package/bin/runners/lib/cli-charts.js +0 -368
  134. package/bin/runners/lib/cli-config-display.js +0 -405
  135. package/bin/runners/lib/cli-demo.js +0 -275
  136. package/bin/runners/lib/cli-errors.js +0 -438
  137. package/bin/runners/lib/cli-help-formatter.js +0 -439
  138. package/bin/runners/lib/cli-interactive-menu.js +0 -509
  139. package/bin/runners/lib/cli-prompts.js +0 -441
  140. package/bin/runners/lib/cli-scan-cards.js +0 -362
  141. package/bin/runners/lib/compliance-reporter.js +0 -710
  142. package/bin/runners/lib/conductor/index.js +0 -671
  143. package/bin/runners/lib/easy/README.md +0 -123
  144. package/bin/runners/lib/easy/index.js +0 -140
  145. package/bin/runners/lib/easy/interactive-wizard.js +0 -788
  146. package/bin/runners/lib/easy/one-click-firewall.js +0 -564
  147. package/bin/runners/lib/easy/zero-config-reality.js +0 -714
  148. package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
  149. package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
  150. package/bin/runners/lib/engines/confidence-scoring.js +0 -276
  151. package/bin/runners/lib/engines/context-detection.js +0 -264
  152. package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
  153. package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
  154. package/bin/runners/lib/engines/env-variables-engine.js +0 -458
  155. package/bin/runners/lib/engines/error-handling-engine.js +0 -437
  156. package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
  157. package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
  158. package/bin/runners/lib/engines/framework-detection.js +0 -508
  159. package/bin/runners/lib/engines/import-order-engine.js +0 -429
  160. package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
  161. package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
  162. package/bin/runners/lib/engines/orchestrator.js +0 -334
  163. package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
  164. package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
  165. package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
  166. package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
  167. package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
  168. package/bin/runners/lib/enhanced-features/index.js +0 -305
  169. package/bin/runners/lib/enhanced-output.js +0 -631
  170. package/bin/runners/lib/enterprise.js +0 -300
  171. package/bin/runners/lib/firewall/command-validator.js +0 -351
  172. package/bin/runners/lib/firewall/config.js +0 -341
  173. package/bin/runners/lib/firewall/content-validator.js +0 -519
  174. package/bin/runners/lib/firewall/index.js +0 -101
  175. package/bin/runners/lib/firewall/path-validator.js +0 -256
  176. package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
  177. package/bin/runners/lib/mcp-utils.js +0 -425
  178. package/bin/runners/lib/output/index.js +0 -1022
  179. package/bin/runners/lib/policy-engine.js +0 -652
  180. package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
  181. package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
  182. package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
  183. package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
  184. package/bin/runners/lib/polish/autofix/index.js +0 -200
  185. package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
  186. package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
  187. package/bin/runners/lib/polish/backend-checks.js +0 -148
  188. package/bin/runners/lib/polish/documentation-checks.js +0 -111
  189. package/bin/runners/lib/polish/frontend-checks.js +0 -168
  190. package/bin/runners/lib/polish/index.js +0 -71
  191. package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
  192. package/bin/runners/lib/polish/library-detection.js +0 -175
  193. package/bin/runners/lib/polish/performance-checks.js +0 -100
  194. package/bin/runners/lib/polish/security-checks.js +0 -148
  195. package/bin/runners/lib/polish/utils.js +0 -203
  196. package/bin/runners/lib/prompt-builder.js +0 -540
  197. package/bin/runners/lib/proof-certificate.js +0 -634
  198. package/bin/runners/lib/reality/accessibility-audit.js +0 -946
  199. package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
  200. package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
  201. package/bin/runners/lib/reality/performance-tracker.js +0 -1077
  202. package/bin/runners/lib/reality/scenario-generator.js +0 -1404
  203. package/bin/runners/lib/reality/visual-regression.js +0 -852
  204. package/bin/runners/lib/reality-profiler.js +0 -717
  205. package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
  206. package/bin/runners/lib/review/ai-code-review.js +0 -832
  207. package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
  208. package/bin/runners/lib/sbom-generator.js +0 -641
  209. package/bin/runners/lib/scan-output-enhanced.js +0 -512
  210. package/bin/runners/lib/security/owasp-scanner.js +0 -939
  211. package/bin/runners/lib/validators/contract-validator.js +0 -283
  212. package/bin/runners/lib/validators/dead-export-detector.js +0 -279
  213. package/bin/runners/lib/validators/dep-audit.js +0 -245
  214. package/bin/runners/lib/validators/env-validator.js +0 -319
  215. package/bin/runners/lib/validators/index.js +0 -120
  216. package/bin/runners/lib/validators/license-checker.js +0 -252
  217. package/bin/runners/lib/validators/route-validator.js +0 -290
  218. package/bin/runners/runAuthority.js +0 -528
  219. package/bin/runners/runConductor.js +0 -772
  220. package/bin/runners/runContainer.js +0 -366
  221. package/bin/runners/runEasy.js +0 -410
  222. package/bin/runners/runIaC.js +0 -372
  223. package/bin/runners/runVibe.js +0 -791
  224. package/mcp-server/tools.js +0 -495
@@ -1,519 +0,0 @@
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
- };
@@ -1,101 +0,0 @@
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
- };