Skip to content

refactor(mecatui): replace scrollback block union with typed payloads #1789

Closed

Description

@jbeda

Problem

cmd/mecatui/ui/conversation.go uses one broad tagged block union for every scrollback entry. The struct combines unrelated payloads: user media, streamed assistant Markdown/reasoning, tool calls/results/delegation state, notices, hook metadata, errors, and scheduled deliveries.

This makes each block kind harder to reason about and spreads its state/rendering concerns across the UI. It is not appropriate to fold into the current functional-block preparation cleanup: the block revision is a cache-safety contract, and event ingestion mutates these records in many places.

Proposed direction

Explore a typed runtime representation with a small common envelope and a closed payload family:

type scrollBlock struct {
    id      uint64
    rev     int
    payload blockPayload
}

type blockPayload interface {
    blockKind() blockKind
}

Examples of payloads: userPayload, assistantPayload, toolPayload, hookPayload, noticePayload, errorPayload, deliveryPayload.

The envelope retains the stable identity and render revision used by the renderer cache. Each payload holds only fields meaningful for its kind. The renderer and event projection use an explicit closed type switch at the boundary rather than one struct with many conditionally meaningful fields.

Avoid a broad behavior interface: the shared data is only identity/revision/kind, and rendering/event projection still need typed payload access.

Staged approach

  1. Complete the current narrow preparation-boundary work first: typed rendering inputs such as blocks.HookInput should be built by explicit UI adapters, e.g. hookInputFromBlock(*block).
  2. In a separately approved implementation plan, inventory every mutation gateway and direct test fixture that touches block.
  3. Introduce typed payloads while preserving the cache envelope and the rule that every render-visible mutation increments rev.
  4. Preserve event ordering, scroll anchoring/provenance, tool-resolution behavior, and delegation/team live-state semantics.

Acceptance criteria

  • No payload type contains fields that are meaningful only for a different block kind.
  • The conversation model retains a stable per-block identity and revision, and every render-visible mutation invalidates the per-block render cache.
  • All event ingestion paths construct or mutate the appropriate typed payload.
  • Rendering, frame provenance, scrolling/selection, tool resolution, assistant streaming, and delegation/team views remain behaviorally equivalent.
  • Existing direct block{...} test fixtures are migrated to typed constructors or focused payload fixtures; tests remain offline.
  • The preparer boundary remains pure: the ui/internal/blocks package receives typed rendering inputs, not mutable UI conversation state.

Non-goals

  • This issue does not require a generic cache package or a behavior-heavy block interface.
  • Do not combine it with the current shared block-theme, cache-key cleanup, or render.go file split unless a follow-up plan explicitly chooses to do so.

Activity

  1. self-assigned this
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions