Lokyr
Documentation

Architecture

On this page

This document describes Lokyr as a whole. Each subsystem has its own document with the details.

Principles

  1. Mechanism in the core, policy in plugins. The kernel provides data models and fast services. Plugins decide what is shown and how people interact with it.
  2. One API for every plugin. First-party plugins use the same interfaces as third-party ones, through a Rust front end instead of a Luau one. If one of our own features cannot be written with the public SDK, the SDK is what's missing something.
  3. No wasted work. When nothing changes there are no frames, timers or wakeups. Anything that is not visible or not installed costs nothing, and that includes the Luau runtime.
  4. Native where it matters, our own where we need control. Windows, menus, IME and accessibility are native on each OS. The chrome and the rendering are ours, and identical everywhere.
  5. No networking code of the app's own. Downloading and installing is Sleip's job. The plugins' network goes through the app, which checks it, to Sleip's helper, so that no response from the network is parsed in the process that sees what is typed; Sparkle's updater is the app's one network client. The MCP server speaks over stdio, through the IPC socket.
  6. Budgets are requirements. Timings and memory have numeric targets that CI checks (PERFORMANCE.md).

Layers

                ┌──────────── sleip (separate CLI) ────────────┐
                │ resolve · download · verify · install · publish │◀──▶ online registry
                └───────────────────────┬─────────────────────────┘
                                        │ writes to disk: store + plugins.lock
