forge-workflow 0.0.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 (105) hide show
  1. package/.claude/commands/dev.md +314 -0
  2. package/.claude/commands/plan.md +389 -0
  3. package/.claude/commands/premerge.md +179 -0
  4. package/.claude/commands/research.md +42 -0
  5. package/.claude/commands/review.md +442 -0
  6. package/.claude/commands/rollback.md +721 -0
  7. package/.claude/commands/ship.md +134 -0
  8. package/.claude/commands/sonarcloud.md +152 -0
  9. package/.claude/commands/status.md +77 -0
  10. package/.claude/commands/validate.md +237 -0
  11. package/.claude/commands/verify.md +221 -0
  12. package/.claude/rules/greptile-review-process.md +285 -0
  13. package/.claude/rules/workflow.md +105 -0
  14. package/.claude/scripts/greptile-resolve.sh +526 -0
  15. package/.claude/scripts/load-env.sh +32 -0
  16. package/.forge/hooks/check-tdd.js +240 -0
  17. package/.github/PLUGIN_TEMPLATE.json +32 -0
  18. package/.mcp.json.example +12 -0
  19. package/AGENTS.md +169 -0
  20. package/CLAUDE.md +99 -0
  21. package/LICENSE +21 -0
  22. package/README.md +414 -0
  23. package/bin/forge-cmd.js +313 -0
  24. package/bin/forge-validate.js +303 -0
  25. package/bin/forge.js +4228 -0
  26. package/docs/AGENT_INSTALL_PROMPT.md +342 -0
  27. package/docs/ENHANCED_ONBOARDING.md +602 -0
  28. package/docs/EXAMPLES.md +482 -0
  29. package/docs/GREPTILE_SETUP.md +400 -0
  30. package/docs/MANUAL_REVIEW_GUIDE.md +106 -0
  31. package/docs/ROADMAP.md +359 -0
  32. package/docs/SETUP.md +632 -0
  33. package/docs/TOOLCHAIN.md +849 -0
  34. package/docs/VALIDATION.md +363 -0
  35. package/docs/WORKFLOW.md +400 -0
  36. package/docs/planning/PROGRESS.md +396 -0
  37. package/docs/plans/.gitkeep +0 -0
  38. package/docs/plans/2026-02-27-forge-test-suite-v2-decisions.md +21 -0
  39. package/docs/plans/2026-02-27-forge-test-suite-v2-design.md +362 -0
  40. package/docs/plans/2026-02-27-forge-test-suite-v2-tasks.md +343 -0
  41. package/docs/plans/2026-03-02-superpowers-gaps-decisions.md +26 -0
  42. package/docs/plans/2026-03-02-superpowers-gaps-design.md +239 -0
  43. package/docs/plans/2026-03-02-superpowers-gaps-tasks.md +260 -0
  44. package/docs/plans/2026-03-04-agent-command-parity-design.md +163 -0
  45. package/docs/plans/2026-03-04-verify-worktree-cleanup-decisions.md +7 -0
  46. package/docs/plans/2026-03-04-verify-worktree-cleanup-design.md +165 -0
  47. package/docs/plans/2026-03-05-forge-uto-decisions.md +6 -0
  48. package/docs/plans/2026-03-05-forge-uto-design.md +116 -0
  49. package/docs/plans/2026-03-05-forge-uto-tasks.md +244 -0
  50. package/docs/plans/2026-03-10-command-creator-and-eval-decisions.md +52 -0
  51. package/docs/plans/2026-03-10-command-creator-and-eval-design.md +350 -0
  52. package/docs/plans/2026-03-10-command-creator-and-eval-tasks.md +426 -0
  53. package/docs/plans/2026-03-10-stale-workflow-refs-decisions.md +8 -0
  54. package/docs/plans/2026-03-10-stale-workflow-refs-design.md +80 -0
  55. package/docs/plans/2026-03-10-stale-workflow-refs-tasks.md +90 -0
  56. package/docs/plans/2026-03-14-beads-plan-context-decisions.md +9 -0
  57. package/docs/plans/2026-03-14-beads-plan-context-design.md +171 -0
  58. package/docs/plans/2026-03-14-beads-plan-context-tasks.md +160 -0
  59. package/docs/plans/2026-03-14-skill-eval-loop-decisions.md +33 -0
  60. package/docs/plans/2026-03-14-skill-eval-loop-design.md +118 -0
  61. package/docs/plans/2026-03-14-skill-eval-loop-results.md +78 -0
  62. package/docs/plans/2026-03-14-skill-eval-loop-tasks.md +160 -0
  63. package/docs/plans/2026-03-15-agent-command-parity-v2-decisions.md +11 -0
  64. package/docs/plans/2026-03-15-agent-command-parity-v2-design.md +145 -0
  65. package/docs/plans/2026-03-15-agent-command-parity-v2-tasks.md +211 -0
  66. package/docs/research/TEMPLATE.md +292 -0
  67. package/docs/research/advanced-testing.md +297 -0
  68. package/docs/research/agent-permissions.md +167 -0
  69. package/docs/research/dependency-chain.md +328 -0
  70. package/docs/research/forge-workflow-v2.md +550 -0
  71. package/docs/research/plugin-architecture.md +772 -0
  72. package/docs/research/pr4-cli-automation.md +326 -0
  73. package/docs/research/premerge-verify-restructure.md +205 -0
  74. package/docs/research/skills-restructure.md +508 -0
  75. package/docs/research/sonarcloud-perfection-plan.md +166 -0
  76. package/docs/research/sonarcloud-quality-gate.md +184 -0
  77. package/docs/research/superpowers-integration.md +403 -0
  78. package/docs/research/superpowers.md +319 -0
  79. package/docs/research/test-environment.md +519 -0
  80. package/install.sh +1062 -0
  81. package/lefthook.yml +39 -0
  82. package/lib/agents/README.md +198 -0
  83. package/lib/agents/claude.plugin.json +28 -0
  84. package/lib/agents/cline.plugin.json +22 -0
  85. package/lib/agents/codex.plugin.json +19 -0
  86. package/lib/agents/copilot.plugin.json +24 -0
  87. package/lib/agents/cursor.plugin.json +25 -0
  88. package/lib/agents/kilocode.plugin.json +22 -0
  89. package/lib/agents/opencode.plugin.json +20 -0
  90. package/lib/agents/roo.plugin.json +23 -0
  91. package/lib/agents-config.js +2112 -0
  92. package/lib/commands/dev.js +513 -0
  93. package/lib/commands/plan.js +696 -0
  94. package/lib/commands/recommend.js +119 -0
  95. package/lib/commands/ship.js +377 -0
  96. package/lib/commands/status.js +378 -0
  97. package/lib/commands/validate.js +602 -0
  98. package/lib/context-merge.js +359 -0
  99. package/lib/plugin-catalog.js +360 -0
  100. package/lib/plugin-manager.js +166 -0
  101. package/lib/plugin-recommender.js +141 -0
  102. package/lib/project-discovery.js +491 -0
  103. package/lib/setup.js +118 -0
  104. package/lib/workflow-profiles.js +203 -0
  105. package/package.json +115 -0
