Skip to content

refactor(mecatui): approval modal consolidation (#555 Phase 1) - #608

Merged
jbeda merged 3 commits into
mainfrom
feat/approval-surface-phase1
Aug 18, 2026
Merged

jbeda merged 3 commits into
mainfrom
feat/approval-surface-phase1

Conversation

@jbeda

@jbeda jbeda commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What

Phase 1 (Milestone 1) of #555: carve the mecatui approval modal out of its six-file, technical-layer spread into four domain-owned files, so a change to the modal touches one place instead of a phase flag, a renderBody arm, an onKey branch, a wheel branch, a hit-test arm, a lifecycle clear, and a help listing held in lockstep.

No behavior change. Frame goldens (TestViewGoldenStripped, TestViewGoldenAztecANSI) pass unmodified; task test, task lint, task docs all green.

The shape

File Owns
approval_state.go approvalState (ask, FIFO queue, dedupe set, plan/args viewport clusters) + pure queue methods. Model now holds one approval approvalState field; resetSession/endRun collapse to approval.reset().
approval_surface.go Behavior split: a pure surface half (mutates state, returns []approvalAction) + thin Model shims that execute them.
approval_render.go Renderers/builders (was permission.go) + renderApprovalBody.
approval_regions.go Mouse hit-test geometry (the #553 region-registry vocabulary stays shared in clickgeom.go).

permission.go is deleted (83% renamed to approval_render.go).

Locked decisions (driving the shape)

  • D1 — state consolidation before file moves, one rename sweep.
  • D3 — approvalDeps: the explicit five-field list of what the surface may touch (theme, keys, sendApproval, notice, sessionID), built per call, never stored. No *Model back-reference.
  • D6 — key bindings stay Model-global (keys.go); a surface's renderer advertises which it consumes.
  • 4 (pure function) — the surface proposes, the Model disposes: resolveAsk/applyPermissionAsk return actions; the shim does stream.SendApproval / conv.addNotice / the phase assign + sp.Tick re-arm. The modal no longer calls the wire. This is the Elm/Redux-slice pattern, and it's what makes the modal testable without a live stream.
  • 5 — approval_arch_test.go is a loud structural gate: fails CI if an approval-vocabulary declaration lands outside the four files, or Model grows a second approvalState field.

m.phase and the phase ⟺ ask.AskID != "" invariant stay Model-side (they gate the whole Model, not just the modal).

Why this is the conventional shape

Surface-as-pure-function-over-state emitting actions that the caller executes is the Elm Architecture (Bubble Tea's own model) taken one level down — the same as Redux slices (state + reducer + action values) and VSCode workbench parts (own view + contribution, registry composes). What we avoid is a retained-mode widget tree with a back-pointer. Phase 2's surface stack (modal exclusivity by z-order, top owns the frame) layers onto this.

Phase-2 handoff

The four-file split is the boundary the surface interface will formalize: Render ≈ renderApprovalBody, Regions() ≈ approvalClickRegions, HandleKey/HandleWheel ≈ onApprovalKey/approvalWheel, Close() ≈ reset(). approvalDeps is the template for each surface's deps. The two things deliberately kept Model-side — m.phase and refreshView() — are what Phase 2 must decide whether to formalize. The arch gate becomes the per-overlay checklist for the inventory-overlay migration.

Verification

  • task test / task lint / task docs: green
  • Goldens pass unmodified (no -update)
  • Spinner re-arm contract intact (TestResolveLastAskRearmsSpinner, TestSpinnerVisibleMatchesFooterRender)
  • go run ./cmd/mecademo prints the full offline session

jbeda and others added 3 commits August 17, 2026 20:34
…Phase 1)

The approval modal's state and behavior were scattered across six files split
by technical layer (model.go fields, update.go reducers, permission.go
renderers, clickgeom.go hit-test, view.go render arm, keys.go bindings). That
spread is the drift point PR #553 exposed — a single feature touched the
render path and the hit-test arm in two places and got them out of sync.

Phase 1 consolidates the modal into four domain-owned files, no behavior
change:

- approval_state.go — the approvalState value (ask, FIFO queue, dedupe set,
  plan/args viewport clusters) and its pure queue-manipulation methods.
  Model now holds ONE `approval approvalState` field instead of ~12 loose
  fields; resetSession/endRun collapse to approval.reset().
- approval_surface.go — the reducers/handlers, split into a pure surface half
  (mutates approvalState, returns []approvalAction) and thin Model shims that
  execute the actions (the wire send, the transcript notice, the phase
  transition, the spinner re-arm). The modal no longer calls the wire
  directly — the surface proposes, the Model disposes. approvalDeps is the
  explicit five-field list of what the surface may touch, built per call,
  never stored; no *Model back-reference.
- approval_render.go — the renderers/builders (formerly permission.go) +
  renderApprovalBody.
- approval_regions.go — the mouse hit-test geometry.

The keymap bindings (Allow/Deny/RawArgs) stay Model-global vocabulary; the
phase value and the phase<->ask invariant stay Model-side.

Structural gate: approval_arch_test.go fails CI if an approval-vocabulary
declaration lands outside the four files, or if Model grows a second
approvalState field.

Verification: task test, task lint, task docs all green; the frame goldens
TestViewGoldenStripped/TestViewGoldenAztecANSI pass unmodified; the
spinner re-arm contract (TestResolveLastAskRearmsSpinner,
TestSpinnerVisibleMatchesFooterRender) is intact. go run ./cmd/mecademo
prints the full offline session.

Co-Authored-By: mecatl <[email protected]>
#555 review)

Panel-review follow-up to Phase 1. The cross-confirmed Domain finding:
approvalState.advance() already clamps adv.resume to idle|running, and the
three Model-side consumers re-applied the identical `if resume != phaseIdle {
resume = phaseRunning }` — one resume invariant living in four places, dead
code that would silently diverge if the rule ever changed. Delete the three
consumer copies and trust advance()'s contract (the single source of truth).

Mechanical cleanups from the same pass:
- miniScroll + permissionModalBodyParts clamps → max(0, min(...)) builtins.
- askQueueIndex → slices.IndexFunc.
- drop the dead Model markAskResolved shim (only a test used it; it now calls
  approvalState.markAskResolved directly).
- fix the arch-gate regex's dead advanceAsk token (the symbol is advance()).

approvalAction's open-* payload (ask/queued/model) is deliberately KEPT: it
makes the action self-describing for any future non-immediate dispatch (the
out-of-order-approval direction discussed in review), at the cost of a
today-redundant copy. Documented in the PR.

task test / task lint green; goldens unmodified.

Co-Authored-By: mecatl <[email protected]>
… review)

The QA/test-adequacy pass on Phase 1 found three behaviors the frame goldens
do not pin — axes a "pure migration" could silently break while the suite
stays green. Add executable oracles for each:

- TestPlanReviewNoOpRepopulationPreservesOffset / TestArgsViewRawToggleRepopulates:
  the planVP/argsVP fingerprint no-op-repopulation guard (a dropped fingerprint
  would re-SetContent and yank the operator's reading position, invisible to a
  single-frame golden). Verified the plan test FAILS when the guard's
  fingerprint term is removed, so it pins the behavior, not just the code.
- TestDebugAskResolveNilStreamNoPanic: the /debug-ask-from-idle nil-stream
  resolve path — the sendApproval dep must return nil, not panic, and the
  notice must still land. The one path no golden executes.
- TestPhaseAskIDBiconditional: the documented `phase==phaseAwaitingApproval ⟺
  ask.AskID != ""` invariant swept across open / enqueue / resolve-successor /
  resolve-drain / retract-visible. The arch gate is placement-only; this is the
  behavioral pin.

task test / task lint green; goldens unmodified.

Co-Authored-By: mecatl <[email protected]>
@jbeda
jbeda marked this pull request as ready for review August 18, 2026 23:02
@jbeda
jbeda merged commit 72c04dd into main Aug 18, 2026
15 checks passed
@jbeda
jbeda deleted the feat/approval-surface-phase1 branch August 18, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant