@hexagen-monaco/sync 0.12.1 → 0.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.
Files changed (107) hide show
  1. package/README.md +729 -0
  2. package/dist/cli.js +7635 -516
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/arch/edit.d.ts.map +1 -1
  5. package/dist/commands/contract/evaluate.d.ts +99 -0
  6. package/dist/commands/contract/evaluate.d.ts.map +1 -0
  7. package/dist/commands/contract/growth.d.ts +22 -0
  8. package/dist/commands/contract/growth.d.ts.map +1 -0
  9. package/dist/commands/contract/index.d.ts +32 -0
  10. package/dist/commands/contract/index.d.ts.map +1 -0
  11. package/dist/commands/evidence/check.d.ts +33 -0
  12. package/dist/commands/evidence/check.d.ts.map +1 -0
  13. package/dist/commands/evidence/index.d.ts +3 -0
  14. package/dist/commands/evidence/index.d.ts.map +1 -0
  15. package/dist/commands/evidence/pack.d.ts +41 -0
  16. package/dist/commands/evidence/pack.d.ts.map +1 -0
  17. package/dist/commands/evidence/verify.d.ts +83 -0
  18. package/dist/commands/evidence/verify.d.ts.map +1 -0
  19. package/dist/commands/grant/build.d.ts +53 -0
  20. package/dist/commands/grant/build.d.ts.map +1 -0
  21. package/dist/commands/grant/canonical.d.ts +27 -0
  22. package/dist/commands/grant/canonical.d.ts.map +1 -0
  23. package/dist/commands/grant/check.d.ts +26 -0
  24. package/dist/commands/grant/check.d.ts.map +1 -0
  25. package/dist/commands/grant/duration.d.ts +8 -0
  26. package/dist/commands/grant/duration.d.ts.map +1 -0
  27. package/dist/commands/grant/index.d.ts +2 -0
  28. package/dist/commands/grant/index.d.ts.map +1 -0
  29. package/dist/commands/grant/issue.d.ts +23 -0
  30. package/dist/commands/grant/issue.d.ts.map +1 -0
  31. package/dist/commands/grant/key-init.d.ts +16 -0
  32. package/dist/commands/grant/key-init.d.ts.map +1 -0
  33. package/dist/commands/grant/list.d.ts +72 -0
  34. package/dist/commands/grant/list.d.ts.map +1 -0
  35. package/dist/commands/grant/revoke.d.ts +35 -0
  36. package/dist/commands/grant/revoke.d.ts.map +1 -0
  37. package/dist/commands/grant/show.d.ts +18 -0
  38. package/dist/commands/grant/show.d.ts.map +1 -0
  39. package/dist/commands/grant/sign.d.ts +3 -0
  40. package/dist/commands/grant/sign.d.ts.map +1 -0
  41. package/dist/commands/grant/signing-key.d.ts +22 -0
  42. package/dist/commands/grant/signing-key.d.ts.map +1 -0
  43. package/dist/commands/grant/verify.d.ts +51 -0
  44. package/dist/commands/grant/verify.d.ts.map +1 -0
  45. package/dist/commands/grant/workspace.d.ts +11 -0
  46. package/dist/commands/grant/workspace.d.ts.map +1 -0
  47. package/dist/commands/observe/imports/jsonc.d.ts +6 -0
  48. package/dist/commands/observe/imports/jsonc.d.ts.map +1 -0
  49. package/dist/commands/observe/imports/pass.d.ts +45 -0
  50. package/dist/commands/observe/imports/pass.d.ts.map +1 -0
  51. package/dist/commands/observe/imports/resolve.d.ts +44 -0
  52. package/dist/commands/observe/imports/resolve.d.ts.map +1 -0
  53. package/dist/commands/observe/imports/safe-read.d.ts +30 -0
  54. package/dist/commands/observe/imports/safe-read.d.ts.map +1 -0
  55. package/dist/commands/observe/imports/scan.d.ts +59 -0
  56. package/dist/commands/observe/imports/scan.d.ts.map +1 -0
  57. package/dist/commands/observe/index.d.ts +59 -0
  58. package/dist/commands/observe/index.d.ts.map +1 -0
  59. package/dist/commands/observe/same-path.d.ts +9 -0
  60. package/dist/commands/observe/same-path.d.ts.map +1 -0
  61. package/dist/commands/observe/walk.d.ts +29 -0
  62. package/dist/commands/observe/walk.d.ts.map +1 -0
  63. package/dist/commands/report/exec-git.d.ts.map +1 -1
  64. package/dist/commands/shared/brownfield-sidecar.d.ts +98 -0
  65. package/dist/commands/shared/brownfield-sidecar.d.ts.map +1 -0
  66. package/dist/commands/shared/git-exclude.d.ts +36 -0
  67. package/dist/commands/shared/git-exclude.d.ts.map +1 -0
  68. package/dist/commands/shared/glob.d.ts +29 -0
  69. package/dist/commands/shared/glob.d.ts.map +1 -0
  70. package/dist/commands/shared/grant-enumerator.d.ts +32 -0
  71. package/dist/commands/shared/grant-enumerator.d.ts.map +1 -0
  72. package/dist/commands/shared/ignore.d.ts +32 -0
  73. package/dist/commands/shared/ignore.d.ts.map +1 -0
  74. package/dist/commands/shared/sidecar-out.d.ts +6 -0
  75. package/dist/commands/shared/sidecar-out.d.ts.map +1 -0
  76. package/dist/commands/shared/sidecar-write.d.ts +2 -0
  77. package/dist/commands/shared/sidecar-write.d.ts.map +1 -0
  78. package/dist/commands/slice/index.d.ts +23 -0
  79. package/dist/commands/slice/index.d.ts.map +1 -0
  80. package/dist/commands/workbook/allow-list.d.ts +27 -0
  81. package/dist/commands/workbook/allow-list.d.ts.map +1 -0
  82. package/dist/commands/workbook/export.d.ts +41 -0
  83. package/dist/commands/workbook/export.d.ts.map +1 -0
  84. package/dist/commands/workbook/index.d.ts +3 -0
  85. package/dist/commands/workbook/index.d.ts.map +1 -0
  86. package/dist/commands/workbook/zip-read.d.ts +7 -0
  87. package/dist/commands/workbook/zip-read.d.ts.map +1 -0
  88. package/dist/fs-utils.d.ts.map +1 -1
  89. package/dist/generators/root-file-templates.d.ts +5 -4
  90. package/dist/generators/root-file-templates.d.ts.map +1 -1
  91. package/dist/generators/root-files.d.ts.map +1 -1
  92. package/dist/index.js +367 -37
  93. package/dist/index.js.map +1 -1
  94. package/dist/templates/agents-md/findings/0001-session-log-grows-unbounded.md +35 -0
  95. package/dist/templates/ci-github-actions/findings/0001-ci-runners-have-no-zsh.md +34 -0
  96. package/dist/templates/orchestration/README.md +88 -0
  97. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/SKILL.md +511 -0
  98. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/references/briefs.md +178 -0
  99. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/references/rationale.md +520 -0
  100. package/dist/templates/orchestration/files/.agents/skills/orchestrate-wave/scripts/wave-event.sh +17 -0
  101. package/dist/templates/orchestration/files/.github/workflows/gate.yml +66 -0
  102. package/dist/templates/orchestration/findings/0001-relative-runbook-links-escape-the-skill.md +48 -0
  103. package/dist/templates/orchestration/findings/0002-interpolation-hazard-in-graphql-line.md +46 -0
  104. package/dist/templates/orchestration/manifest.json +41 -0
  105. package/dist/types/manifest/monorepo.d.ts +5 -0
  106. package/dist/types/manifest/monorepo.d.ts.map +1 -1
  107. package/package.json +1 -1
