8000 feat: ssh workspaces - Explorer, Git pane, Diff tab and sidebar over ssh or WSL by stlindenau · Pull Request #468 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

feat: ssh workspaces - Explorer, Git pane, Diff tab and sidebar over ssh or WSL - #468

Merged
amirlehmam merged 5 commits into
amirlehmam:masterfrom
stlindenau:pr/ssh-workspaces
Nov 24, 2026
Merged

amirlehmam merged 5 commits into
amirlehmam:masterfrom
stlindenau:pr/ssh-workspaces

Conversation

@stlindenau
Copy link
Copy Markdown
Contributor

What

wmux set-ssh-target tells wmux that a workspace's files live on a remote host. The Explorer (list, open, save, create, rename, delete; code and Markdown), the Git pane, the Diff tab and the sidebar branch/dirty marker then work on that checkout over ssh. The ssh runs inside WSL when a distro is given (--wsl-distro). The same latency machinery also serves workspaces on a local WSL share (\\wsl.localhost\...).

wmux set-ssh-target [--workspace <id>] --argv-json '["ssh","-o","BatchMode=yes","user@host"]' --path /abs/checkout [--wsl-distro Ubuntu]
wmux clear-ssh-target [--workspace <id>]

The target is held in memory only and is set again by the caller each time it connects. Without a target nothing changes.

Why

A pane that runs ssh shows a session whose files are on another machine, so the Explorer, Git and Diff views had nothing to show (explorerRootFor answers remote). On Windows the obvious fix does not work: the ssh key and the pinned known_hosts live in WSL, and Windows ssh.exe has neither (it fails the host key, and with that bypassed it has no key the host accepts). So the ssh has to run in WSL, and every request then costs a wsl.exe start.

Why this is one PR

I would normally send this as several PRs. I'm sending one on purpose, because the pieces depend on each other and a partial merge would release an incomplete feature:

  • a read-only Explorer without saving, or git views without the batching and the click-first spawn gate, would be correct but unusable in practice. On the machine I tested, a spawned wsl.exe call took about 350 ms (median), and one Git pane refresh used 4 to 7 of them;
  • the polling snapshot and the persistent worker are what bring the views to 25-70 ms per request on the same machine; shipping the views without them would ship the slow version as the release;
  • the pieces share modules (spawn gate, batch runner, trace, worker), so cutting between them means temporary scaffolding that would be deleted again in the next PR.

It is organised for review as three commits: source (including the few existing tests whose expectations changed), new tests, and docs. If you would still rather have it split, I will; the natural cut lines are noted in the review guide below.

How it works (short)

  • set-ssh-target is a V2 pipe method like set-indicator (validation in main, CLI is the only surface). The ssh command travels as a JSON argv, never a string, and is validated through ssh-argv.ts.
  • Remote work runs as constant POSIX sh scripts; every user-controlled value is a positional argument or base64 payload. Responses are framed with a per-request random nonce and parsed strictly.
  • Explorer paths keep the jail semantics (relative only, no .., no symlinked segment), saves go through the existing grant model with an expected-mtime conflict check, and a failed or ambiguous write is never re-run.
  • Git: several read-only git commands run in one remote call, with a one-by-one fallback; pollers share one cheap change check (a digest) with back-off while nothing changes; a click always goes ahead of a poll (one of three per-host slots is reserved for it) and never reads the poll cache.
  • A persistent worker (one long-lived wsl.exe ... sh per host or distro) serves later requests; any worker problem falls back to a normal spawn, and only idempotent reads are re-run.
  • WMUX_SSH_WORKER=0 turns the worker off 8000 ; WMUX_SSH_TRACE=1 logs one line per remote call (kind, priority, queue wait, duration, exit code, bytes; never paths, hosts, arguments or stderr).

