()
| 55 | * Later directories take precedence, so project agents override global ones. |
| 56 | */ |
| 57 | export async function initializeAgentRegistry(): Promise<void> { |
| 58 | try { |
| 59 | // Let SDK load from all default directories (cwd, parent, home) |
| 60 | userAgentsCache = await sdkLoadLocalAgents({ verbose: false }) |
| 61 | // Build ID-to-filepath map by scanning all agent directories |
| 62 | userAgentFilePaths = buildAgentFilePathMap(getDefaultAgentDirs()) |
| 63 | } catch (error) { |
| 64 | // Fall back to empty cache if SDK loading fails, but log a warning |
| 65 | logger.warn( |
| 66 | { error }, |
| 67 | 'Failed to load user agents from .agents directories', |
| 68 | ) |
| 69 | userAgentsCache = {} |
| 70 | userAgentFilePaths = new Map() |
| 71 | } |
| 72 | |
| 73 | // Load MCP config from mcp.json files in .agents directories |
| 74 | try { |
| 75 | const mcpConfig = loadMCPConfigSync({ verbose: false }) |
| 76 | mcpServersCache = mcpConfig.mcpServers |
| 77 | if (Object.keys(mcpServersCache).length > 0) { |
| 78 | logger.debug( |
| 79 | { |
| 80 | mcpServers: Object.keys(mcpServersCache), |
| 81 | source: mcpConfig._sourceFilePath, |
| 82 | }, |
| 83 | '[agents] Loaded MCP servers from mcp.json', |
| 84 | ) |
| 85 | } |
| 86 | } catch (error) { |
| 87 | logger.warn({ error }, 'Failed to load MCP config from .agents directories') |
| 88 | mcpServersCache = {} |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get default agent directories to scan. |
no test coverage detected