Resolve the PR's CI check failures and linked Issues, and make the PR mergeable.
Operation Modes
| Mode | How to Invoke | Behavior |
|---|---|---|
| Interactive Mode | /pr-green or "Fix the CI" |
Status report → user confirmation → fix → confirm → push |
| Loop Mode | /loop 5 /pr-green |
Autonomously monitor, fix, commit, and push. Exit immediately if there are no problems |
/loop When called via , it operates in loop mode. If it cannot be determined, use interactive mode.
Differences in Behavior by Mode
| Decision Point | Interactive Mode | Loop Mode |
|---|---|---|
| Status Summary | Show in detail and ask for confirmation | Show briefly only when there is a problem |
| Confirmation Before Fixing | Ask the user to confirm the approach | Start fixing without confirmation |
| Commit & Push | After user confirmation | Automatic |
| Close Issue | Present list → close after approval | Automatic close (with comment) |
| When There Are No Problems | Report "Everything is green" | Exit immediately without outputting anything |
| Result Report | Detailed fix report | Report briefly only when fixes were made |
| Difficult-to-Judge Problems | Consult the user | Skip and report |
Workflow
Step 0: Identifying the PR
If a PR number is specified in the arguments, use it. If not specified, automatically detect it from the current branch.
gh pr view --json number,title,state,statusCheckRollup,url,headRefName
If no PR is found, report it and exit.
Step 1: Assessing the Situation
1a. Check CI Check Status
gh pr checks <number>
# 失敗した CI の詳細ログ(run-id は checks 結果から特定)
gh run view <run-id> --log-failed
1b. Check Issues Linked to the PR
PR review comments (including bot reviews such as CodeRabbit):
gh api repos/{owner}/{repo}/pulls/<number>/reviews --jq '.[] | select(.state != "APPROVED") | {user: .user.login, state: .state, body: .body}'
gh api repos/{owner}/{repo}/pulls/<number>/comments --jq '.[] | {user: .user.login, body: .body, path: .path, line: .line, created_at: .created_at}'
Issue linked to PR:
gh pr view <number> --json closingIssuesReferences --jq '.closingIssuesReferences[] | {number, title}'
1c. Early Exit Determination (Loop Mode)
If all of the following conditions are met, exit immediately without doing anything:
- All CI checks are successful (PASS) or running (PENDING)
- There are no unaddressed review comments
- All linked Issues are already closed
If CI is running (PENDING), also exit immediately — check the results on the next loop iteration.
1d. Status Summary (Interactive Mode Only)
In interactive mode, display a status summary and ask for confirmation of the response approach.
Step 2: Resolving CI Errors
Classify CI errors and handle them in order of priority.
| Priority | Error Type | Reproduction command |
|---|---|---|
| 1 | Compile Error | Identify directly from the error message |
| 2 | lint / fmt | ./scripts/ci-check.sh ai lint, ./scripts/ci-check.sh ai dylint |
| 3 | Test failure | ./scripts/ci-check.sh ai unit-test, ./scripts/ci-check.sh ai integration-test |
| 4 | clippy | ./scripts/ci-check.sh ai clippy |
| 5 | Doc Test | ./scripts/ci-check.sh ai doc |
For each error: reproduce → analyze → fix → verify with the same command.
Step 3: Resolving PR Issues
3a. Responding to review comments
Read the code at the pointed-out location and fix it according to the feedback.
3b. Responding to linked Issues
Extract the target code, problem, and expected behavior from the Issue body, then fix and verify.
3c. Closing resolved Issues
gh issue close <number> --comment "$(cat <<'EOF'
## 解決確認
- PR: #<pr-number>
- 修正内容: <具体的な修正の説明>
- 確認方法: <テスト結果やコード確認の根拠>
本 PR の修正により解消されたためクローズします。
EOF
)"
In interactive mode, obtain user approval before closing. In loop mode, close automatically.
Step 4: Commit, local verification, and push
Re-run only the checks related to the modified locations locally. Do not run the full check locally — leave it to CI.
In interactive mode, obtain user confirmation before committing and pushing. In loop mode, do it automatically.
Check the CI results after pushing in the next loop iteration (loop mode) or gh pr checks --watch(interactive mode).
Step 5: Reporting results
Interactive mode: Detailed report of the fixes, Issue handling, and remaining items.
Loop Mode: Report briefly in one line only when there are fixes. If there are no fixes (early termination), produce no output.
Completion conditions
- No CI errors
- Comments/issues on the PR must be resolved
- Apply the Boy Scout Rule