agentleFS
xmtplabsxmtplabs/code-factory/skills/babysit-pr/SKILL.md

babysit-pr

Skill1 starsChanged 6 months agoMITView on GitHub

Use when monitoring one PR or a whole stack of PRs until it is ready — fixing CI failures, responding to review comments, resolving merge conflicts, and pushing verified fixes autonomously in a long-running loop. Works with Graphite (gt) stacks, GitHub stacked PRs (gh stack), and standalone branches.

  • Commits and pushes

22 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use file-pr, codex-review and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • ShlomiPorushSkill

    file-pr

    Review the current Git branch and file a concise, non-draft pull request that follows the repository's contribution rules and Shlomi's Git workflow. Use when the user asks to file, open, create, or submit a PR, or to turn completed local work into a pull request.

    Also in 4 projects that use this

  • xfstudioSkill

    codex-review

    Professional code review with auto CHANGELOG generation, integrated with Codex AI

    Also in 3 projects that use this

  • MicrosoftSkill

    handoff

    Compact the current conversation into a handoff document for another agent to pick up.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 21 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    New commits only: Never --amend, never force-push history you didn't create, in an unattended loop.

    line 12
  2. Very specific:

    Read the matching reference before using backend commands: references/graphite.md or references/gh-stack.md.

    line 29
  3. Very specific:

    Stale-CI guard: if the failing run's SHA ≠ current HEAD_SHA, treat as PENDING — never dispatch a second fixer for a superseded run.

    line 54
  4. Very specific:

    Give-up guard: if fixAttempts[branch:check] ≥ 2 on fresh SHAs, stop fixing that check — report it as needing a human and exclude it from …

    line 55
  5. Distinctive:

    Iteration cap: stop after 12 iterations regardless (≈ a couple of hours) and report where things stand — an unattended loop that can't …

    line 68

“Common” is measured: kept by at least 6 in 10 of the 21 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

Babysit PR

Monitor a PR — or an entire stack — in a loop: snapshot status, fix the highest-priority issue, verify locally, push once, sleep, repeat, until every PR is ready or you hit a give-up guard. Built for unattended operation: every iteration works from persisted state, one action at a time, with hard limits on retries.

Hard rules (read first)

  • New commits only. Never --amend, never force-push history you didn't create, in an unattended loop. (Exception: Graphite's gt modify --commit and restacks are the stack-native equivalent and are allowed on Graphite stacks.)
  • Never git add -A / git add . — stage the files you changed, by name.
  • Never merge the PR, never --no-verify, never disable or skip a failing test to get to green.
  • Only act on checks for the HEAD commit (HEAD_SHA from the snapshot). Stale failures from superseded commits are noise — treat them as PENDING.
  • Every reply starts with "🤖 " so humans can tell it's the babysitter.
  • Resolve only threads whose issue you actually fixed. Scope changes and disagreements stay open for the human.
  • Fix bottom-up in stacks. A fix in a lower branch may cure higher branches after restacking; fixing high first gets overwritten.
  • One push per iteration. Apply all fixes across the stack locally, then push the whole stack once.

Backend detection (once, at session start)

if [ -f .git/.graphite_repo_config ] || gt ls >/dev/null 2>&1        → GRAPHITE
elif gh stack view --json >/dev/null 2>&1                            → GH-STACK
else                                                                 → STANDALONE

Read the matching reference before using backend commands: references/graphite.md or references/gh-stack.md. Standalone needs no reference — plain git + gh. The four verbs that differ:

VerbGraphitegh-stackStandalone
list stack (bottom→top)gt lsgh stack view --jsoncurrent branch only
switch to branchgt checkout <br>gh stack checkout <br>git checkout <br>
commit a fixgt modify --commit -m "..."git add <files> && git commitgit add <files> && git commit
propagate + push allgt restack && gt submit --stackgh stack rebase --upstack && gh stack submit --autogit push

State file (cold-turn memory)

Persist .git/babysit-pr-state.json (inside .git/ so it can never be committed) and update it every iteration — a wakeup has no memory of the last one:

{ "iterations": 3, "lastHeadShas": {"<branch>": "<sha>"},
  "fixAttempts": {"<branch>:<check-name>": 2}, "handledComments": ["<id>", "..."] }

Session loop

