Gh PR Checks Plan Fix
Overview
Use gh to inspect PRs for:
- Failing CI checks (GitHub Actions)
- Merge conflicts
- Update Branch requirements (base branch advanced)
- Reviewer comments (review summaries, inline comments, issue comments)
- Change Requests from reviewers
- Unresolved review threads
Then propose a fix plan, implement after explicit approval, reply to every reviewer comment (with action taken or reason for not addressing), resolve all threads, and notify reviewers.
- Depends on the
plan skill for drafting and approving the fix plan.
Prereq: ensure gh is authenticated (for example, run gh auth login once), then run gh auth status with escalated permissions (include workflow/repo scopes) so gh commands succeed.
Comment Response Policy
No reviewer comment may be left unanswered.
- Every unresolved review thread MUST receive a reply before being resolved.
- If the feedback was addressed: reply with what was done (e.g., "Fixed: refactored as suggested.").
- If the feedback was intentionally not addressed: reply with the reason (e.g., "Not addressed: this is intentional because the API contract requires this format.").
- The
--reply-and-resolve argument enforces this by requiring a reply entry for every unresolved thread and rejecting empty bodies.
Diagnosis Report Anti-Patterns
Prohibited Language
| Prohibited |
Required Alternative |
| "We should look into..." |
"Edit path/file.ts:42 to..." |
| "There seem to be some issues" |
"3 blocking items detected" |
| "This might be causing..." |
"Root cause: <error from log>" |
| "Consider fixing..." / "It looks like..." |
"Action: Fix <what> in <where>" |
| "Various CI checks are failing" |
"2 CI checks failing: build, lint" |
| "Some reviewers have concerns" |
"@reviewer1 requested: <quote>" |
| "I'll try to fix this" |
"Action: <specific fix>" |
Structural Prohibitions
- Prose paragraphs for reporting — use B1/I1 item format exclusively.
- Omitting the Evidence field in any BLOCKING item.
- Combining multiple independent problems into a single item.
- Omitting file paths or line numbers when the script output contains them.
Issue/PR Comment Formatting (must follow)
- Final comment text must not contain escaped newline literals such as
\n.
- Use real line breaks in comment bodies. Do not rely on escaped sequences for formatting.
- Before posting (
--add-comment or manual gh issue/pr comment), verify the final body does not accidentally include escaped control sequences (\n, \t).
- If a raw escape sequence must be shown for explanation, include it only inside a fenced code block and clarify it is intentional.
Issue Progress Comment Template (required for issue-based work)
When work is tracked in GitHub Issues, progress updates must use this template:
Progress
- ...
Done
- ...
Next
- ...
- Post updates at least when starting work, after meaningful progress, and when blocked/unblocked.
- In
Next, explicitly state blockers or the immediate next action.
Inputs
repo: path inside the repo (default .)
pr: PR number or URL (optional; defaults to current branch PR)
mode: inspection mode (checks, conflicts, reviews, all)
required-only: limit CI checks to required checks only (uses gh pr checks --required)
gh authentication for the repo host
Quick start
# Inspect all (CI, conflicts, reviews) - default mode
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>"
# CI checks only
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode checks
# Conflicts only
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode conflicts
# Reviews only (Change Requests + Unresolved Threads)
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode reviews
# JSON output
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --json
# Required checks only (if gh supports --required)
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode checks --required-only
# Reply to all unresolved threads and resolve them
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --reply-and-resolve '[
{"threadId":"PRRT_xxx123","body":"Fixed: refactored the method as suggested."},
{"threadId":"PRRT_xxx456","body":"Not addressed: this is intentional because the API requires this format."}
]'
# Add a comment to notify reviewers
python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --add-comment "Fixed all issues. Please re-review."
Workflow
Verify gh authentication.
- Run
gh auth status in the repo with escalated scopes (workflow/repo).
- If unauthenticated, ask the user to log in before proceeding.
Resolve the PR.
- Prefer the current branch PR:
gh pr view --json number,url.
- If the user provides a PR number or URL, use that directly.
Inspect based on mode:
Conflicts Mode (--mode conflicts):
- Check
mergeable and mergeStateStatus fields.
- If
CONFLICTING or DIRTY, report conflict details.
- If
BEHIND, report that the base branch advanced and an Update Branch is required.
- Suggest resolution steps: fetch base branch, merge/rebase, resolve conflicts.
Reviews Mode (--mode reviews):
- Fetch reviews with
CHANGES_REQUESTED state.
- Fetch unresolved review threads using GraphQL.
- Fetch ALL reviewer comments (review summaries, inline review comments, issue comments) without truncation.
- Display reviewer, comment body (full text), file path, and line number.
- Decide if reviewer feedback requires action (any change request, unresolved thread, or reviewer comment).
Checks Mode (--mode checks):
- Run bundled script to inspect failing CI checks.
- Add
--required-only to limit output to required checks when supported.
- Fetch GitHub Actions logs and extract failure snippets.
- For external checks (Buildkite, etc.), report URL only.
All Mode (--mode all):
- Run all inspections above.
Produce Diagnosis Report (mandatory format).
Output MUST use this exact structure:
## Diagnosis Report: PR #<number>
**Merge Verdict: BLOCKED | CLEAR**
Blocking items: <N>
---
### BLOCKING
#### B1. [CATEGORY] <1-line title>
- **What:** Factual statement (no speculation)
- **Where:** file_path:line_number / check name / branch ref
- **Evidence:** Verbatim quote from script output
- **Action:** Specific fix (file path, command, or code change — at least one required)
- **Auto-fix:** Yes | No (needs confirmation)
#### B2. [CATEGORY] <1-line title>
...
---
### INFORMATIONAL
#### I1. [CATEGORY] <1-line title>
- **What / Note**
---
**Summary:** <N> blocking items to fix, <M> informational items noted.
Classification rules:
- BLOCKING: CONFLICTING/DIRTY merge state, BEHIND, CI failure/cancelled/timed_out/action_required, CHANGES_REQUESTED, unresolved review threads
- INFORMATIONAL: Comments without change requests, pending CI, outdated review threads
Category labels: CONFLICT, BRANCH-BEHIND, CI-FAILURE, CHANGE-REQUEST, UNRESOLVED-THREAD, REVIEW-COMMENT
Auto-fix judgment:
- Auto-fix: Yes — CI-FAILURE code fixes, reviewer instructions that the LLM can address with high confidence
- Auto-fix: No (needs confirmation) — CONFLICT resolution (merge/rebase), low-confidence reviewer instructions, changes requiring design decisions
Each CHANGE-REQUEST and each UNRESOLVED-THREAD is a separate B-item. Do not combine multiple threads or requests into one item.
Decide execution path.
- If ALL blocking items have
Auto-fix: Yes → display Diagnosis Report, skip plan, proceed directly to step 6.
- If ANY blocking item has
Auto-fix: No → create a plan referencing B-item IDs (e.g., "Fix B1: ...", "Fix B3: ...") and request user approval for Auto-fix: No items before proceeding.
Implement fixes.
- Apply the approved fixes, summarize diffs/tests.
- After applying fixes, commit changes and push to the PR branch.
- Verify push succeeded before proceeding to step 7.
- After implementing fixes, proceed to step 7 to reply and resolve ALL threads.
- For BRANCH-BEHIND items, see Fix Strategies: BRANCH-BEHIND.
- For CONFLICT items, see Fix Strategies: CONFLICT.
Reply to ALL reviewer comments and resolve threads (mandatory).
- CRITICAL: Every unresolved review thread MUST receive a reply before resolution. No thread may be silently resolved or left unaddressed.
- For each unresolved thread, prepare a reply:
- If addressed: describe what was done (e.g., "Fixed: refactored the method as suggested in commit abc1234.")
- If intentionally not addressed: explain the reason (e.g., "Not addressed: this is by design because ...")
- Use
--reply-and-resolve with a JSON array covering ALL unresolved threads.
- The script validates completeness and rejects the operation if any thread is missing a reply.
- Requires
Repository Permissions > Contents: Read and Write.
- Resolve threads at this point (after code fix is pushed). Do not wait for CI completion to resolve threads.
Notify reviewers (mandatory).
- With
--add-comment "message", post a comment to the PR.
- Include a summary of what was fixed (list each B-item and the action taken).
- This step is not optional — always notify reviewers after fixes are applied.
Verify fix (mandatory — do not skip).
- Re-run the inspection script with
--mode all (regardless of initial mode).
- Exit code 0 → all resolved → report success to user.
- Exit code 1 → issues remain → go back to step 4 with new output.
- No iteration limit. Continue until all issues are resolved.
- CI still pending/queued → poll at 30-second intervals (no timeout) until ALL checks complete.
- Wait for ALL CI checks to complete before starting fixes (pushing resets pending checks).
- After fix push, re-enter polling to wait for new CI run to complete.
Loop Safety Guard
- If the same CI check name (e.g.,
build) fails 3 consecutive iterations:
- Report to user: which check, what was tried in each iteration, what keeps failing.
- Ask user to choose: continue / abort / change approach.
- Only proceed after explicit user decision.
- This prevents oscillation loops where fix A breaks B and fix B breaks A.
- Different checks failing in different iterations do NOT trigger the guard (e.g.,
build fails → fixed → lint fails is normal progression, not oscillation).
Fix Strategies
BRANCH-BEHIND
- Default strategy:
git fetch origin <base> && git merge origin/<base>
- If merge results in conflicts, switch to CONFLICT handling below.
CONFLICT
- LLM attempts to resolve conflicts after user confirmation.
- Present conflict summary (affected files, conflict markers) and proposed resolution to the user.
- Execute resolution only after user approves.
Bundled Resources
scripts/inspect_pr_checks.py
Comprehensive PR inspection tool. Exits non-zero when issues remain.
Arguments:
| Argument |
Default |
Description |
--repo |
. |
Path inside the target Git repository |
--pr |
(current) |
PR number or URL |
--mode |
all |
Inspection mode: checks, conflicts, reviews, all |
--max-lines |
160 |
Max lines for log snippets |
--context |
30 |
Context lines around failure markers |
--required-only |
false |
Limit CI checks to required checks only |
--json |
false |
Emit JSON output |
--reply-and-resolve |
(none) |
JSON array of {threadId, body} to reply and resolve ALL threads |
--add-comment |
(none) |
Add a comment to the PR |
Exit codes:
0: No issues found
1: Issues detected or error occurred
--reply-and-resolve JSON format:
[
{"threadId": "PRRT_xxx123", "body": "Fixed: refactored the method as suggested."},
{"threadId": "PRRT_xxx456", "body": "Not addressed: this is intentional because ..."}
]
Validation rules:
- Every currently unresolved thread MUST have a corresponding entry.
- Every entry MUST have a non-empty
body.
- If any unresolved thread is missing, the script prints the missing thread details and exits with error.
Features
Conflict Detection
Detects merge conflicts via mergeable and mergeStateStatus fields.
CONFLICTING / DIRTY: Conflict detected
BEHIND: Base branch advanced; Update Branch required
MERGEABLE / CLEAN: No conflicts
Change Request Handling
Fetches reviews with state == "CHANGES_REQUESTED" and displays:
- Reviewer name
- Review body
- Submission timestamp
Reviewer Comments
Fetches ALL reviewer feedback without truncation:
- Review summaries with full comment bodies
- Inline review comments (file/line) with full comment bodies
- PR issue comments with full comment bodies
- Marks review action required if any reviewer feedback exists
Unresolved Review Threads
Uses GraphQL to fetch threads where isResolved == false:
- File path and line number
- Thread ID (for reply and resolution)
- Comment author and full body
- Outdated status
Reply and Resolve
Use --reply-and-resolve to reply to every unresolved thread and resolve them.
- Uses GraphQL
addPullRequestReviewThreadReply to post a reply.
- Uses GraphQL
resolveReviewThread to mark the thread as resolved.
- Validates that ALL unresolved threads are covered (no thread left behind).
- Rejects empty reply bodies.
Required permissions:
- Fine-grained PAT:
Pull requests + Contents: Read and Write
- Classic PAT:
repo scope
Reviewer Notification
Use --add-comment "message" to post a summary comment to the PR after fixes.
Output Examples
Diagnosis Report
## Diagnosis Report: PR #123
**Merge Verdict: BLOCKED**
Blocking items: 3
---
### BLOCKING
#### B1. [CI-FAILURE] TypeScript build fails
- **What:** `build` check failed with compilation error
- **Where:** `src/utils/parser.ts:42` / check: `build`
- **Evidence:** `error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.`
- **Action:** Edit `src/utils/parser.ts:42` — change `parseInt(value)` to pass the correct type
- **Auto-fix:** Yes
#### B2. [CHANGE-REQUEST] @reviewer1 requests error handling
- **What:** Reviewer requested try-catch around API call
- **Where:** `src/api/client.ts:88`
- **Evidence:** "@reviewer1: Please wrap this fetch call in a try-catch block to handle network errors gracefully."
- **Action:** Add try-catch in `src/api/client.ts:88` around the `fetch()` call
- **Auto-fix:** Yes
#### B3. [CONFLICT] Merge conflict with main
- **What:** 2 files have merge conflicts
- **Where:** `src/config.ts`, `src/index.ts` / branch: `main`
- **Evidence:** `Mergeable: CONFLICTING, Merge State: DIRTY`
- **Action:** Merge `origin/main` and resolve conflicts in listed files
- **Auto-fix:** No (needs confirmation)
---
### INFORMATIONAL
#### I1. [REVIEW-COMMENT] Code style suggestion
- **What / Note:** @reviewer2 suggested extracting a helper function — non-blocking style preference
---
**Summary:** 3 blocking items to fix, 1 informational item noted.
Text Output
PR #123: Comprehensive Check Results
============================================================
MERGE STATUS
------------------------------------------------------------
Mergeable: CONFLICTING
Merge State: DIRTY
Base: main <- Head: feature/my-branch
Action Required: Resolve conflicts before merging
CHANGE REQUESTS
------------------------------------------------------------
From @reviewer1 (2025-01-15):
"Please fix these issues..."
UNRESOLVED REVIEW THREADS
------------------------------------------------------------
[1] src/main.ts:42
Thread ID: PRRT_xxx123
@reviewer1: This needs refactoring because the current
implementation violates the single responsibility principle.
[2] src/utils.ts:15
Thread ID: PRRT_xxx456
@reviewer2: Consider using a more descriptive variable name here.
CI FAILURES
------------------------------------------------------------
Check: build
Details: https://github.com/...
Failure snippet:
Error: TypeScript compilation failed
...
============================================================
Reply and Resolve Output
OK: PRRT_xxx123 (src/main.ts:42)
OK: PRRT_xxx456 (src/utils.ts:15)
Result: 2 resolved, 0 failed, 2 total
JSON Output
{
"pr": "123",
"conflicts": {
"hasConflicts": true,
"mergeable": "CONFLICTING",
"mergeStateStatus": "DIRTY",
"baseRefName": "main",
"headRefName": "feature/my-branch"
},
"changeRequests": [
{
"id": 123456,
"reviewer": "reviewer1",
"body": "Please fix these issues...",
"submittedAt": "2025-01-15T12:00:00Z"
}
],
"unresolvedThreads": [
{
"id": "PRRT_xxx123",
"path": "src/main.ts",
"line": 42,
"comments": [
{"author": "reviewer1", "body": "This needs refactoring because..."}
]
}
],
"ciFailures": [
{
"name": "build",
"status": "ok",
"logSnippet": "..."
}
]
}
1---2name: gwt-fix-pr3description: Inspect GitHub PR for CI failures, merge conflicts, update-branch requirements, reviewer comments, change requests, and unresolved review threads. Create fix plans and implement after user approval. Reply to ALL reviewer comments with action taken or reason for not addressing, then resolve threads. Notify reviewers after fixes.4---5
6# Gh PR Checks Plan Fix
7
8## Overview
9
10Use gh to inspect PRs for:
11
12- Failing CI checks (GitHub Actions)
13- Merge conflicts
14- Update Branch requirements (base branch advanced)
15- Reviewer comments (review summaries, inline comments, issue comments)
16- Change Requests from reviewers
17- Unresolved review threads
18
19Then propose a fix plan, implement after explicit approval, **reply to every reviewer comment** (with action taken or reason for not addressing), resolve all threads, and notify reviewers.
20
21- Depends on the `plan` skill for drafting and approving the fix plan.
22
23Prereq: ensure `gh` is authenticated (for example, run `gh auth login` once), then run `gh auth status` with escalated permissions (include workflow/repo scopes) so `gh` commands succeed.
24
25## Comment Response Policy
26
27> **No reviewer comment may be left unanswered.**
28
29- Every unresolved review thread MUST receive a reply before being resolved.
30- If the feedback was addressed: reply with what was done (e.g., "Fixed: refactored as suggested.").
31- If the feedback was intentionally not addressed: reply with the reason (e.g., "Not addressed: this is intentional because the API contract requires this format.").
32- The `--reply-and-resolve` argument enforces this by requiring a reply entry for every unresolved thread and rejecting empty bodies.
33
34## Diagnosis Report Anti-Patterns
35
36### Prohibited Language
37
38| Prohibited | Required Alternative |
39|---|---|
40| "We should look into..." | "Edit `path/file.ts:42` to..." |
41| "There seem to be some issues" | "3 blocking items detected" |
42| "This might be causing..." | "Root cause: `<error from log>`" |
43| "Consider fixing..." / "It looks like..." | "Action: Fix `<what>` in `<where>`" |
44| "Various CI checks are failing" | "2 CI checks failing: `build`, `lint`" |
45| "Some reviewers have concerns" | "@reviewer1 requested: `<quote>`" |
46| "I'll try to fix this" | "Action: \<specific fix\>" |
47
48### Structural Prohibitions
49
50- Prose paragraphs for reporting — use B1/I1 item format exclusively.
51- Omitting the Evidence field in any BLOCKING item.
52- Combining multiple independent problems into a single item.
53- Omitting file paths or line numbers when the script output contains them.
54
55## Issue/PR Comment Formatting (must follow)
56
57- Final comment text must not contain escaped newline literals such as `\n`.
58- Use real line breaks in comment bodies. Do not rely on escaped sequences for formatting.
59- Before posting (`--add-comment` or manual `gh issue/pr comment`), verify the final body does not accidentally include escaped control sequences (`\n`, `\t`).
60- If a raw escape sequence must be shown for explanation, include it only inside a fenced code block and clarify it is intentional.
61
62## Issue Progress Comment Template (required for issue-based work)
63
64When work is tracked in GitHub Issues, progress updates must use this template:
65
66```markdown
67Progress
68- ...
69
70Done
71- ...
72
73Next
74- ...
75```
76
77- Post updates at least when starting work, after meaningful progress, and when blocked/unblocked.
78- In `Next`, explicitly state blockers or the immediate next action.
79
80## Inputs
81
82- `repo`: path inside the repo (default `.`)
83- `pr`: PR number or URL (optional; defaults to current branch PR)
84- `mode`: inspection mode (`checks`, `conflicts`, `reviews`, `all`)
85- `required-only`: limit CI checks to required checks only (uses `gh pr checks --required`)
86- `gh` authentication for the repo host
87
88## Quick start
89
90```bash
91# Inspect all (CI, conflicts, reviews) - default mode
92python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>"
93
94# CI checks only
95python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode checks
96
97# Conflicts only
98python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode conflicts
99
100# Reviews only (Change Requests + Unresolved Threads)
101python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode reviews
102
103# JSON output
104python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --json
105
106# Required checks only (if gh supports --required)
107python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --mode checks --required-only
108
109# Reply to all unresolved threads and resolve them
110python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --reply-and-resolve '[
111 {"threadId":"PRRT_xxx123","body":"Fixed: refactored the method as suggested."},
112 {"threadId":"PRRT_xxx456","body":"Not addressed: this is intentional because the API requires this format."}
113]'
114
115# Add a comment to notify reviewers
116python3 ".codex/skills/gwt-fix-pr/scripts/inspect_pr_checks.py" --repo "." --pr "<number>" --add-comment "Fixed all issues. Please re-review."
117```
118
119## Workflow
120
1211. **Verify gh authentication.**
122 - Run `gh auth status` in the repo with escalated scopes (workflow/repo).
123 - If unauthenticated, ask the user to log in before proceeding.
124
1252. **Resolve the PR.**
126 - Prefer the current branch PR: `gh pr view --json number,url`.
127 - If the user provides a PR number or URL, use that directly.
128
1293. **Inspect based on mode:**
130
131 **Conflicts Mode (`--mode conflicts`):**
132 - Check `mergeable` and `mergeStateStatus` fields.
133 - If `CONFLICTING` or `DIRTY`, report conflict details.
134 - If `BEHIND`, report that the base branch advanced and an Update Branch is required.
135 - Suggest resolution steps: fetch base branch, merge/rebase, resolve conflicts.
136
137 **Reviews Mode (`--mode reviews`):**
138 - Fetch reviews with `CHANGES_REQUESTED` state.
139 - Fetch unresolved review threads using GraphQL.
140 - Fetch ALL reviewer comments (review summaries, inline review comments, issue comments) without truncation.
141 - Display reviewer, comment body (full text), file path, and line number.
142 - Decide if reviewer feedback requires action (any change request, unresolved thread, or reviewer comment).
143
144 **Checks Mode (`--mode checks`):**
145 - Run bundled script to inspect failing CI checks.
146 - Add `--required-only` to limit output to required checks when supported.
147 - Fetch GitHub Actions logs and extract failure snippets.
148 - For external checks (Buildkite, etc.), report URL only.
149
150 **All Mode (`--mode all`):**
151 - Run all inspections above.
152
1534. **Produce Diagnosis Report (mandatory format).**
154
155 Output MUST use this exact structure:
156
157 ```text
158 ## Diagnosis Report: PR #<number>
159
160 **Merge Verdict: BLOCKED | CLEAR**
161 Blocking items: <N>
162
163 ---
164
165 ### BLOCKING
166
167 #### B1. [CATEGORY] <1-line title>
168 - **What:** Factual statement (no speculation)
169 - **Where:** file_path:line_number / check name / branch ref
170 - **Evidence:** Verbatim quote from script output
171 - **Action:** Specific fix (file path, command, or code change — at least one required)
172 - **Auto-fix:** Yes | No (needs confirmation)
173
174 #### B2. [CATEGORY] <1-line title>
175 ...
176
177 ---
178
179 ### INFORMATIONAL
180 #### I1. [CATEGORY] <1-line title>
181 - **What / Note**
182
183 ---
184
185 **Summary:** <N> blocking items to fix, <M> informational items noted.
186 ```
187
188 **Classification rules:**
189
190 - **BLOCKING:** CONFLICTING/DIRTY merge state, BEHIND, CI failure/cancelled/timed\_out/action\_required, CHANGES\_REQUESTED, unresolved review threads
191 - **INFORMATIONAL:** Comments without change requests, pending CI, outdated review threads
192
193 **Category labels:** `CONFLICT`, `BRANCH-BEHIND`, `CI-FAILURE`, `CHANGE-REQUEST`, `UNRESOLVED-THREAD`, `REVIEW-COMMENT`
194
195 **Auto-fix judgment:**
196
197 - **Auto-fix: Yes** — CI-FAILURE code fixes, reviewer instructions that the LLM can address with high confidence
198 - **Auto-fix: No (needs confirmation)** — CONFLICT resolution (merge/rebase), low-confidence reviewer instructions, changes requiring design decisions
199
200 **Each CHANGE-REQUEST and each UNRESOLVED-THREAD is a separate B-item.** Do not combine multiple threads or requests into one item.
201
2025. **Decide execution path.**
203 - If ALL blocking items have `Auto-fix: Yes` → display Diagnosis Report, skip plan, proceed directly to step 6.
204 - If ANY blocking item has `Auto-fix: No` → create a plan referencing B-item IDs (e.g., "Fix B1: ...", "Fix B3: ...") and request user approval for `Auto-fix: No` items before proceeding.
205
2066. **Implement fixes.**
207 - Apply the approved fixes, summarize diffs/tests.
208 - After applying fixes, commit changes and push to the PR branch.
209 - Verify push succeeded before proceeding to step 7.
210 - **After implementing fixes, proceed to step 7 to reply and resolve ALL threads.**
211 - For BRANCH-BEHIND items, see [Fix Strategies: BRANCH-BEHIND](#branch-behind).
212 - For CONFLICT items, see [Fix Strategies: CONFLICT](#conflict).
213
2147. **Reply to ALL reviewer comments and resolve threads (mandatory).**
215 - **CRITICAL:** Every unresolved review thread MUST receive a reply before resolution. No thread may be silently resolved or left unaddressed.
216 - For each unresolved thread, prepare a reply:
217 - If addressed: describe what was done (e.g., "Fixed: refactored the method as suggested in commit abc1234.")
218 - If intentionally not addressed: explain the reason (e.g., "Not addressed: this is by design because ...")
219 - Use `--reply-and-resolve` with a JSON array covering ALL unresolved threads.
220 - The script validates completeness and rejects the operation if any thread is missing a reply.
221 - Requires `Repository Permissions > Contents: Read and Write`.
222 - Resolve threads at this point (after code fix is pushed). Do not wait for CI completion to resolve threads.
223
2248. **Notify reviewers (mandatory).**
225 - With `--add-comment "message"`, post a comment to the PR.
226 - Include a summary of what was fixed (list each B-item and the action taken).
227 - This step is not optional — always notify reviewers after fixes are applied.
228
2299. **Verify fix (mandatory — do not skip).**
230 - Re-run the inspection script with `--mode all` (regardless of initial mode).
231 - Exit code 0 → all resolved → report success to user.
232 - Exit code 1 → issues remain → go back to step 4 with new output.
233 - No iteration limit. Continue until all issues are resolved.
234 - CI still pending/queued → poll at 30-second intervals (no timeout) until ALL checks complete.
235 - Wait for ALL CI checks to complete before starting fixes (pushing resets pending checks).
236 - After fix push, re-enter polling to wait for new CI run to complete.
237
238## Loop Safety Guard
239
240- If the **same CI check name** (e.g., `build`) fails **3 consecutive iterations**:
241 1. Report to user: which check, what was tried in each iteration, what keeps failing.
242 2. Ask user to choose: **continue** / **abort** / **change approach**.
243 3. Only proceed after explicit user decision.
244- This prevents oscillation loops where fix A breaks B and fix B breaks A.
245- Different checks failing in different iterations do NOT trigger the guard (e.g., `build` fails → fixed → `lint` fails is normal progression, not oscillation).
246
247## Fix Strategies
248
249### BRANCH-BEHIND
250
251- Default strategy: `git fetch origin <base> && git merge origin/<base>`
252- If merge results in conflicts, switch to CONFLICT handling below.
253
254### CONFLICT
255
256- LLM attempts to resolve conflicts after user confirmation.
257- Present conflict summary (affected files, conflict markers) and proposed resolution to the user.
258- Execute resolution only after user approves.
259
260## Bundled Resources
261
262### scripts/inspect_pr_checks.py
263
264Comprehensive PR inspection tool. Exits non-zero when issues remain.
265
266**Arguments:**
267
268| Argument | Default | Description |
269|----------|---------|-------------|
270| `--repo` | `.` | Path inside the target Git repository |
271| `--pr` | (current) | PR number or URL |
272| `--mode` | `all` | Inspection mode: `checks`, `conflicts`, `reviews`, `all` |
273| `--max-lines` | 160 | Max lines for log snippets |
274| `--context` | 30 | Context lines around failure markers |
275| `--required-only` | false | Limit CI checks to required checks only |
276| `--json` | false | Emit JSON output |
277| `--reply-and-resolve` | (none) | JSON array of `{threadId, body}` to reply and resolve ALL threads |
278| `--add-comment` | (none) | Add a comment to the PR |
279
280**Exit codes:**
281
282- `0`: No issues found
283- `1`: Issues detected or error occurred
284
285**`--reply-and-resolve` JSON format:**
286
287```json
288[
289 {"threadId": "PRRT_xxx123", "body": "Fixed: refactored the method as suggested."},
290 {"threadId": "PRRT_xxx456", "body": "Not addressed: this is intentional because ..."}
291]
292```
293
294**Validation rules:**
295
296- Every currently unresolved thread MUST have a corresponding entry.
297- Every entry MUST have a non-empty `body`.
298- If any unresolved thread is missing, the script prints the missing thread details and exits with error.
299
300## Features
301
302### Conflict Detection
303
304Detects merge conflicts via `mergeable` and `mergeStateStatus` fields.
305
306- `CONFLICTING` / `DIRTY`: Conflict detected
307- `BEHIND`: Base branch advanced; Update Branch required
308- `MERGEABLE` / `CLEAN`: No conflicts
309
310### Change Request Handling
311
312Fetches reviews with `state == "CHANGES_REQUESTED"` and displays:
313
314- Reviewer name
315- Review body
316- Submission timestamp
317
318### Reviewer Comments
319
320Fetches ALL reviewer feedback without truncation:
321
322- Review summaries with full comment bodies
323- Inline review comments (file/line) with full comment bodies
324- PR issue comments with full comment bodies
325- Marks review action required if any reviewer feedback exists
326
327### Unresolved Review Threads
328
329Uses GraphQL to fetch threads where `isResolved == false`:
330
331- File path and line number
332- Thread ID (for reply and resolution)
333- Comment author and full body
334- Outdated status
335
336### Reply and Resolve
337
338Use `--reply-and-resolve` to reply to every unresolved thread and resolve them.
339
340- Uses GraphQL `addPullRequestReviewThreadReply` to post a reply.
341- Uses GraphQL `resolveReviewThread` to mark the thread as resolved.
342- Validates that ALL unresolved threads are covered (no thread left behind).
343- Rejects empty reply bodies.
344
345**Required permissions:**
346
347- Fine-grained PAT: `Pull requests` + `Contents: Read and Write`
348- Classic PAT: `repo` scope
349
350### Reviewer Notification
351
352Use `--add-comment "message"` to post a summary comment to the PR after fixes.
353
354## Output Examples
355
356### Diagnosis Report
357
358```text
359## Diagnosis Report: PR #123
360
361**Merge Verdict: BLOCKED**
362Blocking items: 3
363
364---
365
366### BLOCKING
367
368#### B1. [CI-FAILURE] TypeScript build fails
369- **What:** `build` check failed with compilation error
370- **Where:** `src/utils/parser.ts:42` / check: `build`
371- **Evidence:** `error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.`
372- **Action:** Edit `src/utils/parser.ts:42` — change `parseInt(value)` to pass the correct type
373- **Auto-fix:** Yes
374
375#### B2. [CHANGE-REQUEST] @reviewer1 requests error handling
376- **What:** Reviewer requested try-catch around API call
377- **Where:** `src/api/client.ts:88`
378- **Evidence:** "@reviewer1: Please wrap this fetch call in a try-catch block to handle network errors gracefully."
379- **Action:** Add try-catch in `src/api/client.ts:88` around the `fetch()` call
380- **Auto-fix:** Yes
381
382#### B3. [CONFLICT] Merge conflict with main
383- **What:** 2 files have merge conflicts
384- **Where:** `src/config.ts`, `src/index.ts` / branch: `main`
385- **Evidence:** `Mergeable: CONFLICTING, Merge State: DIRTY`
386- **Action:** Merge `origin/main` and resolve conflicts in listed files
387- **Auto-fix:** No (needs confirmation)
388
389---
390
391### INFORMATIONAL
392#### I1. [REVIEW-COMMENT] Code style suggestion
393- **What / Note:** @reviewer2 suggested extracting a helper function — non-blocking style preference
394
395---
396
397**Summary:** 3 blocking items to fix, 1 informational item noted.
398```
399
400### Text Output
401
402```text
403PR #123: Comprehensive Check Results
404============================================================
405
406MERGE STATUS
407------------------------------------------------------------
408Mergeable: CONFLICTING
409Merge State: DIRTY
410Base: main <- Head: feature/my-branch
411Action Required: Resolve conflicts before merging
412
413CHANGE REQUESTS
414------------------------------------------------------------
415From @reviewer1 (2025-01-15):
416 "Please fix these issues..."
417
418UNRESOLVED REVIEW THREADS
419------------------------------------------------------------
420[1] src/main.ts:42
421 Thread ID: PRRT_xxx123
422 @reviewer1: This needs refactoring because the current
423 implementation violates the single responsibility principle.
424
425[2] src/utils.ts:15
426 Thread ID: PRRT_xxx456
427 @reviewer2: Consider using a more descriptive variable name here.
428
429CI FAILURES
430------------------------------------------------------------
431Check: build
432Details: https://github.com/...
433Failure snippet:
434 Error: TypeScript compilation failed
435 ...
436============================================================
437```
438
439### Reply and Resolve Output
440
441```text
442OK: PRRT_xxx123 (src/main.ts:42)
443OK: PRRT_xxx456 (src/utils.ts:15)
444
445Result: 2 resolved, 0 failed, 2 total
446```
447
448### JSON Output
449
450```json
451{
452 "pr": "123",
453 "conflicts": {
454 "hasConflicts": true,
455 "mergeable": "CONFLICTING",
456 "mergeStateStatus": "DIRTY",
457 "baseRefName": "main",
458 "headRefName": "feature/my-branch"
459 },
460 "changeRequests": [
461 {
462 "id": 123456,
463 "reviewer": "reviewer1",
464 "body": "Please fix these issues...",
465 "submittedAt": "2025-01-15T12:00:00Z"
466 }
467 ],
468 "unresolvedThreads": [
469 {
470 "id": "PRRT_xxx123",
471 "path": "src/main.ts",
472 "line": 42,
473 "comments": [
474 {"author": "reviewer1", "body": "This needs refactoring because..."}
475 ]
476 }
477 ],
478 "ciFailures": [
479 {
480 "name": "build",
481 "status": "ok",
482 "logSnippet": "..."
483 }
484 ]
485}
486```