From 350688df67335a932b7bd9ba914640b46453e5e3 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 26 Apr 2026 15:53:36 -0500 Subject: [PATCH] fix(installer): resolve url-source custom modules from custom-modules cache (#2323) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(installer): resolve url-source custom modules from custom-modules cache resolveInstalledModuleYaml previously only searched ~/.bmad/cache/external-modules/, so modules installed via --custom-source (cached at ~/.bmad/cache/custom-modules////) could not be located on re-install runs. This caused warnings during npx bmad-method install: [warn] collectAgentsFromModuleYaml: could not locate module.yaml for '' [warn] writeCentralConfig: could not locate module.yaml for '' Adds a fallback that walks the custom-modules cache via _findCacheRepoRoots (identifying repo roots by .bmad-source.json or .claude-plugin/, not marketplace.json, so direct-mode modules are also covered), reuses the same searchRoot candidate-path logic, and matches by the discovered yaml's code or name field. Works without needing _resolutionCache to be populated, which fixes the re-install scenario where no --custom-source flag is passed. Closes #2312 * fix(installer): enumerate all module.yamls when walking custom-modules cache A url-source custom-modules repo can host multiple plugins in discovery mode (e.g. skills/module-a/module.yaml and skills/module-b/module.yaml). The previous walk used searchRoot which returned only the first match, so asking for module-b would surface module-a's yaml, fail the code/name check, and skip the repo entirely — never inspecting module-b. Splits the candidate-path traversal into searchRootAll (returns every module.yaml in priority order) and a thin searchRoot wrapper for the existing single-module fallbacks. The custom-modules walk now iterates every yaml per repo and matches each against code or name. --- tools/installer/project-root.js | 63 ++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/tools/installer/project-root.js b/tools/installer/project-root.js index 123bd5978..f883c8a2e 100644 --- a/tools/installer/project-root.js +++ b/tools/installer/project-root.js @@ -1,5 +1,6 @@ const path = require('node:path'); const os = require('node:os'); +const yaml = require('yaml'); const fs = require('./fs-native'); /** @@ -86,8 +87,11 @@ function getExternalModuleCachePath(moduleName, ...segments) { * Built-in modules (core, bmm) live under . External official modules are * cloned into ~/.bmad/cache/external-modules// with varying internal * layouts (some at src/module.yaml, some at skills/module.yaml, some nested). - * Local custom-source modules are not cached; their path is read from the - * CustomModuleManager resolution cache set during the same install run. + * Url-source custom modules are cloned into ~/.bmad/cache/custom-modules//// + * and are resolved by walking the cache and matching `code` or `name` from the + * discovered module.yaml. Local custom-source modules are not cached; their + * path is read from the CustomModuleManager resolution cache set during the + * same install run. * This mirrors the candidate-path search in * ExternalModuleManager.findExternalModuleSource but performs no git/network * work, which keeps it safe to call during manifest writing. @@ -99,11 +103,14 @@ async function resolveInstalledModuleYaml(moduleName) { const builtIn = path.join(getModulePath(moduleName), 'module.yaml'); if (await fs.pathExists(builtIn)) return builtIn; - // Search a resolved root directory using the same candidate-path pattern. - async function searchRoot(root) { + // Collect every module.yaml under a root using the standard candidate paths. + // Url-source repos can host multiple plugins (discovery mode), so we need all + // matches, not just the first. Returned in priority order. + async function searchRootAll(root) { + const results = []; for (const dir of ['skills', 'src']) { const direct = path.join(root, dir, 'module.yaml'); - if (await fs.pathExists(direct)) return direct; + if (await fs.pathExists(direct)) results.push(direct); const dirPath = path.join(root, dir); if (await fs.pathExists(dirPath)) { @@ -111,7 +118,7 @@ async function resolveInstalledModuleYaml(moduleName) { for (const entry of entries) { if (!entry.isDirectory()) continue; const nested = path.join(dirPath, entry.name, 'module.yaml'); - if (await fs.pathExists(nested)) return nested; + if (await fs.pathExists(nested)) results.push(nested); } } } @@ -121,12 +128,19 @@ async function resolveInstalledModuleYaml(moduleName) { for (const entry of rootEntries) { if (!entry.isDirectory() || !entry.name.endsWith('-setup')) continue; const setupAssets = path.join(root, entry.name, 'assets', 'module.yaml'); - if (await fs.pathExists(setupAssets)) return setupAssets; + if (await fs.pathExists(setupAssets)) results.push(setupAssets); } const atRoot = path.join(root, 'module.yaml'); - if (await fs.pathExists(atRoot)) return atRoot; - return null; + if (await fs.pathExists(atRoot)) results.push(atRoot); + return results; + } + + // Backwards-compatible single-result variant for the existing external-cache + // and resolution-cache fallbacks (one module per root by construction). + async function searchRoot(root) { + const all = await searchRootAll(root); + return all.length > 0 ? all[0] : null; } const cacheRoot = getExternalModuleCachePath(moduleName); @@ -150,6 +164,37 @@ async function resolveInstalledModuleYaml(moduleName) { // Resolution cache unavailable — continue } + // Fallback: url-source custom modules cloned to ~/.bmad/cache/custom-modules/. + // Walk every cached repo, enumerate ALL module.yaml files via searchRootAll + // (a single repo can host multiple plugins in discovery mode), and match by + // the yaml's `code` or `name` field. This works on re-install runs where + // _resolutionCache is empty and covers both discovery-mode (with marketplace.json) + // and direct-mode modules, since we identify repo roots by .bmad-source.json + // (written by cloneRepo) or .claude-plugin/ rather than by marketplace.json. + try { + const customCacheDir = path.join(os.homedir(), '.bmad', 'cache', 'custom-modules'); + if (await fs.pathExists(customCacheDir)) { + const { CustomModuleManager } = require('./modules/custom-module-manager'); + const customMgr = new CustomModuleManager(); + const repoRoots = await customMgr._findCacheRepoRoots(customCacheDir); + for (const { repoPath } of repoRoots) { + const candidates = await searchRootAll(repoPath); + for (const candidate of candidates) { + try { + const parsed = yaml.parse(await fs.readFile(candidate, 'utf8')); + if (parsed && (parsed.code === moduleName || parsed.name === moduleName)) { + return candidate; + } + } catch { + // Malformed yaml — skip + } + } + } + } + } catch { + // Custom-modules cache walk failed — continue + } + return null; }