Repository navigation
feat(native): SSH environments, first slice - #90
Merged
Merged
Conversation
Adds SSH as a way to add an environment, as the desktop app does: discover hosts from ~/.ssh/config and known_hosts, start the T3 release on the host over ssh, forward a local port to it, pair over SSH, save the environment, reconnect it on launch, and stop the tunnel and remote server on remove or disconnect. A host that wants a password asks in an in-app prompt answered through an askpass helper.
…, recorded routes The remote stop and launch scripts signal a recorded server only while it still has the start time recorded with it, so a reused PID is left alone. Quitting stops every ssh the app started, including launches still installing and tunnels still waiting to answer, and waits until each is gone. A tunnel whose local port another process took moves to a free one, and the client reconnects there. Disconnect and remove find the tunnel a target reached and stop the server on the host it started on, even if the SSH config moved the alias since.
rynfar
force-pushed
the
nw/88-ssh-environments
branch
from
November 3, 2026 00:17
d2cfa1a to
64c29d8
Compare
…at once A recorded remote server is signalled only when both its recorded and its current start time are known and equal. Quitting SIGKILLs every ssh process group the app spawned before returning, inside the quit budget. Only a bind collision moves the tunnel to another port. Every command pins the resolved host name, so a HostName added to the config mid-session cannot move the stop.
…nch-failure kill The tunnel monitor deregisters its process group as soon as the leader is reaped, before the diagnostics drain, so a quit never signals a reused group ID. The launch script's readiness-failure path checks the recorded start time before killing, as the stop path does.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the first slice of #88 (ledger row CN-SSH, stays
partial).Problem
The desktop app can add an environment over SSH: it reads your SSH config, starts T3 Code on the host, forwards a local port to it, pairs over SSH, and reconnects it on launch. The native app could only pair with a link or with T3 Code on this Mac.
How it was ported
The desktop's SSH work lives in its main process. The native app is a desktop app, so it does that work itself.
crates/core/src/ssh(pure, tested) portspackages/ssh/src/config.ts(host discovery throughInclude, OpenSSH quoting and escapes,known_hostswith hashed and pattern entries skipped, certain-HostNamededupe),command.ts(ssh -Gparsing, connection key, SHA-256 state key, base and command arguments with the host after--),tunnel.ts(the runner, launch, pairing and stop scripts, launch and pairing output after login-shell noise, tunnel arguments),auth.ts(askpass script and environment, auth-failure and agent-signing classifiers), plus the web'sparseManualDesktopSshTarget,formatDesktopSshTargetandfilterDiscoveredSshHosts. Tests mirrorconfig.test.ts,command.test.ts,auth.test.tsand the script cases oftunnel.test.ts(state-key vectors711bc738002d72fdand326264c4f08c8a0cmatch).crates/client/src/ssh.rsportsSshEnvironmentManagerand the web's SSH gateway (provisionDesktopSshEnvironmentandprepareDesktopSshEnvironment). It resolves the target, launches or reuses the remote server, forwards a local port, and waits for/to answer. It mints a pairing credential over SSH, checks the descriptor (identity and protocol), and redeems the credential. Everysshruns in its own process group and is stopped through the PID this module spawned (SIGTERM, then SIGKILL after 2 s), never by name. One-shot commands die with their future, and the tunnel's stderr tail (16 KiB) explains an early exit.Preparestep that runs before every connection attempt, the way the web resolver authorizes each one. An SSH environment keeps one local port for the session, so a dead tunnel is rebuilt under the supervisor without changing its address. A cancelled prompt or a host that now reaches another machine isConnectionStatus::Blocked: phase Error, no retries until Retry.ssh, skipped when absent, so older files read as direct). Rows and Settings → Environments showSSH user@host:port(environmentTransportLabel). Remove and Disconnect close the tunnel and stop the remote server this app started (registry.tsdisconnectSsh). Quit stops the tunnels.Loading hosts…,No hosts match "…".), plus Username and Port. A suggested host connects at once. Errors show in an error alert in the web's words (Could not prepare the SSH environment: …), the button readsAdding…while busy, and success toastsEnvironment connected/<alias> is ready over an SSH-managed tunnel.. A rejected SSH environment offers Pair again over SSH.SshPasswordPromptDialog(title, description with the target in mono, countdown, Expired/Dismiss, the web's hint and errors) and retries through an askpass helper written once per session into a private 0700 directory. It asks twice at most and never for an agent-signing failure. Answers are kept in memory for the session only.Deliberate differences
t3CLI installed on this Mac, else the latest GitHub release.~/.t3/ssh-launch/native-<key>. The desktop's runner script can't be reproduced byte for byte (it embeds bundled JS), and on a shared key each app would replace the other's server on every reconnect. Each app adopts the other's server through the default runtime file instead.Verification
cargo test --workspaceandcargo clippy --workspace --all-targets -- -D warningspass. So donode scripts/gen-theme.ts --check,node --test parity/sync.test.ts(42 pass) andconformance/generate.ts --check.crates/client/src/ssh/tests.rs) run against a fakesshshell script. Provisioning launches, forwards and pairs, and a second prepare reuses the tunnel and refuses another machine. Disconnect kills the tunnel by PID and runs the stop script; shutdown kills tunnels and leaves the server. A password host prompts twice (wrong, then right) and gets in through the real askpass helper. An agent-signing failure never prompts, and a cancelled prompt is Blocked. An early tunnel exit reports a 16 KiB stderr tail ending incaféacross a split UTF-8 chunk. The remote scripts passsh -n.ssh, a scratchHOMEwith SSH config, and a loopback forwarder standing in for the tunnel, with the smoke server as the "remote" and a read-only pairing credential I minted. Addingdevbox:-G, batch launch denied, in-app prompt, askpass retry, tunnel, pairing, redeem, connected. The supervisor's prepare then reused the single tunnel. Relaunching with the saved environment reconnected through the prepare hook. Disconnect from Settings stopped the tunnel by its PID and ran the stop script. I revoked the two smoke sessions this created afterwards.ssh -o BatchMode=yes localhost truefails here (host key verification), and I didn't change~/.sshor system settings. No realssh, remote shell, or release download ran.Screenshots (offscreen renderer, fixture hosts)
/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/01-ssh-hosts.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/02-filter.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/03-adding.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/04-error.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/05-password.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/06-live-connected.pngSSH [email protected]:22:/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/07-relaunch-settings.png/private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3998c826-bb1a-4777-8d4c-a9ea46007740/scratchpad/ssh88/shots/08-disconnected.pngAfter review
ps -o lstart=) are both known and equal. A reused PID, or a host with no way to tell, is never signalled. The launch-failure kill uses the shell's own$!. The desktop trustskill -0here (tunnel.ts:644,:679,:745).sshprocess group the app spawned before the quit handler returns. That includes launches still installing and tunnels still waiting to answer, and it fits GPUI's 200 ms quit budget. Nothing new starts after a quit.ClientEvent::Moved), and the app reconnects there.-o HostName=), with its user and port; onlyssh -Gitself is unpinned. A running tunnel keeps the resolution it started with, so Disconnect and Remove stop the right tunnel and server after a config change mid-session.Gaps (second slice)
ssh -Gwhen a suggestion is picked.Add routemode (an SSH route to an existing environment) and multi-route environments.prepareDesktopSshEnvironment's scope check). Today a rejected token prompts Pair again over SSH.readRemoteServerLogTail).Built with Claude Opus 5.5 in Claude Code.