Files
museion/docs/adr/0011-apex-html-reading-pipeline.md
T
AlexKucera fd806e9e76
CI / ci (push) Canceled after 0s
fix(reading): ship apex with libyaml, signed
The bundled apex had never run on a Mac without Homebrew: its release
build resolves libyaml through rpaths for its CI runner and the
Homebrew prefixes, and macOS ships no libyaml, so reading mode silently
fell back to the raw source for everyone else since #76. The notary
service rejected it too (an unsigned Mach-O in Resources), which is how
this surfaced during the 0.1.0 cut.

Resources/apex is now the arm64 slice of 1.1.58 (was 1.1.17), Developer
ID-signed with the hardened runtime, with one rpath that resolves in
the bundle and in the checkout alike. libyaml 0.2.5 rides beside it in
libyaml.bundle/, same team signature: a bare dylib in the synced folder
is classified by content and silently linked into the app, so the
.bundle wrapper is load-bearing. THIRD-PARTY-NOTICES.md ships with both
MIT texts; ADR-0011's bundling consequence is rewritten to match.
2026-12-01 15:12:25 +01:00

2.9 KiB
Raw Blame History

0011 — Apex HTML reading pipeline

Reading mode renders markdown through apex (MIT, unified dialect) as an HTML fragment loaded into a single WKWebView styled by our CSS — typography slots become CSS custom properties, and a blank-line-chunked data-source-line stamp (sentinel HTML comments, applied post-conversion; apex emits no source positions) carries the click-to-edit and scroll-sync map at paragraph granularity. Proven live in the #74 spike (PERF-3k: ~18 ms apex, 33 ms end-to-end, zero mis-stamps corpus-wide); ruled in #73. Supersedes ADR-0010's reading stance — its editing stance (TextKit2 mode B) stands — and records ADR-0001's boundary as ruled: native-only governs the editing side; reading is presentation, so WKWebView is allowed.

Considered Options

  • TextKit reading renderer (#71 build) — deleted, not kept as fallback: fallbacks rot, and its stale-flow defect dies unfixed by design. The decoupling obligation (editing side up to par as a plain-text surface) is ticketed separately (#77).
  • loadFileURL instead of loadHTMLString — 4× first paint (255 ms vs ~67 ms) from sandbox negotiation; --embed-images base64 inlining needs no file access at all and writes nothing into the vault.

Consequences

  • Bundling: the prebuilt apex binary (arm64 slice) and a vendored libyaml ship in app resources, Developer ID–signed at commit time (apex with the hardened runtime), apex's rpaths replaced by the single @executable_path/../Resources, which resolves in the bundle and in the checkout alike; Xcode copies and seals both as resources untouched. The vendored copy lives in Resources/libyaml.bundle/ ON PURPOSE: Xcode's synced-folder classifier sniffs Mach-O content and silently adds any bare dylib (extension or not) to the app's link phase; a .bundle folder is an opaque resource. apex's release build links libyaml through CI/Homebrew rpaths, so alone it only ever ran on developer machines — reading mode silently fell back to source for everyone else (surfaced by the 0.1.0 notarization, which also rejects an unsigned Mach-O in Resources). Re-sign both when the Developer ID certificate rotates (codesign -f -s "<identity>" --options runtime --timestamp Resources/apex; codesign -f -s "<identity>" --timestamp Resources/libyaml.bundle/libyaml-0.2.dylib). No source build in CI, no user install gate — a renderer must not grow a gate. Licenses: Resources/THIRD-PARTY-NOTICES.md.
  • One WKWebView, reloaded in place. Remounting per document (.id(sel)) was the dominant switch cost — hundreds of ms of web-process respawn; loadHTMLString on a retained view feels instant.
  • --no-mixed-lists is required, not tuning: apex's default merges an ordered list following a bullet list into one <ul>, killing 1. 1. 1. auto-renumbering.
  • Early handoff: stdout EOF is conversion done; apex's ~65 ms teardown is reaped async via terminationHandler (the error path still waits for exit status).