diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 43ad9a09d399..3bb4c4d0c615 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -331,7 +331,7 @@ export namespace SessionPrompt { modelID: lastUser.model.modelID, providerID: lastUser.model.providerID, history: msgs, - }) + }).catch(() => {}) const model = await Provider.getModel(lastUser.model.providerID, lastUser.model.modelID).catch((e) => { if (Provider.ModelNotFoundError.isInstance(e)) { diff --git a/packages/opencode/src/tool/registry.ts b/packages/opencode/src/tool/registry.ts index 3ff9cce8990f..56f8785d7c67 100644 --- a/packages/opencode/src/tool/registry.ts +++ b/packages/opencode/src/tool/registry.ts @@ -41,9 +41,13 @@ export namespace ToolRegistry { if (matches.length) await Config.waitForDependencies() for (const match of matches) { const namespace = path.basename(match, path.extname(match)) - const mod = await import(match) - for (const [id, def] of Object.entries(mod)) { - custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def)) + try { + const mod = await import(match) + for (const [id, def] of Object.entries(mod)) { + custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def)) + } + } catch (e) { + log.warn("failed to load custom tool", { path: match, error: e }) } } diff --git a/packages/opencode/test/tool/registry.test.ts b/packages/opencode/test/tool/registry.test.ts index 706a9e12caf9..11569c1b6e61 100644 --- a/packages/opencode/test/tool/registry.test.ts +++ b/packages/opencode/test/tool/registry.test.ts @@ -114,6 +114,7 @@ describe("tool.registry", () => { await Instance.provide({ directory: tmp.path, fn: async () => { + // registry should not crash; tool registers even with missing deps const ids = await ToolRegistry.ids() expect(ids).toContain("cowsay") },