Prototype: apex HTML reading-surface spike #74

Closed
opened 2026-10-06 15:30:24 +02:00 by AlexKucera · 1 comment
Owner

Part of #20

Question

Proof or kill the apex → HTML → WKWebView reading surface before ADR-0011 commits to it (decision context: #73).

Scope (one afternoon, throwaway):

  • Bundled apex binary (MIT) renders spike/prose/kitchen-sink.md + spike/prose/PERF-3k.md → HTML fragment (no --standalone).
  • WKWebView (NSViewRepresentable) loads the HTML + local CSS via loadHTMLString(_:baseURL: post-folder) — relative image paths resolve for free.
  • CSS custom properties fed from ProseTypography slots + flow knobs (Body/Headings/Code × face+size, LH 1.25, spacings 1/2 lines, 24pt margins) — Settings pane unchanged.
  • data-source-line stamped on top-level elements by our blank-line chunker as a post-pass (paragraph granularity) — the click-to-edit + scroll-sync mapping proof.
  • ⌘-click link interception (decidePolicyFor), external → NSWorkspace.
  • Measure: first-paint flash, PERF-3k scroll hitches, apex subprocess latency in-app.
  • Eyes on pixels: Alexander judges the typography against the TextKit screenshots.

Deliverable: facts for ADR-0011 — or the kill list if something doesn't hold.

[Generated by AI]

Part of #20 ## Question Proof or kill the apex → HTML → WKWebView reading surface before ADR-0011 commits to it (decision context: #73). Scope (one afternoon, throwaway): - Bundled apex binary (MIT) renders `spike/prose/kitchen-sink.md` + `spike/prose/PERF-3k.md` → HTML fragment (no `--standalone`). - WKWebView (NSViewRepresentable) loads the HTML + local CSS via `loadHTMLString(_:baseURL: post-folder)` — relative image paths resolve for free. - CSS custom properties fed from ProseTypography slots + flow knobs (Body/Headings/Code × face+size, LH 1.25, spacings 1/2 lines, 24pt margins) — Settings pane unchanged. - `data-source-line` stamped on top-level elements by our blank-line chunker as a post-pass (paragraph granularity) — the click-to-edit + scroll-sync mapping proof. - ⌘-click link interception (`decidePolicyFor`), external → NSWorkspace. - Measure: first-paint flash, PERF-3k scroll hitches, apex subprocess latency in-app. - Eyes on pixels: Alexander judges the typography against the TextKit screenshots. Deliverable: facts for ADR-0011 — or the kill list if something doesn't hold. [Generated by AI]
AlexKucera added the wayfinder:prototype label 2026-10-06 15:30:50 +02:00
AlexKucera changed title from Part of #20 to Prototype: apex HTML reading-surface spike 2026-10-06 15:30:50 +02:00
AlexKucera added a new dependency 2026-10-06 15:30:59 +02:00
AlexKucera self-assigned this 2026-10-06 15:39:36 +02:00
Author
Owner

Verdict: PROVEN — the apex → HTML → WKWebView surface holds. ADR-0011 has its facts.

Live-tested by Alexander (window driven in-app, corpus + kitchen-sink + PERF-3k).

Mechanism facts

  • Source mapping works, simply: our blank-line chunker prepends <!--S:N--> before each block; apex passes HTML comments through verbatim; a regex post-pass rewrites them to data-source-line="N" on the following element. Corpus-wide coverage check: 0 mis-stamps (every stamp points at a real non-blank source line), PERF-3k = 128 blocks. Live-verified: click-any-paragraph reports correct line; scroll reports top visible line (same map → scroll-sync).
  • apex flags that matter: --no-mixed-lists is REQUIRED — default mode merges an ordered list that follows a bullet list into one <ul> (kills 1. 1. 1. auto-renumbering, a #69 hard requirement). --embed-images --base-dir <post-folder> inlines images as base64 data URLs.
  • Latency: apex emits complete HTML at stdout-EOF in ~18 ms (PERF-3k 3.4k words); ~65 ms of process teardown follows which we do NOT wait for (async reaping via terminationHandler; error path still waits for exit status). End-to-end render (chunk+apex+stamp) measured 33–34 ms via --pipeline.
  • The dominant UX cost is NOT apex — it was SwiftUI remounting the WKWebView per document (.id(sel)): hundreds of ms of web-process respawn + blank pane. ONE WKWebView reloaded in place (loadHTMLString) makes switches feel instant; old text stays visible until new paints. Alexander: "much better. approved."
  • Paint: loadHTMLString ~67 ms first paint; the loadFileURL alternative measured 255 ms (sandbox negotiation) — 4× cost. Choose loadHTMLString + base64 images; it needs no file access at all (bonus: nothing written into the vault).
  • ⌘-click links: JS interceptor (preventDefault + message handler) → NSWorkspace. Works.
  • Images: inline at 1.6em height, CSS transition expand on hover (cheaper than #71's NSPopover; feels calm — approved).
  • Scrollbar: default WKWebView overlay indicator, native look — fine.

Deviations from ticket scope

  • Typography judged "needs tuning but works" → that's #72 calibration's job, not this spike's.
  • No standalone latency instrumentation in-app beyond stats bar (numbers from --pipeline headless runs).

Kill-list

Empty. Nothing failed.

Lessons (cross-cutting, for #76 rebuild)

  1. Blanket-cancelling navigation in decidePolicyFor also cancels your own loadHTMLString — allow your main-frame load explicitly.
  2. AX (System Events) and CGWindowList can BOTH misreport SwiftUI windows; settle probe-vs-reality with one screenshot.
  3. --embed-images on stdin flow needs --base-dir for relative image paths.

Spike code: branch spike/apex-html, commit 7afd1a0, spike/apexhtml/ (throwaway; --check + --pipeline self-tests).

[Generated by AI]

## Verdict: PROVEN — the apex → HTML → WKWebView surface holds. ADR-0011 has its facts. Live-tested by Alexander (window driven in-app, corpus + kitchen-sink + PERF-3k). ### Mechanism facts - **Source mapping works, simply**: our blank-line chunker prepends `<!--S:N-->` before each block; apex passes HTML comments through verbatim; a regex post-pass rewrites them to `data-source-line="N"` on the following element. Corpus-wide coverage check: **0 mis-stamps** (every stamp points at a real non-blank source line), PERF-3k = 128 blocks. Live-verified: click-any-paragraph reports correct line; scroll reports top visible line (same map → scroll-sync). - **apex flags that matter**: `--no-mixed-lists` is REQUIRED — default mode merges an ordered list that follows a bullet list into one `<ul>` (kills `1. 1. 1.` auto-renumbering, a #69 hard requirement). `--embed-images --base-dir <post-folder>` inlines images as base64 data URLs. - **Latency**: apex emits complete HTML at stdout-EOF in **~18 ms** (PERF-3k 3.4k words); ~65 ms of process teardown follows which we do NOT wait for (async reaping via `terminationHandler`; error path still waits for exit status). End-to-end render (chunk+apex+stamp) measured 33–34 ms via `--pipeline`. - **The dominant UX cost is NOT apex** — it was SwiftUI remounting the WKWebView per document (`.id(sel)`): hundreds of ms of web-process respawn + blank pane. ONE WKWebView reloaded in place (`loadHTMLString`) makes switches feel instant; old text stays visible until new paints. Alexander: "much better. approved." - **Paint**: `loadHTMLString` ~67 ms first paint; the `loadFileURL` alternative measured **255 ms** (sandbox negotiation) — 4× cost. Choose `loadHTMLString` + base64 images; it needs no file access at all (bonus: nothing written into the vault). - **⌘-click links**: JS interceptor (preventDefault + message handler) → NSWorkspace. Works. - **Images**: inline at 1.6em height, CSS transition expand on hover (cheaper than #71's NSPopover; feels calm — approved). - **Scrollbar**: default WKWebView overlay indicator, native look — fine. ### Deviations from ticket scope - Typography judged "needs tuning but works" → that's #72 calibration's job, not this spike's. - No standalone latency instrumentation in-app beyond stats bar (numbers from `--pipeline` headless runs). ### Kill-list Empty. Nothing failed. ### Lessons (cross-cutting, for #76 rebuild) 1. Blanket-cancelling navigation in `decidePolicyFor` also cancels your own `loadHTMLString` — allow your main-frame load explicitly. 2. AX (`System Events`) and CGWindowList can BOTH misreport SwiftUI windows; settle probe-vs-reality with one screenshot. 3. `--embed-images` on stdin flow needs `--base-dir` for relative image paths. Spike code: branch `spike/apex-html`, commit 7afd1a0, `spike/apexhtml/` (throwaway; `--check` + `--pipeline` self-tests). [Generated by AI]
Sign in to join this conversation.