magi-cli 0.274.0

Blind multi-agent implementation competition: N agents implement, M judges rank blind, deliberate, vote privately, winner survives double review + E2E gate
Documentation
# Releases

Conventions for this area of magi. `AGENTS.md` indexes these files: read this
one before changing the code it covers.

## The package is `magi-cli`, everything else is `magi`

`magi` on crates.io is an 882-byte placeholder (`description = "Placeholder"`,
no repository), and crates.io does not reclaim names. So, exactly as
`yukimemi/yui` publishes `yui-cli`:

| thing | name | set in |
|---|---|---|
| crates.io package | `magi-cli` | `[package] name` |
| library | `magi` | `[lib] name` — keeps `use magi::…` working |
| binary | `magi` | `[[bin]] name` |
| GitHub repo | `magi` | — |

`release.yml` derives `BIN_NAME` from the *repo* name, so it already matches
`[[bin]] name` and needs no override.

**`CARGO_PKG_NAME` is therefore not usable as a repo or binary name.**
`src/updater.rs` spells all four out as constants and passes
`.crate_name("magi-cli")` so kaishin's `cargo install` fallback reaches the right
package. Deriving them would make `magi self-update` look for a
`yukimemi/magi-cli` repository that does not exist — which is a live bug in
`yui`, whose updater omits `.crate_name` and would `cargo install yui`, an
unrelated crate by another author.

## Release bumps outside a root `Cargo.toml` (`[release] version_files`)

`src/release_manifest.rs` (pure, plus `apply`) resolves, reads, checks and
rewrites the declared files; `bump`, `release_local` (`bumped_by`, the version
check in `drive`) and `branch_version` all take the version-of-record path from
`release_manifest::primary_path`. Unset means the root `Cargo.toml` and the old
`cargo build` lock sync, unchanged.

- **Declared, never detected.** The first entry must be a `Cargo.toml` with
  kind `cargo` and be the file the repository's `auto-tag.yml` reads; JSON
  files get one string replaced. With declared files the lock beside the first
  entry is edited as text (no `cargo build`: a Tauri crate may not build here)
  and exactly one entry must match. `package-lock.json` is out of scope. shun's
  own `magi.toml` needs the list from the README; that is a change in its repo.
- **A skip is state, not prose.** `ReleaseBump::skipped` (`#[serde(default)]`,
  `run::SCHEMA` unchanged) records no-manifest, disagreeing files, a change that
  already raised the version, and release-only changes. `Skip::action` also
  sets `action_required` and raises a `release-bump:<run>` notice (no manifest
  with an `auto-tag.yml` present, disagreeing files). Unreadable versions are
  unknown, never "unchanged". The already-raised check applies only with
  declared files; the legacy default path is untouched.
- Approval gates, automerge, local-mode approval and the no-manual-tag rule are
  not changed by any of this.

## Releasing without GitHub Actions (`[release] mode = "local"`)

For repositories whose Actions never run (private, no minutes): the release
PR's checks never report, so nothing merges it and `auto-tag.yml` /
`release.yml` never fire. `[release]` in `magi.toml` is opt-in per repository;
**the default `mode = "actions"` changes nothing**.

```toml
[release]
mode = "local"                      # actions (default) | local
commands = ["cargo build --release", "gh release create \"$MAGI_RELEASE_TAG\" --generate-notes"]
timeout_minutes = 30                # per command
```

- **Land gate.** `bump::open_bump_pr` arms no automerge and never merges
  directly (that would skip the approval): it returns
  `AutomergeOutcome::LocalGate`, records `ReleaseBump::local`, and registers
  the PR with the release watcher. `land::decide_with(.., CiExpectation::Absent)`
  is the "no CI will ever exist" reading of `land::decide` (`Expected`, what
  `decide` always passes, is unchanged); the watcher's own `decide_local` is
  pure and applies the same rule to a `RollupView`. A conflict is not a check
  and still stops.
- **The approval follows `graph.land_approval`, and is bound to the head.**
  With it on (the default), or when the repository config cannot be read
  (`ReleaseForge::land_approval` errors: ask, never merge), the watcher files a
  `bump::NOTICE_NODE` question (`merge` / `hold`, no run, no `cwd`) recording
  the head it observed; `merge` runs `gh pr merge --match-head-commit <head>`
  and the forge decides whether it merged (`land::merged_after_all`). An answer
  about an older head asks again; silence and `hold` stay put until the head
  moves. With it off, `decide_local` returns `Merge(<observed head>)` for a head
  nobody was asked about and the same head-bound merge runs with no question,
  then `run_job` as after an approved merge. An approval question that is
  already open is still respected, and a recorded `hold` is not undone by
  turning the setting off. Unchanged either way: nothing moves on an unreadable
  forge answer, a moved head is judged afresh, a conflict still stops, no
  `--admin`. A merge the forge refuses or does not confirm holds that head with
  a "merge it by hand" notice and is not retried until the head moves. CI rerun
  and stall escalation do not apply to a local PR.
- **After the merge** `release_local::run_job` runs from a clean detached
  checkout of the merge commit: the Cargo.toml version there must equal the
  release version; the tag is created (annotated) and pushed with an explicit
  refspec, no force, and **only if neither the remote nor this checkout has it**
  (`tag_step`: a remote tag at the merge commit is "already done", anywhere else
  is `Foreign`, an unreadable remote is `Unreadable` - never "absent"). Then
  `commands` run one at a time through `Config::shell()`; the first failure
  stops the list. Output goes to `<home>/release-local/<id>/release-<n>.out`
  and its tail into the record (`WatchState::job`), not into a run: the release
  PR's own run is long finished.
