@snapback/cli 1.0.10 → 1.0.11

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,288 +1,155 @@
1
1
  # @snapback/cli
2
2
 
3
- **Command-line interface for SnapBack** - AI-safe code snapshots, risk analysis, and intelligent validation.
3
+ > **Git is for commits. SnapBack is for "oh no, what did I just do?"**
4
4
 
5
- ## Installation
5
+ [![npm version](https://img.shields.io/npm/v/@snapback/cli.svg)](https://www.npmjs.com/package/@snapback/cli)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@snapback/cli.svg)](https://www.npmjs.com/package/@snapback/cli)
7
+ [![License](https://img.shields.io/npm/l/@snapback/cli.svg)](https://github.com/snapback-dev/snapback/blob/main/LICENSE)
6
8
 
7
- ```bash
8
- # Global installation
9
- npm install -g @snapback/cli
10
-
11
- # Or use via npx
12
- npx @snapback/cli <command>
13
-
14
- # Or with pnpm
15
- pnpm add -g @snapback/cli
16
- ```
17
-
18
- ## Quick Start
19
-
20
- ```bash
21
- # First-time setup with interactive wizard
22
- snap wizard
23
-
24
- # Initialize SnapBack in your project
25
- snap init
26
-
27
- # Analyze a file for risk
28
- snap analyze src/auth.ts
29
-
30
- # Create a snapshot before risky changes
31
- snap snapshot -m "Before major refactor"
32
-
33
- # Check staged files before commit
34
- snap check --all
9
+ AI coding assistants like **Cursor**, **GitHub Copilot**, and **Claude** are incredible—until they're not. One wrong autocomplete can cascade into hours of debugging. Git doesn't help because you haven't committed yet.
35
10
 
36
- # Run diagnostics if something seems wrong
37
- snap doctor
38
- ```
11
+ **SnapBack is your safety net for AI-native development.**
39
12
 
40
- ## Commands
13
+ ## Why SnapBack?
41
14
 
42
- ### Core Commands
15
+ | The Problem | The Solution |
16
+ |-------------|--------------|
17
+ | AI makes a bad change | Automatic snapshots before risky edits |
18
+ | You don't notice until later | Risk analysis flags dangerous patterns |
19
+ | Git history is clean (no commits yet) | One-click recovery with `snap undo` |
20
+ | Same mistake happens again | Learning loop auto-promotes patterns |
21
+ | Works in Cursor but not VS Code | Editor-agnostic protection |
43
22
 
44
- | Command | Description |
45
- |---------|-------------|
46
- | `snap init` | Initialize `.snapback/` directory in workspace |
47
- | `snap analyze <file>` | Risk analysis for a single file |
48
- | `snap snapshot` | Create a snapshot of current state |
49
- | `snap list` | List all snapshots |
50
- | `snap check` | Pre-commit hook to check for risky changes |
23
+ ### Key Metrics
51
24
 
52
- ### Intelligence Commands
25
+ - **<100ms** snapshot creation
26
+ - 🎯 **89%** AI change detection accuracy
27
+ - 🔒 **Privacy-first** — code never leaves your machine
28
+ - 🧠 **Self-improving** — learns from your mistakes automatically
53
29
 
54
- These commands integrate `@snapback/intelligence` for learning loop and validation:
30
+ ---
55
31
 
56
- | Command | Description | Example |
57
- |---------|-------------|---------|
58
- | `snap context [task]` | Get relevant context before work | `snap context "add auth" -k auth session` |
59
- | `snap validate <file>` | Run 7-layer validation pipeline | `snap validate src/auth.ts` |
60
- | `snap validate --all` | Validate all staged files | `snap validate --all --quiet` |
61
- | `snap stats` | Show learning statistics | `snap stats --json` |
32
+ ## Getting Started
62
33
 
63
- ### Learning Commands
34
+ SnapBack has two primary interfaces:
64
35
 
65
- | Command | Description |
66
- |---------|-------------|
67
- | `snap learn record` | Record a new learning |
68
- | `snap learn list` | List recorded learnings |
69
- | `snap patterns report` | Report a violation (auto-promotes at 3x) |
70
- | `snap patterns summary` | Show violation patterns and status |
36
+ ### 🎨 VS Code Extension (Recommended)
71
37
 
72
- ### Protection Commands
73
-
74
- | Command | Description |
75
- |---------|-------------|
76
- | `snap protect add <file>` | Add file to protection list |
77
- | `snap protect remove <file>` | Remove file from protection |
78
- | `snap protect list` | List protected files |
79
- | `snap session start` | Start a coding session |
80
- | `snap session end` | End current session |
81
-
82
- ### Utility Commands
83
-
84
- | Command | Description |
85
- |---------|-------------|
86
- | `snap status` | Show workspace status |
87
- | `snap fix` | Fix common issues |
88
- | `snap watch` | Continuous file watching daemon |
89
- | `snap interactive` | Guided TUI workflow |
90
-
91
- ### Polish Commands
92
-
93
- | Command | Description |
94
- |---------|-------------|
95
- | `snap wizard` | Interactive first-run setup wizard |
96
- | `snap doctor` | Comprehensive diagnostics and health check |
97
- | `snap doctor --fix` | Auto-fix detected issues |
98
- | `snap upgrade` | Check for and install CLI updates |
99
- | `snap upgrade --check` | Only check for updates, don't install |
100
- | `snap config list` | List all configuration values |
101
- | `snap config get <key>` | Get a specific config value |
102
- | `snap config set <key> <value>` | Set a configuration value |
103
- | `snap config path` | Show config file locations |
104
- | `snap undo` | Undo the last destructive operation |
105
- | `snap undo --list` | Show recent undoable operations |
106
- | `snap alias list` | List command shortcuts |
107
- | `snap alias set <name> <cmd>` | Create a command alias |
108
- | `snap alias suggest` | Show recommended aliases |
109
-
110
- ### MCP Server Command
111
-
112
- | Command | Description |
113
- |---------|-------------|
114
- | `snap mcp --stdio` | Start MCP server for Cursor/Claude integration |
115
-
116
- ## World-Class UX Features
117
-
118
- SnapBack CLI implements best practices from GitHub CLI, Vercel CLI, and Stripe CLI.
119
-
120
- ### Smart Error Messages
121
-
122
- When something goes wrong, SnapBack suggests fixes:
38
+ The extension provides the best experience with automatic snapshots, visual recovery UI, and real-time risk indicators.
123
39
 
124
40
  ```
125
- ╭───────────────────────────────────────────────────╮
126
- │ [ERR_NOT_INIT] Workspace Not Initialized │
127
- │ │
128
- │ This workspace hasn't been set up for SnapBack │
129
- │ │
130
- │ 💡 Suggestion: │
131
- │ Initialize SnapBack in this directory │
132
- │ │
133
- │ 📋 Try running: │
134
- │ $ snap init │
135
- ╰───────────────────────────────────────────────────╯
41
+ ext install snapback-vscode
136
42
  ```
137
43
 
138
- ### Unknown Command Suggestions
44
+ Or search "SnapBack" in the VS Code Extensions marketplace.
139
45
 
140
- Typos are caught with helpful suggestions:
46
+ [![VS Code Marketplace](https://img.shields.io/visual-studio-marketplace/v/snapback.snapback-vscode.svg)](https://marketplace.visualstudio.com/items?itemName=snapback.snapback-vscode)
141
47
 
142
- ```bash
143
- $ snap statis
144
- ╭────────────────────────────────╮
145
- │ Unknown command: statis │
146
- │ │
147
- │ Did you mean: │
148
- │ $ snap status │
149
- │ $ snap stats │
150
- ╰────────────────────────────────╯
151
- ```
48
+ ### 💻 CLI Tool
152
49
 
153
- ### Interactive First-Run Wizard
50
+ For terminal workflows, CI/CD integration, and MCP server setup:
154
51
 
155
52
  ```bash
156
- $ snap wizard
157
- ```
158
-
159
- Guided 5-step onboarding:
160
- 1. **Authentication** - Browser login or API key
161
- 2. **Workspace Setup** - Auto-detects project type
162
- 3. **Protection Level** - Standard or Strict mode
163
- 4. **MCP Integration** - Configure AI tool integration
164
- 5. **Analytics** - Optional anonymous usage data
165
-
166
- ### Terminal Hyperlinks
53
+ # Install globally
54
+ npm install -g @snapback/cli
167
55
 
168
- In supported terminals (iTerm2, VS Code, Windows Terminal, Kitty, etc.), SnapBack outputs clickable links:
169
- - File paths open in your editor
170
- - Documentation links open in browser
171
- - Error codes link to troubleshooting guides
56
+ # Or run without installing
57
+ npx @snapback/cli <command>
58
+ ```
172
59
 
173
- ### Command Aliases
60
+ ---
174
61
 
175
- Create shortcuts for common workflows:
62
+ ## Quick Start
176
63
 
177
64
  ```bash
178
- # Create aliases
179
- snap alias set st status
180
- snap alias set ss snapshot
181
- snap alias set ctx "context --keywords"
65
+ # Interactive setup wizard (recommended for first-time users)
66
+ snap wizard
182
67
 
183
- # Now use them
184
- snap st # → snap status
185
- snap ss -m "before refactor" # → snap snapshot -m "..."
68
+ # Or quick init
69
+ snap init
186
70
 
187
- # See suggested aliases
188
- snap alias suggest
189
- ```
71
+ # Analyze a file for risk
72
+ snap analyze src/auth.ts
190
73
 
191
- ### Undo Support
74
+ # Create a snapshot before risky changes
75
+ snap snapshot -m "Before auth refactor"
192
76
 
193
- Revert destructive operations:
77
+ # Pre-commit validation
78
+ snap check --all
194
79
 
195
- ```bash
196
- # Undo the last operation
80
+ # Something went wrong? Recover instantly
197
81
  snap undo
198
-
199
- # View recent operations
200
- snap undo --list
201
82
  ```
202
83
 
203
- ### Dry-Run Mode
204
-
205
- Preview changes before executing:
206
-
207
- ```bash
208
- snap init --dry-run
209
- ```
84
+ ---
210
85
 
211
- Shows exactly what files will be created/modified without making changes.
86
+ ## MCP Integration (Cursor, Claude, Windsurf)
212
87
 
213
- ### Confirmation Prompts
88
+ SnapBack includes an MCP (Model Context Protocol) server that lets AI assistants understand your codebase and create checkpoints.
214
89
 
215
- Destructive operations require confirmation:
216
- - Standard risk: Simple Y/n prompt
217
- - High risk: Must type "yes, delete" to confirm
218
- - Use `--force` to skip (for CI/automation)
90
+ ### Quick Setup (Recommended)
219
91
 
220
- ### Diagnostics (Doctor Command)
92
+ The CLI can automatically configure MCP for all detected AI tools:
221
93
 
222
94
  ```bash
223
- $ snap doctor
224
-
225
- 🏥 SnapBack Diagnostics
95
+ # Auto-detect and configure all AI tools
96
+ snap tools configure
226
97
 
227
- Node.js version v20.10.0
228
- CLI installation v0.5.2 (latest)
229
- Global directory ~/.snapback/ exists
230
- Authentication Logged in as @user
231
- ✓ Workspace .snapback/ initialized
232
- ✓ MCP tools 3 tools configured
233
- ✓ Git repository Clean
234
- ✓ Network API reachable
235
-
236
- All checks passed!
98
+ # Or configure specific tools
99
+ snap tools configure --cursor
100
+ snap tools configure --claude
101
+ snap tools configure --windsurf
237
102
  ```
238
103
 
239
- ### Shell Completions
104
+ ### Manual Setup
240
105
 
241
- Enable tab completion for your shell:
106
+ If you prefer manual configuration or the auto-setup doesn't work, add this to your AI tool's MCP config:
242
107
 
243
- **Bash:**
244
- ```bash
245
- eval "$(snap completion bash)"
246
- # Or add to ~/.bashrc
247
- ```
248
-
249
- **Zsh:**
250
- ```bash
251
- eval "$(snap completion zsh)"
252
- # Or add to ~/.zshrc
253
- ```
108
+ #### Option 1: Using npx (Recommended)
254
109
 
255
- **Fish:**
256
- ```fish
257
- snap completion fish | source
258
- # Or save to ~/.config/fish/completions/snap.fish
110
+ ```json
111
+ {
112
+ "mcpServers": {
113
+ "snapback": {
114
+ "command": "npx",
115
+ "args": [
116
+ "-y",
117
+ "@snapback/cli",
118
+ "mcp",
119
+ "--stdio",
120
+ "--workspace",
121
+ "/absolute/path/to/your/project"
122
+ ],
123
+ "env": {
124
+ "SNAPBACK_API_KEY": "your-api-key-here"
125
+ }
126
+ }
127
+ }
128
+ }
259
129
  ```
260
130
 
261
- Completion scripts are also available at:
262
- - `apps/cli/resources/completions/snap.bash`
263
- - `apps/cli/resources/completions/snap.zsh`
264
- - `apps/cli/resources/completions/snap.fish`
265
-
266
- ## MCP Server Integration
267
-
268
- SnapBack includes an MCP (Model Context Protocol) server for integration with AI coding assistants like Cursor, Claude Desktop, Windsurf, and others.
131
+ #### Option 2: Using Global Install
269
132
 
270
- ### Starting the MCP Server
271
-
272
- ```bash
273
- # Start with stdio transport (default)
274
- snap mcp --stdio
275
-
276
- # Specify workspace explicitly
277
- snap mcp --stdio --workspace /path/to/your/project
278
-
279
- # Specify user tier
280
- snap mcp --stdio --tier pro
133
+ ```json
134
+ {
135
+ "mcpServers": {
136
+ "snapback": {
137
+ "command": "snap",
138
+ "args": [
139
+ "mcp",
140
+ "--stdio",
141
+ "--workspace",
142
+ "/absolute/path/to/your/project"
143
+ ],
144
+ "env": {
145
+ "SNAPBACK_API_KEY": "your-api-key-here"
146
+ }
147
+ }
148
+ }
149
+ }
281
150
  ```
282
151
 
283
- ### Configuration for AI Clients
284
-
285
- Add to your MCP client configuration (e.g., `mcp.json` for Qoder, Claude, or Cursor):
152
+ #### Option 3: Using Node Directly
286
153
 
287
154
  ```json
288
155
  {
@@ -290,7 +157,7 @@ Add to your MCP client configuration (e.g., `mcp.json` for Qoder, Claude, or Cur
290
157
  "snapback": {
291
158
  "command": "node",
292
159
  "args": [
293
- "/absolute/path/to/apps/cli/dist/index.js",
160
+ "/absolute/path/to/node_modules/@snapback/cli/dist/index.js",
294
161
  "mcp",
295
162
  "--stdio",
296
163
  "--workspace",
@@ -304,148 +171,300 @@ Add to your MCP client configuration (e.g., `mcp.json` for Qoder, Claude, or Cur
304
171
  }
305
172
  ```
306
173
 
307
- **Important:** Both the CLI path and workspace path must be **absolute paths**.
174
+ ### Config File Locations
175
+
176
+ | Tool | Config Path |
177
+ |------|-------------|
178
+ | **Claude Desktop** | `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) |
179
+ | **Cursor** | `~/.cursor/mcp.json` |
180
+ | **Windsurf** | `~/.windsurf/mcp.json` |
181
+ | **Continue** | `~/.continue/config.json` |
308
182
 
309
183
  ### Workspace Requirements
310
184
 
311
- The MCP server validates that the workspace contains at least one of these markers:
185
+ The MCP server requires at least one of these markers in your project:
312
186
 
313
187
  - `.git/` directory
314
188
  - `package.json` file
315
189
  - `.snapback/` directory
316
190
 
317
- If validation fails, you'll see:
318
- ```
319
- [SnapBack MCP] Workspace validation failed: Workspace must contain at least one marker: .git, package.json, or .snapback
191
+ ### Verify Setup
192
+
193
+ ```bash
194
+ # Check which tools are configured
195
+ snap tools status
196
+
197
+ # Validate configurations
198
+ snap tools validate
199
+
200
+ # Repair broken configs
201
+ snap tools repair
320
202
  ```
321
203
 
322
- **Solution:** Ensure the `--workspace` argument points to a valid project root.
204
+ ### Available MCP Tools
323
205
 
324
- ### Troubleshooting
206
+ Once configured, your AI assistant can use:
325
207
 
326
- | Error | Cause | Solution |
327
- |-------|-------|----------|
328
- | `Cannot find module` | Relative path used | Use absolute paths for both CLI and workspace |
329
- | `Workspace validation failed` | Missing `--workspace` arg | Add `--workspace /path/to/project` to args |
330
- | `context deadline exceeded` | Server timeout | Check environment variables are set correctly |
208
+ | Tool | Description |
209
+ |------|-------------|
210
+ | `snapback.get_context` | Understand your codebase |
211
+ | `snapback.analyze_risk` | Assess change risks |
212
+ | `snapback.create_checkpoint` | Create safety snapshots (Pro) |
213
+ | `snapback.restore_checkpoint` | Recover from mistakes (Pro) |
331
214
 
332
- ### Environment Variables
215
+ ---
333
216
 
334
- | Variable | Required | Description |
335
- |----------|----------|-------------|
336
- | `SNAPBACK_API_KEY` | Optional | API key for Pro features |
337
- | `BETTER_AUTH_SECRET` | Optional | Auth secret (32+ chars) |
338
- | `DATABASE_URL` | Optional | PostgreSQL connection URL |
339
- | `REDIS_URL` | Optional | Redis/Upstash URL |
217
+ ## How It Compares
340
218
 
341
- ## Intelligence Integration
219
+ ### vs. Git Stash
342
220
 
343
- The CLI integrates `@snapback/intelligence` to provide the same learning loop and validation capabilities as SnapBack's internal development tools.
221
+ | Feature | Git Stash | SnapBack |
222
+ |---------|-----------|----------|
223
+ | Automatic snapshots | ❌ Manual | ✅ On save |
224
+ | AI change detection | ❌ | ✅ Cursor, Copilot, Claude |
225
+ | Risk analysis | ❌ | ✅ Per-file scoring |
226
+ | Recovery UX | 😬 Arcane | ✅ `snap undo` |
344
227
 
345
- ### Pre-Work Context
228
+ ### vs. Cursor's Built-in Checkpoints
346
229
 
347
- Get relevant patterns, learnings, and constraints before starting work:
230
+ | Feature | Cursor | SnapBack |
231
+ |---------|--------|----------|
232
+ | Works in any editor | ❌ | ✅ |
233
+ | Risk scoring | ❌ | ✅ |
234
+ | Learning from mistakes | ❌ | ✅ |
235
+ | CLI access | ❌ | ✅ |
236
+ | MCP integration | ❌ | ✅ |
348
237
 
349
- ```bash
350
- # Get context for a task
351
- snap context "add user authentication"
238
+ ### vs. Static Analysis (SonarQube, CodeClimate)
352
239
 
353
- # Include files you'll modify
354
- snap context "refactor auth" --files src/auth.ts src/session.ts
240
+ | Feature | Static Analysis | SnapBack |
241
+ |---------|-----------------|----------|
242
+ | Local-first | ❌ Cloud | ✅ |
243
+ | AI source detection | ❌ | ✅ |
244
+ | Recovery/snapshots | ❌ | ✅ |
245
+ | Personal learning | ❌ | ✅ |
355
246
 
356
- # Search with specific keywords
357
- snap context --keywords auth session jwt
247
+ ---
358
248
 
359
- # Machine-readable output
360
- snap context "add auth" --json
361
- ```
249
+ ## Commands
362
250
 
363
- **Output:**
364
- ```
365
- ┌─────────────────────────────────────────┐
366
- │ 📋 Context Loaded │
367
- │ │
368
- │ Hard Rules: 12 constraints │
369
- │ Patterns: 8 patterns │
370
- │ Learnings: 3 relevant │
371
- │ Violations: 2 to avoid │
372
- └─────────────────────────────────────────┘
373
-
374
- Relevant Learnings:
375
- ┌──────────┬──────────────┬─────────────────────────────────┐
376
- │ Type │ Trigger │ Action │
377
- ├──────────┼──────────────┼─────────────────────────────────┤
378
- │ pattern │ auth │ Use @snapback/auth package... │
379
- └──────────┴──────────────┴─────────────────────────────────┘
380
- ```
251
+ ### Core Commands
381
252
 
382
- ### Pre-Commit Validation
253
+ | Command | Description |
254
+ |---------|-------------|
255
+ | `snap init` | Initialize `.snapback/` in your workspace |
256
+ | `snap snapshot` | Create a snapshot of current state |
257
+ | `snap analyze <file>` | Risk analysis for a file |
258
+ | `snap check` | Pre-commit validation |
259
+ | `snap list` | List all snapshots |
260
+ | `snap undo` | Revert the last destructive operation |
261
+ | `snap status` | Show workspace status |
262
+ | `snap fix` | Fix common issues |
383
263
 
384
- Run the 7-layer validation pipeline before committing:
264
+ ### Authentication Commands
385
265
 
386
- ```bash
387
- # Validate a single file
388
- snap validate src/auth.ts
266
+ | Command | Description |
267
+ |---------|-------------|
268
+ | `snap login` | OAuth login flow |
269
+ | `snap logout` | Clear credentials |
270
+ | `snap whoami` | Show current user |
389
271
 
390
- # Validate all staged files
391
- snap validate --all
272
+ ### Intelligence Commands
392
273
 
393
- # Quiet mode (only output if issues)
394
- snap validate --all --quiet
274
+ | Command | Description |
275
+ |---------|-------------|
276
+ | `snap context [task]` | Get relevant patterns before starting work |
277
+ | `snap validate <file>` | Run 7-layer validation pipeline |
278
+ | `snap validate --all` | Validate all staged files |
279
+ | `snap stats` | Show learning statistics |
395
280
 
396
- # JSON output for CI
397
- snap validate --all --json
398
- ```
281
+ ### Learning Commands
399
282
 
400
- **The 7 Validation Layers:**
283
+ | Command | Description |
284
+ |---------|-------------|
285
+ | `snap learn record` | Record a new learning |
286
+ | `snap learn list` | List recorded learnings |
287
+ | `snap patterns report` | Report a violation (auto-promotes at 3×) |
288
+ | `snap patterns summary` | Show violation patterns |
289
+
290
+ ### Protection Commands
291
+
292
+ | Command | Description |
293
+ |---------|-------------|
294
+ | `snap protect add <file>` | Add file to protection list |
295
+ | `snap protect remove <file>` | Remove from protection |
296
+ | `snap protect list` | List protected files |
297
+ | `snap session start` | Start a coding session |
298
+ | `snap session end` | End current session |
299
+ | `snap watch` | Continuous file watching |
401
300
 
402
- | Layer | Checks |
403
- |-------|--------|
301
+ ### MCP & Tools Commands
302
+
303
+ | Command | Description |
304
+ |---------|-------------|
305
+ | `snap mcp --stdio` | Start MCP server for AI assistant integration |
306
+ | `snap tools configure` | Auto-setup MCP for detected AI tools |
307
+ | `snap tools configure --cursor` | Configure for Cursor only |
308
+ | `snap tools configure --claude` | Configure for Claude Desktop only |
309
+ | `snap tools configure --windsurf` | Configure for Windsurf only |
310
+ | `snap tools configure --npm` | Use npx mode (recommended for npm users) |
311
+ | `snap tools configure --dev` | Use local development mode |
312
+ | `snap tools status` | Check MCP configuration status |
313
+ | `snap tools validate` | Validate MCP configurations |
314
+ | `snap tools repair` | Repair broken MCP configurations |
315
+
316
+ ### Daemon Commands
317
+
318
+ | Command | Description |
319
+ |---------|-------------|
320
+ | `snap daemon start` | Start SnapBack daemon |
321
+ | `snap daemon stop` | Stop SnapBack daemon |
322
+ | `snap daemon status` | Check daemon status |
323
+ | `snap daemon restart` | Restart daemon |
324
+
325
+ ### Utility Commands
326
+
327
+ | Command | Description |
328
+ |---------|-------------|
329
+ | `snap wizard` | Interactive first-run setup |
330
+ | `snap doctor` | Diagnostics and health check |
331
+ | `snap doctor --fix` | Auto-fix detected issues |
332
+ | `snap upgrade` | Check for CLI updates |
333
+ | `snap config list` | List configuration values |
334
+ | `snap config get <key>` | Get a specific config value |
335
+ | `snap config set <key> <value>` | Set a configuration value |
336
+ | `snap alias list` | List command shortcuts |
337
+ | `snap alias set <name> <cmd>` | Create a command alias |
338
+ | `snap interactive` | Guided TUI workflow |
339
+
340
+ ---
341
+
342
+ ## The 7-Layer Validation Pipeline
343
+
344
+ When you run `snap validate` or `snap check`, SnapBack analyzes your code across seven layers:
345
+
346
+ | Layer | What It Checks |
347
+ |-------|----------------|
404
348
  | **Syntax** | Bracket matching, semicolons |
405
349
  | **Types** | `any` usage, `@ts-ignore`, non-null assertions |
406
350
  | **Tests** | Vague assertions, 4-path coverage |
407
351
  | **Architecture** | Layer boundaries, service bypass |
408
352
  | **Security** | Hardcoded secrets, `eval()` |
409
353
  | **Dependencies** | Deprecated packages |
410
- | **Performance** | console.log, sync I/O, await in loops |
354
+ | **Performance** | `console.log`, sync I/O, `await` in loops |
355
+
356
+ ```bash
357
+ # Validate a single file
358
+ snap validate src/auth.ts
411
359
 
412
- ### Learning Statistics
360
+ # Validate all staged files (quiet mode for CI)
361
+ snap validate --all --quiet
362
+
363
+ # JSON output for automation
364
+ snap validate --all --json
365
+ ```
413
366
 
414
- Monitor your learning system's health:
367
+ ---
368
+
369
+ ## Auto-Promotion: Learning from Mistakes
370
+
371
+ SnapBack tracks violations and automatically promotes patterns:
372
+
373
+ | Occurrence | Action |
374
+ |------------|--------|
375
+ | **1×** | Stored in `violations.jsonl` |
376
+ | **3×** | Auto-promoted to `workspace-patterns.json` |
377
+ | **5×** | Marked for automated detection |
415
378
 
416
379
  ```bash
417
- snap stats
380
+ # Report a violation manually
381
+ snap patterns report
382
+
383
+ # View promotion status
384
+ snap patterns summary
385
+ ```
386
+
387
+ ---
388
+
389
+ ## World-Class CLI UX
390
+
391
+ SnapBack implements best practices from GitHub CLI, Vercel CLI, and Stripe CLI.
392
+
393
+ ### Smart Error Messages
394
+
418
395
  ```
396
+ ╭───────────────────────────────────────────────────╮
397
+ │ [ERR_NOT_INIT] Workspace Not Initialized │
398
+ │ │
399
+ │ This workspace hasn't been set up for SnapBack │
400
+ │ │
401
+ │ 💡 Suggestion: │
402
+ │ Initialize SnapBack in this directory │
403
+ │ │
404
+ │ 📋 Try running: │
405
+ │ $ snap init │
406
+ ╰───────────────────────────────────────────────────╯
407
+ ```
408
+
409
+ ### Typo Detection
410
+
411
+ ```
412
+ $ snap statis
413
+ ╭────────────────────────────────────────╮
414
+ │ Unknown command: statis │
415
+ │ │
416
+ │ Did you mean: │
417
+ │ $ snap status │
418
+ │ $ snap stats │
419
+ ╰────────────────────────────────────────╯
420
+ ```
421
+
422
+ ### Command Aliases
423
+
424
+ ```bash
425
+ # Create shortcuts
426
+ snap alias set st status
427
+ snap alias set ss snapshot
428
+
429
+ # Use them
430
+ snap st
431
+ snap ss -m "checkpoint"
432
+ ```
433
+
434
+ ### Dry-Run Mode
435
+
436
+ ```bash
437
+ snap init --dry-run
438
+ # Shows what will be created without making changes
419
439
 
420
- **Output:**
440
+ snap tools configure --dry-run
441
+ # Shows what MCP config would be written
421
442
  ```
422
- ┌─────────────────────────────────────────┐
423
- │ 📊 Learning Statistics │
424
- │ │
425
- │ Total Interactions: 142 │
426
- │ Feedback Rate: 68% │
427
- │ Accuracy Rate: 94% │
428
- │ Golden Examples: 23 │
429
- └─────────────────────────────────────────┘
430
-
431
- Violation Patterns:
432
- ┌────────────────────────┬───────┬─────────────────────────┐
433
- Type │ Count Status │
434
- ├────────────────────────┼───────┼─────────────────────────┤
435
- │ missing-error-handling │ 5 │ 🤖 Ready for automation │
436
- │ vague-assertion │ 3 │ 📈 Ready for promotion │
437
- └────────────────────────┴───────┴─────────────────────────┘
443
+
444
+ ### Shell Completions
445
+
446
+ ```bash
447
+ # Bash
448
+ eval "$(snap completion bash)"
449
+
450
+ # Zsh
451
+ eval "$(snap completion zsh)"
452
+
453
+ # Fish
454
+ snap completion fish | source
438
455
  ```
439
456
 
440
- ### Auto-Promotion Thresholds
457
+ Completion scripts are also available at:
458
+
459
+ - `resources/completions/snap.bash`
460
+ - `resources/completions/snap.zsh`
461
+ - `resources/completions/snap.fish`
441
462
 
442
- - **1x seen**: Stored in `violations.jsonl`
443
- - **3x seen**: Auto-promoted to `workspace-patterns.json`
444
- - **5x seen**: Marked for automated detection
463
+ ---
445
464
 
446
- ## Pre-Commit Hook
465
+ ## Pre-Commit Hook Integration
447
466
 
448
- Install as a git pre-commit hook:
467
+ ### Git Hook
449
468
 
450
469
  ```bash
451
470
  #!/bin/sh
@@ -453,50 +472,46 @@ Install as a git pre-commit hook:
453
472
  npx @snapback/cli check --snapshot --quiet
454
473
  ```
455
474
 
456
- Or with lefthook (`.lefthook.yml`):
475
+ ### Lefthook
457
476
 
458
477
  ```yaml
478
+ # .lefthook.yml
459
479
  pre-commit:
460
480
  commands:
461
- snapback-check:
481
+ snapback:
462
482
  run: npx @snapback/cli check --all --quiet
463
483
  ```
464
484
 
465
- ## CI/CD Integration
466
-
467
485
  ### GitHub Actions
468
486
 
469
487
  ```yaml
470
488
  - name: Validate code
471
- run: npx @snapback/cli validate --all --json > validation-report.json
489
+ run: npx @snapback/cli validate --all --json > validation.json
472
490
 
473
491
  - name: Check for risky changes
474
492
  run: npx @snapback/cli check --quiet
475
493
  ```
476
494
 
477
- ### Exit Codes
478
-
479
- - `0`: All checks passed
480
- - `1`: Issues found (validation failed, risky changes detected)
495
+ ---
481
496
 
482
497
  ## Configuration
483
498
 
484
499
  ### Workspace Structure
485
500
 
486
- After `snap init`, your workspace will have:
501
+ After `snap init`:
487
502
 
488
503
  ```
489
504
  your-project/
490
505
  ├── .snapback/
491
- │ ├── config.json # Workspace configuration
492
- │ ├── vitals.json # Workspace vitals
493
- │ ├── constraints.md # Your project constraints (optional)
506
+ │ ├── config.json # Workspace config
507
+ │ ├── vitals.json # Health metrics
508
+ │ ├── constraints.md # Your rules (optional)
494
509
  │ ├── patterns/
495
- │ │ ├── violations.jsonl # Tracked violations
496
- │ │ └── workspace-patterns.json # Promoted patterns
510
+ │ │ ├── violations.jsonl # Tracked violations
511
+ │ │ └── workspace-patterns.json
497
512
  │ └── learnings/
498
- │ └── user-learnings.jsonl # Recorded learnings
499
- └── .snapbackrc # CLI configuration
513
+ │ └── user-learnings.jsonl
514
+ └── .snapbackrc # CLI config
500
515
  ```
501
516
 
502
517
  ### `.snapbackrc` Options
@@ -510,56 +525,75 @@ your-project/
510
525
  }
511
526
  ```
512
527
 
513
- ## Dependencies
528
+ ---
514
529
 
515
- ### Core Packages
516
- - **@snapback/intelligence**: Learning loop, validation pipeline
517
- - **@snapback/core**: Guardian risk analysis
518
- - **@snapback/engine**: V2 analysis engine
519
- - **@snapback/contracts**: Type definitions
530
+ ## Diagnostics
520
531
 
521
- ### CLI Framework
522
- - **commander**: CLI framework
523
- - **chalk**: Terminal styling
524
- - **boxen**: Box rendering
525
- - **cli-table3**: Table formatting
526
- - **ora**: Spinners
527
- - **inquirer**: Interactive prompts
532
+ ```bash
533
+ $ snap doctor
528
534
 
529
- ### UX Enhancements
530
- - Smart error messages with actionable suggestions
531
- - Levenshtein distance for typo detection
532
- - OSC 8 terminal hyperlinks
533
- - Dry-run mode with diff preview
534
- - Operation history for undo support
535
- - Command aliases
535
+ 🏥 SnapBack Diagnostics
536
536
 
537
- ## Development
537
+ Node.js version v20.10.0
538
+ ✓ CLI installation v1.0.11 (latest)
539
+ ✓ Global directory ~/.snapback/ exists
540
+ ✓ Authentication Logged in as @user
541
+ ✓ Workspace .snapback/ initialized
542
+ ✓ MCP tools 3 tools configured
543
+ ✓ Git repository Clean
544
+ ✓ Network API reachable
538
545
 
539
- ```bash
540
- # Clone the repo
541
- git clone https://github.com/snapback-dev/snapback.git
542
- cd snapback
546
+ All checks passed!
547
+ ```
543
548
 
544
- # Install dependencies
545
- pnpm install
549
+ ---
546
550
 
547
- # Build the CLI
548
- pnpm --filter @snapback/cli build
551
+ ## Exit Codes
549
552
 
550
- # Run locally
551
- node apps/cli/dist/index.js <command>
553
+ | Code | Meaning |
554
+ |------|---------|
555
+ | `0` | Success |
556
+ | `1` | Issues found (validation failed, risky changes) |
552
557
 
553
- # Run tests
554
- pnpm --filter @snapback/cli test
555
- ```
558
+ ---
556
559
 
557
560
  ## Related Packages
558
561
 
559
- - [`@snapback/intelligence`](../../packages/intelligence/README.md) - Learning and validation engine
560
- - [`@snapback/core`](../../packages/core/README.md) - Core snapshot logic
561
- - [`@snapback/sdk`](../../packages/sdk/README.md) - SDK for integrations
562
+ ### Open Source (npm)
563
+
564
+ | Package | Description |
565
+ |---------|-------------|
566
+ | [@snapback-oss/sdk](https://www.npmjs.com/package/@snapback-oss/sdk) | Production-ready SDK for code safety systems |
567
+ | [@snapback-oss/contracts](https://www.npmjs.com/package/@snapback-oss/contracts) | Type definitions and schemas |
568
+ | [@snapback-oss/infrastructure](https://www.npmjs.com/package/@snapback-oss/infrastructure) | Storage and logging utilities |
569
+ | [@snapback-oss/events](https://www.npmjs.com/package/@snapback-oss/events) | Event definitions and handlers |
570
+
571
+ ### VS Code Extension
572
+
573
+ | Package | Description |
574
+ |---------|-------------|
575
+ | [snapback-vscode](https://marketplace.visualstudio.com/items?itemName=snapback.snapback-vscode) | VS Code extension with visual UI |
576
+
577
+ ---
578
+
579
+ ## Get an API Key
580
+
581
+ Unlock Pro features like checkpoint creation and restoration:
582
+
583
+ 👉 **[console.snapback.dev/settings/api-keys](https://console.snapback.dev/settings/api-keys)**
584
+
585
+ ---
562
586
 
563
587
  ## License
564
588
 
565
- Apache-2.0
589
+ [Apache-2.0](https://github.com/snapback-dev/snapback/blob/main/LICENSE)
590
+
591
+ ---
592
+
593
+ <p align="center">
594
+ <strong>Stop losing work to AI mistakes.</strong><br>
595
+ <a href="https://snapback.dev">Website</a> ·
596
+ <a href="https://docs.snapback.dev">Docs</a> ·
597
+ <a href="https://console.snapback.dev">Dashboard</a> ·
598
+ <a href="https://discord.gg/snapback">Discord</a>
599
+ </p>