Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4463,7 +4463,7 @@ struct CMUXCLI {
}

let windowRaw = windowOpt ?? windowId
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(sfArg, windowRaw: windowRaw)
let surfaceArg = sfArg ?? (wsArg == nil && windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] : nil)

var params: [String: Any] = [:]
Expand Down Expand Up @@ -4498,7 +4498,7 @@ struct CMUXCLI {
let (sfArg, rem1) = parseOption(rem0, name: "--surface")
let (windowOpt, rem2) = parseOption(rem1, name: "--window")
let windowRaw = windowOpt ?? windowId
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(sfArg, windowRaw: windowRaw)
let surfaceArg = sfArg ?? (wsArg == nil && windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] : nil)
let rawText = rem2.dropFirst(rem2.first == "--" ? 1 : 0).joined(separator: " ")
guard !rawText.isEmpty else { throw CLIError(message: "send requires text") }
Expand All @@ -4518,7 +4518,7 @@ struct CMUXCLI {
let (sfArg, rem1) = parseOption(rem0, name: "--surface")
let (windowOpt, rem2) = parseOption(rem1, name: "--window")
let windowRaw = windowOpt ?? windowId
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(sfArg, windowRaw: windowRaw)
let surfaceArg = sfArg ?? (wsArg == nil && windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] : nil)
let keyArgs = rem2.first == "--" ? Array(rem2.dropFirst()) : rem2
guard let key = keyArgs.first else { throw CLIError(message: "send-key requires a key") }
Expand All @@ -4537,10 +4537,10 @@ struct CMUXCLI {
let (panelArg, rem1) = parseOption(rem0, name: "--panel")
let (windowOpt, rem2) = parseOption(rem1, name: "--window")
let windowRaw = windowOpt ?? windowId
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
guard let panelArg else {
throw CLIError(message: "send-panel requires --panel")
}
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(panelArg, windowRaw: windowRaw)
let rawText = rem2.dropFirst(rem2.first == "--" ? 1 : 0).joined(separator: " ")
guard !rawText.isEmpty else { throw CLIError(message: "send-panel requires text") }
let text = unescapeSendText(rawText)
Expand All @@ -4559,10 +4559,10 @@ struct CMUXCLI {
let (panelArg, rem1) = parseOption(rem0, name: "--panel")
let (windowOpt, rem2) = parseOption(rem1, name: "--window")
let windowRaw = windowOpt ?? windowId
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
guard let panelArg else {
throw CLIError(message: "send-key-panel requires --panel")
}
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(panelArg, windowRaw: windowRaw)
let skpArgs = rem2.first == "--" ? Array(rem2.dropFirst()) : rem2
let key = skpArgs.first ?? ""
guard !key.isEmpty else { throw CLIError(message: "send-key-panel requires a key") }
Expand Down Expand Up @@ -6108,17 +6108,17 @@ struct CMUXCLI {
if let workspaceHandle {
params["workspace_id"] = workspaceHandle
}
if let windowHandle {
params["window_id"] = windowHandle
}
let listed = try client.sendV2(method: "surface.list", params: params)
let items = listed["surfaces"] as? [[String: Any]] ?? []
for item in items where intFromAny(item["index"]) == wantedIndex {
return (item["id"] as? String) ?? (item["ref"] as? String)
}
throw CLIError(message: "Surface index not found")
}

private static func callerWorkspaceForSurfaceHandle(_ raw: String?, windowRaw: String?) -> String? {
let trimmed = raw?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
return windowRaw == nil && (trimmed.isEmpty || Int(trimmed) != nil) ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil
}
private func validateSurfaceHandleInWindow(
_ surfaceHandle: String,
client: SocketClient,
Expand Down Expand Up @@ -22453,7 +22453,7 @@ struct CMUXCLI {
let (windowOpt, rem2) = parseOption(rem1, name: "--window")
let (linesArg, rem3) = parseOption(rem2, name: "--lines")
let windowRaw = windowOpt ?? windowOverride
let workspaceArg = wsArg ?? (windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
let workspaceArg = wsArg ?? Self.callerWorkspaceForSurfaceHandle(sfArg, windowRaw: windowRaw)
let surfaceArg = sfArg ?? (wsArg == nil && windowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] : nil)

var params: [String: Any] = [:]
Expand Down Expand Up @@ -22516,7 +22516,7 @@ struct CMUXCLI {
let (windowOpt, pipeRem2) = parseOption(pipeRem1, name: "--window")
let (cmdOpt, pipeRem3) = parseOption(pipeRem2, name: "--command")
let effectiveWindowRaw = windowOpt ?? windowOverride
let workspaceArg = workspaceOpt ?? (effectiveWindowRaw == nil ? ProcessInfo.processInfo.environment["CMUX_WORKSPACE_ID"] : nil)
let workspaceArg = workspaceOpt ?? Self.callerWorkspaceForSurfaceHandle(surfaceArg, windowRaw: effectiveWindowRaw)
let commandText: String = {
if let cmdOpt { return cmdOpt }
let trimmed = pipeRem3.dropFirst(pipeRem3.first == "--" ? 1 : 0).joined(separator: " ").trimmingCharacters(in: .whitespacesAndNewlines)
Expand All @@ -22525,11 +22525,11 @@ struct CMUXCLI {
guard !commandText.isEmpty else {
throw CLIError(message: "pipe-pane requires --command <shell-command>")
}

var params: [String: Any] = ["scrollback": true]
let winId = try normalizeWindowHandle(effectiveWindowRaw, client: client)
if let winId { params["window_id"] = winId }
let wsId = try normalizeWorkspaceHandle(workspaceArg, client: client, windowHandle: winId, allowCurrent: winId == nil)
let allowCurrentWorkspace = winId == nil && (surfaceArg.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.map { $0.isEmpty || Int($0) != nil } ?? true)
let wsId = try normalizeWorkspaceHandle(workspaceArg, client: client, windowHandle: winId, allowCurrent: allowCurrentWorkspace)
if let wsId { params["workspace_id"] = wsId }
let sfId = try normalizeSurfaceHandle(surfaceArg, client: client, workspaceHandle: wsId, windowHandle: winId, allowFocused: true)
if let sfId { params["surface_id"] = sfId }
Expand Down
4 changes: 4 additions & 0 deletions cmux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
A9F200000000000000000015 /* ClaudeStreamJSONAccumulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9F100000000000000000015 /* ClaudeStreamJSONAccumulator.swift */; };
A5D4120DA1B2C3D4E5F60718 /* CLIAuthAliasTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5D4120EA1B2C3D4E5F60718 /* CLIAuthAliasTests.swift */; };
C0D3F1F00000000000000103 /* CLICodexHookTimeoutRegressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0D3F1F00000000000000104 /* CLICodexHookTimeoutRegressionTests.swift */; };
E295EA3753206FE3FFCA6C0A /* CLIExplicitSurfaceRoutingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1590EE4F01FEF02D40A48698 /* CLIExplicitSurfaceRoutingTests.swift */; };
C46790000000000000000001 /* CLIForwardingLaunchArgumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46790000000000000000002 /* CLIForwardingLaunchArgumentTests.swift */; };
C46790000000000000000003 /* CLIForwardingLaunchRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C46790000000000000000004 /* CLIForwardingLaunchRouter.swift */; };
A5D41207A1B2C3D4E5F60718 /* CLIGenericHookPersistenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5D41208A1B2C3D4E5F60718 /* CLIGenericHookPersistenceTests.swift */; };
Expand Down Expand Up @@ -1288,6 +1289,7 @@
A9F100000000000000000015 /* ClaudeStreamJSONAccumulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/ClaudeStreamJSONAccumulator.swift; sourceTree = "<group>"; };
A5D4120EA1B2C3D4E5F60718 /* CLIAuthAliasTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIAuthAliasTests.swift; sourceTree = "<group>"; };
C0D3F1F00000000000000104 /* CLICodexHookTimeoutRegressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLICodexHookTimeoutRegressionTests.swift; sourceTree = "<group>"; };
1590EE4F01FEF02D40A48698 /* CLIExplicitSurfaceRoutingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIExplicitSurfaceRoutingTests.swift; sourceTree = "<group>"; };
C46790000000000000000002 /* CLIForwardingLaunchArgumentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIForwardingLaunchArgumentTests.swift; sourceTree = "<group>"; };
C46790000000000000000004 /* CLIForwardingLaunchRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App/CLIForwardingLaunchRouter.swift; sourceTree = "<group>"; };
A5D41208A1B2C3D4E5F60718 /* CLIGenericHookPersistenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIGenericHookPersistenceTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3164,6 +3166,7 @@
C46790000000000000000002 /* CLIForwardingLaunchArgumentTests.swift */,
C46790000000000000000008 /* RosettaNativeRelaunchTests.swift */,
C0DE31390000000000000102 /* CMUXOpenCommandTests.swift */,
1590EE4F01FEF02D40A48698 /* CLIExplicitSurfaceRoutingTests.swift */,
C0DE31390000000000000106 /* CMUXCLIErrorOutputRegressionTests.swift */,
C0DE64950000000000000006 /* CMUXCLISessionsListTests.swift */,
C0DE64950000000000000004 /* CMUXCLITestAssertions.swift */,
Expand Down Expand Up @@ -4491,6 +4494,7 @@
A5D41222A1B2C3D4E5F60718 /* ClaudeNotificationStatusLifecycleTests.swift in Sources */,
A5D4120DA1B2C3D4E5F60718 /* CLIAuthAliasTests.swift in Sources */,
C0D3F1F00000000000000103 /* CLICodexHookTimeoutRegressionTests.swift in Sources */,
E295EA3753206FE3FFCA6C0A /* CLIExplicitSurfaceRoutingTests.swift in Sources */,
C46790000000000000000001 /* CLIForwardingLaunchArgumentTests.swift in Sources */,
A5D41207A1B2C3D4E5F60718 /* CLIGenericHookPersistenceTests.swift in Sources */,
A5D41211A1B2C3D4E5F60718 /* CLIHookNoResponseTests.swift in Sources */,
Expand Down
Loading
Loading