Skip to content

Add remote surface listing commands - #4759

Closed
austinywang wants to merge 22 commits into
mainfrom
issue-1037-remote-access
Closed

austinywang wants to merge 22 commits into
mainfrom
issue-1037-remote-access

Conversation

@austinywang

@austinywang austinywang commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add SSH-friendly cmux list-surfaces and cmux list-terminals, defaulting to all windows and backed by system.tree
  • include window/workspace/pane context plus title, tty, browser URL, JSON output, and localized help
  • document the CLI contract and add mocked-socket behavior coverage

Scope

This is a self-contained first increment for #1037. It does not add cmux attach <terminal-id> yet; that needs a separate PTY attach/streaming design for existing local terminal surfaces.

Test plan

  • Not run locally per repo/task policy
  • git diff --check
  • jq empty Resources/Localizable.xcstrings

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.


Note

Low Risk
Read-only CLI listing over existing system.tree; no app RPC or attach/streaming behavior changes.

Overview
Adds cmux list-surfaces and cmux list-terminals so you can inspect surfaces from an SSH shell without a current window context. Both call existing system.tree via shared buildTreePayload, default to all windows when no --workspace / --window is set, and flatten the tree into rows with window/workspace/pane handles, type, title, tty, browser URL, and an active marker from the tree’s global active surface.

list-terminals is the same pipeline with terminal_only filtering. Output supports global or per-command --json, plus scoped flags and validation (missing handles, unknown flags, --all vs scoped options). Help, docs/cli-contract.md, localization, Xcode wiring, and mocked-socket integration tests are included.

Reviewed by Cursor Bugbot for commit 19b6a93. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Adds SSH-friendly cmux list-surfaces and cmux list-terminals to inspect surfaces across windows, workspaces, and panes with text or JSON from system.tree. This is the first step toward remote access in #1037; attach/streaming is not included.

  • New Features

    • New cmux list-surfaces and cmux list-terminals default to all windows when unscoped; flags: --workspace, --window, --all, --json.
    • Text output marks the globally active surface and shows window/workspace/pane, type, title, tty, and browser URL.
    • JSON returns flattened rows plus count and terminal_only; localized help and docs/cli-contract.md updated; internals reuse widened buildTreePayload/TreeCommandOptions.
  • Bug Fixes

    • Active marker now follows the tree’s global active surface, ensuring exactly one starred item and avoiding pane-wide marking.
    • Commands route through the CLI dispatcher (take precedence over same-named paths), honor the global --window override, and validate flags before any socket connection.
    • Clear early errors for missing scoped handles, unknown flags, unexpected args, and --all conflicts.

Written for commit 4a60613. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added cmux list-surfaces and cmux list-terminals commands with --workspace, --window, --all, terminal-only filtering, and --json or human-readable output.
  • Bug Fixes
    • Improved command argument validation with clearer errors for unknown flags, unexpected arguments, and invalid combinations like --workspace with --all.
  • Documentation
    • Updated CLI contract and expanded localized --help/usage text, including new empty-state and error messages.
  • Tests
    • Added integration regression tests for workspace scoping, terminal flattening/filtering, and syntax rejection.

@vercel

vercel Bot commented May 26, 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 Jun 15, 2026 12:51pm
cmux-staging Building Building Preview, Comment Jun 15, 2026 12:51pm

@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 745a8679-cb04-4142-9182-0c8b2f0c86f6

📥 Commits

Reviewing files that changed from the base of the PR and between 3df43fb and 4a60613.

