fix(opencode): load custom tools that import .txt descriptions - #50304
Open
csalvarado wants to merge 1 commit into
Open
csalvarado wants to merge 1 commit into
csalvarado wants to merge 1 commit into
Conversation
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.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #48112
Type of change
What does this PR do?
Custom tools placed in
.opencode/tool/*.tsare imported at runtime. A custom tool that mirrors the built-in convention of importing a.txtdescription file failed to load, because the built-in tools'.txtimports are inlined by the build while runtime module loaders reject the extension (Node:ERR_UNKNOWN_FILE_EXTENSION). The failed import aborted the wholeToolRegistrystate, so every prompt in the session failed.Two changes in
packages/opencode/src/tool/registry.ts:.txtimport failure, a Node module hook is registered that serves.txtas a module whose default export is the file contents, then the import is retried. Bun already resolves.txtnatively, so the hook only engages on Node.How did you verify your code works?
bun test test/tool/registry.test.tsinpackages/opencode(17 pass; two new tests: one asserts a failing tool is skipped while the others load, one asserts a.txtdescription is loaded).registry.tschange makes the new isolation test fail with the reported error.bun typecheck.Screenshots / recordings
No UI changes.
Checklist