feat(ultraplan-local): emit main-merge-gate stats event from Phase 8

Wire the main-merge-gate lifecycle event into commands/ultraexecute-local.md
Phase 8. Three event variants emitted via lib/stats/event-emit.mjs (S8):
  - main-merge-gate     fired at the gate boundary
  - main-merge-approved fired on operator confirm
  - main-merge-declined fired on operator decline (run recorded as partial)

The gate ALWAYS pauses regardless of gates_mode — it is the one always-on
boundary that --gates does not toggle. On decline, --resume re-enters at
the gate, and the wave session branches survive on the remote thanks to
Hard Rule 19's push-before-cleanup. Recovery surface is documented inline.

Pin in tests/lib/main-merge-gate.test.mjs locks the always-on prose, the
event names, and the recovery-surface contract.
This commit is contained in:
Kjell Tore Guttormsen 2026-05-04 07:55:41 +02:00
commit b837274b77
2 changed files with 93 additions and 0 deletions

View file

@ -1267,6 +1267,57 @@ Do NOT dispatch a third recovery. Report to the user.
Always produce a final report.
### Main-merge gate (MAIN_MERGE_GATE — always pauses)
Before writing the final progress + state files (and before any "merge to
main" prose), emit the `main-merge-gate` lifecycle event so observability
and operator tooling can see that the pipeline reached its terminal
boundary:
```bash
node ${CLAUDE_PLUGIN_ROOT}/lib/stats/event-emit.mjs \
--event main-merge-gate \
--payload "{\"plan\":\"${PLAN_PATH}\",\"wave_count\":${WAVE_COUNT}}"
```
Pause for operator confirmation via `AskUserQuestion`:
**Question:** "All waves merged. Ready to proceed with the main-merge step
and finalize the run?"
| Option | Action |
|--------|--------|
| **Confirm — main-merge** | Emit `main-merge-approved`, proceed to write progress + state files. |
| **Decline — hold for review** | Emit `main-merge-declined`. Wave commits remain on their session branches for inspection. The run is recorded as `partial`. |
This pause is **always on**, regardless of `gates_mode`. The `--gates` flag
re-enables earlier per-wave pauses; this gate is the one boundary that
ALWAYS pauses on every run — it is the safety stop between completed waves
and the merge that publishes the integrated result.
On confirm:
```bash
node ${CLAUDE_PLUGIN_ROOT}/lib/stats/event-emit.mjs \
--event main-merge-approved \
--payload "{\"plan\":\"${PLAN_PATH}\"}"
```
On decline:
```bash
node ${CLAUDE_PLUGIN_ROOT}/lib/stats/event-emit.mjs \
--event main-merge-declined \
--payload "{\"plan\":\"${PLAN_PATH}\",\"reason\":\"${reason}\"}"
```
**Recovery surface:** if declined, `--resume re-enters at the gate`
re-running `/ultraexecute-local --resume --project <dir>` jumps directly
back to the main-merge gate AskUserQuestion (skipping completed waves).
The wave session branches are preserved for inspection (Hard Rule 19's
push-before-cleanup ensures they survive on the remote even if local
cleanup ran). To inspect: `git log ultraplan/<slug>/session-N` per wave.
### Progress + state-file writes
Update progress file: `status` to `completed`/`failed`/`stopped`, `updated_at`, `summary`.
**Also atomically write `.session-state.local.json`** (Handover 7) at this