Skip to content

feat(mecatui): wrap + scroll permission-modal args, full-screen ask-args view (#488) - #553

Merged
jbeda merged 1 commit into
mainfrom
488-permission-modal-args-wrap
Aug 15, 2026
Merged

jbeda merged 1 commit into
mainfrom
488-permission-modal-args-wrap

Conversation

@jbeda

@jbeda jbeda commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #488. The permission modal rendered a non-diff ask's args as one unwrapped pretty-JSON blob, so a long Bash command ran off the approval card and the operator authorized commands they couldn't read.

Two tiers now:

  1. In the modal — the args region soft-wraps (ansi.Wrap + ansi.Hardwrap backstop for unbreakable tokens) into a mini-viewport, scrollable via arrow/pgup/pgdn and the mouse wheel while the cursor is over the card. A fixed hint line advertises ctrl+t full args (plus a … scroll clause when rows are hidden).
  2. Full-screen — ctrl+t on a non-diff ask opens a scrollable ask-args view (mirrors the plan-review pattern: argsVP viewport + pinned generic verdict bar). Verdict keys fire from inside the view; esc/ctrl+t returns to the modal.

Raw ⇄ pretty toggle (inside the full-screen view only, rebindable RawArgs, default bare r):

  • Pretty (default): Bash decodes {"command":…} to the command text (unescaped, deliberately no shell reformatting — no mvdan dep) + a muted timeout_ms: N annotation when the envelope carries one; other tools fall back to prettyJSON.
  • Raw: the verbatim wire args string (sanitized, never re-indented), soft-wrapped — the approval-integrity floor that can't lie.

Presentation: the command renders in a bright askArgs style with a tool-coloured left accent bar so it reads distinct from the muted reason/hint metadata; a soft-wrapped logical line carries a warning-coloured trailing ↩ at the end of each continued row (both surfaces) so a wrap is never mistaken for a real newline; the card sizes to content up to 132 columns (stable across scrolling — the block width pins to the widest line over the whole content, not the visible window) and the in-card cap is 10 rows.

Review map

The change reviewed through a 6-agent panel (spec / standards / security / architecture / duplication / reuse) + a QA test-adequacy pass, then iterated through hand-testing rounds. Where to look, in priority order:

Concern Where Note
The one invariant that matters — render & mouse hit-test agree by construction cmd/mecatui/ui/clickgeom.go approvalClickRegions Each approval surface's regions are computed from the SAME layout builders the render path uses (shared builders, re-run on click — an Elm value-Model has no render-pass side channel, so this is the strongest anti-skew guarantee available). clickAt is a lookup; dispatchClick is the single executor; the wheel gate and hit-test share one card-rect source (approvalCardRect). This refactor is the click half of #555 and replaced the old per-surface askButtonAt arms.
ctrl+t routing rule update.go onExpandToolsKey Non-diff ask → full-screen view (does NOT touch global expandTools); Edit/Write → in-modal diff expand (unchanged); plan ask → untouched. ADR 0108 records this so a future change can't silently un-split it.
Raw/pretty tiers permission.go askArgsContent Raw = verbatim wire string; pretty = readable decode + timeout_ms annotation.
Keymap additions keys.go (RawArgs), keymap/validator.go rules 3b/3c RawArgs shares default r with overlay-internal Refresh in disjoint surfaces; validator rejects explicit rebinds that re-overlap the pair OR shadow a rebound verdict chord inside the view.
Debug affordance builtins.go /debug-ask, gated by MECATUI_DEBUG_ASK=1 env (never a flag, stays out of --help) Injects three rotating canned long-args asks through the REAL reducer. Used for all hand-testing.
Docs docs/tui.md, user-docs/what-you-get/{mecatui,permissions}.md, docs/design/IMPLEMENTATION-NOTES.md, new docs/adr/0108-mecatui-ask-args-view.md

Bugs caught by hand-testing (each pinned by a regression test)

  • Idle spinner — /debug-ask at idle resumed into a dead phaseRunning (spinner forever, no run behind it). advanceAsk now resumes the phase the ask interrupted (askResumePhase).
  • Invisible scroll — scrolling the modal moved askVPOffset but the frame never changed: renderPermissionModal hardcoded argsOffset: 0 (only the hit-test threaded it). Now threaded; regression test drives pgdn through the real onKey dispatch.
  • Width drift on scroll — lipgloss sized the styled args block to the widest visible line, so scrolling onto shorter lines re-centred the card. The block's width is now pinned to the widest line over the whole content.
  • Missing hint — the ctrl+t full args hint rendered only when rows were hidden; it is now unconditional on non-diff asks.

Golden-test hygiene

Churn is exactly the two help goldens (new modal-keys section) + the askargs_* goldens. view_*/zerostate_* stayed clean except one round where a restructure dropped the diff-path reason line — the view_stripped golden caught it and it was restored in the same fix.

Try it by hand

MECATUI_DEBUG_ASK=1 go run ./cmd/mecatui
# /debug-ask cycles 3 canned asks: long pipeline (wraps, shows the ↩ markers),
# compound && / ||, and a multi-section heredoc (scrolls past the 10-row cap).
# In the modal: arrows/pgup/pgdn scroll the args region, wheel works over the card;
# ctrl+t opens the full view; there r toggles raw/pretty, esc/ctrl+t returns, a/w/d resolve.

Preview frames without running: cat cmd/mecatui/ui/testdata/askargs_*.golden.

Follow-ups filed

Non-goals

Heredoc syntax highlighting; clause segmentation; general debug-mode apparatus; scrollback tool-card wrap markers (the ↩ is approval-surface-scoped for now); any change to the Edit/Write diff path, plan-review view, or wire/proto surface.

@jbeda
jbeda marked this pull request as draft August 15, 2026 00:17
@jbeda
jbeda force-pushed the 488-permission-modal-args-wrap branch from 193b6f1 to 102c086 Compare August 15, 2026 04:27
@jbeda
jbeda force-pushed the 488-permission-modal-args-wrap branch 2 times, most recently from 0f905a7 to bd5d55b Compare August 15, 2026 16:53
@jbeda
jbeda marked this pull request as ready for review August 15, 2026 16:56
…rgs view (#488)

The permission modal rendered a non-diff ask's args as one unwrapped
pretty-JSON blob, so a long Bash command ran off the approval card and
the operator authorized commands they could not read.

Two tiers now: the modal's args region soft-wraps (ansi.Wrap + Hardwrap
backstop) into a capped mini-viewport (10 rows; arrows/pgup/pgdn + wheel
over the card scroll it; a fixed hint line advertises ctrl+t full args),
and ctrl+t routes by ask type — non-diff asks open a full-screen
scrollable ask-args view (argsVP, mirroring the plan-review pattern) with
the generic verdict buttons pinned; Edit/Write keep the in-modal diff
expand; plan asks untouched. Verdict keys fire from inside the view;
esc/ctrl+t return to the modal. A rebindable RawArgs key (default bare r)
toggles pretty (decoded {"command":...} + muted timeout_ms annotation)
vs raw (the VERBATIM sanitized wire string — the approval-integrity
floor). The command renders in a bright askArgs style with a
tool-coloured left accent bar; a soft wrap carries a warning-coloured
trailing ↩; the card sizes to content up to 132 columns and stays put
while scrolling (the block width pins to the widest line over the whole
content, not the visible window).

Click geometry is a region-emitting registry (the click half of #555):
each approval surface's regions are computed from the SAME layout
builders the render path uses, with the buttonsRow travelling inside the
builder's return value — one source, no skew; clickAt looks up,
dispatchClick executes, and the wheel gate + hit-test share one
approvalCardRect. MECATUI_DEBUG_ASK=1 registers an env-gated /debug-ask
builtin (never a --help flag) cycling three canned long-args asks through
the real reducer; a debug ask resumes the phase it interrupted
(askResumePhase) rather than a dead running phase. ADR 0108 records the
ctrl+t routing rule, the raw/pretty tier decision, and the wrap-marker
convention.

Co-Authored-By: mecatl <[email protected]>
@jbeda
jbeda force-pushed the 488-permission-modal-args-wrap branch from bd5d55b to b4d87ed Compare August 15, 2026 17:33
@jbeda
jbeda merged commit e185c1b into main Aug 15, 2026
15 checks passed
@jbeda
jbeda deleted the 488-permission-modal-args-wrap branch August 15, 2026 17:55
jbeda added a commit that referenced this pull request Aug 18, 2026
* refactor(mecatui): carve approval modal into domain-owned files (#555 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]>

* refactor(mecatui): dedupe approval resume clamp; stdlib min/max/slices (#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]>

* test(mecatui): pin the three approval invariants the goldens miss (#555 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]>

---------

Co-authored-by: mecatl <[email protected]>
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.

mecatui: permission modal does not wrap long tool args (Bash commands run off the card)

1 participant