Skip to content

Commit 2983838

Browse files
authored
Merge pull request #137 from igerber/plan-review-on-pr
Add --pr flag to /review-plan for PR feedback coverage checking
2 parents a044737 + bab1f59 commit 2983838

1 file changed

Lines changed: 181 additions & 6 deletions

File tree

.claude/commands/review-plan.md

Lines changed: 181 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
---
22
description: Review a Claude Code plan file from a staff engineer perspective
3-
argument-hint: "[--updated] <path-to-plan-file>"
3+
argument-hint: "[--updated] [--pr <comment-url>] <path-to-plan-file>"
44
---
55

66
# Review Plan
77

8-
Review a Claude Code plan file from a staff engineer perspective and provide structured feedback across 8 dimensions.
8+
Review a Claude Code plan file from a staff engineer perspective and provide structured feedback across 8 dimensions. Optionally, when given a `--pr <comment-url>`, also verify the plan covers all feedback items from a specific PR review comment (Dimension 9).
99

1010
## Arguments
1111

1212
`$ARGUMENTS` may contain:
1313
- **Plan file path** (required): Path to the plan file, e.g., `~/.claude/plans/dreamy-coalescing-brook.md`
1414
- `--updated` (optional): Signal that the plan has been revised since a prior review. Forces a fresh full review and includes a delta assessment of what changed.
15+
- `--pr <comment-url>` (optional): URL of the specific PR comment whose feedback
16+
the plan addresses. Accepts GitHub comment URLs in any of these formats:
17+
- `https://github.com/owner/repo/pull/123#issuecomment-456`
18+
- `https://github.com/owner/repo/pull/123#discussion_r789`
19+
- `https://github.com/owner/repo/pull/123#pullrequestreview-012`
20+
Enables branch verification and PR feedback coverage checking (Dimension 9).
1521

1622
Parse `$ARGUMENTS` to extract:
1723
- **--updated**: Split `$ARGUMENTS` on whitespace and check if any token is exactly `--updated`. Remove that token to get the remaining text.
18-
- **Plan file path**: The remaining non-flag tokens after removing `--updated`, joined back together. The flag may appear before or after the path.
19-
- If no path remains after stripping the flag, use AskUserQuestion to request it:
24+
- **--pr**: Check if any token is exactly `--pr`. If found, take the next token as the comment URL and remove both tokens. If `--pr` is found with no following URL, use AskUserQuestion to request it:
25+
```
26+
What is the PR comment URL to check coverage against?
27+
28+
Supported formats:
29+
1. PR-level comment: https://github.com/owner/repo/pull/42#issuecomment-123456
30+
2. Inline review comment: https://github.com/owner/repo/pull/42#discussion_r789012
31+
3. Full PR review: https://github.com/owner/repo/pull/42#pullrequestreview-345678
32+
```
33+
- **Plan file path**: The remaining non-flag tokens after removing `--updated` and `--pr <url>`, joined back together. All flags (`--updated`, `--pr <url>`) are position-independent relative to the path and to each other.
34+
- If no path remains after stripping flags, use AskUserQuestion to request it:
2035
```
2136
Which plan file would you like me to review?
2237
@@ -30,6 +45,7 @@ Options:
3045
- **Advisory-only**: Provide feedback and recommendations. Do not implement fixes.
3146
- **No code changes**: Do not modify any source code, test files, or documentation.
3247
- Use the Read tool for files and the Glob/Grep tools for searching. Do not use Write, Edit, NotebookEdit, or any file-modifying Bash commands.
48+
- The `gh api` calls used with `--pr` are read-only API requests, consistent with the read-only constraint.
3349

3450
## Instructions
3551

@@ -66,9 +82,98 @@ Read the project's `CLAUDE.md` file to understand:
6682

6783
If the plan modifies estimator math, standard error formulas, inference logic, or edge-case handling, also read `docs/methodology/REGISTRY.md` to understand the academic foundations and reference implementations for the affected estimator(s).
6884

85+
### Step 2b: Parse Comment URL and Verify Branch (if `--pr`)
86+
87+
Only perform this step when `--pr <comment-url>` was provided. Otherwise skip to Step 3.
88+
89+
**Parse the URL:**
90+
- Strip query parameters from the URL before parsing: remove the query string (the `?...` portion) while preserving the `#` fragment. For example, `https://github.com/o/r/pull/1?notification_referrer_id=abc#issuecomment-123` becomes `https://github.com/o/r/pull/1#issuecomment-123`. If the fragment itself contains `?` (e.g., `#discussion_r123?foo=bar`), strip the `?` and everything after it from the fragment before pattern matching, since GitHub fragments never contain `?` as meaningful data.
91+
- Only `github.com` URLs are supported. If the URL host is not `github.com`, report an error and stop.
92+
- Extract `owner`, `repo`, `pr_number` from the URL path. The `pr_number` is always the path segment immediately after `/pull/`.
93+
- Extract comment type and ID from the fragment:
94+
95+
| Fragment | Type | `gh api` endpoint |
96+
|---|---|---|
97+
| `#issuecomment-{id}` | Issue comment | `repos/{owner}/{repo}/issues/comments/{id}` |
98+
| `#discussion_r{id}` | Inline review comment | `repos/{owner}/{repo}/pulls/comments/{id}` |
99+
| `#pullrequestreview-{id}` | PR review | `repos/{owner}/{repo}/pulls/{pr_number}/reviews/{id}` |
100+
101+
If the URL doesn't match any fragment pattern (including bare PR URLs without a fragment), report:
102+
```
103+
Error: Unrecognized PR comment URL format. Expected a GitHub PR comment URL like:
104+
https://github.com/owner/repo/pull/123#issuecomment-456
105+
The URL must point to a specific comment, not a PR page.
106+
```
107+
108+
**Verify `gh` CLI availability:**
109+
110+
Run `gh auth status 2>/dev/null` (suppress output on success). If it fails, report a hard error:
111+
```
112+
Error: The --pr flag requires the GitHub CLI (gh) to be installed and authenticated.
113+
Run `gh auth login` to authenticate, then retry.
114+
```
115+
116+
**Verify branch state:**
117+
118+
```bash
119+
gh pr view <number> --repo <owner>/<repo> --json headRefName,baseRefName,title --jq '.'
120+
```
121+
122+
Compare `headRefName` against `git branch --show-current`:
123+
- **Match**: Note "Branch verified" in output.
124+
- **Mismatch**: Emit a warning in the output and note under Dimension 2 (Codebase Correctness) that code references may be inaccurate. Recommend the user checkout the PR branch first (`git checkout <headRefName>`), but do not block the review.
125+
126+
### Step 2c: Fetch the Specific Comment (if `--pr`)
127+
128+
Only perform this step when `--pr` was provided. Otherwise skip to Step 3.
129+
130+
Fetch the comment using the `gh api` endpoint from the table in Step 2b.
131+
132+
**For `pullrequestreview-` URLs**, fetch BOTH the review body AND its inline comments:
133+
```bash
134+
# Review body
135+
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews/{id} --jq '{body: .body, user: .user.login, state: .state}'
136+
137+
# All inline comments belonging to this review
138+
gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews/{id}/comments --paginate --jq '.[] | {body: .body, path: .path, line: .line, diff_hunk: .diff_hunk}'
139+
```
140+
141+
**For other comment types**, fetch the single comment:
142+
143+
**Issue comment:**
144+
```bash
145+
gh api repos/{owner}/{repo}/issues/comments/{id} --jq '{body: .body, user: .user.login, created_at: .created_at}'
146+
```
147+
148+
**Inline review comment:**
149+
```bash
150+
gh api repos/{owner}/{repo}/pulls/comments/{id} --jq '{body: .body, user: .user.login, path: .path, line: .line, diff_hunk: .diff_hunk}'
151+
```
152+
153+
**Error handling:**
154+
- **404**: `Error: Comment not found at <url>. It may have been deleted or the URL may be incorrect.`
155+
- **403 / other API errors**: `Error: GitHub API returned <status>. You may not have access to this repository, or you may be rate-limited. Check 'gh auth status' and try again.`
156+
- **Empty comment body** (and no inline comments for review types): report and skip Dimension 9:
157+
```
158+
Note: No feedback text found in the comment at <url>.
159+
Skipping PR Feedback Coverage (Dimension 9). Reviewing plan without PR context.
160+
```
161+
162+
The response includes: `body` (comment text), `user.login` (author), `created_at`, and for inline comments: `path` (file), `line` (line number in the file — use `line`, not `position` which is the diff offset, and not `original_line` which is the base branch line), `diff_hunk` (surrounding diff context).
163+
164+
**Extract discrete feedback items** from the comment body:
165+
- For AI review comments (structured markdown with P0/P1/P2/P3 or Critical/Medium/Minor sections): parse each severity section and extract individual items with their labeled severity
166+
- For human comments with numbered/bulleted lists: each list item is one feedback item
167+
- For human comments that are a single paragraph or conversational: the entire comment is one feedback item
168+
- For inline review comments: each comment is one item, with `path` and `line` as its file/line reference
169+
- **Default severity**: when a feedback item has no severity label, treat it as Medium
170+
- Process all feedback items regardless of count
171+
172+
Each feedback item tracks: severity (labeled or default Medium), description, file path (if available), and line reference (if available).
173+
69174
### Step 3: Read Referenced Files
70175

