From 3f61dd4db8b3fb936035dba921c16c72c4a3a7c3 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 28 Nov 2026 10:36:17 +0100 Subject: [PATCH] feat: render the terminal with ghostty-web ghostty-web runs Ghostty's VT parser as WebAssembly behind an xterm-compatible API. The component keeps its lifecycle; the imports and the WASM bootstrap change. The emulator imports on demand, so the 624 KB chunk loads only when the terminal pane opens. The CSP needs wasm-unsafe-eval for WebAssembly compilation and data: in connect-src for the inlined module the library fetches. The terminal renders to a canvas, so the xterm stylesheet and FitAddon package are gone. --- README.md | 2 +- specs/rhema-together.md | 13 +++--- src/api/mod.rs | 4 +- web/app/assets/css/main.css | 8 +++- web/app/components/TerminalPane.vue | 62 +++++++++++++++-------------- web/package.json | 3 +- web/pnpm-lock.yaml | 24 ++++------- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 7bf43ec..2a2476c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The room is a browser workspace: - **Files** pane: the tree, a read-only file view, `git status`, and `git diff`. - **Terminal**: a real PTY in the sandbox, same target and key as the - agent, rendered with xterm.js. + agent, rendered with ghostty-web (Ghostty's VT parser in WebAssembly). - **Presence**: who is online, who is typing. Accounts own rooms, plans, and providers. Friends join by a single-use diff --git a/specs/rhema-together.md b/specs/rhema-together.md index d084963..e5991d2 100644 --- a/specs/rhema-together.md +++ b/specs/rhema-together.md @@ -386,11 +386,12 @@ when the shell ends. There is no server-side ring buffer; a reconnect starts a fresh shell. Closing the socket closes the channel, which hangs up the remote shell. -The emulator is xterm.js in the browser. The server parses no escape -sequences. A server-side libghostty-vt is a later option: it gives screen -snapshots on reconnect and a way to let the model read the terminal, and -it costs an FFI crate that allows `unsafe`. That crate would live in this -project, not in the framework. +The emulator is ghostty-web in the browser, which runs Ghostty's VT +parser as WebAssembly behind an xterm.js-compatible API. The server +parses no escape sequences. A server-side libghostty-vt is a later +option: it gives screen snapshots on reconnect and a way to let the +model read the terminal, and it costs an FFI crate that allows `unsafe`. +That crate would live in this project, not in the framework. ### Editor (read-only) @@ -664,7 +665,7 @@ This repository, as committed: - SSE event feed with durable replay (`?since=`) and transient deltas; a WS presence socket with online and typing state. - Read-only files tree and file view, `git status` and `git diff`. -- xterm.js terminal over a WebSocket PTY. +- ghostty-web terminal over a WebSocket PTY. - Preview proxy over ssh `direct-tcpip`, signed wildcard hosts, no rewriting. - No approval prompts: the sandbox is the boundary, so `AllowAll`. diff --git a/src/api/mod.rs b/src/api/mod.rs index fe5bc4d..20968dc 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -171,9 +171,11 @@ async fn headers(State(state): State, request: Request, next: Next) -> R Some(source) => format!("'self' {source}"), None => "'self'".to_owned(), }; + // ghostty-web compiles its inlined WASM in the browser. Keep the + // narrow wasm-unsafe-eval allowance and let it fetch the data: module. let csp = format!( "default-src 'self'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; \ - script-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss:; frame-src {frame_src}; \ + script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; connect-src 'self' data: ws: wss:; frame-src {frame_src}; \ frame-ancestors 'self'; base-uri 'self'; form-action 'self'" ); if let Ok(value) = HeaderValue::from_str(&csp) { diff --git a/web/app/assets/css/main.css b/web/app/assets/css/main.css index 060589c..4de70d9 100644 --- a/web/app/assets/css/main.css +++ b/web/app/assets/css/main.css @@ -1387,8 +1387,12 @@ button { overflow: hidden; } -.terminal-host .xterm { - height: 100%; +.terminal-host:focus { + outline: none; +} + +.terminal-host canvas { + display: block; } .preview-wrap { diff --git a/web/app/components/TerminalPane.vue b/web/app/components/TerminalPane.vue index 4611372..dff3d0f 100644 --- a/web/app/components/TerminalPane.vue +++ b/web/app/components/TerminalPane.vue @@ -1,8 +1,6 @@