┌───────────────────────────────────────▼────────── lokyr (app) ────────────────────────────┐
│ First-party plugins (static)            │ Third-party plugins (Luau, sandboxed)          │
│ tabs · splits · search · links ·        │ read from disk, activated only when needed     │
│ core-actions · palette                  │                                                │
├─────────────────────────────────────────┴────────────────────────────────────────────────┤
│ plugin-sdk ── HostApi messages (native) │  plugin-host-luau (Luau VMs → same messages)  │
├──────────────────────────────────────────────────────────────────────────────────────────┤
│ KERNEL: workspace + layout tree · commands · keymap · event bus · config                 │
│         services: search · decorations · triggers                                        │
├─────────────────────────┬──────────────────────────────┬─────────────────────────────────┤
│ TERMINAL                │ UI ENGINE                    │ PER-OS BACKENDS (behind traits) │
│ vt-core · pty ·         │ ui-core (view tree, taffy,   │ platform: macos | wayland | x11 │
│ session · search        │ AccessKit) · text-core       │ render: metal | gl              │
│                         │ · render-core                │ font: coretext | freetype       │
└─────────────────────────┴──────────────────────────────┴─────────────────────────────────┘
LayerCratesResponsibilities
Terminalvt-core, pty, session, searchParsing, state and grid; child processes; per-pane I/O; search engine. No UI
KernelkernelData model, commands, keymap, events, config, services, native plugin host, window composition
UI engineui-core, text-core, render-coreView tree, layout, widgets, text, display list. Platform-independent
Per-OS backendsplatform-*, render-*, font-*Windows and events, GPU, fonts. One crate per OS and engine, behind the traits of the *-core crates
Pluginsplugin-sdk, plugin-host-luau, plugins/*API and Rust SDK, Luau host, first-party plugins
Packagespkg-model, themes, sleip/*, registry/*Shared formats, themes' format, package manager, registry

Kernel data model

Workspace
└── Window (id, screen, size, appearance)
    └── Tab (id, title, color, active pane, zoomed pane)
        └── LayoutTree
            ├── Split { direction, ratio, first, second }
            └── Leaf(PaneId)
                └── Pane (id, profile, cwd) ──▶ Session (pty + process + VT state)

Threads and data flow

ThreadDoesNever does
Main (OS event loop)Input, kernel, native plugins, UI layout, snapshot, shaping, frame submissionBlock on I/O or on a Luau plugin
Reader, one per paneread from the PTY, into a ring of four buffers of 64 KiB, ahead of the parseParse, or wait for the main thread
I/O, one per paneParsing the reader's batches, grid updates; ending synchronized updates at their deadlineWait for the main thread, or for the program to read its input
Writer, one per paneWriting input and replies to the PTYWait for the main thread
Glyphs, three beside the main thread, only while a frame draws glyphs that the atlas lacksRasterizing a frame's new glyphs with CoreText, 2 ms of them at mostOutlive the frame, or touch the atlas
Drawing warm-up, once, as the app launchesMaking the GPU's pipelines and the font, and letting them go, while AppKit launches, so that the app's own take nearly nothingOutlive the launch
Font warm-up, once, after the first frameReadying the system's font fallback and its CJK and emoji faces, about 20 msHold anything of the app's; a frame's first lookup of a CJK face, within those 20 ms, can wait for CoreText's cascade, which the thread fills
Plugin executorCalls into third-party plugins, with a deadline per call; its watchdog runs only while a plugin executesSit on the output path
Plugin workers, one per native plugin that asks for one (F3)Every call of that plugin, its renders too, by messages, as the executor'sHold a lock of the kernel's, or a pane's: a read of much text runs on a host worker
WorkersSearch, reflow of very large scrollbacksHold the grid lock for long

From program output to the screen

  1. The reader thread reads the PTY into a batch of at most 64 KiB, while the I/O thread parses the one before it, so that the program never waits for the parse. A macOS terminal queues about 1 KiB of output, which a program that writes more fills again within microseconds of each read: a reader that parsed between its reads kept the program waiting through each parse, and waited itself through each refill, a KiB for two wakeups. Once a batch holds a full queue, the reader bridges the refills, with up to 16 reads that do not wait, then waits of 1 ms while the I/O thread has a batch to parse, for about 3 ms in all, so that a batch holds many refills; less than a full queue, as a shell's echo, goes to the I/O thread at once, and so does what the reader holds as soon as the I/O thread runs out of batches. Past four batches, the reader stops, and the terminal's queue holds the program back.
  2. The I/O thread parses a batch while holding the pane's grid lock, then releases the lock fairly so the renderer never starves.
  3. It marks the rows that changed and, unless it already has, wakes the main thread (a CFRunLoopSource on macOS, an eventfd on Linux), marking its pane as woken: the main thread looks at the woken panes alone, and asks for their windows' frames alone. A bell or a terminal's event wakes it too, once a frame's time at most: the main thread takes what a pane told no more often, and a timer brings the turn of one that told within it, so that a stream of bells wakes it 60 times a second, not 100 000.
  4. On the display-link tick, the main thread takes the lock, copies only the visible rows that changed (8-byte cells plus the styles they use) and releases it. A frame whose display list is the one that the window shows already presents nothing. The copy carries the program's input modes, its keyboard's flags and the alternate screen, which the frame reads from it, and a key's contexts too, so that a frame takes a pane's lock once, and a key once more to write; a paste, the mouse and a selection that the app just changed read the terminal under the lock.
  5. Shaping, display-list construction and GPU command encoding then run without the lock. The grid's layout collects the glyphs that the atlas lacks rather than drawing each as it comes: CoreText draws them together, on the main thread and three others, for 2 ms at most, and the layout is done again with them. The faces of characters that no frame met before, which the system's fallback gives, are looked up while the frame has spent less than 2 ms on them: a lookup that started goes on. The icons of the private use areas that the configured font lacks take the symbols' font that the binary holds, Symbols Nerd Font Mono, before the system's fallback, which searches every installed font for them, 22 to 29 ms each. What is left, of a screen of hundreds of new glyphs, shows as empty cells, and the frames after, which the frame asks for, draw it: a page of new Chinese shows whole in about three frames, where the first frame of it took about 25 ms, and a 4K screen of all-new glyphs in about 0.2 s, where it took 300. After the first frame, a thread readies the fallback, whose first looks take over a millisecond each, and the CJK and emoji faces: up to about 4 MB of the footprint, most of which a shell's prompt of symbols that the font lacks takes anyway, 1.1 MB more as measured.
  6. If the pane has synchronized output (mode 2026) enabled, the frame waits for the update to finish or for a timeout.

From a key press to the program

  1. The native event reaches the main thread. The IME gets it first (composition text, candidates).
  2. The keymap resolves the key combination in the current context (when). If a binding matches, the command runs. Otherwise:
  3. The vt-core encoder translates the key according to the pane's modes (legacy xterm or kitty keyboard) and queues it for the pane's writer thread, which writes it to the PTY.
  4. If the terminal was idle, the next frame is drawn immediately instead of waiting for the display link. This is the lowest-latency path.

Frame pacing

macOS

Linux (F7): the same scheme, using Wayland frame callbacks (wl_surface.frame) or the Present extension on X11, and wp_presentation for measurement.

Workspace layout

lokyr/
├── Cargo.toml · justfile · deny.toml · rust-toolchain.toml · .github/workflows/
├── crates/
│   ├── vt-core/           parser, state, paged grid, scrollback, reflow, input encoding (pure)
│   ├── pty/               fork+exec, resize, the shells' integration's scripts and their injection; no RawFd in the API (ConPTY later)
│   ├── session/           pty + vt-core + I/O thread, snapshots for the renderer
│   ├── search/            literal and regex search over the grid
│   ├── kernel/            modules: workspace and layout tree, commands, keymap, events, config, texts (l10n), services, shell integration's marks; serves the HostApi's messages
│   ├── app-core/          the window's controller: windows' and panes' state, input's routing, gestures, confirmations, layout geometry, frame composition; generic over a `Backend`, its GPU's Renderer and Surface and its FontBackend; tested with the fake platform and a fake drawing
│   ├── ui-core/           view tree, layout (taffy), widgets (IME text field, lists, menus), surfaces and floating panels, the chrome's regions, hit testing, AccessKit, display list
│   ├── text-core/         FontBackend trait (discovery, fallback, shaping, rasterization), shaping cache, glyph atlas, box-drawing sprites, UCD tables, the symbols' font
│   ├── render-core/       Renderer and Surface traits, display-list types, shaders
│   ├── platform-core/     traits: app, windows, quick windows, global keys, events, IME, clipboard, menus, notifications, appearance, targets that open; the fake platform and the conformance suite
│   ├── platform-macos/    AppKit via objc2 (NSWindow, NSPanel, NSView + CAMetalLayer, NSTextInputClient, NSMenu), Carbon's hot keys
│   ├── platform-wayland/  (F7) smithay-client-toolkit + calloop, our own CSD
│   ├── platform-x11/      (F7) x11rb + xkbcommon + xim
│   ├── render-metal/      objc2-metal
│   ├── render-gl/         (F7) glow + khronos-egl (GL 3.3 / GLES 3)
│   ├── font-coretext/     objc2-core-text (discovery, fallback, shaping, rasterization)
│   ├── font-freetype/     (F7) fontconfig + freetype-rs + harfrust
│   ├── plugin-sdk/        the plugin API (the HostApi's messages and their types, the view tree's data) and its Rust front end; no internal dependencies
│   ├── plugin-host-luau/  Luau host (mlua): one VM per plugin, the Luau front end, capabilities, limits (behind a feature); `luau/`: the API's types, `lokyr.d.luau`, and the template of `sleip new`
│   ├── pkg-model/         plugin.toml, plugins.toml/.lock, the store, the archive, index format, dist (shared by app, sleip, registry)
│   ├── themes/            the themes' native format, its parser and writer, iTerm2's .itermcolors, a theme's resolution (shared by the kernel and sleip)
│   └── app/               the `lokyr` binary: `main`, the backends for the target, their wiring + distribution
├── plugins/               first-party: depend ONLY on plugin-sdk
│   ├── core-actions/ links/ tabs/ splits/ search/ quick-terminal/
│   ├── keymap-macos/ command-palette/ progress/ command-header/ blocks/ copy-mode/
│   ├── plugin-manager/ (F4) automation/ (F5b) keymap-linux/ (F7)
│   └── (F5) blocks/ tmux-cc/ triggers/ images/ …
├── dist/                  default.toml, minimal.toml
├── sleip/              cli/ (`sleip` binary) · resolver/ (pubgrub) · index/ (sparse index, verification) · analyzer/ (Luau's type checker, of Luau's vendored `Analysis`)
├── registry/              registry-server (v1) + index specification
├── tools/                 replay/ (`lokyr-replay`, `lokyr-record`) · differential/ (the VT core against `alacritty_terminal`) · bench/ · ui-gallery/ (`ui-core`'s widgets, to check by hand) · xtask/ (bundle, signing, gen-dist, UCD tables, terminfo)
├── fuzz/                  cargo-fuzz: parser, terminal, differential (against `alacritty_terminal`); later .itermcolors, manifest, archives
└── docs/                  this documentation (later an mdBook)

Crate dependencies

app ─┬─▶ app-core ─▶ kernel
     ├─▶ kernel ─┬─▶ session ─┬─▶ vt-core
     │           │            └─▶ pty
     │           ├─▶ search ───▶ vt-core
     │           ├─▶ ui-core ──┬─▶ text-core
     │           │             ├─▶ render-core
     │           │             └─▶ plugin-sdk          (the view tree's types, which it keeps)
     │           ├─▶ plugin-sdk                      (the kernel serves the HostApi's messages)
     │           ├─▶ pkg-model
     │           └─▶ themes ──▶ plugin-sdk          (the themes' format, which sleip reads too)
     ├─▶ platform-{macos|wayland|x11} ─▶ platform-core
     ├─▶ render-{metal|gl} ─▶ render-core
     ├─▶ font-{coretext|freetype} ─▶ text-core
     ├─▶ plugin-host-luau ─▶ plugin-sdk              (feature `luau-plugins`)
     └─▶ plugins/* ─▶ plugin-sdk                     (selected by dist/*.toml)

sleip/* ─▶ pkg-model, themes   registry/* ─▶ pkg-model

Dependency rules

RuleWhyEnforced by
vt-core and search do not depend on UI, platform or pluginsHeadless tests, fuzzing, reusextask check-deps
plugin-sdk depends on no other workspace crateThe SDK must be publishable and usable on its ownxtask check-deps
Only app and app-core depend on kernel, and xtask, which converts the themes that the bundle holds with the kernel's importer and never shipsPlugins must not be able to bypass the SDKcargo-deny (wrappers) and xtask check-deps
plugins/* depend only on plugin-sdk, plus a whitelist of utility cratesProves the public API is sufficientxtask check-deps
First-party plugins use #![forbid(unsafe_code)]; clippy disallowed-methods forbids threads, blocking I/O and clocksThey follow the same rules as Luau pluginsclippy in CI
Luau (mlua) only in plugin-host-luau, and Luau's analyzer only in sleip-analyzer, a crate of Sleip's that the app never links, which links the libraries of Luau that mlua builds, so that a binary holds one LuauThe C++ runtime stays behind one crate and one feature, and the app holds no analyzercargo-deny (wrappers)
HTTP/TLS (hyper, reqwest, rustls, …) only in sleip/*No networking code of the app's own; Sparkle's updater, a framework, is its one network clientcargo-deny (bans + wrappers)
No async runtime (tokio, async-std, …) in the appFewer threads, less memory, fewer dependenciescargo-deny
Only app picks the backends, via cfg(target_os)Core crates stay portablextask check-deps (backends-only-in-app)
Platform-independent crates (vt-core, pty, session, search, kernel, *-core) build and pass their tests on Linux, and expose no macOS typesKeeps Linux possible after 1.0Linux CI job, and xtask check-deps on Linux's dependencies

The platform, render and font traits are deliberately thin. They describe what the macOS backend needs rather than a lowest common denominator, and the Linux backends will extend them in F7.

The platform tells facts and does what it is asked; the decisions are app-core's, once for every platform. A target that opens, a link's or a path's, is resolved by the platform, Platform::resolve_target: what it is, a URL, a directory, a file or a program that would run rather than open, and the file that its links and the system's aliases lead to; app-core decides whether it opens, shows in the file manager or asks first, as [links] says, a program never opening, and resolves it again once its question is answered. The platform's open refuses a program too, and opens what was resolved. A conformance suite, platform-core's conformance::check, behind its feature conformance, checks what every platform tells alike, the targets and the windows that are not there; the fake passes it in platform-core's tests and the macOS backend in an integration test of its own, and the Linux backends will in F7.

Main libraries

Versions and maturity must be rechecked when coding starts.

SubsystemCratesNotes
macOSobjc2, objc2-app-kit, objc2-metal, objc2-quartz-core, objc2-core-text, objc2-user-notificationsThe metal crate is deprecated. objc2 changes often, and AccessKit's macOS adapter can trail it: it then builds on its own versions of objc2, in one module of platform-macos that hands it the view as a raw pointer, until it catches up
Wayland / X11 (F7)smithay-client-toolkit + calloop; x11rb + xkbcommon + xim
GPU on Linux (F7)glow + khronos-egl
TextCoreText on macOS (discovery, fallback, shaping, rasterization); harfrust + fontconfig + freetype-rs on Linux (F7)HarfRust is young: benchmark it against harfbuzz-sys before adopting it
Corememchr, regex-automata, lz4_flex, unicode-normalization. Scans like the parser's fast path use arithmetic on 64-bit words (SWAR) in safe code; core::arch only where a measurement shows it pays (std::simd is not stable)unicode-normalization may trail the pinned Unicode version: 17 while the tables are 18
UItaffy, accesskit
Formats and configplist, toml_edit (errors with line and column), serde, ciborium (CBOR), notify
Pluginsmlua with the luau and luau-jit features, from vendored sourcesLuau ships every week or two; pin it and upgrade deliberately
Sleippubgrub, reqwest + rustls, ed25519-dalek, zstd, tared25519 signatures before Sigstore
Tests and benchmarksinsta, proptest, cargo-fuzz, criterion, gungraun (formerly iai-callgrind)

Conventions

On-disk paths

WhatmacOSLinux (F7)
Config (config.toml, plugins.toml, plugins.lock, permissions.toml, themes/)~/.config/lokyr/ (or $XDG_CONFIG_HOME/lokyr/ if set)$XDG_CONFIG_HOME/lokyr/
Installed packages~/Library/Application Support/lokyr/store/$XDG_DATA_HOME/lokyr/store/
Caches (fonts, compiled plugins)~/Library/Caches/lokyr/$XDG_CACHE_HOME/lokyr/
State (the last window's directory, the windows kept as Lokyr quits; later, search history)~/Library/Application Support/lokyr/state/$XDG_STATE_HOME/lokyr/
IPC socket$TMPDIR/lokyr-<uid>/$XDG_RUNTIME_DIR/lokyr/

On macOS too the config lives in ~/.config, so it can be versioned with dotfiles, as Ghostty, Alacritty and kitty do.

LOKYR_DATA_HOME, where it names an absolute folder, holds the state and the installed packages in its state/ and store/, in place of the places above, for Lokyr and Sleip alike: a measurement or a test keeps them apart from the user's own.

Glossary

TermMeaning
KernelThe core of the app. It owns the data model (windows, tabs, layouts, panes, sessions), commands, keymap, events, config and fast services. It decides nothing about how things look
First-party pluginOne of our own plugins, statically linked into the binary. It uses only the public SDK
Third-party pluginA Luau plugin loaded from disk. It runs in its own sandboxed VM, with explicit capabilities
DistributionThe list of first-party plugins compiled into the app (dist/*.toml)
ChromeEverything visible besides the terminal text: tab bar, dividers, find bar, palette
PaneAn area that shows one terminal. A tab holds one or more panes, arranged by the layout tree
SessionThe PTY, the child process and the VT state of a pane
PinA stable reference to a position in the grid. It stays valid across scrolling and reflow
CapabilityA permission that a third-party plugin must declare and that must be granted to it (e.g. terminal-read)
SlotA place in the UI where a plugin can render a view tree (e.g. tab-bar)
HostApiThe plugin API: the requests, responses and events of plugin-sdk's message module, which the kernel serves through host::Host. Both front ends, Rust's Cx and Luau's bindings, make its requests