71-
Identify all files the plan references (file paths, module names, class names). Then read them to validate the plan's assumptions:
176+
Identify all files the plan references (file paths, module names, class names). When `--pr` was provided, also include files referenced in the feedback comment — inline comment `path` fields and file paths mentioned in the comment body (e.g., `path/to/file.py:L123`). Then read them to validate the plan's assumptions:
72177

73178
**Priority order for reading files:**
74179
1. **Files the plan proposes to modify** — read ALL of these first
@@ -171,9 +276,25 @@ Plan-specific failure modes that wouldn't show up in a code review:
171276
- For bug fixes: does the plan fix all pattern instances and test all of them?
172277
- Are there missing test scenarios? (Parameter interactions, error paths, boundary conditions)
173278

279+
#### Dimension 9: PR Feedback Coverage (only if `--pr` provided with non-empty comment)
280+
281+
Only evaluate this dimension when `--pr` was provided and a non-empty comment was fetched in Step 2c. For each feedback item extracted in Step 2c, assess:
282+
283+
- **Addressed**: Plan explicitly mentions the issue AND proposes a concrete fix
284+
- **Partially addressed**: Plan touches the area but doesn't fully resolve the feedback
285+
- **Not addressed**: Plan makes no mention of this feedback item
286+
- **Dismissed with justification**: Plan acknowledges the feedback but explains why it won't be acted on (acceptable for Low/P3; flag for Critical/P0)
287+
288+
Use judgment, not just substring matching — the plan may use different words to describe the same fix.
289+
290+
**Verdict impact:**
291+
- Unaddressed P0/P1/Critical items -> automatic "Needs revision"
292+
- Unaddressed P2/Medium items count as Medium issues
293+
- Unaddressed P3/Low items count as Low issues
294+
174295
### Step 5: Present Structured Feedback
175296

176-
Present the review in the following format. Do NOT skip any section — if a section has no findings, write "None." for that section. The Delta Assessment section is only included when the `--updated` flag was provided (see Step 1b).
297+
Present the review in the following format. Do NOT skip any section — if a section has no findings, write "None." for that section. The Delta Assessment section is only included when the `--updated` flag was provided (see Step 1b). The PR Context and PR Feedback Coverage sections are only included when `--pr` was provided with a non-empty comment.
177298

