/agent-almanac:run-copilot-review-loopfrom agent-almanac
Automates fixing GitHub Copilot PR review comments: fix each finding in its own commit, reply with fix SHA, resolve thread, re-request bot, and poll for fresh re-review.
Ships in agent-almanac. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Drive a GitHub Copilot PR review to a clean pass through a deterministic loop: fix → reply → resolve → re-request → poll. Each finding gets its own commit, each thread gets a reply citing the fix sha, and the loop terminates on a verified fresh re-review — not on the stale one that was already there. The same loop works for any bot reviewer with a stable slug.
gh pr view --json number)gh CLI with access to the repository (the loop relies on the existing auth — no extra credentials)copilot-pull-request-reviewer[bot])Replace OWNER, REPO, and PR in the commands below with the repository owner, name, and PR number. See references/EXAMPLES.md for inferring all three from the current branch.
Capture the submitted_at of the bot's most recent review before you change anything. This baseline is what later distinguishes a fresh re-review from the stale review that triggered this loop.
# Infer the PR number from the current branch
gh pr view --json number --jq '.number'
# Baseline: latest Copilot review timestamp (may be null if none yet)
BASE=$(gh api repos/OWNER/REPO/pulls/PR/reviews \
--jq '[.[]|select(.user.login=="copilot-pull-request-reviewer[bot]")]|last|.submitted_at') \
|| { echo "baseline reviews read failed — do not proceed" >&2; false; }
# Baseline: how many times Copilot has been requested on this PR so far. The
# timeline, NOT requested_reviewers (Step 6). Read FIRST, count second: a
# `gh … | wc -l` cannot be guarded, because `||` sees the exit status of `wc`,
# and gh's error body carries no trailing newline, so a failed read counts 0 —
# silently, and 0 is the common healthy value. The awk counts only id-shaped
# lines, so an HTML error page from an edge proxy counts 0 rather than ~20.
# Counted by LINES rather than `| length`: --paginate with --jq emits one result
# per page, so `| length` returns a per-page count past 100 timeline events.
IDS=$(gh api repos/OWNER/REPO/issues/PR/timeline --paginate \
--jq '.[]|select(.event=="review_requested" and .requested_reviewer.login=="Copilot")|.id') \
|| { echo "baseline timeline read failed — do not proceed" >&2; false; }
REQS=$(printf '%s\n' "$IDS" | awk '/^[0-9]+$/{n++} END{print n+0}')
echo "baseline: review=$BASE requests=$REQS"
Expected: PR number resolved; BASE holds an ISO-8601 timestamp (or null when the bot has not reviewed yet — then any future review counts as new); REQS holds a count, commonly 0. Read both back before continuing: gh writes its error body to stdout, so a failed call leaves a baseline holding JSON, which every later comparison then treats as a value. 0 is the common healthy value for REQS, which is why the read is guarded separately from the count — a failed read that counted straight to 0 would be indistinguishable from a healthy one, and reading it back could not tell you either.
On failure: gh pr view errors when the current branch has no PR — pass the number explicitly. An empty reviews list is not evidence that Copilot review is disabled — it is equally the state of a PR nobody has requested it on yet. Step 6 is what distinguishes those.
Every review thread carries two distinct identifiers, and they are never interchangeable:
PRRT_...) — consumed by the GraphQL resolveReviewThread mutation (Step 5)gh api graphql -f query='query { repository(owner:"OWNER",name:"REPO"){
pullRequest(number:PR){ reviewThreads(first:40){ nodes {
id isResolved comments(first:1){ nodes { databaseId path line } } } } } } }' \
| jq -r '.data.repository.pullRequest.reviewThreads.nodes[]
| select(.isResolved==false)
| "\(.comments.nodes[0].databaseId) \(.id) \(.comments.nodes[0].path)"'
Expected: One line per unresolved thread: <databaseId> <PRRT_nodeId> <path>. Empty output means no open threads — skip to Step 8 to read the verdict.
On failure: GraphQL errors about owner/name/number mean the OWNER/REPO/PR placeholders were not replaced (note: number:PR takes a bare integer, not a quoted string). If the PR has more than 40 threads, raise first:40 or paginate.
Read each finding and fix it in its own commit, so each thread reply in Step 4 can cite an exact sha. Record the thread → sha mapping as you go.
# Read the finding body (single-comment GET takes no PR number, unlike the Step 4 replies POST)
gh api repos/OWNER/REPO/pulls/comments/<databaseId> --jq '.body'
# ...make the change, then commit it alone...
git add <files>
git commit -m "fix: <what the finding asked for>"
git rev-parse --short HEAD # record this sha for the thread's reply
Make the claim honest everywhere. When a finding cites the PR description (or a README, a doc comment, a changelog line), fixing only the code leaves the overstated claim standing. Edit every place the claim appears — for the PR description:
gh pr edit PR --body-file <corrected-body.md>
Expected: git log shows one commit per finding, and you hold a mapping of <databaseId>/<PRRT_nodeId> → fix sha. Any claim a finding cited is corrected at every location, not just in code.
On failure: If you disagree with a finding, make no commit — reply in Step 4 with your reasoning instead, then resolve. If one change genuinely closes two threads, cite the same sha in both replies rather than splitting a coherent commit.
Reply via REST using the thread's first comment's databaseId (the numeric id from Step 2 — not the PRRT_... node-id):
gh api --method POST "repos/OWNER/REPO/pulls/PR/comments/<databaseId>/replies" -f body="Fixed in <sha> — <what changed>."
Expected: HTTP 201; the reply appears under the thread on the PR page. The sha link resolves once the branch is pushed (Step 6).
On failure: A 404 here almost always means the wrong ID type — a PRRT_... node-id was used where the numeric comment databaseId belongs. Re-read the Step 2 output: first column replies, second column resolves.
Resolve via GraphQL using the thread node-id (PRRT_...):
gh api graphql -f query='mutation { resolveReviewThread(input:{threadId:"<PRRT_nodeId>"}){ thread { isResolved } } }'
Expected: Response contains "isResolved": true for each thread.
On failure: Could not resolve to a node with the global id means a numeric databaseId was passed where the PRRT_... node-id belongs. If a thread is already resolved, note that the bot auto-resolves threads on push — if you pushed before this step, re-run the Step 2 query and only mutate threads still reported isResolved==false.
Push first, then re-request — the bot reviews whatever HEAD it sees at request time:
git push
gh api --method POST repos/OWNER/REPO/pulls/PR/requested_reviewers -f "reviewers[]=copilot-pull-request-reviewer[bot]"
# The POST succeeding is not the confirmation, and requested_reviewers cannot give
# you one: it omits Bot-type reviewers, so it reads [] whether or not the request
# landed. Assert on the timeline instead — a review_requested event, which also
# persists after the review arrives.
: "${REQS:?run Step 1 first}"
NOW_IDS=$(gh api repos/OWNER/REPO/issues/PR/timeline --paginate \
--jq '.[]|select(.event=="review_requested" and .requested_reviewer.login=="Copilot")|.id') \
|| { echo "timeline read failed — cannot confirm the request" >&2; false; }
NOW=$(printf '%s\n' "$NOW_IDS" | awk '/^[0-9]+$/{n++} END{print n+0}')
# The REFUSAL must sit in the arm a bad operand falls into. `[` exits 2 on a
# non-integer operand (bash 5.2.21, zsh 5.9, either position) and `if` reads any
# non-zero as false — so `if -le; then refuse; fi` SKIPS the refusal on garbage.
# The operator is not the mechanism; arm placement is.
if [ "$NOW" -gt "$REQS" ]; then
REQS=$NOW
else
echo "no new review_requested event for Copilot — the request did not land" >&2
echo "do not poll; use advocatus-diaboli as the reviewer of record" >&2
false
fi
Note the three forms of one identity, and which surface carries which. The POST takes the literal slug copilot-pull-request-reviewer[bot]. The timeline's review_requested event names it Copilot with requested_reviewer.type == "Bot". Submitted reviews carry user.login == "copilot-pull-request-reviewer[bot]". The fourth surface, requested_reviewers on the PR object, is the one to avoid: it omits Bot-type reviewers entirely, so it reads [] for a request that landed and for one that never did.
Expected: Push accepted, and the assertion prints nothing: the timeline carries one more review_requested event for Copilot than it did at Step 1. Pushing may auto-resolve remaining open threads; that is normal bot behavior, not an error.
On failure: A POST that succeeds is not evidence the request took, and the absence of Copilot from requested_reviewers is not evidence that it did not — that field omits Bot-type reviewers, measured on this repository's PRs #512 and #562, where it read [] while the review arrived minutes later. The timeline is the discriminating signal: #512 and #562 each carry review_requested Copilot type=Bot and each received a review; #553 carries no such event and received none. Reaching the failing branch therefore means the request genuinely did not land — Copilot review is not enabled here. Quota exhaustion does not present this way: the request lands and the bot posts a refusal as a review, which Step 7 catches by body and reports as exit 3. Stop, and use advocatus-diaboli as the reviewer of record (Related Skills). A 422 is the separate, older case of a misspelled slug. And if you re-requested before pushing, the bot reviewed the stale HEAD — push, then POST again.
The re-review is asynchronous (typically 30 s to a few minutes). Step 6 confirmed the request landed, so poll every 25 s (up to 20 iterations ≈ 8 min) in one atomic gh api read per iteration, accepting only a bot review where:
submitted_at is an ISO-8601 timestamp newer than $BASE (guards against gh error JSON on stdout)commit_id matches the local pushed HEAD (captured once via git rev-parse HEAD)body carries the genuine-review marker "Pull request overview" (exit 0), explicitly rejecting "unable to review" / "wasn't able to review" as no-reviews (exit 3) and refusing any other unrecognized body (exit 4)Run the full guarded subshell loop in references/EXAMPLES.md (or the standalone poll-copilot.sh variant in references/EXAMPLES.md).
Expected: $? is 0 and a timestamp newer than $BASE was printed, usually within a few minutes. Without a pre-change baseline the check is meaningless — the old review already satisfies "a Copilot review exists".
On failure:
COMMENTED quota refusal ("unable to review") or nothing-to-review notice ("wasn't able to review"). Hand the PR to advocatus-diaboli.$BASE is not a timestamp or git rev-parse HEAD failed — re-run Step 1.gh api repos/OWNER/REPO/pulls/PR/reviews \
--jq '[.[]|select(.user.login=="copilot-pull-request-reviewer[bot]")]|last|{state,submitted_at,body}'
# The suppression block posts NO review threads, so Step 2 cannot see it: read it
# from the body of the bot's review ON HEAD. Filter on the login (each thread
# reply files an empty COMMENTED review under YOUR login) and on the sha, re-read
# here because Step 7's HEAD_SHA lived in its subshell. jq -e exits non-zero when
# no bot review is on HEAD, so an absent review is refused, never read as "no
# block". Prints each collapsed block's <summary> and the suppression entries, in
# body order. Entries quote code, so the block ends only at a column-0 </details>
# outside a ``` fence, and the read exits 1 when the entry headers it printed do
# not add up to the (N) the summary declares.
if BODY=$(gh api repos/OWNER/REPO/pulls/PR/reviews \
| jq -er --arg sha "$(git rev-parse HEAD)" \
'[.[]|select(.user.login=="copilot-pull-request-reviewer[bot]" and .commit_id==$sha)]|last|.body'); then
printf '%s\n' "$BODY" | awk '
/<summary>/{print}
/<summary>[^<]*[Ss]uppressed/{p=1; f=0; n=$0; sub(/.*\(/,"",n); sub(/\).*/,"",n); want+=n; next}
p && /^```/{f=!f}
p && !f && /^<\/details>/{p=0}
p && !f && /^\*\*[^*]+:[0-9]+/{got++}
p
END{ if (want != got) { print "block declares " want " entries, " got " printed - read the raw body" > "/dev/stderr"; exit 1 } }'
else
echo "no bot review on HEAD, or the read failed — no verdict" >&2; false
fi
Interpret the result against how the bot actually reports:
COMMENTED is the bot's terminal state. Copilot does not return APPROVED or CHANGES_REQUESTED; a COMMENTED review is not a rejection.COMMENTED state as one that did; only the body tells them apart. The standing "human review recommended" style banner is fixed bot messaging — it does not block the PR. Nor does a zero headline ("generated no comments", "generated no new comments", or **Comments generated:** 0 in the newer format), but it does not clear the PR either: it does not count the suppression block.<details> block summarised Suppressed comments (N) or Comments suppressed due to low confidence (N) lists **path:line** entries and attaches no review comments, so neither the headline count nor Step 2 sees it — even on zero-headline reviews. Run the Step 8 block read every pass; entries are leads, not verdicts (corpus counts in references/EXAMPLES.md)."Pull request overview" rather than "reviewed N out of M" (which newer formats omit).advocatus-diaboli. Do not match on one wording — the guard shipped matching only the first, and #506 was already in this corpus, passing as clean.BASE and REQS; re-entering below it leaves the previous round's review newer than a stale baseline, and the next poll reports that review as the new one.Expected: An unambiguous verdict: clean pass (stop), or a concrete list of new threads or suppression entries (triage, then iterate).
On failure: When the prose is ambiguous, do not parse it — count unresolved threads with the Step 2 query. The thread count is ground truth for threads; the review body is commentary. The one part of the body the count cannot stand in for is the suppression block, which posts no threads: read it with the second command above, and never infer its absence from a count of zero. If that command refuses, either no bot review is on HEAD (it reads the local HEAD, so an unpushed commit refuses too) or the read failed (a 404 body, for one, puts a jq error above the refusal) — return to Step 7 rather than reading the older review. If it prints block declares N entries, M printed and exits 1, the read lost entries (an entry quoting a column-0 </details> outside a code fence ends the block early) or the entry header changed shape: read the raw body.
git log shows one commit per addressed findingreview_requested event for Copilot after the Step 6 POST — never inferred from requested_reviewers, which omits Bot reviewerssubmitted_at is newer than the Step 1 baselineCOMMENTEDPRRT_... thread node-id; the resolveReviewThread mutation errors when fed a numeric comment databaseId. Reply with the databaseId, resolve with the node-id.COMMENTED as a failing verdict: Copilot never approves; COMMENTED plus a "human review recommended" banner is its normal clean output. Treating it as a blocking finding stalls the merge on boilerplate.submitted_at before re-requesting.git push is expected; re-check isResolved before mutating instead of treating it as data loss.requested_reviewers whether the bot was requested: the field omits Bot-type reviewers, so it reads [] for a request that landed (measured on #512 and #562, both of which were reviewed minutes later) and for one that never did (#553, never reviewed). A poll that treats that emptiness as "the bot finished" reports a clean pass in one iteration, about 25 seconds, having verified nothing — and one that treats it as "the request failed" abandons a review that is on its way. Ask the timeline for a review_requested event instead: it discriminates, and it persists after the review lands. Sibling of Polling without a baseline: that one trusts stale data, this one trusts a field that was never populated.create-pull-request - opens and manages the PR this loop drives to a clean passreview-pull-request - the human/agent-driven review counterpart to this bot loopadvocatus-diaboli (agent) - the reviewer of record when Copilot review is unavailable. The two are alternatives for one job, not complements: if the Step 6 assertion fails, this loop cannot run at all and the PR still needs a reviewverify-web-app-runtime - runtime-verify the fix actually works before replying "Fixed in <sha>"What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (pjt222/agent-almanac) — no native marketplace selected
npx claudepluginhub p/pjt222-agent-almanac377 skills in this plugin
/adapt-architectureExecute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation. Covers transformation planning, parallel running, progressive cutover, rollback design, and post-metamorphosis stabilization for system architecture evolution. Use when assess-form has classified the system as READY for transformation, when migrating from monolith to microservices, when replacing a core subsystem while dependents continue operating, or when any architectural change must be gradual rather than big-bang.
/adapticMaster skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains. Orchestrates meditate, expand-awareness, observe, awareness, integrate-gestalt, and express-insight into a coherent process that produces unified understanding rather than sequential compromise. Use when a problem genuinely spans 3+ domains and the interactions between domains matter more than depth in any one, when sequential analysis feels like compromise rather than integration, or before major architectural decisions affecting multiple stakeholders.
/add-puzzle-typeScaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely new puzzle type to the package or following the 10-point integration checklist to ensure nothing is missed end-to-end.
Other plugins' skills for the same job