@sjawhar/opencode-legion-envoy 3.12.1 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,20 @@ copy the next phase can trust.
14
14
  Every path this skill cites (`packages/...`, `docs/...`, `AGENTS.md`) is in sjawhar/legion, the
15
15
  Legion repository, which need not be the repository you are working in.
16
16
 
17
+ ## References
18
+
19
+ Each file below is part of this skill. Read it at the step beside it, through its `skill://` link
20
+ with the `read` tool: a read by filesystem path stops at 300 lines.
21
+
22
+ | When | Read |
23
+ | --- | --- |
24
+ | You write or edit the PR body, record a proof (an `E2E` line or a handoff `proof` array), verify another phase's proof, or run the simplify pass | `skill://legion-worker/references/pr-body.md` |
25
+ | You reply to, accept, or resolve a review thread, or run `legion threads resolve` | `skill://legion-worker/references/review-threads.md` |
26
+ | GitHub reports a conflict, the pull request is retargeted, you compare heads after a conflict merge, or you would rewrite a pushed commit | `skill://legion-worker/references/conflicts-and-rewrites.md` |
27
+ | You review or approve, push the `.legion/` deletion, publish READY, or check the merge in production | `skill://legion-worker/references/merge-gate.md` |
28
+ | The issue renames a repository, package, or URL across the codebase | `skill://legion-worker/references/systematic-rename.md` |
29
+ | The issue deletes code, a command, or documentation | `skill://legion-worker/references/cleanup-deletion.md` |
30
+
17
31
  ## Identity, scope, and role
18
32
 
