# Rune: plan *Research notes behind every claim are in [`research/`](research/). Numbers marked "target" are commitments to measure against, not results.* ## The short version Rune is a Rust UI framework with its own renderer, text, layout, state, animation and platform shells, built to feel like SwiftUI-on-iOS at 120 Hz and to be written and checked by agents. **Direction:** Rune apps carry **their own design language on every platform, Mac included**, rather than imitating each OS. Rune itself bakes in no brand: it ships a token-driven theming system, and OpenCode's theme is the first theme built on it and the reference example. The flagship test is **recreating OpenCode Desktop** in Rune and raising its bar, which makes Windows and Linux first-class from the start. Native stays where it's behaviour, not looks: text input/IME, accessibility, window management, clipboard, scroll momentum. A Rust component library with the same names as `@opencode/ui`, gallery and screenshot tests, and Hex Settings as the first real screen fold in here instead of becoming a second stack on Slint. | Layer | Pick | Instead of | |---|---|---| | Language | Rust (2024), thin `objc2`/Swift shims on Apple | Zig, C++, Swift, Mojo | | GPU | wgpu on every platform first (one backend ships Mac, Windows, Linux and web); a raw Metal backend later only where a measured need shows up (live-resize sync, IOSurface video), via wgpu-hal escape hatches first | Raw Metal first, Vulkan/D3D12 by hand | | Renderer | One instanced "uber-quad" SDF pass + glyph atlas + Slug for big/animated text and icons + `vello_gpu` sparse strips for complex vectors; soft-edge masks in-shader on every clip | Full compute Vello, Skia, MSAA path textures | | Look | Unbranded core with a token-driven theming system (semantic tokens, themes with light/dark, runtime switching, codegen); the same look on every platform. OpenCode's theme (from `@opencode/ui`) is the first theme and the main example, kept outside the core | A theme baked into the framework; per-OS native look; Liquid Glass as the base (it's an optional Apple extra) | | Text | Parley + HarfRust + skrifa + fontique, GPUI-style two-tier line cache, kitlangton/gpui glyph dilation | CoreText-only, cosmic-text | | Text editing / IME | Zed's `sum_tree` + rope; each platform's own text protocol, implemented directly (`NSTextInputClient`, `UITextInput`, …) | winit's IME, a hidden native text field | | Layout | Taffy (flex, grid, block) on Rune's own node arena, plus a sum-tree height index for huge lists | Own layout engine, SwiftUI-style proposals | | State | Keyed retained tree rebuilt from plain view functions; typed models; reads subscribe; handlers queued with `&mut` | Signals, GPUI entities, immediate mode | | Animation | Render thread owns the presented tree; every property is an analytic spring track (duration + bounce, SwiftUI's formula) that retargets with velocity | Animating through view re-renders on the main thread | | Accessibility | AccessKit, and the same tree is the agent inspector's tree | Own a11y bridges | | Shells | winit to start (the prototype runs on it); own thin shells per platform (borrowing from Zed's Apache-2.0 `gpui_macos`/`gpui_windows`/`gpui_linux`/`gpui_ios`/`gpui_web`) as soon as text input lands, because winit's IME is incomplete | winit forever, SDL3 | | Hot reload | Tokens and live literals with no rebuild (≤ 100 ms), subsecond hot-patching for structural Rust edits on Mac (~1 s measured, goal 300 ms), **split-process dev mode** for the iPhone (renderer on the phone, app code on the Mac) | A view DSL interpreter, code loading on the device | | Platform order | macOS + Windows + Linux together (one wgpu backend) → web (docs site, demos) → iOS → Android | | **Top three risks:** text input and text quality (IME on three desktops, then iOS `UITextInput`), matching OpenCode Desktop's Chromium-rendered look closely enough (text above all), and sheer scope. **First milestones:** Rune's theming system plus an OpenCode theme generated from `@opencode/ui` as its first consumer, and a component gallery styled by it; Hex's Settings as the first real screen on Mac, Windows and Linux; then OpenCode Desktop's main screens. A docs/marketing site comes first to explain it. --- ## 1. Why build this at all Kit has rebuilt the same small surfaces three times in ten days: the Scrawl pill went GPUI → hand-written Metal → SwiftUI helper process, the launcher app went GPUI → SwiftUI with a Core Animation glass morph, and Hex's native branch stalled because Hex also ships on Windows and Linux. Each time, the reasons were the same: 1. **No backdrop or glass.** GPUI draws one forward pass into one layer; Liquid Glass only exists in the window server. 2. **Animation waited behind the main thread.** The Metal pill dropped 85 frames on finish until it got its own display-link thread. 3. **Windows and focus were wrong for HUDs and launchers** (late focus events, Dock policy, no non-activating panels, per-frame window resizes). 4. **Text looked thin and colours were off,** and unseen glyphs stalled the first frame by ~13 ms. 5. **No springs or layout animation,** so every app hand-rolled them. 6. **Upstream was frozen** at 0.2.2 for Kit's apps, so every fix lived in a fork. Upstream GPUI has since moved a lot: Zed's tree at `5447804` has `gpui_ios`, `gpui_web`, a wgpu backend, `spring.rs`, AccessKit and subsecond hot reload (verified in a clone). It still redraws the whole window every dirty frame, has no layer compositing or group opacity, runs animations by re-rendering views on the main thread, and panics on re-entrant entity borrows ([01](research/01-gpui-zed-warp.md)). Those are the exact things that sent Kit to Apple frameworks, and they're architectural. **Verdict: don't fork GPUI; start fresh and lift its best parts** (rope/sum_tree, BoundsTree, line layout cache, the macOS/iOS IME code, the web textarea bridge, the shader fixes in Kit's fork) under its Apache-2.0 licence. ## 2. Tenets 1. **Feel is the product.** 120 Hz, interruptible springs, nothing pops, jumps or hard-clips. Kit's motion rules are runtime defaults, not discipline. 2. **Animation never runs through app code.** Views state targets; the render thread animates. 3. **Everything observable.** Every frame, node, layout rect, spring and timing can be queried, traced and replayed. The agent's view of the app is the same tree as accessibility's. 4. **One way to do things.** Small explicit APIs, no macro DSL for views, errors that say how to fix. 5. **Native behaviour, one look.** Text input, accessibility, scroll momentum, clipboard and window behaviour are native per platform. Controls, type, motion and materials come from the app's theme, the same on every platform, Mac included. The framework ships no brand of its own. 6. **Owned, not wrapped.** Depend on foundational crates (Taffy, Parley, AccessKit), never on another UI framework. 7. **Optimise for performance, correctness, speed of change and prototyping; not for human readability**. Agents write and maintain the code, so: - **Fast path plus reference path.** Each hard subsystem (layout, text, renderer, springs) has a slow, obviously correct reference implementation (CPU, no tricks) and a fast one (SoA, SIMD, `unsafe` where measured, specialised, duplicated). Every change differential-tests the fast one against the reference on generated inputs. Correctness comes from the reference and the oracles, not from the fast code being easy to read. - **Data-oriented everything:** flat arenas indexed by ids, struct-of-arrays, no `Rc`/`RefCell`, zero allocation per frame (enforced by a counting allocator in tests), precomputed tables, pipelines built ahead of time. - **Specialise by codegen, not by generics.** Generated, repetitive, per-component code is fine; deep trait towers and proc-macro DSLs are not, because they slow compiles and bury errors. Debug builds stay type-erased and fast to compile; release builds specialise. - **Edits are safe because checks are instant:** invariants as `debug_assert`s everywhere, scenes, goldens, motion/layout lint and exact perf counters run on every change, so an agent sees breakage in seconds. - **Comments state invariants and intent for the next agent,** not prose for a human reader. - **Perf is measured by counts** (instructions, instances, glyphs, layout nodes, allocations) so gates are exact and bisectable; wall-clock numbers come from reserved hardware. - **Prototypes are cheap and throwaway:** live literals, scenes, the playground and hot reload make trying ten variants faster than debating one. ## 3. Architecture ``` ┌──────────────────────── dev only: same protocol over USB/Wi-Fi ────────────────────────┐ │ │ ┌────────────────┴─────────────────────────────┐ commands: tree diff, ┌──────────────────────┴─────────────────────────┐ │ APP SIDE (platform main thread by default) │ layout rects, targets, │ RENDER THREAD (display-link paced) │ │ │ springs, text runs │ │ │ models (typed state, keyed by stable ids) │ ───────────────────────────────▶ │ presented tree (what's on screen right now) │ │ view fns → keyed El tree → diff │ │ property tracks: analytic springs, retarget │ │ Taffy layout at the *target* state │ ◀─────────────────────────────── │ presence (exiting nodes), layout edge tracks │ │ Parley shaping, line cache │ events: hits, gestures, │ scroll physics, drag bindings (1:1, local) │ │ handlers: queued, get &mut model │ settles, presented-frame ids│ scene build → instance buffers │ │ AccessKit tree updates │ │ encode (Metal / wgpu) → present │ └──────────────┬───────────────────────────────┘ └──────────────┬─────────────────────────────────┘ │ platform calls │ CATransaction: Metal drawable + ┌──────────────┴───────────────────────────────┐ ┌───────────────┴────────────────────────────────┐ │ SHELL (per platform) │ │ NATIVE LAYERS (Apple) │ │ windows/panels, menus, clipboard, DnD, │ │ NSGlassEffectView / UIGlassEffect underlays, │ │ IME protocol, a11y adapter, lifecycle │ │ AVPlayerLayer, MapKit; masks driven per frame │ └──────────────────────────────────────────────┘ └────────────────────────────────────────────────┘ background pool: image decode, big-paragraph shaping, vector flattening, file IO inspector socket (dev + test builds): tree, rects, a11y, source locations, springs, timings, traces, input injection ``` The one boundary that matters is the **command channel between the app side and the render thread**. It carries tree diffs, target layout rects, shaped text runs and spring targets one way, and hits, gesture results, settles and presented-frame ids the other. Three things fall out of making it a real, serializable protocol: - **Animations survive a busy app.** When one value animates, the app side does no work at all: no view re-run, no layout, no diff ([06](research/06-reactivity-animation.md)). - **The iPhone hot-reload path.** In dev, the channel can run over USB: the renderer runs on the phone and the app side runs on the Mac, where subsecond hot-patches it (§5). - **Agents and tests get the same stream.** Recording the channel gives deterministic replay, frame traces and an inspector for free (§6). ## 4. Each layer ### 4.1 Language: Rust Rust is the only option with production text, layout and accessibility crates (Taffy, Parley, HarfRust, fontations, AccessKit), no GC, reach to every target including wasm, and a working hot-patcher (subsecond). Agents write it well; the borrow checker is the main cost, which the state model below is designed around (no `RefCell` re-entry, no borrows held across async). Zig lacks the ecosystem and a dependable incremental patch path on Mach-O; Swift is great on Apple and weak everywhere else; C++ gives up safety and agent reliability for nothing; Mojo isn't a UI language yet ([04 §1](research/04-language-gpu-renderer.md)). Swift is used only for thin host pieces Apple exposes no other way (SwiftUI-only glass morphing, the `RuneView` representable). ### 4.2 GPU API: wgpu everywhere, raw Metal on Apple only where measured wgpu runs on every platform, since the desktop trio ships together. Zed's own move from blade to wgpu in 2026 is the evidence that it's good enough ([04 §2](research/04-language-gpu-renderer.md), [01](research/01-gpui-zed-warp.md)). A raw Metal (`objc2-metal`) backend behind a thin internal trait is a later optimization, added only where measurements show wgpu falls short: precompiled `.metallib` (no shader compile at launch), `IOSurface` zero-copy video, framebuffer fetch for cheap group opacity on Apple silicon, and exact control of `CAMetalLayer` presentation (`presentsWithTransaction`, drawable count). Rejected: hand-written Vulkan/D3D12 (Zed just deleted theirs). ### 4.3 Renderer A typical frame is one render pass. Six primitives, all instanced, all clipped by a GPU clip table that gives rounded clips **and soft gradient edges per side for free**, so "no hard edges" costs nothing extra ([04 §3](research/04-language-gpu-renderer.md)): | Primitive | Does | |---|---| | `UberQuad` | rounded/squircle rects, borders, analytic Gaussian shadows (inner/outer), Oklab gradients with dithering, surface material | | `AtlasSprite` | body text from a greyscale glyph atlas, images, emoji | | `Slug` | big, rotating or scaling text and icons straight from Bézier curves (patent dedicated to the public domain on 2026-03-17; reference shaders MIT/Apache) | | `SparseStrips` | complex vector art via `vello_gpu` (Linebender moved compute Vello to `research/` in 2026) | | `Backdrop` | in-app blur/saturate of what's already drawn (dual Kawase, scissored), with Scrawl's peak-alpha boost for legible blurred text | | `NativeSurface` | zero-copy video and camera frames | Plus: offscreen layers only when needed (group opacity with blur, cached complex subtrees), dirty-rect scissoring for idle-ish frames, linear-light blending, Display P3, and dithering on every gradient and shadow (Kit's GPUI fork (`kitlangton/gpui`) fixes, now partly upstream). **Frame pacing and latency.** `CADisplayLink` with `preferredFrameRateRange` up to 120 while anything animates, zero ticks at rest. Discrete input (key, click) draws immediately instead of waiting for the next tick, with at most two drawables in flight. Animation time is the display link's *target* timestamp, so a late frame still lands on the right pose. `CAMetalDisplayLink` is suspect: one 2026 measurement shows windowed macOS scheduling it 3–5 refreshes ahead ([04 §4](research/04-language-gpu-renderer.md)); spike S3 checks this before we rely on either. ### 4.4 Compositing with native layers (Apple) *Optional now that Rune carries OpenCode's look on every platform; kept for Kit's Mac surfaces (M4).* Rune can't draw Liquid Glass: the shaders that sample behind the window live in the window server. So the Apple shell composes **native underlays and overlays** with Rune's Metal layer: a system glass view sits behind a transparent region of the Metal layer, and its shape is driven by a mask layer that the render thread updates in the same `CATransaction` as the drawable (`presentsWithTransaction`). This is how Scrawl's Metal pill already hosts `NSGlassEffectView`, and the launcher's CA glass recipe is the fallback material backend ([11 §2](research/11-platform-shells.md)). Popovers, HUDs and pills use a fixed, transparent, max-size surface with shape hit-testing, never per-frame window resizes. Two caveats: glass *morphing* between shapes is SwiftUI-only on iOS, and NSViews are main-thread objects. Spike S2 measures whether a glass underlay can track a Rune-animated shape at 120 Hz with the main thread blocked. ### 4.5 Text - **Fonts and shaping:** HarfRust (pure-Rust HarfBuzz port), skrifa/fontations (hinting, variable fonts, COLRv1), fontique (system fonts and fallback), plus SF's tracking tables on Apple. - **Layout:** Parley for bidi, line breaking, rich text and inline boxes, wrapped in GPUI's two-tier cache (shaped runs separate from wrap points), so resizing a container never re-shapes text ([05](research/05-text-ime-a11y-layout.md)). Overflow is a soft fade mask by default, never an ellipsis. - **Rasterizing:** greyscale atlas, 4× horizontal subpixel positioning, and the kitlangton/gpui luminance glyph dilation that fixed "thin text" by matching macOS font smoothing. Text under a scale animation switches to Slug outlines so springs never re-rasterize glyphs every frame. - **Quality bar:** a side-by-side diff against CoreText on the same strings (spike S5). If Rune text doesn't match native on a Retina Mac, nothing else matters. ### 4.6 Text editing and IME Zed's `sum_tree` and rope for storage (O(log n) UTF-8↔UTF-16 offsets, large files). Each platform's real protocol, implemented directly: `NSTextInputClient` (with `doCommandBySelector:` for Kit's key bindings), `UITextInput` plus `UITextInteraction` on iOS (selection handles, loupe, autocorrect, dictation, marked text), `InputConnection` on Android, TSF on Windows, `text-input-v3` on Wayland, and a sliding-window hidden `