| 70 | } |
| 71 | |
| 72 | _loadPlugin(pluginDir) { |
| 73 | const manifestPath = path.join(pluginDir, 'plugin.json'); |
| 74 | if (!fs.existsSync(manifestPath)) return; |
| 75 | |
| 76 | try { |
| 77 | const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8')); |
| 78 | const plugin = { |
| 79 | name: manifest.name || path.basename(pluginDir), |
| 80 | version: manifest.version || '0.0.0', |
| 81 | description: manifest.description || '', |
| 82 | dir: pluginDir, |
| 83 | }; |
| 84 | |
| 85 | // Register tools |
| 86 | if (manifest.tools) { |
| 87 | for (const toolDef of manifest.tools) { |
| 88 | const handlerPath = path.resolve(pluginDir, toolDef.handler || './handler.js'); |
| 89 | let handler = null; |
| 90 | if (fs.existsSync(handlerPath)) { |
| 91 | try { handler = require(handlerPath); } catch {} |
| 92 | } |
| 93 | this.tools.push({ |
| 94 | type: 'function', |
| 95 | function: { |
| 96 | name: toolDef.name, |
| 97 | description: toolDef.description || '', |
| 98 | parameters: toolDef.parameters || { type: 'object', properties: {} }, |
| 99 | }, |
| 100 | // Underscore-prefixed fields are consumed by executor.js when it |
| 101 | // dispatches plugin tool calls. The model never sees these. |
| 102 | _handler: handler, |
| 103 | _plugin: plugin.name, |
| 104 | }); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Register commands |
| 109 | if (manifest.commands) { |
| 110 | for (const cmdDef of manifest.commands) { |
| 111 | const handlerPath = path.resolve(pluginDir, cmdDef.handler || './cmd.js'); |
| 112 | let handler = null; |
| 113 | if (fs.existsSync(handlerPath)) { |
| 114 | try { handler = require(handlerPath); } catch {} |
| 115 | } |
| 116 | this.commands[cmdDef.name] = { |
| 117 | description: cmdDef.description || '', |
| 118 | handler, |
| 119 | plugin: plugin.name, |
| 120 | }; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Register prompt injections |
| 125 | if (manifest.prompts) { |
| 126 | for (const p of manifest.prompts) { |
| 127 | this.prompts.push({ |
| 128 | inject: p.inject || 'always', // "always", "backend", "coding", "debugging" |
| 129 | content: p.content || '', |