19
33
  The daemon spawns you as a separate `omp --mode rpc` process (behind `legion worker-shim`,
@@ -25,8 +39,8 @@ completes the boot handshake for you at session start — it registers with the
25
39
  your role, and signals readiness. You never call `envoy_role_set` yourself.
26
40
 
27
41
  Your role token is not the issue key spelled out literally. The daemon encodes it as
28
- `legion-<project>-<KEY>-<role>`. For example, project `acme`, issue `LEGION-41`, role `architect`
29
- encodes to `legion-acme-LEGION-41-architect`. Never hand-format one for another role: your own role
42
+ `legion-<project>-<key>-<role>` with the issue key lower-cased. For example, project `acme`, issue
43
+ `LEGION-41`, role `architect` encodes to `legion-acme-legion-41-architect`. Never hand-format one for another role: your own role
30
44
  topic and the topic of the architect that owns your issue are stated at the end of your system
31
45
  prompt (a "Legion addressing" line the daemon appends: on a child issue that is the child's
32
46
  sub-architect when one is claimed, else the root's), a sibling role's topic is yours with the
@@ -145,22 +159,6 @@ Anything else, stop and send the owning architect the `jj -R "$LEGION_WORKSPACE"
145
159
  evidence; the architect decides, and an operator performs any operation-log restore with every
146
160
  other tree paused.
147
161
 
148
- **Filesystem and process safety:** Your pane runs as the operator's own user, so one mistaken
149
- path can destroy the machine every agent shares (on 2026-09-13 a probe script's leftover
150
- `rm -rf "$work" "$HOME"` deleted the operator's SSH and signing keys and stopped every worker).
151
- The extension refuses, before it runs, a `bash` command, `eval` code, or `hub` process start
152
- (yours or a `task` subagent's) that would delete, move, truncate, overwrite an existing file by
153
- redirection or `tee`, or `chmod -R`/`chown -R` anything outside `$LEGION_WORKSPACE` and any
154
- directory below `/tmp` except `/tmp` itself, a glob over it, and its tmux and ssh socket
155
- directories. It cannot tell which allowed `/tmp` directory belongs to your pane. It follows
156
- `$HOME`, `~`, variables, `cd`, and the scripts a command runs. A target with no proven path prefix
157
- is refused; an unknown trailing component under a prefix already proven inside your workspace or
158
- permitted `/tmp` remains allowed. `pkill` and `killall` are refused, and `kill` only reaches a
159
- process you started (a descendant of your Oh My Pi process): stop your own long-running processes
160
- through the hub tool. The refusal names the target and the rule; do not rewrite a script just to
161
- silence it. This is a mistake-guard rather than a sandbox. What it cannot read, a compiled program
162
- or code whose paths are only known at run time, is still yours to keep inside the workspace.
163
-
164
162
  ## Phase work
165
163
 
166
164
  Specifications written into Dispatch follow `skill://dispatch`'s [Writing a spec](../dispatch/SKILL.md#writing-a-spec).
@@ -169,6 +167,9 @@ Follow the repository's normal engineering workflow and the assigned issue's acc
169
167
  criteria. Your phase's own charter and the predecessor handoffs you read define the phase
170
168
  artifact and its completion evidence. Do not replace architect-owned decomposition, gate
171
169
  discipline, scheduling, or human communication with labels or a local status model.
170
+ An issue that renames a repository, package, or URL across the codebase also follows
171
+ `skill://legion-worker/references/systematic-rename.md`; one that deletes code, a command, or
172
+ documentation follows `skill://legion-worker/references/cleanup-deletion.md`.
172
173
 
173
174
  Commit attribution is automatic: the extension exports a `JJ_CONFIG` overlay when your
174
175
  session starts, so every jj commit you make carries an `Omp-Session: <this-session-id>`
@@ -189,10 +190,11 @@ check
189
190
  `jj -R "$LEGION_WORKSPACE" log -r 'main@origin..@' -T 'author.email() ++ " | " ++ committer.email() ++ " " ++ description.first_line() ++ "\n"'`
190
191
  shows your role's App in both columns **on every commit you made** — not on the whole list:
191
192
  earlier phases' commits are legitimately authored by their own role's App. Their *committer* is
192
- a different matter, and no longer noise to accept. Resolving a conflict rewrites nothing now —
193
- it is the forward merge above — so it changes no committer at all, and the one rewrite still
194
- open to you (*Rewriting pushed commits*, below) resets the committer only of commits on your own
195
- chain that descend from the commit you named, after its guard cleared. Another role's commit
193
+ a different matter, and no longer noise to accept. Resolving a conflict rewrites nothing — it is a
194
+ forward merge (`skill://legion-worker/references/conflicts-and-rewrites.md`) — so it changes no
195
+ committer at all, and the one rewrite still open to you (*Rewriting pushed commits*, in the same
196
+ reference) resets the committer only of commits on your own chain that descend from the commit
197
+ you named, after its guard cleared. Another role's commit
196
198
  carrying you as committer, which you did not rewrite that way, is evidence that something
197
199
  rewrote commits it should not have — the observable symptom of LEGION-118. Stop and send the
198
200
  architect that log; do not accept it as a side effect. A wrong identity on your own commit, the
@@ -277,325 +279,42 @@ branch name alone is ambiguous. The credential helper and `legion gh` provide th
277
279
  identity; never export, fetch, or replace a token. Other phases advance the existing branch
278
280
  rather than creating a replacement bookmark or PR.
279
281
 
280
- ## PR body and READY discipline
281
-
282
- The implementer writes the PR body in the READY format from the moment the PR opens, and every
283
- later phase keeps it current rather than replacing it:
284
-
285
- ```
286
- ## Verification
287
-
288
- **CI:** `Tests` run <run-id> — jobs lint, typecheck, test all success at <head-sha>; `PR Title` run <run-id> — job pr-title success at <head-sha>.
289
-
290
- **Threads:** <n> resolved, 0 unresolved. Each disposed individually, never in bulk:
291
- - Thread <id>: fixed in <commit-sha> — <one line>.
292
- - Thread <id>: not a defect — <reason>.
293
- `legion threads resolve --pr <n> --repo <owner>/<repo>` at <head-sha>:
294
- resolved <thread URL> — its opener's acceptance
295
- resolved <thread URL> — the Legion reviewer's acceptance of a bot's thread
296
- left open <thread URL> — newest reply by <login> is not an acceptance
297
- left open <thread URL> — newest reply by <login> is an unsubmitted draft in a pending review
298
- left open <thread URL> — newest reply by <login> is not its opener's or the Legion reviewer's acceptance
299
-
300
- **Thermo:** `ce-simplify-code` once at <head-sha>: <0 applied | applied → new head <sha>>; thermonuclear pair at the final head <sha>:
301
- <verdict>. (omitted entirely on a docs-only PR — there is no code for either pass, so neither runs)
302
-
303
- **E2E (implementer):** <surface> — ran `<command or run id>`, observed <result>, at head <sha>.
304
- Negative control: <deliberately broken input> → <refusal or failure observed>.
305
-
306
- **E2E (tester):** <surface> — ran `<command or run id>`, observed <result>, at head <sha>.
307
- Negative control: <deliberately broken input> → <refusal or failure observed>.
308
- Verified the implementer's proof by <re-running its command | driving the same surface independently>.
309
-
310
- **Production:** <what was checked in production, how, what was observed> — merge commit <sha>.
311
- (written by the implementer after the merge lands; `pending <what is missing>` until then)
312
-
313
- **Fast-follow:** <one named cleanup item and where it will land>, or "none".
314
-
315
- **Chain:** stacked on <base bookmark> frozen at <sha> / not stacked.
316
- **Retarget:** Retargeting a pull request to a new base does not re-run Tests; after a retarget, merge the bookmark onto the new base (`jj new legion/<KEY> <new base> -m "<message>"`) and push with `legion-worker`'s ordinary push procedure — a genuine fast-forward, never the procedure for rewritten commits — the new head runs Tests against the new merge result — and cite that run in the PR body.
317
- ```
318
-
319
- **A proof** is the changed behaviour exercised on the surface a user reaches it through, recorded
320
- as the exact command or run id, what was observed, the head SHA, and one negative control —
321
- a deliberately broken input and the refusal or failure observed. The surface is
322
- **production-like** — the repository's real-process test harness and fixtures, a sandbox
323
- repository, a real browser, a devN stack, staging, or a local stack with real migrations, one that
324
- has the resource the change touches — and each `E2E` line carries a **link** to that run,
325
- screenshot, or e2e; human review does not replace user-facing verification, and a green unit suite
326
- is not it. A unit or integration test is a regression lock, never proof of a criterion. Sami,
327
- 2026-09-13, verbatim: "They need to test everything in a production-like
328
- environment before merging, and it is the agent that develops the feature that is responsible
329
- for doing that. If there's anything blocking that, we need to fix it: if it's infrastructure, we
330
- need to fix it; if it's tooling, we need to develop it; if it's skills, we need to fix the skills
331
- ... it should not require deploying to production to realize your feature doesn't work."
332
- Evidence for the rule: in the week of 2026-09-08 three surfaces merged green and were wrong on
333
- inspection (the Astrolabe IPI stack, Dispatch on ECS, the candidate flow), and on 2026-09-12 six
334
- deploy slots died on code first executed after merge, including a production-only ECS bootstrap
335
- the whole staging gate never ran. The implementer's proof and the tester's proof below are both
336
- this proof.
337
-
338
- - **Threads are dispositioned individually, never resolved in bulk.** Every open review
339
- thread gets its own line naming the fixing commit or the reason it isn't a defect. The
340
- reviewer answers each thread it opened, and each thread a bot opened that is none of Legion's
341
- role Apps, with exactly one of `Accepted: fixed in <commit> — <one line>`,
342
- `Accepted: not a defect — <reason>`, or `Still open: <what remains>`; nothing else is an
343
- acceptance, and nobody replies after an `Accepted:` (any later reply that is not itself an
344
- `Accepted:` — the opener's own follow-up included — leaves the thread open, because resolution
345
- considers only the newest comment). The review App can reply on a thread but cannot resolve it:
346
- GitHub grants resolving a review thread to the pull request's author, and the implementer opens
347
- every Legion pull request (`packages/daemon/src/daemon/AGENTS.md`, GitHub Apps).
348
- When `LEGION_GRANT_FILE` or `LEGION_GRANT` is set, use `legion threads resolve --pr <number> --repo <owner>/<repo>`; when neither is set, use `gh api graphql`
349
- with the session's GitHub credential and the fallback below.
350
- In a Legion pane, the **implementer** runs the command before every push that answers a review
351
- (the corrective push and the final `.legion/` deletion push) and pastes its output into the
352
- `Threads` section. The command resolves each unresolved thread whose newest submitted comment is
353
- the opener's own `Accepted:` reply. On a thread a bot account opened that is none of Legion's
354
- role Apps (the daemon names them, keyed by App role), the Legion reviewer's `Accepted:` also
355
- closes it. GitHub cannot tell a CI bot, which never accepts, from a person whose `gh` is routed
356
- to an App, so the reviewer adjudicates such a finding, and it may accept one an App-routed person
357
- raised. The subject of a finding never closes it: the implementer's `Fixed in <commit>: …` or
358
- `Declined: …` answers a thread and closes none. A thread either Legion App opened, a reviewer's
359
- finding included, still needs its opener's `Accepted:`. It makes one `resolveReviewThread` per
360
- thread, prints `resolved <url> — <whose acceptance>` (its opener's, or the Legion reviewer's on a
361
- bot's thread, so the ledger shows which) or `left open <url> — newest reply by <login> is …`
362
- naming why, and exits 1 naming the thread's URL and GitHub's message when GitHub refuses one.
363
-
364
- Without a grant, page through `reviewThreads`, skip `isResolved: true`, and compare the opener
365
- with the newest comment. Query shape, inside `repository { pullRequest { … } }`:
366
-
367
- ```graphql
368
- reviewThreads(first: 100, after: $after) {
369
- pageInfo { hasNextPage endCursor }
370
- nodes {
371
- id isResolved
372
- opener: comments(first: 1) { nodes { author { __typename login } } }
373
- newest: comments(last: 1) { nodes { author { __typename login } body state } }
374
- }
375
- }
376
- ```
377
-
378
- Resolve only when the newest comment is submitted, its `author` is the opener's account (the same
379
- `__typename` and `login`: a login alone is a string anyone may register), and its `body`, after
380
- removing leading spaces, tabs, CR, and LF, begins `Accepted:`. Without a
381
- grant nothing names Legion's own App logins, so this route closes a bot's thread only on its
382
- opener's `Accepted:`: leave one the Legion reviewer accepted for the implementer's or merger's
383
- run in a pane, or report it. For each thread to resolve:
384
-
385
- ```graphql
386
- mutation($threadId: ID!) {
387
- resolveReviewThread(input: { threadId: $threadId }) { thread { isResolved } }
388
- }
389
- ```
390
-
391
- Re-read `reviewThreads` and confirm that thread's `isResolved` is true. In either route, report
392
- a refused resolution to the architect, which opens an ask for a human to resolve the thread by
393
- hand — never skip it silently. The merger runs the command once more before publishing READY
394
- and does not publish while any `left open` line remains.
395
- - **Correctness fixes land in this PR; cleanup is one named fast-follow.** A finding that
396
- changes behavior, hides an error, or breaks a gate is fixed here — never deferred.
397
- Findings about naming, duplication, or wording are batched into the single `Fast-follow`
398
- line instead of iterating per push.
399
- - **Reintegrate the base only on a real conflict, except after a base retarget — and with a
400
- merge, never `jj rebase`.** Sami, 2026-09-11, verbatim:
401
- "Please don't do unnecessary rebases (i.e. unless there are merge conflicts). The CI queue is too long and slow."
402
- The implementer merges the base into the issue branch only when GitHub reports it `CONFLICTING`, the controller asks
403
- because of a conflict, or after the pull request is retargeted to a new base. Otherwise, never reintegrate the base to
404
- pick up `main` or refresh CI. A single failed CI job is re-run on its own with `legion gh -- run rerun <run-id> --failed`, never by
405
- pushing a new commit. A conflict-forced rebase that leaves the branch's diff unchanged is a
406
- confirmation, not a new round (see *The unchanged-diff check* below); that name is the event's,
407
- kept by the rules below and the learnings that cite it, and the operation it names is always
408
- the merge here. Before merging, record
409
- the fingerprint at the current tip; after pushing the merged branch, record it at the new
410
- tip; post one PR comment (Legion footer):
411
- `rebase <old-tip-sha> → <new-tip-sha>; fingerprint <before> → <after>; unchanged|changed`.
412
- Every issue workspace is a `jj workspace` of the same shared repository and operation log, and
413
- jj always rebases every descendant of any commit it rewrites — a revset naming the root of your
414
- own chain and rewriting it in place also rewrites whatever another tree has stacked on that root,
415
- whichever selector chose it (`-s`, `-b`, and `-r` all rewrite descendants; `-r` only re-parents
416
- them to fill the hole, which is worse). This is what happened in LEGION-118: one issue's own
417
- conflict step moved a second issue's twelve commits and its bookmark onto a conflicted copy.
418
- Resolve the conflict with a forward merge instead of a rewrite — merge the branch's own
419
- bookmark with the destination in one new commit, so nothing existing is rewritten and nothing
420
- built on your prior commits, in this tree or another, ever moves:
421
-
422
- ```bash
423
- jj -R "$LEGION_WORKSPACE" new legion/<KEY> main@origin -m "merge: resolve conflict against main@origin"
424
- ```
425
-
426
- Merge from the bookmark, never from `@`: a handoff split leaves `@` an empty, undescribed
427
- commit above the described one the bookmark already names, and `jj git push` refuses to push
428
- any commit without a description — merging from `@` drags that undescribed commit into the
429
- ancestry and the push fails (`Won't push commit … since it has no description`); the bookmark
430
- is always on a described, already-pushed commit. If the merge conflicts, resolve it in that
431
- one commit — edit the markers directly; there is nothing to squash, since the merge is the
432
- only new commit. Then `jj -R "$LEGION_WORKSPACE" new` to move off it, and push with the one
433
- push procedure (*Every role pushes its own commits*, below): the merge descends from both the
434
- bookmark's old position and the destination, so it is a genuine fast-forward and *Rewriting
435
- pushed commits* never applies — nothing was rewritten, so there is no tip to record first.
436
- - **No deferrals.** Sami, 2026-09-11, verbatim: "My rule is no deferrals." The `Fast-follow:`
437
- field names naming, duplication, or wording cleanup only; anything that changes behaviour,
438
- hides an error, or breaks a gate lands in this PR.
439
- - **The implementer proves the change before its phase completes, and writes the `E2E (implementer)` line when the pull request opens.**
440
- The proof is the one defined above. It goes into `.legion/implement.json` as the required `proof`
441
- array (`handoff_write` for phase `implement` refuses a payload without one, or with a blank or
442
- whitespace-only field, and names the field), and into the PR body, because the reviewer and the
443
- merger verify facts on GitHub and never from a handoff.
444
- - **The tester verifies the implementer's proof and adds its own `E2E (tester)` line.** It re-runs
445
- the implementer's command or drives the same surface independently, and records the verdict in
446
- `.legion/test.json` as `implementerProof` (`{verdict, how}`).
447
- A test handoff whose predecessor carried no proof is a test failure, not a gap for the tester to fill:
448
- record it in `failures` with `implementerProof.verdict: "rejected"`, complete the phase, and let
449
- the architect return the issue to the implementer — the agent that developed the change owns
450
- proving it (`handoff_write` for phase `test` refuses a rejected verdict, or `failed > 0`,
451
- with no recorded failure). Otherwise, add your own proof before completing — a proof as defined
452
- above — as the `E2E (tester)` line and the `proof` array `handoff_write` for
453
- phase `test` requires whenever you report no failure. A code path whose first execution is after merge — a
454
- deploy workflow's inline step, a post-merge helper, a production-only resource — is untested
455
- until the implementer has executed it against a devN stack; if no surface can reach it, the
456
- tester names that missing surface as the blocker instead of passing the phase. Environment or
457
- secret-scrub evidence (e.g. "`LEGION_*`/`DISPATCH_*`/`ENVOY_*` unset") is recorded once, in
458
- `.legion/test.json`, and only when the issue's acceptance criteria call for it — never
459
- re-pasted into the PR body each round. After a conflict-forced rebase, compute the
460
- fingerprint at the head your `E2E` line names and at the new head. Equal: re-run only the
461
- bare gates — the repository's CI green at the new head and its smoke check — and change the
462
- `E2E` line's head to the new SHA with
463
- `rebase re-check <old-sha> → <new-sha>: fingerprint unchanged, bare gates only`; the
464
- real-surface verification is not repeated. Different: a full test round.
465
- - **The implementer runs `skill://ce-simplify-code` once per pull request, after the last review round
466
- closes and before the reviewer's final pass, when the diff touches runtime code; a docs-only
467
- diff gets none.** It is scoped to the pull request's own diff, at the head where the last review
468
- round closed: nothing applied leaves that head final; applied → the applied head is the final
469
- head: CI runs on it, the pair runs once on it, and the E2E proof re-runs on it for the surface
470
- the simplify diff touched (Sami, 2026-09-13: test on the real surface before merging, no
471
- shortcuts — a refactor that "preserves behaviour" is a claim until it is executed). That cost is
472
- why 0-applied is the expected outcome and a pass that applies is spent sparingly. At the applied
473
- head the implementer re-cites the `CI` line and re-runs its own proof into `E2E (implementer)`,
474
- and the tester re-runs its proof for the touched surface into `E2E (tester)`, before the
475
- reviewer's final pass. Simplify is the last code change; the pair is the last review. Record it
476
- in the `Thermo` line.
477
- - The reviewer verifies the `CI`, `Threads`, and `E2E` facts against GitHub directly —
478
- never from a handoff — then runs `task(agent="thermonuclear-deep-review")` and
479
- `task(agent="thermonuclear-code-quality")` once at that head — the head the implementer's
480
- simplify pass left final — and records the verdict.
481
- Approval is refused while either `E2E (implementer)` or `E2E (tester)` is missing: `REQUEST_CHANGES` naming the missing line.
482
- Skip the `Thermo` line entirely on a docs-only PR. Submit **one review per round** —
483
- `REQUEST_CHANGES` when any correctness finding stands, otherwise `COMMENT` while the head
484
- still carries `.legion/`; `APPROVE` only for a head that carries no `.legion/` — the head
485
- that differs from the reviewed one by the `.legion/` deletion alone, or, after a
486
- conflict-forced rebase, the new head whose fingerprint equals the approved head's — always
487
- named by SHA — carrying every inline comment in that single
488
- call: `legion gh -- api --method POST repos/{owner}/{repo}/pulls/{number}/reviews --input body.json`
489
- with `commit_id`, `event` (`REQUEST_CHANGES`, `COMMENT`, or `APPROVE`), `body` (with the
490
- Legion footer), and a `comments[]` array of `{path, line, side, body}`, one entry per
491
- finding — never one `pr review` call per finding (each submission fires a `pr-review` wake).
492
- Then return the issue to the architect; when clean, have the architect send the implementer
493
- back to push the `.legion/` deletion, then review **that** head and approve it by name. After a conflict-forced rebase, compute the fingerprint at the
494
- `commit_id` of your last submitted review and at the new head. Equal and that review was
495
- `APPROVE`: submit one more `APPROVE` naming the new head by SHA, its body naming both SHAs
496
- and the fingerprint — a confirmation, not a round; no thermo pass, no thread pass. Equal and
497
- that review was `COMMENT` or `REQUEST_CHANGES`: continue that round against the new head;
498
- nothing restarts. Different: a new round — thermo again, one review.
499
- When you re-review after a corrective push, answer every thread you opened in one of the
500
- three forms above — `Accepted:` is the only reply the implementer's `legion threads resolve`
501
- acts on — and approve only once every thread you opened carries your `Accepted:` reply and the
502
- implementer's run has resolved it (verify `isResolved: true` with `gh api graphql`, never from
503
- the PR body).
504
- - Once a base is frozen for others to stack on, never rewrite it — fixes land as new
505
- commits on top, and the `Chain` line records what is frozen.
506
- - **Retro's commit does not void the reviewer's approval.** After the reviewer approves the
507
- cleaned head, retro commits its learnings under `docs/solutions/` on top of it; that commit
508
- stays, the approval stands, and the tree goes to the merger — never back to the tester or
509
- reviewer. Anything else above the approved head does void it, and the merger tells the
510
- architect the head must return to review instead of publishing. A conflict-forced rebase
511
- after retro moves those documents with the branch; retro never re-runs.
512
- - The merger runs `legion threads resolve --pr <n> --repo <owner>/<repo>` (it acts as the same
513
- code-writing App as the implementer; resolving a thread changes no commit, so this run never
514
- invalidates the approval), does not publish while any `left open` line remains or the command
515
- exits 1 (report the thread to the architect instead), then proves that rule with two commands.
516
- First `cd -- "$LEGION_WORKSPACE" && jj -R "$LEGION_WORKSPACE" git fetch && jj -R
517
- "$LEGION_WORKSPACE" diff --from <approved-sha> --to <tip-sha> --summary`, whose output is quoted
518
- in READY (an empty output is quoted as `no file changes above the approved head`); then the same
519
- with `'~docs/solutions'` appended, which must print nothing. The merger always posts
520
- `READY #<n> at <current sha> (approved at <approved sha>) for <KEY> (<pr url>)` (the shape
521
- `packages/pi-envoy/roles/merger.md` defines), its summary, and the PR body's gate facts as a
522
- `dispatch_message` on the issue. When the `Legion addressing` line names a merge queue, it also
523
- publishes the same packet there with `envoy_publish`; a 404 means the Dispatch message remains
524
- the durable notice and the merger stays idle. The READY packet names both the implementer's and
525
- tester's `E2E` lines; a missing one is reported to the architect instead of published. Legion
526
- never merges.
527
- - **After a human merges, the implementer verifies in production.** Sami, 2026-09-13,
528
- verbatim: "the agent that developed it should be responsible for testing in production."
529
- The architect sends the implementer back once the merge lands; the implementer watches the
530
- deploy slot that carries the merge to `production-apply` (or the equivalent publish step),
531
- drives the changed path in production through the user's own access path, and records the
532
- observation on the PR and the issue before the architect signs off. A staging pass is not
533
- this: on 2026-09-12 a slot's entire staging gate passed at 00:02Z and its production-apply
534
- failed at 00:12Z on a resource staging never runs. If the slot fails on the change, the
535
- implementer owns the fix and the next slot.
536
- The record has three places: the PR body's `Production:` line, one pull-request comment
537
- carrying the Legion footer, and a `dispatch_message` on the issue — the reviewer and merger
538
- read GitHub, the architect reads the issue. When the deploy that carries the merge has not
539
- happened (a shared profile still holding the previous plugin release, a daemon still running
540
- the previous commit, a slot nobody has run), open a `dispatch_ask` naming the exact install or
541
- restart step, with options for its outcomes, keep the `Production:` line at `pending <what is
542
- missing>`, and complete the check once the human answers that it is done. Never record a
543
- staging pass as the production check, and never let the architect sign off on a `pending` line.
544
-
545
- ## When no surface reaches the changed path
546
-
547
- No surface reaches the changed path is a report to the architect, never a reason to complete the phase.
548
- Say which surface is missing and what it would have to do — a rig that can spawn the role, a
549
- sandbox that holds the resource, a credential, a command that does not exist yet — and send it to
550
- the architect with `envoy_publish` to its role topic. The architect creates a child issue in this
551
- tree to build it (infrastructure, tooling, or a skill) and resumes you once it lands. Sami,
552
- 2026-09-13, verbatim: "If there's anything blocking that, we need to fix it: if it's
553
- infrastructure, we need to fix it; if it's tooling, we need to develop it; if it's skills, we need
554
- to fix the skills." A code path whose first execution would be after the merge — a deploy
555
- workflow's inline step, a post-merge helper, a production-only resource — is untested until you
556
- have executed it somewhere production-like; completing with a unit-test-only handoff is the
557
- failure this rule exists to stop.
558
-
559
- ## The unchanged-diff check
560
-
561
- The fingerprint every role compares after a conflict-forced rebase (every flag and the fileset
562
- verified on jj 0.45.1):
563
-
564
- ```bash
565
- cd -- "$LEGION_WORKSPACE" && jj -R "$LEGION_WORKSPACE" git fetch && \
566
- jj -R "$LEGION_WORKSPACE" diff --from "fork_point(main@origin | <head-sha>)" --to <head-sha> \
567
- --git --context 0 '~(.legion | docs/solutions)' \
568
- | sed -e '/^@@/d' -e '/^index /d' | sha256sum
569
- ```
570
-
571
- - `<head-sha>` is a full commit SHA; a jj commit id is the git SHA GitHub shows.
572
- - `fork_point(main@origin | <head-sha>)` is the base the branch was cut from *at that head*:
573
- the old base for the pre-rebase head, the new base for the rebased one, so one command
574
- serves both sides. On a stacked PR substitute its base branch for `main`
575
- (`legion gh -- pr view <n> --json baseRefName`).
576
- - A head the rebase hid is still addressable by its SHA in the shared workspace. A SHA the
577
- workspace cannot resolve (`jj -R "$LEGION_WORKSPACE" log -r <sha>` errors) counts as a
578
- changed diff — never as unchanged.
579
- - `--context 0` drops context lines; the `sed` drops `@@` hunk headers (line positions move
580
- on a rebase) and `index` lines (blob ids move when the base's copy of a file changed). What
581
- is left is exactly the added and removed lines per file.
582
- - The single fileset `'~(.legion | docs/solutions)'` leaves out the handoff ledger and retro's
583
- learnings: process artifacts the rules above already exempt from re-review, which change
584
- between one role's verified head and the next without changing the product. This is what lets
585
- each role compare against *its own* last verified head instead of trusting another role's
586
- numbers. It must be one expression: jj unions positional filesets, so two separate
587
- `'~.legion' '~docs/solutions'` arguments select every file and exclude nothing. Once
588
- `.legion/` is gone, jj warns `No matching entries for paths: .legion` on stderr; the hash is
589
- unaffected.
590
-
591
- Where each role gets its two heads: the implementer — the tip before and after its own rebase;
592
- the tester — the head its `E2E` line names and the new head; the reviewer — the `commit_id` of
593
- its last submitted review (`legion gh -- api repos/{owner}/{repo}/pulls/{n}/reviews --jq '.[] | {commit_id, state, user: .user.login}'`)
594
- and the new head; the merger never computes a fingerprint — it uses the `--summary` check
595
- above.
282
+ ## PR body, review, and the merge gate
283
+
284
+ The implementer writes the pull request body in the READY format when it opens the pull request,
285
+ and every later phase edits its own lines of the live body rather than replacing it. Each proof
286
+ (the implementer's `E2E (implementer)` line and `proof` array, the tester's `E2E (tester)` line
287
+ and `proof` array) is the changed behaviour exercised on a production-like surface, recorded as
288
+ its command or run id, what was observed, the head SHA, and one negative control; a unit test is
289
+ never one. **Before you write or edit any line of the PR body or any `proof` array, read
290
+ `skill://legion-worker/references/pr-body.md`**: the template (the sole definition of the CI
291
+ line), the full definition of a proof, what the tester verifies, and the simplify pass.
292
+
293
+ - **Review threads** are disposed of one by one, never in bulk, and only an `Accepted:` from the
294
+ thread's opener (or, on a bot's thread, from the Legion reviewer) closes one. The implementer
295
+ runs `legion threads resolve` before every push that answers a review, and the merger before
296
+ READY: `skill://legion-worker/references/review-threads.md`.
297
+ - **No deferrals.** Sami, 2026-09-11, verbatim: "My rule is no deferrals." A finding that changes
298
+ behaviour, hides an error, or breaks a gate is fixed in this pull request; naming, duplication,
299
+ or wording cleanup is batched into the one `Fast-follow:` line instead of iterating per push.
300
+ - **A red CI job** that failed on its own is re-run with
301
+ `legion gh -- run rerun <run-id> --failed`, never by pushing a new commit or bringing in the base.
302
+ - **A conflict or a retarget** is the only reason to bring the base into the branch, always as a
303
+ forward merge and never `jj rebase`; the unchanged-diff fingerprint each role compares
304
+ afterwards is in the same reference: `skill://legion-worker/references/conflicts-and-rewrites.md`.
305
+ - **The merge gate**, in order: the tester's evidence green → the implementer's `.legion/`
306
+ deletion push → the reviewer's approval of that head → retro → the merger's READY → the human
307
+ merge → the implementer's production check. Legion never merges. The reviewer's submissions,
308
+ retro's commit, the merger's READY, and the production check follow
309
+ `skill://legion-worker/references/merge-gate.md`.
310
+ - **No surface reaches the changed path** is a report to the architect, never a reason to
311
+ complete the phase: `skill://legion-worker/references/pr-body.md`.
596
312
 
597
313
  ## Completion gate: handoff write, verification, and persistence
598
314
 
315
+ The merger writes no handoff and pushes nothing, so this gate does not apply to it
316
+ (`packages/pi-envoy/roles/merger.md`).
317
+
599
318
  Write the phase-specific handoff: call the `legion` tool with `op: "handoff_write"`, `phase: "<p>"`,
600
319
  and `data`: a JSON object of the phase-specific fields only. It runs `legion handoff write` in
601
320
  `$LEGION_WORKSPACE` and returns its output.
@@ -628,12 +347,31 @@ cd -- "$LEGION_WORKSPACE" && \
628
347
  **Every role pushes its own commits.** After the handoff commit — and, for the tester, the red
629
348
  tests it wrote — advance the issue bookmark and push it with the provisioned credential helper,
630
349
  which authenticates as your role's App (`appRoleForLegionRole` in
631
- `packages/daemon/src/daemon/github-apps.ts`). `-r @-` puts the bookmark on the commit you just
350
+ `packages/daemon/src/daemon/github-apps.ts`).
351
+
352
+ **Under the Go daemon, every push is `legion push`,** run from bash in your workspace in place of
353
+ the commands below. It runs this same procedure on `@-`: the ancestry check, against the remote
354
+ branch or the tip you recorded before rewriting pushed commits (below), then the bookmark and the
355
+ push. It also decides whether the push skips CI. A push skips CI only when none of its commits
356
+ touches anything but handoffs whose phase guarantees a later push: the planner's
357
+ `.legion/plan.json`, the tester's `.legion/test.json`, and a reviewer's `.legion/review.json` whose
358
+ `verdict` is `"changes_requested"`. Its head then ends with GitHub's `skip-checks: true` trailer,
359
+ and the Go daemon carries the code head's verdict to it. Every other push runs CI in full. Never
360
+ add or remove that trailer yourself, never write one of GitHub's bracket keywords (`[skip ci]`,
361
+ `[ci skip]`, `[no ci]`, `[skip actions]`, `[actions skip]`) into a commit message, and never push
362
+ the issue branch with the commands below under the Go daemon: a hand-run push of a handoff that
363
+ could skip CI runs it in full, and a hand-added trailer or keyword on any other push skips CI on a
364
+ head a human may merge. `legion push` refuses a head whose message carries a keyword and pushes
365
+ nothing until you take it out. Under the TypeScript daemon, whose `legion` has no `push` command,
366
+ run the commands below yourself.
367
+
368
+ `-r @-` puts the bookmark on the commit you just
632
369
  split off: the working copy left above it has no description, and `jj git push` refuses a
