/**
 * CAAMP Adapter - Canonical implementation
 *
 * Wraps @cleocode/caamp APIs for use across CLEO subsystems.
 * Provides provider registry, MCP config management, injection operations,
 * and batch/orchestration functions as EngineResult-returning functions.
 *
 * This is the SINGLE SOURCE OF TRUTH for all CAAMP adapter logic.
 * MCP engine layer re-exports from here.
 *
 * @task T4678
 * @task T4705
 * @epic T4663
 */
import { buildServerConfig, checkAllInjections, checkInjection, configureProviderGlobalAndProject, detectAllProviders, generateInjectionContent, 
// Provider Registry
getAllProviders, getInstalledProviders, getInstructionFiles, getProvider, getProviderCount, getRegistryVersion, 
// Instructions
inject, injectAll, 
// Batch / Orchestration
installBatchWithRollback, 
// MCP Config
installMcpServer, listAllMcpServers, listMcpServers, removeMcpServer, resolveAlias, resolveConfigPath, } from '@cleocode/caamp';
// ============================================================
// Provider Operations
// ============================================================
/**
 * List all registered providers.
 * @task T4332
 */
export function providerList() {
    try {
        const providers = getAllProviders();
        return { success: true, data: providers };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_PROVIDER_LIST',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Get a single provider by ID or alias.
 * @task T4332
 */
export function providerGet(idOrAlias) {
    try {
        const provider = getProvider(idOrAlias);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${idOrAlias}`,
                },
            };
        }
        return { success: true, data: provider };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_PROVIDER_GET',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Detect all providers installed on the system.
 * @task T4332
 */
export function providerDetect() {
    try {
        const results = detectAllProviders();
        return { success: true, data: results };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_PROVIDER_DETECT',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Get providers that are installed on the system.
 * @task T4332
 */
export function providerInstalled() {
    try {
        const providers = getInstalledProviders();
        return { success: true, data: providers };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_PROVIDER_INSTALLED',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Get count of registered providers.
 * @task T4332
 */
export function providerCount() {
    try {
        const count = getProviderCount();
        return { success: true, data: { count } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_PROVIDER_COUNT',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Get CAAMP registry version.
 * @task T4332
 */
export function registryVersion() {
    try {
        const version = getRegistryVersion();
        return { success: true, data: { version } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_REGISTRY_VERSION',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
// ============================================================
// MCP Config Operations
// ============================================================
/**
 * List MCP servers for a specific provider.
 * @task T4332
 */
export async function mcpList(providerId, scope, projectDir) {
    try {
        const provider = getProvider(providerId);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${providerId}`,
                },
            };
        }
        const servers = await listMcpServers(provider, scope, projectDir);
        return { success: true, data: { servers } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_MCP_LIST',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * List MCP servers across all installed providers.
 * @task T4332
 */
export async function mcpListAll(scope, projectDir) {
    try {
        const providers = getInstalledProviders();
        const servers = await listAllMcpServers(providers, scope, projectDir);
        return { success: true, data: { servers } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_MCP_LIST_ALL',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Install an MCP server to a provider's config.
 * @task T4332
 */
export async function mcpInstall(providerId, serverName, config, scope, projectDir) {
    try {
        const provider = getProvider(providerId);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${providerId}`,
                },
            };
        }
        const result = await installMcpServer(provider, serverName, config, scope, projectDir);
        return { success: true, data: result };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_MCP_INSTALL',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Remove an MCP server from a provider's config.
 * @task T4332
 */
export async function mcpRemove(providerId, serverName, scope, projectDir) {
    try {
        const provider = getProvider(providerId);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${providerId}`,
                },
            };
        }
        const removed = await removeMcpServer(provider, serverName, scope, projectDir);
        return { success: true, data: { removed } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_MCP_REMOVE',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Resolve the config file path for a provider.
 * @task T4332
 */
export function mcpConfigPath(providerId, scope, projectDir) {
    try {
        const provider = getProvider(providerId);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${providerId}`,
                },
            };
        }
        const path = resolveConfigPath(provider, scope, projectDir);
        return { success: true, data: { path } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_MCP_CONFIG_PATH',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
// ============================================================
// Injection Operations
// ============================================================
/**
 * Check injection status for a single file.
 * @task T4332
 */
export async function injectionCheck(filePath, expectedContent) {
    try {
        const status = await checkInjection(filePath, expectedContent);
        return { success: true, data: status };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_INJECTION_CHECK',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Check injection status across all providers.
 * @task T4332
 */
export async function injectionCheckAll(projectDir, scope, expectedContent) {
    try {
        const providers = getInstalledProviders();
        const results = await checkAllInjections(providers, projectDir, scope, expectedContent);
        return { success: true, data: { results } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_INJECTION_CHECK_ALL',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Inject or update content in a single file.
 * @task T4332
 */
export async function injectionUpdate(filePath, content) {
    try {
        const action = await inject(filePath, content);
        return { success: true, data: { action } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_INJECTION_UPDATE',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Inject content to all providers' instruction files.
 * @task T4332
 */
export async function injectionUpdateAll(projectDir, scope, content) {
    try {
        const providers = getInstalledProviders();
        const resultMap = await injectAll(providers, projectDir, scope, content);
        // Convert Map to plain object for serialization
        const results = {};
        resultMap.forEach((action, key) => {
            results[key] = action;
        });
        return { success: true, data: { results } };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_INJECTION_UPDATE_ALL',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
// ============================================================
// Batch / Orchestration Operations (T4705)
// ============================================================
/**
 * Install multiple MCP servers atomically with rollback on failure.
 * Supports Wave 4 init rewrite which needs to install multiple
 * skills/configs as a single atomic operation.
 *
 * @task T4705
 * @epic T4663
 */
export async function batchInstallWithRollback(options) {
    try {
        const result = await installBatchWithRollback(options);
        return { success: true, data: result };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_BATCH_INSTALL',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
/**
 * Configure a provider at both global and project scope simultaneously.
 * Used during init to set up MCP configs in both scopes atomically.
 *
 * @task T4705
 * @epic T4663
 */
export async function dualScopeConfigure(providerId, options) {
    try {
        const provider = getProvider(providerId);
        if (!provider) {
            return {
                success: false,
                error: {
                    code: 'E_CAAMP_PROVIDER_NOT_FOUND',
                    message: `Provider not found: ${providerId}`,
                },
            };
        }
        const result = await configureProviderGlobalAndProject(provider, options);
        return { success: true, data: result };
    }
    catch (err) {
        return {
            success: false,
            error: {
                code: 'E_CAAMP_DUAL_SCOPE_CONFIGURE',
                message: err instanceof Error ? err.message : String(err),
            },
        };
    }
}
export { buildServerConfig as caampBuildServerConfig, generateInjectionContent as caampGenerateInjectionContent, getInstructionFiles as caampGetInstructionFiles, resolveAlias as caampResolveAlias, };
//# sourceMappingURL=adapter.js.map