178299
```
179300
## Overall Assessment
@@ -182,6 +303,17 @@ Present the review in the following format. Do NOT skip any section — if a sec
182303
183304
---
184305
306+
## PR Context (only include if `--pr` was provided with non-empty comment)
307+
308+
**PR**: #<number> - <title> (<owner>/<repo>)
309+
**Branch**: <headRefName> -> <baseRefName>
310+
**Comment**: <comment-url>
311+
**Comment author**: <user.login>
312+
**Feedback items extracted**: N
313+
**Branch match**: Yes / No (warning: recommend `git checkout <headRefName>`)
314+
315+
---
316+
185317
## Issues
186318
187319
### CRITICAL
@@ -203,6 +335,29 @@ Cross-reference against the relevant CLAUDE.md checklists. List which checklist
203335
204336
---
205337
338+
## PR Feedback Coverage (only include if `--pr` was provided with non-empty comment)
339+
340+
### Addressed
341+
- [severity] <description> -- Plan step: <reference to plan section>
342+
343+
### Partially Addressed
344+
- [severity] <description> -- Gap: <what's missing>
345+
346+
### Not Addressed
347+
- [severity] <description>
348+
349+
### Dismissed
350+
- [severity] <description> -- Plan's reason: "<quote>"
351+
352+
| Status | Count |
353+
|--------|-------|
354+
| Addressed | N |
355+
| Partially addressed | N |
356+
| Not addressed | N |
357+
| Dismissed | N |
358+
359+
---
360+
206361
## Questions for the Author
207362
208363
[Ambiguities or missing information that should be clarified before implementation begins. Phrase as specific questions.]
@@ -220,6 +375,13 @@ Cross-reference against the relevant CLAUDE.md checklists. List which checklist
220375
### New Issues
221376
[List any new issues introduced by the revisions, or "None."]
222377
378+
### PR Feedback Coverage Delta (only include if both `--updated` and `--pr` were provided)
379+
380+
The `--pr` URL must be the same across the initial review and the `--updated` re-review — this compares coverage of the same feedback comment. If the prior review's PR comment URL is no longer available in conversation context (e.g., context compressed), note: "PR coverage delta unavailable — prior PR context not found."
381+
382+
- **Newly addressed**: [list of feedback items now covered that were previously not addressed or partially addressed]
383+
- **Still not addressed**: [list of feedback items still missing]
384+
223385
---
224386
225387
## Summary
@@ -230,6 +392,7 @@ Cross-reference against the relevant CLAUDE.md checklists. List which checklist
230392
| Medium | [count] |
231393
| Low | [count] |
232394
| Checklist gaps | [count] |
395+
| PR feedback gaps | [count of Not Addressed + Partially Addressed] (only if `--pr`) |
233396
| Questions | [count] |
234397
235398
**Verdict**: [Ready / Ready with minor fixes / Needs revision]
@@ -247,3 +410,15 @@ Cross-reference against the relevant CLAUDE.md checklists. List which checklist
247410
- For best results, run this before implementing a plan to catch issues early
248411
- The 8 dimensions are tuned for plan-specific failure modes, not generic code review
249412
- Use `--updated` when re-reviewing a revised plan to get a delta assessment of what changed since the prior review
413+
- Use `--pr <comment-url>` when the plan addresses a specific PR review comment.
414+
This fetches the comment, extracts feedback items, and checks that the plan
415+
covers each one. Pairs naturally with `/read-feedback-revise` which creates the plan.
416+
- The `--pr` flag requires the `gh` CLI to be installed and authenticated.
417+
- For best results, run this while on the PR branch so file contents and line
418+
numbers match what reviewers commented on.
419+
- The comment URL can be copied from the GitHub web UI by right-clicking the
420+
timestamp on any PR comment and selecting "Copy link".
421+
- For `pullrequestreview-` URLs, both the review body and its inline comments
422+
are fetched (matching `/read-feedback-revise` behavior).
423+
- Verification of these changes should be done manually before merging the PR
424+
that adds this feature. See the Verification section of this plan.

0 commit comments

Comments
 (0)