fix: detect and warn about opencode-skills conflict

When opencode-skills plugin is registered alongside oh-my-openagent,
all user skills are loaded twice, causing 'Duplicate tool names detected'
warnings and HTTP 400 errors.

This fix:
1. Detects if opencode-skills plugin is loaded in opencode.json
2. Emits a startup warning explaining the conflict
3. Suggests fixes: either remove opencode-skills or disable skills in oh-my-openagent

Fixes #2881
This commit is contained in:
User
2026-03-27 13:21:08 +01:00
parent 324dbb119c
commit 787ce99eda
3 changed files with 299 additions and 1 deletions
+147
View File
@@ -24,6 +24,16 @@ const KNOWN_NOTIFICATION_PLUGINS = [
"mohak34/opencode-notifier",
]
/**
* Known skill plugins that conflict with oh-my-opencode's skill loading.
* Both plugins scan ~/.config/opencode/skills/ and register tools independently,
* causing "Duplicate tool names detected" warnings and HTTP 400 errors.
*/
const KNOWN_SKILL_PLUGINS = [
"opencode-skills",
"@opencode/skills",
]
function getWindowsAppdataDir(): string | null {
return process.env.APPDATA || null
}
@@ -88,12 +98,68 @@ function matchesNotificationPlugin(entry: string): string | null {
return null
}
/**
* Check if a plugin entry matches a known skill plugin.
* Handles various formats: "name", "name@version", "npm:name", "file://path/name"
*/
function matchesSkillPlugin(entry: string): string | null {
const normalized = entry.toLowerCase()
for (const known of KNOWN_SKILL_PLUGINS) {
// Exact match
if (normalized === known) return known
// Version suffix: "opencode-skills@1.2.3"
if (normalized.startsWith(`${known}@`)) return known
// npm: prefix
if (normalized === `npm:${known}` || normalized.startsWith(`npm:${known}@`)) return known
// file:// path ending exactly with package name
if (normalized.startsWith("file://") && (
normalized.endsWith(`/${known}`) ||
normalized.endsWith(`\\${known}`)
)) return known
}
return null
}
/**
* Check if a plugin entry matches a known skill plugin.
* Handles various formats: "name", "name@version", "npm:name", "file://path/name"
*/
function matchesSkillPlugin(entry: string): string | null {
const normalized = entry.toLowerCase()
for (const known of KNOWN_SKILL_PLUGINS) {
// Exact match
if (normalized === known) return known
// Version suffix: "opencode-skills@1.2.3"
if (normalized.startsWith(`${known}@`)) return known
// npm: prefix
if (normalized === `npm:${known}` || normalized.startsWith(`npm:${known}@`)) return known
// file:// path ending exactly with package name
if (normalized.startsWith("file://") && (
normalized.endsWith(`/${known}`) ||
normalized.endsWith(`\\${known}`)
)) return known
}
return null
}
export interface ExternalNotifierResult {
detected: boolean
pluginName: string | null
allPlugins: string[]
}
export interface ExternalSkillPluginResult {
detected: boolean
pluginName: string | null
allPlugins: string[]
}
export interface ExternalSkillPluginResult {
detected: boolean
pluginName: string | null
allPlugins: string[]
}
/**
* Detect if any external notification plugin is configured.
* Returns information about detected plugins for logging/warning.
@@ -120,6 +186,58 @@ export function detectExternalNotificationPlugin(directory: string): ExternalNot
}
}
/**
* Detect if any external skill plugin is configured.
* Returns information about detected plugins for logging/warning.
*/
export function detectExternalSkillPlugin(directory: string): ExternalSkillPluginResult {
const plugins = loadOpencodePlugins(directory)
for (const plugin of plugins) {
const match = matchesSkillPlugin(plugin)
if (match) {
log(`Detected external skill plugin: ${plugin}`)
return {
detected: true,
pluginName: match,
allPlugins: plugins,
}
}
}
return {
detected: false,
pluginName: null,
allPlugins: plugins,
}
}
/**
* Detect if any external skill plugin is configured.
* Returns information about detected plugins for logging/warning.
*/
export function detectExternalSkillPlugin(directory: string): ExternalSkillPluginResult {
const plugins = loadOpencodePlugins(directory)
for (const plugin of plugins) {
const match = matchesSkillPlugin(plugin)
if (match) {
log(`Detected external skill plugin: ${plugin}`)
return {
detected: true,
pluginName: match,
allPlugins: plugins,
}
}
}
return {
detected: false,
pluginName: null,
allPlugins: plugins,
}
}
/**
* Generate a warning message for users with conflicting notification plugins.
*/
@@ -135,3 +253,32 @@ Both oh-my-opencode and ${pluginName} listen to session.idle events.
1. Remove ${pluginName} from your opencode.json plugins
2. Or set "notification": { "force_enable": true } in oh-my-opencode.json`
}
/**
* Generate a warning message for users with conflicting skill plugins.
*/
export function getSkillPluginConflictWarning(pluginName: string): string {
return `[oh-my-opencode] External skill plugin detected: ${pluginName}
Both oh-my-opencode and ${pluginName} scan ~/.config/opencode/skills/ and register tools independently.
Running both simultaneously causes "Duplicate tool names detected" warnings and HTTP 400 errors.
Consider either:
1. Remove ${pluginName} from your opencode.json plugins to use oh-my-opencode's skill loading
2. Or disable oh-my-opencode's skill loading by setting "claude_code.skills": false in oh-my-opencode.json
3. Or uninstall oh-my-opencode if you prefer ${pluginName}'s skill management`
}
/**
* Generate a warning message for users with conflicting skill plugins.
*/
export function getSkillPluginConflictWarning(pluginName: string): string {
return `[oh-my-openagent] WARNING: External skill plugin detected: ${pluginName}
Both oh-my-openagent and ${pluginName} scan ~/.config/opencode/skills/ and register tools.
Running both simultaneously causes "Duplicate tool names detected" errors.
To fix this issue, either:
1. Remove ${pluginName} from your opencode.json plugins
2. Or disable skills in oh-my-openagent by setting "claude_code": { "skills": false } in oh-my-openagent.json`
}