Skip to content

feat(clients): render Mermaid diagrams as text off the UI thread - #2

Merged
khoi merged 12 commits into
mainfrom
feat/mermaid-ascii-package
Oct 3, 2026
Merged

khoi merged 12 commits into
mainfrom
feat/mermaid-ascii-package

Conversation

@khoi

@khoi khoi commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Mermaid fences currently appear as source in chat and Markdown previews. Supported fences now render as selectable text diagrams, with source switching and copying. Unsupported, invalid, or oversized inputs keep their source.

The renderer is vendored into a standalone workspace package with no runtime dependencies. Web and desktop lazily render visible, closed fences in a browser worker. Mobile renders completed messages in a dedicated Worklets runtime. Its build produces one self-contained worklet, using the existing Expo/Babel setup. Native output uses ASCII borders so Android font fallback cannot misalign Unicode box characters. The text renderer omits terminal coloring and its extra canvases.

The clients share serialized admission, source deduplication, and a bounded cache. Input, graph, allocation, pathfinding, and cooperative time limits bound rendering work. Unsupported syntax and titles that cannot fit their layout retain source. Browser workers have startup and execution deadlines with replacement after failure. Native Worklets has no termination API and relies on the renderer's deterministic bounds and cooperative deadline. The server still delivers the original Markdown.

Implementation and submission were requested by the repository maintainer in the originating thread. This uses the shared Markdown paths for chat and previews, is provider-independent, and requires no server contract or connection-mode changes. The Android chat prerequisite in #6 has merged; this PR targets main.

Verification: 272 focused tests passed, including 100 golden fixtures, parser and drawing fidelity, deep-chain layout, bounds, queue/cache behavior, browser recovery, clipboard fallback, native representation switching, and native packaging. Packaging tests execute the actual serialized worklet for both platform Babel configurations, check parity for six diagram types, and exercise rejected inputs and deadlines. Scoped typechecks, targeted lint, and the mobile dependency check passed. The web production build passed with a separate 77,427-byte worker (23,651 bytes gzip). Production exports for iOS and Android produced Hermes bytecode.

An integrated web pass verified rendering, source switching, copying without the Clipboard API, and source fallback. The actual browser worker passed the statement, label, bottom-to-top, sequence-note, and long-title regressions. An installed Android API 35 development client verified cold startup, pairing with isolated server state, flowchart and sequence rendering, horizontal panning, source switching after panning, copy feedback, fallback-source copy/paste, and light/dark appearance. A renderer source edit appeared in the native background runtime through Fast Refresh; reverting it restored the original diagram. Native verification caught and fixed the startup integration, Android copy icon, scroll reset, and border alignment issues.

iOS simulator execution remains unverified. The installed Xcode 26.3 fails while compiling ExpoModulesJSI before application code runs. Expo documents this toolchain incompatibility; the simulator pass needs a newer Xcode. Packaged Electron and Android release APK execution were not tested. Landing checks exposed stale test fixtures left by the existing app-identity change; their WSL paths, branch prefixes, and release URLs now match production. The four affected test files pass locally (108 tests), and their 13 Linux-only cases pass in CI. CI passes the full test suite, lint, typecheck, build, Rust, and release smoke checks.

Screenshots

Web: rendered sequence diagram and unsupported-input fallback.

Web diagram view

Web before: Mermaid source

Web source before rendering

Android: selectable ASCII diagrams with horizontal scrolling.

Android diagram view

Android source view

Android source view

Recordings: web switching and copying, Android switching and copying.

Model: GPT-6-Astra. Harness: Codex.

khoi added 3 commits October 3, 2026 00:24
Keep the text renderer and its parsers in a dependency-free workspace
package so layout can run independently of the client or server.
Expose plain ASCII and Unicode output and fix invalid coordinates when
chains exceed 25 nodes.
Show supported Mermaid fences as selectable text diagrams with source
switching and copying. Keep rendering local to each client and preserve
source when a diagram exceeds the renderer's limits or is unsupported.

A browser worker and native Worklets runtime share bounded admission,
deduplication, and caching. Native Bundle Mode requires Metro patches and
ESM resolution for workspace packages under inline imports.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL 📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 13.5 KiB — 15.1 KiB ✅
Codex Thread snapshot wire — 7.1 KiB — 7.3 KiB ✅
Codex Live turn WebSocket wire — 6.4 KiB — 7.8 KiB ✅
Codex Live turn WebSocket decoded — 56.2 KiB — 66.4 KiB ✅
Codex Live turn messages — 9 — 21 ✅
Claude Total thread wire — 13.5 KiB — 15.1 KiB ✅
Claude Thread snapshot wire — 7.1 KiB — 7.3 KiB ✅
Claude Live turn WebSocket wire — 6.4 KiB — 7.8 KiB ✅
Claude Live turn WebSocket decoded — 57.0 KiB — 66.4 KiB ✅
Claude Live turn messages — 9 — 21 ✅

Baseline: unavailable · PR result: f1e3e0a · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 114.0 KiB
  • Claude decoded thread snapshot: 114.7 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@khoi
khoi changed the base branch from main to fix/mobile-animated-ref October 3, 2026 00:39
khoi added 3 commits October 3, 2026 01:41
Keep complete statements, updated labels, bottom-to-top text, and initial
sequence notes in rendered diagrams. Size subgraph titles to fit and
fall back to source when spacing cannot preserve them.

Remove unused terminal coloring and its parallel canvases. Reuse the
shared clipboard hook so diagram copying works over remote HTTP.
@khoi
khoi changed the base branch from fix/mobile-animated-ref to main October 3, 2026 00:58
@khoi
khoi marked this pull request as ready for review October 3, 2026 01:07
@khoi
khoi merged commit 3d6ca76 into main Oct 3, 2026
28 of 31 checks passed
@khoi
khoi deleted the feat/mermaid-ascii-package branch October 6, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant