Spec: Equipo merge authority (gate, checks afterwards, Undo)
The coordinator merges approved work whose checks could not run for an environment reason when the change is small, touches no sensitive area, does not ship to users and the project has not lost trust; otherwise it asks with a recommendation. Covers the gate as code, change facts, sensitive paths, ships-to-users, post-merge checks and the fix task, revert as Undo, trust per project, policy in words, audit and tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+497
−0
docs/superpowers/specs/2026-11-11-equipo-merge-authority.md+497 −0
Intent
diff --git a/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md| new file mode 100644 |
| index 00000000..baa0375d |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md |
| @@ -0,0 +1,497 @@ |
| +# Equipo merge authority: when the coordinator merges without asking |
| + |
| +Status: spec addendum for review, 2026-11-11, revision 1. Drafted by |
| +Claude (Opus 5.5) on `merge-authority` from main ac4a809. Builds on |
| +slice 4c (`docs/superpowers/plans/SLICE4C-PROGRESS.md`: the merge step, |
| +the merge card, `ready_sha` and `merge_eligible`), Mac runners |
| +(`2026-11-07-equipo-mac-runners.md` §4.3, ruling 2) and housekeeping |
| +(`2026-11-08-equipo-housekeeping.md` §3, decision classes). Not |
| +implemented. |
| + |
| +## 0. Why |
| + |
| +Paul, on the card "Merge Swipe from the edge to go back doesn't work |
| +without checks? [Merge] [Wait for checks]": "How do we give the |
| +co-ordinator authority to merge stuff like this? I think it needs to be |
| +able to make a decision ... we can give it heuristics and best |
| +practice." This replaces his slice 4c ruling "ask once when checks |
| +can't run": Equipo decides, and asks only when its policy says so. |
| + |
| +Today (`internal/equipo/chat/merge.go`): a candidate whose checks |
| +`passed`, approved on the same SHA, first Ready under the policy |
| +(`merge_eligible`) and not checked outside the sandbox is merged at |
| +once. Anything else that is approved gets one merge card per SHA. This |
| +addendum adds a third outcome for approved work whose checks could not |
| +run: merge and tell, with Undo, then check afterwards. |
| + |
| +Three invariants, each tested as such: |
| + |
| +1. **The gate is code.** One pure function decides; no model output is |
| + an input that can make it merge. |
| +2. **Never looser.** The coordinator can only make a decision stricter |
| + (a hold, a tighter policy). Loosening needs a person who is an owner, |
| + by a tap or a form, never a tool call alone. |
| +3. **Every decision is recorded with its reasons**, in the transaction |
| + that acts on it. |
| + |
| +## 1. Decision classes |
| + |
| +The housekeeping classes, reused by name (`housekeeping.ClassAct`, |
| +`ClassAsk`, and the spec's Never): |
| + |
| +| Class | When | What happens | |
| +|---|---|---| |
| +| `act` (merge and tell) | every criterion of §2 holds | merge step dispatched; receipt card with Undo (§5); checks afterwards (§4) | |
| +| `ask` (with a recommendation) | approved, but a criterion fails, or the project says always ask | one merge card per SHA, worded as Equipo's call (§3) | |
| +| `never` | checks failed, review asked for changes, no verdict yet, branch moved, a merge in flight, task ended or cancelled | no merge, no card (fix rounds and Needs you as today) | |
| + |
| +The housekeeping principal still may never merge, open a merge card or |
| +change a merge policy (`hkForbid`, unchanged). |
| + |
| +## 2. The gate |
| + |
| +New package `internal/equipo/mergegate`, pure (no store, no clock |
| +beyond the input). `chat` builds the inputs inside the `advance` |
| +transaction and calls it at the moment a candidate first earns Ready |
| +(the existing `k.ReadySHA != p.candidate` branch), and again only on a |
| +person's Merge or Wait answer. |
| + |
| +```go |
| +type Inputs struct { |
| + Candidate string // newest pushed candidate, branch at it (not moved) |
| + Verdict string // review verdict on Candidate ("" if none) |
| + Checks string // passed | failed | none | cannot_run | "" |
| + ChecksReason string // e.g. needs_macos, runner_offline |
| + OutsideSandbox bool // checks ran with checks_sandbox none |
| + CanCheckLater bool // §2.2 |
| + Change *ChangeFacts // §2.3; nil when missing |
| + Policy Policy // §6; defaults when the project has none |
| + Repo RepoFacts // §2.5, from the primary's catalog |
| + AsksLeft int // §7 trust counter |
| + Hold string // coordinator hold (§3.2); "" when none |
| + FirstReady bool // this candidate earns Ready now |
| +} |
| + |
| +type Criterion struct{ Name string; OK bool; Value, Limit string } |
| + |
| +type Decision struct { |
| + Class string // act | ask | never |
| + Stance string // merge | wait (for ask) |
| + Checks bool // true: merges with checks passed |
| + Reasons []Criterion // every criterion evaluated, in a fixed order |
| +} |
| + |
| +func Decide(in Inputs) Decision |
| +``` |
| + |
| +### 2.1 Order of evaluation |
| + |
| +1. **Never**: `Verdict != approve`, `Checks == failed`, `Checks == ""` |
| + (still running), `Candidate == ""`. Class `never`. |
| +2. **Checks passed** (`Checks == passed`, not outside the sandbox, |
| + `FirstReady`): `act` with `Checks: true` unless `Policy.Mode == |
| + always_ask`, `AsksLeft > 0` or `Hold != ""`, which make it `ask` |
| + (options Merge, Not now). Size, sensitivity and shipping do not apply |
| + to judged work: slice 4c behaviour is unchanged for these. |
| +3. **Without checks**: `act` only when ALL of these hold, else `ask`: |
| + |
| +| Criterion | Holds when | |
| +|---|---| |
| +| `approved_exact_sha` | `Verdict == approve` on `Candidate`, branch at it | |
| +| `environment_reason` | `Checks == cannot_run` and `ChecksReason` in `{needs_macos, runner_offline}` | |
| +| `can_check_later` | `CanCheckLater` (§2.2) | |
| +| `small` | `Change != nil`, `Change.Lines <= Policy.MaxLines`, `Change.Files <= Policy.MaxFiles`, no binary file; skipped when `Policy.Mode == review_enough` | |
| +| `not_sensitive` | `Change != nil`, `!Change.Truncated`, no path matches §2.4, `!Change.Signing` | |
| +| `not_shipping` | §2.5 says main is not a release | |
| +| `trusted` | `AsksLeft == 0` | |
| +| `no_hold` | `Hold == ""` | |
| +| `policy_allows` | `Policy.Mode != always_ask` | |
| +| `first_ready` | `FirstReady` (never retroactive, as slice 4c) | |
| + |
| +`none` (no gate found), `checks_timeout`, `checks_unavailable` and |
| +`needs_network` are not environment reasons: the gate ran partly, or |
| +there is nothing to run afterwards. They always ask. |
| +`OutsideSandbox` with checks passed asks, as today (Mac runners ruling |
| +2 is not widened here). |
| + |
| +### 2.2 Can check later |
| + |
| +True when the task's person has an enrolled runner, not being removed, |
| +whose tags cover the checks' needs (`checksNeeds`, the same tags that |
| +placed them), online or not. False when no such runner was ever enrolled |
| +(nobody could check it afterwards, so Equipo asks). |
| + |
| +### 2.3 Change facts: what the change is, measured by the runner |
| + |
| +New `wire.ChangeFacts`, carried on the **Review** step's report (Review |
| +always runs on the primary until slice F, always before approval, on |
| +exactly the candidate): |
| + |
| +```go |
| +type ChangeFacts struct { |
| + Base string `json:"base"` // merge-base(task base, candidate) |
| + SHA string `json:"sha"` // == candidate |
| + Files int `json:"files"` |
| + Lines int `json:"lines"` // added + deleted, text files |
| + Binary int `json:"binary"` // files numstat reports as "-" |
| + Special bool `json:"special"` // a submodule or symlink changed |
| + Signing bool `json:"signing"` // §2.4 content rule |
| + Paths []string `json:"paths"` // up to MaxChangePaths (200), each <= 300 bytes |
| + Truncated bool `json:"truncated"` // more paths than were sent |
| +} |
| +``` |
| + |
| +The runner computes it deterministically (no model) from |
| +`git diff --numstat -z -M <base> <candidate>` in the review tree. The |
| +instance keeps it only from the person's primary runner, only when |
| +`SHA == candidate` and the step's `CandidateSHA` matches, stored as JSON |
| +on the review step (`change_facts`). Anything missing, malformed or from |
| +a worker leaves `Change` nil, which fails `small` and `not_sensitive` |
| +(ask). An old runner sends nothing, so it asks, as today. `Special` |
| +counts as sensitive (dependency or infrastructure). |
| + |
| +### 2.4 Sensitive areas |
| + |
| +Defaults are a table in `mergegate/sensitive.go`, matched on the path, |
| +case-insensitive. A path's **tokens** are its segments split on `/`, |
| +`.`, `-`, `_` and lower-to-upper case changes; token rules match whole |
| +tokens only (so `keyboard` is not `key`). |
| + |
| +| Class | Paths (glob) | Tokens | |
| +|---|---|---| |
| +| `migrations` | `**/migrations/**`, `**/migrate/**`, `**/*.sql`, `**/schema.*`, `**/*.prisma`, `**/db/schema*` | `migration`, `migrations`, `schema` | |
| +| `auth_secrets` | `**/.env*`, `**/*.pem`, `**/*.key`, `**/*.p12`, `**/*.p8`, `**/*.keystore`, `**/*.jks`, `**/*.keychain*` | `auth`, `authn`, `authz`, `oauth`, `oidc`, `saml`, `jwt`, `login`, `logout`, `signin`, `signup`, `session`, `sessions`, `password`, `passwords`, `passwd`, `credential`, `credentials`, `secret`, `secrets`, `token`, `tokens`, `key`, `keys`, `keychain`, `crypto`, `cipher`, `encrypt`, `decrypt`, `cert`, `certs`, `certificate`, `tls`, `ssl`, `permission`, `permissions`, `acl`, `rbac` | |
| +| `payments` | | `payment`, `payments`, `billing`, `stripe`, `checkout`, `invoice`, `invoices`, `subscription`, `subscriptions`, `purchase`, `purchases`, `storekit`, `iap`, `paywall`, `refund`, `refunds` | |
| +| `ci_config` | `.amadan/**`, `.github/**`, `.gitlab-ci.yml`, `.circleci/**`, `.buildkite/**`, `Makefile`, `GNUmakefile`, `makefile`, `**/*.mk` | | |
| +| `dependencies` | `go.mod`, `go.sum`, `**/package.json`, `**/package-lock.json`, `**/yarn.lock`, `**/pnpm-lock.yaml`, `**/Cargo.toml`, `**/Cargo.lock`, `**/Gemfile*`, `**/requirements*.txt`, `**/pyproject.toml`, `**/poetry.lock`, `**/Pipfile*`, `**/uv.lock`, `**/Package.swift`, `**/Package.resolved`, `**/Podfile*`, `**/Cartfile*`, `**/*.gradle*`, `**/gradle.lockfile`, `**/composer.*`, `**/mix.exs`, `**/mix.lock`, `.gitmodules`, `vendor/**` | | |
| +| `release_signing` | `**/*.entitlements`, `**/*.mobileprovision`, `**/ExportOptions*.plist`, `fastlane/**`, `**/*.xcconfig`, `.goreleaser*`, `**/VERSION`, `release/**`, `releases/**` | `release`, `signing`, `entitlements`, `provisioning` | |
| +| `infrastructure` | `**/*.tf`, `**/*.tfvars`, `**/*.hcl`, `terraform/**`, `infra/**`, `infrastructure/**`, `deploy/**`, `k8s/**`, `helm/**`, `**/Dockerfile*`, `**/docker-compose*`, `**/*.service`, `fly.toml`, `vercel.json`, `netlify.toml`, `render.yaml`, `Procfile`, `app.yaml`, `carlos.toml` | `terraform`, `ansible`, `pulumi`, `cloudformation`, `deploy` | |
| + |
| +**Content rule** (`Signing`, computed by the runner): an `.pbxproj`, |
| +`.xcconfig` or `Info.plist` change whose added or removed lines name |
| +`CODE_SIGN`, `DEVELOPMENT_TEAM`, `PROVISIONING_PROFILE`, |
| +`ENTITLEMENTS`, `PRODUCT_BUNDLE_IDENTIFIER`, `MARKETING_VERSION`, |
| +`CURRENT_PROJECT_VERSION`, `CFBundleVersion` or |
| +`CFBundleShortVersionString`. A plain `.pbxproj` change (Xcode adding a |
| +file) is not sensitive by itself. |
| + |
| +**Per project**, the policy may add globs (`extra_sensitive`, at most |
| +20, each <= 200 bytes, validated with `path.Match` syntax plus `**`). |
| +Nobody can remove a default: the table is code. The receipt and the |
| +card name the class and the first matching path. |
| + |
| +### 2.5 "Merging ships to users" |
| + |
| +`not_shipping` is decided from three inputs, in this order: |
| + |
| +1. **Deploy signal on the default branch** (stricter wins): the |
| + primary's index of the repository (`wire.RepoInfo`, protocol bump) |
| + gains `deploy_signals []string`, the paths at `head_sha` that suggest |
| + main deploys: any of the `infrastructure` hosting files above |
| + (`fly.toml`, `vercel.json`, `netlify.toml`, `render.yaml`, `Procfile`, |
| + `app.yaml`, `carlos.toml`), `.amadan/deploy*`, an `.amadan/ci.d/*` |
| + file or a `.github/workflows/*` or `.gitlab-ci.yml` that names |
| + `deploy`, `release` or `publish` together with the default branch or |
| + `push`. Any signal: **ships**, whatever the policy says (the card |
| + names the file). |
| +2. **Policy** `main_ships`: `yes` ships; `no` does not. |
| +3. **Default** (`main_ships: auto`): an Xcode app (`RepoInfo.NeedsMacOS` |
| + from its project files, the index's existing flag) does not ship from |
| + main: it ships through a store release (Woodstar). Anything else is |
| + **unknown, which counts as ships** and asks; the card's |
| + recommendation says so and the project page offers "Main is not a |
| + release". |
| + |
| +A repository missing from the catalog, or an index older than 24 hours, |
| +is unknown (ships). |
| + |
| +## 3. Asking, with a recommendation |
| + |
| +### 3.1 The card |
| + |
| +The existing `merge` card, one per SHA (`merge_asked`), in the |
| +creator's conversation only. Its question becomes Equipo's call, |
| +composed by the instance from the decision (no model turn): |
| + |
| +- `Stance: merge` when the only failing criteria are `small`, |
| + `not_shipping` with an unknown default (not a signal, not `yes`), and |
| + `policy_allows`: "I'd merge: %s. [Merge] [Wait ...]". |
| +- `Stance: wait` otherwise: "I'd wait: %s. [Merge] [Wait ...]". |
| + |
| +`%s` joins at most three phrases, from the criteria in order: what |
| +passed for merge ("approved by Review", "a small change, %d lines in %d |
| +files", "nothing ships until a release"), what failed for wait ("it |
| +touches payments (%s)", "Woodstar ships from main (%s)", "checks failed |
| +on main after a recent merge", the coordinator's hold text). |
| + |
| +Options by case: checks could not run for `needs_macos` or |
| +`runner_offline` with a Mac-tagged need: **Merge**, **Wait for a Mac**; |
| +other cannot-run reasons and `none`: **Merge**, **Wait for checks**; |
| +checks passed but asked (always ask, trust, hold): **Merge**, **Not |
| +now**. |
| + |
| +**Wait for a Mac / Wait for checks** now means something: the checks |
| +step for the same SHA is queued again (attempt n+1) with no |
| +`OfflineLimit` (it waits for a runner that fits), and the person's |
| +answer is recorded as consent: when those checks pass the candidate is |
| +merged under the checks-passed rule (`merge_eligible` set by the |
| +answer); when they fail, the fix round runs as usual. A Wait on a task |
| +whose person has no runner that could ever run them (`can_check_later` |
| +false) is Wait for checks with today's meaning (stays at Ready to |
| +merge; Merge stays offered). |
| + |
| +The card is touched or withdrawn exactly as today when the branch moves |
| +or a new candidate arrives. |
| + |
| +### 3.2 The coordinator: stricter only |
| + |
| +- New tool `hold_merge{task, reason}` (own task, not final, not |
| + merging): sets `task.merge_hold` (plain text, <= 200 bytes). A held |
| + task never merges on its own; its card stance is wait with the reason |
| + as the coordinator's words. The coordinator has no tool to release a |
| + hold; the person's Merge on the card is the release for that SHA. |
| +- The coordinator's text reaches the gate only as `Hold`, which can only |
| + turn `act` into `ask`. The coordinator never supplies `Stance: merge`. |
| +- `read_task` shows the decision (class, stance, reasons) so the |
| + coordinator can explain it in conversation. |
| + |
| +## 4. Checks afterwards |
| + |
| +### 4.1 The post-merge step |
| + |
| +`mergeDone` for any merge labelled without checks (Equipo's own or a |
| +person's Merge on the card) creates, in the same transaction, a checks |
| +step on the done task: `post_merge: true`, `CandidateSHA` = the merge |
| +commit, `BaseSHA` = the task's base (so `needsMacOS` sees the change), |
| +the person and needs as the task's checks. Placement and the step |
| +report treat it as ordinary checks with three exceptions: |
| + |
| +- `placeWaiting`, `offline` and `Place` admit `post_merge` steps on a |
| + done task (today they skip final stages). |
| +- `offline` never resolves them `runner_offline`; they wait up to |
| + `PostMergeWait` (14 days), then end `cannot_run` |
| + `post_merge_expired`. |
| +- `progressOf` ignores them (their SHA is not the candidate), and |
| + `advance` stays a no-op on a done task; the outcome is applied by |
| + `postMergeResult` after the report is saved. |
| + |
| +The worker's pack relay serves the merge commit as it serves a |
| +candidate: the primary fetches the default branch before packing a SHA |
| +it does not have (a test proves a merge commit reaches a Mac worker). |
| + |
| +### 4.2 Outcomes |
| + |
| +- **Passed**: the receipt card gains "Checks passed on main afterwards." |
| + (new revision; no new message); trust counts down (§7); audit row. |
| +- **Failed**: at once, in the same transaction: trust lowered (§7); a |
| + **fix task** recorded and started under the task's creator, title |
| + `Fix checks after merging %s` (clipped to the task title bound), brief |
| + with the merge SHA, the gate, the exit code and the last 60 lines of |
| + output, base the default branch's tip at dispatch, through the same |
| + store functions as `record_task` and `start_task` (owner check, |
| + execution enabled; if either fails it is recorded and not started, and |
| + the line says so); one coordinator line in the creator's conversation: |
| + "Checks failed on main after I merged [%s](%s). I opened [%s](%s) to |
| + fix it." Idempotent per post-merge step. At most one open fix task per |
| + project from this path: a later failure adds a report to it |
| + (`add_report`'s store path) instead of a second task. |
| +- **Could not run** (any cannot-run reason, or expired): audit row and |
| + one line: "Checks still could not run on main after merging [%s](%s) |
| + (%s)." Trust unchanged. |
| + |
| +The fix task itself goes through this gate with trust lowered, so it |
| +asks. |
| + |
| +## 5. Receipt and Undo |
| + |
| +An `act` merge without checks gets a receipt card (new kind |
| +`merge_receipt`) in the creator's conversation instead of the |
| +`chat.merged_without_checks` line: "Merged [%s](%s) into %s without |
| +checks: %s. Checks run on main when a Mac is online. [Undo]" (`%s` = |
| +the passing phrases of §3.1; the second sentence names "a runner" when |
| +the need is not a Mac). Receipts follow housekeeping's act-and-tell |
| +rules: visible at once on the task page, in the conversation at |
| +`visible_at` (the person's quiet hours), Undo for `UndoWindow` (7 days). |
| +A checks-passed merge keeps today's plain line and no Undo. |
| + |
| +**Undo is a revert through the same merge path.** The creator's Undo |
| +(card or `POST /api/v1/tasks/{id}/undo-merge`; owner, the creator, the |
| +receipt's revision; 409 when already undone, outside the window, or the |
| +task is not Equipo's merge) does, in one transaction: |
| + |
| +1. records a **revert task** (`revert_of` = the task; title "Undo %s"; |
| + creator the undoing person) and sets `reverted_by` on the original; |
| +2. dispatches its first step, a new deterministic specialist `revert` |
| + (no model): the primary fetches, checks out the default branch's |
| + tip, runs `git revert --no-edit -m 1 <merge sha>` (plain revert for a |
| + squash), commits as Equipo's agent identity, pushes the revert task's |
| + branch with `PushBranch` (record then reconcile) and reports the |
| + candidate. A conflict ends it `revert_conflict`: Needs you on the |
| + revert task, with Start to let Engineering resolve it like any task; |
| +3. on the revert's candidate, the instance dispatches the ordinary merge |
| + step (`forge.MergeBranch`, expect_sha, the hub's own CI rule), |
| + labelled without checks, decided by the person (audit); |
| +4. lowers trust (§7). |
| + |
| +The revert merge gets its own post-merge checks (§4). Undo is offered |
| +only when the person's primary runner advertises the `revert` |
| +capability in hello (an older runner would refuse the dispatch). |
| + |
| +## 6. Policy per project, in words |
| + |
| +### 6.1 Storage |
| + |
| +Migration **0058** (next free on main ac4a809; other open branches may |
| +also claim 0058, so whichever lands second renumbers) adds: |
| + |
| +`chat_merge_policies` (team record, one row per project): |
| +`project_id` primary key, `mode` (`rules` | `review_enough` | |
| +`always_ask`), `max_lines` (default 300, 0 to 2000), `max_files` |
| +(default 15, 0 to 100), `main_ships` (`auto` | `no` | `yes`), |
| +`extra_sensitive` (JSON list), `words` (the person's sentence, <= 300 |
| +bytes, display only), `asks_left`, `trust_reason`, `trust_since`, |
| +`revision`, `updated_by`, `updated_at`. No row means defaults (`rules`, |
| +300, 15, `auto`, none, 0). |
| + |
| +`chat_merge_audit` (append only, §8). |
| + |
| +Columns: `chat_steps.post_merge`, `chat_steps.change_facts`; |
| +`chat_tasks.merge_hold`, `chat_tasks.revert_of`, |
| +`chat_tasks.reverted_by`, `chat_tasks.merge_decision` (the newest audit |
| +row's id). All additive; existing Ready tasks keep their open cards |
| +(no backfill makes anything eligible). |
| + |
| +The instance never parses the words. They are what the person said; |
| +the structured fields are what the gate reads. |
| + |
| +### 6.2 Setting it |
| + |
| +- **In conversation**: new tool `set_merge_policy{project, words, mode?, |
| + max_lines?, max_files?, main_ships?, add_sensitive?}`. The instance |
| + compares each field with the stored policy. Fields that are tighter |
| + (mode towards `always_ask`, smaller numbers, `main_ships: yes`, added |
| + globs) are applied at once with a receipt and Undo (the home card's |
| + revision pattern). If any field is looser, nothing is applied: a |
| + confirm card "Change how Equipo merges %s: %s? [Save] [Cancel]" goes to |
| + the person, and Save (an owner's tap, current revision) applies the |
| + whole change. "for Woodstar, merge when Review approves" maps to |
| + `review_enough`; "always ask me about Suite" to `always_ask`. |
| +- **On the project page**: a section "How Equipo merges" (a partial |
| + template `merge_policy.html` included with one line in |
| + `work_project.html`, to stay clear of the Projects and Tasks redesign) |
| + shows the current policy in plain sentences, the words, the trust |
| + state ("Asking for the next %d merges: checks failed on main after |
| + %s."), and the last five decisions with their reasons; an owner's |
| + form edits the fields directly (a person's action, so it may loosen), |
| + CSRF and revision checked; teammates see it read only. |
| +- `GET/PUT /api/v1/projects/{id}/merge-policy` mirror the form. |
| + |
| +Hard limits are code: `review_enough` waives only `small`; no policy |
| +waives `approved_exact_sha`, `environment_reason`, `can_check_later`, |
| +`not_sensitive` defaults, a deploy signal, `trusted` or `no_hold`. |
| + |
| +## 7. Trust per project |
| + |
| +`asks_left` on the policy row: |
| + |
| +- set to **5** (with `trust_reason`) when post-merge checks fail or an |
| + Undo merges a revert; a second failure while lowered resets it to 5; |
| +- counts down by one for each later **clean** merge into the project: |
| + a merge with checks passed (at `mergeDone`), or a merge without checks |
| + whose post-merge checks passed (at that result); |
| +- `asks_left > 0` fails `trusted`: every merge in the project asks, |
| + including checks passed (§2.1 step 2). At 0 trust is restored and |
| + the project page says so. |
| + |
| +Changes to `asks_left` are audit rows. |
| + |
| +## 8. Audit |
| + |
| +`chat_merge_audit`: `id`, `project_id`, `task_id`, `kind` (`decision`, |
| +`answer`, `merged`, `post_merge`, `fix_task`, `undo`, `trust`, |
| +`policy`), `candidate_sha`, `merge_sha`, `class`, `stance`, |
| +`decided_by` (`policy`, `person:<id>`, `coordinator:<id>`), `reasons` |
| +(JSON: every `Criterion`), `inputs` (JSON: the facts used, without |
| +paths beyond the first ten, policy revision, index head and signals, |
| +checks reason, review label, `asks_left`), `created_at`. Written in the |
| +same transaction as the effect; the transaction also appends the |
| +instance's audit event as every write does. No credentials, no model |
| +prose except the hold text. Read by the project page and `read_task`. |
| + |
| +## 9. Failure modes |
| + |
| +| What goes wrong | What happens | |
| +|---|---| |
| +| Runner sends no or bad change facts | `Change` nil: asks | |
| +| A worker reports change facts | ignored (primary only): asks | |
| +| Index stale or missing | ships unknown: asks | |
| +| Branch moves after the decision | the runner's expect_sha refuses (`branch_moved`), as today | |
| +| Policy tightened while a merge step is in flight | the merge completes (merging cannot be cancelled); the next decision uses the new policy | |
| +| Mac never comes back | post-merge checks expire after 14 days with one line; `can_check_later` stays true only while the Mac is enrolled | |
| +| Post-merge checks fail repeatedly | one open fix task per project; later failures are reports on it | |
| +| Fix task cannot start (not an owner, execution off) | recorded, not started; the line says so | |
| +| Revert conflicts | Needs you on the revert task; nothing merged | |
| +| Old runner, no `revert` capability | no Undo offered; the receipt says how to revert on Amadan | |
| +| Deploy on upgrade with Ready tasks | only candidates first Ready after the deploy are decided; open cards stay | |
| +| The coordinator tries to loosen | confirm card; nothing changes without a tap | |
| +| Hub refuses (`ci_not_green`, forbidden) | today's reasons and Retry | |
| + |
| +## 10. Test plan |
| + |
| +Write each test first and watch it fail; break each guard and watch a |
| +test fail (mutations recorded in the progress log). |
| + |
| +- `mergegate`: `TestDecideEachCriterion` (all pass: act; each failing |
| + alone: ask with that criterion named); `TestDecideNever`; |
| + `TestDecideChecksPassedPath`; `TestDecideNeverLooser`, an invariant |
| + simulation over random inputs: `act` without checks implies every row |
| + of §2.1 holds (an independent oracle), a hold never yields `act`, |
| + no `Hold` text yields `Stance: merge` on its own; |
| + `TestSensitivePaths` (each class, token boundaries, `keyboard`, |
| + `monkey`, signing content rule, extra globs only add); |
| + `TestShipsToUsers` (signal beats `no`, native default, unknown asks). |
| +- Runner: `TestReviewReportsChangeFacts` (numstat, renames, binary, |
| + submodule, symlink, truncation, signing lines); `TestRevertStep` |
| + (clean, conflict, crash after push reconciles, squash); |
| + `TestPostMergeChecksOnMergeCommit` (worker pack relay of a merge SHA). |
| +- Store contracts (`internal/equipo/chat`): `TestContractMergeAuthorityAct` |
| + (Woodstar-shaped needs_macos change merges, receipt, audit row, |
| + post-merge step waiting); `TestContractMergeAuthorityAsks` (each |
| + criterion yields the card with the stance and options of §3.1); |
| + `TestContractWaitForAMac` (requeue without the offline limit, pass |
| + merges, fail fixes); `TestContractPostMergePassed`, |
| + `TestContractPostMergeFailed` (fix task started, one line, trust 5, |
| + next merge asks, second failure is a report); |
| + `TestContractUndoMerge` (revert task, revert step, merge step, trust, |
| + window, 403/404/409); `TestContractTrustCountdown`; |
| + `TestContractMergePolicyTool` (tighter applies with Undo, looser makes |
| + a confirm card, Save by an owner applies, a teammate cannot); |
| + `TestContractHoldMerge`; `TestContractMergeAuthorityNotRetroactive` |
| + (0058 on a database with a Ready task and an open card). |
| +- Pages: `TestProjectPageMergePolicy` (section, form, read only for |
| + teammates); browser `TestBrowserMergePolicy` with `-run`. |
| +- Headless: `ma_act` (fake CLI, local forge: an iOS change merges and |
| + tells, a fake Mac worker comes online, post-merge checks pass) and |
| + `ma_fail` (they fail: fix task, line, the next merge asks). |
| +- Gates kept green: `make budget`, gofmt, `go vet ./internal/...`, |
| + `scripts/runner-dead-references.py`, `TestPlan3ReleaseBoundaries`. |
| + |
| +## 11. Copy |
| + |
| +All new strings in `internal/equipo/copy.go` marked `COPY REVIEW |
| +REQUIRED` and listed in the Plan 3 copy inventory: the card stances |
| +and phrases (§3.1), Wait for a Mac, the receipt and its passed line |
| +(§5), the failure, fix-task and could-not-run lines (§4.2), Undo's |
| +refusals, the policy confirm card and receipts (§6.2), the project page |
| +section, the trust sentence, the tool descriptions of `hold_merge` and |
| +`set_merge_policy`. |
| + |
| +## 12. Choices to confirm with Paul |
| + |
| +1. Trust: "a clean run restores it" read as: five clean merges restore |
| + it, and a failure while lowered starts the five again. |
| +2. Lowered trust and `always_ask` also ask for checks-passed merges. |
| +3. Any binary file (an image asset) asks. |
| +4. "merge when Review approves" waives only the size limit. |
| +5. Projects that are not Xcode apps and have no deploy signal ask until |
| + someone says "main is not a release". |