Skip to content
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
ab80242
Bring the clone finder and review worktree libraries over from the ea…
catalan-adobe Nov 28, 2026
d7748ba
Find the local clone with 3a's config reader, hooks off on every clon…
catalan-adobe Nov 28, 2026
2d600d8
Fetch a missing previous round by SHA from the PR's repository, witho…
catalan-adobe Nov 28, 2026
1b77e31
Review in a worktree of the local clone, with private refs per PR
catalan-adobe Nov 28, 2026
907b62c
Merge remote-tracking branch 'origin/review-state-folder' into review…
catalan-adobe Nov 28, 2026
824f629
Expect 3a's config error wording in the clone finder test
catalan-adobe Nov 28, 2026
7805b94
Keep the ~/repos scan for a config without roots
catalan-adobe Nov 28, 2026
23787b3
Clear the git variables that route to another repository at startup
catalan-adobe Nov 28, 2026
1ce77db
Resolve a --clone or config path to its main clone, and skip a clone …
catalan-adobe Nov 28, 2026
9e748c0
Skip a sparse clone and use the cache clone instead
catalan-adobe Nov 28, 2026
0e137c6
Key PR refs and review worktrees by host, owner, repo and number
catalan-adobe Nov 28, 2026
3cb75f9
Reset a review worktree only when git, run in it, shows it is the clo…
catalan-adobe Nov 28, 2026
69a35ed
Recover only this review path's stale registration instead of pruning…
catalan-adobe Nov 28, 2026
29958fb
Use a round's pins only when both agree with its record, and write th…
catalan-adobe Nov 28, 2026
ec6a9de
Keep the dirty-worktree warning in the run folder too
catalan-adobe Nov 28, 2026
e20b890
Test the saved worktree's reuse: keep the PR state between local roun…
catalan-adobe Nov 28, 2026
22a0a2d
Merge remote-tracking branch 'origin/review-state-folder' into review…
catalan-adobe Nov 28, 2026
9a9c0c8
Merge remote-tracking branch 'origin/main' into review-worktrees
catalan-adobe Nov 28, 2026
d789e21
Run both passes' tripwire on the clone and the review worktree, and s…
catalan-adobe Nov 28, 2026
e4b91fb
Document the read-only reviewer in the shared review worktree: what i…
catalan-adobe Nov 28, 2026
401b303
Clear the caller's git routing and config variables before the real-g…
catalan-adobe Nov 28, 2026
8c7042f
Make the review worktrees and the cache clone readable by their owner…
catalan-adobe Nov 28, 2026
65e1fdc
Hold a lock on the clone for the PR from the fetch to the end of the run
catalan-adobe Nov 28, 2026
e52700e
Make the cache clone one run at a time, move it into place once compl…
catalan-adobe Nov 28, 2026
e9b3076
Run no automatic maintenance in the clone, so a fetch never prunes an…
catalan-adobe Nov 28, 2026
2c2b9fd
Unset an inherited GIT_CONFIG, so the clone's settings are read as ch…
catalan-adobe Nov 28, 2026
c1a8fa8
Turn replacement objects off for the whole run, so the review sees th…
catalan-adobe Nov 28, 2026
ef454eb
Add the review worktree with absolute links, and read a relative gitd…
catalan-adobe Nov 28, 2026
6abce2f
Turn the clone's core.fsmonitor hook off in the run's own git commands
catalan-adobe Nov 28, 2026
6270b3e
Put the review worktree next to the clone's real folder, and refuse a…
catalan-adobe Nov 28, 2026
df3b7cc
Check the review worktree with every untracked file before a reset, a…
catalan-adobe Nov 28, 2026
4ee5d4f
Merge the permission and lock fixes of round 2 (pr16-concurrency)
catalan-adobe Nov 28, 2026
d9760b7
Give CI 15 minutes: the tests alone took over 4 of the 5
catalan-adobe Nov 28, 2026
4b817b0
Print what each lookup said when the cache-clone race test fails
catalan-adobe Nov 28, 2026
634d9cc
DIAGNOSTIC: trace the cache-clone race lookups on CI (to be removed)
catalan-adobe Nov 28, 2026
aa6a39e
DIAGNOSTIC: log the cache-clone race lookups' file operations on CI (…
catalan-adobe Nov 28, 2026
5416d09
DIAGNOSTIC: pass the log path to the traced lookups (to be removed)
catalan-adobe Nov 28, 2026
e7df560
DIAGNOSTIC: pass the trace file itself (to be removed)
catalan-adobe Nov 28, 2026
27e3001
DIAGNOSTIC: record the lock's holder inside the cache-clone race test…
catalan-adobe Nov 28, 2026
4dc19d2
DIAGNOSTIC: record lock_take's decisions in memory and print them aft…
catalan-adobe Nov 28, 2026
6624525
Remove the CI diagnostics of the cache-clone race
catalan-adobe Nov 28, 2026
deb5959
Claim a lock by making its pid file with O_EXCL: mkdir is not exclusi…
catalan-adobe Nov 28, 2026
58a5fd8
Claim a lock folder that has no pid file instead of refusing it, and …
catalan-adobe Nov 28, 2026
65fa046
Probe git's --relative-paths in the test's clone, not the folder the …
catalan-adobe Nov 28, 2026
23c7ece
Retry a fetch whose ref lock is held on git 2.53 too: it says "refere…
catalan-adobe Nov 28, 2026
0f06df4
Clear GIT_NO_REPLACE_OBJECTS in the test fixtures: the replacement co…
catalan-adobe Nov 29, 2026
1fb9dde
Check <clone>.reviews before the clone lock makes or changes anything…
catalan-adobe Nov 29, 2026
64e8a03
Refuse a lock folder without a pid file that holds other files, and l…
catalan-adobe Nov 29, 2026
42de466
Report a lock that can't be removed instead of calling it released
catalan-adobe Nov 29, 2026
c15e319
Keep an https remote's port when matching a clone to a host with a port
catalan-adobe Nov 29, 2026
fc4c7cf
Make the cache clone beside its place, and rename it in, not in the l…
catalan-adobe Nov 29, 2026
2cc8a9f
Refuse a PR state folder that overlaps the clone lock or the review w…
catalan-adobe Nov 29, 2026
0b68d82
Reuse a saved review worktree only inside the private .reviews folder…
catalan-adobe Nov 29, 2026
4da43c0
Test a whole run from a layout an earlier version left: a saved workt…
catalan-adobe Nov 29, 2026
8ebdb14
Merge the worktree path fixes of round 3 (pr16-r3-paths)
catalan-adobe Nov 29, 2026
3f7df1b
Refuse a .reviews with a .git that git cannot read: in it, in the clo…
catalan-adobe Nov 29, 2026
6a76a80
Compare the state folder with the review worktree and the clone lock …
catalan-adobe Nov 29, 2026
860f150
Remove a lock by its pid file and rmdir, never with what else its fol…
catalan-adobe Nov 29, 2026
2ce696a
Report a lock whose pid file can't be read on release, and leave it, …
catalan-adobe Nov 29, 2026
039e52c
Compare the clone key without https's default port, as the remote: a …
catalan-adobe Nov 29, 2026
84ed25d
Merge the worktree path fixes of round 4 (pr16-r4-paths)
catalan-adobe Nov 29, 2026
a0733fe
Refuse a .reviews folder below a .git that git cannot read at any dep…
catalan-adobe Nov 29, 2026
fac5a1b
Follow a path as the file system does when checking for overlaps: "<s…
catalan-adobe Nov 29, 2026
774ae49
One host name for everything kept about a PR on disk: ghe.local:443 a…
catalan-adobe Nov 29, 2026
207d684
Merge the worktree path fixes of round 5 (pr16-r5-paths)
catalan-adobe Nov 29, 2026
ca5074f
Skip a clone below a .git that git cannot read when looking one up, a…
catalan-adobe Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions: {}
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 15
permissions:
contents: read
steps:
Expand Down
78 changes: 62 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Inside a repo clone, a bare number works: `gh pr-review 42`.
| `--json` | off | With `--check`: print the decision as JSON on stdout |
| `--force-round` | off | Run a round even when the loop check stops it or nothing changed |
| `--full` | off | Review the whole PR again, as in round 1. Earlier findings are still re-checked by ID |
| `--clone <path>` | looked up | Review in a worktree of this local clone (see Artifacts) |
| `--fresh` | off | Review in a throwaway depth-50 clone in the run folder, as earlier versions did |
| `--doctor` | — | Check prerequisites and exit |

Environment variables: `GH_PR_REVIEW_MODEL` (default model),
Expand Down Expand Up @@ -118,11 +120,40 @@ only (0700), whatever the umask:
run that is still working, or that ended without posting (an error, exit 6). The run prints its folder.
- `loop-check.md`: the last loop diagnosis that stopped a run (or `--check`)
- `lock/`: held while a review of the PR runs, so a second one on this machine is refused. Its `pid` file says who
holds it, never its age: a lock whose run is gone (killed) is taken over, by one run at a time (`lock.takeover/`,
with its own `pid`, held for that moment only). A lock or `lock.takeover/` whose holder can't be established (no
`pid`, or a takeover whose run is gone) is never removed automatically: the run is refused, with the `rm -rf`
command that removes it once you know no review of the PR is running
- `pr.json`: facts about the PR kept between runs
holds it, never its age: the run that creates the `pid` file holds the lock (bash's noclobber, so one run even where
`mkdir` is not exclusive, as with uutils coreutils on Ubuntu 26.04). An empty `lock/` without one is no one's, and
is taken; one without a `pid` file that holds other files is not a lock: the run is refused, and it is left as it
is, never removed. A lock whose run is gone (killed) is taken over, by one run at a time (`lock.takeover/`, with its
own `pid`, held for that moment only). A lock or `lock.takeover/` whose holder can't be established (a `pid` file
that stays empty, or a takeover whose run is gone) is never removed automatically: the run is refused, with the
`rm -rf` command that removes it once you know no review of the PR is running
- `pr.json`: facts about the PR kept between runs: its clone, its review worktree, its head branch

The review runs in a worktree of a local clone of the repository, at
`<clone>.reviews/<host>/<owner>/<repo>/<head-branch>/<N>`, reused from round to round. The clone is `--clone <path>`,
else the config's `clones` map (`{"clones": {"<host>/<owner>/<repo>": "<path>"}}`), else the newest-fetched clone
with a matching remote under the config's `roots` (default `["~/repos"]`), else a cache clone in
`~/.cache/gh-pr-review/clones/`. A remote matches when it names the host, owner and repo; for a host with a port
(GitHub Enterprise at `ghe.local:8443`), an `https` remote must have that port, an `ssh` one any port (its own is
the SSH server's). A path inside a clone (a subfolder, a linked worktree) stands for that clone.
Shallow, partial and sparse clones are skipped, with a note, and so is a clone inside another one's working tree,
where its `.reviews` folder would land. The run fetches the PR into `refs/pr-review/<host>/<owner>/<repo>/<N>/head`
and `…/base`, and keeps each posted round's commits as `…/<N>/round-<K>`, so a force-push leaves the next round
incremental. A clone that serves a repo and its fork keeps their PRs apart. It changes nothing else in the clone: not
its branches, remote-tracking refs, `HEAD`, index, stash, config or files. `--fresh` reviews in a throwaway clone
instead. The run prints the clone it picked. The `.reviews` folder and the cache folder are yours only (`0700`), and
so are the folders and files the run makes in them: a clone kept in a private folder gets no readable copy next to it.
A worktree is reused only inside that private `.reviews` folder: a saved one elsewhere (an earlier version made it next
to a symlink to the clone, readable by others) is left as it is, with a warning that says how to remove it.
A `<clone>.reviews` that is not the tool's folder (a symlink, someone else's folder, a checkout or a folder inside
one, or a folder in it that leads elsewhere) is refused, naming it, before anything is made or changed in it.
While a review runs, it also holds the clone's lock for its PR, `<clone>.reviews/.locks/<host>/<owner>/<repo>/<N>/`
(with the same rules as `lock/`), so two runs with different state folders never use the PR's refs and review worktree
in one clone at the same time. A state folder that is the clone's lock or review worktree, holds it or is inside it
(`GH_PR_REVIEW_STATE=<clone>.reviews/.locks`) is refused before anything is made there: releasing the lock, or
cleaning the worktree, would delete the PR's history. A cache clone is made by one run at a time (others wait for it),
in a folder beside its place (`<repo>~clone.<random>`), and renamed into place once complete; one there that is not a
usable bare clone of the repo is reported and left as it is.

