@vibecheckai/cli 3.2.5 → 3.3.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 (197) hide show
  1. package/bin/.generated +25 -25
  2. package/bin/dev/run-v2-torture.js +30 -30
  3. package/bin/registry.js +192 -5
  4. package/bin/runners/lib/__tests__/entitlements-v2.test.js +295 -295
  5. package/bin/runners/lib/agent-firewall/change-packet/builder.js +280 -6
  6. package/bin/runners/lib/agent-firewall/critic/index.js +151 -0
  7. package/bin/runners/lib/agent-firewall/critic/judge.js +432 -0
  8. package/bin/runners/lib/agent-firewall/critic/prompts.js +305 -0
  9. package/bin/runners/lib/agent-firewall/lawbook/distributor.js +465 -0
  10. package/bin/runners/lib/agent-firewall/lawbook/evaluator.js +604 -0
  11. package/bin/runners/lib/agent-firewall/lawbook/index.js +304 -0
  12. package/bin/runners/lib/agent-firewall/lawbook/registry.js +514 -0
  13. package/bin/runners/lib/agent-firewall/lawbook/schema.js +420 -0
  14. package/bin/runners/lib/agent-firewall/logger.js +141 -0
  15. package/bin/runners/lib/agent-firewall/policy/loader.js +312 -4
  16. package/bin/runners/lib/agent-firewall/policy/rules/ghost-env.js +113 -1
  17. package/bin/runners/lib/agent-firewall/policy/rules/ghost-route.js +133 -6
  18. package/bin/runners/lib/agent-firewall/proposal/extractor.js +394 -0
  19. package/bin/runners/lib/agent-firewall/proposal/index.js +212 -0
  20. package/bin/runners/lib/agent-firewall/proposal/schema.js +251 -0
  21. package/bin/runners/lib/agent-firewall/proposal/validator.js +386 -0
  22. package/bin/runners/lib/agent-firewall/reality/index.js +332 -0
  23. package/bin/runners/lib/agent-firewall/reality/state.js +625 -0
  24. package/bin/runners/lib/agent-firewall/reality/watcher.js +322 -0
  25. package/bin/runners/lib/agent-firewall/risk/index.js +173 -0
  26. package/bin/runners/lib/agent-firewall/risk/scorer.js +328 -0
  27. package/bin/runners/lib/agent-firewall/risk/thresholds.js +321 -0
  28. package/bin/runners/lib/agent-firewall/risk/vectors.js +421 -0
  29. package/bin/runners/lib/agent-firewall/simulator/diff-simulator.js +472 -0
  30. package/bin/runners/lib/agent-firewall/simulator/import-resolver.js +346 -0
  31. package/bin/runners/lib/agent-firewall/simulator/index.js +181 -0
  32. package/bin/runners/lib/agent-firewall/simulator/route-validator.js +380 -0
  33. package/bin/runners/lib/agent-firewall/time-machine/incident-correlator.js +661 -0
  34. package/bin/runners/lib/agent-firewall/time-machine/index.js +267 -0
  35. package/bin/runners/lib/agent-firewall/time-machine/replay-engine.js +436 -0
  36. package/bin/runners/lib/agent-firewall/time-machine/state-reconstructor.js +490 -0
  37. package/bin/runners/lib/agent-firewall/time-machine/timeline-builder.js +530 -0
  38. package/bin/runners/lib/analyzers.js +81 -18
  39. package/bin/runners/lib/api-client.js +269 -0
  40. package/bin/runners/lib/auth-truth.js +193 -193
  41. package/bin/runners/lib/authority-badge.js +425 -0
  42. package/bin/runners/lib/backup.js +62 -62
  43. package/bin/runners/lib/billing.js +107 -107
  44. package/bin/runners/lib/claims.js +118 -118
  45. package/bin/runners/lib/cli-output.js +7 -1
  46. package/bin/runners/lib/cli-ui.js +540 -540
  47. package/bin/runners/lib/contracts/auth-contract.js +202 -202
  48. package/bin/runners/lib/contracts/env-contract.js +181 -181
  49. package/bin/runners/lib/contracts/external-contract.js +206 -206
  50. package/bin/runners/lib/contracts/guard.js +168 -168
  51. package/bin/runners/lib/contracts/index.js +89 -89
  52. package/bin/runners/lib/contracts/plan-validator.js +311 -311
  53. package/bin/runners/lib/contracts/route-contract.js +199 -199
  54. package/bin/runners/lib/contracts.js +804 -804
  55. package/bin/runners/lib/detect.js +89 -89
  56. package/bin/runners/lib/doctor/autofix.js +254 -254
  57. package/bin/runners/lib/doctor/index.js +37 -37
  58. package/bin/runners/lib/doctor/modules/dependencies.js +325 -325
  59. package/bin/runners/lib/doctor/modules/index.js +46 -46
  60. package/bin/runners/lib/doctor/modules/network.js +250 -250
  61. package/bin/runners/lib/doctor/modules/project.js +312 -312
  62. package/bin/runners/lib/doctor/modules/runtime.js +224 -224
  63. package/bin/runners/lib/doctor/modules/security.js +348 -348
  64. package/bin/runners/lib/doctor/modules/system.js +213 -213
  65. package/bin/runners/lib/doctor/modules/vibecheck.js +394 -394
  66. package/bin/runners/lib/doctor/reporter.js +262 -262
  67. package/bin/runners/lib/doctor/service.js +262 -262
  68. package/bin/runners/lib/doctor/types.js +113 -113
  69. package/bin/runners/lib/doctor/ui.js +263 -263
  70. package/bin/runners/lib/doctor-v2.js +608 -608
  71. package/bin/runners/lib/drift.js +425 -425
  72. package/bin/runners/lib/enforcement.js +72 -72
  73. package/bin/runners/lib/enterprise-detect.js +603 -603
  74. package/bin/runners/lib/enterprise-init.js +942 -942
  75. package/bin/runners/lib/env-resolver.js +417 -417
  76. package/bin/runners/lib/env-template.js +66 -66
  77. package/bin/runners/lib/env.js +189 -189
  78. package/bin/runners/lib/error-handler.js +16 -9
  79. package/bin/runners/lib/exit-codes.js +275 -0
  80. package/bin/runners/lib/extractors/client-calls.js +990 -990
  81. package/bin/runners/lib/extractors/fastify-route-dump.js +573 -573
  82. package/bin/runners/lib/extractors/fastify-routes.js +426 -426
  83. package/bin/runners/lib/extractors/index.js +363 -363
  84. package/bin/runners/lib/extractors/next-routes.js +524 -524
  85. package/bin/runners/lib/extractors/proof-graph.js +431 -431
  86. package/bin/runners/lib/extractors/route-matcher.js +451 -451
  87. package/bin/runners/lib/extractors/truthpack-v2.js +377 -377
  88. package/bin/runners/lib/extractors/ui-bindings.js +547 -547
  89. package/bin/runners/lib/findings-schema.js +281 -281
  90. package/bin/runners/lib/firewall-prompt.js +50 -50
  91. package/bin/runners/lib/global-flags.js +37 -0
  92. package/bin/runners/lib/graph/graph-builder.js +265 -265
  93. package/bin/runners/lib/graph/html-renderer.js +413 -413
  94. package/bin/runners/lib/graph/index.js +32 -32
  95. package/bin/runners/lib/graph/runtime-collector.js +215 -215
  96. package/bin/runners/lib/graph/static-extractor.js +518 -518
  97. package/bin/runners/lib/help-formatter.js +413 -0
  98. package/bin/runners/lib/html-report.js +650 -650
  99. package/bin/runners/lib/llm.js +75 -75
  100. package/bin/runners/lib/logger.js +38 -0
  101. package/bin/runners/lib/meter.js +61 -61
  102. package/bin/runners/lib/missions/evidence.js +126 -126
  103. package/bin/runners/lib/patch.js +40 -40
  104. package/bin/runners/lib/permissions/auth-model.js +213 -213
  105. package/bin/runners/lib/permissions/idor-prover.js +205 -205
  106. package/bin/runners/lib/permissions/index.js +45 -45
  107. package/bin/runners/lib/permissions/matrix-builder.js +198 -198
  108. package/bin/runners/lib/pkgjson.js +28 -28
  109. package/bin/runners/lib/policy.js +295 -295
  110. package/bin/runners/lib/preflight.js +142 -142
  111. package/bin/runners/lib/reality/correlation-detectors.js +359 -359
  112. package/bin/runners/lib/reality/index.js +318 -318
  113. package/bin/runners/lib/reality/request-hashing.js +416 -416
  114. package/bin/runners/lib/reality/request-mapper.js +453 -453
  115. package/bin/runners/lib/reality/safety-rails.js +463 -463
  116. package/bin/runners/lib/reality/semantic-snapshot.js +408 -408
  117. package/bin/runners/lib/reality/toast-detector.js +393 -393
  118. package/bin/runners/lib/reality-findings.js +84 -84
  119. package/bin/runners/lib/receipts.js +179 -179
  120. package/bin/runners/lib/redact.js +29 -29
  121. package/bin/runners/lib/replay/capsule-manager.js +154 -154
  122. package/bin/runners/lib/replay/index.js +263 -263
  123. package/bin/runners/lib/replay/player.js +348 -348
  124. package/bin/runners/lib/replay/recorder.js +331 -331
  125. package/bin/runners/lib/report.js +135 -135
  126. package/bin/runners/lib/route-detection.js +1140 -1140
  127. package/bin/runners/lib/sandbox/index.js +59 -59
  128. package/bin/runners/lib/sandbox/proof-chain.js +399 -399
  129. package/bin/runners/lib/sandbox/sandbox-runner.js +205 -205
  130. package/bin/runners/lib/sandbox/worktree.js +174 -174
  131. package/bin/runners/lib/schema-validator.js +350 -350
  132. package/bin/runners/lib/schemas/contracts.schema.json +160 -160
  133. package/bin/runners/lib/schemas/finding.schema.json +100 -100
  134. package/bin/runners/lib/schemas/mission-pack.schema.json +206 -206
  135. package/bin/runners/lib/schemas/proof-graph.schema.json +176 -176
  136. package/bin/runners/lib/schemas/reality-report.schema.json +162 -162
  137. package/bin/runners/lib/schemas/share-pack.schema.json +180 -180
  138. package/bin/runners/lib/schemas/ship-report.schema.json +117 -117
  139. package/bin/runners/lib/schemas/truthpack-v2.schema.json +303 -303
  140. package/bin/runners/lib/schemas/validator.js +438 -438
  141. package/bin/runners/lib/score-history.js +282 -282
  142. package/bin/runners/lib/share-pack.js +239 -239
  143. package/bin/runners/lib/snippets.js +67 -67
  144. package/bin/runners/lib/unified-cli-output.js +604 -0
  145. package/bin/runners/lib/upsell.js +658 -510
  146. package/bin/runners/lib/usage.js +153 -153
  147. package/bin/runners/lib/validate-patch.js +156 -156
  148. package/bin/runners/lib/verdict-engine.js +628 -628
  149. package/bin/runners/reality/engine.js +917 -917
  150. package/bin/runners/reality/flows.js +122 -122
  151. package/bin/runners/reality/report.js +378 -378
  152. package/bin/runners/reality/session.js +193 -193
  153. package/bin/runners/runAgent.d.ts +5 -0
  154. package/bin/runners/runApprove.js +1200 -0
  155. package/bin/runners/runAuth.js +324 -95
  156. package/bin/runners/runCheckpoint.js +39 -21
  157. package/bin/runners/runClassify.js +859 -0
  158. package/bin/runners/runContext.js +136 -24
  159. package/bin/runners/runDoctor.js +108 -68
  160. package/bin/runners/runFirewall.d.ts +5 -0
  161. package/bin/runners/runFirewallHook.d.ts +5 -0
  162. package/bin/runners/runFix.js +6 -5
  163. package/bin/runners/runGuard.js +262 -168
  164. package/bin/runners/runInit.js +3 -2
  165. package/bin/runners/runMcp.js +130 -52
  166. package/bin/runners/runPolish.js +43 -20
  167. package/bin/runners/runProve.js +1 -2
  168. package/bin/runners/runReport.js +3 -2
  169. package/bin/runners/runScan.js +145 -44
  170. package/bin/runners/runShip.js +3 -4
  171. package/bin/runners/runTruth.d.ts +5 -0
  172. package/bin/runners/runValidate.js +19 -2
  173. package/bin/runners/runWatch.js +104 -53
  174. package/bin/vibecheck.js +106 -19
  175. package/mcp-server/HARDENING_SUMMARY.md +299 -0
  176. package/mcp-server/agent-firewall-interceptor.js +367 -31
  177. package/mcp-server/authority-tools.js +569 -0
  178. package/mcp-server/conductor/conflict-resolver.js +588 -0
  179. package/mcp-server/conductor/execution-planner.js +544 -0
  180. package/mcp-server/conductor/index.js +377 -0
  181. package/mcp-server/conductor/lock-manager.js +615 -0
  182. package/mcp-server/conductor/request-queue.js +550 -0
  183. package/mcp-server/conductor/session-manager.js +500 -0
  184. package/mcp-server/conductor/tools.js +510 -0
  185. package/mcp-server/index.js +1199 -208
  186. package/mcp-server/lib/api-client.cjs +305 -0
  187. package/mcp-server/lib/logger.cjs +30 -0
  188. package/mcp-server/logger.js +173 -0
  189. package/mcp-server/package.json +2 -2
  190. package/mcp-server/premium-tools.js +2 -2
  191. package/mcp-server/tier-auth.js +351 -136
  192. package/mcp-server/tools/index.js +72 -72
  193. package/mcp-server/truth-firewall-tools.js +145 -15
  194. package/mcp-server/vibecheck-tools.js +2 -2
  195. package/package.json +2 -3
  196. package/mcp-server/index.old.js +0 -4137
  197. package/mcp-server/package-lock.json +0 -165