Tests

  • New suites cover the jail and grant gates as behaviour (not source-text pins), the batch framing against forged and truncated output, the worker protocol and fallback rules (crash, hang, noise, large payloads, writes not re-run), the spawn counts of each view action, and the pollers' back-off. Real sh/git stand in for ssh/wsl.exe, so the shell-backed suites skip on Windows (tests/helpers/posix-tools.ts) and the pure-logic suites run everywhere.
  • On Linux: npm run typecheck and npm run verify:resources are clean, npm run lint is unchanged (8 errors, pre-existing), and the full npm test failing set is identical to upstream/master's (69 tests, Windows path/PTY assumptions); +759 tests, all passing.
  • On Windows 11: the 44 new and changed test files give 559 passed, 318 skipped (the suites that need a POSIX shell), 0 failed, including the CLI test over the named pipe. The full npm test run fails only tests that also fail on an unmodified upstream/master checkout on the same machine (the pwsh lookup in pty-manager.test.ts and four relay tests in wmux-bridge-transport.test.ts).
  • resources/cli/wmux.js is regenerated from src/cli/wmux.ts.

Tested by hand

On Windows 11 against a real remote host, through WSL and with the worker on: the folder view, editing and saving, the Git pane and the Diff tab, the path refusal (.. paths are rejected while a normal untracked file still diffs), closing a workspace (its worker stops), and a forced kill of wmux's main process (the worker of a WSL folder exits and removes its temp directory).

Review guide

  • Entry points: src/cli/wmux.ts (verbs), src/main/ssh-targets.ts (registry and validation), src/main/ssh-access.ts (the grant/ownership gates), src/main/ssh-explorer.ts, src/main/ssh-git.ts, src/main/exec-worker.ts (engine) and exec-worker-routed.ts, exec-gate.ts, exec-snapshot.ts, exec-git-batch.ts.
  • Changes to existing upstream code: remote-upload.ts (the shared ssh option builder moved to ssh-exec.ts), git-view.ts and diff-provider.ts (a route for remote/WSL execution and the batched queries), ipc-handlers.ts (thin wiring), the Explorer/Git/Diff renderer hooks.
  • Possible cut lines if you want it split: (1) set-ssh-target + read-only Explorer, (2) writes, (3) git/diff/sidebar + WSL route, (4) batching/gate/snapshot, (5) worker, (6) local-WSL folders.
  • Docs: docs/remote-workspace-views.md (design), the set-ssh-target section in docs/DEVCONTAINER.md, one rules bullet in AGENTS.md.

🤖 Generated with Claude Code

stlindenau and others added 3 commits November 21, 2026 13:05
… ssh or WSL

A workspace can be pointed at a remote checkout with `wmux set-ssh-target`. The Explorer,
Git pane, Diff tab and sidebar branch marker then work on that checkout over ssh (run
inside WSL when a distro is given), with batched git calls, a click-first spawn gate,
a shared change check for the pollers and a persistent worker; WSL folders share the
same machinery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amirlehmam amirlehmam left a comment
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this, and for the way it is organised: the review guide and the three commits made a 15k-line PR readable. I reviewed it and ran it against a real sshd on both routes (Windows OpenSSH directly, and through WSL Ubuntu). I am not merging it into today's release, but I want it in, and the list of what blocks it is short.

What held up. File names containing ', ", \, ;, backticks, $(…) and a newline were read and diffed with nothing executed. The Explorer jail refuses .., absolute paths, a symlinked file and a symlinked directory, in JS and in the script. A stale mtime gives conflict. wsl.exe is resolved by absolute path. The worker is gone within 5 s of a hard kill of the main process, and the target is not persisted. On a real distro the PR and a build of master gave identical answers for repo, changed files and diffs, and the PR was faster. It merges cleanly into current master (which now has #469 and #470), and build, verify:resources and the Windows-runnable tests pass on the merged tree.