- **Environment, not templates**: `MAGI_RELEASE_VERSION`, `MAGI_RELEASE_TAG`,
  `MAGI_RELEASE_COMMIT`, `MAGI_RELEASE_PR`. `{{ version }}` cannot work:
  teravars renders the whole file before any release exists.
- **A failure holds, and nothing retries blind.** A failed command, a
  `Foreign` tag or an unreadable remote raises a notice and one question
  (`retry` / `leave it`); silence is a hold. `retry` resumes from the recorded
  progress: the tag is not recreated and finished commands are skipped.
  Progress is saved *before* every step, so a step that was started and never
  finished (crash, kill) is **unfinished, not failed**: magi cannot know whether
  `gh release create` reached the forge, so it holds with that wording and the
  owner decides. Write the commands to be safe to repeat. The failure is saved
  together with the cleared step, so a stop in between cannot make a failed
  command look retryable. A held job **keeps its checkout** (a resumed
  `gh release create` needs what `cargo build --release` made); only a finished
  release removes it. The task that opened the PR (found through the run id
  recorded at registration) is held with `hold_machine` (reason prefixed
  `[release] `), since the daemon marked it Done at the merge. The hold is
  reconciled on every lap while the job is failed or interrupted (so a restart
  between saving the failure and holding cannot lose it), recorded in
  `WatchState::held_task`, and given back (`Task::succeed`) when a retry
  finishes - only if the task is still a machine hold with that prefix.
- **The version comes from the manifest, not the branch name.** An escalated
  bump (patch -> minor) keeps its first branch name but gets a new title and
  manifest. The merge commit's `Cargo.toml` decides (`release_local::reconcile_version`):
  it replaces the job's version only before anything is tagged or run, and only
  when the title names it or the merge commit itself changed the version
  relative to its first parent; otherwise a mismatch still refuses to tag. A
  record failed with that mismatch recovers on `retry`. Adopting an open release
  PR (`bump.rs`) likewise reads its head's manifest, falling back to the branch name.
- **Needs `magi serve`** (the watcher is a task inside it) and
  `[daemon] release_stall_minutes > 0` (`0` switches the watcher off, local
  releases included). The per-repo config is read with `Config::discover(repo,
  None)`; if it cannot be read the PR is watched as an Actions release and a
  `tracing::warn` says so. Releases are driven one at a time (the watcher is a
  single sequential task), which is the per-repository exclusion.
- **Branch protection.** magi never uses `--admin`. If the base branch
  requires checks that never report, the merge is refused and the watcher
  raises a notice; merge by hand (the next lap releases it) or relax the rule.
- **Do not also publish from a workflow.** With `auto-tag.yml` /
  `release.yml` present and Actions running, the same tag or publish would
  happen twice. Local mode is for repositories where they cannot run.
- **Known gap.** The merge commit is read from the forge after the merge; if
  the forge has not recorded it yet the job is created on a later lap. A PR
  merged by hand is released by the watcher too, but one that was never
  registered or watched (opened by hand, not by magi) is not.
- Tests: `release_local` (real temp git repo + bare remote, `true` / `false`
  commands) and `release_watch` (fake forge) for the flow; `config` for the
  keys and defaults.

## A release PR is watched until it lands

`src/release_watch.rs` is scheduled by `magi serve` through independent finite
service workers, like waiter recovery. It is not a queue step or tied to a run:
a pending bump is coalesced across runs and outlives the run that opened it.
Its in-flight release work survives scheduler replacement; later laps use the
new generation and retain the explicit `serve --config` layer.

- **The forge is the truth.** Every open pull request whose head branch starts
  with `chore/release-v`, in the checkouts under `[repos] roots` plus the
  serve repo. The pending marker is not read, so a missing one changes
  nothing. A pull request that leaves the open list stays watched until
  `land`'s lifecycle read confirms merged / closed; only then are its notice
  dismissed, its question abandoned and its record deleted.
- **`release_watch::decide` is pure.** An unreadable forge answer is
  `Unknown`: nothing moves, not even the stall clock. It deliberately does not
  reuse `land::rollup_verdict`, whose pending-anywhere rule would let another
  run's pending job hide a failure; a failed check is judged by its own
  workflow run (`land::run_of`) being complete. A failure with no run id (an
  external status context) cannot be rerun and escalates once nothing is
  pending.
- **A failed run is rerun at most once.** The run id is written to
  `<home>/release-watch/<id>.json` *before* `gh run rerun <id> --failed`, so a
  restart cannot rerun twice; if the call itself fails the cost is an
  escalation, never a retry loop. Reruns are keyed by run id and forgotten
  when the head moves. The forge keeps reporting the old failure for a moment
  after a rerun, so `RERUN_GRACE` (180 s) must pass before "still red" is
  believed (trade-off: a very slow flip costs one early question).
- **Escalation is a notice plus a question**: still red after the rerun, or no
  new head / check state for `[daemon] release_stall_minutes` (default 60, `0`
  turns the watcher off). The notice key is `release-pr:<owner/repo>#<n>` and
  its text is fixed per stage (no counts, times or job names, so a poll never
  relights it); job names and links ride in the question. The question uses
  `bump::NOTICE_NODE`, no run and no `cwd`, so `settle_run`, the waiter, the
  deputies and `notices::covers` ignore it (a test pins that), and it pages
  once, through the notice.
- **The owner's choice is applied by the watcher on its next lap**, not by the
  daemon's task-bound action path: `rerun again` clears the failed runs'
  records for one more rerun, `hold` (and silence or an abandoned question)
  holds the current fingerprint until a check or the head changes, `leave it`
  stops watching and dismisses the notice. `WatchState::applied` makes an
  answer count once. The watcher never merges, closes or pushes.
- Every side effect is best-effort (`tracing::warn`), and every forge access
  goes through `ReleaseForge`, so tests inject a fake and never touch `gh`,
  a port or the real home.