Photo-to-Mindmap With LaTeX, Mindloft Stage, and 77 Remediation Fixes (v0.5.0–v0.6.0)
How Mindloft shipped Mindloft Stage after fixing 77 full-stack presentation flaws, then skipped traditional OCR to turn whiteboard and slide photos directly into structured KaTeX mindmaps — including an ArkTS union-narrowing fix on HarmonyOS.
Once users could organize Markdown and PDFs in Mindloft, their next request was blunt: I took a photo of a classroom whiteboard or two consecutive lecture slides — turn that into a mindmap.
Across v0.5.0 and v0.6.0, two tracks converged: hardening Mindloft Stage (multi-route presentations built over a single mindmap) after a 77-item audit, and shipping photo-to-mindmap with math formulas across web, desktop, iOS, Android, and HarmonyOS.
Mindloft Stage: 77 Fixes and Four Rich-Text Export Paths
Before commit 6f76fa9b, @ramilo/stage, @ramilo/export, and @ramilo/web unit tests were all green (10, 10, and 43 cases). Walking the actual speaker workflow — drafting from a mindmap, editing slides, publishing, jumping to Q&A side-slides, remote control, and exporting PDF/PPTX — uncovered 77 real defects.
Four P0 failures stood out:
- Private node leakage (
CORE-01): Marking a branchramilo.stage.visibility: 'private'did not propagate down to descendants insourceFromSheet. Worse, a node’s second image or the tail of an auto-split slide (splitOverflow) becameindependentcontent, dropping its source link and leaking private text or images into published decks. - Q&A return jumping to slide 0 (
CORE-02): Advancing past the end of an off-track Q&A slide ranadvancePlayheadagainstsceneOrder, hitindexOf === -1, and kicked the presenter back to slide 0. - Out-of-order exports (
CORE-03):block.moveupdatedslotnumbers without reordering the array, whileresolveScenenever sorted, so the editor and player showed different layouts. - Theme-blind HEX colors and split anchors: Hardcoded dark text dropped to
1.15:1contrast on dark stage themes, and freeform blocks mixed center-basedtranslate(-50%, -50%)with top-left coordinates. We locked down four semantic color tokens viaresolveBlockColor(color, theme)and standardized top-left percentage anchors everywhere.
In v0.5.0, we pushed markdown.ts and latex-unicode.ts down into @ramilo/contracts so all four Stage export targets shared one parser: standalone .html and offline .zip packs emit native MathML via KaTeX (output: 'mathml'), working completely offline, while PDF and PPTX run through buildRichExportParagraphs and check embedded font glyph tables (canUseUnicode) to degrade formulas cleanly into Unicode (α, ∑, ≤) or ASCII (<=). We also gated applyReviewed so collaborator draft reviews only overwrite the live URL during active present mode, added transactional backup_restore_receipts (RESTORE_OUTCOME_UNKNOWN on lost reconnects), and caught RAMILO_AI_TRIAL_SECRET=<UNSET> on production before startup.ts could trigger an automatic rollback.
Skipping OCR: Direct Vision-to-Schema Mindmaps
For v0.6.0 (6d067263), we evaluated 33 real classroom whiteboards, slides, and engineering diagrams organized into 32 test cases (including multi-photo slide sequence multi_7222_7223).
A two-stage pipeline (“OCR first, then text LLM”) broke hand-drawn arrows, piecewise equation braces, subscripts, multi-column comparisons, and projector UI noise before the text model even saw the content. Sending images straight to the vision model (deepseek-flash with thinking disabled) under a strict JSON Schema hit 32/32 after up to one auto-repair pass (28/32 on first pass, 6.60s and ~2,018 input tokens per single photo; 8.01s for multi_7222_7223 yielding 17 nodes across depth 3 with img_1 / img_2 citations in evidence[].blockId).
Two backend rules keep this reliable:
- Normalize math delimiters to
$...$/$$...$$:packages/contracts/src/markdown.tstreats\\(...\\)as escaped text, so prompts and server normalization rewrite them consistently. - Never silently fall back to text-only models:
RAMILO_AI_VISION_*feeds intoaiRuntimeConfigId. When unconfigured,/v1/ai/capabilitiesexplicitly reportsvisionEnabled: false.
Instead of stuffing multi-megabyte Base64 images into AISourceVersion.blocks[] — which breaks the 3 MiB JSON record cap in ai-records.ts and forces ai-worker to depend on OSS — we added ai_source_blobs across Memory, SQLite, and PostgreSQL. services/api/src/ai-source.ts validates raw JPEG/PNG/WebP magic bytes (up to 5 images, 4 MiB each), rejects SVGs, and serves previews with X-Content-Type-Options: nosniff and sandboxed CSP headers.
Four Headless Chromium Passes and HarmonyOS Union Narrowing
Across four headless Chromium visual passes (1440×900, 1024×768, 390×844, light and dark), the side-by-side photo/mindmap review UI surfaced six bugs no unit test caught: stacking split-panes too early at 960px instead of 820px; Escape in <dialog closedby="any"> closing the entire AI drawer instead of just the lightbox; unrendered $...$ inside warning banners and excerpt cards; sticky pane overlap at 1024×768; low-contrast [被遮挡] badges in dark mode; and 390px badge wrapping on 图 1.
On mobile, BrainletFileBridge moved EXIF orientation, 1600px max-edge downscaling, and JPEG compression into native iOS, Android, and HarmonyOS code before crossing the React Native bridge into photo-mindmap-modal.tsx (a full-screen 3-snap split view: 44dp / 35%:65% / 60%:40%).
One compiler snag hit HarmonyOS right after (7b9693e2): BrainletFileBridgePackage.ets initially returned a TypeScript-style discriminated union (CompressedPhotoResult | CompressedPhotoFailure) expecting if (!compressed.ok) to narrow .message and .item. ArkTS rejected that union narrowing during build. Flattening the return type into a single CompressedPhotoOutcome interface (ok: boolean; item?: NativePickedPhotoItem; message?: string;) with explicit if (!compressed.ok || !compressed.item) checks got the HarmonyOS bridge compiling cleanly.
Comments