Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
233 changes: 233 additions & 0 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3375,6 +3375,13 @@ struct CMUXCLI {
)
print(response)

case "right-sidebar":
try forwardRightSidebarCommand(
commandArgs: commandArgs,
client: client,
windowOverride: windowId
)

case "claude-hook":
cliTelemetry.breadcrumb("claude-hook.dispatch")
do {
Expand Down Expand Up @@ -9942,6 +9949,34 @@ struct CMUXCLI {
cmux sidebar-state
cmux sidebar-state --workspace workspace:2
"""
case "right-sidebar":
return String(localized: "cli.rightSidebar.usage", defaultValue: """
Usage: cmux right-sidebar <command> [flags]

Control the right sidebar from the CLI.

Commands:
toggle Toggle right sidebar visibility
show Show the right sidebar
hide Hide the right sidebar
focus Focus the current right sidebar mode
set <files|find|vault|sessions|feed|dock>
Show, switch mode, and focus
mode Print {"visible":bool,"mode":string}
files|find|vault|sessions|feed|dock
Alias for show + set + focus

Flags:
--workspace <id|ref|index> Target the window containing a workspace
--window <id|ref|index> Target a window
--no-focus With set, switch mode without moving focus

Examples:
cmux right-sidebar toggle
cmux right-sidebar set find
cmux right-sidebar set vault --no-focus
cmux right-sidebar mode
""")
case "set-app-focus":
return """
Usage: cmux set-app-focus <active|inactive|clear>
Expand Down Expand Up @@ -10256,6 +10291,203 @@ struct CMUXCLI {
return try sendV1Command(command, client: client)
}

private struct RightSidebarCLIArguments {
let positional: [String]
let workspace: String?
let window: String?
let noFocus: Bool
}

private func forwardRightSidebarCommand(
commandArgs: [String],
client: SocketClient,
windowOverride: String?
) throws {
let parsed = try parseRightSidebarCLIArguments(commandArgs)
let windowId = try resolveRightSidebarWindowId(parsed.window ?? windowOverride, client: client)
let workspaceId = try resolveRightSidebarWorkspaceId(parsed.workspace, windowId: windowId, client: client)
let socketArgs = try rightSidebarSocketArguments(from: parsed)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

var forwardedArgs = socketArgs
if let workspaceId {
forwardedArgs.append("--tab=\(workspaceId)")
}
if let windowId {
forwardedArgs.append("--window=\(windowId)")
}

let command = (["right_sidebar"] + forwardedArgs)
.map(shellQuote)
.joined(separator: " ")
let response = try sendV1Command(command, client: client)
if parsed.positional.first?.lowercased() == "mode" {
print(response)
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
}

private func parseRightSidebarCLIArguments(_ args: [String]) throws -> RightSidebarCLIArguments {
var positional: [String] = []
var workspace: String?
var window: String?
var noFocus = false
var index = 0

while index < args.count {
let arg = args[index]
switch arg {
case "--workspace":
guard index + 1 < args.count else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.workspaceRequiresValue", defaultValue: "right-sidebar: --workspace requires an id"))
}
workspace = args[index + 1]
index += 2
case "--window":
guard index + 1 < args.count else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.windowRequiresValue", defaultValue: "right-sidebar: --window requires an id"))
}
window = args[index + 1]
index += 2
case "--no-focus":
noFocus = true
index += 1
default:
if arg.hasPrefix("--workspace=") {
workspace = String(arg.dropFirst("--workspace=".count))
index += 1
} else if arg.hasPrefix("--window=") {
window = String(arg.dropFirst("--window=".count))
index += 1
} else if arg.hasPrefix("--") {
throw CLIError(message: String(localized: "cli.rightSidebar.error.unknownFlag", defaultValue: "right-sidebar: unknown flag '\(arg)'"))
} else {
positional.append(arg)
index += 1
}
}
}

return RightSidebarCLIArguments(
positional: positional,
workspace: workspace,
window: window,
noFocus: noFocus
)
}

private func rightSidebarSocketArguments(from parsed: RightSidebarCLIArguments) throws -> [String] {
guard let action = parsed.positional.first?.lowercased() else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.missingCommand", defaultValue: "right-sidebar requires a subcommand"))
}

switch action {
case "toggle", "show", "hide", "focus", "mode":
guard parsed.positional.count == 1 else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.unexpectedArguments", defaultValue: "right-sidebar \(action) received unexpected arguments"))
}
guard !parsed.noFocus else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.noFocusOnlySet", defaultValue: "right-sidebar: --no-focus is only valid with set"))
}
return [action]

case "set":
guard parsed.positional.count == 2 else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.setRequiresMode", defaultValue: "right-sidebar set requires a mode: files, find, vault, sessions, feed, or dock"))
}
var args = ["set", parsed.positional[1]]
if parsed.noFocus {
args.append("--no-focus")
}
return args
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

case "files", "find", "vault", "sessions", "feed", "dock":
guard parsed.positional.count == 1 else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.unexpectedArguments", defaultValue: "right-sidebar \(action) received unexpected arguments"))
}
guard !parsed.noFocus else {
throw CLIError(message: String(localized: "cli.rightSidebar.error.noFocusOnlySet", defaultValue: "right-sidebar: --no-focus is only valid with set"))
}
return ["set", action]

default:
throw CLIError(message: String(localized: "cli.rightSidebar.error.unknownCommand", defaultValue: "Unknown right-sidebar command '\(action)'"))
}
}

private func resolveRightSidebarWindowId(_ raw: String?, client: SocketClient) throws -> String? {
guard let raw else { return nil }
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return nil }
if isUUID(trimmed) { return trimmed }

let listed = try client.sendV2(method: "window.list")
let windows = listed["windows"] as? [[String: Any]] ?? []
if let refIndex = handleIndex(trimmed, kind: "window") {
return try idFromIndexedItems(
windows,
index: refIndex,
missingMessage: String(localized: "cli.rightSidebar.error.windowRefNotFound", defaultValue: "Window ref not found")
)
}
if let index = Int(trimmed) {
return try idFromIndexedItems(
windows,
index: index,
missingMessage: String(localized: "cli.rightSidebar.error.windowIndexNotFound", defaultValue: "Window index not found")
)
}
throw CLIError(message: String(localized: "cli.rightSidebar.error.invalidWindow", defaultValue: "Invalid window handle: \(trimmed)"))
}

private func resolveRightSidebarWorkspaceId(
_ raw: String?,
windowId: String?,
client: SocketClient
) throws -> String? {
guard let raw else { return nil }
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return nil }
if isUUID(trimmed) { return trimmed }

var params: [String: Any] = [:]
if let windowId {
params["window_id"] = windowId
}
let listed = try client.sendV2(method: "workspace.list", params: params)
let workspaces = listed["workspaces"] as? [[String: Any]] ?? []
if let refIndex = handleIndex(trimmed, kind: "workspace") {
return try idFromIndexedItems(
workspaces,
index: refIndex,
missingMessage: String(localized: "cli.rightSidebar.error.workspaceRefNotFound", defaultValue: "Workspace ref not found")
)
}
if let index = Int(trimmed) {
return try idFromIndexedItems(
workspaces,
index: index,
missingMessage: String(localized: "cli.rightSidebar.error.workspaceIndexNotFound", defaultValue: "Workspace index not found")
)
}
throw CLIError(message: String(localized: "cli.rightSidebar.error.invalidWorkspace", defaultValue: "Invalid workspace handle: \(trimmed)"))
}

private func handleIndex(_ value: String, kind: String) -> Int? {
let pieces = value.split(separator: ":", omittingEmptySubsequences: false)
guard pieces.count == 2, pieces[0].lowercased() == kind else { return nil }
return Int(pieces[1])
}

private func idFromIndexedItems(
_ items: [[String: Any]],
index: Int,
missingMessage: String
) throws -> String {
for item in items where intFromAny(item["index"]) == index {
if let id = item["id"] as? String { return id }
}
throw CLIError(message: missingMessage)
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

/// Pick the display handle for an item dict based on --id-format.
private func textHandle(_ item: [String: Any], idFormat: CLIIDFormat) -> String {
let ref = item["ref"] as? String
Expand Down Expand Up @@ -20758,6 +20990,7 @@ export default function cmuxPiSessionExtension(pi: ExtensionAPI) {
notify --title <text> [--subtitle <text>] [--body <text>] [--workspace <id|ref>] [--surface <id|ref>]
list-notifications
clear-notifications
right-sidebar <toggle|show|hide|focus|set|mode|files|find|vault|sessions|feed|dock> [--workspace <id|ref|index>] [--window <id|ref|index>] [--no-focus]
set-status <key> <value> [--workspace <id|ref>] [--icon <name>] [--color <#hex>]
clear-status <key> [--workspace <id|ref>]
list-status [--workspace <id|ref>]
Expand Down
Loading
Loading