Skip to content

feat(client,link,proto): open a remote terminal without streaming the screen - #145

Merged
sqlpxc merged 1 commit into
mainfrom
feat/remote-terminal
Dec 3, 2026
Merged

sqlpxc merged 1 commit into
mainfrom
feat/remote-terminal

Conversation

@sqlpxc

@sqlpxc sqlpxc commented Dec 3, 2026

Copy link
Copy Markdown
Owner

What changes

A remote terminal: when you only want to run command-line programs on the other computer (claude, codex, pi, builds, logs…), open a terminal there instead of streaming the desktop. Nothing is captured or encoded, so it uses next to no bandwidth and the remote screen doesn't wake up.

  • Console (desktop and web): on the New connection page, type the control code and click Terminal (next to Connect), or click the terminal icon on a computer in My devices. The terminal opens in a new tab (xterm.js), with the latency, text size and full screen in the toolbar. Several terminals can be open on the same computer, one per tab.
    • Copy and paste: select text and press Ctrl+C (⌘C on macOS) to copy; without a selection Ctrl+C goes to the program as usual. Ctrl+V / ⌘V or right-click pastes (right-click copies when text is selected). Ctrl+Shift+C / V also work.
    • When the program exits, the tab shows the exit code and can open a new terminal.
  • Host (Windows / macOS / Linux): the terminal runs as the signed-in user, like a terminal they open themselves. Windows uses PowerShell 7 if installed, otherwise Windows PowerShell; macOS / Linux use the user's login shell. terminal_shell in config.toml picks another shell.
    • When Airhand is installed for all users on Windows, the host is SYSTEM, and ConPTY must run as the same user as the programs in it. So it starts a helper airhand.exe --terminal as the user signed in on the console session (WTSQueryUserToken, CreateEnvironmentBlock), passing only two pipes (PROC_THREAD_ATTRIBUTE_HANDLE_LIST). The terminal runs in the helper, which talks to the host over its stdin / stdout. If nobody is signed in, no terminal can be opened.
    • New tray item Allow remote terminal (on by default, remote_terminal in config.toml). Turning it off refuses terminal sessions in the handshake and ends open terminals and terminal sessions right away. The tray marks controllers with a terminal "(terminal)". Disconnecting all controllers or changing the control code ends all terminals.
    • During a terminal session the computer is kept from idle sleep, but the display still turns off.
  • Survives dropped connections: the console reconnects as usual. Meanwhile the host keeps the terminal for up to 30 minutes with its programs still running, buffering the latest 1 MiB of output. After reconnecting, the same terminal is resumed from where the console left off. Only the same controller (same public key) can resume it. Closing the tab ends the terminal.
  • Flow control: output is numbered by byte, and the host sends at most 128 KiB the console hasn't acknowledged yet. The console acknowledges after xterm has drawn it, so cat on a big file doesn't pile up in the relay / controller service / browser, and Ctrl+C works right away.
  • Phones don't offer a terminal. The Android / iOS apps only get the text for the new terminalUnavailable problem.

Protocol

Still v10, no version bump. Host and controller must come from the same build, as before.

  • ControllerIntro::terminal (n(7)) marks a terminal session. The host refuses with Refusal::TerminalUnavailable (→ Problem::TerminalUnavailable, final, no auto-reconnect) when it doesn't offer a terminal (Gate::terminal, off by default).
  • New airhand_proto::terminal: TermRequest / TermEvent, carried in ControllerMsg::Terminal (n(14)) / HostMsg::Terminal (n(17)) on the control lane. Unknown variants are skipped via cbor::opt.
  • Golden bytes are added in tests/v10.rs. protocol.json and protocol-contract.ts are regenerated with the terminal* commands; UI JSON uses term for the terminal id, because id is the console's request id.
  • An older host ignores the flag. The console then gives up opening the terminal after 15 s and says so.

Implementation

  • airhand-link::host::terminal: TermHost (all terminals, including ones kept after a drop) and SessionTerms (one session's terminals), with flow control, resume tokens and expiry. Platforms implement Shells / PtyControl. Each terminal has three threads (read / write / wait).
    • host::serve handles Request::Terminal itself, and Platform::terminals() supplies the TermHost.
    • host::Either lets the desktop pick a different platform part for terminal sessions.
  • airhand-link::controller: Command::Terminal{Open,Input,Resize,Ack,Close} and SessionEvent::Terminal{Opened,Output,Exited,Failed}. Output is decoded to text, and a UTF-8 character split across messages waits for the rest.
  • Desktop host client/src-tauri/src/host/terminal/: conpty.rs (Windows), helper.rs (--terminal, service mode), unix.rs (openpty + login shell; the reader polls so killing the terminal hangs up promptly), and TerminalSession (Hello only). power::stay_up() adds a system-only power request / assertion.
  • Console: lib/terminal.ts (TerminalSession: connect / retry / pairing like RemoteSession, xterm, acks, resume), components/TerminalView.tsx, and store.Session = RemoteSession | TerminalSession. The grid and popouts only show desktop sessions.
    • xterm.js (@xterm/xterm, addon-fit, addon-unicode11) loads lazily in its own chunk, so the main bundle doesn't grow.
  • Docs: README, usage, architecture, security and development, in both languages.

Testing

  • Root cargo test --workspace, client/src-tauri cargo test --lib, npm test (138), and Android ProtocolTest / MessagesTest all pass. cargo clippy and cargo fmt --check are clean; host/session.rs has one formatting difference that was already there before this PR.
  • New unit tests:
    • link host::terminal: echo / exit after output, ack window, resume by the same controller only, KEEP trimming, limits.
    • secure: handshake refusal.
    • controller: UTF-8 split decoding.
    • desktop: ConPTY (conpty::tests::runs_a_shell), Unix PTY (run in WSL Ubuntu: shell + resize + exit code, hang-up on kill), config.
    • console: tests/terminal.test.ts.
  • New ignored end-to-end test e2e_terminal, run on Windows with a real relay: refused when turned off, then echo + ack + exit, and turning it off ends the session.
  • Web console driven by headless Edge against a local relay, web console and headless host:
    • pairing, PowerShell prompt, Chinese input/output, resize (130x35 → 94x23), font size
    • 20 000 lines in ~2.3 s
    • exit 3 overlay and restart, closing the tab ends the terminal on the host
    • restarting the relay mid-loop resumed the same terminal with no lost output
    • pi renders correctly, and Ctrl+C interrupts a loop
  • The --terminal helper protocol was tested by spawning it directly (resize, input, exit code 5).
  • Not tested: the full Windows service path (SYSTEM → CreateProcessAsUser as the user) needs an installed service. macOS was only compile-checked (aarch64-apple-darwin).

@sqlpxc
sqlpxc merged commit d7dc312 into main Dec 3, 2026
1 check passed
@sqlpxc
sqlpxc deleted the feat/remote-terminal branch December 3, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant