Skip to content

Latest commit

 

History

History
148 lines (116 loc) · 26.7 KB

cli-usage.md

File metadata and controls

148 lines (116 loc) · 26.7 KB

pr-shepherd interfaces

← README

Reference for the pr-shepherd shell commands and flags. The CLI and the local stdio MCP server (mcp.md) share one workflow model and emit the same deterministic action; the MCP server returns structured data, the CLI renders text or JSON.

Canonical shell commands

pr-shepherd --version | -v
pr-shepherd --help | -h
pr-shepherd [PR ...] [poll-flags] [iterate-flags]
pr-shepherd stack PR [PR ...] [--once] [--merge | --merge-ready | --merge-through PR] [poll-flags] [iterate-flags]
pr-shepherd iterate [PR ...] [iterate-flags]
pr-shepherd apply merge [PR] --require-sha SHA --merge-action ACTION [--method M] [--expected-stack JSON] --transport rest
pr-shepherd apply review [PR] [review-flags]
pr-shepherd apply files [PR] [files...] [--tests] [--match REGEX]
pr-shepherd apply journal [PR] <item> [--dry-run] [--format text|json]
pr-shepherd apply journal [PR] --file <path> [--dry-run] [--format text|json]
pr-shepherd apply journal [PR] --file - [--dry-run] [--format text|json]
pr-shepherd apply check-blocker [PR] --check <name> --blocked-by <ref>
pr-shepherd apply check-blocker [PR] --check <name> --clear
pr-shepherd apply queue-removal [PR] --require-sha SHA --queue-commit SHA --removed-at UNIX
pr-shepherd journal extract --body-file <path>
pr-shepherd playbook [name] [--format text|json]
pr-shepherd suggest [PR] --thread-id ID --message MSG [groups...]
pr-shepherd admin clean <pr|stack|branch|current|repo|all> [value] [--dry-run] [--format text|json]
pr-shepherd admin log-file [--format text|json]
pr-shepherd admin watch-status <PR> [--format text|json]

PR may be a number, owner/repo#N, or a GitHub pull request URL. Multiple explicit PRs must resolve to one repository. pr-shepherd stack PR selects the complete native GitHub stack containing that PR, ordered bottom to top, but a single PR owns only itself; a stack number (stack owner/repo#N) owns every layer, and stack PR PR ... owns only the listed PRs of one stack (ownership is declared, not derived from the author). A caller that opened every layer lists them all, or names the stack number. Refs spanning several stacks fail with one exact command per stack. When PR is omitted, Shepherd infers the current branch's open PR. A qualified PR selects the GitHub target; the working directory stays the local git, config, rules, and log context.

Command What it does
pr-shepherd [PR ...] Bounded poll dispatcher (one PR or an explicit set). See Polling.
stack Bounded poll of one PR's native GitHub stack; --once runs one tick. See Aggregate commands.
iterate One tick for one PR, or one aggregate tick for several, with nextCheck. Use it when the caller owns recurrence (cloud.md).
apply merge Submit or resume one SHA-guarded asynchronous REST merge or enqueue request. Requires --transport rest.
apply review Reply to, resolve, minimize, and dismiss review items after fixes.
apply files Mark selected changed files as viewed (markFileAsViewed).
apply journal Optionally append an agent-authored item to the PR body's Shepherd Journal.
apply check-blocker Record (or --clear) that a failing check is blocked on an external PR or issue.
apply queue-removal Acknowledge one current CI-driven native-stack queue removal.
journal extract Parse a local PR-body file into typed journal JSON.
playbook [name] Print a bundled skill playbook so agents without the skill can read it. The name is the playbook name or its file slug (create-a-pr). No name lists them; an unknown name exits 64 and lists the available ones.
suggest Build ordered, git apply --check-validated patches from review suggestions. Never edits files or git history.
admin clean Remove local Shepherd state (pr, stack, branch, current, repo, or all; stack <number> removes the stack merge approval record).
admin log-file Print the append-only per-worktree debug log path.
admin watch-status Read-only: report whether a live pr-shepherd watches one PR (exit 17 if so, 0 if not, 65 if the lock is unreadable). See Watcher lock.