A run folder holds:

Expand All @@ -131,9 +162,10 @@ A run folder holds:
without its findings block, and `findings.json` the block itself
- `round.json`: the round record (see below); `posted.md`: the exact body posted
- `context/`: the PR description, the discussion and the inline review threads both passes read
- `repo/`: the checkout
- `tripwire/`: the snapshots of the checkout around each model call; `warnings.txt`, when there is one: a change in
the clone only (its refs, HEAD or stash) while the reviewer ran
- `repo/`: the checkout, with `--fresh` only
- `tripwire/`: the snapshots of the review worktree and its clone around each model call
- `warnings.txt`, when there is one: the run's warnings about its checkout, such as a dirty review worktree it reset,
or a change in the clone only (its refs, HEAD or stash) while the reviewer ran

Earlier versions wrote to `./pr-review-sessions/`; those folders are left alone. The optional config file is
`${XDG_CONFIG_HOME:-~/.config}/gh-pr-review/config.json`.
Expand Down Expand Up @@ -337,17 +369,31 @@ record a preview, and exits with code 1. Another run's review on the same
commit, by the same account, does not count. Run
`gh pr-review rounds <PR>` before retrying, so the round is not posted twice.

The reviewer (pi) works read-only. Its `git` is a wrapper that runs only the
The reviewer (pi) works read-only, in both passes (the approach and the code
review), in the review worktree. Its `git` is a wrapper that runs only the
commands that read (`show`, `diff`, `log`, `range-diff`, `status`, …) and
refuses the rest. Git hooks, credential helpers and prompts are disabled. pi
keeps its authenticated `gh` access (with `--user`, that account's token), so
the wrapper is a guard rail against mistakes, not credential isolation. A
snapshot of the review checkout (its HEAD and `git status`) is taken before
and after each model call: if the reviewer changed it anyway, the run stops
before posting, says what changed, keeps the session folder, and exits with
code 4. A checkout the snapshot can't read (its HEAD or `git status` fails),
or a snapshot that can't be saved in the session folder, stops the run the
same way: a change would go unseen.
snapshot of the review worktree (its HEAD, `git status`, its own refs and the
PR's `refs/pr-review/…` refs) and of the clone it belongs to (its refs, HEAD
and stash) is taken before and after each model call:

- A change in the review worktree, its refs or the PR's refs, or a new stash
entry made in the review worktree (on its detached HEAD: the stash is shared
with your clone), is the reviewer's: the run stops before posting, says what
changed, keeps the session folder, and exits with code 4. The checkout is
left as it is; a stash entry stays in your stash list.
- A change in your clone only (a commit, a branch, its HEAD, a stash entry on
your branch) may be your own work while the review runs: the run warns,
keeps the warning in the run folder's `warnings.txt`, and posts. A stash
entry made in your clone while it is detached at the PR head itself can't
be told from the reviewer's, and counts as the reviewer's.

With `--fresh`, the clone and the review worktree are the same throwaway
clone. A checkout the snapshot can't read (its HEAD, `git status` or stash
fails), or a snapshot that can't be saved in the session folder, stops the run
with code 4 too: a change would go unseen.

