@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,364 +0,0 @@
1
- /**
2
- * Architecture Authority - Automated architecture review
3
- *
4
- * Checks for:
5
- * - Import/export patterns
6
- * - Circular dependencies
7
- * - Layer violations
8
- * - Naming conventions
9
- * - File organization
10
- */
11
-
12
- "use strict";
13
-
14
- const crypto = require("crypto");
15
- const path = require("path");
16
-
17
- class ArchitectureAuthority {
18
- static description = "Architecture review (patterns, structure)";
19
- static automated = true;
20
- static tier = "pro";
21
-
22
- constructor(options = {}) {
23
- this.options = options;
24
- this.rules = this._initializeRules();
25
- }
26
-
27
- _initializeRules() {
28
- return {
29
- layerViolations: [
30
- {
31
- name: "ui-imports-db",
32
- pattern: /from\s+['"].*\/(database|db|prisma|models)\//,
33
- context: /(components|pages|views|ui)\//,
34
- message: "UI layer importing directly from database layer",
35
- severity: "high",
36
- },
37
- {
38
- name: "model-imports-ui",
39
- pattern: /from\s+['"].*\/(components|views|pages)\//,
40
- context: /(models|entities|database)\//,
41
- message: "Data layer importing from UI layer",
42
- severity: "high",
43
- },
44
- ],
45
- circularDependencies: {
46
- enabled: true,
47
- severity: "medium",
48
- },
49
- namingConventions: [
50
- {
51
- name: "component-naming",
52
- pattern: /^[A-Z][a-zA-Z0-9]*\.(tsx|jsx)$/,
53
- context: /components\//,
54
- message: "Component files should use PascalCase",
55
- severity: "low",
56
- },
57
- {
58
- name: "hook-naming",
59
- pattern: /^use[A-Z][a-zA-Z0-9]*\.(ts|tsx)$/,
60
- context: /hooks\//,
61
- message: "Hook files should start with 'use' prefix",
62
- severity: "low",
63
- },
64
- {
65
- name: "util-naming",
66
- pattern: /^[a-z][a-zA-Z0-9-]*\.(ts|js)$/,
67
- context: /(utils?|lib|helpers)\//,
68
- message: "Utility files should use camelCase or kebab-case",
69
- severity: "low",
70
- },
71
- ],
72
- importPatterns: [
73
- {
74
- name: "relative-import-depth",
75
- pattern: /from\s+['"]\.\.\/\.\.\/\.\.\/\.\.\//,
76
- message: "Import depth exceeds 3 levels - consider using path aliases",
77
- severity: "medium",
78
- },
79
- {
80
- name: "index-barrel-bloat",
81
- pattern: /export\s+\*\s+from/,
82
- message: "Barrel exports can cause bundle bloat - verify tree-shaking",
83
- severity: "low",
84
- },
85
- {
86
- name: "default-export-missing",
87
- pattern: /^(?!.*export\s+default).*\.tsx$/m,
88
- context: /(pages|app)\//,
89
- message: "Page/App files typically need default export",
90
- severity: "medium",
91
- },
92
- ],
93
- fileOrganization: [
94
- {
95
- name: "test-colocation",
96
- check: (files) => {
97
- const srcFiles = files.filter(f => f.path.match(/src\/.*\.(ts|tsx|js|jsx)$/));
98
- const testFiles = files.filter(f => f.path.match(/\.(test|spec)\.(ts|tsx|js|jsx)$/));
99
- const colocated = testFiles.filter(t => {
100
- const basePath = t.path.replace(/\.(test|spec)\.(ts|tsx|js|jsx)$/, "");
101
- return srcFiles.some(s => s.path.startsWith(basePath));
102
- });
103
- return {
104
- pass: colocated.length === testFiles.length,
105
- message: "Tests should be colocated with source files",
106
- severity: "low",
107
- };
108
- },
109
- },
110
- ],
111
- };
112
- }
113
-
114
- async review(payload) {
115
- const { files = [], diff = "", context = {} } = payload;
116
- const findings = [];
117
- const startTime = Date.now();
118
-
119
- // Analyze imports and exports in diff
120
- if (diff) {
121
- findings.push(...this._analyzeDiffPatterns(diff));
122
- }
123
-
124
- // Analyze file structure
125
- if (files.length > 0) {
126
- findings.push(...this._analyzeFileStructure(files));
127
- findings.push(...this._detectCircularDependencies(files));
128
- }
129
-
130
- // Check naming conventions
131
- findings.push(...this._checkNamingConventions(files));
132
-
133
- // Determine approval status
134
- const hasHigh = findings.some(f => f.severity === "high");
135
- const hasMedium = findings.some(f => f.severity === "medium");
136
-
137
- return {
138
- approved: !hasHigh,
139
- reason: hasHigh
140
- ? "Architecture violations found - review required"
141
- : hasMedium
142
- ? "Approved with architecture warnings"
143
- : findings.length > 0
144
- ? "Approved with minor suggestions"
145
- : "Architecture patterns look good",
146
- findings,
147
- signature: this._sign(findings),
148
- metadata: {
149
- analysisTimeMs: Date.now() - startTime,
150
- filesAnalyzed: files.length,
151
- rulesChecked: this._countRules(),
152
- },
153
- };
154
- }
155
-
156
- _analyzeDiffPatterns(diff) {
157
- const findings = [];
158
- const lines = diff.split("\n");
159
- let currentFile = "unknown";
160
- let lineNumber = 0;
161
-
162
- for (const line of lines) {
163
- // Track file context
164
- if (line.startsWith("+++") || line.startsWith("---")) {
165
- const match = line.match(/[ab]\/(.+)/);
166
- if (match) currentFile = match[1];
167
- continue;
168
- }
169
-
170
- if (line.startsWith("@@")) {
171
- const match = line.match(/@@ -\d+(?:,\d+)? \+(\d+)/);
172
- if (match) lineNumber = parseInt(match[1], 10);
173
- continue;
174
- }
175
-
176
- // Only check added lines
177
- if (line.startsWith("+") && !line.startsWith("+++")) {
178
- const addedContent = line.slice(1);
179
-
180
- // Check layer violations
181
- for (const rule of this.rules.layerViolations) {
182
- if (rule.context.test(currentFile) && rule.pattern.test(addedContent)) {
183
- findings.push({
184
- type: "layer-violation",
185
- rule: rule.name,
186
- severity: rule.severity,
187
- message: rule.message,
188
- file: currentFile,
189
- line: lineNumber,
190
- evidence: addedContent.trim().slice(0, 100),
191
- });
192
- }
193
- }
194
-
195
- // Check import patterns
196
- for (const rule of this.rules.importPatterns) {
197
- if (rule.pattern.test(addedContent)) {
198
- if (!rule.context || rule.context.test(currentFile)) {
199
- findings.push({
200
- type: "import-pattern",
201
- rule: rule.name,
202
- severity: rule.severity,
203
- message: rule.message,
204
- file: currentFile,
205
- line: lineNumber,
206
- evidence: addedContent.trim().slice(0, 100),
207
- });
208
- }
209
- }
210
- }
211
-
212
- lineNumber++;
213
- } else if (!line.startsWith("-")) {
214
- lineNumber++;
215
- }
216
- }
217
-
218
- return findings;
219
- }
220
-
221
- _analyzeFileStructure(files) {
222
- const findings = [];
223
-
224
- for (const rule of this.rules.fileOrganization) {
225
- if (typeof rule.check === "function") {
226
- const result = rule.check(files);
227
- if (!result.pass) {
228
- findings.push({
229
- type: "file-organization",
230
- rule: rule.name,
231
- severity: result.severity || "low",
232
- message: result.message,
233
- });
234
- }
235
- }
236
- }
237
-
238
- return findings;
239
- }
240
-
241
- _detectCircularDependencies(files) {
242
- const findings = [];
243
- const graph = new Map();
244
-
245
- // Build dependency graph
246
- for (const file of files) {
247
- if (!file.content) continue;
248
-
249
- const imports = [];
250
- const importRegex = /import\s+(?:.*?\s+from\s+)?['"]([^'"]+)['"]/g;
251
- let match;
252
-
253
- while ((match = importRegex.exec(file.content)) !== null) {
254
- const importPath = match[1];
255
- // Only track relative imports
256
- if (importPath.startsWith(".")) {
257
- const resolvedPath = this._resolveImportPath(file.path, importPath);
258
- imports.push(resolvedPath);
259
- }
260
- }
261
-
262
- graph.set(file.path, imports);
263
- }
264
-
265
- // Detect cycles using DFS
266
- const visited = new Set();
267
- const recursionStack = new Set();
268
-
269
- const detectCycle = (node, path = []) => {
270
- if (recursionStack.has(node)) {
271
- const cycleStart = path.indexOf(node);
272
- const cycle = path.slice(cycleStart);
273
- return { hasCycle: true, cycle: [...cycle, node] };
274
- }
275
-
276
- if (visited.has(node)) {
277
- return { hasCycle: false };
278
- }
279
-
280
- visited.add(node);
281
- recursionStack.add(node);
282
-
283
- const neighbors = graph.get(node) || [];
284
- for (const neighbor of neighbors) {
285
- const result = detectCycle(neighbor, [...path, node]);
286
- if (result.hasCycle) {
287
- return result;
288
- }
289
- }
290
-
291
- recursionStack.delete(node);
292
- return { hasCycle: false };
293
- };
294
-
295
- for (const node of graph.keys()) {
296
- visited.clear();
297
- recursionStack.clear();
298
- const result = detectCycle(node);
299
-
300
- if (result.hasCycle) {
301
- findings.push({
302
- type: "circular-dependency",
303
- severity: this.rules.circularDependencies.severity,
304
- message: "Circular dependency detected",
305
- evidence: result.cycle.join(" → "),
306
- });
307
- break; // Report only first cycle found
308
- }
309
- }
310
-
311
- return findings;
312
- }
313
-
314
- _checkNamingConventions(files) {
315
- const findings = [];
316
-
317
- for (const file of files) {
318
- const fileName = path.basename(file.path);
319
-
320
- for (const rule of this.rules.namingConventions) {
321
- if (rule.context.test(file.path)) {
322
- if (!rule.pattern.test(fileName)) {
323
- findings.push({
324
- type: "naming-convention",
325
- rule: rule.name,
326
- severity: rule.severity,
327
- message: rule.message,
328
- file: file.path,
329
- });
330
- }
331
- }
332
- }
333
- }
334
-
335
- return findings;
336
- }
337
-
338
- _resolveImportPath(fromPath, importPath) {
339
- const fromDir = path.dirname(fromPath);
340
- return path.normalize(path.join(fromDir, importPath));
341
- }
342
-
343
- _countRules() {
344
- return (
345
- this.rules.layerViolations.length +
346
- this.rules.namingConventions.length +
347
- this.rules.importPatterns.length +
348
- this.rules.fileOrganization.length +
349
- 1 // circular dependencies
350
- );
351
- }
352
-
353
- _sign(findings) {
354
- const timestamp = Date.now();
355
- const hash = crypto
356
- .createHash("sha256")
357
- .update(JSON.stringify({ findings: findings.length, timestamp }))
358
- .digest("hex")
359
- .slice(0, 16);
360
- return `arch_${timestamp}_${hash}_${findings.length}`;
361
- }
362
- }
363
-
364
- module.exports = { ArchitectureAuthority };
@@ -1,341 +0,0 @@
1
- /**
2
- * Compliance Authority - Automated compliance review
3
- *
4
- * Checks for:
5
- * - SOC2 compliance issues
6
- * - GDPR data handling
7
- * - HIPAA PHI handling
8
- * - PCI-DSS requirements
9
- * - License compliance
10
- */
11
-
12
- "use strict";
13
-
14
- const crypto = require("crypto");
15
-
16
- class ComplianceAuthority {
17
- static description = "Compliance check (SOC2, GDPR, HIPAA, etc.)";
18
- static automated = true;
19
- static tier = "pro";
20
-
21
- constructor(options = {}) {
22
- this.options = options;
23
- this.frameworks = options.frameworks || ["soc2", "gdpr"];
24
- this.rules = this._initializeRules();
25
- }
26
-
27
- _initializeRules() {
28
- return {
29
- soc2: [
30
- {
31
- name: "logging-required",
32
- pattern: /(authentication|login|logout|password|permission|access)/i,
33
- checkAuditLog: true,
34
- message: "Security events must be logged for SOC2 compliance",
35
- severity: "high",
36
- },
37
- {
38
- name: "encryption-at-rest",
39
- pattern: /\.encrypt|crypto\.|bcrypt|argon2/,
40
- inverse: true,
41
- context: /(password|secret|token|key)/i,
42
- message: "Sensitive data should be encrypted at rest",
43
- severity: "high",
44
- },
45
- {
46
- name: "access-control",
47
- pattern: /(isAdmin|isAuthenticated|hasPermission|authorize|checkRole)/i,
48
- context: /(route|endpoint|api|handler)/i,
49
- message: "API endpoints should have access control checks",
50
- severity: "medium",
51
- },
52
- ],
53
- gdpr: [
54
- {
55
- name: "pii-handling",
56
- pattern: /(email|phone|address|ssn|social[_-]?security|passport|license)/i,
57
- message: "Personal Identifiable Information detected - ensure GDPR compliance",
58
- severity: "medium",
59
- },
60
- {
61
- name: "consent-tracking",
62
- pattern: /(consent|gdpr|optIn|optOut|dataSubject)/i,
63
- context: /(user|customer|profile)/i,
64
- inverse: true,
65
- message: "User data handling should include consent management",
66
- severity: "high",
67
- },
68
- {
69
- name: "data-retention",
70
- pattern: /(delete|purge|anonymize|retention)/i,
71
- context: /(user|customer|pii)/i,
72
- inverse: true,
73
- message: "Consider data retention and right-to-be-forgotten requirements",
74
- severity: "medium",
75
- },
76
- {
77
- name: "data-export",
78
- pattern: /(export|download|portability)/i,
79
- context: /(user|customer|data)/i,
80
- inverse: true,
81
- message: "GDPR requires data portability capability",
82
- severity: "low",
83
- },
84
- ],
85
- hipaa: [
86
- {
87
- name: "phi-logging",
88
- pattern: /(patient|medical|health|diagnosis|prescription|treatment)/i,
89
- message: "Protected Health Information detected - ensure HIPAA compliance",
90
- severity: "critical",
91
- },
92
- {
93
- name: "phi-encryption",
94
- pattern: /\.encrypt|crypto\./,
95
- context: /(patient|medical|health)/i,
96
- inverse: true,
97
- message: "PHI must be encrypted in transit and at rest",
98
- severity: "critical",
99
- },
100
- {
101
- name: "access-audit",
102
- pattern: /(audit|log|track)/i,
103
- context: /(patient|medical|record)/i,
104
- inverse: true,
105
- message: "Access to PHI must be logged for HIPAA audit requirements",
106
- severity: "high",
107
- },
108
- ],
109
- pciDss: [
110
- {
111
- name: "card-data",
112
- pattern: /(cardNumber|cvv|expiry|pan|primaryAccountNumber)/i,
113
- message: "Payment card data detected - ensure PCI-DSS compliance",
114
- severity: "critical",
115
- },
116
- {
117
- name: "card-storage",
118
- pattern: /(save|store|persist).*card/i,
119
- message: "Storing payment card data requires PCI-DSS compliance",
120
- severity: "critical",
121
- },
122
- {
123
- name: "card-logging",
124
- pattern: /console\.(log|info|debug).*card/i,
125
- message: "Never log payment card data",
126
- severity: "critical",
127
- },
128
- ],
129
- licenses: [
130
- {
131
- name: "gpl-viral",
132
- pattern: /GPL|GNU General Public/i,
133
- context: /LICENSE|package\.json/,
134
- message: "GPL license detected - may require source disclosure",
135
- severity: "medium",
136
- },
137
- {
138
- name: "agpl-network",
139
- pattern: /AGPL|Affero/i,
140
- context: /LICENSE|package\.json/,
141
- message: "AGPL license detected - network use triggers disclosure",
142
- severity: "high",
143
- },
144
- ],
145
- };
146
- }
147
-
148
- async review(payload) {
149
- const { files = [], diff = "", context = {} } = payload;
150
- const findings = [];
151
- const startTime = Date.now();
152
-
153
- // Determine which frameworks to check
154
- const activeFrameworks = context.frameworks || this.frameworks;
155
-
156
- // Analyze diff content
157
- if (diff) {
158
- findings.push(...this._analyzeDiff(diff, activeFrameworks));
159
- }
160
-
161
- // Analyze files
162
- for (const file of files) {
163
- if (file.content) {
164
- findings.push(...this._analyzeFile(file.path || "unknown", file.content, activeFrameworks));
165
- }
166
- }
167
-
168
- // Check for missing compliance requirements
169
- findings.push(...this._checkMissingRequirements(files, activeFrameworks));
170
-
171
- // Determine approval status
172
- const hasCritical = findings.some(f => f.severity === "critical");
173
- const hasHigh = findings.some(f => f.severity === "high");
174
-
175
- return {
176
- approved: !hasCritical,
177
- reason: hasCritical
178
- ? "Critical compliance violations found - immediate action required"
179
- : hasHigh
180
- ? "Approved with compliance warnings - review required"
181
- : findings.length > 0
182
- ? "Approved with minor compliance notes"
183
- : "Compliance checks passed",
184
- findings,
185
- signature: this._sign(findings),
186
- metadata: {
187
- analysisTimeMs: Date.now() - startTime,
188
- filesAnalyzed: files.length,
189
- frameworksChecked: activeFrameworks,
190
- rulesChecked: this._countRules(activeFrameworks),
191
- },
192
- };
193
- }
194
-
195
- _analyzeDiff(diff, frameworks) {
196
- const findings = [];
197
- const lines = diff.split("\n");
198
- let currentFile = "unknown";
199
- let lineNumber = 0;
200
-
201
- for (const line of lines) {
202
- if (line.startsWith("+++") || line.startsWith("---")) {
203
- const match = line.match(/[ab]\/(.+)/);
204
- if (match) currentFile = match[1];
205
- continue;
206
- }
207
-
208
- if (line.startsWith("@@")) {
209
- const match = line.match(/@@ -\d+(?:,\d+)? \+(\d+)/);
210
- if (match) lineNumber = parseInt(match[1], 10);
211
- continue;
212
- }
213
-
214
- if (line.startsWith("+") && !line.startsWith("+++")) {
215
- const addedContent = line.slice(1);
216
-
217
- for (const framework of frameworks) {
218
- const rules = this.rules[framework] || [];
219
- for (const rule of rules) {
220
- if (this._matchesRule(addedContent, currentFile, rule)) {
221
- findings.push({
222
- type: "compliance-violation",
223
- framework,
224
- rule: rule.name,
225
- severity: rule.severity,
226
- message: rule.message,
227
- file: currentFile,
228
- line: lineNumber,
229
- evidence: addedContent.trim().slice(0, 100),
230
- });
231
- }
232
- }
233
- }
234
-
235
- lineNumber++;
236
- } else if (!line.startsWith("-")) {
237
- lineNumber++;
238
- }
239
- }
240
-
241
- return findings;
242
- }
243
-
244
- _analyzeFile(filePath, content, frameworks) {
245
- const findings = [];
246
- const lines = content.split("\n");
247
-
248
- for (let i = 0; i < lines.length; i++) {
249
- const line = lines[i];
250
-
251
- for (const framework of frameworks) {
252
- const rules = this.rules[framework] || [];
253
- for (const rule of rules) {
254
- if (this._matchesRule(line, filePath, rule)) {
255
- findings.push({
256
- type: "compliance-violation",
257
- framework,
258
- rule: rule.name,
259
- severity: rule.severity,
260
- message: rule.message,
261
- file: filePath,
262
- line: i + 1,
263
- evidence: line.trim().slice(0, 100),
264
- });
265
- }
266
- }
267
- }
268
- }
269
-
270
- return findings;
271
- }
272
-
273
- _matchesRule(content, filePath, rule) {
274
- // Check context filter first
275
- if (rule.context && !rule.context.test(content) && !rule.context.test(filePath)) {
276
- return false;
277
- }
278
-
279
- const matches = rule.pattern.test(content);
280
-
281
- // Handle inverse rules (checking for absence of something)
282
- if (rule.inverse) {
283
- return !matches;
284
- }
285
-
286
- return matches;
287
- }
288
-
289
- _checkMissingRequirements(files, frameworks) {
290
- const findings = [];
291
- const allContent = files.map(f => f.content || "").join("\n");
292
-
293
- // Check for missing privacy policy reference (GDPR)
294
- if (frameworks.includes("gdpr")) {
295
- if (!/(privacy[_-]?policy|gdpr|data[_-]?protection)/i.test(allContent)) {
296
- findings.push({
297
- type: "compliance-missing",
298
- framework: "gdpr",
299
- rule: "privacy-policy-reference",
300
- severity: "medium",
301
- message: "Consider adding privacy policy references for GDPR compliance",
302
- });
303
- }
304
- }
305
-
306
- // Check for missing audit logging setup (SOC2)
307
- if (frameworks.includes("soc2")) {
308
- if (!/(auditLog|securityLog|eventLog|audit\.log)/i.test(allContent)) {
309
- findings.push({
310
- type: "compliance-missing",
311
- framework: "soc2",
312
- rule: "audit-logging-setup",
313
- severity: "medium",
314
- message: "SOC2 requires audit logging infrastructure",
315
- });
316
- }
317
- }
318
-
319
- return findings;
320
- }
321
-
322
- _countRules(frameworks) {
323
- let count = 0;
324
- for (const framework of frameworks) {
325
- count += (this.rules[framework] || []).length;
326
- }
327
- return count;
328
- }
329
-
330
- _sign(findings) {
331
- const timestamp = Date.now();
332
- const hash = crypto
333
- .createHash("sha256")
334
- .update(JSON.stringify({ findings: findings.length, timestamp }))
335
- .digest("hex")
336
- .slice(0, 16);
337
- return `compl_${timestamp}_${hash}_${findings.length}`;
338
- }
339
- }
340
-
341
- module.exports = { ComplianceAuthority };