/**
 * Agent registry for managing AI agent implementations
 * Singleton registry that maps agent names to implementations
 */
import * as path from "path";
import { claudeCodeAgentConfig } from "../../cli/features/claude-code/agent.js";
import { clineAgentConfig } from "../../cli/features/cline/agent.js";
import { codexAgentConfig } from "../../cli/features/codex/agent.js";
import { cursorAgentConfig } from "../../cli/features/cursor-agent/agent.js";
import { droidAgentConfig } from "../../cli/features/droid/agent.js";
import { geminiCliAgentConfig } from "../../cli/features/gemini-cli/agent.js";
import { githubCopilotAgentConfig } from "../../cli/features/github-copilot/agent.js";
import { gooseAgentConfig } from "../../cli/features/goose/agent.js";
import { kiloAgentConfig } from "../../cli/features/kilo/agent.js";
import { kimiCliAgentConfig } from "../../cli/features/kimi-cli/agent.js";
import { openclawAgentConfig } from "../../cli/features/openclaw/agent.js";
import { opencodeAgentConfig } from "../../cli/features/opencode/agent.js";
import { piAgentConfig } from "../../cli/features/pi/agent.js";
/**
 * Registry singleton for managing agent implementations
 */
export class AgentRegistry {
    static instance = null;
    agents;
    constructor() {
        this.agents = new Map();
        this.agents.set(claudeCodeAgentConfig.name, claudeCodeAgentConfig);
        this.agents.set(clineAgentConfig.name, clineAgentConfig);
        this.agents.set(codexAgentConfig.name, codexAgentConfig);
        this.agents.set(cursorAgentConfig.name, cursorAgentConfig);
        this.agents.set(droidAgentConfig.name, droidAgentConfig);
        this.agents.set(geminiCliAgentConfig.name, geminiCliAgentConfig);
        this.agents.set(githubCopilotAgentConfig.name, githubCopilotAgentConfig);
        this.agents.set(gooseAgentConfig.name, gooseAgentConfig);
        this.agents.set(kiloAgentConfig.name, kiloAgentConfig);
        this.agents.set(kimiCliAgentConfig.name, kimiCliAgentConfig);
        this.agents.set(opencodeAgentConfig.name, opencodeAgentConfig);
        this.agents.set(openclawAgentConfig.name, openclawAgentConfig);
        this.agents.set(piAgentConfig.name, piAgentConfig);
    }
    /**
     * Get the singleton instance
     * @returns The AgentRegistry singleton instance
     */
    static getInstance() {
        if (AgentRegistry.instance == null) {
            AgentRegistry.instance = new AgentRegistry();
        }
        return AgentRegistry.instance;
    }
    /**
     * Reset the singleton instance (for testing)
     */
    static resetInstance() {
        AgentRegistry.instance = null;
    }
    /**
     * Get an agent by name
     * @param args - Configuration arguments
     * @param args.name - The agent name to look up (validated at runtime)
     *
     * @throws Error if agent not found
     *
     * @returns The agent implementation
     */
    get(args) {
        const { name } = args;
        const agent = this.agents.get(name);
        if (agent == null) {
            const available = this.list().join(", ");
            throw new Error(`Unknown agent '${name}'. Available agents: ${available}`);
        }
        return agent;
    }
    /**
     * Get all registered agents
     * @returns Array of all agent implementations
     */
    getAll() {
        return Array.from(this.agents.values());
    }
    /**
     * List all registered agent names
     * @returns Array of valid agent names
     */
    list() {
        return Array.from(this.agents.keys());
    }
    /**
     * Get the default agent name (first registered agent)
     * Used as a fallback when no agent is explicitly specified.
     * @returns The default agent name
     */
    getDefaultAgentName() {
        return this.list()[0];
    }
    /**
     * Get the basenames of all agent config directories.
     * Used by normalizeInstallDir to strip known agent dir suffixes from paths.
     * @returns Array of agent directory basenames (e.g., [".claude"])
     */
    getAgentDirNames() {
        return this.getAll().map((agent) => {
            const installDir = "/";
            const agentDir = agent.getAgentDir({ installDir });
            const relativeDir = path.relative(installDir, agentDir);
            const topLevelDir = relativeDir.split(path.sep)[0];
            return topLevelDir && topLevelDir.length > 0
                ? topLevelDir
                : path.basename(agentDir);
        });
    }
}
//# sourceMappingURL=agentRegistry.js.map