Expand description
Landing the winner: watch the pull request, fix what it complains about, and merge it.
Opening the pull request used to be where magi stopped and the operator started: watch the checks, read what the review bots found, push a fix, wait again, merge. That loop is mechanical, it takes an hour of wall-clock time per pull request, and doing it by hand six times in one session is how a queue that drains unattended stops being unattended. So it lives here.
§Shape
PrState is one observation of a pull request and decide is the whole
policy as a pure function of it. Nothing in decide talks to gh,
which is what makes “green with an unresolved comment is a fix, not a merge”
an assertion in a test rather than a claim in a comment. land is the
only part that performs I/O: observe, decide, act, repeat.
§What it refuses to do
Merging is the one irreversible thing magi can do to a repository, so the loop is built to stop rather than to guess:
- A red pull request is never merged. When the budget runs out the pull request is left open with a comment naming what is still failing, because a magi that force-merges a red pull request is worse than one that stops.
- A pull request whose checks cannot be read at all (
ghreported no rollup) is not merged either. Landing is for repositories with CI; with no signal there is nothing to be green. - A pull request a human merged or closed underneath us is
Step::Done- the person won, and their decision is not an error.
§Why --subject is not optional
A candidate branch holds one commit whose subject is
magi: candidate A (uncommitted work), and gh pr merge --squash prefers a
single commit’s message over the pull request title. Merging without
merge_argv’s explicit --subject therefore writes a main history that
says nothing about what landed. AGENTS.md records the trap; this module is
where it is prevented.
Structs§
- PrState
- One observation of a pull request.
- Review
Comment - One outstanding review comment, human or bot.
Enums§
- Approval
- What the owner’s answer to the approval question means.
- Blocking
- Whether a failing check actually stands between the pull request and
main, according to the forge. - Checks
- The aggregate verdict of a pull request’s checks.
- PrLifecycle
- Where a pull request is in its life.
- Step
- What the loop decided to do next. Pure, so the policy is testable.
Constants§
- APPROVAL_
NODE - Graph node recorded on the approval question.
- APPROVE
- The choice that lets the merge happen, verbatim as the owner taps it.
- CHECKS_
GRACE - How long the checks may stay unreadable before landing gives up on them.
- DIFF_
MAX_ LINES - Unified diff lines carried in the panel before it is truncated.
- HOLD
- The choice that leaves the pull request open.
- MARKER
- Marker carried by every comment magi posts on a pull request.
- POLL
- How often the pull request is re-read while its checks are still running.
- WAIT_
CEILING - How long one wait may last before landing gives up on the checks finishing.
Functions§
- approval
- Read the owner’s answer, where
Noneis an unanswered question. - approval_
panel - The approval panel’s html: what is about to land, and the evidence for it.
- decide
- Decide the next step. No I/O.
- is_
noise - Is this comment body machinery rather than a finding?
- land
- Run the loop against a real pull request until it merges or the budget runs out.
- merge_
argv - The argv magi merges with, minus the program name.
- merge_
subject - The squash subject to merge under.
- parse_
inline_ comments - Parse
gh api repos/{owner}/{repo}/pulls/<n>/commentsinto inline review comments. No I/O. - parse_
pr - Parse
gh pr view --json url,number,state,statusCheckRollup,reviews,commentsoutput into aPrState. No I/O.