Drain prs

From jikig-ai/soleur · View interactive version

Drain prs is an AI agent skill from the GitHub repository jikig-ai/soleur. This skill should be used when draining open GitHub PRs: triage them into mergeable tiers, confirm scope with the operator, then fix and merge the green ones. The PR-counterpart to drain-labeled-backlog.

How to use this skill

Skill file

<!-- soleur-cloud-mode:start -->

Cloud Mode (Devin): before pipeline work run bash "${CLAUDE_PLUGIN_ROOT}/scripts/cloud-detect.sh". If CLAUDE_PLUGIN_ROOT is unset (cloud exec shells do not export it), resolve the root by IDENTITY, never by script basename: for d in "$HOME/.local/share/devin/cli/plugins/cache" and /opt/.devin/plugins, skip unless [ -d "$d" ], then MANIFEST="$(find "$d" -path '*/.claude-plugin/plugin.json' -exec grep -l '"name"[[:space:]]*:[[:space:]]*"soleur"' {} + 2>/dev/null | head -1)", ROOT="${MANIFEST%/.claude-plugin/plugin.json}" — one resolution, two consumers: $ROOT/scripts/cloud-detect.sh and $ROOT/scripts/precommit-guard.sh. (Shape check, not authentication: a planted {"name":"soleur"} dir passes — ADR-179 A11.) local or not-local:no-devin-env proceeds normally; any other not-local:<reason> applies <plugin-root>/devin/INSTRUCTIONS.md §Cloud Mode: emit the --banner, fan out sequentially with Reviewed-Coverage: sequential-fallback disclosure (never claim an independent review ran), message_user ack before any secrets read or production mutation, and run precommit-guard.sh before any git commit — hooks do not fire in cloud.

<!-- soleur-cloud-mode:end -->

<!-- grok-harness-invoke:start -->

Grok Build (plugins/soleur/lib/harness.ts invokeSkill()): Read this SKILL.md in this process and run it to completion. A one-segment soleur:<name> in this document names a SKILL — on Grok Build, Read plugins/soleur/skills/<name>/SKILL.md in this process; it is not a nested tool_use. A multi-segment id such as soleur:<domain>:<name> names an AGENT: spawn it, never Read it, and on Grok Build spawn_subagent takes the id with its colons replaced by hyphens (agentIdToGrokSubagentType). Claude Code: Skill tool for a skill (soleur:<name>), Task tool with subagent_type for an agent. Forbidden is executing a subset, not the Read.

<!-- grok-harness-invoke:end -->

Drain PRs

Triage all open remote GitHub PRs and drain the mergeable ones in one operator-confirmed pass: enumerate → triage into tiers → confirm scope → fix each in-scope PR to green → merge. The PR-counterpart to drain-labeled-backlog (which drains labeled issues). Distilled from the 2026-06-30 drain session that merged 11 PRs across tiers.

When to use

Use merge-pr for a single named PR. Use drain-labeled-backlog for labeled issues (not PRs). Use this skill to drain the open-PR queue.

<decision_gate>

Merging is outward-facing — confirm before any merge. This skill confirms tier scope with the operator via AskUserQuestion before merging anything, and supports per-PR opt-out within a tier (not just per-tier accept/reject). Confirming a tier means the selected PRs are squash-merged to main — this is not a preview; it lands code (higher irreversibility than the issue-drain, which ends at PR-opened). Respects wg-zero-agents-until-user-confirms.

API budget. Arming any PR that carries no passing review evidence, bot PRs included, delegates to soleur:review, which spawns review agents which run autonomously and spend non-trivial Anthropic credit against the key in your session, scaling with PR count and review-cycle depth. The --dry-run flag prints the full tier table with zero merges and zero delegation. Soleur does not bill or proxy these calls — Anthropic does. The Soleur LICENSE (BSL 1.1) disclaims warranty for runtime cost; you operate this loop against your own budget.

</decision_gate>

Prerequisites

Arguments

<arguments> #$ARGUMENTS </arguments>

Optional flags (any subset):

Workflow

1. Prerequisites check

Verify gh and jq are on PATH (abort with installation guidance if missing). Verify the current directory is a git repository: git -C . rev-parse --git-dir >/dev/null 2>&1 — git errors clearly on non-repo paths, so a fail-fast precheck beats a confusing downstream error.

2. Enumerate + triage

Delegate to the helper triage-prs.sh:

bash "${CLAUDE_PLUGIN_ROOT}/skills/drain-prs/scripts/triage-prs.sh"

The helper runs gh pr list --state open --json number,title,headRefName,isDraft,mergeable,reviewDecision,labels,author,createdAt,statusCheckRollup (two-stage gh --json … | jq, never gh --jq with --arg — learning 2026-04-15-gh-jq-does-not-forward-arg-to-jq) and classifies each PR into eight tiers:

| Tier | Signal | Default handling |

|------|--------|------------------|

| ready-green | mergeable=MERGEABLE, no failing/pending checks | arm through the arm check (§4) |

| needs-lockfile-fix | deps PR (labels has dependencies) failing guards-ruleset (its lockfile-sync member) / test-webplat / e2e on a frozen-install step | fix-recipe (a) → merge |

| needs-conflict-resolution | mergeable=CONFLICTING, few/no other failures | fix-recipe (b) → merge |

| needs-review | bot-fix/review-required label, or a feature PR with no review | delegate to soleur:review, which posts the evidence §4's arm needs (an inline read cannot arm, §5) → merge |

| ready-unarmed | ready PR whose head verdict (ci-head-verdict.sh) is no-run or stalled: no full CI run exists, the red test row is the draft run's. awaiting-approval is not here: it lands in needs-review (the line shows ci=awaiting-approval; a maintainer must approve the fork run) | recover, never arm, unless another session is still inside wait-ready-run for it: gh pr ready --undo <N>, then the whole ready block (ready-run-wait.md), then re-triage |

| drafts | isDraft=true | skip — author-owned WIP, never merged. A draft that also carries parked stays here, flagged parked: true in the JSON and PARKED label (held for the operator) on its text line, and is never readied even when the operator names it |

