Explore browser-as-terminal-shell with localhost helper (protocol-handler bootstrap) #3

Open
opened 2026-04-24 17:33:16 -07:00 by nelsong6 · 0 comments
nelsong6 commented 2026-04-24 17:33:16 -07:00 (Migrated from github.com)

Idea

Stop fighting the terminal-vs-browser split. Run the whole UI in the browser and let a small native helper handle the parts only an OS process can do (PTYs, fs, spawn). Use a custom protocol handler (fzt:// or similar) as the bootstrap/trust seam, not the data channel.

Shape

  1. User installs the helper once. Helper registers fzt:// as a protocol handler.
  2. Browser page (could be hosted on fzt.romaine.life, a PWA, or localhost) is the entire UI.
  3. To start a session, the page fires fzt://spawn?port=<ephemeral>&token=<nonce>.
    • First time: OS prompts "Always allow this site to open fzt?" — user ticks always.
    • After that: helper launches silently with the args.
  4. Helper binds ws://127.0.0.1:<port> with the matching token, spawns a PTY, streams bytes both ways.
  5. Browser connects WebSocket → renders xterm.js (or a custom canvas renderer reusing the sixel/ambience pipeline).

Protocol handler solves "how does a web page start a local process without an installer prompt every time." WebSocket solves the actual stream. Pure one-shot (no return channel) doesn't work — a terminal needs duplex.

Why this might be better than the current path

  • Drops the "real terminal app" problem entirely (no Win32 console fights, no ConPTY capture quirks, no terminal emulator compatibility matrix).
  • The browser is already the best rendering surface we have — fonts, GPU compositing, CSS, ambience canvas overlays all just work.
  • Multiple "terminals" = multiple tabs. Session persistence = whatever the helper remembers.
  • Reuses fzt-showcase / my-homepage rendering work — <canvas data-ambience> behind the shell becomes free.

Risks / open questions

  • Auth. Any tab on the machine can hit 127.0.0.1:<port>. Token-in-URL is fine for first connect; need to think about token rotation, origin pinning (Origin header check on WS upgrade), and what happens if the user has the page open in two browsers.
  • Helper distribution. One more thing to install. Tauri / a single signed binary is probably the right shipping vehicle so it's not "download a Go binary and trust me."
  • Protocol handler UX across OSes. Behaviour differs on Windows / macOS / Linux; the "always allow" affordance isn't uniform. Worth a small spike before committing.
  • Relationship to fzt-terminal and the existing terminal/ ambience integration. If this lands, the sixel renderer in ambience/terminal becomes lower priority — its open issues (#11–#15) might just get sidestepped rather than fixed.
  • Offline / no-network story. If the UI is hosted, what happens when the user is offline? Probably needs to be a PWA or shipped inside the helper.

Next step

Spike: tiny Go helper that registers fzt://, accepts fzt://spawn?port=&token=, opens a localhost WS, runs cmd.exe / pwsh through a PTY. Browser side: xterm.js page that fires the URL and connects. Goal is "type ls in the browser, see output" — nothing more. Decide from there whether to keep going or fold back into the terminal-native path.

## Idea Stop fighting the terminal-vs-browser split. Run the whole UI in the browser and let a small native helper handle the parts only an OS process can do (PTYs, fs, spawn). Use a custom protocol handler (`fzt://` or similar) as the **bootstrap/trust seam**, not the data channel. ## Shape 1. User installs the helper once. Helper registers `fzt://` as a protocol handler. 2. Browser page (could be hosted on `fzt.romaine.life`, a PWA, or `localhost`) is the entire UI. 3. To start a session, the page fires `fzt://spawn?port=<ephemeral>&token=<nonce>`. - First time: OS prompts "Always allow this site to open fzt?" — user ticks always. - After that: helper launches silently with the args. 4. Helper binds `ws://127.0.0.1:<port>` with the matching token, spawns a PTY, streams bytes both ways. 5. Browser connects WebSocket → renders xterm.js (or a custom canvas renderer reusing the sixel/ambience pipeline). Protocol handler solves "how does a web page start a local process without an installer prompt every time." WebSocket solves the actual stream. Pure one-shot (no return channel) doesn't work — a terminal needs duplex. ## Why this might be better than the current path - Drops the "real terminal app" problem entirely (no Win32 console fights, no ConPTY capture quirks, no terminal emulator compatibility matrix). - The browser is already the best rendering surface we have — fonts, GPU compositing, CSS, ambience canvas overlays all just work. - Multiple "terminals" = multiple tabs. Session persistence = whatever the helper remembers. - Reuses fzt-showcase / my-homepage rendering work — `<canvas data-ambience>` behind the shell becomes free. ## Risks / open questions - **Auth.** Any tab on the machine can hit `127.0.0.1:<port>`. Token-in-URL is fine for first connect; need to think about token rotation, origin pinning (`Origin` header check on WS upgrade), and what happens if the user has the page open in two browsers. - **Helper distribution.** One more thing to install. Tauri / a single signed binary is probably the right shipping vehicle so it's not "download a Go binary and trust me." - **Protocol handler UX across OSes.** Behaviour differs on Windows / macOS / Linux; the "always allow" affordance isn't uniform. Worth a small spike before committing. - **Relationship to fzt-terminal and the existing terminal/ ambience integration.** If this lands, the sixel renderer in `ambience/terminal` becomes lower priority — its open issues (#11–#15) might just get sidestepped rather than fixed. - **Offline / no-network story.** If the UI is hosted, what happens when the user is offline? Probably needs to be a PWA or shipped inside the helper. ## Next step Spike: tiny Go helper that registers `fzt://`, accepts `fzt://spawn?port=&token=`, opens a localhost WS, runs `cmd.exe` / `pwsh` through a PTY. Browser side: xterm.js page that fires the URL and connects. Goal is "type `ls` in the browser, see output" — nothing more. Decide from there whether to keep going or fold back into the terminal-native path.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/fzt-automate#3
No description provided.