Remove index-based CLI APIs, make commands workspace-relative

Merged
LA
9mo ago
+673-418

Summary

  • Migrate 14 CLI commands from v1 text protocol to v2 JSON-RPC, making all commands workspace-relative via CMUX_WORKSPACE_ID env var fallback
  • Update 7 more commands to use normalize functions instead of legacy index-based resolvers
  • Remove dead code: 5 structs, 5 parsers, 3 utility functions (net -117 lines in cmux.swift)
  • Add regression tests for workspace-relative behavior and id-format defaults

Motivation

When Claude Code runs cmux send "echo hello" from a background workspace, the text currently goes to whichever workspace the user is looking at (v1 resolves to tabManager.selectedTabId). After this change, commands use the caller's CMUX_WORKSPACE_ID by default, targeting the correct workspace.

Commands migrated v1→v2 (14)

CommandV2 MethodNew flags
sendsurface.send_text--workspace, --surface
send-keysurface.send_key--workspace, --surface
send-panelsurface.send_text--workspace
send-key-panelsurface.send_key--workspace
new-splitsurface.split--workspace, --surface
new-panepane.create--workspace
new-surfacesurface.create--workspace
close-surfacesurface.close--workspace
list-panespane.list--workspace
list-pane-surfacespane.surfaces--workspace
list-panelssurface.listenv fallback
surface-healthsurface.healthenv fallback
focus-panepane.focus--workspace
focus-panelsurface.focus--workspace

Commands updated (7)

move-workspace-to-window, list-workspaces, close-workspace, select-workspace, trigger-flash, resolveWorkspaceId, resolveSurfaceId — switched from v1 parsers to normalize functions with ref handle support.

Dead code removed

  • Structs: WorkspaceInfo, PanelInfo, PaneInfo, PaneSurfaceInfo, SurfaceHealthInfo
  • Parsers: parseWorkspaces, parsePanels, parsePanes, parsePaneSurfaces, parseSurfaceHealth
  • Functions: formatLegacySurfaceResponse, escapeText, remainingArgs

Test plan

  • xcodebuild CLI target builds successfully
  • Run tests_v2/test_workspace_relative.py on VM
  • Run tests_v2/test_cli_id_format_defaults.py on VM
  • Manual smoke test: cmux send, cmux list-panes, cmux new-split right from terminal inside cmux
  • Verify CMUX_WORKSPACE_ID env var scopes commands correctly