Apply subcommand details

  • apply merge — rerun the same command to resume its persisted UUID. pending and enqueued are not merged, and an uncertain submission is never repeated automatically. An unreadable status (403/404) for an unmerged direct_merge request with --method can fall back to synchronous merge. A default request can also fall back when REST proves the base branch has no merge queue and the repository allows exactly one merge method. The method can be cached per repository while it is still the only allowed method. The result identifies the route in merge_route. A request can send the fallback only once, and a rerun whose status remains unreadable reports uncertain. If GitHub refuses the fallback, Shepherd raises GitHub's error. A 405 that names the stack preserves the record, UUID, and sent marker even if the PR has since left the stack. For other 4xx refusals, Shepherd retires the record only if it confirms the PR is standalone. When Shepherd cannot choose a method for default, the message names the --merge-action direct_merge --method <m> retry where applicable. --method applies only to direct_merge. See actions.md. Native stacks always use asynchronous merge. If a stack request’s status is unreadable, rerun the same command to check its preserved UUID. Either fallback above also requires a verified standalone PR: GitHub’s stack endpoint must be readable and list no stack for it, checked again just before the fallback is sent. If the lookup fails (the message carries its own HTTP status) or the PR is stacked, the UUID is kept, the result is uncertain (exit 75), a refusal that kept the record names why in its error, and rerunning the same command checks the request’s outcome.
  • apply review — flags --resolve-thread-ids, --reply-thread-ids, --minimize-comment-ids, --dismiss-review-ids, --message (required with reply or dismiss IDs), --require-sha <sha|HEAD>, and --adopt-existing-replies (generated durable-state commands only). At least one ID flag is required. Explicit IDs are forwarded without iterate's author or capability filtering, except that dismissing or hiding a review (--dismiss-review-ids or a PullRequestReview ID in --minimize-comment-ids) is refused while GitHub still reports unresolved inline threads belonging to that review.
  • apply journal — provide either a positional <item> or --file (--file - reads stdin), not both. Entries live in a collapsed Shepherd Journal details block: apply journal creates that canonical block when absent, appends before its closing tag, and leaves an exact duplicate unchanged. A legacy ## Shepherd Journal section is migrated in place on the next journal operation. Journal updates are optional agent-authored notes; they are never required before review mutations or another iterate call.
  • apply check-blocker --check <name> — records that an exact failing check name is blocked on --blocked-by: a pull URL, an issue URL, owner/repo#N (pull), or issue:owner/repo#N. --clear removes that check only.
  • apply queue-removal — records a local acknowledgment of a current CI-driven native-stack removal, pinned to the head SHA, queue commit SHA, and removal timestamp. Run the generated command only after inspecting the failed queue evidence and deciding the failure was transient or came from another entry in the same queue group, with no source change or other blocker remaining. Only GitHub's failed_checks removal reason qualifies; manual, stale, and non-stack removals are rejected, and REST reports it as transport-unsupported. Fresh source checks and a one-PR READY receipt then permit aggregate stack recovery; the command itself does not enqueue or merge. It does retire a recorded same-head enqueued apply merge request for that PR when the request is not uncertain and the removal timestamp is strictly later than the second the submit PUT that returned enqueued was sent (a removal in the same second does not retire it); a request that only became enqueued on a resumed status read has no such second, so its start second is used instead: the next apply merge for that head, after full revalidation, submits one fresh request.
  • journal extract --body-file <path> — prints exactly one JSON line from the typed journal extractor, with no GitHub, configuration, or log I/O. On POSIX the final path entry is opened without following symlinks and must be a regular file in a trusted parent directory; symlinks, FIFOs, devices, unreadable paths, and missing files exit 66, and unsupported platforms fail closed with exit 66. A malformed or unrecognized journal is still a successful typed JSON result.
  • suggest — each --thread-id starts a group with its --message and optional --description. GitHub's anchored line range at the fetched PR head is authoritative; a clean local descendant is accepted only when the ordered patches pass git apply --check. Otherwise inspect the current source and reviewer intent manually.

Polling

pr-shepherd [PR] is the canonical bounded poll dispatcher. It repeats iterate while the action is WAIT, then prints the next agent-facing action:

  • A clean PR inside its ready-delay returns READY with remainingSeconds immediately rather than sleeping through the countdown.
  • TRIAGE and aggregate stack-level SHEPHERD are delayed by --debounce (default poll.debounce-seconds, built-in 1m): poll keeps iterating at --interval for that window, then returns one later tick.
  • If --timeout expires during WAIT polling, poll returns that final WAIT result rather than a terminal action. The timeout covers the debounce too: a window that would run past it ends at the deadline, and one last tick returns the action it finds (TRIAGE while the work is still there).
  • With --merge it also continues through MARK_READY; the rerun after the ready-delay completes emits MERGE. A native-stack member instead returns non-terminal TRIAGE with a complete stack <PR URL> --until-terminal --merge-through <PR URL> route; the aggregate command verifies the bottom layer before emitting its merge command.
  • --until-terminal ignores --timeout for WAIT ticks and continues through WAIT/MARK_READY/READY until TRIAGE, MERGE, CANCEL, ESCALATE, or stack SHEPHERD; a READY tick sleeps no longer than its remainingSeconds. A crossed quota warning returns its WAIT, MARK_READY, or READY early so the caller can apply the warning cadence.
