/**
 * Agent Validator Service
 *
 * Infrastructure implementation of the IAgentValidator port.
 * Checks if AI agent binaries are available on the system by
 * executing `<binary> --version` via subprocess.
 *
 * Uses constructor dependency injection for the command executor
 * to enable testability without mocking node:child_process directly.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { injectable, inject } from 'tsyringe';
/**
 * Map of supported agent types to their binary command names.
 */
const AGENT_BINARY_MAP = {
    'claude-code': 'claude',
    'codex-cli': 'codex',
    'copilot-cli': 'copilot',
    cursor: 'cursor-agent',
    'gemini-cli': 'gemini',
    cline: 'cline',
};
/**
 * Service that validates agent tool availability on the system.
 *
 * Checks if the agent binary exists and is executable by running
 * `<binary> --version` and parsing the output.
 */
let AgentValidatorService = class AgentValidatorService {
    execFn;
    /**
     * @param execFn - Command executor function (injectable for testing).
     *   Uses execFile semantics (no shell) to prevent command injection.
     */
    constructor(execFn) {
        this.execFn = execFn;
    }
    /**
     * Check if the specified agent tool is available on the system.
     *
     * @param agentType - The agent type to check
     * @returns Validation result with availability status and version
     */
    async isAvailable(agentType) {
        // Dev type requires no binary — always available for local development
        if (agentType === 'dev')
            return { available: true, version: 'dev' };
        // SDK-based agents require no binary — always available (auth checked at execution time)
        if (agentType === 'openrouter' || agentType === 'together-ai' || agentType === 'ollama') {
            return { available: true, version: 'sdk' };
        }
        const binary = AGENT_BINARY_MAP[agentType];
        if (!binary) {
            return {
                available: false,
                error: `Agent type "${agentType}" is not supported yet`,
            };
        }
        try {
            const { stdout } = await this.execFn(binary, ['--version']);
            const version = stdout.trim();
            return {
                available: true,
                version,
            };
        }
        catch (error) {
            const message = error instanceof Error ? error.message : 'Unknown error';
            return {
                available: false,
                error: `Binary "${binary}" not found or not executable: ${message}`,
            };
        }
    }
};
AgentValidatorService = __decorate([
    injectable(),
    __param(0, inject('ExecFunction')),
    __metadata("design:paramtypes", [Function])
], AgentValidatorService);
export { AgentValidatorService };
