AGENT SKILL

review-pr

Cross-review a pull request by number or URL without checking it out. Runs a native Workflow panel with per-finding verification, then posts verified findings as a draft PR review. Required lane failures remain incomplete.

License 许可
MIT
所属仓库
0xgleb/dotconfig
最近更新
2026-11-14
Stars
★ 3
Forks
0

01 前言 Front Matter

name
review-pr
description
Cross-review a pull request by number or URL without checking it out. Runs a native Workflow panel with per-finding verification, then posts verified findings as a draft PR review. Required lane failures remain incomplete.
allowed-tools
Bash(gh:*), Bash(git:*), Bash(command:*), artifact_provenance, Bash(cat:*), Bash(mktemp:*), Bash(rm:*), Bash(wc:*), Bash(uuidgen:*), Bash(basename:*), Bash(test:*), Bash(grep:*), Bash(find:*), Read, Write, Agent, Workflow, Skill
argument-hint
<pr-number | pr-url>
user-invocable
true

03 SKILL.md 正文

Cross-review a pull request that is not currently checked out. The PR number or URL is passed in $ARGUMENTS. Use when you're reviewing someone else's PR and want independent native review lanes before commenting.

The review engine (panel, probes, prompts, the review-panel Workflow, finding output) is shared with /review-loop and /review-sweep and lives in ~/.claude/skills/review-core/SKILL.md. This skill scopes the diff to the PR (without checking it out) and, after the engine returns findings, posts the verified findings as a draft (pending) PR review and then converses so you can adjust before submitting. It never modifies code, and never submits the review verdict — you do that in the GitHub UI.

Follow these steps precisely.

1. Parse the argument

