feat(mermaid): add terminal diagram renderer - #1351
Open
kitlangton wants to merge 34 commits into
Open
Conversation
kitlangton
requested review from
Hona,
kommander,
msmps and
simonklee
as code owners
August 8, 2026 03:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add
@opentui/mermaid, a publishable OpenTUI package for rendering Mermaid-flavored flowchart, sequence, state, and timeline diagrams as terminal text and styled Markdown blocks.The implementation comes from
@kitlangton/mermanand the production OpenCode integration.How
createMermaidMarkdownRendererandcreateMermaidCodeBlockRendererfor OpenTUI Markdown integration.Performance
A calibrated benchmark covers one medium fixture from each family and emits machine-readable
METRIClines.macOS arm64, Bun 1.3.14, seven measured 400 ms rounds:
The true-prefix Markdown streaming benchmark runs five revisions: reset, valid growth, invalid partial fallback, completion, and closing fence.
Baseline diagnostics:
StyledTextDrawing dominates the current workload; parsing is roughly 1% of complete render time. This gives future Zig work a concrete target at the canvas/drawing boundary rather than the syntax layer.
Scope
This PR upstreams and optimizes the TypeScript implementation while establishing its performance contract. It does not add native Mermaid code; the measured TypeScript path is already sub-millisecond for the complete representative streaming cycle.
OpenCode-specific plugin registration and theme-token mapping remain in OpenCode; they can become a thin adapter over this package after release.
Testing
bun testinpackages/mermaid: 313 passbunx tsc --noEmit -p tsconfig.jsonbun run buildinpackages/mermaidbun run test:dist --skip-build: clean built-artifact consumer import, typecheck, and all four family rendersnpm pack --dry-runfrompackages/mermaid/dist: 20 files, 148.5 kB packedbun run fmt:checkbun run lintThe local full native build is blocked by Zig 0.15.2 versus current
main's required Zig 0.16.0. The new Mermaid CI job uses the repository-pinned Zig 0.16.0 on Linux and Windows and performs build, source tests, and built-artifact consumer tests.Demo
Direct
@opentui/mermaidintegration inside an OpenTUIMarkdownRenderable, with cleanqteardown:opentui-mermaid-pr.mp4
Timeline update
The package now also renders Mermaid
timeline,timeline TD, andtimeline LRfences as a terminal-native vertical spine. It supports titles, sections, standalone periods, inline and continued events, entities,<br>lines, comments, and accessibility metadata. The vertical form is intentional for narrow Markdown viewports; parsed Mermaid direction remains available through the public model.Input:
timeline title From private fork to upstream profile in one day section Morning 11:30 : Profile PR parked as draft 12:05 : MCP transport fixes : Environment-spawner stdio transport section Midday 13:16 : MCP stdio merged 13:20 : Interrupt report lands section Afternoon 14:07 : Workerd profile merged 14:36 : Deployed and live self-testActual terminal output from
renderTimelineDiagram:Additional validation after the timeline update: