@rafter-security/cli 0.1.0 → 0.4.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.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @rafter-security/cli
2
2
 
3
- A Node.js CLI for Rafter Security that supports npm, pnpm, and yarn package managers.
3
+ Node.js CLI for [Rafter](https://rafter.so) zero-setup security for AI builders. This is the **full-featured package** with both backend scanning and agent security.
4
+
5
+ **Backend scanning** — Remote SAST/SCA via Rafter API. Trigger scans, retrieve structured vulnerability reports, pipe to any tool.
6
+
7
+ **Agent security** — Local-first protection for autonomous AI agents. Secret scanning (21+ patterns, Gitleaks), command interception with risk-tiered approval, pre-commit hooks, skill/extension auditing, and full audit logging. Works with Claude Code, Codex CLI, and OpenClaw. No API key required.
4
8
 
5
9
  ## Installation
6
10
 
@@ -17,11 +21,30 @@ yarn global add @rafter-security/cli
17
21
 
18
22
  ## Quick Start
19
23
 
24
+ ### Getting an API Key
25
+
26
+ To use backend scanning features, you'll need a Rafter API key:
27
+
28
+ 1. **Sign up**: Create an account at [rafter.so](https://rafter.so)
29
+ 2. **Get API key**: Navigate to Dashboard → Settings → API Keys
30
+ 3. **Set environment variable**:
31
+ ```bash
32
+ export RAFTER_API_KEY="your-api-key-here"
33
+ ```
34
+ 4. **Or use `.env` file**:
35
+ ```bash
36
+ echo "RAFTER_API_KEY=your-api-key-here" >> .env
37
+ ```
38
+
39
+ **Note**: Agent security features (secret scanning, command execution) work **without an API key**. Only backend scanning requires authentication.
40
+
41
+ ### Backend Scanning
42
+
20
43
  ```bash
21
- # Set your API key
44
+ # Set your API key (from above)
22
45
  export RAFTER_API_KEY="your-api-key-here"
23
46
 
24
- # Run a security scan
47
+ # Run a security scan (can also use 'rafter scan')
25
48
  rafter run
26
49
 
27
50
  # Get scan results
@@ -31,9 +54,29 @@ rafter get <scan-id>
31
54
  rafter usage
32
55
  ```
33
56
 
57
+ ### Agent Security
58
+
59
+ ```bash
60
+ # Initialize agent security
61
+ rafter agent init
62
+
63
+ # Scan files for secrets
64
+ rafter agent scan .
65
+
66
+ # Execute commands safely
67
+ rafter agent exec "git commit -m 'Add feature'"
68
+
69
+ # View audit logs
70
+ rafter agent audit
71
+
72
+ # Manage configuration
73
+ rafter agent config show
74
+ ```
75
+
34
76
  ## Commands
35
77
 
36
78
  ### `rafter run [options]`
79
+ **Alias:** `rafter scan`
37
80
 
38
81
  Trigger a new security scan for your repository.
39
82
 
@@ -49,12 +92,14 @@ Trigger a new security scan for your repository.
49
92
  ```bash
50
93
  # Basic scan with auto-detection
51
94
  rafter run
95
+ # or
96
+ rafter scan
52
97
 
53
98
  # Scan specific repo/branch
54
- rafter run --repo myorg/myrepo --branch feature-branch
99
+ rafter scan --repo myorg/myrepo --branch feature-branch
55
100
 
56
101
  # Non-interactive scan
57
- rafter run --skip-interactive
102
+ rafter scan --skip-interactive
58
103
  ```
59
104
 
60
105
  ### `rafter get <scan-id> [options]`
@@ -88,6 +133,308 @@ Check your API quota and usage.
88
133
  rafter usage
89
134
  ```
90
135
 
136
+ ---
137
+
138
+ ## Agent Security Commands
139
+
140
+ Rafter provides local security features for autonomous agents (OpenClaw, Claude Code) to prevent secrets leakage and dangerous operations.
141
+
142
+ ### `rafter agent init [options]`
143
+
144
+ Initialize agent security system.
145
+
146
+ **Options:**
147
+ - `--risk-level <level>` - Set risk level: `minimal`, `moderate`, or `aggressive` (default: `moderate`)
148
+ - `--skip-openclaw` - Skip OpenClaw skill installation
149
+
150
+ **What it does:**
151
+ - Creates `~/.rafter/config.json` configuration
152
+ - Initializes directory structure
153
+ - Detects and installs OpenClaw skill (if present)
154
+ - Sets up audit logging
155
+
156
+ **Example:**
157
+ ```bash
158
+ rafter agent init
159
+ rafter agent init --risk-level aggressive
160
+ ```
161
+
162
+ ### `rafter agent scan [path] [options]`
163
+
164
+ Scan files or directories for secrets.
165
+
166
+ **Arguments:**
167
+ - `path` - File or directory to scan (default: current directory)
168
+
169
+ **Options:**
170
+ - `-q, --quiet` - Only output if secrets found
171
+ - `--json` - Output results as JSON
172
+
173
+ **Features:**
174
+ - Detects 21+ secret types (AWS, GitHub, Stripe, Google, Slack, etc.)
175
+ - Shows severity levels (critical/high/medium/low)
176
+ - Displays line and column numbers
177
+ - Smart redaction (shows first/last 4 chars)
178
+ - Exits with code 1 if secrets found (CI-friendly)
179
+
180
+ **Examples:**
181
+ ```bash
182
+ # Scan current directory
183
+ rafter agent scan
184
+
185
+ # Scan specific file
186
+ rafter agent scan ./config.js
187
+
188
+ # Scan for CI (quiet mode)
189
+ rafter agent scan --quiet
190
+
191
+ # JSON output for processing
192
+ rafter agent scan --json
193
+ ```
194
+
195
+ **Detected patterns:**
196
+ - AWS Access Keys & Secret Keys
197
+ - GitHub Personal Access Tokens
198
+ - Google API Keys
199
+ - Slack Tokens & Webhooks
200
+ - Stripe API Keys
201
+ - Database connection strings
202
+ - JWT tokens
203
+ - npm & PyPI tokens
204
+ - Private keys (RSA, DSA, EC)
205
+ - Generic API keys and secrets
206
+
207
+ ### `rafter agent exec <command> [options]`
208
+
209
+ Execute shell command with security validation.
210
+
211
+ **Arguments:**
212
+ - `command` - Shell command to execute
213
+
214
+ **Options:**
215
+ - `--skip-scan` - Skip pre-execution file scanning
216
+ - `--force` - Skip approval prompts (use with caution, logged in audit)
217
+
218
+ **Features:**
219
+ - Blocks critical commands automatically (rm -rf /, fork bombs)
220
+ - Requires approval for high-risk operations
221
+ - Scans staged files before git commits
222
+ - Logs all executions to audit log
223
+ - Risk assessment for all commands
224
+
225
+ **Command risk levels:**
226
+ - **Critical** (blocked): `rm -rf /`, fork bombs, `dd` to /dev, `mkfs`
227
+ - **High** (requires approval): `rm -rf`, `sudo rm`, `chmod 777`, `curl|sh`, `git push --force`
228
+ - **Medium** (requires approval on moderate+): `sudo`, `chmod`, `kill -9`
229
+ - **Low** (allowed): Most other commands
230
+
231
+ **Examples:**
232
+ ```bash
233
+ # Safe command - executes immediately
234
+ rafter agent exec "npm install"
235
+
236
+ # Git commit - scans staged files first
237
+ rafter agent exec "git commit -m 'Add feature'"
238
+
239
+ # High-risk command - requires approval
240
+ rafter agent exec "sudo rm /tmp/old-files"
241
+
242
+ # Critical command - blocked
243
+ rafter agent exec "rm -rf /"
244
+ ```
245
+
246
+ ### `rafter agent config <subcommand>`
247
+
248
+ Manage agent configuration.
249
+
250
+ **Subcommands:**
251
+ - `show` - Display full configuration
252
+ - `get <key>` - Get specific configuration value
253
+ - `set <key> <value>` - Set configuration value
254
+
255
+ **Configuration keys:**
256
+ - `agent.riskLevel` - Risk level: `minimal`, `moderate`, `aggressive`
257
+ - `agent.commandPolicy.mode` - Policy mode: `allow-all`, `approve-dangerous`, `deny-list`
258
+ - `agent.outputFiltering.redactSecrets` - Redact secrets in output: `true` or `false`
259
+ - `agent.audit.logAllActions` - Log all actions: `true` or `false`
260
+ - `agent.audit.retentionDays` - Log retention period (days)
261
+
262
+ **Examples:**
263
+ ```bash
264
+ # View all configuration
265
+ rafter agent config show
266
+
267
+ # Get risk level
268
+ rafter agent config get agent.riskLevel
269
+
270
+ # Set to aggressive mode
271
+ rafter agent config set agent.riskLevel aggressive
272
+
273
+ # Change command policy
274
+ rafter agent config set agent.commandPolicy.mode deny-list
275
+ ```
276
+
277
+ ### `rafter agent audit [options]`
278
+
279
+ View security audit logs.
280
+
281
+ **Options:**
282
+ - `--last <n>` - Show last N entries (default: 10)
283
+ - `--event <type>` - Filter by event type
284
+ - `--agent <type>` - Filter by agent type (`openclaw`, `claude-code`)
285
+ - `--since <date>` - Show entries since date (YYYY-MM-DD)
286
+
287
+ **Event types:**
288
+ - `command_intercepted` - Command execution attempts
289
+ - `secret_detected` - Secret found in files
290
+ - `content_sanitized` - Output redacted
291
+ - `policy_override` - User override of security policy
292
+ - `scan_executed` - File scan performed
293
+ - `config_changed` - Configuration modified
294
+
295
+ **Examples:**
296
+ ```bash
297
+ # Show recent audit logs
298
+ rafter agent audit
299
+
300
+ # Show last 20 entries
301
+ rafter agent audit --last 20
302
+
303
+ # Filter by event type
304
+ rafter agent audit --event secret_detected
305
+
306
+ # Show logs since date
307
+ rafter agent audit --since 2026-02-01
308
+ ```
309
+
310
+ ### `rafter agent install-hook [options]`
311
+
312
+ Install git pre-commit hook to automatically scan for secrets before commits.
313
+
314
+ **Options:**
315
+ - `--global` - Install globally for all repos (via git config)
316
+
317
+ **Features:**
318
+ - Automatically scans staged files before each commit
319
+ - Blocks commits if secrets are detected
320
+ - Zero-configuration security for git workflows
321
+ - Can be bypassed with `git commit --no-verify` (not recommended)
322
+
323
+ **Examples:**
324
+ ```bash
325
+ # Install for current repository
326
+ cd my-repo
327
+ rafter agent install-hook
328
+
329
+ # Install globally for all repositories
330
+ rafter agent install-hook --global
331
+
332
+ # Uninstall global hook
333
+ git config --global --unset core.hooksPath
334
+ ```
335
+
336
+ **What it does:**
337
+ ```bash
338
+ # When you commit:
339
+ git add .env
340
+ git commit -m "Update config"
341
+
342
+ # Rafter automatically scans:
343
+ 🔍 Rafter: Scanning staged files for secrets...
344
+ ❌ Commit blocked: Secrets detected in staged files
345
+
346
+ Run: rafter agent scan --staged
347
+ To see details and remediate.
348
+ ```
349
+
350
+ **Why use pre-commit hooks?**
351
+
352
+ Pre-commit hooks provide the most effective protection against accidentally committing secrets to git:
353
+ - **Automatic**: No need to remember to scan manually
354
+ - **Fail-safe**: Prevents secrets from entering version control
355
+ - **CI-friendly**: Works locally before code reaches CI/CD
356
+ - **Team-wide**: Can be committed to `.git/hooks` or distributed via git config
357
+
358
+ Always install pre-commit hooks for repositories handling sensitive data.
359
+
360
+ ### `rafter agent audit-skill <skill-path> [options]`
361
+
362
+ Security audit of a Claude Code skill file before installation.
363
+
364
+ **Arguments:**
365
+ - `skill-path` - Path to skill file to audit
366
+
367
+ **Options:**
368
+ - `--skip-openclaw` - Skip OpenClaw integration, show manual review prompt
369
+ - `--json` - Output results as JSON
370
+
371
+ **Features:**
372
+ - **Quick Scan**: Detects secrets, external URLs, high-risk commands
373
+ - **Deep Analysis**: Uses OpenClaw's skill-auditor for comprehensive review (if installed)
374
+ - **12 Security Dimensions**: Trust, network security, command safety, file access, credentials, input validation, data exfiltration, obfuscation, scope alignment, error handling, dependencies, environment manipulation
375
+ - **Risk Rating**: LOW/MEDIUM/HIGH/CRITICAL assessment
376
+ - **Actionable Recommendations**: Clear install/don't install guidance
377
+
378
+ **Security Dimensions Analyzed:**
379
+ 1. Trust & Attribution - Source verification
380
+ 2. Network Security - External communication
381
+ 3. Command Execution - Shell command safety
382
+ 4. File System Access - Read/write patterns
383
+ 5. Credential Handling - Secret management
384
+ 6. Input Validation - Injection risks
385
+ 7. Data Exfiltration - What leaves the system
386
+ 8. Obfuscation - Hidden behavior detection
387
+ 9. Scope Alignment - Matches stated purpose
388
+ 10. Error Handling - Information disclosure
389
+ 11. Dependencies - Supply chain risks
390
+ 12. Environment Manipulation - System modifications
391
+
392
+ **Examples:**
393
+ ```bash
394
+ # Audit a skill file
395
+ rafter agent audit-skill ~/.openclaw/skills/untrusted-skill.md
396
+
397
+ # Audit with OpenClaw (comprehensive)
398
+ rafter agent audit-skill skill.md
399
+ # Then in OpenClaw: /rafter-audit-skill /path/to/skill.md
400
+
401
+ # Manual review prompt (no OpenClaw)
402
+ rafter agent audit-skill skill.md --skip-openclaw
403
+
404
+ # JSON output for automation
405
+ rafter agent audit-skill skill.md --json
406
+ ```
407
+
408
+ **Example Output:**
409
+ ```
410
+ 🔍 Auditing skill: untrusted-skill.md
411
+ ═══════════════════════════════════════════════════════════
412
+ 📊 Quick Scan Results
413
+ ⚠️ Secrets: 1 found
414
+ ⚠️ External URLs: 2 found
415
+ • https://api.example.com/v1/data
416
+ • https://untrusted-cdn.com/script.js
417
+ ⚠️ High-risk commands: 1 found
418
+ • curl | bash (line 45)
419
+
420
+ 🤖 For comprehensive security review:
421
+ 1. Open OpenClaw
422
+ 2. Run: /rafter-audit-skill /path/to/skill.md
423
+ ```
424
+
425
+ **Why audit skills?**
426
+
427
+ Claude Code skills can:
428
+ - Execute shell commands
429
+ - Access sensitive files
430
+ - Make network requests
431
+ - Handle credentials
432
+ - Process user input
433
+
434
+ Always audit skills from untrusted sources before installation. The skill-auditor provides systematic analysis to identify security risks.
435
+
436
+ ---
437
+
91
438
  ## Configuration
92
439
 
93
440
  ### Environment Variables
@@ -103,6 +450,129 @@ The CLI automatically detects your repository and branch from the current Git re
103
450
 
104
451
  **Note**: The CLI only scans remote repositories, not your current local branch.
105
452
 
453
+ ### Agent Security Configuration
454
+
455
+ Agent security settings are stored in `~/.rafter/config.json`. Key settings:
456
+
457
+ **Risk Levels:**
458
+ - `minimal` - Basic guidance only, most commands allowed
459
+ - `moderate` - Standard protections, approval for high-risk commands (recommended)
460
+ - `aggressive` - Maximum security, requires approval for most operations
461
+
462
+ **Command Policy Modes:**
463
+ - `allow-all` - Allow all commands (not recommended for production)
464
+ - `approve-dangerous` - Require approval for high/critical risk commands (default)
465
+ - `deny-list` - Block specific patterns, allow everything else
466
+
467
+ **File Locations:**
468
+ - Config: `~/.rafter/config.json`
469
+ - Audit log: `~/.rafter/audit.log`
470
+ - Binaries: `~/.rafter/bin/`
471
+ - Patterns: `~/.rafter/patterns/`
472
+
473
+ ## OpenClaw Integration
474
+
475
+ Rafter integrates seamlessly with [OpenClaw](https://openclaw.com) autonomous agents.
476
+
477
+ ### Setup
478
+
479
+ When OpenClaw is detected, `rafter agent init` automatically installs a skill to `~/.openclaw/skills/rafter-security.md`.
480
+
481
+ **What the skill provides:**
482
+ - `/rafter-scan` - Scan files before commits
483
+ - `/rafter-bash` - Execute commands with validation (via `rafter agent exec`)
484
+ - `/rafter-audit-skill` - Comprehensive security audit of Claude Code skills
485
+ - `/rafter-audit` - View security logs
486
+
487
+ ### Usage in OpenClaw
488
+
489
+ ```bash
490
+ # In OpenClaw, use Rafter commands naturally:
491
+ "Scan this directory for secrets"
492
+ # OpenClaw will call: rafter agent scan .
493
+
494
+ "Audit this skill for security issues"
495
+ # OpenClaw will call: /rafter-audit-skill <path>
496
+ # Provides comprehensive 12-dimension security analysis
497
+
498
+ "Commit these changes"
499
+ # OpenClaw will call: rafter agent exec "git commit -m '...'"
500
+ # Rafter scans staged files first, blocks if secrets found
501
+ ```
502
+
503
+ ### Best Practices
504
+
505
+ 1. **Install pre-commit hooks**: Run `rafter agent install-hook` to automatically scan before commits (recommended)
506
+ 2. **Audit untrusted skills**: Run `/rafter-audit-skill` before installing skills from unknown sources
507
+ 3. **Review blocked commands**: Check `rafter agent audit` when commands are blocked
508
+ 4. **Configure appropriately**: Use `moderate` risk level for most use cases
509
+ 5. **Keep patterns updated**: Patterns are updated automatically with CLI updates
510
+
511
+ ## Claude Code Integration
512
+
513
+ Rafter provides TWO skills for Claude Code:
514
+
515
+ ### 1. Backend Scanning Skill (Core Feature)
516
+
517
+ **Automatic Integration** - Claude can proactively suggest security scans
518
+
519
+ **Commands:**
520
+ - `rafter run` - Trigger security scan
521
+ - `rafter get <scan-id>` - Get results
522
+ - `rafter usage` - Check quota
523
+
524
+ **Installation:**
525
+ ```bash
526
+ rafter agent init
527
+ # Auto-detects Claude Code and installs both skills
528
+ ```
529
+
530
+ Or manually:
531
+ ```bash
532
+ cp -r node/.claude/skills/rafter ~/.claude/skills/
533
+ ```
534
+
535
+ **Usage:**
536
+ Claude will automatically suggest Rafter scans when you mention security, vulnerabilities, or code analysis. You can also invoke manually:
537
+ ```
538
+ Can you run a Rafter security scan on this repo?
539
+ ```
540
+
541
+ ### 2. Agent Security Skill
542
+
543
+ **User-Invoked** - Requires explicit commands for safety
544
+
545
+ **Commands:**
546
+ - `/rafter-scan` - Scan files for secrets
547
+ - `/rafter-bash` - Execute commands safely
548
+ - `/rafter-audit-skill` - Audit skills before installing
549
+ - `/rafter-audit` - View security logs
550
+
551
+ **Installation:**
552
+ ```bash
553
+ rafter agent init
554
+ # Installs automatically if Claude Code detected
555
+ ```
556
+
557
+ Or manually:
558
+ ```bash
559
+ cp -r node/.claude/skills/rafter-agent-security ~/.claude/skills/
560
+ ```
561
+
562
+ **Usage:**
563
+ Explicitly invoke commands:
564
+ ```
565
+ /rafter-scan .
566
+ /rafter-audit-skill untrusted-skill.md
567
+ ```
568
+
569
+ ### Why Two Skills?
570
+
571
+ - **Backend skill** - Safe for Claude to auto-invoke (read-only API calls)
572
+ - **Agent security skill** - Requires user permission (local file access, command execution)
573
+
574
+ This separation emphasizes Rafter's core backend scanning capabilities while keeping local security features safely behind user control.
575
+
106
576
  ## Documentation
107
577
 
108
578
  For comprehensive documentation, API reference, and examples, see [https://docs.rafter.so](https://docs.rafter.so).