Skip to content

fix(opencode): load custom tools that import .txt descriptions - #50304

Open
csalvarado wants to merge 1 commit into
anomalyco:devfrom
csalvarado:tool-txt-support
Open

csalvarado wants to merge 1 commit into
anomalyco:devfrom
csalvarado:tool-txt-support

Conversation

@csalvarado

Copy link
Copy Markdown

Issue for this PR

Closes #48112

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Custom tools placed in .opencode/tool/*.ts are imported at runtime. A custom tool that mirrors the built-in convention of importing a .txt description file failed to load, because the built-in tools' .txt imports are inlined by the build while runtime module loaders reject the extension (Node: ERR_UNKNOWN_FILE_EXTENSION). The failed import aborted the whole ToolRegistry state, so every prompt in the session failed.

Two changes in packages/opencode/src/tool/registry.ts:

  • A custom tool whose import fails is now logged and skipped; the rest of the registry keeps loading.
  • On the first .txt import failure, a Node module hook is registered that serves .txt as a module whose default export is the file contents, then the import is retried. Bun already resolves .txt natively, so the hook only engages on Node.

How did you verify your code works?

  • bun test test/tool/registry.test.ts in packages/opencode (17 pass; two new tests: one asserts a failing tool is skipped while the others load, one asserts a .txt description is loaded).
  • Reverting the registry.ts change makes the new isolation test fail with the reported error.
  • bun typecheck.

Screenshots / recordings

No UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Custom tools are imported at runtime, where module loaders reject .txt (Node: ERR_UNKNOWN_FILE_EXTENSION) even though built-in tools rely on the build inlining them. A failing import also took down the whole registry and every prompt in the session (anomalyco#48112).

- Skip a custom tool whose import fails, log the error, and keep loading the rest of the registry.
- On the first .txt import failure, register a Node module hook that serves .txt as a module exporting the file contents, then retry.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom tools in .opencode/tool that import .txt descriptions fail at runtime: ERR_UNKNOWN_FILE_EXTENSION

1 participant