Skip to content

feat(native): HTML render frames in the transcript, first slice - #91

Merged
rynfar merged 4 commits into
nativefrom
nw/87-html-render
Nov 3, 2026
Merged

rynfar merged 4 commits into
nativefrom
nw/87-html-render

Conversation

@rynfar

@rynfar rynfar commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Problem

When an agent called html_render, the native client showed only a tool row inside the turn's work log. The web draws the page inline as a sandboxed frame that fits its height, with an "Open full screen" view (HtmlRenderFrame.tsx, HtmlRenderDialog.tsx, HtmlRenderDocument in BrowserDocumentFrame.tsx). Issue #87, ledger row TR-HTML.

Approach

Core (crates/core/src/html_render.rs, tests beside it). Ports readHtmlRenderReference, htmlRenderFrameHeight (measured widths, the column-width cap, live content height up to 20 000), htmlRenderFileName and readHtmlRenderContentHeight from packages/shared/src/htmlRender.ts. It also ports the envelope reader of compactDynamicToolOutput / htmlRenderFromToolItem (toolOutput.ts), including its byte and node budget. resolveT3McpToolId is narrowed to html_render. The upstream envelope test is ported row for row.

Timeline. A completed dynamic_tool whose result carries an htmlRender reference becomes EntryKind::HtmlRender and then RowKind::HtmlRender. It sits outside the turn fold and superseded-attempt folds, as on the web, with the web's pb-2 spacing. Running, failed and isError results stay tool rows. Extended the timeline tests.

The web view (crates/app/src/webview/), reusable for TR-MCPAPP.

  • It wraps a wry 0.54 WKWebView in a clipping NSView container under GPUI's view.
  • The page is served from memory through a private t3-page: scheme, with the server's sandbox CSP minus downloads. Each view gets a non-persistent WebKit store, so the page never sees the app's token, cookies or storage. No token goes in any URL.
  • A navigation delegate (PagePolicy) decides by frame. The main frame loads only the page's own t3-page: document. WebKit keeps no sandbox across a main-frame navigation, nor on inherited data:/blob:/about: documents, and every main-frame document gets the IPC bridge. Subframes load what a nested frame of the web's sandboxed iframe could (http(s), data:, blob:, about:) and inherit the page's sandbox, but never the page's scheme. IPC messages from any frame but the page are ignored. All of this is tested.
  • A new-window request from a clicked http(s) link (the bootstrap's target=_blank) opens in the default browser; windows are always refused. Script windows need a reader's click (javaScriptCanOpenWindowsAutomatically off; macOS defaults it on).
  • Lifetime: a web_view element holds a lease in its element state, and the view is placed with zui's Window::on_present. The view therefore shows only while a frame draws it, follows cached paint reuse, and hides in the same frame its row scrolls away. Only the drawing frame holds it (the store keeps a weak handle), so it is destroyed a frame later: on scroll, a thread switch, or a transcript closing. At most 6 inline views exist; past that a frame shows its card.
  • Scrolling: WebKit keeps every wheel event, so a local NSEvent monitor passes vertical wheel scrolls over inline pages to GPUI's view. The transcript keeps scrolling over a frame, as an iframe that fits its page does on the web. Horizontal scrolls stay with the page.
  • Focus: a click on GPUI content, or a view being hidden or dropped, hands first responder back to GPUI's view.
  • Views are made only while the window is key. On macOS 13, wry activates the app when it builds a view.

Overlays (what I did about z-order).

  • On first use the window calls zui's enable_scene_overlay(). Deferred content (menus, context menus, popovers, dialogs, the command palette, toasts, tooltips) then draws on a plane above native views. That plane takes input while any of it is open, so nothing new was needed at those call sites.
  • Base-plane content that draws over the transcript registers an occluder, and pages are clipped away from it on the edge that keeps the most. The occluders are the find bar, the provider and error banners, the minimap preview, the thread details card (a popover in narrow windows), and the composer's @// menu, which floats above the composer over the transcript. The composer itself sits below the transcript, so it never overlaps.
  • The full-screen view is drawn in the base plane so its page can sit above its backdrop. Its backdrop is an occluder of a higher layer, so inline pages hide while it is open.

App (crates/app/src/transcript/html_render.rs).

  • Pages are fetched with assets.createUrl (inline attachment, text/html) and assets::fetch_media on the network runtime. Up to 32 are cached, and a failed fetch is retried after 30s.
  • The bootstrap only reports height to a parent frame, so a document-start script posts the same ui/notifications/size-changed message through window.ipc.
  • Theme: the view's NSAppearance follows the app's light or dark mode, so the bootstrap's default palette applies. The theme's canvas is set as --background right after the bootstrap's theme sheet, as the web's getStandardThemeColors overrides it. The default theme therefore matches the web exactly, and pages sit seamlessly on the canvas.
  • Full screen (HtmlRenderDialog): the page is 92% wide and min(86vh, 100vh − 160) tall, on a 75% black backdrop. It has the close button above the top-right corner, the title, and zoom from 50% to 200% (page zoom), with the overlay/media-close buttons sized in rem. Escape or a backdrop click closes it.
  • A native view can't have GPUI controls drawn on top of it, so "Open full screen" is an icon-xs button under the frame's right edge, always visible. On the web it is a hover-revealed button on the page.
  • Where no view can exist (other platforms, the offscreen renderer, past the cap), the frame shows the fallback card: title, file name, and "Open in browser" (the signed asset URL).
  • Dev only: --html-fixture <page.html> (and T3_NATIVE_HTML_FIXTURE, both behind the snapshot feature) appends a completed html_render to the open thread, served from the file. The smoke server can't publish one, because html_render needs an agent's thread-scoped MCP call.

thread_view.rs gained the store init and the cfg'd fixture, and transcript/mod.rs the module line plus the row and spacing arms.

Evidence

The page in all captures is a real bootstrapped page, generated by running the shared injectHtmlRenderBootstrap on a small dashboard.

  • Real window (smoke server, "Native client showcase", passive capture of my own PID): /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/87/real-2.png. The WKWebView shows the page inline, sized to its reported height, using the theme variables, seamless on the canvas, with the control under it. real-1.png in the same folder is from before the canvas fix: the page sits on the bootstrap's #0a0a0a, a visible box on the app's #000.
  • Offscreen renderer (--snapshot … --html-fixture):
    • snap-card.png shows the fallback card and row spacing.
    • snap-full.png shows the full-screen layout: backdrop, box, close button, caption and zoom. The page area is empty because the offscreen renderer can't host a native view.
  • Checks: cargo clippy --workspace --all-targets -- -D warnings, cargo clippy -p t3-native --all-targets --features snapshot -- -D warnings, cargo test --workspace, node scripts/gen-theme.ts --check, node --test parity/sync.test.ts, conformance/generate.ts --check.

Not verified

Synthetic input to a real window is dropped, so none of these were exercised in a real window:

  • clicking or typing in a page
  • links opening in the browser
  • the wheel hand-off to the transcript
  • menus or the palette over a page
  • the full-screen page with its view

Gaps (TR-HTML stays partial)

  • Pages get the default T3 palette in the app's light or dark mode, on the active theme's canvas. Named themes' other colors and the reader's font settings don't reach pages yet (the web passes the full htmlRenderTheme).
  • App shortcuts from a focused page (t3/notifications/shortcuts / keydown) are not forwarded.
  • Clicking an image inside a page doesn't open the image viewer (t3/notifications/open-image).
  • Links open in the default browser, not the in-app browser, and change-request links aren't routed.
  • Cmd-key equivalents such as Cmd+C reach GPUI before the page, so copying text inside a page may not work.
  • Pages with their own vertical scroll areas can't be wheel-scrolled inline; they scroll in full screen.
  • "Open full screen" is under the frame rather than hover-revealed on it.
  • The full-screen view doesn't pin the timeline's follow (onFullscreenChange).
  • The full-screen view stays open across a thread switch.
  • No downloads from pages.
  • After the first frame, the window presents with Core Animation transactions (zui's scene overlay), so native geometry and both Metal planes land in the same frame.

Built with Claude Opus 5.5 in Claude Code.

A completed html_render tool result draws as a frame: the page is fetched as an
inline attachment off the UI thread and shown in a WKWebView (wry) while its row
is on screen, sized to the page's reported height, with a full-screen view and
zoom. The web view wrapper (webview/) hosts native views beneath zui's scene
overlay so deferred menus, dialogs and the palette stay above pages, and clips
pages away from base-plane overlays that register an occluder.
@rynfar
rynfar force-pushed the nw/87-html-render branch from fc7ff0e to 460ad06 Compare November 3, 2026 00:06
…views

Pages can no longer navigate any frame to a remote site (WebKit keeps no sandbox
across navigation and every main-frame document gets the IPC bridge), and script
windows need a reader's click. Inline views are held only by the frames drawing
them, so they go when a thread switches or a transcript closes. The thread
details popover registers an occluder, and the full-screen controls scale with
the interface size.
A navigation delegate decides by frame, which wry's URL-only handler cannot: the
main frame loads only the page's own document (WebKit keeps no sandbox across a
main-frame navigation, nor on inherited data:/blob:/about: documents), subframes
load what a sandboxed frame could but never the page's scheme, and a new-window
request from a clicked http(s) link opens in the browser. IPC messages from any
frame but the page are ignored.
Any other t3-page: URL is the 404 document, so the main frame and IPC now accept
only the exact page URL (any fragment), every custom-protocol response carries
the sandbox, and the page policy forwards didFinishNavigation to wry's delegate
too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant