
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f81ce30c-4212-5d47-a177-f84feb4f4d0e")}catch(e){}}();
import { getRuntimeLaunchSupportedAgentCatalog, RUNTIME_AGENT_CATALOG, } from "../core/agent-catalog.js";
import { isBinaryAvailableOnPath } from "./command-discovery.js";
function getDefaultArgs(agentId) {
    const entry = RUNTIME_AGENT_CATALOG.find((candidate) => candidate.id === agentId);
    if (!entry) {
        return [];
    }
    return [...entry.baseArgs];
}
function quoteForDisplay(part) {
    if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(part)) {
        return part;
    }
    return JSON.stringify(part);
}
function joinCommand(binary, args) {
    if (args.length === 0) {
        return binary;
    }
    return [binary, ...args.map(quoteForDisplay)].join(" ");
}
function parseBooleanEnvValue(value) {
    const normalized = value?.trim().toLowerCase();
    return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
}
function isRuntimeDebugModeEnabled() {
    const debugModeValue = process.env.KANBAN_DEBUG_MODE ?? process.env.DEBUG_MODE ?? process.env.debug_mode;
    return parseBooleanEnvValue(debugModeValue);
}
export function detectInstalledCommands() {
    const candidates = [...RUNTIME_AGENT_CATALOG.map((entry) => entry.binary), "npx"];
    const detected = [];
    for (const candidate of candidates) {
        if (isBinaryAvailableOnPath(candidate)) {
            detected.push(candidate);
        }
    }
    return detected;
}
function getCuratedDefinitions(runtimeConfig, detected) {
    const detectedSet = new Set(detected);
    return getRuntimeLaunchSupportedAgentCatalog().map((entry) => {
        const defaultArgs = getDefaultArgs(entry.id);
        const command = joinCommand(entry.binary, defaultArgs);
        const isInstalled = entry.id === "cline" ? true : detectedSet.has(entry.binary);
        return {
            id: entry.id,
            label: entry.label,
            binary: entry.binary,
            command,
            defaultArgs,
            installed: isInstalled,
            configured: runtimeConfig.selectedAgentId === entry.id,
        };
    });
}
export function resolveAgentCommand(runtimeConfig) {
    const selected = getRuntimeLaunchSupportedAgentCatalog().find((entry) => entry.id === runtimeConfig.selectedAgentId);
    if (!selected) {
        return null;
    }
    const defaultArgs = getDefaultArgs(selected.id);
    const command = joinCommand(selected.binary, defaultArgs);
    if (isBinaryAvailableOnPath(selected.binary)) {
        return {
            agentId: selected.id,
            label: selected.label,
            command,
            binary: selected.binary,
            args: defaultArgs,
        };
    }
    return null;
}
export function buildRuntimeConfigResponse(runtimeConfig, clineProviderSettings) {
    const detectedCommands = detectInstalledCommands();
    const agents = getCuratedDefinitions(runtimeConfig, detectedCommands);
    const resolved = resolveAgentCommand(runtimeConfig);
    const effectiveCommand = resolved ? joinCommand(resolved.binary, resolved.args) : null;
    return {
        selectedAgentId: runtimeConfig.selectedAgentId,
        selectedShortcutLabel: runtimeConfig.selectedShortcutLabel,
        agentAutonomousModeEnabled: runtimeConfig.agentAutonomousModeEnabled,
        debugModeEnabled: isRuntimeDebugModeEnabled(),
        effectiveCommand,
        globalConfigPath: runtimeConfig.globalConfigPath,
        projectConfigPath: runtimeConfig.projectConfigPath,
        readyForReviewNotificationsEnabled: runtimeConfig.readyForReviewNotificationsEnabled,
        detectedCommands,
        agents,
        shortcuts: runtimeConfig.shortcuts,
        clineProviderSettings,
        commitPromptTemplate: runtimeConfig.commitPromptTemplate,
        openPrPromptTemplate: runtimeConfig.openPrPromptTemplate,
        commitPromptTemplateDefault: runtimeConfig.commitPromptTemplateDefault,
        openPrPromptTemplateDefault: runtimeConfig.openPrPromptTemplateDefault,
    };
}
//# sourceMappingURL=agent-registry.js.map
//# debugId=f81ce30c-4212-5d47-a177-f84feb4f4d0e