633
370
  commit without one. `--allow-backwards` is for that local step alone: after a split the bookmark
634
371
  can sit on the undescribed working copy above `@-`. `--bookmark` also publishes the locally
635
372
  provisioned bookmark on its first push — a bookmark not yet tracking a remote one is tracked
636
- automatically. This is the one push procedure; every push of the issue branch uses it:
373
+ automatically. This is the one push procedure, run as `legion push` under the Go daemon and by
374
+ hand under the TypeScript daemon; every push of the issue branch uses it:
637
375
 
638
376
  ```bash
639
377
  cd -- "$LEGION_WORKSPACE" && \
@@ -654,38 +392,11 @@ remote branch sideways onto your commit and drops theirs (jj 0.45.1:
654
392
  `bookmark: legion/K [move sideways from <theirs> to <yours>]`). A clone that has not seen the other
655
393
  push is refused by jj itself (`unexpectedly moved on the remote`).
656
394
 
657
- **Rewriting pushed commits** — a `jj squash --into` a commit already on GitHub, or any other
658
- rewrite of a commit you already pushed — is the LEGION-118 hazard in a second shape: jj rebases
659
- every descendant of any commit it rewrites, and in the one shared repository a descendant can be
660
- another tree's branch stacked on your pushed commit, which then moves, with its bookmark, onto a
661
- rewritten copy. So look for a descendant outside your own chain first, and record the pushed tip
662
- — which the rewrite leaves outside `::@-` — after a fetch and while your chain still descends
663
- from it:
664
-
665
- ```bash
666
- cd -- "$LEGION_WORKSPACE" && \
667
- jj -R "$LEGION_WORKSPACE" git fetch && \
668
- foreign=$(jj -R "$LEGION_WORKSPACE" log --no-graph -T 'commit_id.short() ++ "\n"' \
669
- -r 'descendants(<the commit you are about to rewrite>) ~ ::@') && \
670
- { [ -z "$foreign" ] || { echo "not mine, and descends from the commit to rewrite: $foreign" >&2; false; }; } && \
671
- behind=$(jj -R "$LEGION_WORKSPACE" log --no-graph -T 'commit_id.short() ++ "\n"' \
672
- -r 'remote_bookmarks(exact:"legion/<KEY>", exact:"origin") ~ ::@-') && \
673
- { [ -z "$behind" ] || { echo "legion/<KEY>@origin is at $behind, which @- does not descend from" >&2; false; }; } && \
674
- jj -R "$LEGION_WORKSPACE" log --no-graph -T 'commit_id' \
675
- -r 'remote_bookmarks(exact:"legion/<KEY>", exact:"origin")' \
676
- >"${TMPDIR:-/tmp}/legion-<KEY>-$LEGION_ROLE-rewritten-tip"
677
- ```
678
-
679
- `descendants(<commit>) ~ ::@` is everything built on the commit you are about to rewrite that is
680
- not on your own chain. Non-empty means the rewrite would move work that is not yours: do not
681
- rewrite it. Put the change in a new commit on top instead, and report the listed commits to the
682
- architect. On a two-workspace rig of this shape a `jj squash --into` a pushed commit reported
683
- `Rebased 13 descendant commits` and moved a second issue's twelve commits and its bookmark; the
684
- check above listed those thirteen and refused before anything moved.
685
-
686
- Then rewrite, resolve, and push with the procedure above. It lets the remote branch sit on the
687
- tip you recorded, which the rewrite replaced, and on nothing else: when another role pushed after
688
- you recorded it, the push is refused. The push deletes the file.
395
+ Before any rewrite of a commit you already pushed — a `jj squash --into` one, or any other
396
+ rewrite — read *Rewriting pushed commits* in
397
+ `skill://legion-worker/references/conflicts-and-rewrites.md`: it checks that no other tree's work
398
+ is built on that commit and records the pushed tip `$tip_file` above reads, the only case in which
399
+ the push above lets the remote branch move off its current tip.
689
400
 