| parked | has the parked label ("Reviewed draft held until an approved window; do not merge or arm auto-merge") | skip — reviewed and held for the operator; never merged, never armed, never fixed here. The operator removes the label. A parked draft is classified under drafts (drafts are classified first). The parked-hold member step of the required secret-guards check (scripts/ci-parked-hold.sh, #12396) fails while the PR carries the label, which binds auto-merge, the merge queue and every non-bypass identity, and admin-merge-ready.sh reads it as a red required context; it does not stop an admin-credentialed gh pr merge --admin, and anyone with triage access can remove the label. .claude/hooks/ship-operator-step-gate.sh stays as local defence in depth on a branch that carries it; a draft PR remains the first hold. The tier prints a recovery: line saying to do nothing (no other tier carries one except ready-unarmed). The label match is case-insensitive, like the hook's |

| broken | CONFLICTING and many failing checks | surface; fix only if in explicit scope |

Pass --dry-run to stop here and print the table.

3. Decision gate (confirm scope)

Present the tier table via AskUserQuestion. The operator selects which tiers to drain and may opt individual PRs out within a tier. Nothing merges until this returns. (See the <decision_gate> block above for the irreversibility + budget framing.)

4. Per in-scope PR — ensure green, then merge

For each selected PR: bring it to green via the fix-recipes below if needed, then arm it through the arm check (under the merge queue this ENQUEUES the PR; it is not yet merged). A ready-unarmed PR (readied, but no full CI run exists) is NOT armed: recover it first (gh pr ready --undo <N> with a user token, then the whole block below; GITHUB_TOKEN cannot ready a PR). A draft the operator authorizes is readied the same way and armed only once K=$(bash "${CLAUDE_PLUGIN_ROOT}/scripts/ci-head-verdict.sh" ready-count <N>) && gh pr ready <N> && bash "${CLAUDE_PLUGIN_ROOT}/scripts/ci-head-verdict.sh" wait-ready-run <N> --before-count "$K" exits 0 (one Bash call, timeout: 420000; reasons and recoveries: ready-run-wait.md); on non-zero report "readied but unarmed" with the last stdout line and arm nothing:

The arm. Every PR takes this one arm. Run the arm check's first statement from review-evidence-comment.md, both PR_NUMBER tokens replaced by the PR number, after the fetch, then the arm, all in one Bash call. The fetch puts the PR head in the local object store, which the check's merge-base needs:

git fetch -q origin "pull/<N>/head" || { echo "fetch of PR <N>'s head failed: not armed"; exit 1; }
# REPLACE THIS LINE with the arm check's first statement (linked above), PR_NUMBER replaced by <N>; it exits 1 on refusal
gh pr merge <N> --squash --auto --match-head-commit "${H:?run the arm check in this call}"

On a refusal, including a bot PR that carries no evidence, run soleur:review on the PR (it posts fresh evidence), then the same call again. If it still refuses, skip the PR and list it in the §7 report as unarmed: evidence=<…> unreviewed=<…>, copying the two values the refusal line printed (the check's variables do not survive the call). Never arm around it. The check cannot see code written while resolving a merge conflict (it skips merge commits), so a PR onto which drain-prs pushed a hand-resolved merge goes to soleur:review before this arm, even when the check passes. First-party bot PRs normally arm themselves server-side; drain-prs arms one only when autoMergeRequest is null.

5. Review delegation

Every PR drain-prs arms needs a passing Review-Evidence comment covering its head, and only soleur:review posts one, so a PR without one is delegated to soleur:review before §4's arm, whatever its size or author. That includes feature PRs (needs-review), single-file priority/p3-low bot-fixes, bot-authored scheduled content PRs (community digests, the campaign calendar, content-distribution promotes, weakness digests) and bot-fix PRs carrying bot-fix/review-required. A read of gh pr diff <N> is triage, not review: it can decide to skip a PR, never to arm one.

6. Fix-recipes

See knowledge-base/project/learnings/workflow-patterns/2026-06-30-update-branch-drifts-lockfiles-and-npm11-pin.md and knowledge-base/project/learnings/workflow-patterns/2026-06-30-stale-bot-cron-pr-hallucinated-api-and-registration-sweep.md for the full failure analyses.

```bash

cd apps/web-platform

npx --yes npm@11 install --package-lock-only # package-lock.json — npm@11 ONLY

```

The lockfile-sync member of the guards-ruleset CI umbrella pins npm@11; regenerating package-lock.json with local npm produces a divergent shape and fails the gate. On a lockfile merge conflict, resolve by regenerating (git checkout --ours -- <lockfiles> then re-run), not by hand-picking hunks.

7. Cleanup + report

Arming returns at ENQUEUE, not at merge. Run cleanup-merged only once the PRs it should reap read MERGED. Wait on each enqueued PR with a BOUND (90 polls x 60s, the Phase 7 cap), through the Monitor tool (set timeout_ms to its maximum, or persistent: true where the tool offers it: the default is 5 minutes and the watch can run past that, including a 10-minute hold on a BLOCKED PR; when it expires, check the process is gone before re-arming) / AwaitShell (a BLOCKED line alone is not the end on the read path: keep waiting for the SOLEUR_CI_REQUIRED_SET marker or a REQUIRED-SET READ — line; never a backgrounded loop): bash "${CLAUDE_PLUGIN_ROOT}/scripts/monitor-pr-checks.sh" <N> --interval 60 --max-polls 90. It reads the merge queue (sync-pr-behind.sh <N> --queue-state) and ends MERGED, or LEFT THE MERGE QUEUE UNMERGED with the removal reason (the dequeue arm above: ONE re-enqueue, then report), or a timeout, or CHECKS GREEN BUT BLOCKED for an armed, green, un-queued PR held by something outside the check list (after a 10-minute hold, followed by the required-context read: RECOVERY hints and a SOLEUR_CI_REQUIRED_SET marker, read per ready-run-wait.md; wait for the exit before re-arming); it never syncs or pushes. A watch that exits 4 (DUPLICATE MONITOR) means a live monitor already watches that PR (a re-run drain re-arms every enqueued PR, so this is the expected outcome there). If that watch is a Monitor or AwaitShell task of THIS session, it is still your watch: read its output. Otherwise it reports to a session that may be gone: read the queue once with sync-pr-behind.sh <N> --queue-state (a dequeued answer is the dequeue arm below; gh pr view cannot show a silent dequeue), keep the PR in the set awaiting MERGED, never count it as done, and never loop on that read. To hear the outcome yourself, confirm ps -o args= -p <pid> names monitor-pr-checks.sh, kill <pid> (that ends the other session's watch with no verdict line, so that session must read the PR state rather than re-arm), and arm once. An enqueued PR that never reaches MERGED is that dequeue arm, not a merged PR:

bash "${CLAUDE_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh" cleanup-merged

Report the drain delta: before/after open-PR count and the per-tier outcome (merged / enqueued / skipped / deferred), listing an enqueued PR as enqueued until it reads MERGED, then one line per PR §4 refused (#<N> unarmed: …) and one per PR whose head fetch failed (#<N> unarmed: fetch failed; not a refusal, so no soleur:review retry).

Pipeline detection

If $ARGUMENTS contains a RETURN CONTRACT section (i.e., this skill is being driven by another skill), run headless: skip the interactive decision gate and --dry-run prompts; drain only tiers explicitly named via --tiers. Follows the same pattern as plan, review, and ship.

Sharp edges

Test

Unit tests live at drain-prs.test.sh. Run them with:

bash plugins/soleur/test/drain-prs.test.sh

Covers: one synthetic PR per tier (ready-green, lockfile-fail, conflicting, review-required, draft, broken, parked, including a parked conflicting PR with failing checks, a parked dependencies PR with a failing check, a parked PR whose head verdict is no-run, a Parked capitalised label, a parked draft carrying parked: true, and a parked-old decoy label), the head-verdict rows (ready-unarmed, pending-full / decided / awaiting-approval, resolver error), an empty-list case, and the tier-grouped JSON output shape.

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.