diff --git a/README.md b/README.md index 4fa55ee..5cf9493 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,9 @@ 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. 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. @@ -343,9 +345,11 @@ 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. `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 +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. ```bash diff --git a/skills/xpq-pr-review-cycle.md b/skills/xpq-pr-review-cycle.md index d9c6514..b3ab195 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 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 [ ]; with no arguments it uses the PR for the current branch. --- # xpq-pr-review-cycle @@ -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. --- @@ -149,10 +150,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,24 +225,54 @@ 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. + +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: -- 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. +- 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). -## Step 8: Reply, then resolve +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> --workflow <file> --limit 1 --json databaseId,event,status,conclusion +``` + +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. +- 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 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. @@ -250,16 +284,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 CI is green on the current head. 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. - -```bash -gh api graphql -f query='mutation($id:ID!){resolveReviewThread(input:{threadId:$id}){thread{isResolved}}}' -f id=<thread node id> -``` +**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. -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. @@ -273,18 +307,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. -3. CI: state and head sha. +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 CI is green. 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.