690
401
  Before the push, check ancestry and identity as above: the chain carries every earlier phase's
691
402
  commits, and pushing them with yours is expected. A refusal, and a push the remote rejects, is a
@@ -713,17 +424,9 @@ This publishes your phase's completion to the architect's role and clears the da
713
424
  record of this issue's active phase. Do not add pipeline labels, run a controller loop, or
714
425
  invent a different completion protocol — this is the whole contract.
715
426
 
716
- A reviewer's phase ends with its completion, not with its review. A round that writes a handoff
717
- takes this order: write, commit and push the handoff; submit the review of the head that push
718
- made, by its SHA; then complete. An approval waits for the CI verdict to settle green at that head
719
- before you submit it, since an approval stands only on green checks and GitHub can dismiss one
720
- once the head moves, and a verdict that settles red there makes the round's decision a request for
721
- changes naming the failing checks; a request for changes does not wait, since it stands whatever CI says and the
722
- issue leaves reviewing with it. A review of a head the handoff push then replaces names a head
723
- the pull request no longer has. A round that writes none (the final approval of the `.legion/`
724
- deletion head) reviews the head as it is. The daemon moves the issue once both are in —
725
- the decision GitHub reports and your completion, in either order — so a review posted without a
726
- completion leaves the issue in reviewing until you finish.
427
+ A reviewer's phase ends with its completion, not with its review; the order of a review round
428
+ (the handoff push; for an approval, CI settled green at that head; the review of that head; then
429
+ the completion) is in `skill://legion-worker/references/merge-gate.md`.
727
430
 
728
431
  **A refused completion is information, not a retry loop.** The daemon attributes your report to
729
432
  the run whose task you took, and answers with what it found. What each answer carries, and what to