⛔ Files ignored due to path filters (1)
  • .github/swift-file-length-budget.tsv is excluded by !**/*.tsv
📒 Files selected for processing (5)
  • CLI/CMUXCLI+ListSurfaces.swift
  • CLI/cmux.swift
  • Resources/Localizable.xcstrings
  • cmux.xcodeproj/project.pbxproj
  • docs/cli-contract.md
💤 Files with no reviewable changes (3)
  • Resources/Localizable.xcstrings
  • docs/cli-contract.md
  • cmux.xcodeproj/project.pbxproj

📝 Walkthrough

Walkthrough

Adds two CLI subcommands, list-surfaces and list-terminals, with localized help, option parsing/validation, tree-based payload construction, hierarchy flattening with optional terminal-only filtering, JSON/text output, integration tests, and updated CLI contract docs.

Changes

List Surfaces and Terminals Commands

Layer / File(s) Summary
Command dispatcher and help text
CLI/cmux.swift
Adds list-surfaces and list-terminals cases to the command dispatcher, delegates both to a shared handler (differing by terminalOnly), inserts localized help/usage blocks, and updates the top-level command listing.
Options parsing, payload building, flattening, and rendering
CLI/CMUXCLI+ListSurfaces.swift
Parses flags (--workspace, --window, --all, --json), validates unknown flags and invalid combinations, builds TreeCommandOptions payload, flattens window→workspace→pane→surface into flat surfaces rows, filters terminals when requested, computes active flags, and renders JSON or formatted text with helper routines.
Localized strings and type accessibility
Resources/Localizable.xcstrings, CLI/cmux.swift
Adds localized help, empty-state, and error message keys for the new commands, and removes private from TreeCommandOptions and buildTreePayload(...) to make them accessible within the module.
Integration tests
cmuxTests/CLINotifyProcessIntegrationRegressionTests.swift
Adds tests: terminal-only filtering across all windows, workspace-scoped listing including browser surfaces, and rejection of --workspace combined with --all. Tests mock system.tree responses and assert stdout/stderr and socket requests.
CLI contract documentation
docs/cli-contract.md
Adds list-surfaces and list-terminals to the CLI contract and extends no-socket help-probe checks to include their --help output.
Xcode project configuration
cmux.xcodeproj/project.pbxproj
Adds CMUXCLI+ListSurfaces.swift to the cmux-cli target via build file, file reference, group children, and source build phase entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • manaflow-ai/cmux#4211: Both PRs add/extend window-scoped CLI behavior by threading a window_id/--window into system.tree requests for listing/targeting results.

Poem

🐰 I hopped through trees and surfaced names,
Flags in paws and tiny CLI aims.
Terminals filtered, browsers shown,
JSON or text — each row well-known.
A carrot-cheer for tidy commands! 🥕

🚥 Pre-merge checks | ✅ 20 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (20 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add remote surface listing commands' directly and clearly describes the main change: introducing new list-surfaces and list-terminals CLI commands.
Description check ✅ Passed The PR description covers all required sections: Summary (what changed and why), Scope clarification, Test plan with validation steps, and includes detailed implementation notes and objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Cmux Swift Actor Isolation ✅ Passed No Swift 6 actor isolation issues introduced. Exposed types (TreeCommandOptions, buildTreePayload) are pure value types without Sendable/Codable/Identifiable conformances, called synchronously from...
Cmux Swift Blocking Runtime ✅ Passed Production code introduces zero blocking patterns. Only visibility widening of synchronization-free utility functions (TreeCommandOptions, buildTreePayload). Test-only DispatchSemaphore usage is ex...
Cmux Expensive Synchronous Load ✅ Passed PR adds list-surfaces/list-terminals CLI commands. No expensive synchronous loaders (RestorableAgentSessionIndex.load) are introduced. TreeCommandOptions/buildTreePayload visibility widened only to...
Cmux Cache Substitution Correctness ✅ Passed PR adds read-only list-surfaces/list-terminals commands that make fresh socket reads via buildTreePayload (client.sendV2); no cache substitution or persistence/undo/history interaction.
Cmux No Hacky Sleeps ✅ Passed PR contains only Swift code changes and test additions; no TypeScript, JavaScript, shell, or build/runtime scripts. Swift timing is covered by separate check per rule scope.
Cmux Algorithmic Complexity ✅ Passed PR adds tree-flattening algorithm that is O(n) single-pass with O(1) per-surface work on fixed-size operations; no nested rescans, unbounded filtering, or in-memory joins on scalable collections.
Cmux Swift Concurrency ✅ Passed No legacy async patterns introduced. New CMUXCLI+ListSurfaces.swift (349 lines) uses modern throws-based synchronous APIs. Public APIs (runListSurfacesCommand, validateListSurfacesCommandSyntax, Tr...
Cmux Swift @Concurrent ✅ Passed All new Swift functions are synchronous with no @concurrent, async, or actor isolation violations. Blocking network I/O in buildTreePayload is appropriate for CLI tool context.
Cmux Swift File And Package Boundaries ✅ Passed CMUXCLI+ListSurfaces.swift (349 lines) is below the 400-line threshold and has a single clear responsibility (list-surfaces/list-terminals command). Changes to cmux.swift total +74/-2 (net +72), be...
Cmux Swift Logging ✅ Passed PR adds SSH-friendly list-surfaces/list-terminals CLI commands with only compliant logging: 2 print() statements for CLI output in new CMUXCLI+ListSurfaces.swift, no debugPrint/dump/NSLog/Logger vi...
Cmux User-Facing Error Privacy ✅ Passed All user-facing error messages and output comply with privacy rules: no vendor names, provider details, env vars, credentials, tokens, or sensitive payload data exposed. Fields are safe product con...
Cmux Full Internationalization ✅ Passed PR adds 8 new localized string keys with complete translations for all 20 supported locales. All user-facing text (help, errors, empty states) properly uses String(localized:). Hardcoded field labe...
Cmux Swiftui State Layout ✅ Passed PR adds CLI commands only; no SwiftUI code, views, state management, or UI components are modified or introduced.
Cmux Architecture Rethink ✅ Passed PR introduces new CLI commands (list-surfaces/list-terminals) with clear single ownership, no timing/blocking operations, no shared mutable state, no duplicate entrypoints, and proper code reuse of...
Cmux Swift Auxiliary Window Close Shortcuts ✅ Passed PR adds CLI listing commands with no NSWindow, NSPanel, NSWindowController, SwiftUI Window, or WindowGroup code; check is inapplicable to CLI-only changes.
Cmux Source Artifacts ✅ Passed All 6 files are legitimate hand-written source, test, doc, and build config; none are local artifacts, generated logs, scratch dirs, or forbidden patterns per source-control-artifacts.md.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-1037-remote-access

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.

@greptile-apps

greptile-apps Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds cmux list-surfaces and cmux list-terminals as SSH-friendly read-only commands that call the existing system.tree RPC via a widened buildTreePayload/TreeCommandOptions, flatten the tree into rows with window/workspace/pane context, and emit text or JSON. This is a self-contained first step toward remote surface inspection (#1037); no attach/PTY streaming is included.

  • New extension file CLI/CMUXCLI+ListSurfaces.swift handles argument parsing (including early flag validation before any socket connection), tree flattening with active-marker resolution from the top-level active.surface_ref, and text/JSON rendering; CLI/cmux.swift adds dispatch, help text, and known-command routing.
  • Six integration tests cover terminal-only filtering, active marker accuracy, workspace scoping, global --window override, command-over-path precedence, and pre-socket rejection of --workspace/--window + --all conflicts.
  • Localization adds eight new cli.* catalog keys with en/ja translated and all other supported locales marked needs_review.

Confidence Score: 5/5

Read-only CLI listing over an existing RPC with no state mutations; safe to merge.

The change is purely additive and read-only: it calls the existing system.tree endpoint, flattens the result, and prints it. All validation fires before any socket connection. Localization is complete across every supported locale. The one issue found — a misleading error message when a global --window override triggers the --all conflict guard — does not affect correctness or safety.

CLI/CMUXCLI+ListSurfaces.swift lines 107–113: the --all conflict guard labels the scoped option as --window even when only the global flag was set, which can produce a confusing error message for users.

Important Files Changed

Filename Overview
CLI/CMUXCLI+ListSurfaces.swift New 349-line extension adding list-surfaces/list-terminals parsing, flattening, and rendering; one misleading error message when a global --window override triggers the --all conflict guard
CLI/cmux.swift Wires list-surfaces/list-terminals dispatch, early syntax validation, help text, and known-command list; TreeCommandOptions and buildTreePayload visibility widened to internal; budget bumped by 72 lines
cmuxTests/CLINotifyProcessIntegrationRegressionTests.swift Adds six integration tests covering terminal filtering with active marker, workspace scoping with browser surfaces, global window override, command-over-path precedence, workspace+all rejection, and missing-handle validation
Resources/Localizable.xcstrings Adds eight new cli.* keys with en (translated), ja (translated), and all other supported locales marked needs_review; fully satisfies the full-internationalization rule
cmuxTests/CLINotifyProcessTestSupport.swift Adds optional currentDirectoryURL parameter to runProcess to support the command-over-path precedence test
docs/cli-contract.md Documents list-surfaces and list-terminals in the command table and --help contract section
.github/swift-file-length-budget.tsv Bumps cmux.swift budget by 72 lines and test budgets accordingly; CMUXCLI+ListSurfaces.swift at 349 lines is below the tracking threshold and not listed

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["cmux list-surfaces / list-terminals\n(commandArgs, windowOverride)"] --> B["validateListSurfacesCommandSyntax\n(early, before socket)"]
    B --> C{Parse --workspace\n--window --all --json}
    C -- "missing handle value" --> E1["CLIError: requires handle"]
    C -- "unknown flag / extra arg" --> E2["CLIError: unknown flag / unexpected arg"]
    C -- "--all + scoped option" --> E3["CLIError: cannot combine --all with scope"]
    C -- "no scope given" --> D["includeAllWindows = true (default)"]
    C -- "scoped" --> D2["includeAllWindows = false"]
    D & D2 --> F["buildListSurfacesPayload\n-> buildTreePayload (system.tree RPC)"]
    F --> G["treePayloadWithMarkers\n(normalises active surface_ref -> surface.active)"]
    G --> H["flattenTreeSurfaces\n(terminalOnly filter, active matching)"]
    H --> I{--json?}
    I -- yes --> J["print(jsonString)"]
    I -- no --> K["renderListSurfacesText\n(active marker, context, tty, URL)"]
Loading

Reviews (14): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

Comment thread Resources/Localizable.xcstrings Outdated
Comment thread CLI/cmux.swift Outdated
Comment thread CLI/cmux.swift
coderabbitai[bot]
coderabbitai Bot previously requested changes May 26, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CLI/cmux.swift`:
- Around line 12388-12421: The one-line usage synopses for the "list-surfaces"
and "list-terminals" cases (localized keys "cli.help.listSurfaces" and
"cli.help.listTerminals" in the switch handling those commands) are missing the
--json flag; update the triple-quoted defaultValue usage lines in those case
blocks to include " --json" in the Usage: synopsis so the short help matches the
detailed Flags section and accepts the --json option in the summary.
- Around line 14073-14085: The code builds a flattened row but never sets the
"active" key, yet later logic checks row["active"] to render the active marker;
update the flattening to populate that field from an existing tree-state field
(e.g., use pane["focused"] or surface["selected"] / surface["focused"] depending
on which upstream field represents the active surface) by calling
copyTreeListValue(into: &row, key: "active", from: pane["focused"] ??
surface["selected"] ?? surface["focused"]); ensure the "active" key is set on
the same row variable that is appended to result so the text renderer can mark
the active surface.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fdda1b97-1469-49a8-8f3f-a32283ef6139

📥 Commits

Reviewing files that changed from the base of the PR and between b9f2298 and bf7072b.

📒 Files selected for processing (4)
  • CLI/cmux.swift
  • Resources/Localizable.xcstrings
  • cmuxTests/CLINotifyProcessIntegrationRegressionTests.swift
  • docs/cli-contract.md

Comment thread CLI/cmux.swift
Comment thread CLI/cmux.swift Outdated
Comment thread CLI/CMUXCLI+ListSurfaces.swift Outdated
@austinywang
austinywang dismissed coderabbitai[bot]’s stale review May 26, 2026 09:57

Stale CodeRabbit review from bf7072b. The two actionable threads were fixed and resolved, and the latest CodeRabbit status is green on e44e609.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8451793. Configure here.

Comment thread CLI/CMUXCLI+ListSurfaces.swift Outdated
coderabbitai[bot]
coderabbitai Bot previously requested changes Jun 6, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CLI/CMUXCLI`+ListSurfaces.swift:
- Around line 46-59: The current check only looks for the literal flag in
rem0/rem1; instead validate the parsed option values returned by parseOption:
after let (workspaceOpt, rem0) = parseOption(...) throw the missing-handle
CLIError if workspaceOpt is nil OR workspaceOpt is an empty string OR
workspaceOpt starts(with: "-") (same for windowOpt/rem1). Update the checks for
workspaceOpt and windowOpt (not rem0/rem1.contains) to detect empty or flag-like
values and raise the existing CLIError with commandName and the flag name
("--workspace"/"--window").
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 520c5fdf-d738-4ca1-856a-a8829413c942

📥 Commits

Reviewing files that changed from the base of the PR and between 67544dd and 8451793.

📒 Files selected for processing (2)
  • CLI/CMUXCLI+ListSurfaces.swift
  • CLI/cmux.swift
💤 Files with no reviewable changes (1)
  • CLI/cmux.swift

Comment thread CLI/CMUXCLI+ListSurfaces.swift
@austinywang
austinywang dismissed coderabbitai[bot]’s stale review June 6, 2026 09:30

Dismissed after CodeRabbit marked the scoped-handle validation thread addressed on head commit 19b6a93; fix is committed and thread has an acknowledgement reply.

Comment thread CLI/CMUXCLI+ListSurfaces.swift
# Conflicts:
#	.github/swift-file-length-budget.tsv
@lawrencecchen lawrencecchen added the stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening. label Sep 23, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in cmux backlog Sep 23, 2026

This branch was successfully deployed

1 active deployment
Preview – cmux — 4a606138 Deployed Jun 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants