Fix: Support custom module agent compilation in rebuildAgentFiles()

- Check module's own agents directory first for custom modules
- Fall back to installer source for built-in modules
- Fixes custom module agent compilation issue in alpha versions

This change enables rebuildAgentFiles() to properly compile agents
from custom modules by first checking the module's own agents/
directory for .agent.yaml files. If found, it uses those files
directly. Otherwise, it falls back to the installer source directory
for built-in modules (core, bmm, bmb, etc.).

Tested with custom module 'po' (Prompt Optimizer) - agents compile
successfully and slash commands are generated correctly.
This commit is contained in:
hunter6028 2025-11-24 19:24:00 +08:00
parent 9d510fc075
commit 4fd7bba8f0
1 changed files with 17 additions and 5 deletions

View File

@ -1466,12 +1466,24 @@ class Installer {
* @param {string} moduleName - Module name
*/
async rebuildAgentFiles(modulePath, moduleName) {
// Get source agents directory from installer
const sourceAgentsPath =
moduleName === 'core' ? path.join(getModulePath('core'), 'agents') : path.join(getSourcePath(`modules/${moduleName}`), 'agents');
// First try module's own agents directory (for custom modules)
let sourceAgentsPath = path.join(modulePath, 'agents');
if (!(await fs.pathExists(sourceAgentsPath))) {
return; // No source agents to rebuild
// Check if module has its own .agent.yaml files
let hasOwnAgents = false;
if (await fs.pathExists(sourceAgentsPath)) {
const files = await fs.readdir(sourceAgentsPath);
hasOwnAgents = files.some(f => f.endsWith('.agent.yaml'));
}
// If no agents in module directory, try installer source (for built-in modules)
if (!hasOwnAgents) {
sourceAgentsPath =
moduleName === 'core' ? path.join(getModulePath('core'), 'agents') : path.join(getSourcePath(`modules/${moduleName}`), 'agents');
if (!(await fs.pathExists(sourceAgentsPath))) {
return; // No source agents to rebuild
}
}
// Determine project directory (parent of bmad/ directory)