Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3ab069e
Read severity sections only in the Issues section, outside folded det…
catalan-adobe Nov 27, 2026
53eb73f
Give a backfilled code review without a severity section unknown coun…
catalan-adobe Nov 27, 2026
443b1b4
Read a marker without the full counts from its review's Markdown
catalan-adobe Nov 27, 2026
a2ae6f1
Count * and + list items as findings
catalan-adobe Nov 27, 2026
21f1968
Test round 5 under every marker shape marker_line emits
catalan-adobe Nov 27, 2026
7683de1
Give a record read from its Markdown the backfill source
catalan-adobe Nov 27, 2026
075eb54
Document when a round is read from its Markdown
catalan-adobe Nov 27, 2026
4b5ce13
Open a details block only at the start of a line
catalan-adobe Nov 27, 2026
fb61181
Track code fences inside folds and count only structural details tags
catalan-adobe Nov 27, 2026
ac96184
Read headings indented by up to three spaces
catalan-adobe Nov 27, 2026
5203275
Keep a partial marker's last_ids as the floor of its own round
catalan-adobe Nov 27, 2026
1959462
Keep the IDs of a marker whose counts are malformed
catalan-adobe Nov 27, 2026
446614f
Give a parsed review with no severity section unknown counts
catalan-adobe Nov 27, 2026
f760c78
Read only the code review of a body for its counts, sections and find…
catalan-adobe Nov 27, 2026
3c17934
Approve automatically only after a successful check of the blocker count
catalan-adobe Nov 27, 2026
d9a1b20
Describe the comment fallback as an unknown blocker count
catalan-adobe Nov 27, 2026
58d4b02
Document the scope of the Markdown reader
catalan-adobe Nov 27, 2026
6bffbcf
Test the marker shape without last_ids against a conservative ID floor
catalan-adobe Nov 27, 2026
8e786b6
Mark the code review with a boundary line and read it from there
catalan-adobe Nov 27, 2026
d51649d
Build the posted record again when the final check turns an approve i…
catalan-adobe Nov 27, 2026
7dff1b5
Run the overlap test on both minimal marker shapes
catalan-adobe Nov 27, 2026
7e40fca
Describe the Markdown as the cross-check for the findings block
catalan-adobe Nov 27, 2026
3ed98c6
Document how an older minimal marker can shift later finding IDs
catalan-adobe Nov 27, 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
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Inside a repo clone, a bare number works: `gh pr-review 42`.
| `--no-post` | posting on (with confirm) | Print the review only |
| `--instructions <text>` | none | Extra guidance for both passes, for example `"Focus on db/; skip style nits"`. For a file: `--instructions "$(cat notes.md)"`. The tool does not post them, and the reviewer is told not to quote them, but the review can still reflect them: use `--no-post` to preview a review shaped by sensitive notes |
| `--skip-approach` | off | Skip the maintainer's approach pass and run the code review only, for example when the approach is already agreed |
| `--decision <d>` | from verdict | `comment`, `approve`, `request-changes`. Unset: an approach verdict of Rethink → request-changes. Otherwise the last "Ready to merge?" line decides: No → request-changes, a bare Yes → approve, anything else (Yes with fixes, Yes, with fixes, …) → comment. On your own PR it is always comment. `-y` submits the decision without asking |
| `--decision <d>` | from verdict | `comment`, `approve`, `request-changes`. Unset: an approach verdict of Rethink → request-changes. Otherwise the last "Ready to merge?" line decides: No → request-changes, a bare Yes → approve (comment when the round's blocker count is unknown, as for a code review read from its Markdown with no severity section; a valid empty findings block is a known zero, and approves), anything else (Yes with fixes, Yes, with fixes, …) → comment. On your own PR it is always comment. `-y` submits the decision without asking |
| `-y`, `--yes` | off | Skip the confirmations. A loop-check stop then exits with code 3, and no new commits with code 5, instead of asking |
| `--check` | off | Run only the loop check (see below) and exit 0, 3 or 5. No clone, no model call |
| `--json` | off | With `--check`: print the decision as JSON on stdout |
Expand Down Expand Up @@ -152,8 +152,13 @@ a contributor, to a token that cannot see that membership: their rounds are
then left out. `--force-round` still runs a round the loop check would not.

`gh pr-review rounds <PR-URL | PR-number>` prints that history, one row per
round. Reviews posted before the records existed are read back from their
Markdown (`backfill`):
round. Reviews posted before the records existed, and records without the full
counts the tool writes (a review too long for them, or a damaged marker), are
read back from their Markdown (`backfill`). Only the code review is read: the
text after the invisible `<!-- gh-pr-review:code-review -->` line the tool posts
before it, without the footer (a review posted before that line existed is read
whole). Severity headings count only in its Issues section, and a folded
`<details>` list ("Fixed since the last round") holds no open findings:

```
ROUND DATE COMMIT +COMMITS APPROACH READY CRIT IMP MINOR LABEL SOURCE
Expand All @@ -162,6 +167,20 @@ ROUND DATE COMMIT +COMMITS APPROACH READY CRIT IMP MINOR LA
next round: stop · churning · approach-stuck too-big · Settle the approach before the next round: …
```

The Markdown is the cross-check for the model's findings block: it is parsed
before the block is accepted, and a block that leaves out a blocker the Markdown
shows, or has one where it says none, is rejected. It is also the source when
the block is rejected, and for a review without a usable marker. The reader
follows the format the tool asks the model for (the `### Issues` section with
severity headings, findings as list items, the folded Fixed and Later lists,
each `<details>` tag on its own line), and is best effort for other Markdown:
fences nested in longer fences, HTML before `</details>` on the same line,
headings nested in list items.

After an upgrade, a round read from a minimal marker (a review over 60,000
characters) written by an older version can number later findings differently,
if that version counted its findings differently.

`+COMMITS` counts the PR's commits whose commit date falls between the
previous round's review and this one's. It is a date window, not the commits
between the two reviewed heads: a commit pushed while a review runs can be
Expand All @@ -170,7 +189,7 @@ counted toward that review instead of the next one.
The label says whether the loop converges: `early` (fewer than 3 rounds),
`converging`, `ready`, `nit-loop` (a few Important findings that keep coming
back) or `churning`; `unknown` when a round's record has no blocking count and
neither its findings nor its Markdown can rebuild one (never read as 0, so
its Markdown has no severity section to rebuild one from (never read as 0, so
never `ready`). `--json` prints the records and the decision; `-u <login>`
picks the gh account, as for a review.

Expand Down
85 changes: 58 additions & 27 deletions gh-pr-review
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,13 @@ instructions_section() {
printf 'on the PR.\n\n%s\n\n' "$INSTRUCTIONS"
}

# The posted body: the approach section, then the code review, then one footer. Empty in, empty out.
assemble_review() {
# The posted body: the loop line, the approach section, then the code review, then one footer. Empty in, empty out.
# The code review starts with an invisible boundary line (code_review_boundary in lib/records.jq): the reader reads
# the code review from there, as the writer reads it.
assemble_review() { # <loop-line> <approach> <code-review>
local parts=() part
for part in "$@"; do [[ -n "$part" ]] && parts+=("$part"); done
for part in "$1" "$2"; do [[ -n "$part" ]] && parts+=("$part"); done
[[ -n "$3" ]] && parts+=($'<!-- gh-pr-review:code-review -->\n'"$3")
[[ ${#parts[@]} -eq 0 ]] && return 0
parts+=($'---\n'"*Review generated by gh pr-review · model: ${MODEL}*")
printf '%s' "${parts[0]}"
Expand Down Expand Up @@ -883,12 +886,15 @@ REVIEW=$(assemble_review "$LOOP_LINE" "$APPROACH" "$CODE_REVIEW")
# round.json starts as a preview; the post block turns it into the posted round. A failure here never blocks the post.
# It runs under `if !`, where errexit is off: every step checks its own status, and the record is checked before use.
write_round_record() {
local findings parsed source=model code_review=true approach ready meta tmp="${RECORD_FILE}.tmp"
local findings parsed source=model code_review=true no_sections=false approach ready meta tmp="${RECORD_FILE}.tmp"
if [[ "$APPROACH_VERDICT" == rethink ]]; then
code_review=false
findings='[]'
else
# The Markdown's findings: the fallback, and the check that the block shows every blocker the review does.
# The Markdown is the code review alone (review-body.md), never the approach or the footer: the reader of the
# posted review reads the same text, after its boundary line (code_review_part in lib/records.jq).
# The Markdown's findings: the check that the block shows every blocker the review does, and the source when
# the block is rejected.
# A parse failure leaves a parsed record without findings, as the spec says: it never blocks the post.
parsed="${RECORD_FILE}.parsed"
parse_findings "$REVIEW_BODY_FILE" >"$parsed" 2>/dev/null || echo '[]' >"$parsed"
Expand All @@ -904,6 +910,9 @@ write_round_record() {
fi
source=parsed
findings=$(jq -c . "$parsed") || findings='[]'
# No severity section in the Markdown: the blockers are unknown (null counts), as when read back.
no_sections=$(jq -Rs -L "$LIB_DIR" 'include "records"; _sections | length == 0' "$REVIEW_BODY_FILE") ||
no_sections=true
fi
rm -f "$parsed"
fi
Expand All @@ -916,12 +925,12 @@ write_round_record() {
--argjson number "$PR_NUM" --argjson round "$ROUND" --arg reviewer "$ME" --arg model "$MODEL" \
--arg base "$BASE_SHA" --arg head "$HEAD_SHA" --argjson previous "$PREVIOUS_RECORD" \
--arg approach "$approach" --arg ready "$ready" --argjson code_review "$code_review" \
--argjson id_floor "$ID_FLOOR" \
--argjson id_floor "$ID_FLOOR" --argjson no_sections "$no_sections" \
'{source: $source, pr: {host: $host, owner: $owner, repo: $repo, number: $number}, round: $round,
mode: "full", reviewer: (if $reviewer == "" then null else $reviewer end), model: $model,
base_sha: $base, head_sha: $head, previous_head_sha: ($previous.head_sha? // null),
approach: $approach, ready: $ready, decision: null, posted_at: null,
code_review: $code_review, preview: true, id_floor: $id_floor}') || return 1
code_review: $code_review, preview: true, id_floor: $id_floor, no_sections: $no_sections}') || return 1
if ! build_record "$meta" "$findings" "$PREVIOUS_RECORD" |
jq --argjson loop "$LOOP" --argjson forced "$FORCED" \
'.loop = ($loop | {label, flags, decision}) | .forced = $forced' >"$tmp"; then
Expand Down Expand Up @@ -997,6 +1006,30 @@ review_landed() {
| length == 1' <<<"$json" >/dev/null 2>&1
}

# True only when the record file shows how many blockers its round has: a numeric counts.open_blocking. An unknown
# count (a code review read from its Markdown without a severity section), a missing file or a failed read is false:
# an automatic approve needs this to succeed.
known_blockers() { # <record-file>
jq -e '(.counts.open_blocking | type) == "number"' "$1" >/dev/null 2>&1
}

# The final record: round.json as posted, with DECISION, built and checked here. Only a record that passes is
# posted: a preview that went missing, empty or invalid since it was written is no record.
posted_record() {
POSTED_RECORD=""
[[ -n "${RECORD_FILE:-}" ]] || return 0
if [[ -s "$RECORD_FILE" ]] &&
jq --arg decision "$DECISION" --arg at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'.decision = $decision | .posted_at = $at | .preview = false' "$RECORD_FILE" >"$RECORD_FILE.posted" 2>/dev/null &&
jq -e 'type == "object" and (.round | type == "number") and (.counts | type == "object")' \
"$RECORD_FILE.posted" >/dev/null 2>&1; then
POSTED_RECORD="$RECORD_FILE.posted"
else
echo "Warning: could not write the posted round record; the review is posted without it." >&2
rm -f "$RECORD_FILE.posted"
fi
}

if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then
if [[ -z "$DECISION" && "${APPROACH_VERDICT:-}" == rethink ]]; then
DECISION=request-changes
Expand All @@ -1013,10 +1046,14 @@ if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then
*) DECISION=comment ;;
esac
echo "Verdict: ${VERDICT:-not found} → ${DECISION}"
# An approval says the findings were checked; without a record nothing can show that, so only comment.
# An approval says the findings were checked; without a record nothing can show that, so only comment. Nor
# can a record whose blocker count is unknown (known_blockers): that round is not ready.
if [[ "$DECISION" == approve && -z "${RECORD_FILE:-}" ]]; then
DECISION=comment
echo "No round record for this review: posting as comment, not approve."
elif [[ "$DECISION" == approve ]] && ! known_blockers "$RECORD_FILE"; then
DECISION=comment
echo "The review's blockers are unknown: posting as comment, not approve."
fi
fi

Expand Down Expand Up @@ -1085,27 +1122,21 @@ if [[ "$POST_TO_PR" == "true" ]] && [[ -n "$REVIEW" ]]; then
echo "Posting as comment, not approve: an approval must cover the PR's head."
fi

# The final record: round.json as posted, built and checked here. Only a record that passes is posted: a preview
# that went missing, empty or invalid since it was written is no record.
POSTED_RECORD=""
if [[ -n "${RECORD_FILE:-}" ]]; then
if [[ -s "$RECORD_FILE" ]] &&
jq --arg decision "$DECISION" --arg at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'.decision = $decision | .posted_at = $at | .preview = false' "$RECORD_FILE" >"$RECORD_FILE.posted" 2>/dev/null &&
jq -e 'type == "object" and (.round | type == "number") and (.counts | type == "object")' \
"$RECORD_FILE.posted" >/dev/null 2>&1; then
POSTED_RECORD="$RECORD_FILE.posted"
else
echo "Warning: could not write the posted round record; the review is posted without it." >&2
rm -f "$RECORD_FILE.posted"
posted_record
# Right before posting: an automatic approve (the verdict's, or its default taken at the prompt) needs a posted
# record that shows its blocker count (known_blockers); otherwise it posts as comment, and the record is built
# again with that decision, so the event, the marker and round.json all say comment. An approve someone chose
# stays.
if [[ "$DECISION" == approve && "$AUTO_DECISION" == true ]]; then
if [[ -z "$POSTED_RECORD" ]]; then
DECISION=comment
echo "No round record for this review: posting as comment, not approve."
elif ! known_blockers "$POSTED_RECORD"; then
DECISION=comment
echo "The review's blockers are unknown: posting as comment, not approve."
posted_record
fi
fi
# Right before posting: without a posted record, an automatic approve (the verdict's, or its default taken at the
# prompt) posts as comment. An approve someone chose stays.
if [[ "$DECISION" == approve && "$AUTO_DECISION" == true && -z "$POSTED_RECORD" ]]; then
DECISION=comment
echo "No round record for this review: posting as comment, not approve."
fi

MARKER=""
if [[ -n "$POSTED_RECORD" ]]; then
Expand Down
Loading