Follow remote shell cwd for cmux ssh sessions (#7268)
Summary
- Treat remote workspace cwd as trusted only after a remote terminal reports a directory.
- Stop sidebar/titlebar/file-tree/custom-sidebar projections from falling back to the local cwd inherited by
cmux ssh. - Let the existing SSH file explorer use remote home/unavailable state before the first remote cwd report, then switch to the reported remote cwd.
Root Cause
cmux ssh creates the terminal workspace from the local launch context, so the initial terminal has the Mac cwd as currentDirectory/requested cwd. After workspace.remote.configure, the workspace becomes remote, but the sidebar and file explorer still read that inherited local cwd until the remote shell's surface.report_pwd/OSC-style report arrives. That made the UI display ~/development from the Mac and made the SSH file tree try to use that local path as a remote root.
Fixed vs Deferred
Fixed:
- Remote sidebar directory rows and user-facing directory snapshots now use only reported remote panel directories.
- Remote file explorer root sync passes
nilbefore a remote cwd report, so it no longer silently implies the local path. - Remote terminal session snapshots no longer persist the untrusted requested local cwd when no remote cwd has been reported.
- Local-only Finder/VS Code directory opening no longer falls back to the local cwd while a remote workspace is selected.
Deferred:
- cmux still needs a remote shell cwd report to follow exact remote
cdchanges. If a remote shell does not run shell integration/relay reporting, cmux falls back to the existing SSH file explorer remote-home/unavailable behavior rather than inventing a cwd. No new SFTP/remote-browser feature was added in this PR.
Tests
- Added a Swift Testing regression for a
cmux ssh-style workspace that starts with a local cwd and should expose no remote cwd untilupdatePanelDirectoryreceives the remote/home/...report. python3 scripts/swift_file_length_budget.py./scripts/lint-pbxproj-test-wiring.shxcodebuild -project cmux.xcodeproj -scheme cmux -configuration Debug -destination 'platform=macOS' -derivedDataPath /tmp/cmux-issue-7268-ssh-remote-cwd-file-tree build
Local xcodebuild test / XCUITests were not run per the issue instructions; CI should run the test target.
Localization Audit
No user-facing strings were added. The production diff only rewires existing directory values and uses existing empty-string snapshot fallbacks; I audited the changed Swift diff for added string literals and found no new localizable UI copy.
PR Feedback Update
- Addressed Greptile feedback by switching the window-title active directory and control-sidebar state snapshot from currentDirectory to presentedCurrentDirectory, with regression coverage for both surfaces.
- Addressed CodeRabbit feedback by consolidating the duplicated custom-sidebar workspace snapshot builders into Workspace.customSidebarWorkspaceSnapshot(...).
- Rechecked whitespace, Swift file length budget, pbxproj test wiring, pbxproj normalization, compile-only build, and a temporary merge check against the fetched origin/main.
Closes #7268
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
Summary by cubic
Make SSH and remote tmux workspaces follow each panel’s trusted, reported remote cwd so window titles, sidebars, AppleScript, and git/PR metadata use the correct remote path. Trust persists across detach/reattach and reconnects, is included in autosave, and is cleared when panels are removed; closes #7268.
-
Bug Fixes
- Skip local git branch/PR probes and polling for remote terminal panels until a trusted remote cwd is reported; drop late local probe applies.
- Titles (
activeDirectory), AppleScriptworkingDirectory, file explorer, extension/custom sidebars, control sidebars, and mobile lists use trust‑aware presented/effective directories and refresh on trust changes; focused local terminals in a remote workspace keep their own cwd. - Only connected, trusted remote reports (OSC 7, tmux, control socket/agent, Ghostty) update remote paths; generic/local PWD remains untrusted. Remote tmux new windows inherit only trusted remote paths.
- Autosave/restore and detached transfers include cwd provenance and trust; agent panels clear or preserve cwd based on trust (including legacy restores).
-
Refactors
- Added
updateRemoteSurfaceDirectory/updateReportedSurfaceDirectoryand trust‑aware directory APIs (effectivePanelDirectory,presentedCurrentDirectory) that invalidate stale git/PR metadata before fresh probes. - Introduced host hooks
isRemoteTerminalPanel,hasTrustedRemotePanelDirectory, andshouldSkipLocalGitMetadatato gate scheduling, applying, and polling of git/PR metadata. - Centralized custom‑sidebar snapshots in
Workspace.customSidebarWorkspaceSnapshot; observers react to directory‑change revisions and active remote session counts.
- Added
Summary by CodeRabbit
- New Features
- Unified “presented” workspace directory and per-panel “reported” directory across sidebar, command/panel context, window titles, terminal controls, extension sidebar, and mobile lists.
- Added remote directory trust/provenance tracking with revision-aware updates, plus APIs to record remote trusted panel directories and route metadata refreshes.
- Bug Fixes
- Improved remote/SSH roots and focus/fallback directory resolution to prevent stale local values and keep window titles accurate.
- Tests
- Expanded coverage for trust transitions, remote restore, detach/reattach, autosave fingerprints, and mobile fidelity.
- Documentation
- Minor comment/doc updates.