@@ -0,0 +1,511 @@
1
+ ---
2
+ name: Orchestrate a delegated wave
3
+ description: >
4
+ Run one wave of the delegated implementation pipeline for this repo: intake and confirm the
5
+ cast, cut a worktree and branch per lane, dispatch lane briefs to the implementer seat, review
6
+ every PR with two independent models, remediate, sweep the review threads, and merge
7
+ sequentially. Use for "run wave N of the plan", "dispatch the lanes", "orchestrate the
8
+ implementation", "delegate this plan to the agents". Explicit invocation only — it creates
9
+ worktrees, spawns subagents, and opens pull requests.
10
+ disable-model-invocation: true
11
+ argument-hint: "[plan-path] [wave]"
12
+ arguments: [plan, wave]
13
+ ---
14
+
15
+ # Orchestrate one delegated wave
16
+
17
+ You are the **ORCHESTRATOR**. Plan: `$plan`. Wave: `$wave`. If either is empty, ask once, then
18
+ proceed — do not guess a plan file.
19
+
20
+ The full runbook is the delegated-implementation-pipeline document (stage detail, prompt
21
+ templates A–D, invariants, failure playbook) and the orchestrator-kickoff-prompt document. **Read the plan before acting, and, where the project
22
+ ships them, both runbooks** (`docs/workflows/delegated-implementation-pipeline.md` and
23
+ `docs/workflows/orchestrator-kickoff-prompt.md`). This file is the operating contract either way,
24
+ and wins where they differ; it deliberately does not copy them, so they
25
+ cannot drift apart. **Prompt templates A–E ship with this skill**, in
26
+ `references/briefs.md`, so the five briefs this file orders by name never depend on a runbook the
27
+ project may not have.
28
+
29
+ - The cast, and each seat's track record: the overlay's `cast.md`, at `.agents/orchestration/cast.md`
30
+
31
+ - **The overlay's `cast.md` is the authority on current seats; this file does not restate
32
+ them.** Record the worktree tip first and watch the provider's quota. Reviewers stay in-house: a
33
+ second `Agent` that is not the implementer. There is no lane launcher — launch every lane
34
+ yourself and emit its event in the call immediately before. (why: [rationale](references/rationale.md#cast-authority-and-the-retired-launcher))
35
+
36
+ ## Read the overlay right after this contract
37
+
38
+ Everything above is the same for every project. Everything project-specific lives in the
39
+ consumer-owned overlay at `.agents/orchestration/`, which hexagen never emits and never
40
+ overwrites. **Read `.agents/orchestration/config.yaml` right after this contract.** If it is
41
+ absent, or a field of it is absent, these are the defaults and you state them inline:
42
+
43
+ - `planDir: docs/planning` — where the plans live.
44
+ - `gateSteps` — the ordered list the gate reads. With no config, the steps named in the brief
45
+ are the list.
46
+ - `requiredCheck: ^Build` — the CI check whose conclusion a merge waits for.
47
+ - `ciWorkflow: .github/workflows/ci.yml` — the CI workflow `doctor` requires to exist, as a repository-relative path.
48
+ - `appendOnlyPaths` — empty. Nothing is append-only until the project says which paths are.
49
+ - `forbiddenPorts` — **no forbidden ports.** The absent default is an empty list. A scaffolded
50
+ config may name ports; an absent field names none.
51
+ - `operatorDataPaths` — empty. With none declared, the project stages nothing it was not told to.
52
+ - `laneHosts` and `seats` — both `[]`, unset. `laneHosts` says where and how a delegated lane runs
53
+ (its transport prefix, its gate scope, and for a remote host the checks and paths to reach it);
54
+ `seats` says who runs it (an agent and a model, each naming a host). Both are declared in
55
+ `.agents/orchestration/config.yaml`. With none declared, ask the owner which host and seat; never
56
+ start a server.
57
+ - `installProbes` — `[]`, no probes. Each is `{package, check, repair?}`; stage 1 says when the orchestrator runs them.
58
+ - `waveLogDir` — `$HOME/.waves-<name>`, where `<name>` is the name half of `repo`. Never a
59
+ bare shared wave-log root: another project's status server scans one, and a wave logged there
60
+ reports against the wrong repository.
61
+ - `waveStatusPort` — `4318`.
62
+ - `coverageRequirement` — whatever the project's own test command already enforces.
63
+ - `mutate: false` — the mutation-family steps stay out of the resolved list until a project
64
+ turns them on.
65
+ - `tokensCssPath` — unset; the server falls back to its own neutral token set.
66
+ - `overrides: []`
67
+ - `repo` — required. If it is absent from the config, ask for it; never guess a repository.
68
+ - `invariants` — `statusSource: derived`, `eventDuty: true`, `mergeRequiresGreenGate: true`,
69
+ `attribution: false`.
70
+
71
+ Those four **invariants** are the core ones, locked to exactly those defaults: status is
72
+ **derived** from the branch rather than asserted from a progress report; the **emit-an-event
73
+ duty**, so no lane is ever launched without its event already written; **never merging a red
74
+ gate**; and **no attribution** in commits and PRs.
75
+
76
+ **An `overrides:` entry is surfaced before the first lane dispatches.**
77
+ `hexagen-orchestration-doctor` runs at the start of every wave and prints every entry it finds.
78
+ A lane never discovers a weakened invariant by reading the config for itself, and an entry is
79
+ never buried in a log the orchestrator skims.
80
+
81
+ **The overlay may ADD rules, may TIGHTEN rules, and may not silently WEAKEN a core invariant.**
82
+ Weakening one of the four requires an `overrides:` entry naming that invariant with a reason.
83
+ Everything else the overlay holds — `house-rules.md`, `cast.md`, `lessons.md`,
84
+ `rationale.local.md` — is the project's own, this file never restates it, and hexagen's upgrade
85
+ path never touches it.
86
+
87
+ ## Naming waves and lanes
88
+
89
+ An identifier carries **both** the plan's id and what the lane does — `<plan-id>-<what-it-does>`
90
+ for a lane, `<plan-slug>-w<NN>` for a wave, zero-padded. (why: [rationale](references/rationale.md#the-identifier-grammar-and-why-both-halves-are-used))
91
+
92
+ Zero-pad the wave number: identifiers sort lexicographically, so `w10` lands before `w2`.
93
+
94
+ **Never use a bare/unqualified id, and never name a wave without the plan slug.** (why: [rationale](references/rationale.md#never-a-bare-id-or-a-wave-with-no-plan-slug))
95
+
96
+ ## Two preconditions that cost the most when skipped
97
+
98
+ **Run mutations through `hexagen-orchestration-mutate`, not by hand.** (why: [rationale](references/rationale.md#run-mutations-through-the-mutation-bin-not-by-hand))
99
+
100
+ ```sh
101
+ hexagen-orchestration-mutate --file <path> --before <before.txt> --after <after.txt> \
102
+ --because "<the input whose behaviour this changes>" -- <test command…>
103
+ ```
104
+
105
+ **Two exit codes are in play; do not confuse them** — **`0` caught, `1` survived, `2` refused**. (why: [rationale](references/rationale.md#two-exit-codes-are-in-play-do-not-confuse-them))
106
+
107
+ **`--because` is required on purpose**: state the prediction before seeing the result. (why: [rationale](references/rationale.md#the---because-flag-and-equivalent-mutants))
108
+
109
+ **If you mutate by hand anyway, the rest of this section is the checklist you are now keeping
110
+ yourself.**
111
+
112
+ **A mutation is read from the file, never written from memory.** (why: [rationale](references/rationale.md#a-mutation-is-read-from-the-file-never-written-from-memory))
113
+
114
+ **Then read the right signal**: take the command's exit code, not a grep of test names. (why: [rationale](references/rationale.md#then-read-the-right-signal))
115
+
116
+ **A fix round is verified to have landed before its PR merges.** Check for the commit, not the
117
+ exit code, and **record the tip before you dispatch** — `origin/main..HEAD` also lists the
118
+ implementation commits, so it stays non-empty even when a round did nothing. (why: [rationale](references/rationale.md#a-fix-round-is-verified-to-have-landed-before-its-pr-merges))
119
+
120
+ **Dispose of a class once, not a thread at a time.** (why: [rationale](references/rationale.md#dispose-of-a-class-once-not-a-thread-at-a-time))
121
+
122
+ **A finding with no mechanism gets a one-line refusal, not an investigation.** "Consider adding…",
123
+ "for robustness", "this could be confusing" — ask for the input that fails and resolve. Reopen if
124
+ one arrives. Verifying a claim nobody has actually made costs the same as verifying a real one.
125
+
126
+ ## The rule everything else rests on
127
+
128
+ **Lane status is derived, never asserted.** Before believing any progress report — an
129
+ implementer's, a reviewer's, or your own from an earlier turn — run these and let their output be
130
+ the status:
131
+
132
+ ```bash
133
+ gh pr list --head "<branch>" --json number,url --jq '.[] | "#\(.number) \(.url)"' # empty ⇒ stuck
134
+ git -C "<worktree>" rev-list --count origin/main..HEAD # 0 ⇒ it wrote nothing
135
+ (cd "<worktree>" && npx --no-install hexagen-orchestration-gate)
136
+ git -C "<worktree>" status --porcelain=v1 -b && git -C "<worktree>" diff --stat origin/main...HEAD
137
+ ```
138
+
139
+ **Run the commit count first, and do not skip it because the seat said `SUCCESS`.** (why: [rationale](references/rationale.md#run-the-commit-count-first-and-do-not-skip-it-because-the-seat-said-success))
140
+
141
+ **The gate is a subset of CI, and the difference is named.** The gate binary runs the
142
+ project's configured `gateSteps` in one command — the list `config.yaml` carries, in order, and
143
+ stops at the first failure by name. `ci.yml` runs **one** step it does not:
144
+
145
+ **`yarn install --immutable`** is not in the gate. Say in the brief whether a lane may add
146
+ a dependency, and if it may, that the regenerated `yarn.lock` travels with it. (why: [rationale](references/rationale.md#yarn-install---immutable))
147
+
148
+ **Where a project's `gateSteps` carry a byte-level scan, it is its own step — it is not inside the
149
+ typecheck step.** Nothing else in a usual gate set looks at bytes. The scaffolded config does not add
150
+ one: the gate is a subset of CI, and a scaffold-added step the project did not choose would be a
151
+ required step that fails wherever the scan's bin is not installed (only a `yarn <script>` step can
152
+ skip), so adding it is the project's own decision. (why: [rationale](references/rationale.md#the-byte-level-scan))
153
+
154
+ **A project-specific guard (for example a route-registry scan) belongs in `gateSteps` as its own
155
+ step**, so a lane that adds or moves a test file into a scanned directory is covered by the gate
156
+ itself rather than by a reviewer's memory. (why: [rationale](references/rationale.md#the-other-two-a-conditional-no-op-and-a-route-registry-guard))
157
+
158
+ **A green local gate is not a green CI: diff your gate against the CI workflow first.** (why: [rationale](references/rationale.md#a-green-local-gate-is-not-a-green-ci))
159
+
160
+ Read the diffstat's **deletions**, not just its file count: a tree removing tests whose sources
161
+ still exist is thrashing, not progress. A lane with **no PR has not started stage 2**, and stage 2
162
+ is the only stage that finds defects. If the derived status contradicts the report, the derived
163
+ status wins and your summary says so.
164
+
165
+ **Every lane brief ends with two lines, and they are not optional.** Both were earned:
166
+
167
+ - *If a finding is wrong, say so with the mechanism rather than changing code to match it.* Counters
168
+ the failure that rots a suite quietly — an assertion weakened until it passes.
169
+ - *Run every verification command in the foreground and read its exit code. A task you launched is not a result.* Two
170
+ seats reported green gates they had started and never watched; one of those branches did not
171
+ typecheck.
172
+
173
+ - *Measure a file's coverage the way the gate does — a claim of per-file 100% without the JSON
174
+ reporter's per-file listing is not evidence.* (Template A, in `references/briefs.md`.)
175
+ - *A loaded host is a reason to show the isolated pass and let CI be the gate, never to raise a test
176
+ timeout.* (Template A, in `references/briefs.md`.)
177
+
178
+ **Know which gates are enforced by CI and which are enforced by you.** The plan verifier, a
179
+ lane retiring its own premise, and the mutation verifier on a changed manifest are **CI**; a
180
+ manifest existing at all, and the handoff check on a two-stage lane, are **habits only you
181
+ enforce**. (why: [rationale](references/rationale.md#which-gates-are-machinery-and-which-are-you))
182
+
183
+ **A two-stage lane hands over a handoff file, not a claim.** (why: [rationale](references/rationale.md#a-two-stage-lane-hands-over-a-handoff-file-not-a-claim))
184
+
185
+ **And every lane brief opens by asking the lane to prove the defect before changing anything:**
186
+
187
+ > Restate the defect in your own words and demonstrate it — the failing test, the wrong output, the
188
+ > command that misbehaves. If you cannot reproduce it, **stop and report that**. Do not implement
189
+ > against a defect you have not seen.
190
+
191
+ (why: [rationale](references/rationale.md#and-every-lane-brief-opens-by-asking-the-lane-to-prove-the-defect-before-changing-anything))
192
+
193
+ **Every cell of your final table is command output, not recollection.** If you cannot produce the
194
+ output for a cell, the cell is *unknown* — a valid answer. A confident wrong one is not.
195
+
196
+ ## Before you dispatch
197
+
198
+ 1. **Verify main is green** and the tree is clean. Fast-forward local main.
199
+ 2. **Give the subagent what it cannot infer.** It inherits none of this conversation, so its
200
+ prompt must carry the **absolute worktree path**, the branch, whether a PR already exists, and
201
+ the house rules below. A brief that assumes context the agent does not have is the
202
+ equivalent of an unfunded seat: a whole cycle, nothing to show.
203
+
204
+ 3. **Prove each seat with a trivial DISPATCH, not a chat probe — and give a failing seat one
205
+ attempt per wave.** Edit a scratch file in the lane worktree, confirm it changed, delete it and
206
+ verify the tree is clean, then dispatch for real; when a seat fails, **switch rather than debug**.
207
+ (why: [rationale](references/rationale.md#3-prove-each-seat-with-a-trivial-dispatch-not-a-chat-probe))
208
+
209
+ 4. **Confirm the cast, the lanes and their file ownership** with the owner, and wait for the
210
+ go-ahead. If the plan does not assign file ownership per lane, say so — that is a plan defect
211
+ and the lanes will collide.
212
+ 5. **Red-team each lane brief against the code before dispatching it.** Every path, symbol and line
213
+ number a brief cites must exist; every acceptance criterion must be able to fail. This step has
214
+ caught false premises that would have stalled a lane at its mandatory mutation check.
215
+ 6. **Red-team each brief against ITSELF for completeness.** Step 4 checks that what a brief cites
216
+ exists. This step checks that what it *omits* was a decision. **A lane implements the brief's
217
+ enumeration, not its adjective** — "in full", "the whole surface", "all the relevant fields"
218
+ carry no information the implementer can act on, and they actively suppress the question,
219
+ because a lane that sees a list assumes the list was checked.
220
+
221
+ Before dispatch, for every brief:
222
+
223
+ - **Grep the lane id against every plan, not only its own** (`grep -rniw '<ID>' docs/planning/`),
224
+ matching on word boundaries, **never** on `**<ID>**`. (why: [rationale](references/rationale.md#grep-the-lane-id-against-every-plan-not-only-its-own))
225
+
226
+ - **Mark the plan's lane and decision tables.** `hexagen-orchestration-plan-review` finds a
227
+ row by its bold id (`| **<id>** |`), and a plan that bolds the same id in a second table
228
+ — a shipped list, a findings table — makes the row ambiguous. Put `<!-- plan-review: lanes -->`
229
+ before a lane table and `<!-- plan-review: decisions -->` before a decision table. A marker
230
+ holds across prose and further tables until the next heading of any level, so a table split by
231
+ a paragraph stays covered, and every table needs a marker under its own heading. A plan with
232
+ no marker keeps the old rule (every bold-id row counts); once a plan has one, only rows inside
233
+ a marked region count. Either marker satisfies any id lookup. Adding a marker never changes a
234
+ row's hash.
235
+
236
+ - **Check the gap is still open before dispatching the lane that closes it.** (why: [rationale](references/rationale.md#check-the-gap-is-still-open-before-dispatching-the-lane-that-closes-it))
237
+
238
+ - **If it names a type or a document surface, open that type and paste its fields in.** A
239
+ brief that names a type covers every field that type declares — a reader who cannot see the
240
+ declaration will implement the subset the brief happened to mention, and each field it omits
241
+ ships untested.
242
+ - **Write one test requirement per field**, so a missed field fails a test instead of shipping.
243
+ - **If a value is parsed from a string, name the hazards**: leading zeros, values past
244
+ `Number.MAX_SAFE_INTEGER`, delimiters that can appear in the data.
245
+ - **If the lane compares or gates on state, list the inputs and their refresh cadence.** Two
246
+ sides collected at different times need a carve-out, not a threshold.
247
+
248
+ (why: [rationale](references/rationale.md#four-defects-came-from-briefs-that-failed-exactly-this))
249
+
250
+ The tell is an adjective standing where a list belongs. When you write one, stop and enumerate.
251
+
252
+ 7. **Check the plan's premises first.** `hexagen-orchestration-plan-verify` fails when a
253
+ lane's stated gap has already been closed. Four lanes in one week were dispatched, or nearly
254
+ dispatched, to re-implement shipped behaviour. A lane whose premise no longer holds is not a
255
+ lane.
256
+
257
+ 8. **Every fence you write must be TIMED and shown to decide, before it lands.** `plan:verify`
258
+ kills a premise at **10 seconds**; record the wall time beside each fence, in **milliseconds**.
259
+ Verify three things: that it **holds today**, that it **can flip**, and that it **answers fast**.
260
+ (why: [rationale](references/rationale.md#8-every-fence-you-write-must-be-timed-and-shown-to-decide-before-it-lands))
261
+
262
+ Prefer a probe over a scan: grep one file for the marker that means the lane is done, rather
263
+ than recomputing the lane's whole subject. If the honest completion marker is a gate step, grep
264
+ the workflow for it — a lane that wires a gate cannot land without satisfying that gate, so the
265
+ marker cannot be forged.
266
+
267
+ 9. **Send the plan to the plan reviewer** — the seat the overlay's `cast.md` names for plan
268
+ review — before dispatching any lane from it, whenever the plan introduces or rewrites lanes or
269
+ changes a premise. Nothing else needs this seat. (why: [rationale](references/rationale.md#9-send-the-plan-to-the-plan-reviewer))
270
+
271
+ ## The six stages
272
+
273
+ *Emitting is part of the stage, not a courtesy.* Every transition below appends one event via
274
+ `hexagen-orchestration-wave-event <logdir> <wave> <lane> <stage> <event> [--pr N] [--round N] [--detail '<json>']`
275
+ — one JSON line in `<logdir>/events.jsonl`, where `<logdir>` is the wave's directory under the
276
+ configured `waveLogDir` — and a stage with no event is, to the server, a stage
277
+ that did not happen.
278
+
279
+ 1. **Implement.** One lane = one worktree = one branch = one PR. `yarn install` per worktree
280
+ yourself — **one at a time, never in parallel, and only where the lane actually needs one.**
281
+
282
+ Skip the install **only for a lane that runs no local command needing dependencies** (a
283
+ docs-only lane and little else — a deletion lane still needs `node_modules`). (why: [rationale](references/rationale.md#yarn-berry-hardlinks-package-contents-from-a-shared-global-cache))
284
+
285
+ **Run the config's `installProbes` once the install finishes, before the worktree is
286
+ dispatched.** Under concurrent installs on one host a dependency's postinstall binary can be
287
+ silently skipped, and a lane then fails on a missing binary it cannot repair. Each probe is
288
+ `{package, check, repair?, platform?}`. On a remote lane host run it as
289
+ `ssh <alias> -- sh -c 'cd "$1" && shift && exec "$@"' sh <remote worktree path> <check argv…>`, which runs the probe in the new worktree and passes every argv word
290
+ as its own argument, so nothing is shell-joined; `repair` uses the same form. On a local host
291
+ run `check` with its cwd set to the new worktree. A probe with a `platform` (`darwin`, `linux`
292
+ or `win32`) runs only on a lane host whose platform matches; on a remote host find it with
293
+ `ssh <alias> -- uname -s` (`Darwin` is darwin, `Linux` is linux). When a `check` fails, run its
294
+ `repair` ONCE (same host, same worktree), emit the repair as a wave event, then run `check`
295
+ again. A repair for a stripped package removes the package directory before it reinstalls, as the
296
+ native-binary check below says. If `check` still fails, or `repair` is absent or exits non-zero, **do not dispatch that
297
+ worktree**: report the package and both exit codes. `hexagen-orchestration-doctor` runs the
298
+ `check` of each probe whose platform matches your own host, never a `repair`, and reports a failing
299
+ `check` as FAIL.
300
+ (why: [rationale](references/rationale.md#install-probes))
301
+
302
+ And **after a wave's installs, verify the main checkout still has its native binaries** rather
303
+ than letting the owner's next dev start find out:
304
+
305
+ ```sh
306
+ # Names any platform package left with metadata only, exits non-zero when it names one, and
307
+ # exits non-zero when it discovers NO platform package at all: a loop over nothing proves nothing,
308
+ # and an unmatched glob must not read as healthy. Run it on a Darwin host, and run it under `sh`
309
+ # (zsh's `nomatch` aborts the loop on an unmatched glob).
310
+ #
311
+ # `find node_modules -name '*.node' | head` is NOT a check: a stripped package simply
312
+ # contributes no line, so the command prints the survivors and exits 0 — it reports what
313
+ # exists, never what is missing. Nor is "has a .node file" the test: @esbuild ships
314
+ # `bin/esbuild`, @img/sharp-libvips ships `lib/`, and both are healthy with no .node at
315
+ # all. The payload test below has neither false negative nor false positive on this repo.
316
+ found=0 stripped=0
317
+ for d in node_modules/@*/*darwin*/ node_modules/*darwin*/; do
318
+ [ -d "$d" ] || continue
319
+ found=$((found + 1))
320
+ n=$(find "$d" -type f ! -name '*.json' ! -name '*.md' ! -name 'LICENSE*' | wc -l)
321
+ if [ "$n" -eq 0 ]; then echo "STRIPPED: $d"; stripped=$((stripped + 1)); fi
322
+ done
323
+ [ "$found" -gt 0 ] || echo "NOTHING DISCOVERED: no *darwin* package under node_modules"
324
+ [ "$found" -gt 0 ] && [ "$stripped" -eq 0 ]
325
+ ```
326
+
327
+ (why: [rationale](references/rationale.md#what-the-stripped-binary-check-found))
328
+
329
+ The repair is to delete the stripped package directory and reinstall — a plain `yarn install` will
330
+ not restore it, because the directory's presence makes the package look installed.
331
+
332
+ Write each brief from Template A in `references/briefs.md`, then dispatch it as an `Agent`.
333
+ **Record the worktree tip first** — an agent that reports success having committed nothing looks
334
+ identical to one that did the work. Never let two lanes own the same file at the same time.
335
+
336
+ **A lane is not done until the PR exists, and lanes routinely stop one step short.** Write
337
+ "commit, push, and open the PR with `gh pr create`" as the explicit final instruction in every
338
+ brief; when a lane stops anyway, **finish it mechanically yourself** after verifying the diff. (why: [rationale](references/rationale.md#a-lane-is-not-done-until-the-pr-exists-and-lanes-routinely-stop-one-step-short))
339
+
340
+ **Emit the event in the tool call immediately before the launch, with nothing between them** —
341
+ never afterwards, never "as you go". **There is no launcher that emits for you, and there will not
342
+ be one.** Emission is therefore yours. (why: [rationale](references/rationale.md#emit-the-event-in-the-tool-call-immediately-before-the-launch))
343
+
344
+ Emit as you go: `dispatch started` per lane just before its launch, carrying the seat that
345
+ runs it in `--detail` — `--detail '{"seat":"<implementer model>"}'` — because
346
+ the status page names the seat that ran each lane, and a lane whose record never names one reads
347
+ **unknown**. The seat is a property of the lane, so later stages need not repeat it.
348
+ **When the seat is an external CLI**, the roster the overlay's `cast.md` names, launch it
349
+ directly from a tool call that returns straight away, never from a wrapper that launches and then
350
+ waits (see above): the launch `cd`s into the lane's own worktree, the brief path **must be
351
+ absolute**, the command appends an `EXIT` marker to a log the later call polls, and a probe
352
+ artefact is deleted before the lane is dispatched for real. The template assumes paths without
353
+ spaces or glob characters; quote them for the inner shell if that ever changes. Liveness differs
354
+ by CLI: some stream within seconds, so a log still at 0 bytes after ~30 s **with no process for
355
+ that worktree** is a dead lane, while a CLI that writes nothing until it exits must be watched by
356
+ its process and the worktree's commits. Never call a lane dead from the log alone.
357
+
358
+ **Delegated seats and lane hosts.** The overlay's `laneHosts` and `seats` name where a delegated
359
+ lane runs and who runs it. These rules hold for every host:
360
+
361
+ 1. A remote opencode server executes its tools on the server side. `--dir` is the server
362
+ worktree path. The orchestrator creates that worktree over `ssh`, fetches the lane's commits
363
+ back, then runs the full gate, pushes and opens the PR itself. The lane never pushes; its brief
364
+ carries Template A's lane-host variant.
365
+ 2. A sandboxed seat can read only its worktree. Its brief lives at `.lane/brief.md` inside the
366
+ worktree, and is verified with `git check-ignore` before dispatch.
367
+ 3. A `gate: targeted-only` host runs targeted tests and replays only. Its briefs forbid the full
368
+ gate. The full gate runs on the orchestrator's host, and CI stays the gate.
369
+ 4. Lane liveness is the bytes streamed from the dispatch, plus the lane's commit count against
370
+ the tip recorded before dispatch. An exit code of 0 is not evidence.
371
+ 5. A lane host's `check` exercises the same path as its `dispatch`. A check that only proves the
372
+ remote server is up can pass while the dispatch fails.
373
+ 6. Record the lane's `sessionID` from the first `--format json` event of its dispatch, alongside
374
+ the worktree tip recorded before dispatch. A host's `usage` reader is invoked as
375
+ `<usage…> --server <laneHosts[].server> --session <id>` with that id when the host has
376
+ `laneHosts[].server`; a host without `server` keeps the legacy form, `<usage…> <worktree path>`
377
+ (for example a worktree-based usage script), and
378
+ `hexagen-orchestration-lane-watch follow` takes the same two flags to watch the session. Both
379
+ need the host's `server` (a loopback URL, reached through a tunnel; the caller is assumed to keep it open, which is an open owner question in P-D2). A
380
+ `usage` reading that prints `unknown` and exits 3 is incomplete, not zero.
381
+ 7. **A fix round resumes the lane's own session when the dispatch transport supports it, and
382
+ forks it when the branch has moved** since the lane's last turn (a merge, a refresh). With
383
+ opencode that is `run -s <sessionID>`, plus `--fork` when the branch moved, using the
384
+ `sessionID` recorded in rule 6. These flags are orchestrator-side: they go in the dispatch
385
+ command, never in a lane brief. **Stagger forked resumes by about 20 s.** Two forks launched
386
+ in the same second fail with "database is locked" (opencode's sqlite). (why: [rationale](references/rationale.md#a-fix-round-resumes-the-lanes-own-session))
387
+ 8. **A lane's result is verified on a host other than the one it ran on before it is merged.**
388
+ For a remote lane host, the second host is yours: run the gate after fetching the commits,
389
+ before the PR opens. For a local lane host, CI is the second host: open the PR and read CI's
390
+ conclusion on the PR's final head before merging, never your own gate alone. (why: [rationale](references/rationale.md#a-lanes-result-is-verified-on-a-second-host))
391
+
392
+ **Every brief carries the checkpoint rule**: commit failing tests once seen to fail, commit
393
+ again after each green step, push only when the gate passes — a scoped, owner-confirmed exception
394
+ to `.agents/testing.md`, limited to a lane's own branch. **Do not rewrite history to hide them.**
395
+ (why: [rationale](references/rationale.md#every-brief-carries-the-checkpoint-rule))
396
+
397
+ The per-lane `implement settled|failed` events **are** the completion record of a dispatch —
398
+ `implement settled` when a lane's `EXIT` marker lands, `implement failed` on a non-zero
399
+ marker or a lane killed without one; and `gate settled` with the gate exit and the coverage
400
+ numbers `config.yaml` requires (statements, branches, functions, lines) in `--detail` once the
401
+ gate has run.
402
+ 2. **Review.** **How many model reviews a lane gets follows the plan row's risk column.** A
403
+ normal-risk lane gets ONE combined reviewer pass covering the plan row, the brief and the
404
+ implementation diff together. A high-risk lane keeps separate row, brief and pre-PR reviews, each its own
405
+ pass. The review bots stay on every PR at either tier: they have found real defects after the
406
+ model reviewer approved. (why: [rationale](references/rationale.md#review-tiering-follows-the-plan-rows-risk)) Per PR, two independent inputs, both required: a read-only review from a model that
407
+ is **not** the implementer, and the bot comments (`gh pr checks`, `gh api …/comments`). Verify
408
+ every finding — yours and the bots' — against the branch diff before acting on it. Require the
409
+ reviewer to remove any throwaway worktree it created, and check: two have been left behind.
410
+ When the review of a PR is dispositioned, emit `review settled` with the counts of BUG /
411
+ SUGGESTION / NIT findings in `--detail`.
412
+
413
+ 3. **Remediate.** Merge verified findings into a fix brief (Template C, in
414
+ `references/briefs.md`), listing refuted items with reasons. For a fix round where the lane commits only,
415
+ draft the brief with `hexagen-orchestration-fix-brief --pr <n> --round <k> …` instead: it renders Template E
416
+ from the PR's unresolved threads, and you set each item's `Disposition:` before dispatch. Findings from the
417
+ read-only pre-PR review that were never posted as threads are not in that output: append them yourself as
418
+ additional items in the same layout. Template C remains the brief for a fix lane that pushes. **After any interrupted or killed
419
+ `mutate:verify`, scan for a stranded mutation before anything commits.** (why:
420
+ [rationale](references/rationale.md#3-remediate))
421
+
422
+ Run the remediator in that worktree, then **verify it yourself**: full gate, re-read the
423
+ diff. Never merge on a remediator's self-report.
424
+ After each round you verify, emit `remediate settled` per round with the fixed/refuted counts in
425
+ `--detail`.
426
+ 4. **Sweep** (you, no CLI). Per thread: verify → reply with the resolution and its commit, or the
427
+ refutation and its mechanism → resolve. Then one disposition comment per PR. A refutation is a
428
+ first-class outcome; a silently ignored comment is indistinguishable from an overlooked one.
429
+ When a PR's threads are all dispositioned, emit `sweep settled` with the `fixed` / `refuted` /
430
+ `deferred` counts in `--detail`.
431
+ 5. **Merge** (you). Sequential, via `hexagen-orchestration-merge-prs` — each merge invalidates the CI of
432
+ everything behind it. If main goes red: stop, reproduce locally, ship a minimal hotfix, resume.
433
+ **A green gate is not a merge condition on its own.** Merge only when, on the PR's *final* head:
434
+ every check-run conclusion is success, skipped or neutral (read conclusions, not the rollup line —
435
+ `neutral` is what informational checks report); the review bots have had time to post on that head;
436
+
437
+ and **zero review threads are unresolved**. The merge bin **enforces this
438
+ mechanically** — it waits a bounded settle period for the review bots, then refuses while any
439
+ review thread is unresolved, naming each open thread — and re-reads the PR's head immediately
440
+ before `gh pr merge`, refusing if it moved. **The settle period is a wait, not a proof the bots
441
+ reviewed the final head** — confirm a bot actually posted on it yourself. (why: [rationale](references/rationale.md#the-merge-bin-enforces-this))
442
+
443
+ After each merge lands, emit `merge settled` with the merge SHA in `--detail`.
444
+ 6. **Close the wave** (you, immediately — not later). Append the orchestrator's wave record to
445
+ `.agents/session-log.md`: what merged with its commits, what was refuted **and why**, what the
446
+ review layer actually bought, any defect found in the *plan* rather than the code, and what
447
+ stays deferred. **A wave is not finished when its PRs merge; it is finished when that record is
448
+ committed.** Do this before dispatching the next wave, even under standing authorization —
449
+ especially then, because chained waves are exactly where it slides. If a lane's own session-log
450
+ entry already exists, yours is still owed: a lane reports on itself, the orchestrator reports on
451
+ the wave.
452
+ When the record is committed, emit `record settled` with the PR number in `--pr`.
453
+
454
+ ## Your authority, and its limits
455
+
456
+ Decide without asking: lane boundaries within the plan's ownership table, brief contents, whether a
457
+ finding is real, whether a bot comment is refuted, when a PR is ready, merge order.
458
+
459
+ **You write no feature code** unless intake put you in the implement seat. Even then, keep the
460
+ seats separate in time and never review your own code in the same context.
461
+
462
+ **Standing authorization.** When the owner says to run the remaining waves without stopping
463
+ ("don't stop until it's done", "merge when green and proceed"), that replaces the per-wave
464
+ go-ahead and you do **not** surface for permission you already have — dispatch the next wave as
465
+ soon as its gate clears. It does not replace the stop conditions below, and it does not excuse the
466
+ wave record (stage 6): closing out is part of finishing, not a thing you do at the end if there is
467
+ time. Yielding a turn while a lane runs is not stopping; ending a turn with a status report and
468
+ waiting to be told to continue *is*, and under standing authorization it is wrong.
469
+
470
+ **Stop and report** when: two lanes need the same file and the plan is silent; a merge conflicts
471
+ outside the append-only allowlist; main goes red; a lane's CLI exits non-zero without a PR; a
472
+ finding cannot be verified against the code; the plan and the code contradict each other on a
473
+ locked decision; or a seat runs out of credit.
474
+
475
+ ## House rules that bite here
476
+
477
+ - **Never spawn a funded model seat to reproduce a defect.** Reproduce dispatch and launcher
478
+ behaviour with a stub process, never a paid CLI. (why: [rationale](references/rationale.md#never-spawn-a-funded-model-seat-to-reproduce-a-defect))
479
+
480
+ - **Touching a manifest arms it.** CI replays only the manifests a change *touches*, so editing
481
+ one for an unrelated reason pulls it into the replay set. `hexagen-orchestration-mutate-anchors`
482
+ checks every anchor cheaply ahead of the replay, and also checks whether the `command`'s `-t` still
483
+ selects a test — verify it against the test file's own listing before you record it. Re-anchor
484
+ when the code moved; retire (`"retired": "<why>"`) only when it is gone. (why: [rationale](references/rationale.md#touching-a-manifest-arms-it))
485
+
486
+ - **Before `git reset --hard`, save the diff.** Commit before you test, not after. (why: [rationale](references/rationale.md#before-git-reset---hard-save-the-diff))
487
+
488
+ - **A mutation you did not confirm applied is not a mutation.** (why: [rationale](references/rationale.md#a-mutation-you-did-not-confirm-applied-is-not-a-mutation))
489
+
490
+ - **Never `git add -A`.** The paths `config.yaml` lists as `operatorDataPaths` are the
491
+ owner's data and are never staged by a lane.
492
+ - **Never start a dev server or curl a port `config.yaml` lists as forbidden** — those are the
493
+ owner's live servers; a request there overwrites their output and spends their credits.
494
+ - **Run full gates in a worktree**, never in the main checkout beside a running dev server: the
495
+ build shares its output directory and will disturb it.
496
+ - `best_practices.md` is the reviewer-facts file. Check it before endorsing a finding class it
497
+ disproves, and extend it when a new premise-false class appears.
498
+
499
+ ## Reporting contract
500
+
501
+ After each stage, a few lines: what ran, what came back, what you decided, what is next. At the
502
+ end, one table: `PR | branch | URL | gate | fixed | refuted`. Never claim a fix you have not
503
+ verified, never report a lane done without a PR URL you have just listed, and never call a merge
504
+ complete until you have confirmed main contains it. When stuck, say **STUCK** and what blocks it —
505
+ a stalled lane reported as progress costs far more than one reported as stuck.
506
+
507
+ Every wave gets its record at stage 6, committed before the next wave dispatches. At the end of the
508
+ run, open one session-log PR carrying whichever records are not yet on `main`, then report whether
509
+ the plan has a next wave. **Stop there unless the owner gave standing authorization** — see
510
+ *Standing authorization* above; with it, keep going and let the records, not the pauses, be what
511
+ proves each wave finished.