@torka/claude-workflows 0.3.1 → 0.5.0
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.
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
"description": "Analyze epic files to identify which epics can run in parallel using Git worktrees"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"name": "git-cleanup-
|
|
16
|
-
"description": "Analyze
|
|
15
|
+
"name": "git-local-cleanup-push-pr",
|
|
16
|
+
"description": "Analyze local branches, cleanup merged branches, push changes, and create PRs"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "github-pr-resolve",
|
|
20
|
+
"description": "Assess open PRs, handle review comments, run CI, and merge"
|
|
17
21
|
}
|
|
18
22
|
],
|
|
19
23
|
"agents": [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: 'Analyze
|
|
2
|
+
description: 'Analyze local branches, cleanup merged branches, push changes, and create PRs'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
IT IS CRITICAL THAT YOU FOLLOW THIS WORKFLOW EXACTLY.
|
|
@@ -33,7 +33,7 @@ Before any operations, verify the environment is safe:
|
|
|
33
33
|
- Run `git branch --show-current` to get current branch name
|
|
34
34
|
- **If empty (detached HEAD)**: Run `git rev-parse HEAD` to save the commit SHA instead
|
|
35
35
|
- Run `git rev-parse --show-toplevel` to record the current worktree path
|
|
36
|
-
- Track whether we started in detached HEAD state for Phase
|
|
36
|
+
- Track whether we started in detached HEAD state for Phase 6 restoration
|
|
37
37
|
|
|
38
38
|
8. **Build worktree inventory**: Run `git worktree list --porcelain` to detect all worktrees.
|
|
39
39
|
- Parse the output to build a map: `{ branch_name -> worktree_path }`
|
|
@@ -58,7 +58,7 @@ Before any operations, verify the environment is safe:
|
|
|
58
58
|
11. **Initialize operation log**: Create an in-memory log to track all operations performed.
|
|
59
59
|
- This log will be used for error recovery if something fails mid-workflow
|
|
60
60
|
- Track: operation type, target (branch/worktree), status (success/failed)
|
|
61
|
-
- Log each destructive operation as it completes (worktree removal, branch deletion, push, PR creation
|
|
61
|
+
- Log each destructive operation as it completes (worktree removal, branch deletion, push, PR creation)
|
|
62
62
|
|
|
63
63
|
If any pre-flight check fails, STOP and clearly explain what the user needs to do.
|
|
64
64
|
|
|
@@ -213,11 +213,6 @@ For each branch now eligible for deletion:
|
|
|
213
213
|
|
|
214
214
|
- Run `git branch -vv | grep ': gone]'` and delete them
|
|
215
215
|
|
|
216
|
-
### Step 7: Final cleanup
|
|
217
|
-
|
|
218
|
-
- Run `git fetch --prune` to clean up stale refs
|
|
219
|
-
- Run `git worktree prune` to clean up stale worktree admin entries
|
|
220
|
-
|
|
221
216
|
---
|
|
222
217
|
|
|
223
218
|
## Phase 4: Push Local Changes to Remote
|
|
@@ -307,123 +302,31 @@ For each confirmed branch:
|
|
|
307
302
|
|
|
308
303
|
---
|
|
309
304
|
|
|
310
|
-
## Phase 6:
|
|
311
|
-
|
|
312
|
-
For each open PR (including newly created ones):
|
|
313
|
-
|
|
314
|
-
**Configuration:**
|
|
315
|
-
- Max 3 fix attempts per PR
|
|
316
|
-
- Max 5 minute wait per CI run
|
|
317
|
-
- 30 second polling interval
|
|
318
|
-
|
|
319
|
-
**Process:**
|
|
320
|
-
1. Check CI status: `gh pr checks <pr-number>` or `gh pr view <pr-number> --json statusCheckRollup`
|
|
321
|
-
2. If CI is running:
|
|
322
|
-
- Display: "Waiting for CI on PR #<number>... (attempt X/3, Xs elapsed)"
|
|
323
|
-
- Wait 30 seconds
|
|
324
|
-
- Re-check (up to 5 minutes total)
|
|
325
|
-
3. If CI passes: Mark PR as ready for merge, proceed to Phase 7
|
|
326
|
-
4. If CI fails:
|
|
327
|
-
- Fetch and display the failure output
|
|
328
|
-
- Categorize the failure:
|
|
329
|
-
- **Lint/Formatting errors**: Offer to run `npm run lint -- --fix` automatically
|
|
330
|
-
- **Type errors**: Show errors, ask user: "Skip this PR", "I'll fix manually"
|
|
331
|
-
- **Test failures**: Show test output, ask user: "Skip this PR", "I'll fix manually"
|
|
332
|
-
- **Build errors**: Show error, ask user: "Skip this PR", "I'll fix manually"
|
|
333
|
-
- If auto-fix chosen (lint only):
|
|
334
|
-
- Run the fix command
|
|
335
|
-
- Show the diff to user
|
|
336
|
-
- Ask for confirmation before committing
|
|
337
|
-
- Commit with message: "fix: auto-fix lint errors"
|
|
338
|
-
- Push and decrement retry counter
|
|
339
|
-
- If manual fix chosen:
|
|
340
|
-
- Inform user and pause for this PR
|
|
341
|
-
- Ask: "Continue with other PRs?" or "Wait for manual fix?"
|
|
342
|
-
5. If max retries exceeded:
|
|
343
|
-
- Ask user: "Skip this PR", "Abort workflow", or "I'll fix manually"
|
|
344
|
-
- Handle accordingly
|
|
345
|
-
|
|
346
|
-
**IMPORTANT**: NEVER auto-fix test failures or type errors. Only lint/formatting issues are safe to auto-fix.
|
|
347
|
-
|
|
348
|
-
---
|
|
349
|
-
|
|
350
|
-
## Phase 7: Merge PRs
|
|
351
|
-
|
|
352
|
-
For each PR that passed CI:
|
|
353
|
-
|
|
354
|
-
**Pre-merge checks:**
|
|
355
|
-
1. Re-verify CI status (avoid race condition): `gh pr view <pr-number> --json statusCheckRollup`
|
|
356
|
-
2. Check merge state: `gh pr view <pr-number> --json mergeStateStatus,mergeable`
|
|
357
|
-
|
|
358
|
-
**If branch is behind default branch (`mergeStateStatus` is `BEHIND`):**
|
|
359
|
-
- Ask user: "Update branch via GitHub" or "Skip this PR"
|
|
360
|
-
- If update chosen:
|
|
361
|
-
- Run: `gh api repos/{owner}/{repo}/pulls/{pr-number}/update-branch -X PUT`
|
|
362
|
-
- If the API call fails (e.g., merge conflicts), inform user and offer to skip
|
|
363
|
-
- Wait for CI to re-run after update
|
|
364
|
-
- Re-check merge state
|
|
365
|
-
|
|
366
|
-
**If merge conflicts exist (`mergeable` is `CONFLICTING`):**
|
|
367
|
-
- STOP - cannot auto-merge
|
|
368
|
-
- Show the PR URL
|
|
369
|
-
- Ask user: "Skip this PR" or "I'll resolve conflicts manually"
|
|
370
|
-
- If manual resolution, wait for user confirmation then re-check
|
|
371
|
-
|
|
372
|
-
**Merge:**
|
|
373
|
-
- Run `gh pr merge <pr-number> --delete-branch`
|
|
374
|
-
- This respects the repository's merge strategy settings
|
|
375
|
-
- The `--delete-branch` flag removes the remote branch after merge
|
|
376
|
-
|
|
377
|
-
**If merge fails:**
|
|
378
|
-
- Report the error
|
|
379
|
-
- Ask user how to proceed
|
|
380
|
-
|
|
381
|
-
---
|
|
382
|
-
|
|
383
|
-
## Phase 8: Final Cleanup & Summary
|
|
305
|
+
## Phase 6: Local Cleanup & Summary
|
|
384
306
|
|
|
385
|
-
### Step 1:
|
|
386
|
-
|
|
387
|
-
For any worktrees whose branches were merged in Phase 7:
|
|
388
|
-
- The remote branch is now deleted, but the local worktree may still exist
|
|
389
|
-
- For each such worktree, ask user:
|
|
390
|
-
```
|
|
391
|
-
Worktree at '<path>' is now on merged branch '<branch>'.
|
|
392
|
-
|
|
393
|
-
Options:
|
|
394
|
-
1. Remove worktree (Recommended)
|
|
395
|
-
2. Keep worktree (switch to <default-branch>)
|
|
396
|
-
```
|
|
397
|
-
- If remove: `git worktree remove <path>`
|
|
398
|
-
- If keep: `git -C <path> checkout <default-branch>`
|
|
399
|
-
|
|
400
|
-
### Step 2: Clean up stale refs and worktree entries
|
|
307
|
+
### Step 1: Clean up stale refs and worktree entries
|
|
401
308
|
|
|
402
309
|
1. Run `git fetch --prune` to clean up all stale remote refs
|
|
403
310
|
2. Run `git worktree prune` to clean up stale worktree admin entries
|
|
404
|
-
3. Delete any local branches that were merged (check against PRs merged in Phase 7)
|
|
405
|
-
- Skip branches that are checked out in remaining worktrees
|
|
406
311
|
|
|
407
|
-
### Step
|
|
312
|
+
### Step 2: Return to original context
|
|
408
313
|
|
|
409
314
|
- **If original state was a branch**: Run `git checkout <original-branch>` (if it still exists, otherwise stay on default branch)
|
|
410
315
|
- **If original state was detached HEAD**: Run `git checkout <original-commit-sha>` to restore exact position
|
|
411
|
-
- If the original branch was
|
|
316
|
+
- If the original branch was deleted, inform user: "Your original branch '<branch>' was deleted. You are now on '<default-branch>'."
|
|
412
317
|
|
|
413
|
-
### Step
|
|
318
|
+
### Step 3: Display final summary
|
|
414
319
|
|
|
415
320
|
```
|
|
416
321
|
=====================================================
|
|
417
|
-
Git
|
|
322
|
+
Local Git Cleanup Complete!
|
|
418
323
|
=====================================================
|
|
419
324
|
|
|
420
325
|
BRANCHES:
|
|
421
326
|
✓ Deleted X merged branches (local + remote)
|
|
422
327
|
✓ Pushed X branches to remote
|
|
423
328
|
✓ Created X PRs
|
|
424
|
-
✓ Merged X PRs
|
|
425
329
|
○ Skipped X WIP branches
|
|
426
|
-
✗ X PRs skipped (CI failed / merge conflicts)
|
|
427
330
|
|
|
428
331
|
WORKTREES:
|
|
429
332
|
✓ Removed X worktrees (merged branches)
|
|
@@ -434,6 +337,10 @@ CURRENT STATE:
|
|
|
434
337
|
Branch: <current-branch>
|
|
435
338
|
Worktree: <current-worktree-path>
|
|
436
339
|
|
|
340
|
+
PRs CREATED:
|
|
341
|
+
- PR #42: feature-x
|
|
342
|
+
- PR #43: bugfix-1
|
|
343
|
+
|
|
437
344
|
REMAINING BRANCHES:
|
|
438
345
|
- feature-wip (in worktree: /path/to/feature-wip)
|
|
439
346
|
- bugfix-active (ahead 2)
|
|
@@ -442,9 +349,8 @@ ACTIVE WORKTREES:
|
|
|
442
349
|
/path/to/main main (this worktree)
|
|
443
350
|
/path/to/feature feature-wip clean
|
|
444
351
|
|
|
445
|
-
|
|
446
|
-
-
|
|
447
|
-
- Worktree at /path/to/feature has uncommitted changes
|
|
352
|
+
NEXT STEPS:
|
|
353
|
+
Run `/github-pr-resolve` to handle CI, reviews, and merging.
|
|
448
354
|
=====================================================
|
|
449
355
|
```
|
|
450
356
|
|
|
@@ -481,11 +387,6 @@ If the workflow fails at any point, display:
|
|
|
481
387
|
- Branch is pushed, PR was not created
|
|
482
388
|
- Retry: `gh pr create --head <branch>`
|
|
483
389
|
|
|
484
|
-
**If failed during merge:**
|
|
485
|
-
- PR still exists, not merged
|
|
486
|
-
- Check PR status: `gh pr view <number>`
|
|
487
|
-
- Retry via GitHub UI or: `gh pr merge <number>`
|
|
488
|
-
|
|
489
390
|
**If failed during rebase:**
|
|
490
391
|
- Rebase may be in progress
|
|
491
392
|
- Check: `git status`
|
|
@@ -502,8 +403,6 @@ If the workflow fails at any point, display:
|
|
|
502
403
|
- NEVER use force push (`--force` or `-f`)
|
|
503
404
|
- NEVER use force delete for branches (`-D`) unless confirmed squash-merged
|
|
504
405
|
- ALWAYS confirm with user before destructive operations
|
|
505
|
-
- NEVER merge without CI passing
|
|
506
|
-
- ALWAYS respect retry limits
|
|
507
406
|
- ALWAYS preserve the user's working context (return to original branch)
|
|
508
407
|
|
|
509
408
|
### Worktree Safety Rules
|
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Assess open PRs, handle review comments, run CI, and merge'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
IT IS CRITICAL THAT YOU FOLLOW THIS WORKFLOW EXACTLY.
|
|
6
|
+
|
|
7
|
+
<workflow CRITICAL="TRUE">
|
|
8
|
+
|
|
9
|
+
## Phase 0: Pre-flight Checks
|
|
10
|
+
|
|
11
|
+
Before any operations, verify the environment is safe:
|
|
12
|
+
|
|
13
|
+
1. **Check gh authentication**: Run `gh auth status`. If not authenticated, STOP and inform user.
|
|
14
|
+
|
|
15
|
+
2. **Detect remote name**: Run `git remote` and use the first result (usually `origin`).
|
|
16
|
+
|
|
17
|
+
3. **Detect default branch**: Run `gh repo view --json defaultBranchRef -q .defaultBranchRef.name`. Fallback to `main` if this fails.
|
|
18
|
+
|
|
19
|
+
4. **Record current branch and worktree**:
|
|
20
|
+
- Run `git branch --show-current` to get current branch name
|
|
21
|
+
- **If empty (detached HEAD)**: Run `git rev-parse HEAD` to save the commit SHA instead
|
|
22
|
+
- Run `git rev-parse --show-toplevel` to record the current worktree path
|
|
23
|
+
- Track whether we started in detached HEAD state for Phase 5 restoration
|
|
24
|
+
|
|
25
|
+
5. **Build worktree inventory**: Run `git worktree list --porcelain` to detect all worktrees.
|
|
26
|
+
- Parse the output to build a map: `{ branch_name -> worktree_path }`
|
|
27
|
+
- For each branch, record if it's checked out in a worktree and where
|
|
28
|
+
|
|
29
|
+
6. **Check for uncommitted changes**: Run `git status --porcelain`.
|
|
30
|
+
- If output is non-empty, offer handling options:
|
|
31
|
+
```
|
|
32
|
+
You have uncommitted changes in your working directory.
|
|
33
|
+
|
|
34
|
+
Options:
|
|
35
|
+
1. Stash changes now (I'll restore them at the end)
|
|
36
|
+
2. Proceed carefully (I'll warn before any checkout operation)
|
|
37
|
+
3. Let me commit/stash manually first (pause workflow)
|
|
38
|
+
```
|
|
39
|
+
- If stash chosen: Run `git stash push -m "github-pr-resolve: auto-stash"` and track `stash_used = true`
|
|
40
|
+
- Track stash state for restoration in Phase 5
|
|
41
|
+
|
|
42
|
+
7. **Initialize task tracking**: Use TodoWrite to create a task list for the session.
|
|
43
|
+
- Add tasks for each phase: PR assessment, review comments, CI fixes, merges, cleanup
|
|
44
|
+
- Update task status as work progresses (this ensures nothing is missed)
|
|
45
|
+
- The todo list provides visibility to the user and keeps the workflow on track
|
|
46
|
+
|
|
47
|
+
If gh authentication fails, STOP and clearly explain what the user needs to do.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Phase 1: PR Discovery & Assessment
|
|
52
|
+
|
|
53
|
+
Gather comprehensive information about all open PRs:
|
|
54
|
+
|
|
55
|
+
1. **Fetch all open PRs**: Run `gh pr list --state open --json number,title,headRefName,baseRefName,statusCheckRollup,reviewDecision,isDraft,createdAt,url`
|
|
56
|
+
|
|
57
|
+
2. **For each PR, gather additional details**:
|
|
58
|
+
- Review status: `gh pr view <number> --json reviews,reviewDecision`
|
|
59
|
+
- CI status: Parse `statusCheckRollup` from the list query
|
|
60
|
+
- Mergeable status: `gh pr view <number> --json mergeStateStatus,mergeable`
|
|
61
|
+
|
|
62
|
+
3. **Categorize PRs**:
|
|
63
|
+
|
|
64
|
+
| Category | Description | Action |
|
|
65
|
+
|----------|-------------|--------|
|
|
66
|
+
| Ready to Merge | CI passed, approved, no conflicts | Phase 4 |
|
|
67
|
+
| Needs Review Comments | Has pending/requested changes | Phase 2 |
|
|
68
|
+
| CI Running | Checks in progress | Phase 3 |
|
|
69
|
+
| CI Failed | Checks failed | Phase 3 |
|
|
70
|
+
| Draft | Marked as draft | Skip unless user requests |
|
|
71
|
+
| Conflicts | Has merge conflicts | Warn user |
|
|
72
|
+
|
|
73
|
+
4. **Present summary table**:
|
|
74
|
+
```
|
|
75
|
+
Open PRs Assessment:
|
|
76
|
+
|
|
77
|
+
| # | Title | Branch | Status | Reviews | CI | Mergeable |
|
|
78
|
+
|---|-------|--------|--------|---------|----|-----------|
|
|
79
|
+
| 42 | Add auth | feature-auth | Ready | Approved | ✓ | Yes |
|
|
80
|
+
| 43 | Fix bug | bugfix-123 | Review | Changes Requested | ✓ | Yes |
|
|
81
|
+
| 44 | New API | api-v2 | CI | - | Running | Yes |
|
|
82
|
+
| 45 | Refactor | refactor | Conflicts | - | ✓ | No |
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
5. **Ask user how to proceed**:
|
|
86
|
+
- "Process all PRs in order"
|
|
87
|
+
- "Let me select which PRs to process"
|
|
88
|
+
- "Skip to specific phase" (if user only wants merging)
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Phase 2: Review Comments Handling
|
|
93
|
+
|
|
94
|
+
For each PR with pending reviews or requested changes:
|
|
95
|
+
|
|
96
|
+
### Step 1: Fetch ALL review data (multiple sources required)
|
|
97
|
+
|
|
98
|
+
GitHub stores review feedback in THREE separate places. You MUST check all three:
|
|
99
|
+
|
|
100
|
+
1. **PR-level reviews** (approval/rejection decisions):
|
|
101
|
+
```bash
|
|
102
|
+
gh pr view <number> --json reviews,reviewDecision
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
2. **PR conversation comments** (general discussion):
|
|
106
|
+
```bash
|
|
107
|
+
gh pr view <number> --json comments
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
3. **Inline code review comments** (line-specific feedback - CRITICAL, OFTEN MISSED):
|
|
111
|
+
```bash
|
|
112
|
+
gh api repos/{owner}/{repo}/pulls/{number}/comments
|
|
113
|
+
```
|
|
114
|
+
This returns comments attached to specific lines of code. These are the most actionable!
|
|
115
|
+
|
|
116
|
+
**CRITICAL**: The `--json comments` flag does NOT include inline code review comments.
|
|
117
|
+
You MUST call the `/pulls/{number}/comments` API endpoint separately.
|
|
118
|
+
|
|
119
|
+
Parse each source and combine into a unified list with:
|
|
120
|
+
- Comment body/text
|
|
121
|
+
- Author (check if bot - see Step 1.5)
|
|
122
|
+
- File path and line number (for inline comments)
|
|
123
|
+
- Whether it's resolved/outdated
|
|
124
|
+
- Creation timestamp
|
|
125
|
+
|
|
126
|
+
### Step 1.5: Identify bot reviewers
|
|
127
|
+
|
|
128
|
+
Before categorizing comments, identify automated reviewers:
|
|
129
|
+
|
|
130
|
+
**Known CI/review bots:**
|
|
131
|
+
- `github-actions[bot]`
|
|
132
|
+
- `chatgpt-codex-connector[bot]` or similar Codex bots
|
|
133
|
+
- `coderabbitai[bot]`
|
|
134
|
+
- `dependabot[bot]`
|
|
135
|
+
- `renovate[bot]`
|
|
136
|
+
- `sonarcloud[bot]`
|
|
137
|
+
|
|
138
|
+
**Bot comment handling:**
|
|
139
|
+
- Bot comments are often MORE actionable than they appear (security suggestions, code quality)
|
|
140
|
+
- ALWAYS expand/check bot comments even if they seem informational
|
|
141
|
+
- Display bot comments separately in the summary
|
|
142
|
+
|
|
143
|
+
### Step 2: Categorize comments
|
|
144
|
+
|
|
145
|
+
Analyze each comment and categorize:
|
|
146
|
+
|
|
147
|
+
| Category | Auto-addressable? | Examples |
|
|
148
|
+
|----------|-------------------|----------|
|
|
149
|
+
| Add comment/docstring | Yes | "Please add a comment explaining this", "Add JSDoc" |
|
|
150
|
+
| Rename variable/function | Yes | "Rename `x` to `count`", "Use more descriptive name" |
|
|
151
|
+
| Add type annotation | Yes | "Add type for this parameter" |
|
|
152
|
+
| Fix typo | Yes | "Typo: 'recieve' -> 'receive'" |
|
|
153
|
+
| Logic change | No - guided | "This should handle the null case" |
|
|
154
|
+
| Refactor request | No - guided | "Extract this into a separate function" |
|
|
155
|
+
| Question/clarification | No - guided | "Why is this needed?" |
|
|
156
|
+
| Approval/praise | Skip | "LGTM", "Nice work" |
|
|
157
|
+
|
|
158
|
+
### Step 3: Display summary and ask user
|
|
159
|
+
|
|
160
|
+
For each PR with comments:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
PR #42: "Add user authentication"
|
|
164
|
+
Review status: Changes Requested
|
|
165
|
+
Reviewer: @reviewer-name
|
|
166
|
+
|
|
167
|
+
Comments: 5 total
|
|
168
|
+
- 3 auto-addressable (add docstring, rename var, fix typo)
|
|
169
|
+
- 2 need guidance (logic change, refactor request)
|
|
170
|
+
|
|
171
|
+
Options:
|
|
172
|
+
1. Auto-address 3 simple comments (Recommended)
|
|
173
|
+
2. Guide me through all 5 comments
|
|
174
|
+
3. View all comments first
|
|
175
|
+
4. Skip this PR
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Step 4: Auto-address simple comments
|
|
179
|
+
|
|
180
|
+
If user chooses auto-address:
|
|
181
|
+
|
|
182
|
+
1. **Checkout the PR branch** (if not already):
|
|
183
|
+
- Check if branch is in a worktree - if so, operate there with `git -C`
|
|
184
|
+
- Otherwise: `git checkout <branch>`
|
|
185
|
+
|
|
186
|
+
2. **For each auto-addressable comment**:
|
|
187
|
+
- Read the file at the specified path
|
|
188
|
+
- Identify the exact location (line number from review comment)
|
|
189
|
+
- Make the change based on the comment type:
|
|
190
|
+
- **Add comment/docstring**: Generate appropriate documentation
|
|
191
|
+
- **Rename**: Use find/replace for the identifier
|
|
192
|
+
- **Add type annotation**: Infer or use suggested type
|
|
193
|
+
- **Fix typo**: Apply the correction
|
|
194
|
+
- Show diff to user: "Change X to Y in file.ts:42"
|
|
195
|
+
- Ask: "Apply this change?" / "Skip" / "Edit manually"
|
|
196
|
+
|
|
197
|
+
3. **After all accepted changes**:
|
|
198
|
+
- Show consolidated diff
|
|
199
|
+
- Ask for confirmation before committing
|
|
200
|
+
- **Stage ONLY modified files explicitly** (NEVER use `git add .` or `git commit -a`):
|
|
201
|
+
```bash
|
|
202
|
+
git add <file1> <file2> ... # Only files that were actually modified
|
|
203
|
+
```
|
|
204
|
+
- Verify staging is correct: `git status --short`
|
|
205
|
+
- If unexpected files are staged, warn user and ask how to proceed
|
|
206
|
+
- Commit: `git commit -m "fix: address review comments"`
|
|
207
|
+
- **Check upstream tracking before push**:
|
|
208
|
+
```bash
|
|
209
|
+
# If no upstream set, use -u flag
|
|
210
|
+
git rev-parse --abbrev-ref --symbolic-full-name @{upstream} 2>/dev/null || git push -u origin <branch>
|
|
211
|
+
# Otherwise just push
|
|
212
|
+
git push
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Step 5: Guided resolution for complex comments
|
|
216
|
+
|
|
217
|
+
If user chooses guided resolution or has complex comments remaining:
|
|
218
|
+
|
|
219
|
+
For each complex comment:
|
|
220
|
+
1. Display the comment with full context:
|
|
221
|
+
```
|
|
222
|
+
File: src/auth/login.ts
|
|
223
|
+
Line: 42-45
|
|
224
|
+
Reviewer: @reviewer-name
|
|
225
|
+
Comment: "This should handle the null case - what happens if user is undefined?"
|
|
226
|
+
|
|
227
|
+
Current code:
|
|
228
|
+
40 | const user = getUser(id);
|
|
229
|
+
41 | return user.name; // <- reviewer's concern
|
|
230
|
+
42 | }
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
2. Ask user with `AskUserQuestion`:
|
|
234
|
+
```
|
|
235
|
+
How would you like to address this?
|
|
236
|
+
1. Show me the file (I'll make the fix)
|
|
237
|
+
2. Suggest a fix (Claude will propose code)
|
|
238
|
+
3. Mark as resolved with reply
|
|
239
|
+
4. Skip for now
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
3. **If "Suggest a fix"**:
|
|
243
|
+
- Analyze the code and comment
|
|
244
|
+
- Propose a code change
|
|
245
|
+
- Show diff and ask for confirmation
|
|
246
|
+
- Apply if accepted
|
|
247
|
+
|
|
248
|
+
4. **If "Mark as resolved with reply"**:
|
|
249
|
+
- Ask user for reply text
|
|
250
|
+
- Post reply: `gh api repos/{owner}/{repo}/pulls/{number}/comments/{comment_id}/replies -f body="<reply>"`
|
|
251
|
+
|
|
252
|
+
### Step 6: Post-comment handling
|
|
253
|
+
|
|
254
|
+
After addressing comments:
|
|
255
|
+
- Ask: "Re-request review from @reviewer?" / "Mark ready for review?" / "Leave as-is"
|
|
256
|
+
- If re-request: `gh pr ready <number>` (if was draft) or comment @-mentioning reviewer
|
|
257
|
+
|
|
258
|
+
### Safety Guardrails
|
|
259
|
+
|
|
260
|
+
- NEVER auto-address comments that involve logic changes
|
|
261
|
+
- ALWAYS show diff before committing auto-addressed changes
|
|
262
|
+
- ALWAYS confirm before pushing
|
|
263
|
+
- Track which comments were addressed vs skipped for summary
|
|
264
|
+
- NEVER modify code that the comment doesn't directly reference
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Phase 3: CI Loop
|
|
269
|
+
|
|
270
|
+
For each open PR that needs CI verification:
|
|
271
|
+
|
|
272
|
+
**Configuration:**
|
|
273
|
+
- Max 3 fix attempts per PR
|
|
274
|
+
- Max 5 minute wait per CI run
|
|
275
|
+
- 30 second polling interval
|
|
276
|
+
|
|
277
|
+
### CI Wait Strategy
|
|
278
|
+
|
|
279
|
+
At the start of Phase 3, if multiple PRs have CI running, ask user:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
Multiple PRs have CI in progress:
|
|
283
|
+
- PR #39: CI running (2 min elapsed)
|
|
284
|
+
- PR #40: CI running (1 min elapsed)
|
|
285
|
+
- PR #41: CI running (just started)
|
|
286
|
+
|
|
287
|
+
Options:
|
|
288
|
+
1. Wait for all CIs before proceeding (slower but complete)
|
|
289
|
+
2. Process PRs as their CI completes (faster, may revisit)
|
|
290
|
+
3. Only process PRs with CI already complete
|
|
291
|
+
4. Check back in X minutes (pause workflow)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
If a PR is created during the workflow (e.g., a CI fix PR), ask:
|
|
295
|
+
- "Wait for this PR's CI before continuing"
|
|
296
|
+
- "Continue with other ready PRs, check back later"
|
|
297
|
+
- "This PR is a prerequisite - wait for it, then re-check dependent PRs"
|
|
298
|
+
|
|
299
|
+
**Process:**
|
|
300
|
+
|
|
301
|
+
1. **Check CI status**: `gh pr view <pr-number> --json statusCheckRollup`
|
|
302
|
+
|
|
303
|
+
2. **If CI is running**:
|
|
304
|
+
- Display: "Waiting for CI on PR #<number>... (attempt X/3, Xs elapsed)"
|
|
305
|
+
- Wait 30 seconds
|
|
306
|
+
- Re-check (up to 5 minutes total)
|
|
307
|
+
|
|
308
|
+
3. **If CI passes**: Mark PR as ready for merge, proceed to Phase 4
|
|
309
|
+
|
|
310
|
+
4. **If CI fails**:
|
|
311
|
+
- Fetch and display the failure output
|
|
312
|
+
- Categorize the failure:
|
|
313
|
+
- **Lint/Formatting errors**: Offer to run `npm run lint -- --fix` automatically
|
|
314
|
+
- **Type errors**: Show errors, ask user: "Skip this PR", "I'll fix manually"
|
|
315
|
+
- **Test failures**: Show test output, ask user: "Skip this PR", "I'll fix manually"
|
|
316
|
+
- **Build errors**: Show error, ask user: "Skip this PR", "I'll fix manually"
|
|
317
|
+
- If auto-fix chosen (lint only):
|
|
318
|
+
- Checkout branch (handle worktree if needed)
|
|
319
|
+
- Run the fix command
|
|
320
|
+
- Show the diff to user
|
|
321
|
+
- Ask for confirmation before committing
|
|
322
|
+
- **Stage ONLY files that were actually fixed** (use explicit paths, never `git add .`)
|
|
323
|
+
- Commit with message: "fix: auto-fix lint errors"
|
|
324
|
+
- **Check upstream tracking before push** (use `-u` flag if needed)
|
|
325
|
+
- Push and decrement retry counter
|
|
326
|
+
- If manual fix chosen:
|
|
327
|
+
- Inform user and pause for this PR
|
|
328
|
+
- Ask: "Continue with other PRs?" or "Wait for manual fix?"
|
|
329
|
+
|
|
330
|
+
5. **If max retries exceeded**:
|
|
331
|
+
- Ask user: "Skip this PR", "Abort workflow", or "I'll fix manually"
|
|
332
|
+
- Handle accordingly
|
|
333
|
+
|
|
334
|
+
**IMPORTANT**: NEVER auto-fix test failures or type errors. Only lint/formatting issues are safe to auto-fix.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Phase 4: Merge PRs
|
|
339
|
+
|
|
340
|
+
For each PR that passed CI (and has no pending review comments):
|
|
341
|
+
|
|
342
|
+
### Merge Order Strategy
|
|
343
|
+
|
|
344
|
+
When multiple PRs are ready to merge, order matters:
|
|
345
|
+
|
|
346
|
+
1. **Check for file overlap** between PRs:
|
|
347
|
+
```bash
|
|
348
|
+
gh pr diff <pr1> --name-only > /tmp/pr1_files
|
|
349
|
+
gh pr diff <pr2> --name-only > /tmp/pr2_files
|
|
350
|
+
comm -12 <(sort /tmp/pr1_files) <(sort /tmp/pr2_files)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
2. **Recommended merge order**:
|
|
354
|
+
| Priority | Criteria | Rationale |
|
|
355
|
+
|----------|----------|-----------|
|
|
356
|
+
| 1 | CI/infrastructure fixes | Unblocks other PRs |
|
|
357
|
+
| 2 | PRs with no file overlap | Independent, safe in any order |
|
|
358
|
+
| 3 | Dependency PRs first | If PR B depends on PR A's changes |
|
|
359
|
+
| 4 | Oldest PRs | Reduce stale PR backlog |
|
|
360
|
+
| 5 | Smallest PRs | Quick wins |
|
|
361
|
+
|
|
362
|
+
3. **Present merge plan to user**:
|
|
363
|
+
```
|
|
364
|
+
Recommended merge order:
|
|
365
|
+
1. PR #41 "Fix CI" (infrastructure - may unblock others)
|
|
366
|
+
2. PR #40 "Add feature X" (no conflicts)
|
|
367
|
+
3. PR #39 "Update component Y" (no conflicts)
|
|
368
|
+
|
|
369
|
+
Proceed with this order? [Yes / Let me reorder / Merge one at a time]
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
4. **Between merges**: Re-check remaining PRs for new conflicts after each merge
|
|
373
|
+
|
|
374
|
+
### Pre-merge checks
|
|
375
|
+
|
|
376
|
+
1. Re-verify CI status (avoid race condition): `gh pr view <pr-number> --json statusCheckRollup`
|
|
377
|
+
2. Check merge state: `gh pr view <pr-number> --json mergeStateStatus,mergeable`
|
|
378
|
+
|
|
379
|
+
### Handle branch behind default branch
|
|
380
|
+
|
|
381
|
+
**If `mergeStateStatus` is `BEHIND`:**
|
|
382
|
+
- Ask user: "Update branch via GitHub" or "Skip this PR"
|
|
383
|
+
- If update chosen:
|
|
384
|
+
- Run: `gh api repos/{owner}/{repo}/pulls/{pr-number}/update-branch -X PUT`
|
|
385
|
+
- If the API call fails (e.g., merge conflicts), inform user and offer to skip
|
|
386
|
+
- Wait for CI to re-run after update
|
|
387
|
+
- Re-check merge state
|
|
388
|
+
|
|
389
|
+
### Handle merge conflicts
|
|
390
|
+
|
|
391
|
+
**If `mergeable` is `CONFLICTING`:**
|
|
392
|
+
- STOP - cannot auto-merge
|
|
393
|
+
- Show the PR URL
|
|
394
|
+
- Ask user: "Skip this PR" or "I'll resolve conflicts manually"
|
|
395
|
+
- If manual resolution, wait for user confirmation then re-check
|
|
396
|
+
|
|
397
|
+
### Merge
|
|
398
|
+
|
|
399
|
+
- Present merge summary before proceeding:
|
|
400
|
+
```
|
|
401
|
+
Ready to merge:
|
|
402
|
+
PR #42: "Add user authentication" (feature-auth -> main)
|
|
403
|
+
|
|
404
|
+
This will:
|
|
405
|
+
- Merge the PR using repository's merge strategy
|
|
406
|
+
- Delete the remote branch
|
|
407
|
+
|
|
408
|
+
Proceed? [Yes / Skip / Abort]
|
|
409
|
+
```
|
|
410
|
+
- Run `gh pr merge <pr-number> --delete-branch`
|
|
411
|
+
- This respects the repository's merge strategy settings
|
|
412
|
+
- The `--delete-branch` flag removes the remote branch after merge
|
|
413
|
+
|
|
414
|
+
### Handle merge failure
|
|
415
|
+
|
|
416
|
+
- Report the error
|
|
417
|
+
- Ask user how to proceed
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## Phase 5: Final Cleanup & Summary
|
|
422
|
+
|
|
423
|
+
### Step 0: Restore stashed changes (if applicable)
|
|
424
|
+
|
|
425
|
+
If changes were stashed in Phase 0:
|
|
426
|
+
1. After returning to original branch (Step 4), run `git stash pop`
|
|
427
|
+
2. If pop fails (conflicts), warn user:
|
|
428
|
+
```
|
|
429
|
+
Could not automatically restore your stashed changes.
|
|
430
|
+
Your changes are still in the stash. Run `git stash list` to see them.
|
|
431
|
+
Restore manually with: `git stash pop` or `git stash apply`
|
|
432
|
+
```
|
|
433
|
+
3. Show `git status` to confirm restoration
|
|
434
|
+
|
|
435
|
+
### Step 1: Handle orphaned worktrees from merged PRs
|
|
436
|
+
|
|
437
|
+
For any worktrees whose branches were merged in Phase 4:
|
|
438
|
+
- The remote branch is now deleted, but the local worktree may still exist
|
|
439
|
+
- For each such worktree, ask user:
|
|
440
|
+
```
|
|
441
|
+
Worktree at '<path>' is now on merged branch '<branch>'.
|
|
442
|
+
|
|
443
|
+
Options:
|
|
444
|
+
1. Remove worktree (Recommended)
|
|
445
|
+
2. Keep worktree (switch to <default-branch>)
|
|
446
|
+
```
|
|
447
|
+
- If remove: `git worktree remove <path>`
|
|
448
|
+
- If keep: `git -C <path> checkout <default-branch>`
|
|
449
|
+
|
|
450
|
+
### Step 2: Clean up local branches
|
|
451
|
+
|
|
452
|
+
For each PR merged in Phase 4:
|
|
453
|
+
- Delete local branch if it exists: `git branch -d <branch>`
|
|
454
|
+
- Skip if branch is checked out in a remaining worktree
|
|
455
|
+
|
|
456
|
+
### Step 3: Clean up stale refs
|
|
457
|
+
|
|
458
|
+
1. Run `git fetch --prune` to clean up all stale remote refs
|
|
459
|
+
2. Run `git worktree prune` to clean up stale worktree admin entries
|
|
460
|
+
|
|
461
|
+
### Step 4: Return to original context
|
|
462
|
+
|
|
463
|
+
- **If original state was a branch**: Run `git checkout <original-branch>` (if it still exists, otherwise stay on default branch)
|
|
464
|
+
- **If original state was detached HEAD**: Run `git checkout <original-commit-sha>` to restore exact position
|
|
465
|
+
- If the original branch was merged and deleted, inform user: "Your original branch '<branch>' was merged. You are now on '<default-branch>'."
|
|
466
|
+
|
|
467
|
+
### Step 5: Display final summary
|
|
468
|
+
|
|
469
|
+
```
|
|
470
|
+
=====================================================
|
|
471
|
+
GitHub PR Resolution Complete!
|
|
472
|
+
=====================================================
|
|
473
|
+
|
|
474
|
+
PRs PROCESSED:
|
|
475
|
+
✓ Merged X PRs
|
|
476
|
+
- PR #42: "Add user authentication"
|
|
477
|
+
- PR #43: "Fix login bug"
|
|
478
|
+
○ Skipped X PRs (CI failed / conflicts)
|
|
479
|
+
- PR #45: "Refactor" (merge conflicts)
|
|
480
|
+
|
|
481
|
+
REVIEW COMMENTS:
|
|
482
|
+
✓ Auto-addressed X comments
|
|
483
|
+
✓ Manually resolved X comments
|
|
484
|
+
○ Skipped X comments
|
|
485
|
+
|
|
486
|
+
CI FIXES:
|
|
487
|
+
✓ Auto-fixed X lint issues
|
|
488
|
+
○ X PRs need manual fixes
|
|
489
|
+
|
|
490
|
+
CLEANUP:
|
|
491
|
+
✓ Deleted X remote branches
|
|
492
|
+
✓ Deleted X local branches
|
|
493
|
+
✓ Removed X worktrees
|
|
494
|
+
|
|
495
|
+
CURRENT STATE:
|
|
496
|
+
Branch: <current-branch>
|
|
497
|
+
Worktree: <current-worktree-path>
|
|
498
|
+
|
|
499
|
+
REMAINING OPEN PRs:
|
|
500
|
+
- PR #45: "Refactor" - merge conflicts, needs manual resolution
|
|
501
|
+
- PR #46: "Draft feature" - draft, skipped
|
|
502
|
+
|
|
503
|
+
WARNINGS (if any):
|
|
504
|
+
- PR #45 has merge conflicts at src/auth/login.ts
|
|
505
|
+
=====================================================
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
</workflow>
|
|
509
|
+
|
|
510
|
+
## Error Recovery
|
|
511
|
+
|
|
512
|
+
If the workflow fails at any point, display:
|
|
513
|
+
|
|
514
|
+
1. **Operations completed successfully** (from the operation log)
|
|
515
|
+
2. **The operation that failed** and the error message
|
|
516
|
+
3. **Current repository state**:
|
|
517
|
+
- Current branch: `git branch --show-current`
|
|
518
|
+
- Uncommitted changes: `git status --porcelain`
|
|
519
|
+
- Any in-progress operations: check for rebase/merge/cherry-pick
|
|
520
|
+
|
|
521
|
+
4. **Recovery guidance based on failure point**:
|
|
522
|
+
|
|
523
|
+
**If failed during review comment fix:**
|
|
524
|
+
- Changes may be uncommitted
|
|
525
|
+
- Check: `git status` and `git diff`
|
|
526
|
+
- Either commit or stash the changes
|
|
527
|
+
- PR is still open (safe)
|
|
528
|
+
|
|
529
|
+
**If failed during CI fix commit:**
|
|
530
|
+
- Changes may be uncommitted
|
|
531
|
+
- Check: `git status`
|
|
532
|
+
- Commit manually: `git commit -am "fix: ..."`
|
|
533
|
+
- Push: `git push`
|
|
534
|
+
|
|
535
|
+
**If failed during merge:**
|
|
536
|
+
- PR still exists, not merged
|
|
537
|
+
- Check PR status: `gh pr view <number>`
|
|
538
|
+
- Retry via GitHub UI or: `gh pr merge <number>`
|
|
539
|
+
|
|
540
|
+
**If failed during worktree cleanup:**
|
|
541
|
+
- Worktree may be partially removed
|
|
542
|
+
- Run: `git worktree prune` to clean up
|
|
543
|
+
- Check: `git worktree list`
|
|
544
|
+
|
|
545
|
+
**If failed during branch deletion:**
|
|
546
|
+
- Local branch may be deleted but remote still exists (or vice versa)
|
|
547
|
+
- Check: `git branch -a | grep <branch>`
|
|
548
|
+
- Manual cleanup if needed
|
|
549
|
+
|
|
550
|
+
5. **Always safe to re-run**: The workflow is idempotent - running it again will skip already-completed operations.
|
|
551
|
+
|
|
552
|
+
---
|
|
553
|
+
|
|
554
|
+
## Safety Rules
|
|
555
|
+
|
|
556
|
+
### PR Safety Rules
|
|
557
|
+
- NEVER merge without CI passing
|
|
558
|
+
- NEVER force merge when conflicts exist
|
|
559
|
+
- ALWAYS verify merge state before merging
|
|
560
|
+
- ALWAYS respect retry limits
|
|
561
|
+
|
|
562
|
+
### Review Comment Safety Rules
|
|
563
|
+
- NEVER auto-address comments that involve logic changes
|
|
564
|
+
- ALWAYS show diff before committing changes
|
|
565
|
+
- ALWAYS confirm before pushing
|
|
566
|
+
- NEVER modify code that the comment doesn't directly reference
|
|
567
|
+
- ALWAYS track which comments were addressed for summary
|
|
568
|
+
|
|
569
|
+
### Branch Safety Rules
|
|
570
|
+
- NEVER use force push (`--force` or `-f`)
|
|
571
|
+
- ALWAYS preserve the user's working context (return to original branch)
|
|
572
|
+
|
|
573
|
+
### Commit Safety Rules
|
|
574
|
+
- NEVER use `git commit -a` or `git add .` without first reviewing what will be staged
|
|
575
|
+
- ALWAYS use explicit file paths when staging: `git add <specific-file>`
|
|
576
|
+
- ALWAYS run `git status` before committing to verify staged files
|
|
577
|
+
- If the commit includes unexpected files, STOP and ask user before proceeding
|
|
578
|
+
- ALWAYS check upstream tracking before push (use `-u` flag if no upstream)
|
|
579
|
+
|
|
580
|
+
### Worktree Safety Rules
|
|
581
|
+
- NEVER remove a worktree with uncommitted changes without explicit user confirmation
|
|
582
|
+
- ALWAYS check worktree status before operations
|
|
583
|
+
- ALWAYS run `git worktree prune` after removing worktrees
|
|
584
|
+
- ALWAYS use `git -C <path>` for operations in linked worktrees
|