@@ -1,168 +1,262 @@
1
- /**
2
- * vibecheck guard - Unified trust boundary enforcement
3
- *
4
- * Combines: validate + claim-verifier + prompt-firewall
5
- *
6
- * Usage:
7
- * vibecheck guard # Run all checks
8
- * vibecheck guard --claims # Verify AI claims against truthpack
9
- * vibecheck guard --prompts # Check for prompt injection
10
- * vibecheck guard --hallucinations # Detect AI hallucination patterns
11
- */
12
-
13
- const path = require("path");
14
- const fs = require("fs");
15
-
16
- // Import underlying implementations
17
- const { runValidate } = require("./runValidate");
18
- const { runPromptFirewall } = require("./runPromptFirewall");
19
-
20
- // ANSI colors
21
- const c = {
22
- reset: "\x1b[0m",
23
- dim: "\x1b[2m",
24
- bold: "\x1b[1m",
25
- cyan: "\x1b[36m",
26
- green: "\x1b[32m",
27
- yellow: "\x1b[33m",
28
- red: "\x1b[31m",
29
- magenta: "\x1b[35m",
30
- };
31
-
32
- function printHelp() {
33
- console.log(`
34
- ${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}
35
- ${c.bold}vibecheck guard${c.reset} - Trust boundary enforcement for AI outputs
36
- ${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}
37
-
38
- ${c.green}USAGE${c.reset}
39
- vibecheck guard [options]
40
-
41
- ${c.yellow}OPTIONS${c.reset}
42
- --claims Verify AI claims against truthpack (route_exists, auth_enforced, etc.)
43
- --prompts Check code for prompt injection vulnerabilities
44
- --hallucinations Detect AI hallucination patterns in generated code
45
- --file <path> Check specific file(s)
46
- --json Output JSON for CI integration
47
- --strict Fail on warnings (default: fail on errors only)
48
-
49
- ${c.magenta}EXAMPLES${c.reset}
50
- vibecheck guard # Run all checks
51
- vibecheck guard --claims --file api.ts # Verify claims in specific file
52
- vibecheck guard --prompts # Prompt injection scan
53
- vibecheck guard --json # CI-friendly output
54
-
55
- ${c.dim}This command unifies trust boundary checks for AI-generated code.${c.reset}
56
- `);
57
- }
58
-
59
- async function runGuard(args = []) {
60
- // Parse arguments
61
- if (args.includes("--help") || args.includes("-h")) {
62
- printHelp();
63
- return 0;
64
- }
65
-
66
- const runClaims = args.includes("--claims") || (!args.includes("--prompts") && !args.includes("--hallucinations"));
67
- const runPrompts = args.includes("--prompts") || (!args.includes("--claims") && !args.includes("--hallucinations"));
68
- const runHallucinations = args.includes("--hallucinations") || (!args.includes("--claims") && !args.includes("--prompts"));
69
- const jsonOutput = args.includes("--json");
70
- const strict = args.includes("--strict");
71
-
72
- const results = {
73
- claims: null,
74
- prompts: null,
75
- hallucinations: null,
76
- verdict: "PASS",
77
- errors: 0,
78
- warnings: 0,
79
- };
80
-
81
- console.log(`
82
- ${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}
83
- ${c.bold}🛡️ VIBECHECK GUARD${c.reset} - Trust Boundary Enforcement
84
- ${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}
85
- `);
86
-
87
- // Run claims verification (validates AI claims against truthpack)
88
- if (runClaims) {
89
- console.log(`${c.dim}▸ Verifying AI claims against truthpack...${c.reset}`);
90
- try {
91
- const validateArgs = args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a));
92
- const exitCode = await runValidate(validateArgs);
93
- results.claims = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
94
- if (exitCode !== 0) {
95
- results.errors++;
96
- results.verdict = "FAIL";
97
- }
98
- console.log(exitCode === 0
99
- ? ` ${c.green}✓${c.reset} Claims verified`
100
- : ` ${c.red}✗${c.reset} Claim verification failed`);
101
- } catch (e) {
102
- results.claims = { error: e.message };
103
- console.log(` ${c.yellow}⚠${c.reset} Claims check skipped: ${e.message}`);
104
- }
105
- }
106
-
107
- // Run prompt injection detection
108
- if (runPrompts) {
109
- console.log(`${c.dim}▸ Scanning for prompt injection vulnerabilities...${c.reset}`);
110
- try {
111
- const firewallArgs = args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a));
112
- const exitCode = await runPromptFirewall(firewallArgs);
113
- results.prompts = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
114
- if (exitCode !== 0) {
115
- results.warnings++;
116
- if (strict) results.verdict = "FAIL";
117
- }
118
- console.log(exitCode === 0
119
- ? ` ${c.green}✓${c.reset} No prompt injection risks`
120
- : ` ${c.yellow}⚠${c.reset} Prompt injection risks detected`);
121
- } catch (e) {
122
- results.prompts = { error: e.message };
123
- console.log(` ${c.yellow}⚠${c.reset} Prompt check skipped: ${e.message}`);
124
- }
125
- }
126
-
127
- // Run hallucination detection
128
- if (runHallucinations) {
129
- console.log(`${c.dim}▸ Detecting hallucination patterns...${c.reset}`);
130
- // Use validate with hallucination focus
131
- try {
132
- const validateArgs = ["--hallucinations", ...args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a))];
133
- const exitCode = await runValidate(validateArgs);
134
- results.hallucinations = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
135
- if (exitCode !== 0) {
136
- results.warnings++;
137
- if (strict) results.verdict = "FAIL";
138
- }
139
- console.log(exitCode === 0
140
- ? ` ${c.green}✓${c.reset} No hallucination patterns`
141
- : ` ${c.yellow}⚠${c.reset} Potential hallucinations detected`);
142
- } catch (e) {
143
- results.hallucinations = { error: e.message };
144
- console.log(` ${c.yellow}⚠${c.reset} Hallucination check skipped: ${e.message}`);
145
- }
146
- }
147
-
148
- // Summary
149
- console.log(`
150
- ${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}`);
151
-
152
- if (results.verdict === "PASS") {
153
- console.log(` ${c.green}${c.bold}✓ GUARD PASS${c.reset} - All trust boundaries intact`);
154
- } else {
155
- console.log(` ${c.red}${c.bold}✗ GUARD FAIL${c.reset} - Trust boundary violations detected`);
156
- }
157
-
158
- console.log(`${c.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c.reset}
159
- `);
160
-
161
- if (jsonOutput) {
162
- console.log(JSON.stringify(results, null, 2));
163
- }
164
-
165
- return results.verdict === "PASS" ? 0 : (results.errors > 0 ? 2 : 1);
166
- }
167
-
168
- module.exports = { runGuard };
1
+ /**
2
+ * vibecheck guard - Unified trust boundary enforcement
3
+ *
4
+ * ═══════════════════════════════════════════════════════════════════════════════
5
+ * World-Class AI Guardrails
6
+ * ═══════════════════════════════════════════════════════════════════════════════
7
+ */
8
+
9
+ const path = require("path");
10
+ const fs = require("fs");
11
+ const { parseGlobalFlags, shouldSuppressOutput, isJsonMode } = require("./lib/global-flags");
12
+ const { EXIT } = require("./lib/exit-codes");
13
+ const {
14
+ ansi,
15
+ sym,
16
+ renderMinimalHeader,
17
+ renderSectionHeader,
18
+ renderVerdict,
19
+ renderSuccess,
20
+ renderError,
21
+ renderWarning,
22
+ renderFooter,
23
+ Spinner,
24
+ getTierFromKey,
25
+ } = require("./lib/unified-cli-output");
26
+
27
+ // Import underlying implementations
28
+ let runValidate, runPromptFirewall;
29
+ try {
30
+ runValidate = require("./runValidate").runValidate;
31
+ } catch {
32
+ runValidate = null;
33
+ }
34
+ try {
35
+ runPromptFirewall = require("./runPromptFirewall").runPromptFirewall;
36
+ } catch {
37
+ runPromptFirewall = null;
38
+ }
39
+
40
+ function printHelp() {
41
+ console.log(`
42
+ ${ansi.bold}USAGE${ansi.reset}
43
+ ${ansi.cyan}vibecheck guard${ansi.reset} [options]
44
+
45
+ ${ansi.dim}Aliases: ai-guard, firewall, validate${ansi.reset}
46
+
47
+ Validate AI-generated code and prompts. Detects prompt injection attempts,
48
+ verifies claims against your codebase (hallucination checking), and ensures
49
+ AI outputs meet your standards.
50
+
51
+ ${ansi.bold}CHECK MODES${ansi.reset}
52
+ ${ansi.cyan}--claims${ansi.reset} Verify AI claims against truthpack
53
+ ${ansi.cyan}--prompts${ansi.reset} Check code for prompt injection
54
+ ${ansi.cyan}--hallucinations${ansi.reset} Detect AI hallucination patterns
55
+ ${ansi.dim}(default: run all checks)${ansi.reset}
56
+
57
+ ${ansi.bold}OPTIONS${ansi.reset}
58
+ ${ansi.cyan}--file <path>${ansi.reset} Check specific file(s)
59
+ ${ansi.cyan}--strict${ansi.reset} Fail on warnings (default: fail on errors only)
60
+ ${ansi.cyan}--json${ansi.reset} Output as JSON (CI integration)
61
+ ${ansi.cyan}--quiet, -q${ansi.reset} Suppress non-essential output
62
+ ${ansi.cyan}--help, -h${ansi.reset} Show this help
63
+
64
+ ${ansi.bold}EXAMPLES${ansi.reset}
65
+ ${ansi.dim}# Run all guardrail checks${ansi.reset}
66
+ vibecheck guard
67
+
68
+ ${ansi.dim}# Verify AI claims in specific file${ansi.reset}
69
+ vibecheck guard --claims --file api.ts
70
+
71
+ ${ansi.dim}# Prompt injection scan only${ansi.reset}
72
+ vibecheck guard --prompts
73
+
74
+ ${ansi.dim}# CI pipeline (strict, JSON output)${ansi.reset}
75
+ vibecheck guard --strict --json
76
+
77
+ ${ansi.bold}EXIT CODES${ansi.reset}
78
+ 0 All checks passed
79
+ 1 Warnings found (non-blocking)
80
+ 2 Errors found (blocking issues)
81
+
82
+ ${ansi.dim}────────────────────────────────────────────────────────────────────${ansi.reset}
83
+ ${ansi.dim}Documentation: https://docs.vibecheckai.dev/cli/guard${ansi.reset}
84
+ `);
85
+ }
86
+
87
+ async function runGuard(args = []) {
88
+ const { flags: globalFlags } = parseGlobalFlags(args);
89
+ const quiet = shouldSuppressOutput(globalFlags);
90
+ const json = isJsonMode(globalFlags) || args.includes("--json");
91
+ const startTime = Date.now();
92
+
93
+ // Parse arguments
94
+ if (globalFlags.help || args.includes("--help") || args.includes("-h")) {
95
+ printHelp();
96
+ return EXIT.SUCCESS;
97
+ }
98
+
99
+ const runClaims = args.includes("--claims") || (!args.includes("--prompts") && !args.includes("--hallucinations"));
100
+ const runPrompts = args.includes("--prompts") || (!args.includes("--claims") && !args.includes("--hallucinations"));
101
+ const runHallucinations = args.includes("--hallucinations") || (!args.includes("--claims") && !args.includes("--prompts"));
102
+ const strict = args.includes("--strict");
103
+
104
+ // Validate --file if provided
105
+ const fileIndex = args.indexOf("--file");
106
+ if (fileIndex !== -1) {
107
+ const filePath = args[fileIndex + 1];
108
+ if (!filePath || filePath.startsWith("--")) {
109
+ if (json) {
110
+ console.log(JSON.stringify({ success: false, error: "--file requires a path argument" }));
111
+ } else {
112
+ renderError("--file requires a path argument");
113
+ }
114
+ return EXIT.USER_ERROR;
115
+ }
116
+ if (!fs.existsSync(filePath)) {
117
+ if (json) {
118
+ console.log(JSON.stringify({ success: false, error: `File not found: ${filePath}` }));
119
+ } else {
120
+ renderError(`File not found: ${filePath}`);
121
+ }
122
+ return EXIT.NOT_FOUND;
123
+ }
124
+ }
125
+
126
+ const results = {
127
+ claims: null,
128
+ prompts: null,
129
+ hallucinations: null,
130
+ verdict: "PASS",
131
+ errors: 0,
132
+ warnings: 0,
133
+ };
134
+
135
+ try {
136
+ if (!quiet && !json) {
137
+ renderMinimalHeader("guard", "starter");
138
+ renderSectionHeader("Trust Boundary Checks", sym.shield);
139
+ }
140
+
141
+ // Run claims verification
142
+ if (runClaims) {
143
+ const spinner = !quiet && !json ? new Spinner("Verifying AI claims against truthpack").start() : null;
144
+
145
+ if (!runValidate) {
146
+ results.claims = { skipped: true, reason: "Validator module not available" };
147
+ spinner?.warn("Claims check skipped: module not available");
148
+ } else {
149
+ try {
150
+ const validateArgs = args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a));
151
+ const exitCode = await runValidate(validateArgs);
152
+ results.claims = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
153
+ if (exitCode !== 0) {
154
+ results.errors++;
155
+ results.verdict = "FAIL";
156
+ spinner?.fail("Claim verification failed");
157
+ } else {
158
+ spinner?.succeed("Claims verified");
159
+ }
160
+ } catch (e) {
161
+ results.claims = { error: e.message };
162
+ spinner?.warn(`Claims check failed: ${e.message}`);
163
+ }
164
+ }
165
+ }
166
+
167
+ // Run prompt injection detection
168
+ if (runPrompts) {
169
+ const spinner = !quiet && !json ? new Spinner("Scanning for prompt injection vulnerabilities").start() : null;
170
+
171
+ if (!runPromptFirewall) {
172
+ results.prompts = { skipped: true, reason: "Firewall module not available" };
173
+ spinner?.warn("Prompt check skipped: module not available");
174
+ } else {
175
+ try {
176
+ const firewallArgs = args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a));
177
+ const exitCode = await runPromptFirewall(firewallArgs);
178
+ results.prompts = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
179
+ if (exitCode !== 0) {
180
+ results.warnings++;
181
+ if (strict) results.verdict = "FAIL";
182
+ spinner?.warn("Prompt injection risks detected");
183
+ } else {
184
+ spinner?.succeed("No prompt injection risks");
185
+ }
186
+ } catch (e) {
187
+ results.prompts = { error: e.message };
188
+ spinner?.warn(`Prompt check failed: ${e.message}`);
189
+ }
190
+ }
191
+ }
192
+
193
+ // Run hallucination detection
194
+ if (runHallucinations) {
195
+ const spinner = !quiet && !json ? new Spinner("Detecting hallucination patterns").start() : null;
196
+
197
+ if (!runValidate) {
198
+ results.hallucinations = { skipped: true, reason: "Validator module not available" };
199
+ spinner?.warn("Hallucination check skipped: module not available");
200
+ } else {
201
+ try {
202
+ const validateArgs = ["--hallucinations", ...args.filter(a => !["--claims", "--prompts", "--hallucinations"].includes(a))];
203
+ const exitCode = await runValidate(validateArgs);
204
+ results.hallucinations = { exitCode, status: exitCode === 0 ? "pass" : "fail" };
205
+ if (exitCode !== 0) {
206
+ results.warnings++;
207
+ if (strict) results.verdict = "FAIL";
208
+ spinner?.warn("Potential hallucinations detected");
209
+ } else {
210
+ spinner?.succeed("No hallucination patterns");
211
+ }
212
+ } catch (e) {
213
+ results.hallucinations = { error: e.message };
214
+ spinner?.warn(`Hallucination check failed: ${e.message}`);
215
+ }
216
+ }
217
+ }
218
+
219
+ // Summary
220
+ const duration = Date.now() - startTime;
221
+
222
+ if (!quiet && !json) {
223
+ renderVerdict(results.verdict === "PASS" ? "PASS" : "FAIL", {
224
+ warnings: results.warnings,
225
+ critical: results.errors,
226
+ duration,
227
+ });
228
+
229
+ renderFooter({
230
+ nextSteps: results.verdict === "PASS" ? [
231
+ { cmd: "vibecheck scan", desc: "run full code analysis" },
232
+ { cmd: "vibecheck ship", desc: "get ship verdict" },
233
+ ] : [
234
+ { cmd: "vibecheck fix --plan-only", desc: "view fix recommendations" },
235
+ ],
236
+ docsUrl: "https://docs.vibecheckai.dev/cli/guard",
237
+ });
238
+ }
239
+
240
+ if (json) {
241
+ console.log(JSON.stringify({ ...results, duration }, null, 2));
242
+ }
243
+
244
+ // Return appropriate exit code
245
+ if (results.verdict === "PASS") {
246
+ return EXIT.SUCCESS;
247
+ } else if (results.errors > 0) {
248
+ return EXIT.BLOCKING;
249
+ } else {
250
+ return EXIT.WARNINGS;
251
+ }
252
+ } catch (error) {
253
+ if (json) {
254
+ console.log(JSON.stringify({ success: false, error: error.message }));
255
+ } else {
256
+ renderError(`Guard check failed: ${error.message}`);
257
+ }
258
+ return EXIT.INTERNAL_ERROR;
259
+ }
260
+ }
261
+
262
+ module.exports = { runGuard };
@@ -12,6 +12,7 @@
12
12
  const fs = require("fs");
13
13
  const path = require("path");
14
14
  const { parseGlobalFlags, shouldShowBanner } = require("./lib/global-flags");
15
+ const { EXIT } = require("./lib/exit-codes");
15
16
 
16
17
  // Use enhanced wizard if available
17
18
  let InitWizard;
@@ -1747,7 +1748,7 @@ async function runInit(args) {
1747
1748
  console.log(` ${colors.info}${ICONS.info}${c.reset} Run ${c.cyan}vibecheck init --repair${c.reset} to fix partial state`);
1748
1749
  }
1749
1750
  if (!opts.dryRun) {
1750
- return 1; // Exit on error unless dry-run
1751
+ return EXIT.INTERNAL_ERROR; // Exit on error unless dry-run
1751
1752
  }
1752
1753
  }
1753
1754
  }
@@ -1765,7 +1766,7 @@ async function runInit(args) {
1765
1766
  }
1766
1767
  }
1767
1768
  if (!opts.dryRun) {
1768
- return 1;
1769
+ return EXIT.INTERNAL_ERROR;
1769
1770
  }
1770
1771
  }
1771
1772
  }