The open source coding agent.
TypeScript
core: improve plugin loading to handle builtin plugin failures gracefully
Dax Raad038cff4a93bb
diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.tsindex 18a621fbbdc..9b9d3266a9c 100644--- a/packages/opencode/src/plugin/index.ts+++ b/packages/opencode/src/plugin/index.ts@@ -11,6 +11,8 @@ import { Flag } from "../flag/flag"export namespace Plugin {const log = Log.create({ service: "plugin" })+ const BUILTIN = ["[email protected]", "[email protected]"]+const state = Instance.state(async () => {const client = createOpencodeClient({baseUrl: "http://localhost:4096",@@ -29,8 +31,7 @@ export namespace Plugin {}const plugins = [...(config.plugin ?? [])]if (!Flag.OPENCODE_DISABLE_DEFAULT_PLUGINS) {- plugins.push("[email protected]")- plugins.push("[email protected]")+ plugins.push(...BUILTIN)}for (let plugin of plugins) {log.info("loading plugin", { path: plugin })@@ -38,7 +39,11 @@ export namespace Plugin {const lastAtIndex = plugin.lastIndexOf("@")const pkg = lastAtIndex > 0 ? plugin.substring(0, lastAtIndex) : pluginconst version = lastAtIndex > 0 ? plugin.substring(lastAtIndex + 1) : "latest"- plugin = await BunProc.install(pkg, version)+ plugin = await BunProc.install(pkg, version).catch((err) => {+ if (BUILTIN.includes(pkg)) return ""+ throw err+ })+ if (!plugin) continue}const mod = await import(plugin)for (const [_name, fn] of Object.entries<PluginInstance>(mod)) {