feat(browser): WebKit browser in Rex panes, with point-and-ask for agents

Merged
DE
1d ago
+2638-4

What

A WebKit browser that lives in a Rex pane, built into leaf. Nothing is installed in Applications. Point at anything on a page and ask your coding agent about it.

  • Leaf: Open Browser (or leaf browser [url]) splits a pane and keeps a native WebKit window exactly over it. It follows the pane through splits, resizes, zoom and tab switches. It hides during Mission Control and while Rex animates panes, and gives way to Rex's palette.
  • Point and ask: use the pointer button or shift+cmd+c, then pick elements with React Grab. Type a question and press enter. It goes to the agent picked with Leaf: Choose Agent…, either in that agent's pane or in a new pane beside the browser. The composer names the agent live.
  • Browser basics: Safari user agent, find, zoom, downloads, uploads, JS dialogs, an error page, and the pane label follows the page title. Rex's shortcuts keep working while the page has focus, and there's a close button in the toolbar.

How

  • build.rs compiles src/browser.swift for the target arch (macOS 13+), and leaf embeds it. On first use, leaf unpacks it to ~/Library/Caches/leaf/webkit-<hash>, replacing older copies. Without swiftc, leaf builds without the browser; in CI that's a build failure.
  • Placement comes from the session.view fractions, Rex's chrome settings from its preferences, and the window-server frame of the Rex window. Refreshes are driven by session events, ignoring client connect events, which used to cause a feedback loop.
  • The helper and leaf browser exchange JSON lines over stdin and stdout. Rust builds the prompt (unit tested) and sends it with agent::deliver.
  • React Grab 0.2.0 is vendored unmodified under vendor/react-grab (MIT). It's loaded only when pointing starts, with telemetry off.

Safety

Any page can call into injected JS. So a pick only adds context to a native composer, and only enter in that composer sends anything to the agent. Picks are accepted only right after a real click or key in the browser window.

Testing

  • cargo test: 679 pass. Clippy shows no new warnings.
  • Tested live in Rex: placement (side by side, stacked, zoomed); close; navigation, search and errors; find; Cloudflare-protected pages; React Grab picks sent to a stand-in agent pane; the composer naming the agent (picked or open); and the palette over a browser pane.
  • Not tested: an Intel build, dark mode, or Rex layouts other than vertical tabs with no headers.

🤖 Generated with Claude Code


Summary by cubic

Adds a WebKit browser that opens in a Rex pane, embedded in leaf. Point at page elements and ask your agent about them; includes leaf storage and saved HTML pages read as markdown. Also tightens up the browser's security and edge cases and bumps the release to 0.18.0.

New Features

  • Leaf: Open Browser splits a pane and keeps a native WebKit window over it; nothing is installed in Applications.
  • The browser and its pages follow Rex's light or dark appearance.
  • Opened without an address, it shows a start page with leaf's mark and the web servers running on this Mac, one click away.
  • Point-and-ask: pick elements with React Grab, type a question, and it goes to the agent picked with Leaf: Choose Agent….
  • leaf storage shows what fills a drive, with junk to clear.
  • Saved HTML pages read as markdown, with inline images and sharp SVGs.

Fixes

  • Picks are only accepted right after a real click or key in the browser, and a page can't forge the markers around the picked elements, page titles, or addresses.
  • Prompts are capped at 24k characters of elements; shift+cmd+c points while cmd+c stays copy.
  • The browser exits cleanly when its pane closes, and reruns the build script if a Swift toolchain appears.
  • leaf browser --check prints the helper's path so the release can verify it's built for the right architecture.