Architecture
The Engine
TerminalCore — Pure Swift, Zero UI Dependencies
The engine is a standalone module the SwiftUI app, the test suite, and headless tools all drive identically — the factoring you'd want if the engine had to outlive any one UI. The parser implements the canonical DEC/xterm state machine: CSI/OSC/ESC dispatch, CAN/SUB aborts, ESC interrupts, two-byte ST terminators, and incremental UTF-8 decoding that stays correct across arbitrary chunk boundaries.
Interpreter & Screen Model
SGR in 16-color, 256-color, and truecolor; primary and alternate screens (mode 1049); DEC private modes; DSR/DA responses; OSC titles. The grid models DECSTBM scroll margins, scrollback, and reflow-free resize in all four directions.
Correctness Details
Deferred Wrap, Done Right
Printing in the last column sets a pending-wrap flag instead of moving the cursor; explicit motion clears it. This is the detail that separates emulators that run vim correctly from ones that almost do.
East-Asian Display Width
CJK ideographs, kana, fullwidth forms, and emoji occupy two cells (leading cell + spacer); combining marks and zero-width joiners fuse into the preceding cell. Get this wrong and the cursor drifts the moment someone types 日本語.
Mouse Reporting
Modes 1000/1002/1003 with both X10 and SGR encodings — enough for htop, tmux, and modern TUIs to behave natively.
Process & PTY
posix_spawn over fork
Forking a multithreaded GUI process to do setup work is undefined-behavior roulette. The PTY child is created with posix_spawn + POSIX_SPAWN_SETSID and file actions: controlling-tty acquisition, dispatch-source I/O, and TIOCSWINSZ resize propagation. A dedicated hardening pass made teardown race-free — children are reaped, writes are never dropped.
Performance
~5.6 → ~44 MB/s — an 8× Win, Measured
Two throughput benchmarks live in the test suite and feed 8 MB through the full pipeline. A printable-run fast path batches runs of printable ASCII into the grid with one copy-on-write check instead of one per cell. Critically, it's an opt-in hook: the per-character action stream the tests assert against is unchanged, so every existing interpreter test re-runs through the fast path as a free equivalence check. Optimisation with a built-in proof it didn't change behavior.
Intelligence Layer
PromptKit — Provider-Abstracted AI
The ⌘K assistant is a separate module behind a provider interface: a local model served via MLX and remote providers are interchangeable. The two data boundaries between terminal content and the assistant are explicitly hardened — what the model sees, and what it's allowed to put back, are both controlled.
Hardening
Untrusted Input as a First-Class Threat
A terminal parses attacker-controllable bytes by design. Every untrusted escape-sequence input is explicitly bounded, with flood tests in the suite to prove it — oversized OSC payloads, runaway parameter lists, and malformed sequences degrade gracefully instead of allocating unbounded memory.
Quality & Delivery
151 Tests, One Engine
- Parser: chunk-split UTF-8, OSC termination, aborts
- Interpreter: SGR, alt-screen round-trips, scroll regions
- Grid: deferred wrap, scrollback, 4-direction resize
- PTY integration, selection, blocks, mouse, flood cases
Shipping Discipline
- Throughput benchmarks keep perf claims honest
- CI with universal (arm64 + x86_64) builds
- Version stamping, LICENSE, credited sources