guardrail-cli 2.4.13 → 2.5.1

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 (244) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +548 -521
  3. package/dist/commands/autopilot-decision.d.ts +24 -0
  4. package/dist/commands/autopilot-decision.d.ts.map +1 -0
  5. package/dist/commands/autopilot-decision.js +304 -0
  6. package/dist/commands/autopilot-decision.js.map +1 -0
  7. package/dist/commands/autopilot.d.ts +33 -0
  8. package/dist/commands/autopilot.d.ts.map +1 -0
  9. package/dist/commands/autopilot.js +1539 -0
  10. package/dist/commands/autopilot.js.map +1 -0
  11. package/dist/commands/baseline.d.ts.map +1 -1
  12. package/dist/commands/baseline.js.map +1 -1
  13. package/dist/commands/cache.d.ts.map +1 -1
  14. package/dist/commands/cache.js +3 -1
  15. package/dist/commands/cache.js.map +1 -1
  16. package/dist/commands/context.d.ts +8 -0
  17. package/dist/commands/context.d.ts.map +1 -0
  18. package/dist/commands/context.js +340 -0
  19. package/dist/commands/context.js.map +1 -0
  20. package/dist/commands/debug.d.ts +78 -0
  21. package/dist/commands/debug.d.ts.map +1 -0
  22. package/dist/commands/debug.js +381 -0
  23. package/dist/commands/debug.js.map +1 -0
  24. package/dist/commands/evidence.d.ts.map +1 -1
  25. package/dist/commands/evidence.js +23 -7
  26. package/dist/commands/evidence.js.map +1 -1
  27. package/dist/commands/index.d.ts +5 -0
  28. package/dist/commands/index.d.ts.map +1 -1
  29. package/dist/commands/index.js +16 -1
  30. package/dist/commands/index.js.map +1 -1
  31. package/dist/commands/preview.d.ts +54 -0
  32. package/dist/commands/preview.d.ts.map +1 -0
  33. package/dist/commands/preview.js +352 -0
  34. package/dist/commands/preview.js.map +1 -0
  35. package/dist/commands/quality/check.d.ts +31 -0
  36. package/dist/commands/quality/check.d.ts.map +1 -0
  37. package/dist/commands/quality/check.js +242 -0
  38. package/dist/commands/quality/check.js.map +1 -0
  39. package/dist/commands/quality/index.d.ts +8 -0
  40. package/dist/commands/quality/index.d.ts.map +1 -0
  41. package/dist/commands/quality/index.js +14 -0
  42. package/dist/commands/quality/index.js.map +1 -0
  43. package/dist/commands/quality/setup-quality.d.ts +23 -0
  44. package/dist/commands/quality/setup-quality.d.ts.map +1 -0
  45. package/dist/commands/quality/setup-quality.js +452 -0
  46. package/dist/commands/quality/setup-quality.js.map +1 -0
  47. package/dist/commands/quality/tidy.d.ts +41 -0
  48. package/dist/commands/quality/tidy.d.ts.map +1 -0
  49. package/dist/commands/quality/tidy.js +466 -0
  50. package/dist/commands/quality/tidy.js.map +1 -0
  51. package/dist/commands/quality/utils.d.ts +73 -0
  52. package/dist/commands/quality/utils.d.ts.map +1 -0
  53. package/dist/commands/quality/utils.js +158 -0
  54. package/dist/commands/quality/utils.js.map +1 -0
  55. package/dist/commands/scan-secrets.d.ts.map +1 -1
  56. package/dist/commands/scan-secrets.js +35 -18
  57. package/dist/commands/scan-secrets.js.map +1 -1
  58. package/dist/commands/scan-vulnerabilities-enhanced.d.ts +1 -0
  59. package/dist/commands/scan-vulnerabilities-enhanced.d.ts.map +1 -1
  60. package/dist/commands/scan-vulnerabilities-enhanced.js +40 -14
  61. package/dist/commands/scan-vulnerabilities-enhanced.js.map +1 -1
  62. package/dist/commands/scan-vulnerabilities-osv.d.ts +1 -1
  63. package/dist/commands/scan-vulnerabilities-osv.d.ts.map +1 -1
  64. package/dist/commands/scan-vulnerabilities-osv.js +76 -45
  65. package/dist/commands/scan-vulnerabilities-osv.js.map +1 -1
  66. package/dist/commands/scan-vulnerabilities.d.ts.map +1 -1
  67. package/dist/commands/scan-vulnerabilities.js +82 -21
  68. package/dist/commands/scan-vulnerabilities.js.map +1 -1
  69. package/dist/commands/secrets-allowlist.d.ts.map +1 -1
  70. package/dist/commands/secrets-allowlist.js +12 -11
  71. package/dist/commands/secrets-allowlist.js.map +1 -1
  72. package/dist/fix/analytics.d.ts +121 -0
  73. package/dist/fix/analytics.d.ts.map +1 -0
  74. package/dist/fix/analytics.js +289 -0
  75. package/dist/fix/analytics.js.map +1 -0
  76. package/dist/fix/applicator.d.ts +21 -2
  77. package/dist/fix/applicator.d.ts.map +1 -1
  78. package/dist/fix/applicator.js +109 -6
  79. package/dist/fix/applicator.js.map +1 -1
  80. package/dist/fix/audit.d.ts +61 -0
  81. package/dist/fix/audit.d.ts.map +1 -0
  82. package/dist/fix/audit.js +149 -0
  83. package/dist/fix/audit.js.map +1 -0
  84. package/dist/fix/backup.d.ts +12 -2
  85. package/dist/fix/backup.d.ts.map +1 -1
  86. package/dist/fix/backup.js +53 -4
  87. package/dist/fix/backup.js.map +1 -1
  88. package/dist/fix/config.d.ts +78 -0
  89. package/dist/fix/config.d.ts.map +1 -0
  90. package/dist/fix/config.js +200 -0
  91. package/dist/fix/config.js.map +1 -0
  92. package/dist/fix/engine.d.ts.map +1 -1
  93. package/dist/fix/engine.js +5 -5
  94. package/dist/fix/engine.js.map +1 -1
  95. package/dist/fix/impact.d.ts +74 -0
  96. package/dist/fix/impact.d.ts.map +1 -0
  97. package/dist/fix/impact.js +281 -0
  98. package/dist/fix/impact.js.map +1 -0
  99. package/dist/fix/index.d.ts +3 -0
  100. package/dist/fix/index.d.ts.map +1 -1
  101. package/dist/fix/index.js +7 -1
  102. package/dist/fix/index.js.map +1 -1
  103. package/dist/fix/interactive.d.ts.map +1 -1
  104. package/dist/fix/interactive.js +9 -4
  105. package/dist/fix/interactive.js.map +1 -1
  106. package/dist/fix/learning.d.ts +109 -0
  107. package/dist/fix/learning.d.ts.map +1 -0
  108. package/dist/fix/learning.js +296 -0
  109. package/dist/fix/learning.js.map +1 -0
  110. package/dist/fix/metrics.d.ts +106 -0
  111. package/dist/fix/metrics.d.ts.map +1 -0
  112. package/dist/fix/metrics.js +138 -0
  113. package/dist/fix/metrics.js.map +1 -0
  114. package/dist/fix/parallel.d.ts +69 -0
  115. package/dist/fix/parallel.d.ts.map +1 -0
  116. package/dist/fix/parallel.js +203 -0
  117. package/dist/fix/parallel.js.map +1 -0
  118. package/dist/fix/report.d.ts +40 -0
  119. package/dist/fix/report.d.ts.map +1 -0
  120. package/dist/fix/report.js +212 -0
  121. package/dist/fix/report.js.map +1 -0
  122. package/dist/fix/strategy.d.ts +53 -0
  123. package/dist/fix/strategy.d.ts.map +1 -0
  124. package/dist/fix/strategy.js +143 -0
  125. package/dist/fix/strategy.js.map +1 -0
  126. package/dist/fix/templates.d.ts +58 -0
  127. package/dist/fix/templates.d.ts.map +1 -0
  128. package/dist/fix/templates.js +259 -0
  129. package/dist/fix/templates.js.map +1 -0
  130. package/dist/fix/testing.d.ts +68 -0
  131. package/dist/fix/testing.d.ts.map +1 -0
  132. package/dist/fix/testing.js +245 -0
  133. package/dist/fix/testing.js.map +1 -0
  134. package/dist/fix/validation.d.ts +71 -0
  135. package/dist/fix/validation.d.ts.map +1 -0
  136. package/dist/fix/validation.js +267 -0
  137. package/dist/fix/validation.js.map +1 -0
  138. package/dist/fix/visualization.d.ts +73 -0
  139. package/dist/fix/visualization.d.ts.map +1 -0
  140. package/dist/fix/visualization.js +243 -0
  141. package/dist/fix/visualization.js.map +1 -0
  142. package/dist/formatters/sarif-enhanced.d.ts.map +1 -1
  143. package/dist/formatters/sarif-enhanced.js +15 -7
  144. package/dist/formatters/sarif-enhanced.js.map +1 -1
  145. package/dist/formatters/sarif-v2.d.ts.map +1 -1
  146. package/dist/formatters/sarif-v2.js +82 -46
  147. package/dist/formatters/sarif-v2.js.map +1 -1
  148. package/dist/formatters/sarif.d.ts.map +1 -1
  149. package/dist/formatters/sarif.js +49 -22
  150. package/dist/formatters/sarif.js.map +1 -1
  151. package/dist/index.js +2544 -410
  152. package/dist/index.js.map +1 -1
  153. package/dist/init/ci-generator.d.ts.map +1 -1
  154. package/dist/init/ci-generator.js +186 -180
  155. package/dist/init/ci-generator.js.map +1 -1
  156. package/dist/init/detect-framework.d.ts.map +1 -1
  157. package/dist/init/detect-framework.js +19 -9
  158. package/dist/init/detect-framework.js.map +1 -1
  159. package/dist/init/hooks-installer.d.ts.map +1 -1
  160. package/dist/init/hooks-installer.js +74 -65
  161. package/dist/init/hooks-installer.js.map +1 -1
  162. package/dist/init/index.d.ts +3 -3
  163. package/dist/init/index.d.ts.map +1 -1
  164. package/dist/init/index.js.map +1 -1
  165. package/dist/init/templates.d.ts +10 -10
  166. package/dist/init/templates.d.ts.map +1 -1
  167. package/dist/init/templates.js +9 -4
  168. package/dist/init/templates.js.map +1 -1
  169. package/dist/reality/reality-runner.d.ts.map +1 -1
  170. package/dist/reality/reality-runner.js +23 -7
  171. package/dist/reality/reality-runner.js.map +1 -1
  172. package/dist/runtime/auth-utils.d.ts.map +1 -1
  173. package/dist/runtime/auth-utils.js.map +1 -1
  174. package/dist/runtime/cli-errors.d.ts +38 -0
  175. package/dist/runtime/cli-errors.d.ts.map +1 -0
  176. package/dist/runtime/cli-errors.js +354 -0
  177. package/dist/runtime/cli-errors.js.map +1 -0
  178. package/dist/runtime/client.d.ts.map +1 -1
  179. package/dist/runtime/client.js +27 -10
  180. package/dist/runtime/client.js.map +1 -1
  181. package/dist/runtime/creds.d.ts +5 -0
  182. package/dist/runtime/creds.d.ts.map +1 -1
  183. package/dist/runtime/creds.js +6 -1
  184. package/dist/runtime/creds.js.map +1 -1
  185. package/dist/runtime/exit-codes.d.ts +32 -4
  186. package/dist/runtime/exit-codes.d.ts.map +1 -1
  187. package/dist/runtime/exit-codes.js +42 -14
  188. package/dist/runtime/exit-codes.js.map +1 -1
  189. package/dist/runtime/owner-mode.d.ts +48 -0
  190. package/dist/runtime/owner-mode.d.ts.map +1 -0
  191. package/dist/runtime/owner-mode.js +284 -0
  192. package/dist/runtime/owner-mode.js.map +1 -0
  193. package/dist/runtime/semver.d.ts.map +1 -1
  194. package/dist/runtime/semver.js +5 -2
  195. package/dist/runtime/semver.js.map +1 -1
  196. package/dist/scanner/baseline.d.ts.map +1 -1
  197. package/dist/scanner/baseline.js +3 -3
  198. package/dist/scanner/baseline.js.map +1 -1
  199. package/dist/scanner/incremental.d.ts.map +1 -1
  200. package/dist/scanner/incremental.js +3 -3
  201. package/dist/scanner/incremental.js.map +1 -1
  202. package/dist/scanner/index.d.ts +8 -0
  203. package/dist/scanner/index.d.ts.map +1 -0
  204. package/dist/scanner/index.js +15 -0
  205. package/dist/scanner/index.js.map +1 -0
  206. package/dist/scanner/parallel.d.ts.map +1 -1
  207. package/dist/scanner/parallel.js +29 -8
  208. package/dist/scanner/parallel.js.map +1 -1
  209. package/dist/scanner/placeholder-detector.d.ts +56 -0
  210. package/dist/scanner/placeholder-detector.d.ts.map +1 -0
  211. package/dist/scanner/placeholder-detector.js +220 -0
  212. package/dist/scanner/placeholder-detector.js.map +1 -0
  213. package/dist/scanner/route-detector.d.ts +100 -0
  214. package/dist/scanner/route-detector.d.ts.map +1 -0
  215. package/dist/scanner/route-detector.js +455 -0
  216. package/dist/scanner/route-detector.js.map +1 -0
  217. package/dist/scanner/scoring.d.ts +67 -0
  218. package/dist/scanner/scoring.d.ts.map +1 -0
  219. package/dist/scanner/scoring.js +284 -0
  220. package/dist/scanner/scoring.js.map +1 -0
  221. package/dist/ship-baseline.d.ts +56 -0
  222. package/dist/ship-baseline.d.ts.map +1 -0
  223. package/dist/ship-baseline.js +194 -0
  224. package/dist/ship-baseline.js.map +1 -0
  225. package/dist/ship-config.d.ts +91 -0
  226. package/dist/ship-config.d.ts.map +1 -0
  227. package/dist/ship-config.js +133 -0
  228. package/dist/ship-config.js.map +1 -0
  229. package/dist/ship-data-loader.d.ts +70 -0
  230. package/dist/ship-data-loader.d.ts.map +1 -0
  231. package/dist/ship-data-loader.js +301 -0
  232. package/dist/ship-data-loader.js.map +1 -0
  233. package/dist/ui/frame.d.ts.map +1 -1
  234. package/dist/ui/frame.js +3 -1
  235. package/dist/ui/frame.js.map +1 -1
  236. package/dist/utils/ai-helpers.d.ts +72 -0
  237. package/dist/utils/ai-helpers.d.ts.map +1 -0
  238. package/dist/utils/ai-helpers.js +339 -0
  239. package/dist/utils/ai-helpers.js.map +1 -0
  240. package/dist/utils/validation.d.ts +34 -0
  241. package/dist/utils/validation.d.ts.map +1 -0
  242. package/dist/utils/validation.js +160 -0
  243. package/dist/utils/validation.js.map +1 -0
  244. package/package.json +3 -2
package/README.md CHANGED
@@ -1,521 +1,548 @@
1
- # Guardrail CLI
2
-
3
- The official command-line interface for Guardrail - AI-native code security and guardrail platform.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install -g guardrail-cli
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```bash
14
- # Authenticate with your API key
15
- guardrail auth --key gr_pro_your_api_key_here
16
-
17
- # Check authentication status (shows masked key)
18
- guardrail auth --status
19
-
20
- # Scan your project
21
- guardrail scan --path ./your-project
22
-
23
- # Ship readiness check
24
- guardrail ship --path ./your-project
25
- ```
26
-
27
- ## Authentication
28
-
29
- The CLI uses enterprise-grade authentication with secure credential storage.
30
-
31
- ### Commands
32
-
33
- ```bash
34
- # Authenticate with API key (validates against Guardrail API)
35
- guardrail auth --key gr_pro_abc123xyz789
36
-
37
- # Check current authentication status
38
- # Shows masked key (gr_pro_****xyz9), tier, email, expiry
39
- guardrail auth --status
40
-
41
- # Force refresh cached entitlements
42
- guardrail auth --refresh
43
-
44
- # Logout and remove stored credentials
45
- guardrail auth --logout
46
- ```
47
-
48
- ### Features
49
-
50
- - **Real API Validation**: Keys are validated against `POST /v1/cli/auth/validate`
51
- - **Secure Storage**: Credentials stored with 0600 permissions (Unix) or NTFS ACLs (Windows)
52
- - **Local Caching**: Entitlements cached for 15 minutes to reduce API calls
53
- - **Auto-Refresh**: Cache reused if > 5 minutes remaining; use `--refresh` to force
54
- - **Key Masking**: API keys always displayed masked: `gr_pro_****abcd`
55
- - **Expiry Warnings**: Yellow warning if entitlements expire within 72 hours
56
-
57
- ### Credential Storage
58
-
59
- | Platform | Location |
60
- |----------|----------|
61
- | macOS | `~/Library/Application Support/guardrail/state.json` |
62
- | Linux | `~/.config/guardrail/state.json` |
63
- | Windows | `%APPDATA%\guardrail\state.json` |
64
-
65
- If `keytar` is available, sensitive tokens are stored in the OS keychain.
66
-
67
- ## Commands
68
-
69
- - `guardrail auth` - Authenticate with your API key
70
- - `guardrail scan` - Run security scans
71
- - `guardrail scan:secrets` - Scan for hardcoded secrets
72
- - `guardrail scan:vulnerabilities` - Scan dependencies for CVEs (OSV integration)
73
- - `guardrail scan:compliance` - Compliance assessment (Pro)
74
- - `guardrail sbom:generate` - Generate SBOM (Pro)
75
- - `guardrail ship` - Ship readiness checks (Starter+)
76
- - `guardrail reality` - Browser testing for fake data (Starter+)
77
- - `guardrail smells` - Code smell analysis
78
- - `guardrail fix` - Manual fix suggestions (Starter+)
79
- - `guardrail autopilot` - AI-powered batch remediation (Pro)
80
- - `guardrail cache:clear` - Clear OSV vulnerability cache
81
- - `guardrail cache:status` - Show cache statistics
82
- - `guardrail init` - Initialize Guardrail in a project (see [Init Command](#init-command))
83
- - `guardrail menu` - Interactive menu
84
-
85
- ## Init Command
86
-
87
- The `guardrail init` command provides enterprise-grade project initialization with automatic framework detection and template-based configuration.
88
-
89
- ### Basic Usage
90
-
91
- ```bash
92
- # Initialize with interactive prompts (auto-detects framework)
93
- guardrail init
94
-
95
- # Initialize with a specific template
96
- guardrail init --template enterprise
97
-
98
- # Initialize with CI and git hooks
99
- guardrail init --ci --hooks
100
-
101
- # Non-interactive mode
102
- guardrail init --template startup --no-interactive
103
- ```
104
-
105
- ### Options
106
-
107
- | Option | Description |
108
- |--------|-------------|
109
- | `-p, --path <path>` | Project path (default: `.`) |
110
- | `-t, --template <template>` | Template: `startup`, `enterprise`, or `oss` |
111
- | `--ci` | Generate CI/CD workflow (GitHub Actions with SARIF upload) |
112
- | `--hooks` | Install git hooks (husky or lefthook) |
113
- | `--hook-runner <runner>` | Specify hook runner: `husky` or `lefthook` |
114
- | `--no-interactive` | Disable interactive prompts |
115
-
116
- ### Framework Detection
117
-
118
- Guardrail automatically detects your project framework by inspecting `package.json` and file structure:
119
-
120
- | Framework | Detection Signals |
121
- |-----------|-------------------|
122
- | **Next.js** | `next` dependency, `next.config.*`, `app/` or `pages/` directory |
123
- | **Express** | `express` dependency, `src/server.*` patterns, `routes/` directory |
124
- | **NestJS** | `@nestjs/core` dependency, `nest-cli.json`, `*.module.ts` files |
125
- | **Fastify** | `fastify` dependency, `@fastify/*` packages |
126
- | **Remix** | `@remix-run/*` packages, `remix.config.*`, `app/routes/` |
127
- | **Vite+React** | `vite` + `react` dependencies, `@vitejs/plugin-react` |
128
-
129
- Based on the detected framework, Guardrail recommends the most relevant scans:
130
-
131
- - **Next.js/Remix**: secrets, vulnerabilities, ship readiness, reality mode (auth flows)
132
- - **Express/NestJS/Fastify**: secrets, vulnerabilities, ship readiness, compliance (logging/rate limits)
133
- - **Vite+React**: secrets, vulnerabilities, ship readiness
134
-
135
- ### Templates
136
-
137
- Templates configure `.guardrail/config.json` with different defaults:
138
-
139
- #### Startup Template
140
- - **Use case**: Early-stage teams, fast iteration
141
- - **Scan thresholds**: High (fewer alerts)
142
- - **Compliance**: Disabled
143
- - **Gating**: Block on critical only
144
- - **Output**: Table format
145
- - **Noise reduction**: Suppress test files, low-confidence findings
146
-
147
- ```bash
148
- guardrail init --template startup
149
- ```
150
-
151
- #### Enterprise Template
152
- - **Use case**: Regulated industries, strict security requirements
153
- - **Scan thresholds**: Low (catch everything)
154
- - **Compliance**: Enabled (SOC2 by default)
155
- - **Gating**: Block on critical and high, baseline/allowlist enabled
156
- - **Output**: SARIF format with upload
157
- - **SBOM**: Enabled
158
-
159
- ```bash
160
- guardrail init --template enterprise
161
- ```
162
-
163
- #### OSS Template
164
- - **Use case**: Open source projects, contributor-friendly
165
- - **Focus**: Supply chain security (SBOM, vulnerabilities)
166
- - **Gating**: Permissive, baseline/allowlist enabled
167
- - **Output**: Markdown format (PR-friendly)
168
- - **Noise reduction**: Suppress test files, examples
169
-
170
- ```bash
171
- guardrail init --template oss
172
- ```
173
-
174
- ### Generated Files
175
-
176
- #### Configuration (`.guardrail/config.json`)
177
-
178
- ```json
179
- {
180
- "version": "1.0.0",
181
- "template": "enterprise",
182
- "framework": "nextjs",
183
- "scans": {
184
- "secrets": { "enabled": true, "threshold": "low" },
185
- "vulnerabilities": { "enabled": true, "threshold": "medium" },
186
- "compliance": { "enabled": true, "frameworks": ["soc2"] },
187
- "sbom": { "enabled": true }
188
- },
189
- "gating": {
190
- "enabled": true,
191
- "blockOnCritical": true,
192
- "blockOnHigh": true,
193
- "baselineEnabled": true,
194
- "allowlistEnabled": true
195
- },
196
- "output": {
197
- "format": "sarif",
198
- "sarifUpload": true,
199
- "badgeGeneration": true
200
- }
201
- }
202
- ```
203
-
204
- #### CI Workflow (`.github/workflows/guardrail.yml`)
205
-
206
- When using `--ci`, generates a GitHub Actions workflow that:
207
- - Runs secrets and vulnerability scans
208
- - Runs compliance checks (if enabled)
209
- - Generates SBOM (if enabled)
210
- - Uploads SARIF results to GitHub Security tab
211
- - Runs ship readiness check
212
- - Fails the workflow on critical/high findings
213
-
214
- **Required**: Add `GUARDRAIL_API_KEY` to your repository secrets.
215
-
216
- #### Git Hooks (`.husky/` or `lefthook.yml`)
217
-
218
- When using `--hooks`, installs:
219
- - **pre-commit**: Secrets scan on staged files
220
- - **pre-push**: Full secrets + vulnerability scan + ship check
221
-
222
- ### Examples
223
-
224
- ```bash
225
- # Next.js project with enterprise security
226
- guardrail init --template enterprise --ci --hooks
227
-
228
- # Express API with startup defaults
229
- guardrail init --path ./api --template startup
230
-
231
- # OSS project with lefthook
232
- guardrail init --template oss --hooks --hook-runner lefthook
233
-
234
- # CI-only setup (no hooks)
235
- guardrail init --template enterprise --ci --no-interactive
236
- ```
237
-
238
- ## Vulnerability Scanning (OSV Integration)
239
-
240
- The `scan:vulnerabilities` command uses real-time data from the [Open Source Vulnerabilities (OSV)](https://osv.dev) database.
241
-
242
- ### Features
243
-
244
- - **Real-time OSV API queries** - Live vulnerability data from Google's OSV database
245
- - **Multi-ecosystem support** - npm, PyPI, RubyGems, Go
246
- - **Lockfile parsing** - package-lock.json, pnpm-lock.yaml, yarn.lock
247
- - **24-hour caching** - Reduces API calls with local cache in `.guardrail/cache/osv.json`
248
- - **CVSS scoring** - Severity levels with optional NVD enrichment
249
- - **Remediation paths** - Upgrade suggestions with breaking change detection
250
- - **SARIF output** - GitHub code scanning integration
251
-
252
- ### Usage
253
-
254
- ```bash
255
- # Basic vulnerability scan
256
- guardrail scan:vulnerabilities --path ./my-project
257
-
258
- # Bypass cache for fresh data
259
- guardrail scan:vulnerabilities --no-cache
260
-
261
- # Enable NVD enrichment for CVSS scores (slower)
262
- guardrail scan:vulnerabilities --nvd
263
-
264
- # Output as SARIF for GitHub code scanning
265
- guardrail scan:vulnerabilities --format sarif -o results.sarif
266
-
267
- # Filter by ecosystem
268
- guardrail scan:vulnerabilities --ecosystem npm
269
-
270
- # Fail CI if critical vulnerabilities found
271
- guardrail scan:vulnerabilities --fail-on-critical
272
- ```
273
-
274
- ### Options
275
-
276
- | Option | Description |
277
- |--------|-------------|
278
- | `-p, --path <path>` | Project path to scan (default: `.`) |
279
- | `-f, --format <format>` | Output format: `table`, `json`, `sarif` (default: `table`) |
280
- | `-o, --output <file>` | Write report to file |
281
- | `--no-cache` | Bypass 24h cache, fetch fresh data from OSV |
282
- | `--nvd` | Enable NVD enrichment for CVSS scores (slower) |
283
- | `--fail-on-critical` | Exit with error if critical vulnerabilities found |
284
- | `--fail-on-high` | Exit with error if high+ vulnerabilities found |
285
- | `--ecosystem <eco>` | Filter by ecosystem: `npm`, `PyPI`, `RubyGems`, `Go` |
286
-
287
- ### Cache Management
288
-
289
- Vulnerability data is cached for 24 hours in `.guardrail/cache/osv.json`.
290
-
291
- ```bash
292
- # View cache statistics
293
- guardrail cache:status
294
-
295
- # Clear the cache
296
- guardrail cache:clear
297
-
298
- # Clear global cache
299
- guardrail cache:clear --global
300
- ```
301
-
302
- ### SARIF Output for GitHub
303
-
304
- Generate SARIF v2.1.0 output for GitHub code scanning:
305
-
306
- ```bash
307
- # Generate SARIF report
308
- guardrail scan:vulnerabilities --format sarif -o vuln-results.sarif
309
-
310
- # In GitHub Actions workflow:
311
- - name: Run Guardrail Vulnerability Scan
312
- run: guardrail scan:vulnerabilities --format sarif -o results.sarif
313
-
314
- - name: Upload SARIF to GitHub
315
- uses: github/codeql-action/upload-sarif@v2
316
- with:
317
- sarif_file: results.sarif
318
- ```
319
-
320
- The SARIF output includes:
321
- - Rule metadata with CVE/GHSA IDs
322
- - CVSS scores and vectors
323
- - Remediation suggestions
324
- - Package.json line locations
325
- - Direct vs transitive classification
326
-
327
- ### Consistent Command Headers
328
-
329
- All analysis commands (`scan`, `ship`, `smells`, etc.) display a consistent framed header with:
330
- - **Title**: Command name with icon
331
- - **Project**: Project name from directory
332
- - **Path**: Project path (truncated for long paths)
333
- - **Started**: Timestamp when command started
334
- - **Mode**: Tier badge when authenticated (FREE/STARTER/PRO/ENTERPRISE)
335
- - **Metadata**: Command-specific options (e.g., scan type, severity filter)
336
-
337
- The header respects `NO_COLOR` environment variable and `--no-color` flag for CI/accessibility.
338
-
339
- ## Tiers
340
-
341
- - **Free**: Basic scanning and validation
342
- - **Starter** ($29/mo): Ship checks, reality mode, fix suggestions
343
- - **Pro** ($99/mo): Advanced analysis, autopilot, smells detection, compliance
344
- - **Enterprise** ($499/mo): Custom policies, SSO, dedicated support
345
-
346
- ## Environment Variables
347
-
348
- | Variable | Description |
349
- |----------|-------------|
350
- | `GUARDRAIL_API_BASE_URL` | Override API endpoint (default: `https://api.guardrail.dev`) |
351
- | `GUARDRAIL_NO_INTERACTIVE` | Disable interactive prompts (`1` to disable) |
352
- | `GUARDRAIL_NO_UNICODE` | Disable Unicode output (`1` for ASCII-only) |
353
-
354
- ## Reality Mode
355
-
356
- Reality Mode detects fake data, mock backends, and placeholder content in your running application using Playwright browser automation.
357
-
358
- ### Generate Only (default)
359
-
360
- ```bash
361
- # Generate a Playwright test for the auth flow
362
- guardrail reality --flow auth
363
-
364
- # Generate test for a custom URL
365
- guardrail reality --url http://localhost:8080 --flow checkout
366
- ```
367
-
368
- ### Generate + Run
369
-
370
- ```bash
371
- # Generate and immediately execute the test
372
- guardrail reality --run --flow auth
373
-
374
- # Run in headed mode (show browser)
375
- guardrail reality --run --flow auth --headless=false
376
-
377
- # Custom timeout and workers
378
- guardrail reality --run --timeout 60 --workers 2
379
-
380
- # Use HTML reporter for detailed results
381
- guardrail reality --run --reporter html,list
382
-
383
- # Full configuration example
384
- guardrail reality --run \
385
- --url http://localhost:8080 \
386
- --flow checkout \
387
- --timeout 45 \
388
- --workers 4 \
389
- --reporter html,json \
390
- --trace retain-on-failure \
391
- --video retain-on-failure \
392
- --screenshot only-on-failure
393
- ```
394
-
395
- **Exit Code**: Mirrors Playwright's exit code (0 = pass, non-zero = fail)
396
-
397
- #### 3. Record Mode
398
-
399
- Opens Playwright in interactive recording mode using `codegen` to capture user actions.
400
-
401
- ```bash
402
- # Start recording session
403
- guardrail reality --record --url http://localhost:3000
404
-
405
- # Record with custom flow name
406
- guardrail reality --record --url http://localhost:8080 --flow signup
407
- ```
408
-
409
- **How it works**:
410
- 1. Opens browser with Playwright Inspector
411
- 2. Interact with your app (click, type, navigate)
412
- 3. Playwright records all actions with robust selectors
413
- 4. Generated test saved to `.guardrail/reality/<runId>/reality-<flow>.test.ts`
414
- 5. Press Ctrl+C when done
415
-
416
- ### Options
417
-
418
- | Flag | Description | Default |
419
- |------|-------------|---------|
420
- | `-p, --path <path>` | Project path | `.` |
421
- | `-u, --url <url>` | Base URL of running app | `http://localhost:3000` |
422
- | `-f, --flow <flow>` | Flow to test: auth, checkout, dashboard | `auth` |
423
- | `-t, --timeout <seconds>` | Test timeout in seconds | `30` |
424
- | `--headless` | Run in headless mode | `false` |
425
- | `--run` | Execute the generated test immediately | `false` |
426
- | `--record` | Open Playwright codegen for recording | `false` |
427
- | `--workers <n>` | Number of parallel workers | `1` |
428
- | `--reporter <type>` | Test reporter: list, dot, html, json | `list` |
429
- | `--trace <mode>` | Trace mode: on, off, retain-on-failure, on-first-retry | `retain-on-failure` |
430
- | `--video <mode>` | Video mode: on, off, retain-on-failure, on-first-retry | `retain-on-failure` |
431
- | `--screenshot <mode>` | Screenshot mode: on, off, only-on-failure | `only-on-failure` |
432
-
433
- ### Artifacts
434
-
435
- When using `--run`, artifacts are saved under `.guardrail/reality/<runId>/`:
436
-
437
- ```
438
- .guardrail/reality/auth-1704123456789-a1b2c3d4/
439
- ├── reality-auth.test.ts # Generated test file
440
- ├── output.log # Playwright console output
441
- ├── result.json # Run result summary (success, exitCode, duration)
442
- ├── run-metadata.json # Execution configuration
443
- ├── screenshots/ # Failure screenshots (if --screenshot enabled)
444
- │ ├── test-failed-1.png
445
- │ └── test-failed-2.png
446
- └── report/ # HTML report (if --reporter html)
447
- └── index.html
448
- ```
449
-
450
- ### Viewing Results
451
-
452
- **HTML Report** (if `--reporter html`):
453
- ```bash
454
- npx playwright show-report .guardrail/reality/<runId>/report
455
- ```
456
-
457
- **JSON Results**:
458
- ```bash
459
- cat .guardrail/reality/<runId>/result.json
460
- ```
461
-
462
- **Logs**:
463
- ```bash
464
- cat .guardrail/reality/<runId>/output.log
465
- ```
466
-
467
- ### Prerequisites
468
-
469
- Reality Mode requires Playwright and browser binaries.
470
-
471
- **Install Playwright**:
472
- ```bash
473
- npm install -D @playwright/test
474
- npx playwright install
475
- ```
476
-
477
- The CLI automatically detects missing dependencies and provides exact install commands with exit code 2.
478
-
479
- ### Exit Codes
480
-
481
- | Code | Meaning |
482
- |------|---------|
483
- | 0 | Tests passed |
484
- | 1 | Tests failed |
485
- | 2 | Playwright or browsers not installed |
486
-
487
- ### Examples
488
-
489
- **Quick test in CI**:
490
- ```bash
491
- guardrail reality --run --flow auth --headless --timeout 30
492
- ```
493
-
494
- **Debug with full visibility**:
495
- ```bash
496
- guardrail reality --run --flow checkout \
497
- --no-headless \
498
- --trace on \
499
- --video on \
500
- --screenshot on
501
- ```
502
-
503
- **Record custom flow**:
504
- ```bash
505
- guardrail reality --record --url http://localhost:3000 --flow onboarding
506
- ```
507
-
508
- **Parallel execution**:
509
- ```bash
510
- guardrail reality --run --workers 4 --reporter html,json
511
- ```
512
-
513
- ## Support
514
-
515
- - [Documentation](https://guardrail.dev/docs)
516
- - [Discord](https://discord.gg/guardrail)
517
- - [Support](mailto:support@guardrail.dev)
518
-
519
- ## License
520
-
521
- MIT
1
+ # Guardrail CLI v2.5.0 🎉
2
+
3
+ The official command-line interface for Guardrail - AI-native code security and guardrail platform.
4
+
5
+ ## ✨ What's New in v2.5.0
6
+
7
+ - 🎮 **Interactive Menu** - Arrow key navigation, visual selection indicators
8
+ - 🎭 **Reality Mode** - Automatic Playwright installation for browser testing
9
+ - 📦 **Ship Check** - Plain English audit and deployment readiness
10
+ - 🛠️ **AI Fixes** - Enhanced guided suggestions and automated remediation
11
+ - 🧪 **Full Test Coverage** - 50+ integration tests ensuring reliability
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install -g guardrail-cli@latest
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ # 🎮 Open the new interactive menu (recommended)
23
+ guardrail menu
24
+
25
+ # 🔐 Authenticate with your API key
26
+ guardrail auth --key gr_pro_your_api_key_here
27
+
28
+ # 🔍 Scan your project
29
+ guardrail scan --path ./your-project
30
+
31
+ # 🚀 Try Reality Mode (auto-installs Playwright)
32
+ guardrail reality --url https://your-site.com --flow user-journey
33
+
34
+ # 📦 Ship readiness check
35
+ guardrail ship --path ./your-project
36
+ ```
37
+
38
+ ## Authentication
39
+
40
+ The CLI uses enterprise-grade authentication with secure credential storage.
41
+
42
+ ### Commands
43
+
44
+ ```bash
45
+ # Authenticate with API key (validates against Guardrail API)
46
+ guardrail auth --key gr_pro_abc123xyz789
47
+
48
+ # Check current authentication status
49
+ # Shows masked key (gr_pro_****xyz9), tier, email, expiry
50
+ guardrail auth --status
51
+
52
+ # Force refresh cached entitlements
53
+ guardrail auth --refresh
54
+
55
+ # Logout and remove stored credentials
56
+ guardrail auth --logout
57
+ ```
58
+
59
+ ### Features
60
+
61
+ - **Real API Validation**: Keys are validated against `POST /v1/cli/auth/validate`
62
+ - **Secure Storage**: Credentials stored with 0600 permissions (Unix) or NTFS ACLs (Windows)
63
+ - **Local Caching**: Entitlements cached for 15 minutes to reduce API calls
64
+ - **Auto-Refresh**: Cache reused if > 5 minutes remaining; use `--refresh` to force
65
+ - **Key Masking**: API keys always displayed masked: `gr_pro_****abcd`
66
+ - **Expiry Warnings**: Yellow warning if entitlements expire within 72 hours
67
+
68
+ ### Credential Storage
69
+
70
+ | Platform | Location |
71
+ | -------- | ---------------------------------------------------- |
72
+ | macOS | `~/Library/Application Support/guardrail/state.json` |
73
+ | Linux | `~/.config/guardrail/state.json` |
74
+ | Windows | `%APPDATA%\guardrail\state.json` |
75
+
76
+ If `keytar` is available, sensitive tokens are stored in the OS keychain.
77
+
78
+ ## Commands
79
+
80
+ - `guardrail auth` - Authenticate with your API key
81
+ - `guardrail scan` - Run security scans
82
+ - `guardrail scan:secrets` - Scan for hardcoded secrets
83
+ - `guardrail scan:vulnerabilities` - Scan dependencies for CVEs (OSV integration)
84
+ - `guardrail scan:compliance` - Compliance assessment (Pro)
85
+ - `guardrail sbom:generate` - Generate SBOM (Pro)
86
+ - `guardrail ship` - Ship readiness checks (Starter+)
87
+ - `guardrail reality` - Browser testing for fake data (Starter+)
88
+ - `guardrail smells` - Code smell analysis
89
+ - `guardrail fix` - Manual fix suggestions (Starter+)
90
+ - `guardrail autopilot` - AI-powered batch remediation (Pro)
91
+ - `guardrail cache:clear` - Clear OSV vulnerability cache
92
+ - `guardrail cache:status` - Show cache statistics
93
+ - `guardrail init` - Initialize Guardrail in a project (see [Init Command](#init-command))
94
+ - `guardrail menu` - Interactive menu
95
+
96
+ ## Init Command
97
+
98
+ The `guardrail init` command provides enterprise-grade project initialization with automatic framework detection and template-based configuration.
99
+
100
+ ### Basic Usage
101
+
102
+ ```bash
103
+ # Initialize with interactive prompts (auto-detects framework)
104
+ guardrail init
105
+
106
+ # Initialize with a specific template
107
+ guardrail init --template enterprise
108
+
109
+ # Initialize with CI and git hooks
110
+ guardrail init --ci --hooks
111
+
112
+ # Non-interactive mode
113
+ guardrail init --template startup --no-interactive
114
+ ```
115
+
116
+ ### Options
117
+
118
+ | Option | Description |
119
+ | --------------------------- | ---------------------------------------------------------- |
120
+ | `-p, --path <path>` | Project path (default: `.`) |
121
+ | `-t, --template <template>` | Template: `startup`, `enterprise`, or `oss` |
122
+ | `--ci` | Generate CI/CD workflow (GitHub Actions with SARIF upload) |
123
+ | `--hooks` | Install git hooks (husky or lefthook) |
124
+ | `--hook-runner <runner>` | Specify hook runner: `husky` or `lefthook` |
125
+ | `--no-interactive` | Disable interactive prompts |
126
+
127
+ ### Framework Detection
128
+
129
+ Guardrail automatically detects your project framework by inspecting `package.json` and file structure:
130
+
131
+ | Framework | Detection Signals |
132
+ | -------------- | ------------------------------------------------------------------ |
133
+ | **Next.js** | `next` dependency, `next.config.*`, `app/` or `pages/` directory |
134
+ | **Express** | `express` dependency, `src/server.*` patterns, `routes/` directory |
135
+ | **NestJS** | `@nestjs/core` dependency, `nest-cli.json`, `*.module.ts` files |
136
+ | **Fastify** | `fastify` dependency, `@fastify/*` packages |
137
+ | **Remix** | `@remix-run/*` packages, `remix.config.*`, `app/routes/` |
138
+ | **Vite+React** | `vite` + `react` dependencies, `@vitejs/plugin-react` |
139
+
140
+ Based on the detected framework, Guardrail recommends the most relevant scans:
141
+
142
+ - **Next.js/Remix**: secrets, vulnerabilities, ship readiness, reality mode (auth flows)
143
+ - **Express/NestJS/Fastify**: secrets, vulnerabilities, ship readiness, compliance (logging/rate limits)
144
+ - **Vite+React**: secrets, vulnerabilities, ship readiness
145
+
146
+ ### Templates
147
+
148
+ Templates configure `.guardrail/config.json` with different defaults:
149
+
150
+ #### Startup Template
151
+
152
+ - **Use case**: Early-stage teams, fast iteration
153
+ - **Scan thresholds**: High (fewer alerts)
154
+ - **Compliance**: Disabled
155
+ - **Gating**: Block on critical only
156
+ - **Output**: Table format
157
+ - **Noise reduction**: Suppress test files, low-confidence findings
158
+
159
+ ```bash
160
+ guardrail init --template startup
161
+ ```
162
+
163
+ #### Enterprise Template
164
+
165
+ - **Use case**: Regulated industries, strict security requirements
166
+ - **Scan thresholds**: Low (catch everything)
167
+ - **Compliance**: Enabled (SOC2 by default)
168
+ - **Gating**: Block on critical and high, baseline/allowlist enabled
169
+ - **Output**: SARIF format with upload
170
+ - **SBOM**: Enabled
171
+
172
+ ```bash
173
+ guardrail init --template enterprise
174
+ ```
175
+
176
+ #### OSS Template
177
+
178
+ - **Use case**: Open source projects, contributor-friendly
179
+ - **Focus**: Supply chain security (SBOM, vulnerabilities)
180
+ - **Gating**: Permissive, baseline/allowlist enabled
181
+ - **Output**: Markdown format (PR-friendly)
182
+ - **Noise reduction**: Suppress test files, examples
183
+
184
+ ```bash
185
+ guardrail init --template oss
186
+ ```
187
+
188
+ ### Generated Files
189
+
190
+ #### Configuration (`.guardrail/config.json`)
191
+
192
+ ```json
193
+ {
194
+ "version": "1.0.0",
195
+ "template": "enterprise",
196
+ "framework": "nextjs",
197
+ "scans": {
198
+ "secrets": { "enabled": true, "threshold": "low" },
199
+ "vulnerabilities": { "enabled": true, "threshold": "medium" },
200
+ "compliance": { "enabled": true, "frameworks": ["soc2"] },
201
+ "sbom": { "enabled": true }
202
+ },
203
+ "gating": {
204
+ "enabled": true,
205
+ "blockOnCritical": true,
206
+ "blockOnHigh": true,
207
+ "baselineEnabled": true,
208
+ "allowlistEnabled": true
209
+ },
210
+ "output": {
211
+ "format": "sarif",
212
+ "sarifUpload": true,
213
+ "badgeGeneration": true
214
+ }
215
+ }
216
+ ```
217
+
218
+ #### CI Workflow (`.github/workflows/guardrail.yml`)
219
+
220
+ When using `--ci`, generates a GitHub Actions workflow that:
221
+
222
+ - Runs secrets and vulnerability scans
223
+ - Runs compliance checks (if enabled)
224
+ - Generates SBOM (if enabled)
225
+ - Uploads SARIF results to GitHub Security tab
226
+ - Runs ship readiness check
227
+ - Fails the workflow on critical/high findings
228
+
229
+ **Required**: Add `GUARDRAIL_API_KEY` to your repository secrets.
230
+
231
+ #### Git Hooks (`.husky/` or `lefthook.yml`)
232
+
233
+ When using `--hooks`, installs:
234
+
235
+ - **pre-commit**: Secrets scan on staged files
236
+ - **pre-push**: Full secrets + vulnerability scan + ship check
237
+
238
+ ### Examples
239
+
240
+ ```bash
241
+ # Next.js project with enterprise security
242
+ guardrail init --template enterprise --ci --hooks
243
+
244
+ # Express API with startup defaults
245
+ guardrail init --path ./api --template startup
246
+
247
+ # OSS project with lefthook
248
+ guardrail init --template oss --hooks --hook-runner lefthook
249
+
250
+ # CI-only setup (no hooks)
251
+ guardrail init --template enterprise --ci --no-interactive
252
+ ```
253
+
254
+ ## Vulnerability Scanning (OSV Integration)
255
+
256
+ The `scan:vulnerabilities` command uses real-time data from the [Open Source Vulnerabilities (OSV)](https://osv.dev) database.
257
+
258
+ ### Features
259
+
260
+ - **Real-time OSV API queries** - Live vulnerability data from Google's OSV database
261
+ - **Multi-ecosystem support** - npm, PyPI, RubyGems, Go
262
+ - **Lockfile parsing** - package-lock.json, pnpm-lock.yaml, yarn.lock
263
+ - **24-hour caching** - Reduces API calls with local cache in `.guardrail/cache/osv.json`
264
+ - **CVSS scoring** - Severity levels with optional NVD enrichment
265
+ - **Remediation paths** - Upgrade suggestions with breaking change detection
266
+ - **SARIF output** - GitHub code scanning integration
267
+
268
+ ### Usage
269
+
270
+ ```bash
271
+ # Basic vulnerability scan
272
+ guardrail scan:vulnerabilities --path ./my-project
273
+
274
+ # Bypass cache for fresh data
275
+ guardrail scan:vulnerabilities --no-cache
276
+
277
+ # Enable NVD enrichment for CVSS scores (slower)
278
+ guardrail scan:vulnerabilities --nvd
279
+
280
+ # Output as SARIF for GitHub code scanning
281
+ guardrail scan:vulnerabilities --format sarif -o results.sarif
282
+
283
+ # Filter by ecosystem
284
+ guardrail scan:vulnerabilities --ecosystem npm
285
+
286
+ # Fail CI if critical vulnerabilities found
287
+ guardrail scan:vulnerabilities --fail-on-critical
288
+ ```
289
+
290
+ ### Options
291
+
292
+ | Option | Description |
293
+ | ----------------------- | ---------------------------------------------------------- |
294
+ | `-p, --path <path>` | Project path to scan (default: `.`) |
295
+ | `-f, --format <format>` | Output format: `table`, `json`, `sarif` (default: `table`) |
296
+ | `-o, --output <file>` | Write report to file |
297
+ | `--no-cache` | Bypass 24h cache, fetch fresh data from OSV |
298
+ | `--nvd` | Enable NVD enrichment for CVSS scores (slower) |
299
+ | `--fail-on-critical` | Exit with error if critical vulnerabilities found |
300
+ | `--fail-on-high` | Exit with error if high+ vulnerabilities found |
301
+ | `--ecosystem <eco>` | Filter by ecosystem: `npm`, `PyPI`, `RubyGems`, `Go` |
302
+
303
+ ### Cache Management
304
+
305
+ Vulnerability data is cached for 24 hours in `.guardrail/cache/osv.json`.
306
+
307
+ ```bash
308
+ # View cache statistics
309
+ guardrail cache:status
310
+
311
+ # Clear the cache
312
+ guardrail cache:clear
313
+
314
+ # Clear global cache
315
+ guardrail cache:clear --global
316
+ ```
317
+
318
+ ### SARIF Output for GitHub
319
+
320
+ Generate SARIF v2.1.0 output for GitHub code scanning:
321
+
322
+ ```bash
323
+ # Generate SARIF report
324
+ guardrail scan:vulnerabilities --format sarif -o vuln-results.sarif
325
+
326
+ # In GitHub Actions workflow:
327
+ - name: Run Guardrail Vulnerability Scan
328
+ run: guardrail scan:vulnerabilities --format sarif -o results.sarif
329
+
330
+ - name: Upload SARIF to GitHub
331
+ uses: github/codeql-action/upload-sarif@v2
332
+ with:
333
+ sarif_file: results.sarif
334
+ ```
335
+
336
+ The SARIF output includes:
337
+
338
+ - Rule metadata with CVE/GHSA IDs
339
+ - CVSS scores and vectors
340
+ - Remediation suggestions
341
+ - Package.json line locations
342
+ - Direct vs transitive classification
343
+
344
+ ### Consistent Command Headers
345
+
346
+ All analysis commands (`scan`, `ship`, `smells`, etc.) display a consistent framed header with:
347
+
348
+ - **Title**: Command name with icon
349
+ - **Project**: Project name from directory
350
+ - **Path**: Project path (truncated for long paths)
351
+ - **Started**: Timestamp when command started
352
+ - **Mode**: Tier badge when authenticated (FREE/STARTER/PRO/ENTERPRISE)
353
+ - **Metadata**: Command-specific options (e.g., scan type, severity filter)
354
+
355
+ The header respects `NO_COLOR` environment variable and `--no-color` flag for CI/accessibility.
356
+
357
+ ## Tiers
358
+
359
+ - **Free**: Basic scanning and validation
360
+ - **Starter** ($29/mo): Ship checks, reality mode, fix suggestions
361
+ - **Pro** ($99/mo): Advanced analysis, autopilot, smells detection, compliance
362
+ - **Enterprise** ($499/mo): Custom policies, SSO, dedicated support
363
+
364
+ ## Environment Variables
365
+
366
+ | Variable | Description |
367
+ | -------------------------- | ------------------------------------------------------------ |
368
+ | `GUARDRAIL_API_BASE_URL` | Override API endpoint (default: `https://api.guardrail.dev`) |
369
+ | `GUARDRAIL_NO_INTERACTIVE` | Disable interactive prompts (`1` to disable) |
370
+ | `GUARDRAIL_NO_UNICODE` | Disable Unicode output (`1` for ASCII-only) |
371
+
372
+ ## Reality Mode
373
+
374
+ Reality Mode detects fake data, mock backends, and placeholder content in your running application using Playwright browser automation.
375
+
376
+ ### Generate Only (default)
377
+
378
+ ```bash
379
+ # Generate a Playwright test for the auth flow
380
+ guardrail reality --flow auth
381
+
382
+ # Generate test for a custom URL
383
+ guardrail reality --url http://localhost:8080 --flow checkout
384
+ ```
385
+
386
+ ### Generate + Run
387
+
388
+ ```bash
389
+ # Generate and immediately execute the test
390
+ guardrail reality --run --flow auth
391
+
392
+ # Run in headed mode (show browser)
393
+ guardrail reality --run --flow auth --headless=false
394
+
395
+ # Custom timeout and workers
396
+ guardrail reality --run --timeout 60 --workers 2
397
+
398
+ # Use HTML reporter for detailed results
399
+ guardrail reality --run --reporter html,list
400
+
401
+ # Full configuration example
402
+ guardrail reality --run \
403
+ --url http://localhost:8080 \
404
+ --flow checkout \
405
+ --timeout 45 \
406
+ --workers 4 \
407
+ --reporter html,json \
408
+ --trace retain-on-failure \
409
+ --video retain-on-failure \
410
+ --screenshot only-on-failure
411
+ ```
412
+
413
+ **Exit Code**: Mirrors Playwright's exit code (0 = pass, non-zero = fail)
414
+
415
+ #### 3. Record Mode
416
+
417
+ Opens Playwright in interactive recording mode using `codegen` to capture user actions.
418
+
419
+ ```bash
420
+ # Start recording session
421
+ guardrail reality --record --url http://localhost:3000
422
+
423
+ # Record with custom flow name
424
+ guardrail reality --record --url http://localhost:8080 --flow signup
425
+ ```
426
+
427
+ **How it works**:
428
+
429
+ 1. Opens browser with Playwright Inspector
430
+ 2. Interact with your app (click, type, navigate)
431
+ 3. Playwright records all actions with robust selectors
432
+ 4. Generated test saved to `.guardrail/reality/<runId>/reality-<flow>.test.ts`
433
+ 5. Press Ctrl+C when done
434
+
435
+ ### Options
436
+
437
+ | Flag | Description | Default |
438
+ | ------------------------- | ------------------------------------------------------ | ----------------------- |
439
+ | `-p, --path <path>` | Project path | `.` |
440
+ | `-u, --url <url>` | Base URL of running app | `http://localhost:3000` |
441
+ | `-f, --flow <flow>` | Flow to test: auth, checkout, dashboard | `auth` |
442
+ | `-t, --timeout <seconds>` | Test timeout in seconds | `30` |
443
+ | `--headless` | Run in headless mode | `false` |
444
+ | `--run` | Execute the generated test immediately | `false` |
445
+ | `--record` | Open Playwright codegen for recording | `false` |
446
+ | `--workers <n>` | Number of parallel workers | `1` |
447
+ | `--reporter <type>` | Test reporter: list, dot, html, json | `list` |
448
+ | `--trace <mode>` | Trace mode: on, off, retain-on-failure, on-first-retry | `retain-on-failure` |
449
+ | `--video <mode>` | Video mode: on, off, retain-on-failure, on-first-retry | `retain-on-failure` |
450
+ | `--screenshot <mode>` | Screenshot mode: on, off, only-on-failure | `only-on-failure` |
451
+
452
+ ### Artifacts
453
+
454
+ When using `--run`, artifacts are saved under `.guardrail/reality/<runId>/`:
455
+
456
+ ```
457
+ .guardrail/reality/auth-1704123456789-a1b2c3d4/
458
+ ├── reality-auth.test.ts # Generated test file
459
+ ├── output.log # Playwright console output
460
+ ├── result.json # Run result summary (success, exitCode, duration)
461
+ ├── run-metadata.json # Execution configuration
462
+ ├── screenshots/ # Failure screenshots (if --screenshot enabled)
463
+ │ ├── test-failed-1.png
464
+ │ └── test-failed-2.png
465
+ └── report/ # HTML report (if --reporter html)
466
+ └── index.html
467
+ ```
468
+
469
+ ### Viewing Results
470
+
471
+ **HTML Report** (if `--reporter html`):
472
+
473
+ ```bash
474
+ npx playwright show-report .guardrail/reality/<runId>/report
475
+ ```
476
+
477
+ **JSON Results**:
478
+
479
+ ```bash
480
+ cat .guardrail/reality/<runId>/result.json
481
+ ```
482
+
483
+ **Logs**:
484
+
485
+ ```bash
486
+ cat .guardrail/reality/<runId>/output.log
487
+ ```
488
+
489
+ ### Prerequisites
490
+
491
+ Reality Mode requires Playwright and browser binaries.
492
+
493
+ **Install Playwright**:
494
+
495
+ ```bash
496
+ npm install -D @playwright/test
497
+ npx playwright install
498
+ ```
499
+
500
+ The CLI automatically detects missing dependencies and provides exact install commands with exit code 2.
501
+
502
+ ### Exit Codes
503
+
504
+ | Code | Meaning |
505
+ | ---- | ------------------------------------ |
506
+ | 0 | Tests passed |
507
+ | 1 | Tests failed |
508
+ | 2 | Playwright or browsers not installed |
509
+
510
+ ### Examples
511
+
512
+ **Quick test in CI**:
513
+
514
+ ```bash
515
+ guardrail reality --run --flow auth --headless --timeout 30
516
+ ```
517
+
518
+ **Debug with full visibility**:
519
+
520
+ ```bash
521
+ guardrail reality --run --flow checkout \
522
+ --no-headless \
523
+ --trace on \
524
+ --video on \
525
+ --screenshot on
526
+ ```
527
+
528
+ **Record custom flow**:
529
+
530
+ ```bash
531
+ guardrail reality --record --url http://localhost:3000 --flow onboarding
532
+ ```
533
+
534
+ **Parallel execution**:
535
+
536
+ ```bash
537
+ guardrail reality --run --workers 4 --reporter html,json
538
+ ```
539
+
540
+ ## Support
541
+
542
+ - [Documentation](https://guardrail.dev/docs)
543
+ - [Discord](https://discord.gg/guardrail)
544
+ - [Support](mailto:support@guardrail.dev)
545
+
546
+ ## License
547
+
548
+ MIT