diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 4f77920cc98..fbc97d9c748 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 c6d7fbc1e4b..ed5f8bd0173 100644 --- a/packages/opencode/src/tool/registry.ts +++ b/packages/opencode/src/tool/registry.ts @@ -45,9 +45,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(pathToFileURL(match).href) - for (const [id, def] of Object.entries(mod)) { - custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def)) + try { + const mod = await import(pathToFileURL(match).href) + 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 706a9e12caf..11569c1b6e6 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") },