Repository navigation
feat(web): render terminals with libghostty-vt - #4860
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review Diff is too large for automated approval analysis. A human reviewer should evaluate this PR. You can customize Macroscope's approvability policy. Learn more. |
9a3b61d to
92bd4ec
Compare
Closes #1310.
What changed
Replaces the web terminal's xterm.js parser and renderer with a T3-owned browser adapter over the official
libghostty-vtC ABI.The implementation stays deliberately close to mobile:
A 112-byte companion WASM trampoline connects Ghostty's official
write_ptycallback to JavaScript through Ghostty's exported function table. This preserves terminal-generated replies without depending on Ghostty's unstable Zig API. Captured-session restore temporarily detaches that callback so historical device queries cannot emit replies into the current shell.The reproducible build script reads mobile's canonical
libghostty-vt/VERSION, checks out that exact upstream revision, and vendors the WASM artifact, license, and version. The production build emits separate cacheable assets:ghostty-vt.wasm: 630.9 KB raw / 187.9 KB gzipghostty-write-pty.wasm: 112 bytesThis is an independent implementation of the worthwhile idea behind #3820, avoiding the lifecycle and input limitations of the third-party
ghostty-webwrapper.Expected benefits
Review fixes and reliability pass
All review findings to date are fixed and their threads resolved:
A review-driven polish pass hardened the rest of the adapter:
deltaModewith fractional accumulation, and wheel motion on the alternate screen becomes arrow keys (honoring DECCKM) so vim/less scroll without mouse trackingkeyCode229 composition keydown is guardedValidation
mainCSI > 3 uimages
06-ghostty-terminal-demo.webm
Feedback on the adapter boundary, checked-in artifacts, callback trampoline, and Canvas 2D as the initial renderer would be especially useful.
Implemented by GPT-5.6-sol through the Codex harness in T3 Code, with review fixes and the reliability pass by Claude Fable 5 through Claude Code.
Note
Replace xterm.js with libghostty-vt WebAssembly for web terminal rendering
GhosttyRuntimeto load and interact with the WASM module,GhosttyTerminalCoreto manage terminal state and I/O, andrenderGhosttySnapshotto paint dirty rows to a canvas with cursor and selection support.ghostty-vt.wasmandghostty-write-pty.wasmfrom the pinned Ghostty revision.TerminalViewportto useGhosttyTerminalSurfacefor resize, selection, copy, link activation, and exit handling.'wasm-unsafe-eval'inscript-srcto allow WASM execution.Macroscope summarized 0054869.
Note
High Risk
Large renderer swap with async WASM startup, new CSP for WASM, and deep input/selection/mouse behavior; PTY transport is unchanged but terminal UX regressions are the main risk.
Overview
Replaces xterm.js in the web app with a Canvas 2D stack built on vendored
libghostty-vtWebAssembly, aligned with the Android terminal’s Ghostty revision and C ABI.Adds a reproducible Zig build (
build-libghostty-wasm.sh) forghostty-vt.wasmand a tiny PTY callback trampoline, plus modules for runtime loading, terminal core, rendering, and browser input/selection/IME/links.ThreadTerminalDrawernow mountsGhosttyTerminalSurfaceasynchronously (theme, resize, selection, exit handling) and drops xterm dependencies and CSS.Desktop CSP gains
wasm-unsafe-evalfor WASM.ChatViewwidens terminal ID allocation so drawer and panel terminals cannot collide on one PTY. Third-party notices document the shared Ghostty pin.Reviewed by Cursor Bugbot for commit 0b3c1fc. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Replace xterm.js with libghostty-vt WebAssembly terminal renderer in the web app
GhosttyTerminalSurfaceinstead of xterm.js, with async creation,onResize-driven PTY sizing, and theme updates viasetTheme.@xterm/xtermand@xterm/addon-fitdependencies; adds a build script that downloads Zig and compilesghostty-vt.wasmandghostty-write-pty.wasmfrom the same pinned Ghostty revision used by the mobile app.'wasm-unsafe-eval'to the desktop Electron Content-Security-Policy to allow WASM execution.ChatViewto use the union of all known terminal ID sets when creating or splitting terminals.'wasm-unsafe-eval'in CSP; the custom scrollbar and canvas cursor replace all previous xterm-derived styles.Macroscope summarized 0b3c1fc.