[PR #1765] Fix plugin loading to support JavaScript files and improve error handling #10049

Open
opened 2026-02-16 18:14:37 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1765
Author: @rmoriz
Created: 8/9/2025
Status: 🔄 Open

Base: devHead: fix-plugin-search-path


📝 Commits (3)

  • 219a307 Fix plugin loading to support JavaScript files and improve error handling
  • 9ef08e0 Add comprehensive tests for plugin loading system
  • b42715c Fix TypeScript issues in plugin test fixtures and improve syntax error test

📊 Changes

10 files changed (+343 additions, -15 deletions)

View changed files

.opencode/plugin/say-notification.js (+17 -0)
.opencode/plugin/say-notification.ts (+19 -0)
.opencode/plugin/test-js.js (+12 -0)
📝 packages/opencode/src/config/config.ts (+2 -2)
📝 packages/opencode/src/plugin/index.ts (+31 -4)
packages/opencode/test/fixtures/plugins/invalid-plugins.ts (+14 -0)
packages/opencode/test/fixtures/plugins/valid-js.js (+21 -0)
packages/opencode/test/fixtures/plugins/valid-ts.ts (+21 -0)
packages/opencode/test/plugin.test.ts (+201 -0)
📝 packages/web/src/content/docs/docs/plugins.mdx (+5 -9)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1765 **Author:** [@rmoriz](https://github.com/rmoriz) **Created:** 8/9/2025 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix-plugin-search-path` --- ### 📝 Commits (3) - [`219a307`](https://github.com/anomalyco/opencode/commit/219a30776dc26b2ae4c7f681a149f9e3e9b1c9b3) Fix plugin loading to support JavaScript files and improve error handling - [`9ef08e0`](https://github.com/anomalyco/opencode/commit/9ef08e00184536ce4d04148cf8218dde1b088ee2) Add comprehensive tests for plugin loading system - [`b42715c`](https://github.com/anomalyco/opencode/commit/b42715ce8ba549bfb9a19ff92b972906da398310) Fix TypeScript issues in plugin test fixtures and improve syntax error test ### 📊 Changes **10 files changed** (+343 additions, -15 deletions) <details> <summary>View changed files</summary> ➕ `.opencode/plugin/say-notification.js` (+17 -0) ➕ `.opencode/plugin/say-notification.ts` (+19 -0) ➕ `.opencode/plugin/test-js.js` (+12 -0) 📝 `packages/opencode/src/config/config.ts` (+2 -2) 📝 `packages/opencode/src/plugin/index.ts` (+31 -4) ➕ `packages/opencode/test/fixtures/plugins/invalid-plugins.ts` (+14 -0) ➕ `packages/opencode/test/fixtures/plugins/valid-js.js` (+21 -0) ➕ `packages/opencode/test/fixtures/plugins/valid-ts.ts` (+21 -0) ➕ `packages/opencode/test/plugin.test.ts` (+201 -0) 📝 `packages/web/src/content/docs/docs/plugins.mdx` (+5 -9) </details> ### 📄 Description ## 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](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10049