agentleFS
mthinesmthines/agent-skills/skills/delivery/prepare/SKILL.md

prepare

Skill22 starsChanged 33 days agoMITView on GitHub

Gets a PR, and every PR stacked above it, green without new work: resolves merge conflicts, fixes failing CI, and applies unresolved review comments, in that order, then confirms CI; --merge squash-merges bottom to top once every gate passes. Triggers on "get this PR green", "prepare this PR", "make the stack mergeable", "fix and merge", "/prepare".

  • Deletes or force-pushes
  • Commits and pushes

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When a PR has more than one child, order by depth, then PR number.

    line 38
  2. Very specific:

    If no PR needs work and every PR ran CI, print Already green (without --merge) and stop.

    line 70
  3. Very specific:

    If a Skill() call is refused, apply that skill's contract inline rather than skipping the step.

    line 95
  4. Distinctive:

    Do not stop after the first PR, even when it was already green.

    line 97
  5. Distinctive:

    If a rebase conflict is not one you can resolve with confidence, stop and ask.

    line 100
  6. Distinctive:

    Never: start new work, refactor, or re-review.

    line 119

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Prepare

Gets one PR, and every open PR stacked above it, to green: no conflicts, passing CI, no unresolved review threads. It delegates each fix to an existing skill and starts no new work.

Arguments

Parse $ARGUMENTS: the first non-flag token is the PR, everything else is a flag.

ArgumentDefaultEffect
<pr-url|#n>the current branch's PR (gh pr view --json url -q .url)The bottom PR of the job.
--mergeoffAfter the fixes, squash-merge bottom to top behind explicit gates. Read and follow rules/merge.md.
--singleoffOnly this PR; skip the stack walk.

Step 0: Resolve scope

  1. Set PRS to the given PR.
  2. Unless --single, walk up: for each PR in PRS, run gh pr list --base <its head branch> --state open --json number,url,headRefName, and append the results. When a PR has more than one child, order by depth, then PR number.
  3. PRS is now ordered bottom to top, which is also merge order.

Step 1: Check state

For each PR in PRS:

gh pr view <n> --json mergeable,mergeStateStatus,statusCheckRollup,reviewDecision,headRefName,baseRefName
node "${CLAUDE_SKILL_DIR:-$HOME/.claude/skills/prepare}/scripts/threads.mjs" --pr <pr-url>

threads.mjs prints THREADS: clear|open|pending — <reason> last, naming each unresolved thread (outdated ones count); exit 0 only for clear.

A PR needs work when mergeable is CONFLICTING, any check is failing, or any review thread is unresolved.

A check still running is not green: gh pr checks <n> --watch first, then decide. Then classify the head's CI with the bundled helper; its last line is the answer, its exit code 0 only for green:

node "${CLAUDE_SKILL_DIR:-$HOME/.claude/skills/prepare}/scripts/ci-ran.mjs" --pr <pr-url>   # CI: green|pending|red|not-run — <reason>

CI ran when at least one required check completed without being skipped, or, when the head reports no required check, at least one GitHub Actions check run did. External commit statuses and other apps' checks (Vercel, security scanners) never prove CI ran on their own, unless the repo marks one required. CI: not-run (a repo that skips CI on drafts) → report CI not run (<its reason>), never green, and do not merge it.

✗ draft PR, 16 checks SKIPPED, 2 Vercel statuses SUCCESS, none failing → Already green
✓ #41 CI not run (CI not run at b56dfb5: every required check skipped (4))

If no PR needs work and every PR ran CI, print Already green (without --merge) and stop. Under --merge, skip Step 2 and go to the merge step.

Step 2: Fix, bottom to top

Work one PR at a time, bottom first, and finish it before moving up. gh pr checkout <n> before touching any PR other than the one already checked out. Skip every step that does not apply:

OrderConditionRun
1Merge conflictsStart the update, then Skill("resolve-conflicts") (below)
2Failing CISkill("ci-auto-fix", "<pr-url>")
3Unresolved review threadsSkill("implement-suggestion", "<pr-url> --resolve-all")

resolve-conflicts only resolves a merge or rebase that is already in progress, and previews against origin/main otherwise. So for row 1, start the update against the PR's own base first, so a stacked PR is compared with its real base:

git fetch origin <baseRefName>
git rebase origin/<baseRefName>   # stops on conflicts; resolve-conflicts takes it from there

Once the rebase finishes, git push --force-with-lease.

If a Skill() call is refused, apply that skill's contract inline rather than skipping the step. A push to a lower PR can create conflicts or red CI above it, so after every push re-run Step 1 for the PRs above. Do not stop after the first PR, even when it was already green.

Rebases use --force-with-lease, never --force. If a rebase conflict is not one you can resolve with confidence, stop and ask; do not resolve unfamiliar conflicts to make the stack green.

Step 3: Confirm

Watch CI on each PR's new head: gh pr checks <n> --watch. A PR that is not passing after the fixes is reported as blocked, with the reason.

Step 4: Report

One line per PR:

#1 already green · #2 fixed CI · #3 resolved conflicts · #4 CI not run (every required check skipped)

Say Already green only when every PR in scope is, and never for a PR whose CI did not run.

Hard rules

  • Never start new work, refactor, or re-review.
  • Never weaken a check to get CI green.
  • Never merge without --merge.
  • Never merge a PR that sits above one that is still open.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.