$ARGUMENTS must be a PR number (e.g. 123), a full GitHub URL (https://github.com/owner/repo/pull/123), or an owner/repo#123 shorthand. If $ARGUMENTS is empty, use the PR associated with the current branch.

Normalize to (owner, repo, number) using gh:

pr_ref="$ARGUMENTS"

if [ -z "$pr_ref" ]; then
  # No argument — use the PR for the currently checked-out branch
  pr_json=$(gh pr view --json number,title,author,headRefName,baseRefName,url,body,headRepository,baseRepository,headRefOid,baseRefOid,state,isDraft,additions,deletions,changedFiles)
else
  case "$pr_ref" in
    https://github.com/*) ;;
    */*\#*)              ;;  # owner/repo#n
    [0-9]*)              ;;  # bare number (use current repo)
    *) echo "Unrecognized PR reference: $pr_ref"; exit 1 ;;
  esac
  pr_json=$(gh pr view "$pr_ref" --json number,title,author,headRefName,baseRefName,url,body,headRepository,baseRepository,headRefOid,baseRefOid,state,isDraft,additions,deletions,changedFiles)
fi

If gh pr view fails (e.g. no PR exists for the current branch), stop and tell the user — they need to either pass a PR reference or check out a branch that has an open PR.

Record the fields from the JSON: number, title, author.login, headRefName, baseRefName, url, body, headRefOid, baseRefOid, state, isDraft, changedFiles, additions, deletions, and the owner/name of the head and base repos.

If the PR is closed, merged, or draft, warn the user and ask whether to continue. Proceed only on explicit confirmation.

2. Prepare the workspace

Resolve repo_root from the checkout assigned to this review. When using a linked review worktree, run setup there: every patch, prompt, report, payload, and log belongs under that worktree's .tmp/, never the main checkout's .tmp/. A coordinator running elsewhere must pass the verified review-worktree root to workflows and explicitly set every child's cwd to that root. Do not derive artifact paths from the coordinator's cwd or the shared Git directory, or fall back to the main checkout. Remove temporary artifacts with the worktree. This does not authorize creating a worktree or checking out the PR.

repo_root=$(git rev-parse --show-toplevel) || exit 1
invocation_id=$(uuidgen) || exit 1
safe_branch=$(echo "<headRefName>" | tr '/' '_')
out_dir="$repo_root/.tmp/reviews/pr-${pr_number}-${invocation_id}-${safe_branch}"

Before creating the invocation directory or writing any artifact, apply GLOBAL_AGENTS.md's directory-ignore preflight, including state capture and separate repair accounting, to this invocation path:

git check-ignore --verbose "$repo_root/.tmp/" "$out_dir/diff.patch"

Then call the registered artifact_provenance tool with the resolved absolute value of out_dir:

{ "action": "create_directory", "path": "<resolved absolute out_dir>" }

Require successful creation and provenance recording before writing descendants. Use an available registered harness equivalent if its tool name differs; do not fall back to raw mkdir. Add crossWorkspace: true only for an independently authorized target outside the tool session's workspace. The native UUID supplies the invocation namespace; the creation API does not promise exclusive allocation. Artifacts remain local-only and ephemeral.

3. Fetch the diff

Fetch the PR diff from GitHub — do not check out the PR:

gh pr diff "<pr-ref>" > "$out_dir/diff.patch"
gh pr view "<pr-ref>" --json files --jq '.files[] | "\(.additions)\t\(.deletions)\t\(.path)"' > "$out_dir/files.txt"
wc -l "$out_dir/diff.patch"

Refuse to proceed if the diff is empty. Diff size is not an approval gate and must not reduce review depth. For large diffs, follow review-core's bounded chunking and track complete retained-code and removal-boundary coverage. Inspect deleted code only as needed to verify surviving behavior, compatibility and removal effects; do not spend a review pass re-auditing intentional deletions. Preserve completed reviews and recover only missing chunks or context.

Also save the PR metadata and the author's description:

echo "$pr_json" > "$out_dir/pr.json"

Strip bot-appended footers from the description before passing it to the engine: cut everything from the first HTML-comment footer marker onward (CodeRabbit / Codesmith badges, tracking links). Reviewers should see only the author-written text.

4. Fetch the head ref for context

The reviewers need to read source files that the diff references, even if they're not changed by the PR. Fetch the head ref into the local repo without switching branches:

head_owner_repo="<owner>/<repo>"   # from headRepository.nameWithOwner
head_sha="<headRefOid>"

# If the PR is from a fork, add the fork as a remote
git remote add pr-review-head "https://github.com/${head_owner_repo}.git" 2>/dev/null || true
git fetch pr-review-head "$head_sha"

# Now reviewers can resolve paths at that commit via `git show $head_sha:<path>`

If the PR is on the same repo, skip the remote-add step; the fetch is enough.

5. Load project context

find "$repo_root" -maxdepth 3 \( -name "CLAUDE.md" -o -name "AGENTS.md" \) \
  -not -path "*/node_modules/*" -not -path "*/target/*"

Keep only the paths — they become docsPaths for the engine.

6. Run the review engine

Run every review, inspector, verifier, Markdown and synthesis lane through Pi's classified workflow with authenticated openai-codex/gpt-6.1-sol. Do not launch external model CLIs or substitute another provider/model. If required execution is unavailable, preserve incomplete evidence and the exact blocker, not a clean result.

Run the shared engine in ~/.claude/skills/review-core/SKILL.md (steps 1–7: available lanes → reviewer prompts → inspector prompts → the review-panel Workflow → after-workflow handling → print findings). Pass the contract inputs:

Contract input Value for review-pr
out_dir, {DIFF_PATH}, {FILES_PATH}, {REPO_ROOT} from steps 2–3 ($out_dir/diff.patch, $out_dir/files.txt)
{PROJECT_DOCS_PATHS} the docs paths from step 5
{PR_DESCRIPTION} the author's description (bot footers stripped) from step 3
{SOURCE_ACCESS} The change was authored against commit <head_sha>. Read source files via 'git show <head_sha>:<path>' — the working tree does not match the change under review.
{SOURCE_REVISION} the exact lowercase hexadecimal <head_sha> from verified PR metadata
{SCOPE_NOTE} The diff is scoped to exactly the changes on this PR.
{INSPECTOR_ARG} the PR reference (<pr-ref>)
{REPORT_HEADER} # Review — PR #<n>: <title>\n**Author:** <author>\n**URL:** <url>\n**Branches:** <head> -> <base>\n**Head SHA:** <head_sha>\n**Files changed:** <N> (+<additions>/-<deletions>)
{TERMINAL_HEADER} PR #<n> — <title>\n<author> · <head>..<base> · <N> files, +<add>/-<del> lines\n<url>
{SYNTHESIS_EXTRA} CRITICAL ADAPTATIONS FOR THIS REPORT: (1) No AI references anywhere — no agent attribution, no 'Found by' field, no mention of models, reviewers, lanes, or cross-review. The report must read like a single human senior engineer wrote it. (2) Frame the Overall assessment as advice to the REVIEWER reading this report, not to the PR author — e.g. 'This PR looks ready to merge pending X' or 'I'd push back on Y before approving.'
{INCLUDE_ATTRIBUTION} false

Pass the typed source object explicitly in the Workflow args:

"sourceRevision": "<head_sha>"

The shared engine validates that value as a 40–64 character lowercase hexadecimal Git object ID before exposing Bash to native lanes. Those lanes may use Bash only for exact read-only git show '<head_sha>:<repo-relative-path>' calls. They must never read .env*, credential stores, private keys, or certificates, and must not use Bash for checkout, worktree creation, mutation, or unrelated commands.

{INCLUDE_ATTRIBUTION} being false makes the engine strip the Found by field from review.md and drop the lane bracket from the terminal output — the on-disk findings.json keeps found_by for local audit only. With {SOURCE_ACCESS} threaded into the workflow, the in-panel verifier and synthesizer read source at the head SHA via git show, not the (mismatched) working tree.

The engine writes $out_dir/review.md and $out_dir/findings.json and prints the terminal summary. Then continue to the conversation below — do not triage or fix anything; this skill only comments.

7. Post the draft batch, then converse

After the engine prints, immediately post the verified findings as a draft batch — this is the default, with no approval gate and no waiting. Create one PENDING (draft) GitHub review with every verified finding as an inline comment (see "Posting a draft review" below). You only ever create the draft; you NEVER submit the review verdict (approve / comment / request changes) — the user does that in the GitHub UI.

Then stay in the session so the user can take it from there. Tell them the draft is up and print the overall assessment as a copy-paste block. Say something like:

Draft review posted to <pr-url> with N inline comments — inspect, edit, or delete in the UI, then submit the verdict yourself when ready. Paste this into the summary box on submit:

<overall assessment — 2-3 sentences>

Want me to dig into any finding, or add/drop comments before you submit?

For any follow-up:

  • "tell me more about #N" — read the full finding from review.md and explain it conversationally. Read the relevant source via git show $head_sha:<path> to confirm the claim yourself.
  • "is finding #N actually valid?" — verify by reading the code at the head SHA. Report your independent read.
  • "drop #N" / "add a comment about X" — update the still-pending draft (delete or add the relevant inline comments via the API, or tell the user to do it in the UI). Never submit the review.
  • "I'm done" — summarize what's in the draft and end the turn. The user submits the verdict themselves.

If the user ever says "don't post yet" (or similar) up front, skip the auto-post and converse first — but the default on invocation is to post the batch.

Posting a draft review

Create a PENDING GitHub review with each verified finding as an inline comment on its file/line. This lets the user go to the GitHub UI, inspect each comment, edit or delete as needed, and click "Submit review" themselves — you never submit it.

Step 1 — Build the comments JSON. For each finding, create an inline comment object. Use the finding's file path and line number from the review.

Comment tone rules:

  • Write like a human colleague leaving a quick review comment. Short, direct, conversational.
  • No numbered prefixes like #1, **#2 (HIGH)**, etc. Just say what the issue is.
  • No em dashes. Use commas, periods, or "because" instead.
  • Start each comment with a lowercase severity prefix that signals how important the finding is: critical:, should fix:, minor:, or nit:. This replaces bold labels and numbered prefixes. The prefix is short and natural, like a colleague would write.
  • No bullet-point lists inside a single comment unless genuinely needed. Prefer short paragraphs.
  • Keep each comment to 2-4 sentences. Say what's wrong, why it matters, and what to do about it.

Leave the review body empty. Do NOT post the overall assessment to the draft — GitHub would attach it as the review summary, and the user wants to write/paste that themselves at submit time. You'll print the assessment in the conversation in Step 2 instead.

# Build the review payload as a JSON file.
# "body" is intentionally empty — the overall assessment is displayed in
# the conversation (Step 2), not posted to the draft.
review_json="$out_dir/pending-review.json"
cat > "$review_json" <<'ENDJSON'
{
  "commit_id": "<head_sha>",
  "body": "",
  "comments": [
    {
      "path": "<file relative to repo root>",
      "line": <line number in NEW file>,
      "side": "RIGHT",
      "body": "<finding description + suggested fix>"
    }
  ]
}
ENDJSON

For findings that span a range, use start_line + line:

{
  "path": "src/foo.rs",
  "start_line": 10,
  "line": 15,
  "side": "RIGHT",
  "body": "..."
}

Step 2 — Post via the Reviews API.

gh api repos/<owner>/<repo>/pulls/<pr-number>/reviews \
  --input "$review_json"
rm "$review_json"

CRITICAL: Omit the event field entirely to create a PENDING review. The GitHub API does NOT accept "event": "PENDING" — it returns a 422. Omitting event is what makes the review a draft.

This creates a draft review visible only to you (the reviewer) until submitted. Tell the user the draft is up, then print the overall assessment in the conversation as a fenced copy-paste block so they can paste it into the review summary box when they submit from the GitHub UI:

Draft review created with N inline comments. The overall summary is not part of the draft — paste this into the review summary box when you submit:

<overall assessment — 2-3 sentences>

Go to <pr-url> to inspect, edit, or delete comments, then click "Submit review."

CRITICAL: line must be a line present in the diff hunk, not any arbitrary line in the file. To find the right line number:

  • Read the diff ($out_dir/diff.patch) and identify the +-side line number within the changed hunk that best matches the finding
  • If the finding points to a line NOT in the diff, use the nearest related changed line in the same file. Never fall back to a top-level review body.

Step 3 — Handle findings without diff lines. Use only inline comments over top-level body text. If a finding references unchanged code, look for a related changed line in the diff where the comment makes sense contextually. For example, if a finding is about an interaction between existing code and newly introduced code (e.g., "the existing reconciler doesn't account for the new compaction policy"), place the comment on the new code that introduces the interaction, not on the untouched code. Only when a finding has genuinely no related changed code anywhere in the diff (e.g., a missing file, a documentation gap, a broad architectural concern), fold it into the copy-paste assessment block you print in the conversation (Step 2) rather than the posted body — the draft body stays empty.

Hard rules

  1. Never check out the PR branch. Work off gh pr diff and git show at the head SHA.
  2. review.md has no per-finding agent attribution ({INCLUDE_ATTRIBUTION} is false). Attribution stays in findings.json only.
  3. Only ever create a PENDING (draft) review (event omitted). Submitting the review verdict — approve / comment / request changes — is the user's alone, done in the GitHub UI; never submit a verdict yourself, even if asked. The draft needs no per-comment approval — the UI is where the user inspects, edits, deletes, and submits.
  4. Always use --body-file (or heredoc to a tempfile) for comment bodies.
  5. Stay in the session after the engine prints — this command is a conversation, not a one-shot.
  6. If the PR is closed/merged/draft, ask before proceeding.
  7. Posted reviews must read like a human wrote them. No AI references (models, agents or model/provider identities). No numbered finding prefixes (#1, **#2 (HIGH)**). No em dashes. No bold severity labels. Use lowercase severity prefixes (critical:, should fix:, minor:, nit:). Write short, direct comments like a colleague would. The findings.json and review.md on disk can use structured formatting (they're local), but anything posted to GitHub must be conversational and concise.
  8. Maximize inline comments; the draft body stays empty. Never post the overall assessment to the draft review — leave body empty and print the 2-3 sentence assessment in the conversation as a copy-paste block for the user to paste at submit time. Every finding should be an inline comment on a diff line. When a finding references unchanged code, place the comment on the nearest related changed line.
  9. For ordinary body-only correction, update only the evidenced review's top-level body to the empty string and preserve its inline comments. If the user explicitly identifies the entire agent-created review as accidental and orders full cleanup, delete only the exact evidenced accidental review and its inline comments. Never replace the body with a marker, apology, zero-width text, or other content. Try the exact supported deletion once before reporting it impossible; retain the API error, continue any independently executable cleanup, and identify GitHub support escalation if submitted-review deletion or emptying is rejected.
  10. The review runs as a single Workflow invocation (review-core), using read-only native openai-codex/gpt-6.1-sol lanes. Do not launch external model CLIs or substitute another provider when a required lane is blocked.

04 同仓库更多 Skills

0xgleb
0xgleb/dotconfig

worktree

Manage worktrees only for concurrent work by the owner or agents launched by the owner on the same repository, or for explicitly requested inventory and cleanup; never create one for isolation alone.

★ 3
0xgleb
0xgleb/dotconfig

unslop

Rewrite draft prose before owner-facing replies, docs, issues, PR text, handoffs, or Telegram reports to remove AI tells while preserving facts, links, tone, and authority; auto-trigger on externally visible prose, but never on code, commands, logs, tool output, quoted sources, or user text.

★ 3
0xgleb
0xgleb/dotconfig

threat-model-first

Use at the START of a change that moves money, changes balances or custody, touches access control or signing, deserializes untrusted input, adds an external or on-chain integration, or wires an LLM tool. Design-time threat modeling that turns abuse cases into the first failing tests; it precedes the post-hoc security-review pass.

★ 3
0xgleb
0xgleb/dotconfig

test-inspector

Auto-run for new or changed retained behavior, even without test changes, and for test, fixture, snapshot or mock changes; verify real happy-path and error-path coverage, expose false-confidence assertions and over-mocking, but do not perform general production-code correctness review.

★ 3
0xgleb
0xgleb/dotconfig

strong-typing-inspector

Lightweight review — flags primitives used where a domain type already exists (e.g. String for a USD field when Usd exists) and missed newtype opportunities.

★ 3
0xgleb
0xgleb/dotconfig

spec-review

Critique existing specifications and design proposals, including whether their approach or addition is justified, and refine them through adversarial Pi review and authorized author revisions. Not for code review, implementation-plan sequencing, creating a design from scratch or minor copy edits.

★ 3