pr-shepherd 42 --interval 60s --timeout 4.5m --quiet-status
pr-shepherd 42 --until-terminal --quiet-status
pr-shepherd 42 --debounce 5m
pr-shepherd iterate 42 --ready-delay 15m
pr-shepherd 42 --merge
pr-shepherd 42 43 44
pr-shepherd stack 43

Choosing a wait mode

The bounded poll (poll.timeout-seconds, default 270s = 4.5m) suits agents that wait in the foreground: each call stays inside Anthropic's default 5-minute prompt-cache window and under common tool timeouts. The timeout includes the TRIAGE debounce: the window ends at the deadline, and one final tick then runs at or after it, so a call runs about --timeout plus one tick. --until-terminal suits a background process or an external shepherd. Pick by what your host does, not its name:

Host capability Run
A background command's exit wakes the agent pr-shepherd [PR ...] --until-terminal (plus --merge when requested) as a background command; end the turn; act on its output when it exits. Do not poll its output file.
No wake-up on exit (foreground subagent, polling-style tools) pr-shepherd [PR ...] in the foreground; pass --timeout below the host's command-time limit if that is under 270s; on a non-terminal WAIT/READY, rerun it.
One tick per invocation (cloud sessions, MCP, iterate) Unchanged: follow nextCheck (cloud.md).

Run one watcher per selection, and never two on the same PR; stop the running one before restarting with different PRs or flags (for example adding --merge). Shepherd enforces this: a repeating run takes a lock per PR, and a run that finds a PR already watched by a live process skips it, or exits 17 without polling when every requested PR is watched (watcher lock). Exit 10-17 from a background --until-terminal run is a Shepherd action (exit codes), not a crash, though some hosts label it a failure. Exit 64 and above is a real command failure (75 is retryable).