`gh pr-review <PR> --check` runs the check alone and exits 0 (run), 3 (stop)
or 5 (no new commits); `--check --json` prints the decision as JSON for
Expand All @@ -358,7 +404,7 @@ scripts. `gh pr-review rounds <PR>` shows the same decision under the history.
| 0 | Done |
| 1 | Error |
| 3 | Stopped by the loop check |
| 4 | The reviewer changed the review checkout (its HEAD or its files), or it could not be read or its snapshot saved, so a change could not be seen; nothing posted, the session is kept |
| 4 | The reviewer changed the review checkout (its HEAD, its files, its refs or the PR's refs, or it stashed there), or it could not be read or its snapshot saved, so a change could not be seen; nothing posted, the session is kept |
| 5 | No new commits since the last round |
| 6 | History changed while the review ran (someone posted another round, or a round went away); nothing posted, the session is kept |

Expand Down
46 changes: 30 additions & 16 deletions docs/superpowers/specs/2026-11-26-review-tracking-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ For `<host>/<owner>/<repo>`, in this order:

A shallow or partial (blobless) clone is skipped, with a note, and the cache clone is used instead. In such a clone,
`git show` and `git diff` fetch missing history or file contents on demand, which needs the network and the
credentials that the reviewer's git sandbox removes. The script never deepens or changes my clone to fix that.
credentials that the reviewer's git sandbox removes. A sparse clone is skipped too: a new worktree takes its patterns
and would lack files the review reads. The script never deepens or changes my clone to fix that.

`--clone <path>` overrides this for one run. `--fresh` keeps today's throwaway clone, in the state folder.

Expand All @@ -222,24 +223,27 @@ with the same per-command credential helper as today, into its own refs:

```bash
git -C "$CLONE" -c core.hooksPath=/dev/null "${GIT_AUTH[@]}" fetch --no-tags "$CLONE_URL" \
"+refs/pull/${PR_NUM}/head:refs/pr-review/${PR_NUM}/head" \
"+refs/heads/${BASE_BRANCH}:refs/pr-review/${PR_NUM}/base"
"+refs/pull/${PR_NUM}/head:refs/pr-review/${HOST}/${OWNER}/${REPO}/${PR_NUM}/head" \
"+refs/heads/${BASE_BRANCH}:refs/pr-review/${HOST}/${OWNER}/${REPO}/${PR_NUM}/base"
```

After it posts round K, it sets `refs/pr-review/<N>/round-<K>` to the reviewed head. These refs keep old commits
The refs carry the whole PR key, host/owner/repo/N (lowercase), not the number alone: one clone can serve a repo and
its fork, whose PR numbers overlap. A name part git refuses in a ref (`.github`) has its leading `.` written `%2E`.
After it posts round K, it sets `refs/pr-review/<key>/round-<K>` to the reviewed head. These refs keep old commits
alive after a force-push, so the delta between rounds is always there. The full history also ends the "no
merge-base within depth 50" failure.

### The review worktree

Path: `<clone-dir>.reviews/<head-branch-slug>/<N>`, next to the clone. For example
`~/repos/ai/adobe/skills.reviews/feat-extend-pages/823`.
Path: `<clone-dir>.reviews/<host>/<owner>/<repo>/<head-branch-slug>/<N>`, next to the clone. For example
`~/repos/ai/adobe/skills.reviews/github.com/adobe/skills/feat-extend-pages/823`.

- `<clone-dir>` is the clone's folder name: `~/repos/adobe-skills` gives `adobe-skills.reviews`.
- The slug is the PR's head branch, with `/` and other unsafe characters replaced by `-`, cut at 60 characters.
The PR number keeps fork PRs with the same branch name apart.
The PR number keeps fork PRs with the same branch name apart; host, owner and repo keep apart the PRs of a repo
and its fork that share a number.
- The run finds an existing worktree by PR number (saved in `pr.json`), so a renamed branch does not get a second one.
- Round 1: `git worktree add --detach <path> refs/pr-review/<N>/head`. Later rounds reuse it:
- Round 1: `git worktree add --detach <path> refs/pr-review/<key>/head`. Later rounds reuse it:
`git checkout --detach --force <sha>`.
- A detached HEAD also works for my own PRs, while their branch is checked out in another worktree.
- Every git command of the script runs with `-c core.hooksPath=/dev/null`, so the clone's hooks (husky, lefthook) do
Expand All @@ -261,10 +265,19 @@ objects, stash and config with my working clone. Three guards:
`range-diff`, `for-each-ref`, `describe`, `shortlog`, `status`) and refuses everything else with a clear message:
commit, checkout, switch, reset, branch, tag, stash, merge, rebase, fetch, pull, push, worktree, update-ref. It
guards against a model's mistake, not an attacker: `/usr/bin/git` with a full path gets past it.
3. **A tripwire on the review worktree.** Before and after each pi pass, the script records the worktree's `HEAD` and
`git status --porcelain`. Nobody else works there, so any change is the reviewer's. The run stops before posting,
prints what changed and saves it. With `-y` it exits with code 4. The clone's own branches and stash are compared
too, but a change there is only a warning: I may be working in the clone while a review runs.
3. **A tripwire on the review worktree.** Before and after each pi pass (the approach pass and the code review, both
run in the review worktree with the sandbox and the read-only `git`), the script records the worktree's `HEAD`,
`git status --porcelain` (every untracked file and submodule), the worktree's own refs (`refs/worktree/`,
`refs/bisect/`) and the PR's own `refs/pr-review/<key>/*`. Nobody else works there, and nothing else writes those
refs while pi runs (the run writes them before and after the passes; another PR's run, in its own folder), so any
change is the reviewer's. The run stops before posting, prints what changed and saves it: exit code 4. The same
goes for a new stash entry made in the review worktree, on its detached `HEAD` (the entry's commit says
`On (no branch)` and has that `HEAD` as its parent): the stash is shared with my clone, and nothing else stashes
there. The clone's own refs (but `refs/pr-review/`), its `HEAD` and its stash are compared too, from the clone
(`CLONE_DIR`, distinct from the review worktree `REVIEW_DIR`), but a change there is only a warning, printed and
kept in the run folder's `warnings.txt`: I may be working in the clone while a review runs, and a branch or a stash
entry made in it can't be told from mine. A stash entry I make in my clone detached at the PR head itself counts
as the reviewer's. With `--fresh`, the clone and the review worktree are the same throwaway clone.

A dirty review worktree at the start of a run is reset (`git checkout --force`, `git clean -fd`), with a warning in
the record.
Expand Down Expand Up @@ -414,7 +427,7 @@ Stopping at the first bad round would have cut short #460 and #466, which recove
| 0 | Done (posted, or printed with `--no-post`) |
| 1 | Error |
| 3 | The loop check stopped the run |
| 4 | The tripwire found a change in the review worktree; nothing posted |
| 4 | The tripwire found a change in the review worktree, its refs or the PR's refs, or a stash entry made in it; nothing posted |
| 5 | No new commits since the last round |

## Phase 4: `gh pr-review status`
Expand Down Expand Up @@ -582,7 +595,7 @@ gh pr-review gc [--dry-run] [--purge]
```

For each PR in the state folder that is merged or closed: remove its review worktree (`git worktree remove --force`),
delete `refs/pr-review/<N>/*`, remove empty `<branch>` and `.reviews` folders, and run `git worktree prune`. Records
delete `refs/pr-review/<key>/*`, remove empty `<branch>` and `.reviews` folders, and run `git worktree prune`. Records
stay, since they are small and feed the stats, unless `--purge` is passed.

## Config
Expand Down Expand Up @@ -632,8 +645,9 @@ Stub tests in `tests/`, as today:
- Loop rules: the series in the calibration table give the labels, warn rounds and stop rounds in it.
- Checkout: the clone lookup (config, scan, two clones, cache fallback), the worktree path and slug, reuse across
rounds, a detached HEAD, and hooks off.
- Guards: the git wrapper passes read commands and refuses writes; the tripwire stops a post when the worktree
changes, and only warns when a branch of the clone changes.
- Guards: the git wrapper passes read commands and refuses writes, in both passes, in the review worktree; the
tripwire stops a post when the worktree, its refs or the PR's refs change or it stashes, and only warns when a
branch, the `HEAD` or the stash of the clone changes.
- Loop check: the prompt, exit code 3 with `-y`, `--force-round`, and exit code 5 on an unchanged head.
- `status`: filters, whose-turn rules and superseded detection, on stub GraphQL output.
- Shepherd: draft and auto, own and all, the hard limits, the executor for each action with a stub `gh`, and the
Expand Down
Loading