@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
@@ -0,0 +1,560 @@
1
+ /**
2
+ * Next Best Action Engine
3
+ *
4
+ * Single source of truth for "what should user do next?"
5
+ * Used across CLI, Web, VS Code, and MCP to provide consistent guidance.
6
+ *
7
+ * @module bin/runners/lib/next-action
8
+ */
9
+
10
+ "use strict";
11
+
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+
15
+ // ═══════════════════════════════════════════════════════════════════════════════
16
+ // CONSTANTS
17
+ // ═══════════════════════════════════════════════════════════════════════════════
18
+
19
+ const PRICING_URL = "https://vibecheckai.dev/pricing";
20
+ const DASHBOARD_URL = "https://app.vibecheckai.dev";
21
+ const DOCS_URL = "https://docs.vibecheckai.dev";
22
+
23
+ // Time estimates for each command (in seconds, displayed as human-readable)
24
+ const TIME_ESTIMATES = {
25
+ init: "~30 seconds",
26
+ doctor: "~10 seconds",
27
+ ctx: "~10 seconds",
28
+ scan: "~45 seconds",
29
+ ship: "~15 seconds",
30
+ report: "~5 seconds",
31
+ fix: "~30 seconds",
32
+ prove: "~2 minutes",
33
+ watch: "continuous",
34
+ badge: "~5 seconds",
35
+ };
36
+
37
+ // ═══════════════════════════════════════════════════════════════════════════════
38
+ // ANSI STYLING (for CLI output)
39
+ // ═══════════════════════════════════════════════════════════════════════════════
40
+
41
+ const SUPPORTS_COLOR = process.stdout.isTTY && !process.env.NO_COLOR;
42
+
43
+ const c = SUPPORTS_COLOR ? {
44
+ reset: "\x1b[0m",
45
+ bold: "\x1b[1m",
46
+ dim: "\x1b[2m",
47
+ cyan: "\x1b[36m",
48
+ green: "\x1b[32m",
49
+ yellow: "\x1b[33m",
50
+ magenta: "\x1b[35m",
51
+ red: "\x1b[31m",
52
+ gray: "\x1b[90m",
53
+ underline: "\x1b[4m",
54
+ } : {
55
+ reset: "", bold: "", dim: "", cyan: "", green: "", yellow: "",
56
+ magenta: "", red: "", gray: "", underline: "",
57
+ };
58
+
59
+ const sym = {
60
+ arrow: "→",
61
+ check: "✓",
62
+ star: "★",
63
+ rocket: "🚀",
64
+ link: "🔗",
65
+ clock: "⏱",
66
+ };
67
+
68
+ // ═══════════════════════════════════════════════════════════════════════════════
69
+ // STATE DETECTION
70
+ // ═══════════════════════════════════════════════════════════════════════════════
71
+
72
+ /**
73
+ * Detect current project state for next action computation
74
+ * @param {string} projectPath - Path to project root
75
+ * @returns {object} Project state
76
+ */
77
+ function detectProjectState(projectPath) {
78
+ const state = {
79
+ hasConfig: false,
80
+ hasTruthpack: false,
81
+ lastDoctorStatus: null,
82
+ lastScan: null,
83
+ lastShip: null,
84
+ tier: "free",
85
+ runId: null,
86
+ githubConnected: false,
87
+ limits: null,
88
+ };
89
+
90
+ try {
91
+ // Check for config file
92
+ const configPath = path.join(projectPath, ".vibecheckrc");
93
+ state.hasConfig = fs.existsSync(configPath);
94
+
95
+ // Check for truthpack
96
+ const truthpackPath = path.join(projectPath, ".vibecheck", "truthpack.json");
97
+ state.hasTruthpack = fs.existsSync(truthpackPath);
98
+
99
+ // Check for latest scan results
100
+ const latestScanPath = path.join(projectPath, ".vibecheck", "results", "latest.json");
101
+ if (fs.existsSync(latestScanPath)) {
102
+ try {
103
+ const scanData = JSON.parse(fs.readFileSync(latestScanPath, "utf-8"));
104
+ state.lastScan = {
105
+ verdict: scanData.result?.verdict || scanData.verdict,
106
+ score: scanData.result?.score || scanData.score,
107
+ findings: scanData.result?.findings?.length || 0,
108
+ runId: scanData.runId,
109
+ timestamp: scanData.timestamp || scanData.startTime,
110
+ };
111
+ state.runId = scanData.runId;
112
+ } catch {}
113
+ }
114
+
115
+ // Check for ship results
116
+ const lastShipPath = path.join(projectPath, ".vibecheck", "last_ship.json");
117
+ if (fs.existsSync(lastShipPath)) {
118
+ try {
119
+ const shipData = JSON.parse(fs.readFileSync(lastShipPath, "utf-8"));
120
+ state.lastShip = {
121
+ verdict: shipData.meta?.verdict || shipData.verdict,
122
+ findings: shipData.findings?.length || 0,
123
+ timestamp: shipData.meta?.generatedAt,
124
+ };
125
+ } catch {}
126
+ }
127
+
128
+ // Check summary for latest run info
129
+ const summaryPath = path.join(projectPath, ".vibecheck", "summary.json");
130
+ if (fs.existsSync(summaryPath)) {
131
+ try {
132
+ const summary = JSON.parse(fs.readFileSync(summaryPath, "utf-8"));
133
+ if (summary.runId) state.runId = summary.runId;
134
+ if (summary.verdict && !state.lastShip) {
135
+ state.lastShip = {
136
+ verdict: summary.verdict,
137
+ score: summary.score,
138
+ };
139
+ }
140
+ } catch {}
141
+ }
142
+
143
+ } catch (error) {
144
+ // Silently handle errors - return partial state
145
+ }
146
+
147
+ return state;
148
+ }
149
+
150
+ // ═══════════════════════════════════════════════════════════════════════════════
151
+ // NEXT ACTION COMPUTATION
152
+ // ═══════════════════════════════════════════════════════════════════════════════
153
+
154
+ /**
155
+ * Compute next best action based on project state
156
+ * @param {object} state - Project state (from detectProjectState or manual)
157
+ * @returns {object} Next action recommendation
158
+ */
159
+ function computeNextAction(state) {
160
+ const {
161
+ hasConfig = false,
162
+ hasTruthpack = false,
163
+ lastDoctorStatus = null,
164
+ lastScan = null,
165
+ lastShip = null,
166
+ tier = "free",
167
+ runId = null,
168
+ } = state;
169
+
170
+ const isPro = tier === "pro" || tier === "starter" || tier === "enterprise";
171
+
172
+ // Priority order: setup → scan → ship → fix → prove
173
+
174
+ // 1. No config - need init
175
+ if (!hasConfig) {
176
+ return {
177
+ action: "init",
178
+ command: "vibecheck init",
179
+ dashboardLink: null,
180
+ why: "Project not initialized. Run init to create config and Truth Pack.",
181
+ timeEstimate: TIME_ESTIMATES.init,
182
+ tier: "free",
183
+ priority: "high",
184
+ };
185
+ }
186
+
187
+ // 2. No truthpack - need context
188
+ if (!hasTruthpack) {
189
+ return {
190
+ action: "ctx",
191
+ command: "vibecheck context",
192
+ dashboardLink: null,
193
+ why: "Truth Pack missing. Generate context for accurate analysis.",
194
+ timeEstimate: TIME_ESTIMATES.ctx,
195
+ tier: "free",
196
+ priority: "high",
197
+ };
198
+ }
199
+
200
+ // 3. No scans yet - run first scan
201
+ if (!lastScan) {
202
+ return {
203
+ action: "scan",
204
+ command: "vibecheck scan",
205
+ dashboardLink: `${DASHBOARD_URL}/scan`,
206
+ why: "No scans yet. Run your first scan to detect issues.",
207
+ timeEstimate: TIME_ESTIMATES.scan,
208
+ tier: "free",
209
+ priority: "high",
210
+ };
211
+ }
212
+
213
+ // 4. Has scan but no ship verdict (PRO only)
214
+ if (!lastShip && isPro) {
215
+ return {
216
+ action: "ship",
217
+ command: "vibecheck ship",
218
+ dashboardLink: `${DASHBOARD_URL}/ship`,
219
+ why: "Scan complete. Get your SHIP/WARN/BLOCK verdict.",
220
+ timeEstimate: TIME_ESTIMATES.ship,
221
+ tier: "pro",
222
+ priority: "medium",
223
+ };
224
+ }
225
+
226
+ // 5. Ship passed - suggest badge (PRO)
227
+ if (lastShip?.verdict === "SHIP" && isPro) {
228
+ return {
229
+ action: "badge",
230
+ command: "vibecheck ship --badge",
231
+ dashboardLink: `${DASHBOARD_URL}/runs/${runId}`,
232
+ why: "SHIP passed! Generate a verified badge for your README.",
233
+ timeEstimate: TIME_ESTIMATES.badge,
234
+ tier: "pro",
235
+ priority: "low",
236
+ };
237
+ }
238
+
239
+ // 6. Ship failed with issues - suggest fix (PRO)
240
+ if (lastShip && lastShip.verdict !== "SHIP" && isPro) {
241
+ const issueCount = lastShip.findings || lastScan?.findings || 0;
242
+ return {
243
+ action: "fix",
244
+ command: "vibecheck fix",
245
+ dashboardLink: `${DASHBOARD_URL}/findings`,
246
+ why: `${issueCount} issue${issueCount !== 1 ? "s" : ""} found. Auto-fix them.`,
247
+ timeEstimate: TIME_ESTIMATES.fix,
248
+ tier: "pro",
249
+ priority: "high",
250
+ };
251
+ }
252
+
253
+ // 7. Free tier after scan - suggest report or upgrade
254
+ if (tier === "free") {
255
+ return {
256
+ action: "report",
257
+ command: "vibecheck report",
258
+ dashboardLink: `${DASHBOARD_URL}/runs/${runId}`,
259
+ why: "Scan complete. Export report or upgrade to get verdict.",
260
+ timeEstimate: TIME_ESTIMATES.report,
261
+ tier: "free",
262
+ priority: "medium",
263
+ upgradeHint: {
264
+ feature: "Ship Verdict",
265
+ benefit: "Get SHIP/WARN/BLOCK verdict with evidence",
266
+ url: PRICING_URL,
267
+ },
268
+ };
269
+ }
270
+
271
+ // 8. Default: watch mode for continuous monitoring
272
+ return {
273
+ action: "watch",
274
+ command: "vibecheck watch",
275
+ dashboardLink: `${DASHBOARD_URL}/dashboard`,
276
+ why: "All caught up. Enable watch mode for continuous verification.",
277
+ timeEstimate: TIME_ESTIMATES.watch,
278
+ tier: "free",
279
+ priority: "low",
280
+ };
281
+ }
282
+
283
+ /**
284
+ * Get next action for a specific command completion
285
+ * @param {string} completedCmd - Command that just completed
286
+ * @param {object} result - Result of the command
287
+ * @param {string} tier - User's tier
288
+ * @returns {object} Next action
289
+ */
290
+ function getNextActionForCommand(completedCmd, result = {}, tier = "free") {
291
+ const isPro = tier === "pro" || tier === "starter" || tier === "enterprise";
292
+ const verdict = result.verdict;
293
+ const runId = result.runId;
294
+ const findings = result.findings?.length || 0;
295
+
296
+ switch (completedCmd) {
297
+ case "init":
298
+ return {
299
+ action: "scan",
300
+ command: "vibecheck scan",
301
+ dashboardLink: `${DASHBOARD_URL}/scan`,
302
+ why: "Setup complete. Run your first scan.",
303
+ timeEstimate: TIME_ESTIMATES.scan,
304
+ tier: "free",
305
+ };
306
+
307
+ case "doctor":
308
+ return {
309
+ action: "scan",
310
+ command: "vibecheck scan",
311
+ dashboardLink: `${DASHBOARD_URL}/scan`,
312
+ why: "Environment healthy. Run a scan to check your code.",
313
+ timeEstimate: TIME_ESTIMATES.scan,
314
+ tier: "free",
315
+ };
316
+
317
+ case "scan":
318
+ if (isPro) {
319
+ return {
320
+ action: "ship",
321
+ command: "vibecheck ship",
322
+ dashboardLink: `${DASHBOARD_URL}/ship`,
323
+ why: `Scan complete (${findings} findings). Get your verdict.`,
324
+ timeEstimate: TIME_ESTIMATES.ship,
325
+ tier: "pro",
326
+ };
327
+ }
328
+ return {
329
+ action: "report",
330
+ command: "vibecheck report",
331
+ dashboardLink: `${DASHBOARD_URL}/runs/${runId}`,
332
+ why: `Scan complete. Export report.`,
333
+ timeEstimate: TIME_ESTIMATES.report,
334
+ tier: "free",
335
+ upgradeHint: {
336
+ feature: "Ship Verdict",
337
+ benefit: "Get SHIP/WARN/BLOCK verdict",
338
+ url: PRICING_URL,
339
+ },
340
+ };
341
+
342
+ case "ship":
343
+ if (verdict === "SHIP" && isPro) {
344
+ return {
345
+ action: "badge",
346
+ command: "vibecheck ship --badge",
347
+ dashboardLink: `${DASHBOARD_URL}/runs/${runId}`,
348
+ why: "SHIP passed! Generate a verified badge.",
349
+ timeEstimate: TIME_ESTIMATES.badge,
350
+ tier: "pro",
351
+ };
352
+ }
353
+ if (verdict !== "SHIP" && isPro) {
354
+ return {
355
+ action: "fix",
356
+ command: "vibecheck fix",
357
+ dashboardLink: `${DASHBOARD_URL}/findings`,
358
+ why: `${findings} issues blocking ship. Auto-fix them.`,
359
+ timeEstimate: TIME_ESTIMATES.fix,
360
+ tier: "pro",
361
+ };
362
+ }
363
+ return {
364
+ action: "report",
365
+ command: "vibecheck report",
366
+ dashboardLink: `${DASHBOARD_URL}/runs/${runId}`,
367
+ why: "Export detailed report.",
368
+ timeEstimate: TIME_ESTIMATES.report,
369
+ tier: "free",
370
+ };
371
+
372
+ case "fix":
373
+ return {
374
+ action: "ship",
375
+ command: "vibecheck ship",
376
+ dashboardLink: `${DASHBOARD_URL}/ship`,
377
+ why: "Fixes applied. Verify with ship.",
378
+ timeEstimate: TIME_ESTIMATES.ship,
379
+ tier: "pro",
380
+ };
381
+
382
+ case "report":
383
+ if (isPro) {
384
+ return {
385
+ action: "ship",
386
+ command: "vibecheck ship",
387
+ dashboardLink: `${DASHBOARD_URL}/ship`,
388
+ why: "Report generated. Get your verdict.",
389
+ timeEstimate: TIME_ESTIMATES.ship,
390
+ tier: "pro",
391
+ };
392
+ }
393
+ return {
394
+ action: "watch",
395
+ command: "vibecheck watch",
396
+ dashboardLink: `${DASHBOARD_URL}/dashboard`,
397
+ why: "Enable watch for continuous monitoring.",
398
+ timeEstimate: TIME_ESTIMATES.watch,
399
+ tier: "free",
400
+ };
401
+
402
+ default:
403
+ return computeNextAction({ tier });
404
+ }
405
+ }
406
+
407
+ // ═══════════════════════════════════════════════════════════════════════════════
408
+ // FORMATTING
409
+ // ═══════════════════════════════════════════════════════════════════════════════
410
+
411
+ /**
412
+ * Format next action for CLI output
413
+ * @param {object} nextAction - Result from computeNextAction
414
+ * @param {object} opts - Options
415
+ * @returns {string} Formatted string
416
+ */
417
+ function formatNextAction(nextAction, opts = {}) {
418
+ const { color = true, compact = false } = opts;
419
+ const cc = color ? c : { reset: "", bold: "", dim: "", cyan: "", green: "", magenta: "", gray: "", underline: "" };
420
+
421
+ if (compact) {
422
+ return `${cc.dim}Next:${cc.reset} ${cc.cyan}${nextAction.command}${cc.reset}`;
423
+ }
424
+
425
+ let output = "";
426
+
427
+ // Box header
428
+ output += `\n${cc.dim}┌─────────────────────────────────────────────────────────────────────┐${cc.reset}\n`;
429
+ output += `${cc.dim}│${cc.reset} ${cc.bold}NEXT BEST ACTION${cc.reset}${" ".repeat(51)}${cc.dim}│${cc.reset}\n`;
430
+ output += `${cc.dim}├─────────────────────────────────────────────────────────────────────┤${cc.reset}\n`;
431
+
432
+ // Command
433
+ output += `${cc.dim}│${cc.reset} ${cc.cyan}${sym.arrow}${cc.reset} ${cc.bold}${nextAction.command}${cc.reset}`;
434
+ output += `${" ".repeat(Math.max(1, 54 - nextAction.command.length))}`;
435
+ output += `${cc.dim}${nextAction.timeEstimate}${cc.reset} ${cc.dim}│${cc.reset}\n`;
436
+
437
+ // Why
438
+ const whyTruncated = nextAction.why.length > 60 ? nextAction.why.slice(0, 57) + "..." : nextAction.why;
439
+ output += `${cc.dim}│${cc.reset} ${cc.gray}${whyTruncated}${cc.reset}`;
440
+ output += `${" ".repeat(Math.max(1, 67 - whyTruncated.length))}${cc.dim}│${cc.reset}\n`;
441
+
442
+ // Dashboard link
443
+ if (nextAction.dashboardLink) {
444
+ output += `${cc.dim}│${cc.reset} ${cc.dim}${sym.link}${cc.reset} ${cc.underline}${nextAction.dashboardLink}${cc.reset}`;
445
+ const linkLen = nextAction.dashboardLink.length + 4;
446
+ output += `${" ".repeat(Math.max(1, 67 - linkLen))}${cc.dim}│${cc.reset}\n`;
447
+ }
448
+
449
+ // Upgrade hint
450
+ if (nextAction.upgradeHint) {
451
+ output += `${cc.dim}│${cc.reset} ${cc.magenta}${sym.star} PRO:${cc.reset} ${nextAction.upgradeHint.benefit}`;
452
+ const hintLen = nextAction.upgradeHint.benefit.length + 8;
453
+ output += `${" ".repeat(Math.max(1, 67 - hintLen))}${cc.dim}│${cc.reset}\n`;
454
+ }
455
+
456
+ output += `${cc.dim}└─────────────────────────────────────────────────────────────────────┘${cc.reset}\n`;
457
+
458
+ return output;
459
+ }
460
+
461
+ /**
462
+ * Format next action as simple one-liner
463
+ * @param {object} nextAction
464
+ * @param {object} opts
465
+ * @returns {string}
466
+ */
467
+ function formatNextActionOneLine(nextAction, opts = {}) {
468
+ const { color = true } = opts;
469
+ const cc = color ? c : { reset: "", dim: "", cyan: "", magenta: "" };
470
+
471
+ let line = `${cc.dim}Next:${cc.reset} ${cc.cyan}${nextAction.command}${cc.reset}`;
472
+
473
+ if (nextAction.dashboardLink) {
474
+ line += ` ${cc.dim}|${cc.reset} ${nextAction.dashboardLink}`;
475
+ }
476
+
477
+ if (nextAction.upgradeHint) {
478
+ line += ` ${cc.dim}|${cc.reset} ${cc.magenta}PRO: ${nextAction.upgradeHint.feature}${cc.reset}`;
479
+ }
480
+
481
+ return line;
482
+ }
483
+
484
+ /**
485
+ * Format dashboard link for CLI output
486
+ * @param {string} runId - Run ID
487
+ * @param {string} type - Type of link (runs, findings, ship)
488
+ * @returns {string}
489
+ */
490
+ function formatDashboardLink(runId, type = "runs") {
491
+ const url = runId
492
+ ? `${DASHBOARD_URL}/${type}/${runId}`
493
+ : `${DASHBOARD_URL}/${type}`;
494
+ return `${c.dim}Dashboard:${c.reset} ${url}`;
495
+ }
496
+
497
+ // ═══════════════════════════════════════════════════════════════════════════════
498
+ // JSON OUTPUT (for MCP, API, VS Code)
499
+ // ═══════════════════════════════════════════════════════════════════════════════
500
+
501
+ /**
502
+ * Get next action as JSON (for MCP tool, API, VS Code)
503
+ * @param {string} projectPath
504
+ * @param {string} tier
505
+ * @returns {object}
506
+ */
507
+ function getNextActionJson(projectPath, tier = "free") {
508
+ const state = detectProjectState(projectPath);
509
+ state.tier = tier;
510
+ const nextAction = computeNextAction(state);
511
+
512
+ return {
513
+ action: nextAction.action,
514
+ command: nextAction.command,
515
+ cliCommand: `vibecheck ${nextAction.action}`,
516
+ dashboardLink: nextAction.dashboardLink,
517
+ docsLink: `${DOCS_URL}/cli/${nextAction.action}`,
518
+ why: nextAction.why,
519
+ timeEstimate: nextAction.timeEstimate,
520
+ requiredTier: nextAction.tier,
521
+ priority: nextAction.priority,
522
+ upgradeHint: nextAction.upgradeHint || null,
523
+ projectState: {
524
+ hasConfig: state.hasConfig,
525
+ hasTruthpack: state.hasTruthpack,
526
+ lastScanVerdict: state.lastScan?.verdict || null,
527
+ lastShipVerdict: state.lastShip?.verdict || null,
528
+ runId: state.runId,
529
+ },
530
+ };
531
+ }
532
+
533
+ // ═══════════════════════════════════════════════════════════════════════════════
534
+ // EXPORTS
535
+ // ═══════════════════════════════════════════════════════════════════════════════
536
+
537
+ module.exports = {
538
+ // Core functions
539
+ computeNextAction,
540
+ getNextActionForCommand,
541
+ detectProjectState,
542
+
543
+ // Formatting
544
+ formatNextAction,
545
+ formatNextActionOneLine,
546
+ formatDashboardLink,
547
+
548
+ // JSON output
549
+ getNextActionJson,
550
+
551
+ // Constants
552
+ PRICING_URL,
553
+ DASHBOARD_URL,
554
+ DOCS_URL,
555
+ TIME_ESTIMATES,
556
+
557
+ // Styling (for consistent use elsewhere)
558
+ c,
559
+ sym,
560
+ };
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Prerequisite Auto-Running
3
+ *
4
+ * Automatically runs prerequisites (like scan) if they're missing
5
+ * to improve UX - users don't need to know the correct command order.
6
+ */
7
+
8
+ const fs = require("fs");
9
+ const path = require("path");
10
+
11
+ /**
12
+ * Check if scan results exist
13
+ */
14
+ function hasScanResults(projectPath) {
15
+ const latestPath = path.join(projectPath, ".vibecheck", "results", "latest.json");
16
+ return fs.existsSync(latestPath);
17
+ }
18
+
19
+ /**
20
+ * Check if ship results exist
21
+ */
22
+ function hasShipResults(projectPath) {
23
+ const shipPath = path.join(projectPath, ".vibecheck", "last_ship.json");
24
+ return fs.existsSync(shipPath);
25
+ }
26
+
27
+ /**
28
+ * Check if truthpack exists
29
+ */
30
+ function hasTruthpack(projectPath) {
31
+ const truthpackPath = path.join(projectPath, ".vibecheck", "truthpack.json");
32
+ return fs.existsSync(truthpackPath);
33
+ }
34
+
35
+ /**
36
+ * Auto-run scan if results are missing
37
+ */
38
+ async function ensureScanResults(projectPath, opts = {}) {
39
+ if (hasScanResults(projectPath)) {
40
+ return { ran: false, reason: "Scan results already exist" };
41
+ }
42
+
43
+ // Don't auto-run in CI or if explicitly disabled
44
+ if (opts.ci || opts.noAutoRun || process.env.CI) {
45
+ return { ran: false, reason: "Auto-run disabled (CI mode or --no-auto-run)" };
46
+ }
47
+
48
+ try {
49
+ const { runScan } = require("../runScan");
50
+
51
+ if (!opts.quiet && !opts.json) {
52
+ console.log(`\n ${opts.colors?.info || ''}${opts.icons?.info || 'ℹ'}${opts.ansi?.reset || ''} No scan results found. Running scan first...\n`);
53
+ }
54
+
55
+ const scanArgs = ["--path", projectPath, "--offline", "--quiet"];
56
+ if (opts.json) scanArgs.push("--json");
57
+
58
+ const exitCode = await runScan(scanArgs);
59
+
60
+ if (hasScanResults(projectPath)) {
61
+ return { ran: true, exitCode, success: true };
62
+ } else {
63
+ return { ran: true, exitCode, success: false, reason: "Scan completed but no results file created" };
64
+ }
65
+ } catch (error) {
66
+ return { ran: true, success: false, error: error.message };
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Auto-run ship if results are missing (for commands that need ship results)
72
+ */
73
+ async function ensureShipResults(projectPath, opts = {}) {
74
+ if (hasShipResults(projectPath)) {
75
+ return { ran: false, reason: "Ship results already exist" };
76
+ }
77
+
78
+ // Don't auto-run in CI or if explicitly disabled
79
+ if (opts.ci || opts.noAutoRun || process.env.CI) {
80
+ return { ran: false, reason: "Auto-run disabled (CI mode or --no-auto-run)" };
81
+ }
82
+
83
+ try {
84
+ const { runShip } = require("../runShip");
85
+
86
+ if (!opts.quiet && !opts.json) {
87
+ console.log(`\n ${opts.colors?.info || ''}${opts.icons?.info || 'ℹ'}${opts.ansi?.reset || ''} No ship results found. Running ship first...\n`);
88
+ }
89
+
90
+ const shipArgs = ["--path", projectPath, "--no-banner", "--offline"];
91
+ if (opts.quiet) shipArgs.push("--quiet");
92
+ if (opts.json) shipArgs.push("--json");
93
+
94
+ const exitCode = await runShip(shipArgs);
95
+
96
+ if (hasShipResults(projectPath)) {
97
+ return { ran: true, exitCode, success: true };
98
+ } else {
99
+ return { ran: true, exitCode, success: false, reason: "Ship completed but no results file created" };
100
+ }
101
+ } catch (error) {
102
+ return { ran: true, success: false, error: error.message };
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Auto-run context if truthpack is missing
108
+ */
109
+ async function ensureTruthpack(projectPath, opts = {}) {
110
+ if (hasTruthpack(projectPath)) {
111
+ return { ran: false, reason: "Truthpack already exists" };
112
+ }
113
+
114
+ // Don't auto-run in CI or if explicitly disabled
115
+ if (opts.ci || opts.noAutoRun || process.env.CI) {
116
+ return { ran: false, reason: "Auto-run disabled (CI mode or --no-auto-run)" };
117
+ }
118
+
119
+ try {
120
+ const { runContext } = require("../runContext");
121
+
122
+ if (!opts.quiet && !opts.json) {
123
+ console.log(`\n ${opts.colors?.info || ''}${opts.icons?.info || 'ℹ'}${opts.ansi?.reset || ''} No truthpack found. Generating context first...\n`);
124
+ }
125
+
126
+ const contextArgs = ["--path", projectPath];
127
+ if (opts.quiet) contextArgs.push("--quiet");
128
+ if (opts.json) contextArgs.push("--json");
129
+
130
+ const exitCode = await runContext(contextArgs);
131
+
132
+ if (hasTruthpack(projectPath)) {
133
+ return { ran: true, exitCode, success: true };
134
+ } else {
135
+ return { ran: true, exitCode, success: false, reason: "Context completed but no truthpack created" };
136
+ }
137
+ } catch (error) {
138
+ return { ran: true, success: false, error: error.message };
139
+ }
140
+ }
141
+
142
+ module.exports = {
143
+ hasScanResults,
144
+ hasShipResults,
145
+ hasTruthpack,
146
+ ensureScanResults,
147
+ ensureShipResults,
148
+ ensureTruthpack,
149
+ };