Host behavior, as of 2026-11 (it changes; check the source):

  • Claude Code: a Bash command with run_in_background re-invokes the session when it exits, and a background subagent is notified too. A foreground subagent's background commands stop when its run ends. Bash defaults to a 120s timeout (max 600s, set per call), and a foreground command that times out moves to the background.
  • Codex CLI: no wake-on-exit yet (openai/codex#13733). exec_command yields after about 10s with a session id, and the model polls with write_stdin, each poll waiting up to about 300s. Use the bounded poll.
  • Cursor CLI: recent releases send a completion follow-up when a background shell finishes.
  • Gemini CLI: is_background / & has no documented exit notification, so treat it as no wake-up.
  • Prompt cache: Anthropic's default TTL is 5 minutes, while OpenAI's retention options differ (30m, 12h, 24h). The cache argument for 270s is Claude-specific; the tool-timeout argument applies everywhere.

Event-driven waits

With events.source: hook-harness (hook-harness.md), the sleep between WAIT ticks becomes a wait for a matching GitHub event. A wake-up still runs a normal tick, so output, JSON, and exit codes do not change; --verbose prints the wake reason to stderr. If the source is unreachable, waits fall back to poll.interval-seconds.

Flags

Flag Applies to Default / notes
--interval <duration> poll poll.interval-seconds (built-in 60). stack and multi-PR polls multiply it by poll.stack-interval-factor (built-in 2, so 120s) unless --interval is set; it is not multiplied again.
--timeout <duration> poll poll.timeout-seconds (270). Covers the TRIAGE debounce, which ends at this deadline. Ignored under --until-terminal.
--debounce <duration> poll poll.debounce-seconds (60). Settle window after the first TRIAGE or stack SHEPHERD; 0 disables.
--quiet-status / --no-quiet-status poll poll.quiet-status (false). By default each WAIT tick writes a stderr line naming what it waits on; stdout carries only the final action.
--until-terminal poll See above and Choosing a wait mode. The shipped skill's canonical form for a host that a background command's exit wakes.
--once stack Run one aggregate tick with nextCheck instead of polling; the poll flags are ignored.
--ready-delay <duration> iterate iterate.ready-delay-minutes (0).
--stall-timeout <duration> iterate iterate.stall-timeout-minutes (60); 0 disables.
--merge iterate Shepherd through readiness, then emit a merge or merge-queue command.
--no-auto-mark-ready iterate Leave clean drafts in draft and stop their one-PR session after other work is handled.
--instructions inline|playbook iterate iterate.instructions (inline). playbook folds triage's invariant commit/push step into a pointer to the "Triage loop" playbook.
--transport auto|graphql|rest all github.transport (auto). See api.md.
--format text|json all except journal extract text (Markdown). journal extract always prints JSON and rejects --format.
--verbose iterate/poll Verbose iterate fields and detailed per-tick lines.
--help / -h all Print usage and exit 0 before any I/O.

With CLAUDE_CODE_REMOTE=true, pr-shepherd [PR ...] and stack run one tick like iterate, ignore the poll flags, and print nextCheck (cloud.md).

Durations accept s, m, and h (30s, 4.5m, 1h). Bare polling durations are seconds; bare iterate durations are minutes. poll.reconcile-seconds (900) has no flag; it caps how long an idle GraphQL wait replays its last snapshot (see graphql.md). Config keys: configuration.md.

Aggregate commands

Explicit PR sets and native stacks use a compact summary instead of the stateful one-PR iterator per row. Its only GitHub mutation is rule-driven classification auto-resolve. Aggregate polling returns when work is needed, every selected PR is complete, every row is CANCEL, or the timeout expires. Every output format has one row per PR with raw state, bounded check/review counts, and routing context.

  • Explicit PR sets include an exact one-PR pollCommand for each actionable row, which callers may handle independently. A PR whose summary could not be read becomes a TRIAGE row (summary-read-failed, with the raw error) instead of failing the other rows; rate limits, credential errors, and an all-rows failure still fail the tick. When every row is CANCEL, the aggregate stops; if any open row is a native-stack layer with appears-ready, a second step says this poll records no READY receipt and, if the user asked to merge, points to pr-shepherd stack with --merge. When every row is CANCEL or ESCALATE, the instructions say to stop after reporting the handoffs.
  • stack never emits rebase or push commands. When any layer is draft, lacks a current one-PR READY receipt, conflicts, fails checks, remains pending, or has stale ancestry, the result is SHEPHERD, naming a one-PR session for every such layer at once. The instruction says to start one session per printed command; a layer without a command needs no session that tick. A layer that only lacks its receipt reads mergeable, no READY receipt yet, its step says only its own one-PR session records that receipt, and the first step says not to fold the commands into one multi-PR poll. With automatic mark-ready enabled, a clean draft is marked ready by its own session without waiting for lower layers. With it disabled, draft layers with work get bounded probe commands (pollProbe) and their work is processed normally. A clean draft row is CANCEL with reason draft-auto-mark-ready-disabled and has no probe command; the draft stays in draft. stack continues independent work and eligible ready-prefix merges, then returns CANCEL when only such drafts remain.
  • A queued stack, or one whose remaining layers can only wait on CI, merge state, or a blocking review, returns WAIT until that state stays unchanged past --stall-timeout, then ESCALATE with stall-timeout. A terminal READY stack, a stack with only clean drafts held by disabled auto mark-ready, or a fully merged stack returns CANCEL. A closed-unmerged layer returns ESCALATE only after every other shepherdable layer completes; mixed states return SHEPHERD and surface the eventual human blocker. When only layers the command does not list have work, or a layer's state could not be read, the stack returns WAIT under the same stall timer; an unlisted layer with work also gets a step that prints the command listing it, for a caller that opened it.
  • stack --merge / --merge-ready / --merge-through PR: --merge lands every owned open layer once all are ready, --merge-ready lands the highest ready owned prefix, and --merge-through lands one PR and everything below it. Unowned layers at or below the target escalate (unowned-stack-layers), layers that join after the request escalate (unapproved-stack-layer), and a closed through PR or a listed PR that left the stack escalates (merge-through-target-closed, listed-pr-left-stack). A single PR owns only itself; a stack number owns every layer. Once the bottom open layer targets the stack base, the highest layer in scope whose open lower layers are all READY returns MERGE with a command that lands that layer and every unmerged layer below it (a SHA-pinned pr-shepherd apply merge --expected-stack on both transports; the printed command always runs over REST, so it works from a GraphQL session). A merge queue queues that prefix together and evaluates each layer from the bottom; a failure ejects that layer and the layers above it. Reconciliation continues until every layer merges and returns CANCEL. JSON and MCP results carry the same raw ancestry, routing context, nextAction, and instructions as Markdown.

Full aggregate semantics: actions.md.

MCP server

mcp.md covers installing the stdio server (the plugin does not start it) and the contract for each tool. Seven tools mirror the CLI: iterate, stack (stack --once), apply (apply merge|review|files|journal|check-blocker|queue-removal), playbook, suggest, extract_journal (journal extract, from a body string), and get_journal (no CLI counterpart; fetches the PR body, then extracts). See mcp.md. admin clean and admin log-file are shell-only. MCP has no polling tool: call iterate or stack again after the returned work is done or when the client's scheduler rechecks.

Exit codes

All CLI commands honor --help/-h before I/O. Iterate/poll PR outcomes use exit codes 0 and 10–16; command, validation, and GitHub failures use sysexits.h codes. See exit-codes.md.