|
| 1 | +--- |
| 2 | +name: pr-babysitter |
| 3 | +description: Set up automated PR monitoring. Watches GitHub repos for PRs with failing CI or unanswered review comments, fixes high-confidence issues automatically, and messages you when human input is needed. Triggers on "pr babysitter", "watch PRs", "monitor PRs", "pr monitor". |
| 4 | +--- |
| 5 | + |
| 6 | +# PR Babysitter |
| 7 | + |
| 8 | +Automated PR monitoring that only spawns an agent when there's actual work to do. Uses the scheduler's `pre_check` feature to run a lightweight `gh` CLI check first — zero API credits burned when all PRs are clean. |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +### 1. Verify GitHub CLI |
| 13 | + |
| 14 | +```bash |
| 15 | +gh auth status |
| 16 | +``` |
| 17 | + |
| 18 | +If not authenticated, run `gh auth login`. |
| 19 | + |
| 20 | +### 2. Ask the user |
| 21 | + |
| 22 | +Use `AskUserQuestion` for each: |
| 23 | + |
| 24 | +1. **Which repos to watch?** Accept either: |
| 25 | + - Specific repos: `owner/repo1 owner/repo2` |
| 26 | + - All repos: `gh repo list --json nameWithOwner -q '.[].nameWithOwner'` |
| 27 | +2. **How often to check?** Default: every 30 minutes (`*/30 * * * *`) |
| 28 | +3. **What to watch for?** Default: all of the below. Let user pick: |
| 29 | + - Failing CI checks |
| 30 | + - Unanswered review comments (especially from AI reviewers) |
| 31 | + - Stale PRs (no activity for 48h+) |
| 32 | +4. **Auto-fix?** Should the agent attempt high-confidence fixes (typos, linting, simple test fixes) or always ask first? |
| 33 | + |
| 34 | +### 3. Create the scheduled task |
| 35 | + |
| 36 | +Build a pre_check script and prompt based on user choices. Example for watching specific repos: |
| 37 | + |
| 38 | +```bash |
| 39 | +cat > $GHOSTCLAW_IPC_DIR/tasks/pr-babysitter_$(date +%s).json << 'TASKEOF' |
| 40 | +{ |
| 41 | + "type": "schedule_task", |
| 42 | + "pre_check": "REPOS=\"owner/repo1 owner/repo2\"; for repo in $REPOS; do gh pr list --repo $repo --state open --json number,title,headRefName,statusCheckRollup,reviewDecision,updatedAt --jq '.[] | select(.statusCheckRollup == \"FAILURE\" or .reviewDecision == \"CHANGES_REQUESTED\" or (.reviewDecision == \"\" and (.statusCheckRollup == \"PENDING\" or .statusCheckRollup == \"\")))' 2>/dev/null; done", |
| 43 | + "prompt": "You are a PR babysitter. These PRs need attention:\n\n{{pre_check_output}}\n\nFor each PR:\n1. Check CI status: `gh pr checks <number> --repo <repo>`\n2. Read review comments: `gh api repos/<owner>/<repo>/pulls/<number>/comments`\n3. If CI fails with a clear fix (linting, type error, simple test fix):\n - Clone the repo, checkout the branch, fix it, push\n - Comment on the PR: \"Fixed [issue] automatically\"\n4. If review comments are from AI reviewers and the suggestion is high-confidence:\n - Implement the change, push, reply to the comment\n5. If it needs human judgement:\n - Message me with: repo, PR number, what's wrong, what you think the fix is\n\nBe conservative. Only auto-fix things you're confident about. When in doubt, ask.", |
| 44 | + "schedule_type": "cron", |
| 45 | + "schedule_value": "*/30 * * * *", |
| 46 | + "context_mode": "isolated", |
| 47 | + "targetJid": "TARGET_JID" |
| 48 | +} |
| 49 | +TASKEOF |
| 50 | +``` |
| 51 | + |
| 52 | +Replace `TARGET_JID` with the user's chat JID (get from registered groups). |
| 53 | + |
| 54 | +### 4. Confirm setup |
| 55 | + |
| 56 | +Tell the user: |
| 57 | +- PR babysitter is active |
| 58 | +- Checking every [interval] for [repos] |
| 59 | +- Will auto-fix: [yes/no] |
| 60 | +- To pause: "pause the PR babysitter" or "stop watching PRs" |
| 61 | +- To check now: "check my PRs" |
| 62 | + |
| 63 | +## Pre-check script details |
| 64 | + |
| 65 | +The `pre_check` runs as a bash script before spawning the agent: |
| 66 | +- **Exit 0 + no output** → nothing to do, agent not spawned (free) |
| 67 | +- **Exit 0 + output** → PRs found, output passed to agent as `{{pre_check_output}}` |
| 68 | +- **Exit non-zero** → something's wrong, agent spawned to investigate |
| 69 | + |
| 70 | +The `gh pr list` with `--jq` filter only outputs PRs that actually need attention. If all PRs are green with no pending reviews, the output is empty and the agent is skipped entirely. |
| 71 | + |
| 72 | +## Customising the pre_check |
| 73 | + |
| 74 | +For users who want to watch all their repos: |
| 75 | + |
| 76 | +```bash |
| 77 | +"pre_check": "gh repo list --json nameWithOwner -q '.[].nameWithOwner' | while read repo; do gh pr list --repo $repo --state open --json number,title,headRefName,statusCheckRollup,reviewDecision --jq '.[] | select(.statusCheckRollup == \"FAILURE\" or .reviewDecision == \"CHANGES_REQUESTED\")' 2>/dev/null; done" |
| 78 | +``` |
| 79 | + |
| 80 | +For users who only care about failing CI (not review comments): |
| 81 | + |
| 82 | +```bash |
| 83 | +"pre_check": "gh pr list --repo owner/repo --state open --json number,title,statusCheckRollup --jq '.[] | select(.statusCheckRollup == \"FAILURE\")'" |
| 84 | +``` |
| 85 | + |
| 86 | +## Managing the babysitter |
| 87 | + |
| 88 | +- **Pause**: Update task status to `paused` via IPC or ask the agent |
| 89 | +- **Resume**: Update task status to `active` |
| 90 | +- **Change repos**: Cancel old task, create new one with updated pre_check |
| 91 | +- **Run now**: User can say "check my PRs now" — agent runs the same prompt manually |
0 commit comments