|
| 1 | +--- |
| 2 | +name: review |
| 3 | +description: Check all open PRs, resolve conflicts, update branches, address Claude and Greptile review concerns, fix CI failures, and retrigger reviewers until clean |
| 4 | +allowed-tools: Bash, Read, Write, Edit, Glob, Grep, Agent |
| 5 | +--- |
| 6 | + |
| 7 | +# PR Review Sweep |
| 8 | + |
| 9 | +You are performing a full review sweep across all open PRs in this repository. Your goal is to bring every PR to a clean, mergeable state: no conflicts, CI passing, all reviewer comments addressed, and reviewers re-triggered until satisfied. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Step 0: Worktree Isolation |
| 14 | + |
| 15 | +Before doing anything else, run `/worktree` to get an isolated copy of the repo. CLAUDE.md mandates that every session starts with `/worktree` to prevent cross-session interference. All subsequent steps run inside the worktree. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Step 1: Discover Open PRs |
| 20 | + |
| 21 | +```bash |
| 22 | +gh pr list --repo optave/codegraph --state open --json number,title,headRefName,baseRefName,mergeable,statusCheckRollup,reviewDecision --limit 50 |
| 23 | +``` |
| 24 | + |
| 25 | +Record each PR's number, branch, base, merge status, and CI state. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Step 2: Process Each PR |
| 30 | + |
| 31 | +For **each** open PR, perform the following steps in order. Process PRs one at a time to avoid cross-contamination. |
| 32 | + |
| 33 | +### 2a. Switch to the PR branch |
| 34 | + |
| 35 | +Ensure the working tree is clean before switching to avoid cross-PR contamination: |
| 36 | + |
| 37 | +```bash |
| 38 | +if [ -n "$(git status --porcelain)" ]; then |
| 39 | + git stash push -m "pre-checkout stash" |
| 40 | +fi |
| 41 | +``` |
| 42 | + |
| 43 | +Then check out the PR branch: |
| 44 | + |
| 45 | +```bash |
| 46 | +gh pr checkout <number> |
| 47 | +``` |
| 48 | + |
| 49 | +### 2b. Resolve merge conflicts |
| 50 | + |
| 51 | +Check if the PR has conflicts with its base branch: |
| 52 | + |
| 53 | +```bash |
| 54 | +gh pr view <number> --json mergeable --jq '.mergeable' |
| 55 | +``` |
| 56 | + |
| 57 | +If `CONFLICTING`: |
| 58 | + |
| 59 | +1. Merge the base branch into the head branch (never rebase): |
| 60 | + ```bash |
| 61 | + git merge origin/<base-branch> |
| 62 | + ``` |
| 63 | +2. **Do not assume which side to keep.** You must fully understand the context of both sides before resolving. If you don't know why a line was added — what feature it supports, what bug it fixes, what reviewer requested it — you cannot resolve the conflict correctly. Before touching any conflict: |
| 64 | + - Read the PR description and any linked issues (`gh pr view <number>`) to understand the PR's purpose and scope. |
| 65 | + - Check the PR's commit history (`git log --oneline origin/<base-branch>..HEAD -- <file>`) to understand *why* the conflicting line was changed on the PR side. Also check the base branch history (`git log --oneline HEAD..origin/<base-branch> -- <file>`) to understand *why* the base version exists. |
| 66 | + - Read Greptile and Claude review comments on the PR (`gh api repos/optave/codegraph/pulls/<number>/comments`, `gh api repos/optave/codegraph/issues/<number>/comments`) — a reviewer may have requested the change that caused the conflict. |
| 67 | + - Check what landed on main that introduced the other side (`git log --oneline HEAD..origin/<base-branch> -- <file>`) and read those PR descriptions too if needed. |
| 68 | + - Compare the PR's diff against its merge base (`git diff $(git merge-base origin/<base-branch> HEAD) HEAD -- <file>`) to see which side introduced an intentional change vs. which side carried stale code. |
| 69 | + - Only then choose the correct resolution. If the PR deliberately changed a line and main still has the old version, keep the PR's version. If main introduced a fix or new feature the PR doesn't have, keep main's version. If both sides made intentional changes, merge them together manually. |
| 70 | +3. After resolving, stage the resolved files by name (not `git add .`), commit with: `fix: resolve merge conflicts with <base-branch>` |
| 71 | +4. Push the updated branch. |
| 72 | + |
| 73 | +### 2c. Check CI status |
| 74 | + |
| 75 | +```bash |
| 76 | +gh pr checks <number> |
| 77 | +``` |
| 78 | + |
| 79 | +If any checks are failing: |
| 80 | + |
| 81 | +1. Read the failing check logs: |
| 82 | + ```bash |
| 83 | + gh run view <run-id> --log-failed |
| 84 | + ``` |
| 85 | +2. Diagnose the failure — read the relevant source files, understand the error. |
| 86 | +3. Fix the issue in code. |
| 87 | +4. Run tests locally to verify: `npm test` |
| 88 | +5. Run lint locally: `npm run lint` |
| 89 | +6. Commit the fix with a descriptive message: `fix: <what was broken and why>` |
| 90 | +7. Push and wait for CI to re-run. Check again: |
| 91 | + ```bash |
| 92 | + gh pr checks <number> |
| 93 | + ``` |
| 94 | +8. Repeat until CI is green. |
| 95 | + |
| 96 | +### 2d. Gather all review comments |
| 97 | + |
| 98 | +Fetch **all** review comments from both Claude and Greptile: |
| 99 | + |
| 100 | +```bash |
| 101 | +# PR review comments (inline code comments) |
| 102 | +gh api repos/optave/codegraph/pulls/<number>/comments --paginate --jq '.[] | {id: .id, user: .user.login, body: .body, path: .path, line: .line, created_at: .created_at}' |
| 103 | + |
| 104 | +# PR reviews (top-level review bodies) |
| 105 | +gh api repos/optave/codegraph/pulls/<number>/reviews --paginate --jq '.[] | {id: .id, user: .user.login, body: .body, state: .state}' |
| 106 | + |
| 107 | +# Issue-style comments (includes @greptileai trigger responses) |
| 108 | +gh api repos/optave/codegraph/issues/<number>/comments --paginate --jq '.[] | {id: .id, user: .user.login, body: .body, created_at: .created_at}' |
| 109 | +``` |
| 110 | + |
| 111 | +### 2e. Address every comment |
| 112 | + |
| 113 | +For **each** review comment — including minor suggestions, nits, style feedback, and optional improvements: |
| 114 | + |
| 115 | +1. **Read the comment carefully.** Understand what the reviewer is asking for. |
| 116 | +2. **Read the relevant code** at the file and line referenced. |
| 117 | +3. **Make the change.** Even if the comment is marked as "nit" or "suggestion" or "minor" — address it. The goal is zero outstanding comments. |
| 118 | +4. **If you disagree** with a suggestion (e.g., it would introduce a bug or contradicts project conventions), do NOT silently ignore it. Reply to the comment explaining why you chose a different approach. |
| 119 | +5. **Reply to each comment** explaining what you did: |
| 120 | + ```bash |
| 121 | + gh api repos/optave/codegraph/pulls/<number>/comments/<comment-id>/replies \ |
| 122 | + -f body="Fixed — <brief description of what was changed>" |
| 123 | + ``` |
| 124 | + For issue-style comments, reply on the issue: |
| 125 | + ```bash |
| 126 | + gh api repos/optave/codegraph/issues/<number>/comments \ |
| 127 | + -f body="Addressed: <summary of changes made>" |
| 128 | + ``` |
| 129 | + |
| 130 | +### 2f. Commit and push fixes |
| 131 | + |
| 132 | +After addressing all comments for a PR: |
| 133 | + |
| 134 | +1. Stage only the files you changed. |
| 135 | +2. Group changes by concern — each logically distinct fix gets its own commit (e.g., one commit for a missing validation, another for a naming change). Do not lump all feedback into a single commit. |
| 136 | +3. Use descriptive messages per commit: `fix: <what this specific change does> (#<number>)` |
| 137 | +4. Push to the PR branch. |
| 138 | + |
| 139 | +### 2g. Re-trigger reviewers |
| 140 | + |
| 141 | +**Greptile:** Always re-trigger after pushing fixes. Post a comment: |
| 142 | + |
| 143 | +```bash |
| 144 | +gh api repos/optave/codegraph/issues/<number>/comments \ |
| 145 | + -f body="@greptileai" |
| 146 | +``` |
| 147 | + |
| 148 | +**Claude (claude-code-review / claude bot):** Only re-trigger if you addressed something Claude specifically suggested. If you did: |
| 149 | + |
| 150 | +```bash |
| 151 | +gh api repos/optave/codegraph/issues/<number>/comments \ |
| 152 | + -f body="@claude" |
| 153 | +``` |
| 154 | + |
| 155 | +If all changes were only in response to Greptile feedback, do NOT re-trigger Claude. |
| 156 | + |
| 157 | +### 2h. Wait and re-check |
| 158 | + |
| 159 | +After re-triggering: |
| 160 | + |
| 161 | +1. Wait for the new reviews to come in (check after a reasonable interval). |
| 162 | +2. Fetch new comments again (repeat Step 2d). |
| 163 | +3. If there are **new** comments from Greptile or Claude, go back to Step 2e and address them. |
| 164 | +4. **Repeat this loop for a maximum of 3 rounds.** If after 3 rounds there are still actionable comments, mark the PR as "needs human review" in the summary table and move to the next PR. |
| 165 | +5. Verify CI is still green after all changes. |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +## Step 3: Summary |
| 170 | + |
| 171 | +After processing all PRs, output a summary table: |
| 172 | + |
| 173 | +``` |
| 174 | +| PR | Branch | Conflicts | CI | Comments Addressed | Reviewers Re-triggered | Status | |
| 175 | +|----|--------|-----------|----|--------------------|----------------------|--------| |
| 176 | +| #N | branch | resolved/none | green/red | N comments | greptile, claude | ready/needs-work | |
| 177 | +``` |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## Rules |
| 182 | + |
| 183 | +- **Never rebase.** Always `git merge <base>` to resolve conflicts. |
| 184 | +- **Never force-push** unless fixing a commit message that fails commitlint. Amend + force-push is the only way to fix a pushed commit title (messages are part of the SHA). This is safe on feature branches. For all other problems, fix with a new commit. |
| 185 | +- **Address ALL comments**, even minor/nit/optional ones. Leave zero unaddressed. |
| 186 | +- **Always reply to comments** explaining what was done. Don't just fix silently. |
| 187 | +- **Always re-trigger Greptile** after pushing fixes — it must confirm satisfaction. |
| 188 | +- **Only re-trigger Claude** if you addressed Claude's feedback specifically. |
| 189 | +- **No co-author lines** in commit messages. |
| 190 | +- **No Claude Code references** in commit messages or comments. |
| 191 | +- **Run tests and lint locally** before pushing any fix. |
| 192 | +- **One concern per commit** — don't lump conflict resolution with code fixes. |
| 193 | +- **Flag scope creep.** If a PR's diff contains files unrelated to its stated purpose (e.g., a docs PR carrying `src/` or test changes from a merged feature branch), flag it immediately. Split the unrelated changes into a separate branch and PR. Do not proceed with review until the PR is scoped correctly — scope creep is not acceptable. |
| 194 | +- If a PR is fundamentally broken beyond what review feedback can fix, note it in the summary and skip to the next PR. |
0 commit comments