diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index bf4a6035bd8..98226d967e1 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -331,17 +331,23 @@ export namespace Config { /** * Extracts a canonical plugin name from a plugin specifier. - * - For file:// URLs: extracts filename without extension + * - For file:// URLs: extracts filename without extension (or parent dir for index.ts) * - For npm packages: extracts package name without version * * @example * getPluginName("file:///path/to/plugin/foo.js") // "foo" + * getPluginName("file:///path/to/my-plugin/index.ts") // "my-plugin" * getPluginName("oh-my-opencode@2.4.3") // "oh-my-opencode" * getPluginName("@scope/pkg@1.0.0") // "@scope/pkg" */ export function getPluginName(plugin: string): string { if (plugin.startsWith("file://")) { - return path.parse(new URL(plugin).pathname).name + const parsed = path.parse(new URL(plugin).pathname) + // Use parent directory name if file is index.ts/index.js to avoid collisions + if (parsed.name === "index") { + return path.basename(parsed.dir) + } + return parsed.name } const lastAt = plugin.lastIndexOf("@") if (lastAt > 0) {