@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,433 +0,0 @@
1
- /**
2
- * Bundle Size Analyzer Engine
3
- * Detects:
4
- * - Large library imports that hurt bundle size
5
- * - Non-tree-shakeable imports
6
- * - Heavy dependencies that have lighter alternatives
7
- * - Dynamic imports that could be code-split
8
- * - Duplicate functionality across packages
9
- */
10
-
11
- const { getAST } = require("./ast-cache");
12
- const traverse = require("@babel/traverse").default;
13
- const t = require("@babel/types");
14
- const { shouldExcludeFile } = require("./file-filter");
15
-
16
- /**
17
- * Known heavy packages with size estimates and alternatives
18
- */
19
- const HEAVY_PACKAGES = {
20
- // Date/time libraries
21
- moment: {
22
- size: "290KB",
23
- minified: "72KB",
24
- alternatives: ["date-fns", "dayjs", "luxon"],
25
- message: "moment.js is large and mutable. Consider date-fns (tree-shakeable) or dayjs (2KB).",
26
- },
27
- "moment-timezone": {
28
- size: "900KB+",
29
- minified: "200KB+",
30
- alternatives: ["date-fns-tz", "luxon"],
31
- message: "moment-timezone is very large. Consider date-fns-tz or native Intl API.",
32
- },
33
-
34
- // Utility libraries
35
- lodash: {
36
- size: "530KB",
37
- minified: "72KB",
38
- alternatives: ["lodash-es", "lodash/[function]", "native ES"],
39
- message: "Full lodash import adds ~70KB. Import individual functions or use lodash-es.",
40
- checkTreeShaking: true,
41
- },
42
- underscore: {
43
- size: "60KB",
44
- minified: "18KB",
45
- alternatives: ["native ES", "lodash-es"],
46
- message: "underscore has native ES alternatives for most functions.",
47
- },
48
- ramda: {
49
- size: "240KB",
50
- minified: "50KB",
51
- alternatives: ["native ES", "individual imports"],
52
- message: "Consider importing only needed Ramda functions.",
53
- checkTreeShaking: true,
54
- },
55
-
56
- // UI frameworks
57
- "@material-ui/core": {
58
- size: "varies",
59
- minified: "300KB+",
60
- alternatives: ["@mui/material with tree-shaking"],
61
- message: "Ensure you're importing MUI components individually, not from root.",
62
- checkTreeShaking: true,
63
- },
64
- antd: {
65
- size: "2MB+",
66
- minified: "500KB+",
67
- alternatives: ["individual antd imports"],
68
- message: "Import antd components individually to enable tree-shaking.",
69
- checkTreeShaking: true,
70
- },
71
-
72
- // Visualization
73
- "chart.js": {
74
- size: "200KB",
75
- minified: "60KB",
76
- alternatives: ["lightweight-charts", "uPlot"],
77
- message: "chart.js is large. For simple charts, consider lighter alternatives.",
78
- },
79
- d3: {
80
- size: "500KB+",
81
- minified: "100KB+",
82
- alternatives: ["d3 micro-libraries", "visx"],
83
- message: "Import only needed d3 modules (d3-scale, d3-shape) instead of full d3.",
84
- checkTreeShaking: true,
85
- },
86
-
87
- // Animation
88
- "framer-motion": {
89
- size: "130KB",
90
- minified: "45KB",
91
- alternatives: ["motion/react", "@formkit/auto-animate"],
92
- message: "framer-motion is large. For simple animations, consider CSS or lighter libs.",
93
- },
94
- gsap: {
95
- size: "60KB",
96
- minified: "20KB",
97
- alternatives: ["CSS animations", "Web Animations API"],
98
- message: "For simple animations, CSS or Web Animations API may be sufficient.",
99
- },
100
-
101
- // Validation
102
- yup: {
103
- size: "45KB",
104
- minified: "15KB",
105
- alternatives: ["zod", "valibot"],
106
- message: "yup is heavier than zod or valibot. Consider switching if bundle size matters.",
107
- },
108
- joi: {
109
- size: "150KB",
110
- minified: "40KB",
111
- alternatives: ["zod", "valibot"],
112
- message: "joi is designed for Node.js. For browser, use zod or valibot.",
113
- },
114
-
115
- // PDF generation
116
- pdfkit: {
117
- size: "2MB+",
118
- minified: "500KB+",
119
- alternatives: ["jspdf", "server-side generation"],
120
- message: "Consider generating PDFs server-side to reduce client bundle.",
121
- },
122
-
123
- // State management
124
- redux: {
125
- size: "20KB",
126
- minified: "7KB",
127
- alternatives: ["zustand", "jotai", "valtio"],
128
- message: "For simpler state, zustand (1KB) or jotai may be sufficient.",
129
- },
130
-
131
- // HTTP clients
132
- axios: {
133
- size: "30KB",
134
- minified: "13KB",
135
- alternatives: ["native fetch", "ky", "redaxios"],
136
- message: "Native fetch or ky (3KB) may be sufficient for most use cases.",
137
- },
138
-
139
- // Crypto
140
- "crypto-js": {
141
- size: "200KB",
142
- minified: "50KB",
143
- alternatives: ["Web Crypto API", "individual modules"],
144
- message: "Use Web Crypto API for browser or import only needed modules.",
145
- checkTreeShaking: true,
146
- },
147
-
148
- // UUID
149
- uuid: {
150
- size: "15KB",
151
- minified: "5KB",
152
- alternatives: ["crypto.randomUUID()", "nanoid"],
153
- message: "Modern browsers support crypto.randomUUID(). nanoid is only 130B.",
154
- },
155
- };
156
-
157
- /**
158
- * Non-tree-shakeable import patterns
159
- */
160
- const NON_TREESHAKEABLE_PATTERNS = [
161
- // Namespace imports from large libraries
162
- { pattern: /import\s+\*\s+as\s+\w+\s+from\s+['"]lodash['"]/, lib: "lodash" },
163
- { pattern: /import\s+\*\s+as\s+\w+\s+from\s+['"]ramda['"]/, lib: "ramda" },
164
- { pattern: /import\s+\*\s+as\s+\w+\s+from\s+['"]d3['"]/, lib: "d3" },
165
-
166
- // Default imports from libraries that should use named imports
167
- { pattern: /import\s+\w+\s+from\s+['"]lodash['"]/, lib: "lodash" },
168
- { pattern: /import\s+\w+\s+from\s+['"]@material-ui\/core['"]/, lib: "@material-ui/core" },
169
- { pattern: /import\s+\w+\s+from\s+['"]antd['"]/, lib: "antd" },
170
-
171
- // Importing entire icon sets
172
- { pattern: /import\s+\*\s+as\s+\w+\s+from\s+['"]@?[\w-]+\/icons/, lib: "icons" },
173
- { pattern: /import\s+\{\s*\*\s*\}\s+from\s+['"]lucide-react['"]/, lib: "lucide" },
174
- ];
175
-
176
- /**
177
- * Server-only packages that shouldn't be in client bundles
178
- */
179
- const SERVER_ONLY_PACKAGES = [
180
- "fs",
181
- "path",
182
- "crypto",
183
- "http",
184
- "https",
185
- "net",
186
- "child_process",
187
- "bcrypt",
188
- "bcryptjs",
189
- "@prisma/client",
190
- "pg",
191
- "mysql2",
192
- "mongodb",
193
- "redis",
194
- "nodemailer",
195
- "sharp",
196
- ];
197
-
198
- function snippetForLine(lines, line) {
199
- return lines[line - 1] ? lines[line - 1].trim() : "";
200
- }
201
-
202
- /**
203
- * Check if file is a client-side file
204
- */
205
- function isClientFile(filePath, code) {
206
- const normalizedPath = filePath.replace(/\\/g, "/");
207
-
208
- // Check for "use client" directive
209
- if (/['"]use client['"]/.test(code)) return true;
210
-
211
- // Check path patterns
212
- const clientPatterns = [
213
- /\/components\//,
214
- /\/pages\//,
215
- /\/app\/.*\/page\./,
216
- /\/src\/.*\.(tsx?|jsx?)$/,
217
- /\/client\//,
218
- /\/web\//,
219
- /\/frontend\//,
220
- ];
221
-
222
- const serverPatterns = [
223
- /\/api\//,
224
- /\/server\//,
225
- /\/backend\//,
226
- /\/lib\/server/,
227
- /\.server\./,
228
- /\/actions\//,
229
- ];
230
-
231
- // Server patterns take precedence
232
- if (serverPatterns.some(p => p.test(normalizedPath))) return false;
233
- if (clientPatterns.some(p => p.test(normalizedPath))) return true;
234
-
235
- // Check for "use server" directive
236
- if (/['"]use server['"]/.test(code)) return false;
237
-
238
- // Default to client for tsx/jsx files
239
- return /\.(tsx|jsx)$/.test(normalizedPath);
240
- }
241
-
242
- /**
243
- * Analyze bundle size issues
244
- */
245
- function analyzeBundleSize(code, filePath) {
246
- const findings = [];
247
-
248
- if (shouldExcludeFile(filePath)) return findings;
249
-
250
- const ast = getAST(code, filePath);
251
- if (!ast) return findings;
252
-
253
- const lines = code.split("\n");
254
- const isClient = isClientFile(filePath, code);
255
- const importedPackages = new Set();
256
-
257
- traverse(ast, {
258
- ImportDeclaration(path) {
259
- const source = path.node.source.value;
260
- const loc = path.node.loc?.start;
261
- if (!loc) return;
262
-
263
- // Get the root package name
264
- const packageName = source.startsWith("@")
265
- ? source.split("/").slice(0, 2).join("/")
266
- : source.split("/")[0];
267
-
268
- importedPackages.add(packageName);
269
-
270
- // Check for heavy packages
271
- const heavyPkg = HEAVY_PACKAGES[packageName];
272
- if (heavyPkg) {
273
- const specifiers = path.node.specifiers;
274
- const isNamespaceImport = specifiers.some(s => t.isImportNamespaceSpecifier(s));
275
- const isDefaultImport = specifiers.some(s => t.isImportDefaultSpecifier(s));
276
-
277
- // Check if tree-shaking is being prevented
278
- let isTreeShakeIssue = false;
279
- if (heavyPkg.checkTreeShaking) {
280
- // Namespace import prevents tree-shaking
281
- if (isNamespaceImport) isTreeShakeIssue = true;
282
- // Importing from root instead of subpath
283
- if (isDefaultImport && source === packageName) isTreeShakeIssue = true;
284
- }
285
-
286
- // Only warn for client bundles or tree-shake issues
287
- if (isClient || isTreeShakeIssue) {
288
- findings.push({
289
- type: "heavy_dependency",
290
- severity: isTreeShakeIssue ? "WARN" : "INFO",
291
- category: "BundleSize",
292
- file: filePath,
293
- line: loc.line,
294
- column: loc.column,
295
- title: `Heavy package: ${packageName} (~${heavyPkg.minified} minified)`,
296
- message: heavyPkg.message,
297
- codeSnippet: snippetForLine(lines, loc.line),
298
- confidence: isTreeShakeIssue ? "high" : "med",
299
- fixHint: `Consider: ${heavyPkg.alternatives.join(", ")}`,
300
- });
301
- }
302
- }
303
-
304
- // Check for server-only packages in client code
305
- if (isClient && SERVER_ONLY_PACKAGES.includes(packageName)) {
306
- findings.push({
307
- type: "server_only_import",
308
- severity: "BLOCK",
309
- category: "BundleSize",
310
- file: filePath,
311
- line: loc.line,
312
- column: loc.column,
313
- title: `Server-only package in client bundle: ${packageName}`,
314
- message: `'${packageName}' should not be imported in client-side code.`,
315
- codeSnippet: snippetForLine(lines, loc.line),
316
- confidence: "high",
317
- fixHint: "Move this import to a server component or API route",
318
- });
319
- }
320
-
321
- // Check for non-tree-shakeable patterns
322
- const importLine = code.substring(path.node.start, path.node.end);
323
- for (const { pattern, lib } of NON_TREESHAKEABLE_PATTERNS) {
324
- if (pattern.test(importLine)) {
325
- findings.push({
326
- type: "non_treeshakeable",
327
- severity: "WARN",
328
- category: "BundleSize",
329
- file: filePath,
330
- line: loc.line,
331
- column: loc.column,
332
- title: `Non-tree-shakeable import from ${lib}`,
333
- message: "This import pattern prevents tree-shaking, including the entire library.",
334
- codeSnippet: snippetForLine(lines, loc.line),
335
- confidence: "high",
336
- fixHint: `Import only what you need: import { specificFn } from '${lib}'`,
337
- });
338
- break;
339
- }
340
- }
341
-
342
- // Check for large icon imports
343
- if (/icons?/i.test(source)) {
344
- const specifiers = path.node.specifiers;
345
- const namedImports = specifiers.filter(s => t.isImportSpecifier(s));
346
-
347
- if (namedImports.length > 20) {
348
- findings.push({
349
- type: "large_icon_import",
350
- severity: "INFO",
351
- category: "BundleSize",
352
- file: filePath,
353
- line: loc.line,
354
- column: loc.column,
355
- title: `Large icon import (${namedImports.length} icons)`,
356
- message: "Consider code-splitting or using dynamic imports for icons.",
357
- codeSnippet: snippetForLine(lines, loc.line),
358
- confidence: "low",
359
- fixHint: "Use dynamic imports: const Icon = dynamic(() => import('...'))",
360
- });
361
- }
362
- }
363
- },
364
-
365
- // Check for dynamic imports that could benefit from code splitting
366
- CallExpression(path) {
367
- const callee = path.node.callee;
368
- const loc = path.node.loc?.start;
369
- if (!loc) return;
370
-
371
- // Check import() calls
372
- if (t.isImport(callee)) {
373
- const arg = path.node.arguments[0];
374
- if (t.isStringLiteral(arg)) {
375
- const importPath = arg.value;
376
- const packageName = importPath.startsWith("@")
377
- ? importPath.split("/").slice(0, 2).join("/")
378
- : importPath.split("/")[0];
379
-
380
- // Heavy packages being dynamically imported - good!
381
- if (HEAVY_PACKAGES[packageName]) {
382
- // This is actually good practice, just note it
383
- }
384
- }
385
- }
386
-
387
- // Check require() calls (CommonJS)
388
- if (t.isIdentifier(callee, { name: "require" })) {
389
- const arg = path.node.arguments[0];
390
- if (t.isStringLiteral(arg)) {
391
- const importPath = arg.value;
392
- const packageName = importPath.startsWith("@")
393
- ? importPath.split("/").slice(0, 2).join("/")
394
- : importPath.split("/")[0];
395
-
396
- if (isClient && SERVER_ONLY_PACKAGES.includes(packageName)) {
397
- findings.push({
398
- type: "server_only_require",
399
- severity: "BLOCK",
400
- category: "BundleSize",
401
- file: filePath,
402
- line: loc.line,
403
- column: loc.column,
404
- title: `Server-only require in client bundle: ${packageName}`,
405
- message: `'${packageName}' should not be required in client-side code.`,
406
- codeSnippet: snippetForLine(lines, loc.line),
407
- confidence: "high",
408
- fixHint: "Move this require to a server component or API route",
409
- });
410
- }
411
- }
412
- }
413
- },
414
- });
415
-
416
- return findings;
417
- }
418
-
419
- /**
420
- * Get recommended alternatives for a package
421
- */
422
- function getAlternatives(packageName) {
423
- const pkg = HEAVY_PACKAGES[packageName];
424
- return pkg ? pkg.alternatives : [];
425
- }
426
-
427
- module.exports = {
428
- analyzeBundleSize,
429
- getAlternatives,
430
- HEAVY_PACKAGES,
431
- SERVER_ONLY_PACKAGES,
432
- isClientFile,
433
- };
@@ -1,276 +0,0 @@
1
- /**
2
- * Standardized Confidence Scoring Module
3
- *
4
- * Provides consistent confidence scoring across all vibecheck engines.
5
- *
6
- * Confidence Scale (0-1):
7
- * - 1.0 (HIGH): Definitely an issue, AST-verified, high certainty
8
- * - 0.8 (MEDIUM): Likely an issue, pattern-matched with context
9
- * - 0.5 (LOW): Possibly an issue, needs manual verification
10
- * - 0.3 (HINT): Potential improvement, informational only
11
- *
12
- * Legacy string values are mapped:
13
- * - "high" → 1.0
14
- * - "med" → 0.8
15
- * - "low" → 0.5
16
- */
17
-
18
- /**
19
- * Confidence levels with numeric values
20
- */
21
- const CONFIDENCE = {
22
- // Definite issues - AST verified, no false positives expected
23
- DEFINITE: 1.0,
24
- HIGH: 1.0,
25
-
26
- // Likely issues - pattern matched with good context
27
- LIKELY: 0.8,
28
- MEDIUM: 0.8,
29
- MED: 0.8,
30
-
31
- // Possible issues - lexical match, needs verification
32
- POSSIBLE: 0.5,
33
- LOW: 0.5,
34
-
35
- // Hints - informational, may not be issues
36
- HINT: 0.3,
37
- INFO: 0.3,
38
- };
39
-
40
- /**
41
- * Convert legacy string confidence to numeric
42
- */
43
- function normalizeConfidence(value) {
44
- if (typeof value === "number") {
45
- return Math.max(0, Math.min(1, value));
46
- }
47
-
48
- if (typeof value === "string") {
49
- const key = value.toUpperCase();
50
- if (CONFIDENCE[key] !== undefined) {
51
- return CONFIDENCE[key];
52
- }
53
-
54
- // Legacy mappings
55
- switch (value.toLowerCase()) {
56
- case "high":
57
- return CONFIDENCE.HIGH;
58
- case "med":
59
- case "medium":
60
- return CONFIDENCE.MEDIUM;
61
- case "low":
62
- return CONFIDENCE.LOW;
63
- case "info":
64
- case "hint":
65
- return CONFIDENCE.HINT;
66
- default:
67
- return CONFIDENCE.MEDIUM; // Default fallback
68
- }
69
- }
70
-
71
- return CONFIDENCE.MEDIUM;
72
- }
73
-
74
- /**
75
- * Get confidence label from numeric value
76
- */
77
- function getConfidenceLabel(value) {
78
- const normalized = normalizeConfidence(value);
79
-
80
- if (normalized >= 0.9) return "high";
81
- if (normalized >= 0.6) return "med";
82
- if (normalized >= 0.4) return "low";
83
- return "hint";
84
- }
85
-
86
- /**
87
- * Severity levels (aligned with SARIF)
88
- */
89
- const SEVERITY = {
90
- BLOCK: "error", // Must fix before shipping
91
- WARN: "warning", // Should fix, but not blocking
92
- INFO: "note", // Informational
93
- };
94
-
95
- /**
96
- * Map internal severity to SARIF level
97
- */
98
- function toSarifLevel(severity) {
99
- switch (severity?.toUpperCase()) {
100
- case "BLOCK":
101
- case "ERROR":
102
- case "CRITICAL":
103
- return "error";
104
- case "WARN":
105
- case "WARNING":
106
- case "HIGH":
107
- return "warning";
108
- case "INFO":
109
- case "LOW":
110
- case "NOTE":
111
- default:
112
- return "note";
113
- }
114
- }
115
-
116
- /**
117
- * Confidence modifiers based on context
118
- */
119
- const CONFIDENCE_MODIFIERS = {
120
- // Increase confidence
121
- AST_VERIFIED: 0.2, // Finding verified via AST analysis
122
- PATTERN_CONTEXT: 0.1, // Pattern has surrounding context
123
- MULTIPLE_EVIDENCE: 0.1, // Multiple pieces of evidence
124
-
125
- // Decrease confidence
126
- LEXICAL_ONLY: -0.2, // Only lexical/regex match
127
- POSSIBLE_FALSE_POSITIVE: -0.3, // Known false positive pattern nearby
128
- IN_COMMENT: -0.3, // Found in comment
129
- IN_STRING: -0.2, // Found in string literal
130
- TEST_FILE: -0.4, // In test file
131
- CONFIG_FILE: -0.2, // In config file
132
- };
133
-
134
- /**
135
- * Calculate confidence with modifiers
136
- */
137
- function calculateConfidence(baseConfidence, modifiers = []) {
138
- let confidence = normalizeConfidence(baseConfidence);
139
-
140
- for (const modifier of modifiers) {
141
- if (typeof modifier === "string" && CONFIDENCE_MODIFIERS[modifier]) {
142
- confidence += CONFIDENCE_MODIFIERS[modifier];
143
- } else if (typeof modifier === "number") {
144
- confidence += modifier;
145
- }
146
- }
147
-
148
- // Clamp to valid range
149
- return Math.max(0, Math.min(1, confidence));
150
- }
151
-
152
- /**
153
- * Create a standardized finding object
154
- */
155
- function createFinding({
156
- type,
157
- severity = "WARN",
158
- category,
159
- file,
160
- line = 0,
161
- column = 0,
162
- title,
163
- message,
164
- codeSnippet = "",
165
- confidence = CONFIDENCE.MEDIUM,
166
- fixHint = "",
167
- evidence = [],
168
- modifiers = [],
169
- }) {
170
- const normalizedConfidence = calculateConfidence(confidence, modifiers);
171
-
172
- return {
173
- type,
174
- severity: severity.toUpperCase(),
175
- category,
176
- file,
177
- line,
178
- column,
179
- title,
180
- message,
181
- codeSnippet,
182
- confidence: getConfidenceLabel(normalizedConfidence),
183
- confidenceScore: normalizedConfidence,
184
- fixHint: fixHint || undefined,
185
- evidence: evidence.length > 0 ? evidence : undefined,
186
- };
187
- }
188
-
189
- /**
190
- * Filter findings by minimum confidence threshold
191
- */
192
- function filterByConfidence(findings, minConfidence = 0.3) {
193
- const threshold = normalizeConfidence(minConfidence);
194
-
195
- return findings.filter(finding => {
196
- const score = finding.confidenceScore !== undefined
197
- ? finding.confidenceScore
198
- : normalizeConfidence(finding.confidence);
199
- return score >= threshold;
200
- });
201
- }
202
-
203
- /**
204
- * Sort findings by confidence (highest first)
205
- */
206
- function sortByConfidence(findings) {
207
- return [...findings].sort((a, b) => {
208
- const scoreA = a.confidenceScore ?? normalizeConfidence(a.confidence);
209
- const scoreB = b.confidenceScore ?? normalizeConfidence(b.confidence);
210
- return scoreB - scoreA;
211
- });
212
- }
213
-
214
- /**
215
- * Group findings by confidence level
216
- */
217
- function groupByConfidence(findings) {
218
- return {
219
- high: findings.filter(f => normalizeConfidence(f.confidence) >= 0.9),
220
- medium: findings.filter(f => {
221
- const c = normalizeConfidence(f.confidence);
222
- return c >= 0.6 && c < 0.9;
223
- }),
224
- low: findings.filter(f => {
225
- const c = normalizeConfidence(f.confidence);
226
- return c >= 0.4 && c < 0.6;
227
- }),
228
- hint: findings.filter(f => normalizeConfidence(f.confidence) < 0.4),
229
- };
230
- }
231
-
232
- /**
233
- * Calculate overall confidence score for a scan
234
- */
235
- function calculateOverallScore(findings) {
236
- if (findings.length === 0) return 1.0; // No issues = high confidence
237
-
238
- // Weight by severity
239
- const weights = {
240
- BLOCK: 3,
241
- WARN: 2,
242
- INFO: 1,
243
- };
244
-
245
- let totalWeight = 0;
246
- let weightedSum = 0;
247
-
248
- for (const finding of findings) {
249
- const weight = weights[finding.severity?.toUpperCase()] || 1;
250
- const confidence = finding.confidenceScore ?? normalizeConfidence(finding.confidence);
251
-
252
- totalWeight += weight;
253
- weightedSum += confidence * weight;
254
- }
255
-
256
- // Invert - higher issues = lower score
257
- return 1 - (weightedSum / totalWeight) * 0.5;
258
- }
259
-
260
- module.exports = {
261
- // Constants
262
- CONFIDENCE,
263
- SEVERITY,
264
- CONFIDENCE_MODIFIERS,
265
-
266
- // Functions
267
- normalizeConfidence,
268
- getConfidenceLabel,
269
- toSarifLevel,
270
- calculateConfidence,
271
- createFinding,
272
- filterByConfidence,
273
- sortByConfidence,
274
- groupByConfidence,
275
- calculateOverallScore,
276
- };