Repository navigation
Description
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
- Complete the current narrow preparation-boundary work first: typed rendering inputs such as
blocks.HookInputshould be built by explicit UI adapters, e.g.hookInputFromBlock(*block). - In a separately approved implementation plan, inventory every mutation gateway and direct test fixture that touches
block. - Introduce typed payloads while preserving the cache envelope and the rule that every render-visible mutation increments
rev. - 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/blockspackage 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.gofile split unless a follow-up plan explicitly chooses to do so.
Activity