forge-workflow 0.0.2 → 0.0.4

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