From 8ac5840796b24be010ccd650b32991ed2054c511 Mon Sep 17 00:00:00 2001 From: Robin Coe Date: Fri, 16 Oct 2026 21:44:14 -0400 Subject: [PATCH 1/5] #74: skill: single Copilot round; read CI from workflow runs Copilot reviews a PR once, when it opens, so drop the re-review wait and rounds. Fine-grained tokens have no Checks permission, so read CI from workflow runs (Actions read) instead of gh pr checks. Where the base has no CI (PRs into dev), a passing local suite on the head stands in, so threads can be resolved. Co-Authored-By: Claude Opus 5.5 --- README.md | 9 ++++--- skills/xpq-pr-review-cycle.md | 51 +++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4fa55ee..53a8b32 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,8 @@ For Claude's sessions use a fine-grained personal access token instead: - Resource owner `XP-Quest`, the five repos, an expiry (for example 90 days). - Repository permissions: Contents **read**, Pull requests **read and write**, Issues **read and - write**, Metadata read, Checks read, Commit statuses read. The REST merge endpoint requires + write**, Metadata read, Actions read, Commit statuses read. Fine-grained tokens have no + Checks permission, so the skill reads CI from workflow runs. The REST merge endpoint requires Contents **write**, so this token cannot call it. Pushes use SSH and are unaffected. - Add the organization permission Projects (read and write) only if Claude should keep setting board Status. @@ -344,8 +345,10 @@ Takes one open PR to "ready for you to merge". With no arguments it uses the cur It rewrites a default or template-only PR title and description from the issue, waits for the Copilot review, sorts each Copilot thread into FIX, DECLINE or DEFER (a filed issue), makes each fix with a test that fails without it, replies on every thread, and resolves them once CI is -green. `scripts/pr-unresolved-threads.sh` is the final gate. It never merges, and it stops if the -merge guard is not loaded. To run several PRs at once, start one invocation per PR from +green (or the local test suite passes, where the PR's base has no CI). Copilot reviews once, when +the PR opens; the skill does not wait for a re-review after fixes. +`scripts/pr-unresolved-threads.sh` is the final gate. It never merges, and it stops if the merge +guard is not loaded. To run several PRs at once, start one invocation per PR from `~/xpquest`, each in its own worktree. ```bash diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index d9c6514..b89ff9e 100644 --- a/skills/xpq-pr-review-cycle.md +++ b/skills/xpq-pr-review-cycle.md @@ -1,6 +1,6 @@ --- name: xpq-pr-review-cycle -description: Take an open XP Quest PR from "opened" to "ready for the user to merge". Normalises the PR title and description (issue-derived, not the GitHub default), waits for the Copilot review, triages every Copilot thread into FIX / DECLINE / DEFER, implements fixes with mutation-verified tests, replies on and resolves every thread once CI is green, then reports. Never merges. Run as /xpq-pr-review-cycle [ ]; with no arguments it uses the PR for the current branch. +description: Take an open XP Quest PR from "opened" to "ready for the user to merge". Normalises the PR title and description (issue-derived, not the GitHub default), waits for the Copilot review, triages every Copilot thread into FIX / DECLINE / DEFER, implements fixes with mutation-verified tests, replies on and resolves every thread once CI (or, where the base has no CI, the local test suite) passes, then reports. Never merges. Run as /xpq-pr-review-cycle [ ]; with no arguments it uses the PR for the current branch. --- # xpq-pr-review-cycle @@ -149,10 +149,13 @@ gh api -X PATCH repos/XP-Quest//pulls/ -f title="" -F body=@<fil ## Step 3: Wait for the Copilot review -Poll `gh pr view <N> -R XP-Quest/<repo> --json headRefOid,reviews` until a review whose author -login starts with `copilot` exists on the current `headRefOid` (the login is -`copilot-pull-request-reviewer`). Poll every 60 seconds for up to 20 minutes. Foreground `sleep` -is blocked; use the Monitor tool with an until-loop. +Copilot reviews a PR once, when it is opened. It does not re-review later pushes, so its review +can be on an older commit than the current head. + +Poll `gh pr view <N> -R XP-Quest/<repo> --json reviews` until a review whose author login starts +with `copilot` exists on any commit of the PR (the login is `copilot-pull-request-reviewer`). +Poll every 60 seconds for up to 20 minutes. Foreground `sleep` is blocked; use the Monitor tool +with an until-loop. - No review after 20 minutes: report "no Copilot review arrived" and stop. That is not the same as "clean"; never say the PR has no findings on that basis. @@ -221,22 +224,29 @@ For each FIX, on the PR's head branch: One commit per distinct fix keeps the table below readable. Do not fold unrelated threads into one commit. -After pushing, repeat Step 3 for a re-review on the new head (up to 10 minutes). New Copilot -threads are another round, up to three rounds in total. If it is still producing threads after -that, stop and report. - -Keep the ids of the threads you have already triaged. Threads stay unresolved until Step 8, so -each re-review query returns the old ids together with the new ones. In a later round, triage -only ids that are not in your list, and reply once per thread. +There is one round of triage. Do not wait for or request a Copilot re-review after pushing; +go to Step 7 once the last fix is pushed. ## Step 7: CI -`gh pr checks <N> -R XP-Quest/<repo>` exits 0 (pass), 1 (fail) or 8 (pending). Poll while it -exits 8. Green means exit 0 on the current `headRefOid`. +Do not use `gh pr checks`: it reads check runs, and the fine-grained token cannot (GitHub offers +no Checks permission for fine-grained tokens). Read the workflow runs on the current head instead: + +```bash +gh run list -R XP-Quest/<repo> --commit <headRefOid> --json name,event,status,conclusion +``` + +Ignore runs with `event` `dynamic` (the Copilot review runs as one). Poll every 60 seconds while +any remaining run's `status` is not `completed`. Green means every remaining run concluded +`success`, `skipped` or `neutral`. -- Failing: diagnose. A failure your commits introduced is a bug to fix. A pre-existing or - unrelated failure is reported, not hidden, and threads stay unresolved. -- "No checks reported": say that. Do not call it green. +- Failing: diagnose (`gh run view <id> -R XP-Quest/<repo> --log-failed`). A failure your commits + introduced is a bug to fix. A pre-existing or unrelated failure is reported, not hidden, and + threads stay unresolved. +- No runs within 2 minutes of the last push: the repo has no CI for this base (for example, + `xpq-api`'s workflows run only on PRs into `main`). Run the repo's full test suite (Step 6, + item 3) on the current head, unless it already passed on that exact sha. A pass stands in for + CI. Record the command, result and sha for the report. Do not call it CI. ## Step 8: Reply, then resolve @@ -251,7 +261,8 @@ Reply format: `FIX in <sha> — <what changed>; test: <test name>`, `DECLINE — `DEFER — filed XP-Quest/<repo>#<n>`. **Resolve only when all of these hold:** every Copilot thread has a recorded disposition, all fix -commits are pushed, and CI is green on the current head. Then resolve every FIX, DECLINE and DEFER +commits are pushed, and Step 7 passed on the current head (CI green, or the local suite where +the base has no CI). Then resolve every FIX, DECLINE and DEFER thread (CLAUDE.md §8: resolve all of them; a DEFER carries its issue link). Do not resolve a thread marked NEEDS USER. @@ -282,9 +293,9 @@ Final report: words. Commit is the sha, the filed issue for DEFER, or `—`. Test is the test name with "fails without fix: yes", or `n/a — <why>`. 2. Unresolved count from the re-query, and the list if non-zero. -3. CI: state and head sha. +3. CI: state and head sha, or "no CI for base `<base>`; `<command>` passed on `<sha>`". 4. PR title and description: updated or unchanged, and anything left for the user. 5. Human threads and NEEDS USER items. 6. The last line: `PR <url> is ready for you to review and merge.` Say that only if the unresolved - count is zero or fully explained and CI is green. Otherwise say what blocks it. Do not describe + count is zero or fully explained and Step 7 passed. Otherwise say what blocks it. Do not describe the PR as merged, merging or auto-merging. From 866bf9c46dd466f12a601247d58ba3ba076ba296 Mon Sep 17 00:00:00 2001 From: Robin Coe <rdcoe@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:56:55 -0400 Subject: [PATCH 2/5] #74: skill: re-read headRefOid before reading CI runs Step 1's headRefOid is stale after Step 6 pushes fixes, and the dropped re-review poll no longer refreshes it. Without a re-read, Step 7 could pass on the pre-fix commit's runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- skills/xpq-pr-review-cycle.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index b89ff9e..ba0ec7d 100644 --- a/skills/xpq-pr-review-cycle.md +++ b/skills/xpq-pr-review-cycle.md @@ -230,7 +230,10 @@ go to Step 7 once the last fix is pushed. ## Step 7: CI Do not use `gh pr checks`: it reads check runs, and the fine-grained token cannot (GitHub offers -no Checks permission for fine-grained tokens). Read the workflow runs on the current head instead: +no Checks permission for fine-grained tokens). Read the workflow runs on the current head instead. + +Re-read the head first: `gh pr view <N> -R XP-Quest/<repo> --json headRefOid`. The value from +Step 1 is stale once Step 6 has pushed fixes. Use the fresh `headRefOid` everywhere below. ```bash gh run list -R XP-Quest/<repo> --commit <headRefOid> --json name,event,status,conclusion From 4d35d881fb04c9314dea6fdd5ce7828fe8a084d0 Mon Sep 17 00:00:00 2001 From: Robin Coe <rdcoe@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:57:59 -0400 Subject: [PATCH 3/5] #74: skill: gate on applicable workflows' newest runs Listing every run on the head sha mixed in other workflows, runs from an earlier base and superseded runs, and treated "no runs yet" as "no CI". Step 7 now decides which workflows apply from their pull_request triggers (branches, types, paths), takes the newest run of each, and falls back to the local suite only when none apply. A missing run for an applicable workflow blocks instead of falling back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- skills/xpq-pr-review-cycle.md | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index ba0ec7d..1ce042f 100644 --- a/skills/xpq-pr-review-cycle.md +++ b/skills/xpq-pr-review-cycle.md @@ -235,21 +235,41 @@ no Checks permission for fine-grained tokens). Read the workflow runs on the cur Re-read the head first: `gh pr view <N> -R XP-Quest/<repo> --json headRefOid`. The value from Step 1 is stale once Step 6 has pushed fixes. Use the fresh `headRefOid` everywhere below. +**Which workflows apply.** Read the workflow files on the head +(`gh api "repos/XP-Quest/<repo>/contents/.github/workflows?ref=<headRefOid>"`). A workflow applies +to this PR when its `on:` has `pull_request` or `pull_request_target`, and: + +- its `branches` filter, if any, includes the PR's base; +- its `types`, if any, include `opened`, `synchronize` or `reopened` (a `closed`-only workflow + such as `branch-cleanup` does not gate review); +- its `paths` or `paths-ignore` filter, if any, matches at least one file in + `gh pr diff <N> -R XP-Quest/<repo> --name-only` (`xpq-infra`'s `bicep-validate` has one). + +Decide from the triggers, never from whether runs have appeared. Runs on the same sha from other +workflows, or from an earlier base, are not this PR's CI. + +**No workflow applies:** the base has no CI (for example, PRs into `dev` in `xpq-api`). Run the +repo's full test suite (Step 6, item 3) on the current head, unless it already passed on that +exact sha. A pass stands in for CI. Record the command, result and sha for the report. Do not +call it CI. + +**Otherwise,** take the newest run of each applicable workflow on the head: + ```bash -gh run list -R XP-Quest/<repo> --commit <headRefOid> --json name,event,status,conclusion +gh run list -R XP-Quest/<repo> --commit <headRefOid> --workflow <file> --limit 1 --json databaseId,event,status,conclusion ``` -Ignore runs with `event` `dynamic` (the Copilot review runs as one). Poll every 60 seconds while -any remaining run's `status` is not `completed`. Green means every remaining run concluded -`success`, `skipped` or `neutral`. +Older runs of the same workflow on the same sha are superseded (an `edited` run after Step 2 can +replace an earlier failure). Poll every 60 seconds while a newest run's `status` is not +`completed`. Green means every applicable workflow's newest run concluded `success`, `skipped` +or `neutral`. - Failing: diagnose (`gh run view <id> -R XP-Quest/<repo> --log-failed`). A failure your commits introduced is a bug to fix. A pre-existing or unrelated failure is reported, not hidden, and threads stay unresolved. -- No runs within 2 minutes of the last push: the repo has no CI for this base (for example, - `xpq-api`'s workflows run only on PRs into `main`). Run the repo's full test suite (Step 6, - item 3) on the current head, unless it already passed on that exact sha. A pass stands in for - CI. Record the command, result and sha for the report. Do not call it CI. +- An applicable workflow has no run after 10 minutes: CI is missing, not passing. Check + `gh pr view <N> -R XP-Quest/<repo> --json mergeable` (`pull_request` workflows do not run on a + conflicted PR), report it, and keep the threads unresolved. Do not fall back to the local suite. ## Step 8: Reply, then resolve From 3b3e7bc343c33ad6288af625f80030e2b7383fbf Mon Sep 17 00:00:00 2001 From: Robin Coe <rdcoe@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:18:40 -0400 Subject: [PATCH 4/5] #74: skill: hand thread resolution to the user resolveReviewThread is refused for the fine-grained token even with Pull requests read/write. Step 8 now posts the replies and lists each thread's link for the user to resolve; Step 9 accepts unresolved threads that are on that list. README notes the limitation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- README.md | 9 +++++---- skills/xpq-pr-review-cycle.md | 35 ++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 53a8b32..5cf9493 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,8 @@ For Claude's sessions use a fine-grained personal access token instead: - Resource owner `XP-Quest`, the five repos, an expiry (for example 90 days). - Repository permissions: Contents **read**, Pull requests **read and write**, Issues **read and write**, Metadata read, Actions read, Commit statuses read. Fine-grained tokens have no - Checks permission, so the skill reads CI from workflow runs. The REST merge endpoint requires + Checks permission, so the skill reads CI from workflow runs. They also cannot resolve review + threads, so the skill leaves resolving to you. The REST merge endpoint requires Contents **write**, so this token cannot call it. Pushes use SSH and are unaffected. - Add the organization permission Projects (read and write) only if Claude should keep setting board Status. @@ -344,9 +345,9 @@ files for narrative context, and writes the enriched output. Takes one open PR to "ready for you to merge". With no arguments it uses the current branch's PR. It rewrites a default or template-only PR title and description from the issue, waits for the Copilot review, sorts each Copilot thread into FIX, DECLINE or DEFER (a filed issue), makes each -fix with a test that fails without it, replies on every thread, and resolves them once CI is -green (or the local test suite passes, where the PR's base has no CI). Copilot reviews once, when -the PR opens; the skill does not wait for a re-review after fixes. +fix with a test that fails without it, replies on every thread, and lists them for you to resolve +once CI is green (or the local test suite passes, where the PR's base has no CI). Copilot reviews +once, when the PR opens; the skill does not wait for a re-review after fixes. `scripts/pr-unresolved-threads.sh` is the final gate. It never merges, and it stops if the merge guard is not loaded. To run several PRs at once, start one invocation per PR from `~/xpquest`, each in its own worktree. diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index 1ce042f..b6cf927 100644 --- a/skills/xpq-pr-review-cycle.md +++ b/skills/xpq-pr-review-cycle.md @@ -1,6 +1,6 @@ --- name: xpq-pr-review-cycle -description: Take an open XP Quest PR from "opened" to "ready for the user to merge". Normalises the PR title and description (issue-derived, not the GitHub default), waits for the Copilot review, triages every Copilot thread into FIX / DECLINE / DEFER, implements fixes with mutation-verified tests, replies on and resolves every thread once CI (or, where the base has no CI, the local test suite) passes, then reports. Never merges. Run as /xpq-pr-review-cycle [<repo> <N>]; with no arguments it uses the PR for the current branch. +description: Take an open XP Quest PR from "opened" to "ready for the user to merge". Normalises the PR title and description (issue-derived, not the GitHub default), waits for the Copilot review, triages every Copilot thread into FIX / DECLINE / DEFER, implements fixes with mutation-verified tests, replies on every thread, and once CI (or, where the base has no CI, the local test suite) passes, hands the user the list of threads to resolve, then reports. Never merges. Run as /xpq-pr-review-cycle [<repo> <N>]; with no arguments it uses the PR for the current branch. --- # xpq-pr-review-cycle @@ -271,7 +271,7 @@ or `neutral`. `gh pr view <N> -R XP-Quest/<repo> --json mergeable` (`pull_request` workflows do not run on a conflicted PR), report it, and keep the threads unresolved. Do not fall back to the local suite. -## Step 8: Reply, then resolve +## Step 8: Reply, then hand off resolution Reply on **every** Copilot thread with its disposition. Replies can go out as dispositions are decided; a FIX reply goes out after the push that contains it. @@ -283,17 +283,16 @@ gh api -X POST repos/XP-Quest/<repo>/pulls/<N>/comments/<databaseId>/replies -F Reply format: `FIX in <sha> — <what changed>; test: <test name>`, `DECLINE — <reason>`, or `DEFER — filed XP-Quest/<repo>#<n>`. -**Resolve only when all of these hold:** every Copilot thread has a recorded disposition, all fix -commits are pushed, and Step 7 passed on the current head (CI green, or the local suite where -the base has no CI). Then resolve every FIX, DECLINE and DEFER -thread (CLAUDE.md §8: resolve all of them; a DEFER carries its issue link). Do not resolve a thread -marked NEEDS USER. +**The user resolves the threads.** The fine-grained token cannot: `resolveReviewThread` returns +"Resource not accessible by personal access token" with Pull requests read and write. Do not +call it, and do not switch to another credential to get past it. -```bash -gh api graphql -f query='mutation($id:ID!){resolveReviewThread(input:{threadId:$id}){thread{isResolved}}}' -f id=<thread node id> -``` - -The id is the thread's node id from Step 4, not the comment id. +**Hand off only when all of these hold:** every Copilot thread has a recorded disposition, all fix +commits are pushed, and Step 7 passed on the current head (CI green, or the local suite where +the base has no CI). Then list every FIX, DECLINE and DEFER thread for the user to resolve, each +with its link `https://github.com/XP-Quest/<repo>/pull/<N>#discussion_r<databaseId>` (the first +comment's `databaseId` from Step 4). Leave NEEDS USER threads out of that list; they are reported +separately. Then update the PR body's follow-up section (a `## Review follow-up (Copilot, N findings)` table of finding and disposition, as in recent PRs) via the REST PATCH in Step 2. @@ -307,18 +306,20 @@ bash ~/xpquest/.xpq-org-main/scripts/pr-unresolved-threads.sh <repo> <N> ``` Exit 0 means zero unresolved. Exit 1 prints each unresolved thread (id, author, `path:line`, -first line): say which and why. Exit 2 is an API error; retry once, then report it. Do not -report done while a thread you were responsible for is unresolved without an explicit reason. +first line). Every unresolved thread must be on the Step 8 hand-off list or a NEEDS USER item; +say which and why for any other. Exit 2 is an API error; retry once, then report it. Final report: 1. A table with columns **thread | disposition | commit | test**. Thread is `path:line` plus a few words. Commit is the sha, the filed issue for DEFER, or `—`. Test is the test name with "fails without fix: yes", or `n/a — <why>`. -2. Unresolved count from the re-query, and the list if non-zero. +2. Threads for the user to resolve: the Step 8 hand-off list with links, and the unresolved + count from the re-query. 3. CI: state and head sha, or "no CI for base `<base>`; `<command>` passed on `<sha>`". 4. PR title and description: updated or unchanged, and anything left for the user. 5. Human threads and NEEDS USER items. -6. The last line: `PR <url> is ready for you to review and merge.` Say that only if the unresolved - count is zero or fully explained and Step 7 passed. Otherwise say what blocks it. Do not describe +6. The last line: `PR <url> is ready for you to review and merge once you resolve the <k> + threads listed above.` (drop the clause when `<k>` is 0). Say that only if every unresolved + thread is on the hand-off list or explained, and Step 7 passed. Otherwise say what blocks it. Do not describe the PR as merged, merging or auto-merging. From 588bc88d9858311e30c28f2ee8d3b14420fd5e05 Mon Sep 17 00:00:00 2001 From: Robin Coe <rdcoe@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:28:30 -0400 Subject: [PATCH 5/5] #74: skill: make the skill the authority for PR review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The authority line let CLAUDE.md §8 win over the skill, and §8 still said to resolve every thread, which the token cannot do. The skill now owns the review procedure; §13 and the conventions doc still win where they overlap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- skills/xpq-pr-review-cycle.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index b6cf927..b3ab195 100644 --- a/skills/xpq-pr-review-cycle.md +++ b/skills/xpq-pr-review-cycle.md @@ -9,10 +9,11 @@ Takes one PR to "ready for the user to merge". It runs when invoked and finishes ready or it is blocked. It does not stay resident. To cover several PRs, run one invocation per PR, each in its own worktree (the `~/xpquest` clones are shared with other sessions). -Authority: CLAUDE.md §8 (review habits) and §13 (guardrails), SR_ED_CONVENTIONS.md "PR and -issue lifecycle" and "Issue-driven commit workflow". Where this skill restates one of those, -the doc wins. The PR title format in Step 2 is the exception: it is not in the conventions doc -and is taken from the titles of merged PRs. +Authority: this skill is the source for the PR review procedure (Steps 2–9), including the +commands and how threads are replied to and resolved. CLAUDE.md §13 (guardrails) and +SR_ED_CONVENTIONS.md "PR and issue lifecycle" and "Issue-driven commit workflow" win over it +where they overlap. The PR title format in Step 2 is not in the conventions doc; it is taken +from the titles of merged PRs. ---