/**
 * XLL startup resolution — decides whether the local XLL runtime is ready.
 *
 * In source-checkout mode, validates that required files exist on disk.
 * In installed mode, delegates to syncXll() to copy shipped files to the
 * stable user-local directory.
 */
import { existsSync } from 'fs';
import { join } from 'path';
import { getAgentDir, getEmbeddedPythonExe, getXllPath } from '../config.js';
import { syncXll } from './sync-xll.js';
function getSourceCheckoutRequiredPaths() {
    return [
        getXllPath(),
        join(getAgentDir(), 'xll', 'modules', 'shortcut_xl', '__init__.py'),
        getEmbeddedPythonExe()
    ];
}
/** Resolve XLL readiness: validate source checkout paths or sync shipped files. */
export function resolveStartupXll({ sourceCheckout, needsSetup }) {
    if (sourceCheckout) {
        const missingPaths = getSourceCheckoutRequiredPaths().filter((p) => !existsSync(p));
        return missingPaths.length === 0
            ? { kind: 'ok', updated: 0 }
            : { kind: 'source-missing', missingPaths };
    }
    const result = syncXll();
    if (result.xllReady) {
        return { kind: 'ok', updated: result.updated };
    }
    if (needsSetup) {
        return { kind: 'install-failed' };
    }
    return { kind: 'degraded', updated: result.updated };
}
//# sourceMappingURL=startup-xll.js.map