Repository navigation
fix: prevent cmux omo legacy plugin warning loop #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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? { | ||
|
|
@@ -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" | ||
|
|
@@ -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 { | ||
|
|
@@ -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 | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The file-copy loop uses the literal |
||
| let userFile = userDir.appendingPathComponent(filename) | ||
| let shadowFile = shadowDir.appendingPathComponent(filename) | ||
| if fm.fileExists(atPath: userFile.path) && !fm.fileExists(atPath: shadowFile.path) { | ||
|
|
@@ -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) | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix SwiftLint SwiftLint 0.63.2 flags this as a ♻️ 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 |
||
| } else { | ||
|
|
||
There was a problem hiding this comment.
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.legacyOmoPluginNameconstants instead of hardcoded string literalsThe 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
Also applies to: 12121-12121, 12127-12127, 12136-12138
🤖 Prompt for AI Agents