Skip to content
Closed
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
58 changes: 39 additions & 19 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11825,7 +11825,8 @@ struct CMUXCLI {
}
}

private static let omoPluginName = "oh-my-opencode"
private static let omoPluginName = "oh-my-openagent"
private static let legacyOmoPluginName = "oh-my-opencode"
private static let openCodeSessionPluginConfigSpec = "./plugins/cmux-session.js"

private func resolveExecutableInPath(_ name: String) -> String? {
Expand Down Expand Up @@ -11868,7 +11869,7 @@ struct CMUXCLI {

// Keep the shadow package isolated from stale/yanked pins in the user's
// opencode package.json. bun will update this manifest with the resolved
// oh-my-opencode version when installation succeeds.
// version when installation succeeds.
let packageManifest: [String: Any] = [
"dependencies": [
Self.omoPluginName: "latest"
Expand Down Expand Up @@ -12012,7 +12013,7 @@ struct CMUXCLI {
return "4096"
}

/// Creates a shadow config directory that layers oh-my-opencode on top of the user's
/// Creates a shadow config directory that layers the plugin on top of the user's
/// existing opencode config without modifying the original. Sets OPENCODE_CONFIG_DIR
/// to point at the shadow directory.
private func omoEnsurePlugin() throws {
Expand All @@ -12037,7 +12038,8 @@ struct CMUXCLI {
}

var plugins = Self.openCodePluginListRemovingSessionPlugin((config["plugin"] as? [Any]) ?? [])
if !Self.openCodePluginListContains(plugins, spec: Self.omoPluginName, allowVersionSuffix: true) {
if !Self.openCodePluginListContains(plugins, spec: Self.omoPluginName, allowVersionSuffix: true)
&& !Self.openCodePluginListContains(plugins, spec: Self.legacyOmoPluginName, allowVersionSuffix: true) {
plugins.append(Self.omoPluginName)
}
config["plugin"] = plugins
Expand All @@ -12061,8 +12063,9 @@ struct CMUXCLI {

try writeOpenCodeSessionPlugin(in: shadowDir)

// Copy oh-my-opencode plugin config (jsonc) if the user has one
for filename in ["oh-my-opencode.json", "oh-my-opencode.jsonc"] {
// Copy plugin config (jsonc) if the user has one — check both legacy and current names
for filename in ["oh-my-openagent.json", "oh-my-openagent.jsonc",
"oh-my-opencode.json", "oh-my-opencode.jsonc"] {
Comment on lines +12067 to +12068

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Use Self.omoPluginName / Self.legacyOmoPluginName constants instead of hardcoded string literals

The new constants are defined in hunk 1 but are then bypassed by hardcoded literals scattered across four sites. If the plugin name changes again the constants would be updated but these literals would silently diverge.

♻️ Proposed fix — replace literals with constants
-        for filename in ["oh-my-openagent.json", "oh-my-openagent.jsonc",
-                         "oh-my-opencode.json", "oh-my-opencode.jsonc"] {
+        for filename in ["\(Self.omoPluginName).json", "\(Self.omoPluginName).jsonc",
+                         "\(Self.legacyOmoPluginName).json", "\(Self.legacyOmoPluginName).jsonc"] {
-        let omoConfigURL = shadowDir.appendingPathComponent("oh-my-openagent.json")
+        let omoConfigURL = shadowDir.appendingPathComponent("\(Self.omoPluginName).json")
-            let candidate = shadowDir.appendingPathComponent("oh-my-opencode.json")
+            let candidate = shadowDir.appendingPathComponent("\(Self.legacyOmoPluginName).json")
-            let userOmoConfigURLs = [
-                userDir.appendingPathComponent("oh-my-openagent.json"),
-                userDir.appendingPathComponent("oh-my-opencode.json")
-            ]
+            let userOmoConfigURLs = [
+                userDir.appendingPathComponent("\(Self.omoPluginName).json"),
+                userDir.appendingPathComponent("\(Self.legacyOmoPluginName).json")
+            ]

Also applies to: 12121-12121, 12127-12127, 12136-12138

🤖 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/cmux.swift` around lines 12067 - 12068, Replace the hardcoded filenames
("oh-my-openagent.json", "oh-my-openagent.jsonc", "oh-my-opencode.json",
"oh-my-opencode.jsonc") with uses of the new constants by constructing filenames
from Self.omoPluginName and Self.legacyOmoPluginName plus the extensions
(".json" and ".jsonc"); e.g. use "\(Self.omoPluginName).json",
"\(Self.omoPluginName).jsonc", "\(Self.legacyOmoPluginName).json",
"\(Self.legacyOmoPluginName).jsonc" wherever those four literals appear
(including the for-loop array and the other occurrences mentioned) so the code
consistently uses the defined constants.

Comment on lines +12067 to +12068

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 Hardcoded legacy name diverges from legacyOmoPluginName constant

The file-copy loop uses the literal "oh-my-opencode" string instead of Self.legacyOmoPluginName. The same pattern appears inside the IIFE on line 12127 (shadowDir.appendingPathComponent("oh-my-opencode.json")). If the legacy name ever changes again, these two sites would need to be updated manually and are easy to miss — the whole value of the new constant is to have a single source of truth.

let userFile = userDir.appendingPathComponent(filename)
let shadowFile = shadowDir.appendingPathComponent(filename)
if fm.fileExists(atPath: userFile.path) && !fm.fileExists(atPath: shadowFile.path) {
Expand All @@ -12075,15 +12078,15 @@ struct CMUXCLI {
if !fm.fileExists(atPath: pluginPackageDir.path) {
let installDir = shadowDir
if let bunPath = resolveExecutableInPath("bun") {
FileHandle.standardError.write("Installing oh-my-opencode plugin (this may take a minute on first run)...\n".data(using: .utf8)!)
FileHandle.standardError.write("Installing \(Self.omoPluginName) plugin (this may take a minute on first run)...\n".data(using: .utf8)!)
let installArguments = ["add", Self.omoPluginName]
let firstAttemptStatus = try omoRunPackageInstall(
executablePath: bunPath,
arguments: installArguments,
currentDirectoryURL: installDir
)
if firstAttemptStatus != 0 {
FileHandle.standardError.write("Retrying oh-my-opencode install with a clean shadow package state...\n".data(using: .utf8)!)
FileHandle.standardError.write("Retrying \(Self.omoPluginName) install with a clean shadow package state...\n".data(using: .utf8)!)
try? fm.removeItem(at: shadowBunLockURL)
try? fm.removeItem(at: shadowNodeModules)
try omoEnsureShadowNodeModulesSymlink(shadowNodeModules: shadowNodeModules, userNodeModules: userNodeModules)
Expand All @@ -12093,39 +12096,56 @@ struct CMUXCLI {
currentDirectoryURL: installDir
)
if retryStatus != 0 {
throw CLIError(message: "Failed to install oh-my-opencode. Try manually: npm install -g oh-my-opencode")
throw CLIError(message: "Failed to install \(Self.omoPluginName). Try manually: npm install -g \(Self.omoPluginName)")
}
}
} else if let npmPath = resolveExecutableInPath("npm") {
FileHandle.standardError.write("Installing oh-my-opencode plugin (this may take a minute on first run)...\n".data(using: .utf8)!)
FileHandle.standardError.write("Installing \(Self.omoPluginName) plugin (this may take a minute on first run)...\n".data(using: .utf8)!)
let status = try omoRunPackageInstall(
executablePath: npmPath,
arguments: ["install", Self.omoPluginName],
currentDirectoryURL: installDir
)
if status != 0 {
throw CLIError(message: "Failed to install oh-my-opencode. Try manually: npm install -g oh-my-opencode")
throw CLIError(message: "Failed to install \(Self.omoPluginName). Try manually: npm install -g \(Self.omoPluginName)")
}
} else {
throw CLIError(message: "Neither bun nor npm found in PATH. Install oh-my-opencode manually: bunx oh-my-opencode install")
throw CLIError(message: "Neither bun nor npm found in PATH. Install \(Self.omoPluginName) manually: bunx \(Self.omoPluginName) install")
}
FileHandle.standardError.write("oh-my-opencode plugin installed\n".data(using: .utf8)!)
FileHandle.standardError.write("\(Self.omoPluginName) plugin installed\n".data(using: .utf8)!)
Comment on lines 12081 to +12115

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 Ad-hoc stderr writes bypass unified logging

Every FileHandle.standardError.write(...) call in this block is raw stderr output, sidestepping os_log/Logger. This violates the project's unified-logging rule (no print/ad-hoc file/stdout logging in production Swift). These lines were pre-existing but are being actively modified by this PR, making them in-scope. The install progress messages should route through a Logger subsystem and category so they appear in Console.app, are filterable, and don't mix with other process output.

Rule Used: Flag production Swift diagnostics that bypass unif... (source)

}

// Ensure tmux mode is enabled in oh-my-opencode config.
// Ensure tmux mode is enabled in the plugin config.
// Without this, the TmuxSessionManager won't spawn visual panes even though
// $TMUX is set (tmux.enabled defaults to false).
let omoConfigURL = shadowDir.appendingPathComponent("oh-my-opencode.json")
let omoConfigURL = shadowDir.appendingPathComponent("oh-my-openagent.json")
var omoConfig: [String: Any]
if let data = try? Data(contentsOf: omoConfigURL),
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
omoConfig = existing
} else if let legacyURL = { () -> URL? in
let candidate = shadowDir.appendingPathComponent("oh-my-opencode.json")
return fm.fileExists(atPath: candidate.path) ? candidate : nil
}(),
let data = try? Data(contentsOf: legacyURL),
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
omoConfig = existing
} else {
// Check if user has a config we symlinked, read from source
let userOmoConfig = userDir.appendingPathComponent("oh-my-opencode.json")
if let data = try? Data(contentsOf: userOmoConfig),
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
omoConfig = existing
let userOmoConfigURLs = [
userDir.appendingPathComponent("oh-my-openagent.json"),
userDir.appendingPathComponent("oh-my-opencode.json")
]
var found: [String: Any]?
for url in userOmoConfigURLs {
if let data = try? Data(contentsOf: url),
let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
found = existing
break
}
}
if let found {
omoConfig = found
// Remove the symlink so we can write our own copy
try? fm.removeItem(at: omoConfigURL)
Comment on lines +12139 to 12150

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix SwiftLint discouraged_optional_collection warning on var found: [String: Any]?

SwiftLint 0.63.2 flags this as a discouraged_optional_collection violation. The mutable optional can be replaced with a single lazy.compactMap.first expression, which also eliminates the var and the break.

♻️ Proposed fix
-            var found: [String: Any]?
-            for url in userOmoConfigURLs {
-                if let data = try? Data(contentsOf: url),
-                   let existing = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
-                    found = existing
-                    break
-                }
-            }
-            if let found {
+            let found = userOmoConfigURLs.lazy.compactMap { url -> [String: Any]? in
+                guard let data = try? Data(contentsOf: url) else { return nil }
+                return try? JSONSerialization.jsonObject(with: data) as? [String: Any]
+            }.first
+            if let found {
                 omoConfig = found
                 // Remove the symlink so we can write our own copy
                 try? fm.removeItem(at: omoConfigURL)
🧰 Tools
🪛 SwiftLint (0.63.2)

[Warning] 12139-12139: Prefer empty collection over optional collection

(discouraged_optional_collection)

🤖 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/cmux.swift` around lines 12139 - 12150, The mutable optional collection
"found" flagged by SwiftLint (discouraged_optional_collection) should be
replaced by a single immutable lookup: compute a let found =
userOmoConfigURLs.lazy.compactMap { url in if let data = try? Data(contentsOf:
url), let existing = try? JSONSerialization.jsonObject(with: data) as? [String:
Any] { return existing } else { return nil } }.first and then use if let found {
omoConfig = found; try? fm.removeItem(at: omoConfigURL) } so you remove the
var/loop/break and keep the same behavior for omoConfig and fm.removeItem(at:
omoConfigURL).

} else {
Expand Down
Loading