Make ⌘N in a remote-tmux mirror window open a session on that host, and add New Local Workspace
In a remote-tmux mirror window, New Workspace (⌘N) creates a local workspace today, next to workspaces that are all sessions on the window's host. To add a session there you have to leave cmux and run tmux new-session on the host.
Repro: attach a host with cmux ssh-tmux <host>, select one of its workspaces, and press ⌘N. You get a local shell, not a session on that host.
The fix
With a mirrored workspace selected, ⌘N now creates a new tmux session on that workspace's host and mirrors it into the window. The host comes from the selected workspace's own mirror, not the window, because one window can hold mirrors from several hosts next to local workspaces. If creating the session fails, an alert says so instead of quietly making a local workspace.
Creating the session and attaching to it are separate steps on the host. If the session is created and cmux then cannot attach to it, the alert says that, and cmux removes the session it just made so it is not left on the host with nothing showing it. If the removal fails as well, the alert names the session so you can find it.
That leaves no way to open local work in such a window, so the PR also adds a New Local Workspace File-menu item that forces local creation. It's shown only when plain New Workspace in the active window would route remote, so it never clutters ordinary windows — a window where New Workspace already creates a local workspace doesn't need it.
performNewLocalWorkspaceActionroutes through the sameperformNewWorkspaceCreationActionas plain New Workspace, with aforceLocalflag that bypasses only the remote-routing branch. Window placement, naming, and workspace-group handling stay identical.- The remote-vs-local decision now lives in one place,
wouldNewWorkspaceSpawnRemote(in:), used by both the routing handler and the menu item's visibility — so the item appears exactly when New Workspace would go remote, and the two can't drift. - Visibility re-evaluates on window focus and workspace selection (a window must become key before its menu bar opens, so switching into a mirror window refreshes it).
- Bound to ⌃⌥⌘N by default. ⌃⌘N already belongs to New Pane (Auto Layout), and New Local Workspace is matched first, so sharing it made the pane action unreachable. It is a first-class
KeyboardShortcutSettingsaction (editable in Settings, in the config schema, and documented), sitting alongside New Workspace (⌘N), New Window (⇧⌘N), and New Browser Workspace (⌥⌘N). The menu item stays conditionally shown; the shortcut always creates a local workspace.
Tests
The remote-vs-local decision is newSessionHost(activeTabId:entries:), a pure function whose truth table RemoteTmuxNewWorkspaceHostRoutingTests covers: no host → local; host but no tab manager (window mid-teardown) → remote; host + active mirror tab → remote; host + a dragged-in local active tab → local. RemoteTmuxNewWorkspaceRoutingTests then covers this PR's own behaviour — the menu item appears only when New Workspace would go remote (menuVisibilityFollowsTheActiveWorkspace), and choosing it on a mirrored workspace creates a local one (newLocalWorkspaceOnActiveMirrorCreatesLocalWorkspace). Two more cover the edges: the item goes away when the selected mirror is detached and its workspace stays open (detachingTheSelectedMirrorChangesTheMirrorSetRevision), and the failure alert shows the localized message plus only the last line of the host's error (newSessionFailureReasonIsOneBoundedLine).
For the shortcut, noOtherActionSharesTheDefault checks both shortcut catalogs, and eachDefaultKeystrokeMatchesOnlyItsOwnAction feeds ⌃⌘N and ⌃⌥⌘N through the app's shortcut matcher and checks each reaches only its own action. For the attach failure, aFailedAttachRemovesTheSessionItCreatedAndReportsAnAttachFailure and aFailedAttachWhoseCleanupFailsReportsTheSessionAsLeftBehind run a create that succeeds followed by an attach that throws, and check the report and the kill-session sent to the host. theAlertSaysWhichStepFailed checks the three alert texts differ in the right way. With the two fixes undone, 11 expectations across these tests fail; with them, 32 tests in 4 suites pass.
Verified at runtime
Attached a mirror window and read the File menu in each state:
- Mirror window, mirror tab active → New Local Workspace shown (right after New Workspace).
- Same mirror window, a local tab active → item hidden (the gate keys on the active tab, not just the window).
- Plain local window → item hidden.
- Clicking it in the mirror window created a local workspace in that window — the host's tmux session count did not change, confirming it skipped remote routing.
- Pressing the shortcut in the mirror window created a local workspace the same way (host session count unchanged). That run used the earlier ⌃⌘N default. I have not repeated it by hand with ⌃⌥⌘N; the keystroke test above covers the new default.
Follow-ups
- Command-palette entry for parity with New Workspace / New Browser Workspace — designed in #7210 (the shared action path here already supports it).
Changelog
Changed: In a remote tmux mirror, New Workspace (⌘N) opens a new tmux session on that host, and New Local Workspace (⌃⌥⌘N) opens a local workspace
Summary by CodeRabbit
- New Features
- Added “New Local Workspace” with the default ⌃⌘N shortcut, letting you create a local workspace when a remote tmux workspace is active.
- New Workspace can create and open a session on the active remote tmux host. The new workspace is selected unless you switch workspaces while it’s being created.
- Added localized labels and shortcut descriptions for the new workspace options.
- Bug Fixes
- Remote session creation failures now display an error instead of silently creating a local workspace.