Blocking

  1. The direct route (no --wsl-distro) hangs intermittently. runSsh in src/main/ssh-exec.ts (around line 312) ends the child's stdin only when there is input. With Windows OpenSSH 9.5, 6 of 24 Explorer reads hung until the timeout and came back as read_failed; with stdin always ended, 0 of 24. In the app that is a 30 s stall each time, holding one of the host's three slots. Always calling child.stdin.end() fixes it.

  2. The Git view can read outside the checkout through a symlinked directory. The untracked section of workingDiff (src/main/git-view.ts, around line 859) runs git diff --no-index -- /dev/null <file> after canonicalRemoteRelPath, which checks the spelling of the path only. With etc-link -> /etc in the checkout, a request for etc-link/passwd returned the remote /etc/passwd. The Explorer jail refuses that same path, so the Git route needs the same no-symlinked-segment check. No click in the UI produces this request, so it takes a compromised renderer plus a repo that ships the symlink, but the jail is there for exactly that case.

  3. Workspaces on a \\wsl.localhost\… share change behaviour with no set-ssh-target and no way to turn it off. The description says "without a target nothing changes", but for those workspaces git and diff calls now go through the batched script, the gate and a persistent wsl.exe per distro, and that worker is started on window focus or workspace switch even when no Explorer, Git or Diff view is open (exec-warm.ts). The part that will be noticed: polls are answered from the cache while the fingerprint is unchanged, backing off to 30 s, so a git commit or a save made from the pane can show up to about 30 s late, where master re-ran git on every poll. WMUX_SSH_WORKER=0 turns off the worker only. I would like either the local-WSL route left as it is on master in this PR (your cut line 6), or one switch that turns off batching, gate and poll cache together, and a poll that does not lag behind a change made in the workspace's own pane.

  4. The jail, script, worker and explorer suites never run in release CI. tests/helpers/posix-tools.ts returns false on win32, so 318 tests in 11 files are skipped, and release.yml runs on windows-latest only. In WSL all 44 files pass (877 tests, none skipped), so the tests are good, they just do not gate anything. Could they find a POSIX sh and git on a Windows runner (Git for Windows ships both), or run in a WSL/Linux job?

Not blocking, but please look

  • ControlPersist=300 on the WSL route leaves an ssh: /tmp/wmux-… [mux] process in the distro for up to five minutes after wmux quits or is killed. wmux should close the master on quit (ssh -O exit), or use a much shorter persist.
  • remoteCreateEntry, remoteRenameEntry and remoteDeleteEntry in ssh-explorer.ts have no IPC handler, so create, rename and delete over ssh are not reachable, while the description lists them. Either wire them or drop them from this PR.
  • The argv validation: set_ssh_target needs the pipe token, so it is the same trust as typing in a pane and I am fine with that. But only LocalCommand and PermitLocalCommand are refused, while -o ProxyCommand= and -F <file> pass, and an argv[0] with a path runs the ssh.exe beside it. Unlike a command typed in a pane, these then run unseen and repeatedly on view polls. Please say so in docs/remote-workspace-views.md, so nobody reads the validation as a sandbox.
  • Not run, from reading only: posixShellQuote relies on \ being literal inside single quotes, which fish does not honour, so a remote account whose login shell is fish may be exposed on the direct route (untracked file names are passed by diff polls). resolveRemoteIdentity in ssh-markdown.ts matches on destination, port and path, so two targets with the same alias reaching different hosts could send a save to the wrong one. The direct route opens a new ssh login per poll. Targets are cleared on workspace close, and I could not see it for a window close.

With 1 to 4 addressed I will merge it as one PR; there is no need to split it. If it is easier, 1 and 2 are small enough that I can push them to your branch myself, tell me.

@stlindenau
stlindenau marked this pull request as draft November 23, 2026 17:36
amirlehmam and others added 2 commits November 24, 2026 03:54
…mam#468)

1. Direct route hang: every spawn that sends no input now closes the
   child's stdin (runSsh, execFilePlain, diff-provider's execFile).
   Windows OpenSSH 9.5 waits on an open stdin pipe, which stalled about
   one read in four until the timeout.

2. Git view reading outside the checkout: `git diff --no-index` follows
   a symlinked directory, so `etc-link/passwd` read the host's
   /etc/passwd. GIT_SCRIPT and BATCH_SCRIPT now walk the file argument
   and refuse a symlink in any segment with status 126
   (NO_INDEX_GUARD_SH in ssh-path.ts), the explorer jail's rule.

