@vibecheckai/cli 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/bin/registry.js +243 -152
  2. package/bin/runners/cli-utils.js +2 -33
  3. package/bin/runners/context/generators/cursor.js +49 -2
  4. package/bin/runners/lib/agent-firewall/learning/learning-engine.js +849 -0
  5. package/bin/runners/lib/analyzers.js +544 -19
  6. package/bin/runners/lib/audit-logger.js +532 -0
  7. package/bin/runners/lib/authority/authorities/architecture.js +364 -0
  8. package/bin/runners/lib/authority/authorities/compliance.js +341 -0
  9. package/bin/runners/lib/authority/authorities/human.js +343 -0
  10. package/bin/runners/lib/authority/authorities/quality.js +420 -0
  11. package/bin/runners/lib/authority/authorities/security.js +228 -0
  12. package/bin/runners/lib/authority/index.js +293 -0
  13. package/bin/runners/lib/authority-badge.js +425 -425
  14. package/bin/runners/lib/bundle/bundle-intelligence.js +846 -0
  15. package/bin/runners/lib/cli-charts.js +368 -0
  16. package/bin/runners/lib/cli-config-display.js +405 -0
  17. package/bin/runners/lib/cli-demo.js +275 -0
  18. package/bin/runners/lib/cli-errors.js +438 -0
  19. package/bin/runners/lib/cli-help-formatter.js +439 -0
  20. package/bin/runners/lib/cli-interactive-menu.js +509 -0
  21. package/bin/runners/lib/cli-prompts.js +441 -0
  22. package/bin/runners/lib/cli-scan-cards.js +362 -0
  23. package/bin/runners/lib/compliance-reporter.js +710 -0
  24. package/bin/runners/lib/conductor/index.js +671 -0
  25. package/bin/runners/lib/easy/README.md +123 -0
  26. package/bin/runners/lib/easy/index.js +140 -0
  27. package/bin/runners/lib/easy/interactive-wizard.js +788 -0
  28. package/bin/runners/lib/easy/one-click-firewall.js +564 -0
  29. package/bin/runners/lib/easy/zero-config-reality.js +714 -0
  30. package/bin/runners/lib/engines/accessibility-engine.js +218 -18
  31. package/bin/runners/lib/engines/api-consistency-engine.js +335 -30
  32. package/bin/runners/lib/engines/async-patterns-engine.js +444 -0
  33. package/bin/runners/lib/engines/bundle-size-engine.js +433 -0
  34. package/bin/runners/lib/engines/confidence-scoring.js +276 -0
  35. package/bin/runners/lib/engines/context-detection.js +264 -0
  36. package/bin/runners/lib/engines/cross-file-analysis-engine.js +292 -27
  37. package/bin/runners/lib/engines/database-patterns-engine.js +429 -0
  38. package/bin/runners/lib/engines/duplicate-code-engine.js +354 -0
  39. package/bin/runners/lib/engines/empty-catch-engine.js +127 -17
  40. package/bin/runners/lib/engines/env-variables-engine.js +458 -0
  41. package/bin/runners/lib/engines/error-handling-engine.js +437 -0
  42. package/bin/runners/lib/engines/false-positive-prevention.js +630 -0
  43. package/bin/runners/lib/engines/framework-adapters/index.js +607 -0
  44. package/bin/runners/lib/engines/framework-detection.js +508 -0
  45. package/bin/runners/lib/engines/import-order-engine.js +429 -0
  46. package/bin/runners/lib/engines/mock-data-engine.js +53 -10
  47. package/bin/runners/lib/engines/naming-conventions-engine.js +544 -0
  48. package/bin/runners/lib/engines/noise-reduction-engine.js +452 -0
  49. package/bin/runners/lib/engines/orchestrator.js +334 -0
  50. package/bin/runners/lib/engines/performance-issues-engine.js +176 -36
  51. package/bin/runners/lib/engines/react-patterns-engine.js +457 -0
  52. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +382 -54
  53. package/bin/runners/lib/engines/type-aware-engine.js +263 -39
  54. package/bin/runners/lib/engines/vibecheck-engines/index.js +122 -13
  55. package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +806 -0
  56. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +373 -73
  57. package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +577 -0
  58. package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +543 -0
  59. package/bin/runners/lib/engines/vibecheck-engines.js +514 -0
  60. package/bin/runners/lib/enhanced-features/index.js +305 -0
  61. package/bin/runners/lib/enhanced-output.js +631 -0
  62. package/bin/runners/lib/enterprise.js +300 -0
  63. package/bin/runners/lib/entitlements-v2.js +103 -11
  64. package/bin/runners/lib/firewall/command-validator.js +351 -0
  65. package/bin/runners/lib/firewall/config.js +341 -0
  66. package/bin/runners/lib/firewall/content-validator.js +519 -0
  67. package/bin/runners/lib/firewall/index.js +101 -0
  68. package/bin/runners/lib/firewall/path-validator.js +256 -0
  69. package/bin/runners/lib/html-proof-report.js +350 -700
  70. package/bin/runners/lib/intelligence/cross-repo-intelligence.js +817 -0
  71. package/bin/runners/lib/mcp-utils.js +425 -0
  72. package/bin/runners/lib/missions/plan.js +46 -6
  73. package/bin/runners/lib/missions/templates.js +232 -0
  74. package/bin/runners/lib/output/index.js +1022 -0
  75. package/bin/runners/lib/policy-engine.js +652 -0
  76. package/bin/runners/lib/polish/autofix/accessibility-fixes.js +333 -0
  77. package/bin/runners/lib/polish/autofix/async-handlers.js +273 -0
  78. package/bin/runners/lib/polish/autofix/dead-code.js +280 -0
  79. package/bin/runners/lib/polish/autofix/imports-optimizer.js +344 -0
  80. package/bin/runners/lib/polish/autofix/index.js +200 -0
  81. package/bin/runners/lib/polish/autofix/remove-consoles.js +209 -0
  82. package/bin/runners/lib/polish/autofix/strengthen-types.js +245 -0
  83. package/bin/runners/lib/polish/backend-checks.js +148 -0
  84. package/bin/runners/lib/polish/documentation-checks.js +111 -0
  85. package/bin/runners/lib/polish/frontend-checks.js +168 -0
  86. package/bin/runners/lib/polish/index.js +71 -0
  87. package/bin/runners/lib/polish/infrastructure-checks.js +131 -0
  88. package/bin/runners/lib/polish/library-detection.js +175 -0
  89. package/bin/runners/lib/polish/performance-checks.js +100 -0
  90. package/bin/runners/lib/polish/security-checks.js +148 -0
  91. package/bin/runners/lib/polish/utils.js +203 -0
  92. package/bin/runners/lib/prompt-builder.js +540 -0
  93. package/bin/runners/lib/proof-certificate.js +634 -0
  94. package/bin/runners/lib/reality/accessibility-audit.js +946 -0
  95. package/bin/runners/lib/reality/api-contract-validator.js +1012 -0
  96. package/bin/runners/lib/reality/chaos-engineering.js +1084 -0
  97. package/bin/runners/lib/reality/performance-tracker.js +1077 -0
  98. package/bin/runners/lib/reality/scenario-generator.js +1404 -0
  99. package/bin/runners/lib/reality/visual-regression.js +852 -0
  100. package/bin/runners/lib/reality-profiler.js +717 -0
  101. package/bin/runners/lib/replay/flight-recorder-viewer.js +1160 -0
  102. package/bin/runners/lib/review/ai-code-review.js +832 -0
  103. package/bin/runners/lib/rules/custom-rule-engine.js +985 -0
  104. package/bin/runners/lib/sbom-generator.js +641 -0
  105. package/bin/runners/lib/scan-output-enhanced.js +512 -0
  106. package/bin/runners/lib/scan-output.js +47 -0
  107. package/bin/runners/lib/security/owasp-scanner.js +939 -0
  108. package/bin/runners/lib/terminal-ui.js +113 -1
  109. package/bin/runners/lib/unified-cli-output.js +603 -430
  110. package/bin/runners/lib/validators/contract-validator.js +283 -0
  111. package/bin/runners/lib/validators/dead-export-detector.js +279 -0
  112. package/bin/runners/lib/validators/dep-audit.js +245 -0
  113. package/bin/runners/lib/validators/env-validator.js +319 -0
  114. package/bin/runners/lib/validators/index.js +120 -0
  115. package/bin/runners/lib/validators/license-checker.js +252 -0
  116. package/bin/runners/lib/validators/route-validator.js +290 -0
  117. package/bin/runners/runAIAgent.js +5 -10
  118. package/bin/runners/runAgent.js +3 -0
  119. package/bin/runners/runApprove.js +1233 -1200
  120. package/bin/runners/runAuth.js +22 -1
  121. package/bin/runners/runAuthority.js +528 -0
  122. package/bin/runners/runCheckpoint.js +4 -24
  123. package/bin/runners/runClassify.js +862 -859
  124. package/bin/runners/runConductor.js +772 -0
  125. package/bin/runners/runContainer.js +366 -0
  126. package/bin/runners/runContext.js +3 -0
  127. package/bin/runners/runDoctor.js +28 -41
  128. package/bin/runners/runEasy.js +410 -0
  129. package/bin/runners/runFirewall.js +3 -0
  130. package/bin/runners/runFirewallHook.js +3 -0
  131. package/bin/runners/runFix.js +76 -66
  132. package/bin/runners/runGuard.js +411 -18
  133. package/bin/runners/runIaC.js +372 -0
  134. package/bin/runners/runInit.js +10 -60
  135. package/bin/runners/runMcp.js +11 -12
  136. package/bin/runners/runPolish.js +240 -64
  137. package/bin/runners/runPromptFirewall.js +5 -12
  138. package/bin/runners/runProve.js +20 -55
  139. package/bin/runners/runReality.js +68 -59
  140. package/bin/runners/runReport.js +31 -5
  141. package/bin/runners/runRuntime.js +5 -8
  142. package/bin/runners/runScan.js +194 -1286
  143. package/bin/runners/runShip.js +695 -47
  144. package/bin/runners/runTruth.js +3 -0
  145. package/bin/runners/runValidate.js +7 -11
  146. package/bin/runners/runVibe.js +791 -0
  147. package/bin/runners/runWatch.js +14 -23
  148. package/bin/vibecheck.js +175 -56
  149. package/mcp-server/index.js +190 -14
  150. package/mcp-server/package.json +1 -1
  151. package/mcp-server/tools-v3.js +397 -64
  152. package/mcp-server/tools.js +495 -0
  153. package/package.json +1 -1
  154. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +0 -164
  155. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +0 -291
  156. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +0 -83
  157. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +0 -198
  158. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +0 -275
  159. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +0 -167
  160. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +0 -217
  161. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +0 -140
  162. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +0 -164
  163. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +0 -234
  164. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +0 -217
  165. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +0 -78
  166. package/mcp-server/index-v1.js +0 -698
@@ -0,0 +1,433 @@
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
+ };
@@ -0,0 +1,276 @@
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
+ };