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