3. WSL folders changed behaviour with no target set: the fast route
   (batch, gate, poll cache, worker, warm-up) is now opt-in behind one
   switch, WMUX_WSL_FAST=1. Off by default, a `\wsl.localhost` folder
   runs one `wsl.exe --exec git` per command, as on master.

4. POSIX suites never gated a release: release.yml gets a Linux job
   that runs every suite importing the posix-tools helper
   (`npm run test:posix`), and the Windows build job needs it.
   WMUX_REQUIRE_POSIX=1 turns a skip into a failure.

Also documents that the set-ssh-target argv validation is not a
sandbox, and flattens a few nested conditionals in the touched files.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@amirlehmam
Copy link
Copy Markdown
Owner

I went ahead and pushed the four blockers to your branch myself (4b70e72, on top of a merge of current master), so this can go into the next release. Nothing of yours was rewritten beyond what is listed here.

  1. Direct route hang. stdin is now always ended: in runSsh, and also in execFilePlain and diff-provider's execFile, since the git calls on the direct route had the same open pipe.
  2. Symlinked directory in the Git view. GIT_SCRIPT and BATCH_SCRIPT both run a small shell function (NO_INDEX_GUARD_SH, ssh-path.ts) before a diff --no-index: it walks the file argument and refuses a symlink in any segment with status 126, the last segment included, like the Explorer jail. A new test in exec-git-batch.test.ts covers the batch (c and w groups), the single-call script, .., an absolute path and the --numstat form.
  3. WSL folders. The fast route is opt-in behind one switch, WMUX_WSL_FAST=1. wslGitContextFor answers null without it, which turns off batch, gate, poll cache, worker and warm-up together; by default a \wsl.localhost folder behaves as on master. Your WSL suites run with the switch on (vitest.config.ts), and wsl-fast-route-switch.test.ts covers the default.
  4. POSIX suites in release CI. release.yml has a Linux job that runs every test file importing tests/helpers/posix-tools (npm run test:posix), and the Windows build job needs it. WMUX_REQUIRE_POSIX=1 makes a missing tool throw instead of skip. In WSL Ubuntu: 21 files, 501 tests, none skipped.

docs/remote-workspace-views.md now says the argv validation is not a sandbox, and describes the switch and the --no-index guard. I also flattened a few nested conditionals in git-view.ts and diff-provider.ts while I was in those files; behaviour is unchanged.

Still open, none of it blocking: ControlPersist=300 outliving wmux on the WSL route, the create/rename/delete functions that have no IPC handler, a fish login shell on the direct route, resolveRemoteIdentity matching on alias, and clearing targets on window close. Follow-up PRs for any of those are welcome.

Windows: typecheck clean, verify:resources clean, 7606 tests passed. Thank you again for this.

@amirlehmam
amirlehmam marked this pull request as ready for review November 24, 2026 03:07
@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Nov 24, 2026 •
Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T03:15:12.372008Z
We couldn’t complete this review. Comment @codex review to try again.
4b70e72 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@amirlehmam
amirlehmam merged commit 2ef32ba into amirlehmam:master Nov 24, 2026
@stlindenau
stlindenau deleted the pr/ssh-workspaces branch November 24, 2026 07:38
amirlehmam pushed a commit that referenced this pull request Nov 25, 2026
…#468) (#475)

* fix: send the direct-route ssh command as base64 so no login shell can re-parse a file name

Review of #468, non-blocking (fish login shell).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* test: let the fake ssh and the command assertions read the base64 direct-route command

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix: refuse a remote markdown identity that two differently reached targets share

Review of #468, non-blocking (resolveRemoteIdentity).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix: drop an ssh target when the window that set it closes

Review of #468, non-blocking (targets on window close).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix: close the ssh ControlMaster of each WSL distro when wmux quits

Review of #468, non-blocking (ControlPersist).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* docs: how the non-blocking points of the ssh workspaces review were settled

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* docs: say in the code that no view reaches remote create, rename and delete

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet
4B02

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0