do-issue-solo

Work on a GitHub issue end-to-end autonomously, only pausing when blocked or when clarification is needed.

SKILL.md

GitHub

Work on GitHub Issue (Autonomous)

Work on GitHub issue $ARGUMENTS autonomously, coordinating safely with any other Maverick instance that might also hold a claim on this issue. Follow every phase in order. Only pause to ask the user when you are blocked or need clarification.

Preflight (mandatory)

Preflight output, captured when this skill was invoked (dynamic-content pilot — the command ran before you read this):

!uv run maverick preflight do-issue-solo 2>&1 && echo PREFLIGHT_OK

  • Ends with PREFLIGHT_OK → prerequisites are met; proceed.

  • Shows an error → halt and report the output verbatim to the user. Do not proceed, do not work around missing prerequisites.

  • Empty, or shows the literal command text (dynamic skill content is disabled via disableSkillShellExecution) → run it manually first and apply the same rules:

    uv run maverick preflight do-issue-solo
    

The check verifies: the project is initialised, the Maverick GitHub App is configured (maverick gh-app status reports configured: true), and required tools (gh, git, uv) are on PATH.

Before You Begin

If $ARGUMENTS is empty or not a valid issue number, ask the user for the issue number before proceeding.

Determine the repo (via gh repo view --json nameWithOwner) — you will pass it to every maverick coord command below.

PR code review runs locally during Phase 9 as the agent-code-reviewer subagent — its binary PASS/FAIL verdict is the gate. Some projects also opt into a CI-side re-run via mav-bp-remote-code-review (independent verification for multi-machine fleets or audit needs); when present it adds a status check the auto-merge in Phase 10 will wait on, but its absence is not a blocker.

Dispatching agents

You are the story agent. Your context is re-read on every call you make, so keep it for coordination: claims, checkpoints, verdicts, task bookkeeping. The work that reads code and runs commands — design, planning, implementation, fixes, docs, reviews — goes to subagents, and you keep only what they return.

  • Model routing. Before each dispatch, look up the agent's route:
    uv run maverick agent-model <agent-name>
    
    A non-empty result is the project's agent_models choice for that agent: pass it as the dispatch's model override. An empty line means no route: dispatch without an override, so the agent keeps its own pinned model or inherits yours. Look the routes up once (run it with no argument for the full list) and reuse them for the rest of the story.
  • Foreground only. Every dispatch in this workflow runs in the foreground and you wait for its result. A story agent that ends its turn while a subagent runs in the background is never woken, and the story stalls.
  • Context budget. If your own context grows past about 100k tokens, stop reading files and command output yourself: hand anything that needs them to agent-implementer (or the relevant agent) and keep only its summary.
  • Command output: failures only. Whenever you run a test, typecheck, lint or build command yourself, send its output to a log under .maverick/tmp/ in the worktree and read back only the exit status, the summary lines and the failures (tail, grep), never the whole log.

Phase 0: Coordination + cold-start

