Skip to content

cmux ssh: add --no-focus flag to suppress auto-focus on connect - #1942

Closed
maucher wants to merge 2 commits into
manaflow-ai:mainfrom
maucher:feat/ssh-no-focus
Closed

maucher wants to merge 2 commits into
manaflow-ai:mainfrom
maucher:feat/ssh-no-focus

Conversation

@maucher

@maucher maucher commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add --no-focus flag to cmux ssh so scripted/background SSH workspace creation does not steal the user's active workspace focus.

Without this flag, workspace.select is called immediately after workspace.remote.configure returns, switching the user away from their current workspace before SSH is even established. With --no-focus, the workspace is created and configured but the caller's workspace retains focus. The caller can then redirect to the new workspace later via cmux select-workspace.

Usage

cmux ssh dev@my-host --no-focus
cmux ssh dev@my-host --name "gpu-box" --no-focus

Consistency

Follows the same pattern as break-pane --no-focus and join-pane --no-focus.

Changes

  • SSHCommandOptions: add noFocus: Bool field
  • parseSSHCommandOptions: parse --no-focus flag (also made internal for testability)
  • runSSH: guard workspace.select call with if !sshOptions.noFocus
  • Help text: document --no-focus flag
  • Tests: fix existing SSHCommandOptions initializer call; add testParseSSHCommandOptionsNoFocusFlag

Testing

cmux_ssh_no_focus

Tested locally by compiling the CLI directly and running against a live cmux socket:

/tmp/cmux-test-cli ssh devbox --name "no focus" --no-focus
# → OK workspace=workspace:N target=devbox state=connecting
# active workspace did not change

Also verified:

  • --no-focus alongside other flags (--name, --port) parses correctly
  • unknown flags still error as expected
  • unit test testParseSSHCommandOptionsNoFocusFlag added to CLIProcessRunnerTests

Issues

Addresses the cmux ssh case of #140 ("CLI commands should not change focus state") and is complementary to #1418 (new-surface: add --no-focus flag).

maucher added 2 commits March 22, 2026 14:59
When cmux ssh is used from a script, workspace.select is called
immediately after workspace.remote.configure, stealing the user's
active workspace focus before SSH is established.

Add --no-focus flag (consistent with break-pane/join-pane) to skip
the workspace.select call so the caller's workspace retains focus.
The caller can then redirect to the new workspace later via
cmux select-workspace.

Addresses cmux ssh case of manaflow-ai#140; complementary to manaflow-ai#1418.
- Fix existing test that constructs SSHCommandOptions directly
  (add noFocus: false to the initializer call)
- Make parseSSHCommandOptions internal so it's accessible from tests
- Add testParseSSHCommandOptionsNoFocusFlag covering:
  - flag sets noFocus=true, destination parses correctly
  - absent flag defaults noFocus=false
  - combined with --name and --port
@vercel

vercel Bot commented Mar 22, 2026

Copy link
Copy Markdown

@maucher is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Mar 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e43110a-fc7b-4480-b005-33b07bb655f6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@greptile-apps

greptile-apps Bot commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a --no-focus flag to cmux ssh so that scripted or background SSH workspace creation does not steal the user's active workspace focus. It follows the same implementation pattern as break-pane --no-focus and join-pane --no-focus.

Key changes:

  • SSHCommandOptions gains a noFocus: Bool field (defaults to false, preserving current behavior)
  • parseSSHCommandOptions is widened from private to internal to enable direct unit testing via @testable import
  • The workspace.select call in runSSH is guarded by if !sshOptions.noFocus
  • Help text is updated with the new flag
  • Tests cover the default-off, explicit-on, and mixed-flag parsing scenarios

The change is clean, minimal, and consistent with the codebase's existing --no-focus convention. No behavioral regressions to existing callers (flag defaults to false).

Confidence Score: 5/5

  • Safe to merge — additive flag with false default preserves all existing behavior.
  • The change is a minimal, well-scoped addition. The noFocus field defaults to false so all existing call sites are unaffected. The guard is placed at the only workspace.select call within runSSH. The implementation is consistent with break-pane/join-pane. Tests cover the parser path and the existing initializer call is correctly updated.
  • No files require special attention.

Important Files Changed

Filename Overview
CLI/cmux.swift Adds noFocus: Bool to SSHCommandOptions, widens parseSSHCommandOptions from private to internal for testability, guards workspace.select call with if !sshOptions.noFocus, and adds help text. Change is minimal, well-scoped, and consistent with break-pane/join-pane precedent.
cmuxTests/CLIProcessRunnerTests.swift Updates existing SSHCommandOptions initializer call to include the new noFocus parameter, and adds testParseSSHCommandOptionsNoFocusFlag covering default-off, explicit-on, and mixed-flag scenarios. Tests exercise real runtime behavior through the parser path.

Sequence Diagram

sequenceDiagram
    participant User
    participant cmux CLI
    participant App (workspace)

    User->>cmux CLI: cmux ssh dev@host [--no-focus]
    cmux CLI->>App (workspace): workspace.create
    App (workspace)-->>cmux CLI: workspace_id
    cmux CLI->>App (workspace): workspace.rename (if --name)
    cmux CLI->>App (workspace): workspace.remote.configure
    App (workspace)-->>cmux CLI: configuredPayload

    alt --no-focus NOT set (default)
        cmux CLI->>App (workspace): workspace.select
        App (workspace)-->>User: Focus switches to new workspace
    else --no-focus set
        Note over cmux CLI,App (workspace): workspace.select skipped
        Note over User: Caller retains active workspace focus
    end

    cmux CLI-->>User: OK workspace=... target=... state=...
Loading

Reviews (1): Last reviewed commit: "CLI: add test coverage for --no-focus fl..." | Re-trigger Greptile

@vercel

vercel Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Ready Ready Preview, Comment Mar 22, 2026 10:45pm

@lawrencecchen
lawrencecchen changed the base branch from pr-ssh-stack-main to main March 27, 2026 01:28
@lawrencecchen

Copy link
Copy Markdown
Contributor

Superseded by #2227 (cherry-picked onto main with conflict resolution). Thank you for the contribution!

This branch was successfully deployed

1 active deployment
Preview — 8d3419e2 Deployed Mar 22, 2026 by vercel[bot]
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.

2 participants