Review pr

From nudgebee/nudgebee · View interactive version

Review pr is an AI agent skill from the GitHub repository nudgebee/nudgebee. Review a pull request design-first in an isolated worktree — premise, root cause, simpler alternatives, blast radius, rollout — then line-level issues; post comments on the PR and clean up

How to use this skill

Skill file

Review Pull Request

Review the pull request specified by $ARGUMENTS (PR number or URL).

What this review is for

A reviewer approves the decision, not the lines. The comments that change outcomes here are design comments: the premise doesn't hold, the fix treats a symptom, a much smaller change would do, the change quietly alters a flow everyone uses, the rollout order loses data, the next call site will bring the bug back. Line-level bugs come second. Style nits come last, capped, and never block.

A review that lists ten nits and misses that the approach is wrong has failed. A review that says "the approach is right, here is what I checked" with zero findings has succeeded.

Step 0: Validate Arguments

If $ARGUMENTS is empty or not provided, you MUST stop and ask the user for a PR number. Do NOT proceed without an explicit PR number or URL. Do NOT fall back to the current branch's PR.

Example prompt: "Please provide a PR number or URL. Usage: /review-pr 123"

Step 1: Fetch PR Metadata and Create Worktree

Run these commands sequentially in a single bash call:

REPO_ROOT=$(git rev-parse --show-toplevel)
PR_NUMBER=<pr number from arguments>
WORKTREE_DIR="${REPO_ROOT}-pr-review-${PR_NUMBER}"

# Fetch PR metadata
gh pr view $PR_NUMBER --json number,title,body,baseRefName,headRefName,headRefOid,additions,deletions,changedFiles,author,closingIssuesReferences

# Fetch latest and create worktree
git fetch origin
HEAD_BRANCH=$(gh pr view $PR_NUMBER --json headRefName -q .headRefName)
# A leftover worktree from an aborted run would sit on an old head — always start from the current one
git worktree remove "$WORKTREE_DIR" --force 2>/dev/null
git worktree add --detach "$WORKTREE_DIR" "origin/${HEAD_BRANCH}"

echo "WORKTREE_DIR=${WORKTREE_DIR}"

Store the WORKTREE_DIR path. You will use it for ALL subsequent operations.

CRITICAL: Worktree Path Rule

From this point forward, you MUST:

Step 2: Read the Intent Before the Code

You cannot judge a design without knowing what it is for. Before opening the diff, collect:

  1. The PR body. Note its Decision line, its claims ("X is excluded", "refused before LLM spend", "no change for other providers"), its Risks, and its "Not in this PR". Every claim is something to check in Step 5.
  2. The linked ticket (Fixes #N / Part of #N, or closingIssuesReferences) and its parent epic: gh issue view <N> --comments. Note the acceptance criteria and any requirement the ticket states. Also note what the next tickets in the epic need: a design that has to be migrated away from next sprint is a finding now.
  3. Decision log. Read the entries in CODE0 that touch this area. A PR that re-opens a settled decision, or tries something listed under "won't try again", needs to say why.
  4. Sibling PRs. Open PRs touching the same files or adding migrations: gh pr list --state open --search "<file or area>". Look for migration V<N> collisions with main and each other, atlas.sum conflicts, and required merge order.
  5. Earlier review rounds on this PR: inline comments (gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/comments), reviews (.../pulls/$PR_NUMBER/reviews), and summary comments, which are issue comments (gh api repos/{owner}/{repo}/issues/$PR_NUMBER/comments). Do not repeat a point already raised. On a re-review, check each earlier point against the new head and say which are fixed.

Write down two lines for yourself before going further:

Step 3: Identify Affected Services and Read Their CLAUDE.md

gh pr diff $PR_NUMBER --name-only

| Path prefix | Service | Type |

|---|---|---|

| api-server/services/ | api-server | Go |

| ticket-server/ | ticket-server | Go |

| collector-server/cloud-collector/ | cloud-collector | Go |

| collector-server/k8s-collector/relay-server/ | relay-server | Go |

| collector-server/k8s-collector/app/ | k8s-collector-app | Python |

| llm/code-analysis/ | code-analysis | Go |

| llm/llm-server/ | llm-server | Go |

| llm/gateway/ | llm-gateway | Go |

| llm/rag-server/ | rag-server | Python |

| llm/benchmark/ | benchmark | Python |

| ml-k8s-server/ | ml-k8s-server | Python |

| auto-pilot/ | auto-pilot | Python |

| auto-pilot/sidecar/ | auto-pilot-sidecar | Python |

| notifications-server/ | notifications-server | Python |

| runbook-server/ | runbook-server | Go |

| app/ | frontend | TypeScript |

| api-server/migrations/ | migrations | SQL |

| deploy/ | infrastructure | Helm/K8s |

For each affected service, read $WORKTREE_DIR/{path prefix}CLAUDE.md (the path prefix from the table, e.g. llm/llm-server/CLAUDE.md) if it exists. For app/, also check the relevant sections of app/design-system.md.

Step 4: Read the Diff, Then Read Outward

cd $WORKTREE_DIR && gh pr diff $PR_NUMBER

Read each changed file in full from the worktree. Then read outward — design problems live at the edges of the diff, not inside it:

Step 5: Review — Design First

Work through these in order. Each later pass matters less than the one before it; do not let a long list of small findings crowd out one finding from 5.1–5.4.

For PRs over ~100 non-test lines, or that touch shared types, API contracts, DB schema, or cross-service behavior, spawn the plan-alternative agent in the background at the start of this step. Give it the Goal from Step 2 (not the PR's framing) and a one-paragraph summary of the PR's approach, and ask it to design the simplest thing that meets the goal in this codebase and say whether it materially dominates. Use its answer in 5.3; do not paste it verbatim.

5.1 Premise — is the problem real, and does the fix reach it?

5.2 Root cause or symptom?

5.3 Could this be simpler — or different?

5.4 Make the class impossible, not the instance

5.5 Boundaries and ownership

5.6 Blast radius on existing flows

5.7 Failure modes and state

5.8 Rollout and operations

5.9 Authorization and security semantics

5.10 Cross-service consumers and claims

5.11 Scope

5.12 Line-level correctness, tests, conventions

Only now: logic errors, nil risks, missing error handling, races inside a function, off-by-one, language idioms (Go slog / testify; Python black 120 / flake8; TS oxlint / prettier; ds/* primitives in app/).

For tests, ask one question: would this test fail on main? A test that stays green when the bug is present (it asserts the eventual outcome, not that the first attempt succeeded) is not a regression guard. Suggest the assertion that would be.

Nits: at most three per review in total (inline and summary combined), labelled Nit, never blocking. If you have more, drop the least useful.

Evidence rules (all passes)

Step 6: Decide the Verdict

Pick one:

| Verdict | When |

|---|---|

| Approve | Approach right, nothing blocking. Findings are non-blocking or follow-ups. |

| Revise | Approach right, but specific things must change before merge. |

| Redesign | Premise wrong, or a materially simpler / safer design exists that the PR should switch to. |

The verdict is about the approach first. A PR with a wrong approach is Redesign even if every line is correct.

Step 7: Post the Review

Inline comments

Post inline only for findings anchored to a specific line. Design findings spanning several files go in the summary, not scattered across inline comments.

Each inline comment starts with a severity icon, then a blank line, then:

  1. Label, then the claim. Match the label to the icon: critical/high → **Fix before merge.**; medium → **Should:** (blocking) or Non-blocking.; low → Non-blocking. or Nit:. Only the blocking labels are bold.
  2. The scenario that breaks (input → outcome).
  3. The fix, with a `suggestion block when it's a line replacement.

Aim for five lines; a scenario that needs a short bullet list is fine. Never restate the code back to the author — GitHub renders it above your comment. If a finding needs more than ~8 lines, it belongs in the summary.

| Severity | Icon markdown |

|---|---|

| Critical bug / must fix | ![critical](https://www.gstatic.com/codereviewagent/critical.svg) |

| High importance | ![high](https://www.gstatic.com/codereviewagent/high-priority.svg) |

| Medium importance | ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg) |

| Low / nit | ![low](https://www.gstatic.com/codereviewagent/low-priority.svg) |

| Security critical | ![security-high](https://www.gstatic.com/codereviewagent/security-high-priority.svg) followed by ![high](https://www.gstatic.com/codereviewagent/high-priority.svg) |

| Security medium | ![security-medium](https://www.gstatic.com/codereviewagent/security-medium-priority.svg) followed by ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg) |

Example inline comment body:

![high](https://www.gstatic.com/codereviewagent/high-priority.svg)

**Fix before merge.** Save the tasks and the approval row in one transaction. A crash between the two leaves tasks parked with no approval — that is why the orphan sweep exists, and the sweep has an edge case of its own (line 264). With one transaction there are no orphans and the sweep can go.

Posting: always use --input with a JSON payload, so gh api -f doesn't escape the ! in image markdown:

cd $WORKTREE_DIR && cat <<'JSONEOF' | gh api repos/{owner}/{repo}/pulls/$PR_NUMBER/comments --input -
{
  "body": "<comment-with-icon>",
  "path": "<file-path-relative-to-repo-root>",
  "commit_id": "<head-commit-sha>",
  "position": <diff-hunk-position>
}
JSONEOF

Use position (the line offset within the diff hunk, starting from 1), NOT line + subject_type. Head SHA: gh pr view $PR_NUMBER --json headRefOid -q .headRefOid.

Summary comment

One comment. Above the fold ≤ 200 words (per CODE0); everything else in folds. No changelog of the diff — the author knows what they changed.

**{Approve | Revise | Redesign}.** {One or two sentences: is the approach right, and the single most important thing. E.g. "The design is right: plan, park, approve into a separate run. Two things to fix before merge."}

**Before merge**
1. **{Short title}.** {Scenario → fix, 1–3 lines.} ([inline]({link}))
2. ...

**Non-blocking**
1. {Short title — one line.}

**Could this be simpler?** {Only when a materially simpler or different design exists: options A/B with what each takes and its cost, and which you'd pick. Omit otherwise.}

<details>
<summary>Checked and fine</summary>

- **{Area — authz / blast radius / rollout / perf / migration}:** {what you verified and how — "traced every changed core hunk for a non-feature session: identical to main"}
- **Simpler?** {alternatives considered and why this approach wins}
</details>

<details>
<summary>Follow-ups (not for this PR)</summary>

1. {Item — ask for a ticket under the epic so it doesn't drop}
</details>

Rules:

cd $WORKTREE_DIR && gh pr comment $PR_NUMBER --body-file - <<'EOF'
<summary comment>
EOF

Step 8: Clean Up Worktree

After the review is posted, remove the worktree (this also removes any throwaway probe tests):

# The shell may still be inside the review worktree, where --show-toplevel would return the worktree
# itself; the first `worktree list` entry is always the main checkout.
REPO_ROOT=$(git worktree list --porcelain | head -1 | cut -d' ' -f2-)
WORKTREE_DIR="${REPO_ROOT}-pr-review-${PR_NUMBER}"

cd "$REPO_ROOT"
git -C "$REPO_ROOT" worktree remove "$WORKTREE_DIR" --force
git -C "$REPO_ROOT" worktree list

Step 9: Output Summary

Review posted on PR #{number}: {title}
  Verdict: {Approve | Revise | Redesign} — {one-line reason}
  - {N} before-merge items, {M} non-blocking, {K} follow-ups
  - {N} inline comments + 1 summary comment
  - Worktree cleaned up

PR URL: {url}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.