(config: QodexConfig, cwd: string)
| 204 | * config roles always win over imported agents. Returns how many agents were added. |
| 205 | */ |
| 206 | export async function mergeClaudeCodeAgentRoles(config: QodexConfig, cwd: string): Promise<number> { |
| 207 | if (disabled()) return 0; |
| 208 | let agents: Record<string, RoleConfig>; |
| 209 | try { |
| 210 | agents = await loadClaudeCodeAgents(cwd); |
| 211 | } catch (e: any) { |
| 212 | logger.debug('mergeClaudeCodeAgentRoles failed', { err: e?.message }); |
| 213 | return 0; |
| 214 | } |
| 215 | const names = Object.keys(agents); |
| 216 | if (names.length === 0) return 0; |
| 217 | const existing = ((config as any).roles ?? {}) as Record<string, RoleConfig | undefined>; |
| 218 | // Imported agents first, user config last → user wins on name collisions. |
| 219 | (config as any).roles = { ...agents, ...existing }; |
| 220 | const added = names.filter(n => !existing[n]).length; |
| 221 | logger.info('Imported Claude Code agents as roles', { found: names.length, added }); |
| 222 | return added; |
| 223 | } |
| 224 | |
| 225 | // ──────────────────────── MCP servers + hooks ────────────────────────────── |
| 226 |
no test coverage detected