Skip to content

Bug: getPluginName incorrectly deduplicates plugins with same entry filename (index.js) #12285

@cpkt9762

Description

@cpkt9762

多个插件的入口文件都是 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

  1. 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"
]
  1. Both oh-my-opencode and opencode-openai-codex-auth are installed in ~/.config/opencode/node_modules/

  2. Run opencode debug config

  3. 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.jsoh-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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions