多个插件的入口文件都是 index.js 时,getPluginName 函数只提取文件名,导致它们被错误地视为重复插件而被去重
Bug Description
When multiple plugins are resolved to file:// URLs with the same entry filename (e.g., index.js), the getPluginName function incorrectly identifies them as duplicates, causing some plugins to be silently dropped.
Steps to Reproduce
- Configure multiple plugins in
~/.config/opencode/opencode.json:
"plugin": [
"oh-my-opencode@latest",
"opencode-anthropic-auth@0.0.13",
"opencode-antigravity-auth@1.4.3",
"opencode-openai-codex-auth"
]
-
Both oh-my-opencode and opencode-openai-codex-auth are installed in ~/.config/opencode/node_modules/
-
Run opencode debug config
-
Observe that oh-my-opencode is missing from the plugin list
Root Cause
In packages/opencode/src/config/config.ts, the getPluginName function extracts only the filename for file:// URLs:
export function getPluginName(plugin: string): string {
if (plugin.startsWith("file://")) {
return path.parse(new URL(plugin).pathname).name // Returns "index" for both plugins!
}
// ...
}
When plugins are resolved via import.meta.resolve, they become:
file:///...node_modules/oh-my-opencode/dist/index.js → name: index
file:///...node_modules/opencode-openai-codex-auth/dist/index.js → name: index
Since both have the same name index, deduplicatePlugins treats them as duplicates and keeps only one.
Suggested Fix
Extract the package name from the node_modules path:
export function getPluginName(plugin: string): string {
if (plugin.startsWith("file://")) {
const pathname = new URL(plugin).pathname
// Extract package name from node_modules path
const nodeModulesMatch = pathname.match(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/)
if (nodeModulesMatch) {
return nodeModulesMatch[1]
}
return path.parse(pathname).name
}
// ...
}
This correctly extracts:
file:///...node_modules/oh-my-opencode/dist/index.js → oh-my-opencode
file:///...node_modules/@scope/pkg/dist/index.js → @scope/pkg
Workaround
Reorder plugins so the one you want to keep is listed last:
"plugin": [
"opencode-anthropic-auth@0.0.13",
"opencode-antigravity-auth@1.4.3",
"opencode-openai-codex-auth",
"oh-my-opencode@latest"
]
Environment
- OpenCode version: 1.1.49
- OS: macOS (Apple Silicon)
多个插件的入口文件都是 index.js 时,getPluginName 函数只提取文件名,导致它们被错误地视为重复插件而被去重
Bug Description
When multiple plugins are resolved to
file://URLs with the same entry filename (e.g.,index.js), thegetPluginNamefunction incorrectly identifies them as duplicates, causing some plugins to be silently dropped.Steps to Reproduce
~/.config/opencode/opencode.json:Both
oh-my-opencodeandopencode-openai-codex-authare installed in~/.config/opencode/node_modules/Run
opencode debug configObserve that
oh-my-opencodeis missing from the plugin listRoot Cause
In
packages/opencode/src/config/config.ts, thegetPluginNamefunction extracts only the filename forfile://URLs:When plugins are resolved via
import.meta.resolve, they become:file:///...node_modules/oh-my-opencode/dist/index.js→ name:indexfile:///...node_modules/opencode-openai-codex-auth/dist/index.js→ name:indexSince both have the same name
index,deduplicatePluginstreats them as duplicates and keeps only one.Suggested Fix
Extract the package name from the
node_modulespath:This correctly extracts:
file:///...node_modules/oh-my-opencode/dist/index.js→oh-my-opencodefile:///...node_modules/@scope/pkg/dist/index.js→@scope/pkgWorkaround
Reorder plugins so the one you want to keep is listed last:
Environment