Each iteration does exactly one of the following, chosen by the first match top-down, then updates the state file, prints what it did and the chosen sleep, and sleeps.

  1. Snapshot. For each branch in the stack (bottom→top) with a PR, run scripts/check-pr.sh <pr> <repo-dir> — greppable KEY=VALUE output; judgment stays here, parsing stays in the script. With 3+ PRs, fan the snapshots out to parallel subagents. Skip branches without PRs. No PRs anywhere → exit with an error.
  2. Merge conflicts first (MERGEABLE=CONFLICTING anywhere): resolve on the lowest conflicted branch — conflicts block CI from meaning anything. Rebase per backend (see reference); resolve markers, verify, commit, propagate up, push once.
  3. CI failures (CI=FAIL on the HEAD commit, lowest affected branch first):
    • Stale-CI guard: if the failing run's SHA ≠ current HEAD_SHA, treat as PENDING — never dispatch a second fixer for a superseded run.
    • Give-up guard: if fixAttempts[branch:check] ≥ 2 on fresh SHAs, stop fixing that check — report it as needing a human and exclude it from further iterations.
    • Otherwise: dispatch one subagent per failing check to fetch logs (gh run view <run-id> --log-failed) and diagnose — CI logs are verbose; isolating them keeps this context clean. Fix at the root cause, run targeted local verification (lint/typecheck changed files, run only the tests exercising them — consult the repo's CLAUDE.md/AGENTS.md for scoped commands), commit, increment fixAttempts, propagate, push once. Required checks gate readiness; optional-check failures are best-effort.
  4. Review feedback (unresolved threads, review bodies, conversation comments — fetch all three buckets; reviewers put their most important feedback in top-level review bodies, not inline). Skip anything resolved, authored by the babysitter (🤖), or in handledComments. Triage each remaining item:

    TypeAction
    Real defectFix, verify, commit. Reply "🤖 Fixed — <what changed>", resolve thread.
    Question / misunderstanding / non-issueReply "🤖 <concrete answer citing code>". Leave open. No code changes.
    Scope change, style preference, architectural askReply "🤖 Flagged for the PR author — outside this babysitter's mandate." Leave open, record for the final report.

    Subjective or architectural feedback is never silently implemented — judge the code, not the confidence of the comment (bots included: CodeRabbit, Copilot, Greptile, Bugbot are frequently out of scope).

  5. All quiet → check the exit condition; if not met, sleep on the long interval.

Iteration cap: stop after 12 iterations regardless (≈ a couple of hours) and report where things stand — an unattended loop that can't converge in 12 rounds needs a human.

Sleep intervals

SituationSleep
Just pushed; CI hasn't picked up the new SHA2 min
CI running, started < 15 min ago3–5 min
CI running, long-running suite5 min
All green, waiting on human reviewers10 min
No actionable items, PR not fully ready5 min

Across a stack, use the shortest applicable interval. Print Sleeping {N} min — {reason} first. In a plain shell loop use sleep <seconds>; in Claude Code prefer scheduled wakeups (/loop or ScheduleWakeup) over a blocked foreground sleep — same cadence, cheaper.

Exit condition

Every PR in the stack: all required checks passing on HEAD, every review thread resolved-or-answered (🤖 reply is the last word), every review body and conversation comment addressed. Optional-check failures don't block — note them and declare ready. Print: "All required checks passing and all review comments addressed across the stack. PRs are ready." Then report anything parked by give-up guards or flagged as needing the author.

Common mistakes

MistakeFix
Fixing a check that failed on a superseded commitStale-CI guard: compare run SHA to HEAD_SHA first
Re-fixing the same check foreverGive-up guard: 2 strikes per check on fresh SHAs, then escalate
Replying twice to the same commentCheck handledComments and whether the last reply is 🤖
Pushing per-branch during a stack passFix everything locally bottom-up, push once
Missing top-level review bodiesFetch all three comment buckets, not just inline threads
Forgetting to propagate after a mid-stack fixRestack/rebase-upstack before touching the next branch; then re-check higher PRs — the restack itself can break them
Implementing a reviewer's architectural suggestionThat's the author's call — reply, flag, leave open
Trusting this session's memory of previous iterationsThe state file is the memory; read it, update it, every iteration
Fetching CI logs into the main contextOne subagent per failing check; keep this context for decisions

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.