@@ -0,0 +1,721 @@
1
+ ---
2
+ description: Safely rollback changes with USER section preservation
3
+ ---
4
+
5
+ Comprehensive rollback system with multiple methods and automatic USER content preservation.
6
+
7
+ # Rollback
8
+
9
+ This command provides safe rollback operations with comprehensive validation and USER section preservation.
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ bunx forge rollback
15
+ ```
16
+
17
+ Interactive menu with 6 options:
18
+ 1. **Rollback last commit** - Quick undo of most recent change
19
+ 2. **Rollback specific commit** - Target any commit by hash
20
+ 3. **Rollback merged PR** - Revert an entire PR merge
21
+ 4. **Rollback specific files** - Restore only certain files
22
+ 5. **Rollback entire branch** - Revert multiple commits
23
+ 6. **Preview rollback** - Dry run mode (shows changes without executing)
24
+
25
+ ## How It Works
26
+
27
+ ### Safety Features
28
+
29
+ **1. Working Directory Check**
30
+ - Requires clean working directory (no uncommitted changes)
31
+ - Prevents accidental data loss
32
+ - Prompts to commit or stash changes first
33
+
34
+ **2. Input Validation**
35
+ - Commit hashes: Must match `/^[0-9a-f]{4,40}$/i` or be 'HEAD'
36
+ - File paths: Validated to be within project (prevents path traversal)
37
+ - Methods: Whitelisted to 'commit', 'pr', 'partial', 'branch'
38
+ - Shell metacharacters: Rejected (`;`, `|`, `&`, `$`, `` ` ``, `(`, `)`, `<`, `>`, `\n`, `\r`)
39
+
40
+ **3. USER Section Preservation**
41
+ - Automatically extracts USER sections before rollback
42
+ - Restores USER sections after rollback
43
+ - Preserves custom commands in `.claude/commands/custom/`
44
+ - Amends rollback commit to include restored content
45
+
46
+ **4. Dry Run Mode**
47
+ - Preview affected files without executing
48
+ - Shows what would change
49
+ - No git operations performed
50
+
51
+ **5. Non-Destructive**
52
+ - Uses `git revert` (creates new commit)
53
+ - Never uses `git reset --hard` (destructive)
54
+ - Preserves full git history
55
+ - Can be undone with another rollback
56
+
57
+ ### USER Section Preservation
58
+
59
+ **What Gets Preserved**:
60
+ ```markdown
61
+ <!-- USER:START -->
62
+ Your custom content here
63
+ <!-- USER:END -->
64
+
65
+ <!-- USER:START:custom-name -->
66
+ Named USER section
67
+ <!-- USER:END:custom-name -->
68
+ ```
69
+
70
+ **Process**:
71
+ 1. Extract all USER sections from AGENTS.md, CLAUDE.md, etc.
72
+ 2. Backup custom commands from `.claude/commands/custom/`
73
+ 3. Execute rollback operation
74
+ 4. Restore USER sections to current file content
75
+ 5. Restore custom command files
76
+ 6. Amend rollback commit to include restored content
77
+
78
+ **Result**: Your customizations survive rollback operations.
79
+
80
+ ## Rollback Methods
81
+
82
+ ### 1. Rollback Last Commit
83
+
84
+ **Use when**: Quick undo of most recent change
85
+
86
+ **How it works**:
87
+ ```bash
88
+ git revert HEAD --no-edit
89
+ ```
90
+
91
+ **Example**:
92
+ ```bash
93
+ bunx forge rollback
94
+ # Select: 1. Rollback last commit
95
+
96
+ ✓ Working directory is clean
97
+ ✓ Extracting USER sections...
98
+ ✓ Executing: git revert HEAD --no-edit
99
+ ✓ Restoring USER sections...
100
+ ✓ Amended commit to preserve USER content
101
+
102
+ Rollback complete!
103
+ Commit: a1b2c3d "Revert: add authentication feature"
104
+ Files affected: 5
105
+ ```
106
+
107
+ ### 2. Rollback Specific Commit
108
+
109
+ **Use when**: Need to revert a commit from earlier in history
110
+
111
+ **How it works**:
112
+ ```bash
113
+ git revert <commit-hash> --no-edit
114
+ ```
115
+
116
+ **Example**:
117
+ ```bash
118
+ bunx forge rollback
119
+ # Select: 2. Rollback specific commit
120
+ # Enter: a1b2c3d
121
+
122
+ ✓ Validating commit hash...
123
+ ✓ Working directory is clean
124
+ ✓ Extracting USER sections...
125
+ ✓ Executing: git revert a1b2c3d --no-edit
126
+ ✓ Restoring USER sections...
127
+ ✓ Amended commit to preserve USER content
128
+
129
+ Rollback complete!
130
+ Commit: x9y8z7w "Revert: a1b2c3d"
131
+ Files affected: 8
132
+ ```
133
+
134
+ **Input validation**:
135
+ - Accepts 4-40 character hex strings
136
+ - Accepts 'HEAD'
137
+ - Rejects shell metacharacters
138
+ - Rejects invalid formats
139
+
140
+ ### 3. Rollback Merged PR
141
+
142
+ **Use when**: Need to revert an entire merged pull request
143
+
144
+ **How it works**:
145
+ ```bash
146
+ git revert -m 1 <merge-commit-hash> --no-edit
147
+ ```
148
+
149
+ **Example**:
150
+ ```bash
151
+ bunx forge rollback
152
+ # Select: 3. Rollback merged PR
153
+ # Enter: def456 (merge commit hash)
154
+
155
+ ✓ Validating commit hash...
156
+ ✓ Working directory is clean
157
+ ✓ Extracting USER sections...
158
+ ✓ Executing: git revert -m 1 def456 --no-edit
159
+ ✓ Restoring USER sections...
160
+ ✓ Amended commit to preserve USER content
161
+ ✓ Beads integration: Issue #123 marked as 'reverted'
162
+
163
+ Rollback complete!
164
+ Commit: m1n2o3p "Revert: Merge pull request #123"
165
+ Files affected: 15
166
+ Beads issue: #123 status → reverted
167
+ ```
168
+
169
+ **Beads Integration**:
170
+ - Parses commit message for issue number (`#123`)
171
+ - If found, runs: `bd update <id> --status reverted --comment "PR reverted"`
172
+ - Silently skips if Beads not installed
173
+ - Updates issue tracking automatically
174
+
175
+ ### 4. Rollback Specific Files
176
+
177
+ **Use when**: Only certain files need to be restored
178
+
179
+ **How it works**:
180
+ ```bash
181
+ git checkout HEAD~1 -- <file1> <file2> ...
182
+ git commit -m "Rollback: <files>"
183
+ ```
184
+
185
+ **Example**:
186
+ ```bash
187
+ bunx forge rollback
188
+ # Select: 4. Rollback specific files
189
+ # Enter: AGENTS.md,docs/WORKFLOW.md
190
+
191
+ ✓ Validating file paths...
192
+ ✓ Working directory is clean
193
+ ✓ Extracting USER sections...
194
+ ✓ Executing: git checkout HEAD~1 -- AGENTS.md docs/WORKFLOW.md
195
+ ✓ Committing changes...
196
+ ✓ Restoring USER sections...
197
+ ✓ Amended commit to preserve USER content
198
+
199
+ Rollback complete!
200
+ Commit: q4r5s6t "Rollback: AGENTS.md, docs/WORKFLOW.md"
201
+ Files affected: 2
202
+ ```
203
+
204
+ **Path validation**:
205
+ - Comma-separated file paths
206
+ - Validates paths are within project root
207
+ - Prevents path traversal (`../../../etc/passwd`)
208
+ - Rejects shell metacharacters
209
+ - Uses `path.resolve()` + `startsWith()` check
210
+
211
+ ### 5. Rollback Entire Branch
212
+
213
+ **Use when**: Need to revert a range of commits
214
+
215
+ **How it works**:
216
+ ```bash
217
+ git revert <start-commit>..<end-commit> --no-edit
218
+ ```
219
+
220
+ **Example**:
221
+ ```bash
222
+ bunx forge rollback
223
+ # Select: 5. Rollback entire branch
224
+ # Enter: abc123..def456
225
+
226
+ ✓ Validating commit range...
227
+ ✓ Working directory is clean
228
+ ✓ Extracting USER sections...
229
+ ✓ Executing: git revert abc123..def456 --no-edit
230
+ ✓ Restoring USER sections...
231
+ ✓ Amended commit to preserve USER content
232
+
233
+ Rollback complete!
234
+ Commits reverted: 7
235
+ Files affected: 24
236
+ ```
237
+
238
+ **Range validation**:
239
+ - Format: `start..end`
240
+ - Both commits must be valid hashes (4-40 chars)
241
+ - Rejects invalid formats
242
+ - Checks for `..` separator
243
+
244
+ ### 6. Preview Rollback (Dry Run)
245
+
246
+ **Use when**: Want to see what would change without executing
247
+
248
+ **How it works**:
249
+ - Prompts for method and target
250
+ - Validates inputs
251
+ - Shows affected files
252
+ - No git operations performed
253
+
254
+ **Example**:
255
+ ```bash
256
+ bunx forge rollback
257
+ # Select: 6. Preview rollback (dry run)
258
+ # Enter method: partial
259
+ # Enter target: AGENTS.md,package.json
260
+
261
+ ✓ Validating inputs...
262
+ ✓ DRY RUN MODE - No changes will be made
263
+
264
+ Preview of rollback:
265
+ Method: partial
266
+ Target: AGENTS.md, package.json
267
+
268
+ Files that would be affected:
269
+ - AGENTS.md
270
+ - package.json
271
+
272
+ USER sections that would be preserved:
273
+ - AGENTS.md: 2 sections
274
+
275
+ Custom commands that would be preserved:
276
+ - .claude/commands/custom/my-workflow.md
277
+
278
+ No changes made (dry run).
279
+ ```
280
+
281
+ ## Integration with Workflow
282
+
283
+ ### When to Use Rollback
284
+
285
+ **During Development** (`/dev`):
286
+ - Implemented wrong approach
287
+ - Tests reveal fundamental issues
288
+ - Need to start over with different strategy
289
+
290
+ **After Shipping** (`/ship`):
291
+ - PR feedback requires complete redesign
292
+ - CI/CD failures indicate architecture problems
293
+ - Breaking changes need to be reverted
294
+
295
+ **After Merging** (`/premerge` + user merge):
296
+ - Production issues discovered
297
+ - Need to revert feature entirely
298
+ - Rollback PR merge commit
299
+
300
+ **Recovery Scenarios**:
301
+ - Accidentally committed sensitive data (rollback + force push)
302
+ - Merge conflict resolution went wrong
303
+ - Refactor broke existing functionality
304
+
305
+ ### Workflow Integration
306
+
307
+ ```bash
308
+ # Standard workflow
309
+ /status → /plan → /dev → /validate → /ship → /review → /premerge → /verify
310
+
311
+ # Recovery workflow
312
+ /dev → (issues discovered) → bunx forge rollback → /dev (retry)
313
+ /ship → (CI fails) → bunx forge rollback → /dev (fix) → /ship
314
+ /verify → (production issues) → bunx forge rollback → /plan (redesign)
315
+ ```
316
+
317
+ ### Example: Failed Feature Implementation
318
+
319
+ ```bash
320
+ # 1. Development phase - implement feature
321
+ /dev
322
+ # ... implementation ...
323
+ git commit -m "feat: add payment integration"
324
+
325
+ # 2. Check phase - tests fail
326
+ /validate
327
+ # ERROR: Security vulnerability in payment handling
328
+
329
+ # 3. Rollback the implementation
330
+ bunx forge rollback
331
+ # Select: 1. Rollback last commit
332
+
333
+ # 4. Plan with security in mind
334
+ /plan payment-integration
335
+
336
+ # 5. Implement correctly
337
+ /dev
338
+ # ... proper implementation with security ...
339
+
340
+ # 6. Verify and ship
341
+ /validate → /ship
342
+ ```
343
+
344
+ ## Beads Integration
345
+
346
+ If Beads is installed (`bun install -g @beads/bd`), rollback automatically updates issue tracking.
347
+
348
+ ### PR Rollback → Issue Status
349
+
350
+ When rolling back a merged PR:
351
+ 1. Parse commit message for issue number (`#123`, `fixes #456`, etc.)
352
+ 2. If issue number found:
353
+ ```bash
354
+ bd update <id> --status reverted --comment "PR reverted by rollback"
355
+ ```
356
+ 3. Silently skip if:
357
+ - Beads not installed
358
+ - No issue number in commit message
359
+ - Issue doesn't exist
360
+
361
+ ### Manual Beads Update
362
+
363
+ If automatic detection doesn't work:
364
+ ```bash
365
+ # After rollback
366
+ bd update 123 --status reverted --comment "Rolled back due to production issues"
367
+ ```
368
+
369
+ ## Troubleshooting
370
+
371
+ ### Error: "Working directory not clean"
372
+
373
+ **Cause**: Uncommitted changes in working directory
374
+
375
+ **Solution**:
376
+ ```bash
377
+ # Option 1: Commit changes
378
+ git add .
379
+ git commit -m "wip: current work"
380
+
381
+ # Option 2: Stash changes
382
+ git stash
383
+
384
+ # Then retry rollback
385
+ bunx forge rollback
386
+ ```
387
+
388
+ ### Error: "Invalid commit hash format"
389
+
390
+ **Cause**: Commit hash doesn't match required pattern
391
+
392
+ **Valid formats**:
393
+ - `HEAD` (special keyword)
394
+ - `a1b2c3d` (4-40 character hex string)
395
+ - `abc123def456` (longer hash)
396
+
397
+ **Invalid formats**:
398
+ - `abc;rm -rf /` (contains shell metacharacter)
399
+ - `12` (too short, < 4 chars)
400
+ - `not-a-hash` (not hexadecimal)
401
+
402
+ **Solution**:
403
+ ```bash
404
+ # Get valid commit hash
405
+ git log --oneline
406
+ # Copy full or abbreviated hash (4+ chars)
407
+ ```
408
+
409
+ ### Error: "Path outside project"
410
+
411
+ **Cause**: File path resolves to outside project root
412
+
413
+ **Examples**:
414
+ - `../../../etc/passwd` (path traversal)
415
+ - `/absolute/path/outside/project`
416
+
417
+ **Solution**:
418
+ ```bash
419
+ # Use relative paths within project
420
+ bunx forge rollback
421
+ # Select: 4. Rollback specific files
422
+ # Enter: src/auth.js,docs/API.md (relative paths)
423
+ ```
424
+
425
+ ### Error: "Invalid characters in path"
426
+
427
+ **Cause**: File path contains shell metacharacters
428
+
429
+ **Rejected characters**: `;`, `|`, `&`, `$`, `` ` ``, `(`, `)`, `<`, `>`, `\n`, `\r`
430
+
431
+ **Solution**:
432
+ ```bash
433
+ # Remove special characters from filename
434
+ mv "file;name.js" "filename.js"
435
+
436
+ # Or escape properly (not recommended)
437
+ ```
438
+
439
+ ### Error: "Branch range must use format: start..end"
440
+
441
+ **Cause**: Branch range doesn't include `..` separator
442
+
443
+ **Valid formats**:
444
+ - `abc123..def456`
445
+ - `a1b2c3d..x9y8z7w`
446
+
447
+ **Invalid formats**:
448
+ - `abc123-def456` (wrong separator)
449
+ - `abc123` (no range)
450
+
451
+ **Solution**:
452
+ ```bash
453
+ # Use correct format
454
+ bunx forge rollback
455
+ # Select: 5. Rollback entire branch
456
+ # Enter: <start-commit>..<end-commit>
457
+ ```
458
+
459
+ ### Merge Conflicts During Rollback
460
+
461
+ **Cause**: Revert conflicts with subsequent changes
462
+
463
+ **Solution**:
464
+ ```bash
465
+ # 1. Rollback creates conflict markers
466
+ git status
467
+ # On branch: main
468
+ # Unmerged paths:
469
+ # both modified: src/auth.js
470
+
471
+ # 2. Resolve conflicts manually
472
+ # Edit src/auth.js, remove markers
473
+
474
+ # 3. Complete the revert
475
+ git add src/auth.js
476
+ git revert --continue
477
+
478
+ # 4. USER sections restored automatically
479
+ ```
480
+
481
+ ### USER Sections Not Restored
482
+
483
+ **Cause**: Markers missing or malformed
484
+
485
+ **Check markers**:
486
+ ```bash
487
+ grep -n "USER:START" AGENTS.md
488
+ grep -n "USER:END" AGENTS.md
489
+ ```
490
+
491
+ **Valid markers**:
492
+ ```markdown
493
+ <!-- USER:START -->
494
+ Content
495
+ <!-- USER:END -->
496
+
497
+ <!-- USER:START:name -->
498
+ Named section
499
+ <!-- USER:END:name -->
500
+ ```
501
+
502
+ **Invalid markers**:
503
+ ```markdown
504
+ <!-- USER START --> (missing colon)
505
+ <!-- USER:START (missing closing -->)
506
+ <!-- USER:END --> (no matching START)
507
+ ```
508
+
509
+ **Solution**:
510
+ ```bash
511
+ # Fix markers before rollback
512
+ # Ensure all USER:START have matching USER:END
513
+ ```
514
+
515
+ ## Safety Notes
516
+
517
+ ### Input Validation
518
+
519
+ All inputs are validated **before** use in git commands:
520
+
521
+ **Commit hashes**:
522
+ ```javascript
523
+ if (target !== 'HEAD' && !/^[0-9a-f]{4,40}$/i.test(target)) {
524
+ return { valid: false, error: 'Invalid commit hash format' };
525
+ }
526
+ ```
527
+
528
+ **File paths**:
529
+ ```javascript
530
+ const resolved = path.resolve(projectRoot, file);
531
+ if (!resolved.startsWith(projectRoot)) {
532
+ return { valid: false, error: 'Path outside project' };
533
+ }
534
+ ```
535
+
536
+ **Shell metacharacters**:
537
+ ```javascript
538
+ if (/[;|&$`()<>\r\n]/.test(file)) {
539
+ return { valid: false, error: 'Invalid characters in path' };
540
+ }
541
+ ```
542
+
543
+ ### Non-Destructive Operations
544
+
545
+ **Uses**:
546
+ - `git revert` (creates new commit, preserves history)
547
+ - `git checkout HEAD~1 -- <files>` (restores specific files)
548
+
549
+ **Never uses**:
550
+ - `git reset --hard` (destroys commits)
551
+ - `git push --force` (overwrites remote)
552
+ - `git clean -f` (deletes untracked files)
553
+
554
+ ### Data Preservation
555
+
556
+ **Always preserved**:
557
+ - USER sections in all files
558
+ - Custom commands in `.claude/commands/custom/`
559
+ - Git history (revert creates new commits)
560
+ - Untracked files (not affected)
561
+
562
+ **Never lost**:
563
+ - Your customizations
564
+ - Work in progress (if committed/stashed)
565
+ - Remote branches (local operation only)
566
+
567
+ ### Recommended Workflow
568
+
569
+ ```bash
570
+ # 1. Always commit work before rollback
571
+ git add .
572
+ git commit -m "wip: current state"
573
+
574
+ # 2. Use dry run to preview
575
+ bunx forge rollback
576
+ # Select: 6. Preview rollback (dry run)
577
+
578
+ # 3. Execute rollback
579
+ bunx forge rollback
580
+ # Select appropriate method
581
+
582
+ # 4. Verify USER sections preserved
583
+ grep -A5 "USER:START" AGENTS.md
584
+
585
+ # 5. Push if needed (after verification)
586
+ git push
587
+ ```
588
+
589
+ ## Examples
590
+
591
+ ### Example 1: Quick Undo Last Commit
592
+
593
+ ```bash
594
+ # Scenario: Just committed but realized approach is wrong
595
+
596
+ git log --oneline
597
+ # abc123d (HEAD) feat: add caching layer
598
+ # def456e fix: validation bug
599
+
600
+ bunx forge rollback
601
+ # 1. Rollback last commit
602
+
603
+ # Output:
604
+ # ✓ Working directory is clean
605
+ # ✓ Extracting USER sections...
606
+ # ✓ Executing: git revert HEAD --no-edit
607
+ # ✓ Restoring USER sections...
608
+ # ✓ Rollback complete!
609
+
610
+ git log --oneline
611
+ # xyz789f (HEAD) Revert: feat: add caching layer
612
+ # abc123d feat: add caching layer
613
+ # def456e fix: validation bug
614
+ ```
615
+
616
+ ### Example 2: Revert Merged PR
617
+
618
+ ```bash
619
+ # Scenario: PR #123 caused production issues
620
+
621
+ git log --oneline
622
+ # merge789 (HEAD) Merge pull request #123
623
+ # feat456a feat: add real-time updates
624
+ # bugfix123 fix: websocket connection
625
+
626
+ bunx forge rollback
627
+ # 3. Rollback merged PR
628
+ # Enter: merge789
629
+
630
+ # Output:
631
+ # ✓ Validating commit hash...
632
+ # ✓ Working directory is clean
633
+ # ✓ Extracting USER sections...
634
+ # ✓ Executing: git revert -m 1 merge789 --no-edit
635
+ # ✓ Restoring USER sections...
636
+ # ✓ Beads: Issue #123 → status: reverted
637
+ # ✓ Rollback complete!
638
+
639
+ bd show 123
640
+ # ID: 123
641
+ # Title: Add real-time updates
642
+ # Status: reverted
643
+ # Comments:
644
+ # - PR reverted by rollback
645
+ ```
646
+
647
+ ### Example 3: Restore Specific Files
648
+
649
+ ```bash
650
+ # Scenario: Accidentally updated wrong files in last commit
651
+
652
+ git show HEAD --name-only
653
+ # commit abc123
654
+ # feat: update documentation
655
+ # AGENTS.md (should not have changed)
656
+ # docs/API.md
657
+ # README.md
658
+
659
+ bunx forge rollback
660
+ # 4. Rollback specific files
661
+ # Enter: AGENTS.md
662
+
663
+ # Output:
664
+ # ✓ Validating file paths...
665
+ # ✓ Working directory is clean
666
+ # ✓ Extracting USER sections...
667
+ # ✓ Executing: git checkout HEAD~1 -- AGENTS.md
668
+ # ✓ Committing changes...
669
+ # ✓ Restoring USER sections...
670
+ # ✓ Rollback complete!
671
+ # Files affected: 1
672
+
673
+ git status
674
+ # On branch: main
675
+ # nothing to commit, working tree clean
676
+ # (AGENTS.md restored to previous version)
677
+ ```
678
+
679
+ ### Example 4: Dry Run Preview
680
+
681
+ ```bash
682
+ # Scenario: Want to see what rollback would do
683
+
684
+ bunx forge rollback
685
+ # 6. Preview rollback (dry run)
686
+ # Method: commit
687
+ # Target: HEAD
688
+
689
+ # Output:
690
+ # ✓ Validating inputs...
691
+ # ✓ DRY RUN MODE - No changes will be made
692
+ #
693
+ # Preview of rollback:
694
+ # Method: commit
695
+ # Target: HEAD
696
+ #
697
+ # Files that would be affected:
698
+ # - src/auth/middleware.js
699
+ # - src/auth/validators.js
700
+ # - tests/auth.test.js
701
+ #
702
+ # USER sections that would be preserved:
703
+ # - AGENTS.md: 2 sections
704
+ # - CLAUDE.md: 1 section
705
+ #
706
+ # Custom commands that would be preserved:
707
+ # - .claude/commands/custom/deploy.md
708
+ #
709
+ # No changes made (dry run).
710
+
711
+ # Decision: Proceed with rollback
712
+ bunx forge rollback
713
+ # 1. Rollback last commit
714
+ ```
715
+
716
+ ## See Also
717
+
718
+ - [/dev](.claude/commands/dev.md) - TDD development workflow
719
+ - [/validate](.claude/commands/validate.md) - Validation before shipping
720
+ - [docs/WORKFLOW.md](../../docs/WORKFLOW.md) - Complete workflow guide
721
+ - [Beads](https://github.com/beadshq/beads) - Issue tracking integration