Pr captain merge

From the-agency-ai/the-agency · View interactive version

Pr captain merge is an AI agent skill from the GitHub repository the-agency-ai/the-agency. Captain-only. Merge a PR safely — true merge commit (never squash, never rebase), branch protection respected, --principal-approved gate for --admin override. Prevents the "accidentally squashed via the wide GitHub UI button" failure mode that has burned the fleet.

How to use this skill

Skill file

<!--

allowed-tools omitted — inherits Bash(*) from .claude/settings.json.

Subcommand-level restriction (e.g. Bash(gh pr merge *)) silently blocked

fleet agents in the past (flag #62/#63 / devex dispatch #171).

This skill legitimately calls gh + agency/tools/pr-merge + agency/tools/git-*

— narrow tool-level restriction would work but would need maintenance as

called tools evolve. Inherit Bash(*) is safer.

-->

pr-captain-merge

Captain's safe wrapper for merging PRs on GitHub. Always a true merge commit (no squash, no rebase). Respects branch protection by default. --principal-approved is the only way to engage --admin override.

Name pattern: pr- prefix groups with the PR skill family (autocomplete /pr<tab> shows the full kit), captain- qualifier makes captain-only scope visible at a glance.

Why this exists

Raw gh pr merge is too easy to misuse:

pr-captain-merge is the gate — skill-level enforcement plus the underlying agency/tools/pr-merge tool that does the actual work.

Required reading

Before running, Read the files in required_reading: frontmatter. GIT-MERGE-NOT-REBASE.md explains why we never squash or rebase. SAFE-TOOLS.md covers the safe-tool family this skill composes.

Usage

/pr-captain-merge <pr-number>
/pr-captain-merge <pr-number> --principal-approved
/pr-captain-merge <pr-number> --delete-branch
/pr-captain-merge <pr-number> --dry-run

Preconditions

If any precondition is missing, STOP. Ask the principal to resolve, or use the non-approved path and let branch protection block.

Flow / Steps

Step 1: Pre-flight

  1. Confirm the PR number (ask if missing).
  2. Confirm you're not on the PR's branch — captain merges from master or any non-PR branch.
  3. If you're going to use --principal-approved, confirm the principal has authorized in THIS conversation. Don't infer from history.
  4. Check for pending post-merge (C#372 Fix B). Run ./agency/tools/post-merge-state check. If exit 1, STOP — a prior PR was merged but its release hasn't been cut yet. Run /pr-captain-post-merge <pending-PR> first, then re-invoke this skill. New work cannot start while a prior PR is in pending state. Exit 0 → continue.

Step 2: Invoke the tool

./agency/tools/pr-merge <N>

Or with explicit principal approval (only when they verbally OK'd in-session):

./agency/tools/pr-merge <N> --principal-approved

Tool enforces:

Step 3: Handle the outcome

On success (exit 0): report merge URL + next-step recommendation (sync master via ./agency/tools/_sync-main-ref, or wait for /pr-captain-post-merge).

On branch-protection block (exit 3): tool prints the gate. Two resolutions:

On merge conflict (exit 1): resolve locally first:

gh pr checkout <N>
./agency/tools/git-safe merge-from-master --remote
# resolve conflicts
./agency/tools/git-safe add <files>
./agency/tools/git-captain merge-continue
./agency/tools/git-push <branch>
# then retry
/pr-captain-merge <N>

Step 4: Post-merge (handoff or chain)

After successful merge:

Failure modes

What this does NOT do

Why never squash, never rebase

Both rewrite history. The-agency framework is built on visible, append-only history:

Cost: heavier git log output. Benefit: you can SEE what happened and WHY, which is essential when fleet agents and adopters all have to read the same history.

Captain-only — three-layer defense

Defense in depth against accidental invocation from the wrong context:

  1. paths: [] (intentionally empty) — no file-path auto-activation; universally discoverable for the captain but scoped out of worktree contexts.
  2. Name contains captain- — any reader sees scope in the skill listing.
  3. Runtime precondition — underlying agency/tools/pr-merge checks caller context before engaging --admin.

(Historically disable-model-invocation: true was a fourth layer. That flag was removed 2026-04-20 because the captain session IS the principal's session — DMI was blocking the captain from invoking captain-* skills. See REFERENCE-SKILL-CONVENTIONS.md §1.)

Status

active — ships as of agency-skill-version 2 adoption 2026-04-19. Replaces v1 pr-merge skill.

Related

OFFENDERS WILL BE FED TO THE — CUTE — ATTACK KITTENS!

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.