Skip to content

feat(terminal): run remote sessions in browser WebAssembly - #2144

Merged
houko merged 2 commits into
mainfrom
feat/terminal-web-1455
Nov 23, 2026
Merged

houko merged 2 commits into
mainfrom
feat/terminal-web-1455

Conversation

@houko

@houko houko commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

A browser terminal can now consume a remote Options.Conn through NSGo’s existing view and input path. The package embeds the pinned libghostty-vt as browser-native WebAssembly, marshals its separate 32-bit memory using validated ABI metadata, and installs typed callbacks for terminal effects, PNG decoding and secure entropy. Local-program requests return the existing remote-session guidance.

The generator reproduces the full-feature freestanding module from an isolated copy of the pinned source, with two scoped graphics/file-media adjustments and linked license notices. Browser apps need no Zig installation, native library or runtime download. English/Chinese public terminal guides and the agent reference describe the app-owned WebSocket byte-stream and resize contracts; HarmonyOS and mini-program hosts remain documented gaps.

Validation on macmini:

  • go tool nsgo check -target all,harmonyos,miniprogram_wechat,miniprogram_qq,miniprogram_alipay,miniprogram_douyin -jobs 2 passed.
  • Native terminal suite: 52 passed; browser terminal suite: 22 passed, including the 3,000-frame randomized mirror regression.
  • Browser VT binding suite: 14 passed, including guest memory growth, encoders, selection/search, PNG limits, clipboard callbacks and prompt-state boolean ABI.
  • TestTerminalBrowserSession passed against a real native PTY over a real WebSocket: actual DOM input, executed command output, ANSI pixels, alternate-screen restoration and close. Captured screenshots were inspected.
  • Selected-target generator rebuild passed from the stock pinned checkout; the generated module’s SHA-256 is c8c95f1183f2416d18b37e50a1e7c1a9a0aeea0122f72a5e7c2c6e2e623dcc1d.
  • Layering and skill-reference tests, 11 changelog tests, and go tool nsgo build -target web examples/gallery passed. The web release’s third-party notices include Ghostty, Zig and Wuffs.

Closes #1455.

@github-actions github-actions Bot added enhancement New feature or request size/XL documentation Improvements or additions to documentation base tsx cli labels Nov 22, 2026
Comment thread tools/libghostty/wasm.go
extractErr = fmt.Errorf("non-local source path %q", h.Name)
break
}
path := filepath.Join(dir, filepath.FromSlash(h.Name))
Comment thread tools/libghostty/wasm.go
if !filepath.IsLocal(filepath.Join(filepath.Dir(h.Name), h.Linkname)) {
extractErr = fmt.Errorf("non-local source link %q", h.Linkname)
} else {
extractErr = os.Symlink(h.Linkname, path)
@houko

houko commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Checked that every guest export has an explicit argument schema, that struct marshalling goes through the guest manifest plus abi64.json (already covering GhosttyTerminalSemanticPrompt and the CURSOR_AT_PROMPT bool), that callbacks use typed trampolines, and that local-program requests in a browser keep returning the remote-session guidance.

Rebased onto main, which merged #2147 (OSC 133 prompts, Kitty images) and #2138 (the -target generator flag) in the meantime. Pushed one follow-up commit:

  • feat(terminal): add search images and prompt navigation #2147's semantic-prompt callback used the native-only newCallback(fn) and mem; it now uses newCallback("viii", ...) with foreignValue[semanticPrompt], semanticPrompt has its foreignType, and optSemanticPrompt is in the ghostty_terminal_set callback allowlist. Without this the package did not compile.
  • TestViewOpensPaths (from Terminal: Paths as links #1457) now skips on js like TestFindPath, since browsers have no local paths.
  • Merged the generator conflicts (wasm target plus main's selection test), the terminal guides (main's page plus this PR's "In a browser" section, en and zh), the architecture page and the roadmap (Terminal: The web #1455 row removed), and unwrapped the hard-wrapped comments.

vet passes for linux, darwin, windows and js/wasm; under js/wasm (Node) the vt suite (including both browser ABI tests) and the base/terminal suite pass, TestOptionClickPrompt included; native -race tests for base/terminal, tsx/terminal, tools/libghostty and the cmd/nsgo terminal tests pass. The real-browser TestTerminalBrowserSession was not rerun.

@houko
houko force-pushed the feat/terminal-web-1455 branch from bd20224 to 02cd2f2 Compare November 23, 2026 00:37
@houko
houko force-pushed the feat/terminal-web-1455 branch from 02cd2f2 to 1cfb39d Compare November 23, 2026 00:43
@houko

houko commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased again over #1456 (mouse reports) and #1458 (clipboard protocols); docs conflicts only. js/wasm vet and the js/wasm vt and base/terminal suites still pass under Node.

@houko
houko merged commit e9ec82d into main Nov 23, 2026
18 of 19 checks passed
@houko
houko deleted the feat/terminal-web-1455 branch November 23, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base cli documentation Improvements or additions to documentation enhancement New feature or request size/XL tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal: The web

2 participants