Jon Karrer

← Case studies

macOS browser and terminal Oct 28 – Nov 23, 2026 5 min read

Ternt

An Arc-style browser and terminal, with an AI agent in every space.

releases
28
days
27
commits
164
lines of Rust
~36k

A browser and terminal in one macOS window: Arc's sidebar model, real terminals as tabs, and one AI agent per space. Most of the interesting work was in the seams between WebKit, AppKit and the webview library.

At a glance

What
Arc-style spaces, profiles and command bar, with terminals as first-class tabs
Stack
Tauri v2 (Rust), Svelte 5, WebKit, xterm.js; the agent is a separate Rust process
Platform
macOS 14 or later, Apple silicon and Intel
Size
About 36,000 lines of Rust, 9,600 of Svelte and TypeScript
Tests
About 300 Rust tests, 66 TypeScript unit tests, 45 end-to-end suites

Architecture

One window, many native webviews

Each web tab is its own WKWebView. The sidebar, command bar, terminals and agent panel are separate webviews layered in the same window. Pages get real browser processes and data stores, and the UI never shares a JavaScript world with them. The cost: layering native views is where most of the hard bugs came from.

Rust owns the state

Tabs, spaces and folders are plain data in Rust. Webviews mirror it through events and never hold the truth, so the model is unit-tested without a window and a webview that crashes loses nothing. Because every update is a whole new state, the sidebar uses structural sharing so only changed rows re-render.

Tabs load lazily and unload when idle

A tab's webview is created when first shown, so restoring a large session costs about one tab. A tab off screen for 30 minutes drops its view; tabs playing sound or in a call stay loaded.

Terminals: flow control, not buffering

Rust streams raw PTY bytes to xterm.js, which acknowledges what it has parsed. When too much is unacknowledged, Rust stops reading the PTY. A flood throttles the program, not the UI. All terminals share one webview, and only visible ones hold a WebGL renderer.

Web pages get nothing of Ternt

Tab webviews have no IPC access, and the framework's injected scripts are removed from them. This began as a bug fix and became a rule: pages never talk to the app or see its internals.

Profiles are the identity, spaces are the view

A profile is a WebKit data store: cookies, logins, history. Each space gets its own, or several spaces share one. The sidebar only ever shows spaces.

The agent

A sidecar process, not a library

The release build aborts on panic, so a panic or out-of-memory kill in a linked-in agent would take the browser down. The agent runs in its own process, speaking JSON lines over stdin and stdout. Ternt supervises it with back-off restarts and gives up after repeated crashes, showing a Restart button instead of looping.

A written protocol, with a stub behind it

A stub speaks the same protocol with canned replies. The panel, the supervisor and their tests were finished before the real agent was connected, and connecting it changed little. The protocol types have a single source and are generated into the host, after a hand-kept copy had already drifted.

Scope held deliberately small

The agent is a chat with memory, plus tools that need nothing from the browser. Letting it read or act on pages was designed for and deliberately deferred. That kept it shippable and its failure modes few.

A cheap model for the small decisions

Much of an agent's work is small judgement: which thread a message belongs to, which memories matter, whether something is worth keeping. Those go to a fast typed-answer model, used only when it is confident. The main model still writes every word, and everything works without the fast one.

Bring your own key, per space

Each space picks its provider and tools. A change reaches the running agent without ending its conversations. Keys reach the agent only through its environment and are never logged or written to disk. A tool whose key is missing is left out, and the space still opens.

Hard problems

Google Docs would not load

Tauri defines a locked window.ipc in every webview. Google's editors declare their own global ipc, so their main script threw. The fix was removing the framework's scripts from page views, which became the isolation rule above.

Google Docs was blurry

outerWidth was 0 because the webview library's UI delegate lacked WebKit's window-frame callback. Docs scales its canvas by outer over inner width, so it drew at half resolution. Answering that callback with the view's real frame fixed it.

The cursor flickered, and the fix crashed the app

AppKit sends mouse moves to every tracking area, so the UI webview under a page kept resetting the cursor. The first fix missed most cases, because WebKit's tracking belongs to a private observer object rather than the view. The second guarded the observer, but passed the wrong event type into mouseExited:, which raised through Rust frames and aborted the app. The third built a real exit event and contained exceptions in mouse handlers, shipped the same day.

Real new windows

Reopening window.open targets as plain tabs broke pages that open a window and then set its location, forms posted to a new window, and named targets. Ternt now answers WebKit's create-webview call with a tab built from WebKit's own configuration, so the page keeps a real window handle.

Supervising a process has more states than it looks

A process that never became ready left a stale pid. Quitting could spawn a new process during shutdown. A late "off" could undo a later "on". The final shape keeps the wanted state in one flag, checked wherever a process could start, and re-checked after every exit.

Switching a tool off mid-conversation

After web search was turned off, one provider returned empty replies because the history held calls to a tool no longer offered. Before each request, calls to tools that are not on offer are now retold as plain text.

What it shows

  • A thin native layer is not a small one. The hard bugs lived in private observers, missing delegate callbacks and injected globals, and each needed its real cause found.
  • Isolation paid twice. Keeping the app out of web pages fixed Google's editors and closed a security question. Keeping the agent out of the app's process let an unfinished agent ship inside a browser people depend on.
  • Deferring is a design choice. Not letting the agent act on pages yet kept it simple to reason about.

© 2026 Jon Karrer