Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ jobs:
CmuxControlSocket
CmuxFoundation
CmuxGit
CmuxOrchestration
CmuxSettings
CmuxSettingsUI
CmuxTerminal
Expand Down
77 changes: 77 additions & 0 deletions CLI/CMUXCLI+OptionParsing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Foundation

/// Shared per-command flag/option parsing helpers, extracted verbatim from
/// `cmux.swift` (which may not grow). All of them stop interpreting flags at
/// the `--` terminator so forwarded arguments pass through untouched.
extension CMUXCLI {
func parseOption(_ args: [String], name: String) -> (String?, [String]) {
var remaining: [String] = []
var value: String?
var skipNext = false
var pastTerminator = false
for (idx, arg) in args.enumerated() {
if skipNext {
skipNext = false
continue
}
if arg == "--" {
pastTerminator = true
remaining.append(arg)
continue
}
if !pastTerminator, arg.hasPrefix("\(name)=") {
value = String(arg.dropFirst(name.count + 1))
continue
}
if !pastTerminator, arg == name, idx + 1 < args.count {
value = args[idx + 1]
skipNext = true
continue
}
remaining.append(arg)
}
return (value, remaining)
}

func parseRepeatedOption(_ args: [String], name: String) -> ([String], [String]) {
var remaining: [String] = []
var values: [String] = []
var skipNext = false
var pastTerminator = false
for (idx, arg) in args.enumerated() {
if skipNext {
skipNext = false
continue
}
if arg == "--" {
pastTerminator = true
remaining.append(arg)
continue
}
if !pastTerminator, arg == name, idx + 1 < args.count {
values.append(args[idx + 1])
skipNext = true
continue
}
remaining.append(arg)
}
return (values, remaining)
}

func optionValue(_ args: [String], name: String) -> String? {
for (index, arg) in args.enumerated() {
if arg == "--" { return nil }
if arg == name, index + 1 < args.count {
return args[index + 1]
}
if arg.hasPrefix("\(name)=") {
return String(arg.dropFirst(name.count + 1))
}
}
return nil
}

func hasFlag(_ args: [String], name: String) -> Bool {
args.contains(name)
}
Comment on lines +74 to +76

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Stop flag detection at the -- terminator.

hasFlag contradicts the documented parser contract and treats forwarded arguments as cmux flags. For example, a post-terminator --yes still bypasses the orchestration trust prompt.

Proposed fix
 func hasFlag(_ args: [String], name: String) -> Bool {
-    args.contains(name)
+    args.prefix { $0 != "--" }.contains(name)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func hasFlag(_ args: [String], name: String) -> Bool {
args.contains(name)
}
func hasFlag(_ args: [String], name: String) -> Bool {
args.prefix { $0 != "--" }.contains(name)
}
🤖 Prompt for 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.

In `@CLI/CMUXCLI`+OptionParsing.swift around lines 74 - 76, Update hasFlag to
inspect only arguments before the standalone "--" terminator, so flags appearing
afterward are treated as forwarded arguments rather than cmux options. Preserve
existing exact flag matching for pre-terminator arguments and return false when
the requested flag occurs only after "--".

}
Loading
Loading