Skip to content

fix(tui): sync Mermaid renderer fixes - #41347

Open
kitlangton wants to merge 1 commit into
v2from
fix/v2-mermaid-session-rendering
Open

fix(tui): sync Mermaid renderer fixes#41347
kitlangton wants to merge 1 commit into
v2from
fix/v2-mermaid-session-rendering

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What

Sync the v2 terminal Mermaid renderer with the latest OpenTUI renderer fixes and performance work.

This fixes corrupted state diagrams with branching and feedback, supports Mermaid connectors used in real model output, decodes HTML entities in labels, and brings over the spatial routing and canvas row-extent optimizations.

Before / After

Before: A lifecycle state diagram containing a main path, a side branch, two self-transitions, and a feedback edge placed PromptSubmitted and Polling in overlapping bounds. The Completed -> Idle feedback route also crossed MailboxPending, overwriting its frame and label. Valid -. label .- and <--> flowchart connectors fell back to source code instead of rendering.

After: Fallback states keep their compact rank-based placement but move when that position collides. Bottom feedback approaches select a clear vertical corridor around unrelated states. Labeled undirected dashed and bidirectional connectors parse and render with the correct arrowheads.

How

  • packages/merman/src/state/layout.ts detects and separates colliding horizontal fallback states.
  • packages/merman/src/state/routing.ts chooses collision-free bottom approach corridors for feedback and parallel routes.
  • packages/merman/src/flowchart/parser.ts and drawing.ts support labeled undirected dashed edges and bidirectional arrowheads.
  • packages/merman/src/core/spatial.ts centralizes semantic body, route, and label collision checks.
  • packages/merman/src/core/canvas.ts tracks visible row extents and fast-paths ASCII writes.
  • Parser, routing, placement, Markdown, and real-world diagram regressions are synchronized with OpenTUI.

Scope

OpenCode-specific plugin.ts, palette.ts, markdown.ts, and color integration remain unchanged. The newer OpenTUI Markdown-renderable reuse path is not included because v2 currently uses @opentui/core 0.4.5 and does not expose those APIs.

Testing

  • cd packages/merman && bun run test (285 passing)
  • cd packages/merman && bun run typecheck
  • Push hook: bun turbo typecheck --concurrency=3 (33 packages passing)
  • Replayed all 18 Mermaid fences from session ses_01db49b85ffe6yLOdvjVuh2siN through the synced renderer with no failures
  • Verified the lifecycle regression preserves each state label exactly once

Demo

Real PTY capture of the corrected lifecycle fixture rendered by @opencode-ai/merman:

Corrected Mermaid lifecycle rendering

Flow

flowchart TD
    Diagram[Parsed state diagram] --> Place[Compact rank placement]
    Place --> Collision{State bounds collide?}
    Collision -->|Yes| Shift[Move fallback state past occupied bounds]
    Collision -->|No| Route[Plan transitions]
    Shift --> Route
    Route --> Approach{Bottom approach crosses a state?}
    Approach -->|Yes| Clear[Select nearest clear corridor]
    Approach -->|No| Draw[Draw route]
    Clear --> Draw
Loading

@kitlangton
kitlangton enabled auto-merge (squash) August 9, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant