Pr shepherd

From KjellKod/quest · View interactive version

Pr shepherd is an AI agent skill from the GitHub repository KjellKod/quest. Shepherd an existing PR through CI and review comments, then mark ready for review when clean.

How to use this skill

Skill file

PR Shepherd

Shepherd an existing PR through CI and review comments, then mark ready for review when clean.

At activation, announce the skill name and scope in one line. Example: [pr-shepherd] shepherding PR #97.

See .skills/review-anti-patterns.md for the shared rule set.

Default Commenting Mode

Use inline-first commenting by default.

Procedure

Step 1: Locate Existing PR

pr-assistant owns draft PR creation and PR body updates. If no PR exists for

the current branch, stop and ask the user to run pr-assistant first.

Accepted targets:

Use inspection-first checkout:

python3 scripts/quest_pr_shepherd_checkout.py [<target>] --json

This command must not mutate the current worktree unless --apply is supplied.

If the current branch already matches the PR head branch, it returns

action: "none" and must not run gh pr checkout.

Only use mutation when the user explicitly targets a different PR and the

worktree is clean:

python3 scripts/quest_pr_shepherd_checkout.py <target> --apply --json

Dirty worktrees block mutation paths, not read-only inspection.

Step 1.5: Commit/Push Context Guard

Before every commit or push performed by this skill, verify that the local

workspace still matches the PR branch:

  1. Run git status --short --branch.
  2. Run git branch --show-current.
  3. If a PR already exists, run gh pr view <PR_NUMBER> --json headRefName --jq .headRefName.
  4. If a PR already exists, confirm the current branch exactly matches the PR

headRefName; otherwise, before PR creation, confirm the current branch is

the intended branch for this PR.

  1. If shepherding from a known worktree, verify the current directory/repo root

is that worktree before committing.

  1. If branch or workspace verification fails, stop and ask the user to confirm

the intended workspace before editing, committing, or pushing.

  1. After workspace verification, sync with the remote default branch from this

PR worktree using the shared helper only when the worktree is clean. If the

worktree is dirty because a local fix is being prepared, do not apply sync

over those edits; finish and validate the fix commit first, then rerun this

guard before pushing:

python3 scripts/quest_pr_sync_default_branch.py --strategy merge --apply --json.

Merge is the default shepherd strategy because it avoids rewriting an

under-review PR's commit SHAs and preserves inline review-thread anchoring.

specific hunks when they are available. The inspect path can be

filename-only; when hunks or conflict markers are not available, pause

instead of guessing. Resolve only clearly safe, non-destructive conflicts

(additive / adjacent / whitespace / import-or-list ordering where nothing

from main is dropped); otherwise pause and ask the human. Never use

blanket -X theirs or -X ours.

surface the reason and message fields. Do not continue shepherding from

a stale or partially checked sync state.

helper payload: push with git push --force-with-lease when

force_with_lease: true; otherwise push normally. This is the same narrow

lease-protected own-PR-branch exception documented in

.skills/pr-assistant/SKILL.md under Force-with-lease exception.

This guard is mandatory before:

Step 2: Wait for CI

Use a hard polling budget for CI waits:

Loop:

  1. Run gh pr checks <PR_NUMBER> to get the current status.
  2. Stop when all checks are green, a confirmed failure is present, or the polling budget is exhausted.
  3. If checks are still pending and budget remains, sleep 30 seconds before the next retry.

Step 3: Evaluate CI Results

Step 4: Check PR Comments

  1. Collect compact records-shaped intake:
  1. Normalize and annotate:
  1. For each comment, respond on the comment itself (threaded reply), never move an inline discussion to the general PR thread:
  1. Decision per comment:

Step 4.4: Canonical Intake → Decisions → Validation → Batches → Push

Run the review loop through the canonical review-intelligence pipeline. Order matters: validation steps must be attached to backlog items before batching, otherwise build-fix-batches falls back to one-item batches keyed by finding_id and the "batched PR response" behavior is lost.

  1. Collect one intake payload per cycle:
  1. Normalize intake to canonical findings:
  1. Annotate changed-line scope:
  1. Build decision backlog with shared policy:
  1. Select concrete validation per actionable finding and persist onto the backlog:
  1. Build actionable non-overlapping batches:
  1. Execute one batch at a time:
  1. Classify loop stop after each cycle:

Step 4.5: Inline Commenting Playbook

Use this for every inline review reply so comments feel coaching-oriented and actionable.

Inline posting defaults:

Comment formula:

  1. Start with a small positive anchor.
  2. Name the issue precisely (what and why).
  3. Suggest a concrete fix (or two).
  4. Keep tone warm; humor is optional and brief.

Example shape:

Nice cleanup here. One issue: <specific issue>. Could we <specific fix>?

Tone rules:

Inline scope rules:

Severity labels (optional but recommended):

Signature requirement for every posted review comment:

- Reviewed by <model>, in collaboration with <github username>

Ready-to-use template:

Nice improvement here. One issue: <issue>. This can cause <impact>. Suggestion: <specific change>.

- Reviewed by <model>, in collaboration with <github username>

Step 4.6: Decision Policy Alignment

When reducing findings to actionable buckets, align with .skills/review-decisions/SKILL.md:

Step 5: Re-check CI (if changes were made)

If any fixes were pushed in Step 4, loop back to Step 2.

Step 6: Mark Ready for Review

Once CI is green AND all comments are addressed:

gh pr ready <PR_NUMBER>

Only run this from operational state clean.

Inform the user the PR is ready for their review.

Key Principles

Command Invocation

Run gh commands directly — not through bash -lc, sh -c, or other shell wrappers.

Permission prefixes (e.g. ["gh","pr"]) only match when gh is the top-level command.

Wrapping in a shell defeats prefix matching and triggers repeated permission prompts.

Use shell wrappers only when you need pipes, redirects, or multi-command composition.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.