forge-workflow 0.0.2 → 0.0.3

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