opencode
opencode copied to clipboard
Fix plugin loading to support JavaScript files and improve error handling
Summary
Fixes user reports of plugins not loading by adding JavaScript support and improving error handling in the plugin system. Should fix #1473
Changes
🎯 JavaScript Plugin Support
- Updated plugin discovery glob patterns from
plugin/*.tstoplugin/*.{ts,js} - Both global (
~/.config/opencode/plugin/) and project (.opencode/plugin/) directories now support JS files - Resolves discrepancy where documentation showed JavaScript examples but only TypeScript files were loaded
🛡️ Improved Error Handling
- Replaced try/catch blocks with functional error handling using
Promise.catch() - Added validation for non-function exports to prevent loading invalid plugins
- Implemented resilient loading where one broken plugin doesn't prevent others from loading
- Enhanced error logging with plugin path and specific error details
📚 Documentation Fix
- Corrected hook structure example in documentation to use flat format (
"tool.execute.before") - Previously showed nested object structure that didn't match actual implementation
🔍 Better Debugging
- Added comprehensive logging for each step of plugin initialization
- Clear error messages when plugins fail to import or initialize
- Success confirmations when plugins load correctly
Testing
- All typechecks pass
- Plugin loading logic refactored without breaking existing functionality
- Error handling tested with both valid and invalid plugin scenarios
Impact
This resolves the core issues preventing plugins from working:
- JavaScript plugins now load - Matches documented behavior
- Better error visibility - Users can see exactly why plugins fail
- Robust loading - Plugin system doesn't crash on individual plugin failures
- Accurate documentation - Examples now work as written
Fixes plugin loading issues reported by users where plugins weren't being discovered or loaded properly.
🤖 Generated with opencode
Very much needed fix, as I faced the issue with JavaScript plugin loading myself. I created a plugin following the official docs but it didn't work. Debugging this issue is quite challenging because the logs don't provide any useful information even with DEBUG level.