Before any other phase.

  1. Run uv run maverick coord read <repo> $ARGUMENTS and inspect the snapshot. Decide which of the four branches in mav-multi-instance-coordination applies:

    • Blocked (blocked-by:#N label): abort cleanly, report to user.
    • Claimed with live lease: abort cleanly, report holder + expiry.
    • Claimed with stale lease: decide take-over vs defer.
    • Free: proceed to claim.
  2. Claim the issue: uv run maverick coord claim <repo> $ARGUMENTS. The command exits non-zero if the claim is rejected — treat that as abort.

  3. Start the workflow report (writes a run-start row that later report calls inherit maverick_skill from):

    uv run maverick report run-start do-issue-solo --issue $ARGUMENTS --phase claimed
    

    From here, agent-dispatch intervals are recorded automatically by the plugin's hooks (open on dispatch, closed on return), and invoking a tracked inner skill auto-opens its skill-dispatch interval. Your only bookkeeping obligation is the one-line report end --auto --outcome <…> after each inner skill returns — everything else is hooks. Anything left open is flushed as outcome=unknown by report generate.

    Attribution marker (mandatory). Every agent you dispatch and every inner skill you invoke from here on must carry the line maverick-issue: $ARGUMENTS — at the end of the agent prompt, or appended to the skill's arguments. When this run is one story of an epic, the session holds several claims at once and the marker is how the hooks know which story's report a dispatch belongs to. Without it, the dispatch is not recorded.

  4. Start the heartbeat daemon. It refreshes the lease every HEARTBEAT_INTERVAL_MINUTES minutes for as long as you hold the claim and exits on its own when the claim is released:

    uv run maverick coord heartbeat-loop <repo> $ARGUMENTS --daemonize
    

    Never background the foreground loop with & — a process backgrounded from a tool shell dies with the shell or leaks unobservably. Liveness is checked in the task loop with coord heartbeat-status.

  5. Release is handled on every exit path without any action from you: the plugin's SessionEnd hook runs coord release-all when the session ends (normal exit, user interrupt, crash-caught), and lease expiry (10-minute TTL) covers machine death. Your only release obligations are the explicit ones at workflow boundaries: --reason merged after auto-merge lands, --reason ejected on eject. Do not attempt trap-on-exit wrappers — each Bash call is a fresh shell, so a trap cannot survive to session end.

  6. Authorization scopes (only when needed): if the issue explicitly authorizes infrastructure changes — the maverick-authorize-infra label or a Maverick-Authorize: infra line in the issue body — record it so the scope-guard hook permits those edits in autonomous mode:

    uv run maverick coord authorize <repo> $ARGUMENTS infra
    

    If the command exits non-zero, the issue does not authorize the scope: do not make infrastructure changes; note the gap in the solution design instead. Never write .maverick/session-auth.json by any other means — the hook blocks it, and self-granting defeats the authorization model.

  7. Cold-start hydrate per mav-durability-on-gh. The skill is fully resumable — a fresh agent re-entering after a crash, stop, or context-exhaustion must skip phases that already completed rather than re-running them against an in-flight or merged PR (#41). Do not reconstruct the resume position by hand:

    uv run maverick coord resume-point <repo> $ARGUMENTS
    

    The command reads the task-progress marker, finds the PR via the recorded branch, inspects CI and the review verdict, and returns {next, instruction, evidence} — follow the instruction. Also check for an existing worktree under .maverick/worktrees/ before creating one. Each phase below ends with a task-progress set write so re-entry advances one boundary at a time without re-running anything.

Phase 1-2: Understand the Issue and Solution Design (subagent)

Run Phases 1 and 2 as a subagent to keep the main context window clean for implementation.

  1. Refresh the local base branch before the analyst reads anything. The analyst runs against the main checkout — Phase 4 hasn't created the worktree yet — so a stale local base lets pre-resolved ambiguities slip into the design pass and surface as phantom blockers (#102). Follow the "Base Branch Freshness" rule in mav-git-workflow:

    STORY_BASE=$(uv run maverick git-workflow story-base)
    git fetch origin "$STORY_BASE"
    CURRENT=$(git rev-parse --abbrev-ref HEAD)
    if [ "$CURRENT" = "$STORY_BASE" ]; then
        git pull --ff-only origin "$STORY_BASE"
    else
        git fetch origin "$STORY_BASE:$STORY_BASE"
    fi
    

    If either form refuses a non-fast-forward, halt and report to the user — there are local commits on $STORY_BASE that have not been pushed, which violates trunk-based discipline.

  2. Dispatch the agent-issue-analyst agent with:

    • Issue number: $ARGUMENTS
    • Mode: solo
    • maverick-issue: $ARGUMENTS (The dispatch interval is recorded by the plugin hooks — no report calls needed.)
  3. When the agent returns, verify the design landed durably — uv run maverick task-progress read <repo> $ARGUMENTS shows comments.design set to a comment ID (the analyst posts it via uv run maverick issue comment post --kind design).

  4. If the agent flagged ambiguities it could not resolve:

    • uv run maverick report begin question --issue $ARGUMENTS --topic ambiguity-resolution
    • Ask the user.
    • uv run maverick report end --auto --issue $ARGUMENTS --outcome success

    Otherwise continue.

  5. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS design.

Phase 3: Create Tasks (subagent)

Run Phase 3 as a subagent.

  1. Dispatch the agent-github-issue-planner agent with:
    • Issue number: $ARGUMENTS
    • Design comment ID from the task-progress marker (comments.design)
    • maverick-issue: $ARGUMENTS
  2. When the agent returns, verify the tasks landed durably — uv run maverick task-progress read <repo> $ARGUMENTS shows:
    • If < 5 tasks: comments.tasks set to a comment ID (posted via uv run maverick issue comment post --kind tasks)
    • If >= 5 tasks: sub-issues exist on the issue
  3. If the agent flagged scope concerns:
    • uv run maverick report begin question --issue $ARGUMENTS --topic scope-concerns
    • Ask the user.
    • uv run maverick report end --auto --issue $ARGUMENTS --outcome success
  4. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS tasks (append --has-sub-issues when the >= 5 tasks path was taken).

Phase 4: Create Worktree + Branch

The branch is created inside a dedicated worktree, not in the main checkout.

  1. Derive the branch name per the mav-github-issue-workflow skill.
  2. Resolve the base branch from the project config:
    STORY_BASE=$(uv run maverick git-workflow story-base)
    
    • If this story depends on a sibling story whose PR is open but not merged, stack per mav-stacked-prs — base = sibling branch.
  3. Create the worktree: uv run maverick worktree create <branch> [--base <sibling-branch>]. From this point on, all file edits happen inside the worktree path.
  4. Note the current directory as the main checkout path (Phase 10 returns there before destroying the worktree), then cd into the worktree path for the rest of the story.
  5. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS branch --branch <branch> (recording the branch is what lets coord resume-point find the PR later).

Phase 5: Execute Tasks (push after every task)

Push after every task, not at the end. See mav-durability-on-gh.

Each task is implemented by a fresh agent-implementer subagent, not in your own context. The implementer reads the code, runs /do-code, verifies, commits and pushes; you keep only its summary and the per-task bookkeeping. Do not read the task's source files or its test output yourself.

For each task (sub-issue or checklist item), in order:

Each step below is its own obligation. When the implementer returns in step 1, do not stop — continue with step 2. Its return is a hand-back, not a task-complete signal (#106).

  1. Dispatch agent-implementer in the foreground (with its agent-model route, if any) with:

    • Mode: task
    • Worktree path and branch (from Phase 4)
    • Repo and issue number: <repo>, $ARGUMENTS
    • Task: its number and text, exactly as the tasks comment or sub-issue states it
    • Design comment ID: comments.design from the task-progress marker
    • Files: the files the plan names for this task
    • Stacked on: the sibling branch, if Phase 4 stacked the branch
    • maverick-issue: $ARGUMENTS

    The agent-dispatch interval is recorded by the plugin hooks, and the implementer closes the skill-dispatch interval its /do-code call opened, so there is no report end for you here.

  2. Read the result block (## Implementer result).

    • status: done — continue with step 3.
    • status: failure or blocked, a missing result block, or pushed: no — halt the per-task loop (the implementer never commits red). Record it, then decide: re-dispatch once in fix mode with the reported failure, or surface it to the user if the cause is outside the issue's scope:
      uv run maverick report note --issue $ARGUMENTS --phase implement \
          --text "task <n>: <status> — <one line from the result>"
      
    • Anything under unexpected: that changes the plan or the scope: note it the same way, and carry follow-ups to "Follow-up Issues".
  3. Log the commit to the workflow report, from the result's commit and subject (the timestamp is wall-clock at this call):

    uv run maverick report commit --issue $ARGUMENTS \
        --phase implement --sha "<commit>" --subject "<subject>"
    
  4. Check the task off durably — uv run maverick tasks check <repo> $ARGUMENTS <n> (or close the sub-issue). Never PATCH the comment body by hand.

  5. Verify the heartbeat daemon is alive: uv run maverick coord heartbeat-status <repo> $ARGUMENTS — if it reports not running, treat it as claim-lost: stop pushing, re-run the Phase 0 entry check before continuing.

After the last task, run the full verification suite once more, output to a log and read back failures only (see "Dispatching agents"). If it fails, dispatch the implementer in fix mode with the failing lines only, then run the suite again.

Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS implement.

Follow mav-plan-execution for the broader execution loop, verification discipline, failure handling, and crash recovery.

Phase 6: Documentation Review (mandatory)

This phase always runs before the PR is opened. There is no skip path — the heuristic-gated version used to let stale docs ship when Claude's affected-or-not call was wrong. The agent decides whether work is needed; the workflow decides whether the agent runs.

The agent is dispatched with a pre-filtered shortlist of docs the change plausibly touches, not the open-ended "audit every doc" brief that made this phase the longest single subagent cost on prior issues. Docs that belong to someone else (configured in docs.owners) are never edited by the docs writer: drift in them is routed to their owner in step 4, not left as a PR note nobody acts on.

  1. Build the diff and candidate-doc shortlist in one deterministic step:
    uv run maverick docs shortlist \
        --base "$(uv run maverick git-workflow story-base)" --issue $ARGUMENTS
    
    The JSON output names the files it wrote (diff, shortlist, detail) in a per-worktree directory, so parallel stories never overwrite each other's — always use the paths it prints, never a fixed /tmp path. Candidates come from three sources: words from the diff, docs/ paths the issue cites, and the repo's own docs.shortlist_commands (e.g. a route → help-topic map). owned lists shortlisted docs that belong to a docs.owners entry. Print any warning: lines in the run notes. An empty shortlist is a valid input to step 2.
  2. Dispatch agent-tech-docs-writer with (interval recorded automatically by the plugin hooks):
    • Mode: update (per do-docs)
    • Diff: the diff path from step 1
    • Candidate docs: the contents of the shortlist file. If it is empty, pass the literal string <empty — scan only for gaps requiring new coverage>.
    • Owned docs (report only, never edit): the owned map from step 1, if any.
    • maverick-issue: $ARGUMENTS
    • Instructions:
      • Read each candidate doc. Update only sections rendered stale by the diff; do not refactor unrelated content.
      • Never edit an owned doc unless its owner entry says editable: true. Report what is stale in it instead.
      • If the diff introduces a component, subsystem, or architectural change with no coverage anywhere in docs/, create the new document.
      • If you find a doc outside the candidate list that you believe is impacted, list its path in your return payload — do not edit it. One-pass dispatch: no widen-and-retry.
      • Return three lists: docs changed, owned docs with drift (path + what is stale), other impacted docs not edited. Returning "no doc changes required" is a valid outcome and must be stated explicitly (not silently inferred).
  3. Commit any doc changes with a docs: conventional commit and push per the push-per-task rule. If a commit was made, log it so the docs phase row gets its own sub-row in the report:
    SHA=$(git rev-parse HEAD)
    SUBJECT=$(git log -1 --pretty=%s)
    uv run maverick report commit --issue $ARGUMENTS \
        --phase docs --sha "$SHA" --subject "$SUBJECT"
    
  4. Route drift the writer could not fix. Look up owners for every path the writer reported but did not edit:
    uv run maverick docs owners <path> [<path> ...]
    
    • Owner entry with agent — dispatch that project agent (e.g. a product-owner agent) with the diff path, the stale docs and what the writer said is stale, plus maverick-issue: $ARGUMENTS. Commit and push whatever it changes as in step 3.
    • Owner entry without agent, or no owner — open one follow-up issue listing the docs and what is stale, labelled with the entry's label (default docs-drift), referencing this issue: uv run maverick gh-app gh -- issue create --title "Docs drift from #$ARGUMENTS" --label <label> --body-file <file>. Create the label first if it doesn't exist. A PR-body note alone is not enough: nobody acts on those.
  5. Record the outcome in the PR body draft so the gate is auditable (Docs review: <n> updated, <n> routed to owners, <n> follow-up issue(s) or Docs review: no changes required.), and as evidence in the report — the evidence note is what distinguishes a genuine no-op from a skipped step:
    uv run maverick report note --issue $ARGUMENTS --phase docs \
        --text "shortlist=<n> (terms <n>, issue <n>, command <n>) updated=<n> owned-drift=<n> followups=<links or none>"
    
  6. The PR cannot proceed to Phase 7 until this phase has produced either committed doc changes or the auditable no-op record.
  7. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS docs.

Phase 7: Pre-PR Security Review (mandatory, independent)

This phase always runs before the PR is opened. There is no skip path. The review is done by agent-security-reviewer — a read-only agent with a fresh context — not by you. You wrote the code; reviewing it yourself is the author checking their own work. The agent applies the project's security checklist from docs/maverick/skills/, runs the project's invariant checks, and reviews the changed code plus its impact set.

  1. Refresh the diff (Phase 6 may have added doc commits):

    uv run maverick docs shortlist \
        --base "$(uv run maverick git-workflow story-base)"
    

    and use the diff path it prints.

  2. Dispatch agent-security-reviewer with (interval recorded automatically by the plugin hooks):

    • Mode: diff
    • Diff: the diff path from step 1
    • Base: the story base branch
    • Spec: the issue title and acceptance criteria
    • maverick-issue: $ARGUMENTS

    Do not tell it what you think is safe or explain your design choices; it must reach its own conclusions from the code.

  3. Parse the verdict from the marker line only. The reply must end with exactly one MAVERICK_SECURITY_VERDICT: PASS|FINDINGS|BLOCKING line. Missing, ambiguous or repeated with conflicting values → treat as BLOCKING.

  4. Record the evidence (verdict, files reviewed, checklist and checks counts, from the agent's JSON):

    uv run maverick report note --issue $ARGUMENTS --phase security \
        --text "verdict=<V> files=<n> checklist=<n pass>/<n> checks=<n failed>/<n> findings=<n by severity>"
    
  5. Act on the verdict:

    • BLOCKING — do not open the PR. Fix each BLOCKING finding by dispatching agent-implementer in fix mode with that finding only (severity, location, description, recommendation), then handle its result as in Phase 5 steps 2–3 and re-run this phase from step 1. If a finding cannot be fixed within the issue's scope (it needs an auth or infrastructure change the issue does not authorise, or a product decision), halt and surface the findings to the user verbatim.
    • Round cap. Count the BLOCKING rounds per file or mechanism (a sanitiser, a parser, a key scheme). After two rounds on the same one, stop refining it: a third finding there means point-patches are chasing edge cases. Either switch it to a fail-closed design (refuse, redact or withhold anything it cannot classify with certainty) and run this phase once more, or halt and surface the remaining findings to the user. Never start a third narrower regex or parser rule for the same mechanism. Record the count in the step 4 note as rounds=<n>.
    • FINDINGS — append a ## Security Review section to the PR body draft listing each finding (severity, location, description, recommendation). The PR may proceed to Phase 8 with these items visible to the human reviewer and to agent-code-reviewer. Any finding the PR leaves unfixed gets a follow-up issue per "Follow-up Issues" below.
    • PASS — record Security review: PASS (<files> files, <checklist summary>). in the PR body draft so the gate is auditable.
  6. The PR cannot proceed to Phase 8 until this phase has returned a non-BLOCKING verdict and the outcome has been folded into the PR body draft.

  7. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS security.

Phase 8: Open PR + Monitor CI

  1. Pre-push verification per mav-local-verification — a final green check before asking for review. Output to a log, failures only; a failure goes to agent-implementer in fix mode.

  2. Stacked-PR retarget check per mav-stacked-prs if the branch stacks on a sibling. Retarget before opening the PR if the sibling is now merged.

  3. Resolve the PR target from config:

    PR_TARGET=$(uv run maverick git-workflow pr-target)
    

    Open the PR as a draft. Phases 8–10 still have gates to run, and an open, non-draft PR looks finished: a human can't tell "an agent is still working on this" from "ready for you", and GitHub will merge either. GitHub refuses to merge a draft, from the button and from gh pr merge. The PR is marked ready only in Phase 10, once it is settled, or in Phase 11 when it is handed to a human.

    The body must end with a literal Closes #$ARGUMENTS line (capitalised; not Refs, Related to, or any other phrasing). gh pr merge --squash carries the PR body verbatim into the squash commit body; GitHub only auto-closes the linked issue when one of Closes/Fixes/Resolves appears in a commit on the default branch. If multiple PRs land via a non-squash promotion (Gitflow: develop → main), each squash commit's body is what GitHub scans — so omitting the keyword on a single PR leaves that story open even after promotion (#56). Use Refs #N only for cross-references to other issues, never for the primary story:

    gh pr create --draft --base "$PR_TARGET" --head <branch> \
        --title "<conventional title referencing #$ARGUMENTS>" \
        --body "$(cat <<'PR_EOF'
    ## Summary
    <1-3 bullet points>
    
    Closes #$ARGUMENTS
    PR_EOF
    )"
    
  4. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS pr_open.

  5. Monitor CI with a bounded wait:

    uv run maverick pr wait <repo> <pr-num> --checks --timeout 30m
    
    • Exit 0: checks green — continue.
    • Exit 5: checks failed — find the failing job and its failing lines per mav-bp-cicd (read the failures, not the whole log: gh run view <run-id> --log-failed | tail -n 60), dispatch agent-implementer in fix mode with those lines only, handle its result as in Phase 5 steps 2–3, then re-run the wait.
    • Exit 3: timeout — investigate the stuck check (a required check that never reports blocks auto-merge too); report to the user if it cannot be resolved. Do not proceed to Phase 9 until the wait exits 0. The PR stays a draft through these fixes. If the project's CI skips draft PRs, the wait finds no checks and exits 0, so CI is checked again after Phase 10 marks the PR ready. That only works if the CI workflow triggers on the ready_for_review event as well as the defaults.
  6. Browser/UI verification is non-blocking. If the change touches UI and Claude's global instructions or a project skill ask for browser verification, run it with a strict timeout (e.g. 5 min total). On hang, timeout, or failure, post the outcome as a non-blocking PR comment and proceed to Phase 9 — do not wait indefinitely (#41). Phase 9's reviewer is the binding gate; CI is the binding regression check; ad-hoc browser runs are advisory.

  7. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS ci_green.

Phase 9: Code Review (binary, hard gate)

The local agent-code-reviewer subagent's verdict is the review gate the auto-merge path trusts. This is a binary verdict against the open PR, not a local-diff advisory loop.

  1. Dispatch agent-code-reviewer with (interval recorded automatically by the plugin hooks):
    • The PR URL
    • The issue body, design comment, and tasks list (so it has the spec)
    • maverick-issue: $ARGUMENTS
  2. Parse the verdict from the marker line only. The agent's reply must end with exactly one MAVERICK_VERDICT: PASS or MAVERICK_VERDICT: FAIL line — that line is the verdict; do not infer it from the prose above it.
    • MAVERICK_VERDICT: PASS — proceed to Phase 10 (merge).
    • MAVERICK_VERDICT: FAIL — proceed to Phase 11 (eject). Do not attempt to auto-fix.
    • Marker missing, ambiguous, or present more than once with conflicting values — treat as FAIL and eject. Do not re-dispatch the reviewer to "get a cleaner answer", and never substitute your own reading of the review body for a missing marker.
  3. Record the evidence:
    uv run maverick report note --issue $ARGUMENTS --phase review        --text "verdict=<PASS|FAIL> <one-line reason>"
    
  4. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS review.

There is no fix-and-re-review loop. If the reviewer FAILs the PR, the next step is eject-to-human, not iterate.

Phase 10: Auto-merge (on PASS)

  1. Verify the PR body still carries the closing keyword. The body becomes the squash commit body, and the closing keyword must survive into the commit that lands on the default branch (#56). If the body was edited after Phase 8 — by a reviewer, by another subagent, or by a force-push — re-add the line before merging:

    uv run maverick gh-app gh -- pr view <pr-url> --json body -q .body \
        | grep -Eq '(Closes|Fixes|Resolves) #$ARGUMENTS\b' \
        || { echo "PR body missing 'Closes #$ARGUMENTS' — re-add before merging"; exit 1; }
    
  2. Auth-path gate (hard). Never auto-merge a PR that touches authentication/authorization surfaces or CI workflow definitions — those require human review regardless of the code-review verdict:

    uv run maverick pr auth-scan <repo> <pr-num> --security-verdict <PASS|FINDINGS|BLOCKING>
    

    Pass the verdict Phase 7 recorded for this diff, exactly as the marker gave it. Test files and comment-only changes are cleared by the scan itself. Only a project that set scope_guards.auth_scan: "advisory" treats auth-path hits as advisory, and then only with PASS; CI workflow definitions always gate.

    • Exit 0: clean — proceed.
    • Exit 3: gated paths touched — do not merge. Treat this exactly like a review FAIL: follow the eject path (apply needs-human, post the scan output as a comment, release the claim) and stop.
    • Exit 2: scan error — retry once; if it still fails, eject rather than merging unverified.
  3. Settle, then mark the PR ready. Ready is the handoff: it tells a human the agent is done, and it is the last step before approval and auto-merge (GitHub can't enable auto-merge on a draft). Before it:

    • nothing this run started against the branch is still running — a browser check, a background job, a subagent, a migration regeneration;
    • the local branch has no unpushed commits, and its head is the commit Phases 8 and 9 checked.

    Then let the CLI confirm the pushed head has passed its checks and flip the PR:

    uv run maverick pr ready <repo> <pr-num> --expect-head "$(git rev-parse HEAD)"
    
    • Exit 0: marked ready (or already was) — continue.
    • Exit 3: checks still running — wait with uv run maverick pr wait <repo> <pr-num> --checks --timeout 30m, then re-run.
    • Exit 5 or 6: the checks failed, or the PR head is not the commit that was reviewed (push any local commits first). The PR is still a draft and is not settled: go back to Phase 8 step 5 for the pushed head, then re-run Phase 9 against it.
    • Exit 4: the PR was closed or merged under you — stop and report.

    Then wait for checks once more, before approving. A project whose CI skips drafts only starts it now, and auto-merge waits only for required checks:

    uv run maverick pr wait <repo> <pr-num> --checks --timeout 30m
    

    Exit 0 continues. Exit 5 (failed) or 3 (timed out): put the PR back to draft (uv run maverick pr ready <repo> <pr-num> --undo), then handle it as in Phase 8 step 5 and re-run Phase 9.

    Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS settled.

    Re-entry. Once the PR is ready, any change to the branch — a conflict resolution, a base-branch merge, a migration regeneration — first puts it back to draft, before its first commit:

    uv run maverick pr ready <repo> <pr-num> --undo
    

    This also turns auto-merge off, so an approval left from the last pass cannot merge the new head. Then go back through Phase 8 step 5, Phase 9 and this step. Dispatch a fresh agent-code-reviewer for the re-run of Phase 9, and tell it which commits are new since its last PASS: it may narrow its review to those commits, because that PASS completed both stages. The commonest case is auto-merge stalling because branch protection requires the branch to be up to date with its base.

  4. The Maverick GitHub App posts the approval:

    uv run maverick gh-app gh -- pr review <pr-url> --approve \
        --body "Approved by agent-code-reviewer at $(date -u +%FT%TZ)"
    
  5. Enable auto-merge (squash):

    uv run maverick gh-app gh -- pr merge <pr-url> --auto --squash
    

    The merge waits on whatever required status checks the project's branch protection enforces — typically lint, tests, build, and (if the optional mav-bp-remote-code-review workflow is adopted) the CI-side re-run of agent-code-reviewer. If all required checks were already green, GitHub merges immediately; otherwise it merges when they pass.

  6. Wait for the merge to land with a bounded wait — cleanup steps below assume the PR is no longer in flight:

    uv run maverick pr wait <repo> <pr-num> --timeout 30m
    

    Exit 3 (timeout) usually means a required check never reported, or the branch must be brought up to date with its base (a re-entry, per step 3) — investigate rather than looping; exit 4 (closed without merge) means a human intervened — stop and report; exit 6 means the PR is a draft again — someone converted it, so stop and report rather than marking it ready over them.

  7. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS merged.

  8. Post the completion comment on the issue per mav-github-issue-workflow, and file any reviewer notes the PR left unfixed per "Follow-up Issues" below.

  9. Run the post-merge issue-lifecycle step. This always posts an audit comment ("Resolved in PR #<P>; merged to <branch>.") and applies a merged-to-<branch> label, then closes the issue per the per-project policy in .maverick/config.json's issue_lifecycle.close_policy (#52). The default policy (on_pr_merge) closes the issue immediately, which is right for trunk-based and GitHub Flow repos. Repos using Gitflow or custom promotion gates can set the policy to on_default_branch_merge or manual to keep the issue open until promotion — the audit comment and label still surface the merge so gh issue list -l merged-to-develop finds work pending promotion. The CLI is idempotent (re-running it on a closed issue is a no-op), so it is safe to retry:

    uv run maverick issue close-on-merge <repo> $ARGUMENTS \
        --pr <pr-num> --target <target-branch>
    
  10. Emit per-phase narrative notes so the report's Analysis section has context for what happened. The JSONL is the authoritative record; the report is a pure render of it, so notes must land in the JSONL — do not edit the rendered Markdown by hand:

    uv run maverick report note --issue $ARGUMENTS --phase design \
        --text "<one-sentence summary of what the analyst returned>"
    uv run maverick report note --issue $ARGUMENTS --phase implement \
        --text "<one-sentence summary of what landed in Phase 5>"
    # ... one `report note` per phase that produced work worth narrating
    
  11. Checkpoint: uv run maverick task-progress set <repo> $ARGUMENTS completed. Spell it completed: Claude Code's worktree guard refuses any command containing the bare name of the shell's completion builtin, so that spelling can never run from an isolated story (#160). The CLI records it as the complete phase. Run it before releasing the claim and destroying the worktree: once the worktree is gone the shell's working directory no longer exists, so any later uv run maverick … fails. The checkpoint is a merge-set, so re-running it is safe.

  12. Release the claim: uv run maverick coord release <repo> $ARGUMENTS --reason merged. Releasing also writes the workflow report to the main repo's .maverick/reports/ (it prints report: <path>), so the report exists on every exit path — including halts and crashes, where the SessionEnd hook does the release. Because the complete checkpoint landed first, this report already includes it.

  13. Destroy the worktree — always the last step. Leave the worktree first, then remove it from the main checkout:

    cd <main-checkout-path>
    uv run maverick worktree destroy <worktree-path>
    

    Run nothing from inside the worktree after this. If a step after the destroy is ever refused or fails because the directory is gone, cd to the main checkout and re-run it there — every command in this phase is idempotent.

Phase 11: Eject (on FAIL)

  1. Post the reviewer's verdict as a PR comment (App identity, per mav-github-issue-workflow):
    uv run maverick gh-app gh -- pr comment <pr-url> --body-file - <<'EOF'
    <reviewer verdict>
    
    This PR is now waiting on a person: the agent has stopped work on it
    and marked it ready for review.
    EOF
    
    Pass the body on stdin (--body-file -) or, if it is long, write it with the Write tool to .maverick/tmp/review-verdict-$ARGUMENTS.md in the story's checkout and pass that path. Never use a shared /tmp or scratchpad file — concurrent stories would post each other's (#159).
  2. Apply the needs-human label to both the PR and the issue, and mark the PR ready, so its draft/ready state says whose turn it is (draft: the agent's; ready: a person's). Turn auto-merge off first: a re-entry may have left it enabled with an approval from an earlier pass, and marking ready would then merge the FAILed head. The disable fails harmlessly when auto-merge is already off. Use plain gh pr ready here, not maverick pr ready, which refuses while checks are failing:
    gh pr edit <pr-url> --add-label needs-human
    gh issue edit $ARGUMENTS --add-label needs-human
    uv run maverick gh-app gh -- pr merge <pr-url> --disable-auto || true
    uv run maverick gh-app gh -- pr ready <pr-url>
    
  3. Request human review on the PR:
    gh pr edit <pr-url> --add-reviewer <human-handle>
    
  4. If this story belongs to an epic (look for a parent epic reference on the issue, or uv run maverick state show <repo> <epic>):
    • Mark this story ejected: uv run maverick state set <repo> <epic> $ARGUMENTS ejected.
    • Run block propagation (idempotent, resumable): uv run maverick bprop run <repo> <epic> --ejected $ARGUMENTS.
    • Cancel any in-flight subagent work for stories now in the blocked set, per mav-block-propagation.
  5. Checkpoint the eject (#83): uv run maverick task-progress set <repo> $ARGUMENTS ejected.
  6. Emit per-phase narrative notes so the eject report has context for the human reviewer:
    uv run maverick report note --issue $ARGUMENTS --phase review \
        --text "<one-sentence summary of what the reviewer flagged>"
    # ... one `report note` per phase that produced work worth narrating
    
  7. Release the claim: uv run maverick coord release <repo> $ARGUMENTS --reason ejected. Releasing also writes the workflow report (it prints report: <path>). If the release errors, generate it directly: uv run maverick report generate <repo> $ARGUMENTS.
  8. Do not destroy the worktree — the human may want to inspect it. Log the worktree path so the user can find it.

Follow-up Issues

Reviewers return low and informational notes on every story. Opening an issue per note buries the backlog in one-liners and duplicates. When the run ends (Phase 10 or 11):

  • Don't file notes the PR already fixed.
  • One issue per story for the remaining low and informational notes: a checklist in one body, the area in the title (Review notes from #$ARGUMENTS: <area>), labelled review-notes (create the label if it doesn't exist).
  • A separate issue only for an unfixed medium, high or critical finding, or for a distinct defect in code this story didn't change.
  • Search before filing. For each would-be issue, look for an open one that covers it (gh issue list --state open --search "<file path or key term>"). If one exists, comment on it instead of opening another.

File with the Maverick GitHub App identity (uv run maverick gh-app gh -- issue create …), with a body file under .maverick/tmp/ in the story's checkout. Docs drift from Phase 6 keeps its own single issue.

Rules

  • Only pause for user input when blocked or when the issue is ambiguous.
  • Never commit directly to the default branch. All work flows through the feature branch → PR.
  • Always use conventional commits referencing #$ARGUMENTS.
  • Push after every task. Durability trumps CI-cost optimisation.
  • Implementation runs in subagents. Every task and every fix goes to a fresh agent-implementer in the foreground. You keep its summary, never the code or the logs it read.
  • Binary review. PASS auto-merges; FAIL ejects. No fix loop.
  • Draft until settled. The PR is opened as a draft and marked ready only by Phase 10 step 3 or by an eject. Any later push to the branch first puts it back to draft with maverick pr ready --undo.
  • Two rounds, then change approach. After two review rounds on the same file or mechanism — security, docs accuracy or any other — stop point-patching. Security switches to a fail-closed design or ejects (Phase 7). For other reviews, the next round covers only the lines changed since the last one, not a fresh sample.
  • Release the claim on every exit path. Success, eject, abort, crash — all of them must release. Release is also what writes the report.
  • Every dispatch carries maverick-issue: $ARGUMENTS. Without it, runs inside an epic record no dispatches.
  • Never review your own code for security. The security gate is agent-security-reviewer's verdict, not yours.
  • Never remove a blocked-by:#N label from inside the workflow. Only a human may clear a block.
<!-- maverick-plugin-version: 5.3.2-dev -->