Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cmux-owned Swift file length budget.
# Format: max_lines<TAB>relative path
# Reduce counts as files shrink. CI fails if tracked files exceed this budget.
18705 CLI/cmux.swift
18761 CLI/cmux.swift
16364 Sources/TerminalController.swift
15762 Sources/ContentView.swift
13748 Sources/AppDelegate.swift
Expand Down
56 changes: 56 additions & 0 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,8 @@ struct CMUXCLI {
"set-buffer",
"paste-buffer",
"list-buffers",
"list-clients",
"list-sessions",
"respawn-pane",
"display-message":
try runTmuxCompatCommand(
Expand Down Expand Up @@ -11578,6 +11580,12 @@ struct CMUXCLI {
let canonicalWorkspaceId = try resolveWorkspaceId(workspaceId, client: client)
var context: [String: String] = [
"session_name": "cmux",
"session_attached": "1",
"session_id": "@\(canonicalWorkspaceId)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Wrong prefix for session_id fallback value

session_id is initialized to "@\(canonicalWorkspaceId)" — the @ sigil is tmux's window-ID prefix, not a session-ID prefix (which uses $). When no matching workspace is found in workspaceItems (so the if let index branch never executes), the context emits a malformed session ID. Callers that parse #{session_id} and validate the sigil — including omx's session-attached check — will fail silently.

Suggested change
"session_id": "@\(canonicalWorkspaceId)",
"session_id": "$\(canonicalWorkspaceId)",

"session_index": "",
"client_name": "cmux",
"client_attached": "1",
"client_tty": "",
"window_id": "@\(canonicalWorkspaceId)",
"window_uuid": canonicalWorkspaceId
]
Expand All @@ -11588,6 +11596,8 @@ struct CMUXCLI {
}) {
if let index = intFromAny(workspace["index"]) {
context["window_index"] = String(index)
context["session_index"] = String(index)
context["session_id"] = "$\(index)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Accept generated session IDs as -t targets

tmuxFormatContext now emits session_id values like $1, but workspace target resolution does not accept the $ prefix (it only normalizes @/index/title forms). In workflows that chain tmux-compatible commands (e.g. capture #{session_id} from list-sessions and pass it back via -t), this regresses into Workspace target not found even though the ID came from the shim itself. Either emit a resolvable value here or extend target parsing to normalize $ session IDs.

Useful? React with 👍 / 👎.

}
let title = ((workspace["title"] as? String) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
if !title.isEmpty {
Expand Down Expand Up @@ -13229,6 +13239,16 @@ struct CMUXCLI {
print(tmuxRenderFormat(parsed.value("-F"), context: context, fallback: fallback))
}

case "list-clients", "list-sessions":
try runTmuxCompatCommand(
command: command,
commandArgs: rawArgs,
client: client,
jsonOutput: jsonOutput,
idFormat: idFormat,
windowOverride: windowOverride
)

case "rename-window", "renamew":
let parsed = try parseTmuxArguments(rawArgs, valueFlags: ["-t"], boolFlags: [])
let title = parsed.positional.joined(separator: " ").trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down Expand Up @@ -13939,6 +13959,42 @@ struct CMUXCLI {
}
}

case "list-clients":
let parsed = try parseTmuxArguments(commandArgs, valueFlags: ["-F", "-t"], boolFlags: [])
let workspaceId = try {
if let target = parsed.value("-t") {
return try tmuxResolveWorkspaceTarget(target, client: client)
}
if let windowOverride {
return try resolveWorkspaceId(windowOverride, client: client)
}
return try resolveWorkspaceId(nil, client: client)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 var context never mutated — use let

context is assigned once from tmuxFormatContext and never modified afterward; declaring it var is misleading. Use let to match the pattern used in the list-sessions block directly below.

Suggested change
return try resolveWorkspaceId(nil, client: client)
let context = try tmuxFormatContext(workspaceId: workspaceId, client: client)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}()
let context = try tmuxFormatContext(workspaceId: workspaceId, client: client)
let fallback = [
context["client_name"] ?? "cmux",
context["session_name"] ?? "cmux",
context["client_attached"] ?? "1"
].joined(separator: "|")
print(tmuxRenderFormat(parsed.value("-F"), context: context, fallback: fallback))

case "list-sessions":
let parsed = try parseTmuxArguments(commandArgs, valueFlags: ["-F", "-t"], boolFlags: [])
let targetWorkspaceId: String? = try {
if let target = parsed.value("-t") {
return try tmuxResolveWorkspaceTarget(target, client: client)
}
return nil
}()
let workspaceItems = try tmuxWorkspaceItems(client: client)
for item in workspaceItems {
guard let workspaceId = item["id"] as? String else { continue }
if let targetWorkspaceId, workspaceId != targetWorkspaceId { continue }
let context = try tmuxFormatContext(workspaceId: workspaceId, client: client)
let fallback = context["session_name"] ?? context["window_name"] ?? workspaceId
print(tmuxRenderFormat(parsed.value("-F"), context: context, fallback: fallback))
}

Comment on lines +13983 to +13997

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 N+1 tmuxWorkspaceItems calls in list-sessions

tmuxWorkspaceItems is called once to obtain the loop items, and then tmuxFormatContext calls it again for every iteration (it fetches workspace items internally to populate window_index, session_index, etc.). For N sessions this issues N+1 round-trips to the cmux daemon, which will be noticeable when there are many workspaces. Consider passing the already-fetched items into tmuxFormatContext via an optional parameter, or enriching the context directly inside the loop using the item already in hand.

case "paste-buffer":
let workspaceArg = workspaceFromArgsOrEnv(commandArgs, windowOverride: windowOverride)
let surfaceArg = optionValue(commandArgs, name: "--surface")
Expand Down
Loading