opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Fix plugin loading to support JavaScript files and improve error handling

Open rmoriz opened this issue 4 months ago • 1 comments

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/*.ts to plugin/*.{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:

  1. JavaScript plugins now load - Matches documented behavior
  2. Better error visibility - Users can see exactly why plugins fail
  3. Robust loading - Plugin system doesn't crash on individual plugin failures
  4. 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

rmoriz avatar Aug 09 '25 22:08 rmoriz

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.

imajus avatar Aug 12 '25 10:08 imajus