/**
 * Pure decision logic for runtime routing.
 *
 * Extracted from main.ts so that the full startup decision matrix can be
 * verified without spinning up the real agent, filesystem, or TUI.
 *
 * Every branch in main()'s startup sequence that gates on platform, newSheet,
 * Mog SDK availability, user/account eligibility, sourceCheckout, install state,
 * or sync result is encoded here as a pure function of its inputs.
 */
// ---------------------------------------------------------------------------
// Known startup agent modes — a subset of MODE in mode-names.ts.
// Manage mode is user-entered only via /manage and is not a startup mode.
// ---------------------------------------------------------------------------
const KNOWN_MODES = {
    PLAN: 'plan',
    ASK: 'ask',
    ACTION: 'action'
};
// ---------------------------------------------------------------------------
// Pure routing function
// ---------------------------------------------------------------------------
export function resolveRuntimeRouting(input) {
    const warnings = [];
    const effectiveNewSheetEnabled = input.newSheetEnabled && input.mogSdkAvailable && input.mogAllowed;
    // 1. Does this platform + config require a local XLL runtime?
    const requiresLocalXll = input.platform === 'win32' && !effectiveNewSheetEnabled;
    // 2. XLL outcome
    let xllOutcome;
    if (!requiresLocalXll) {
        xllOutcome = { action: 'skip' };
    }
    else {
        switch (input.xllStatus.kind) {
            case 'ok':
                xllOutcome = { action: 'ok', updated: input.xllStatus.updated };
                if (input.xllStatus.updated > 0 && input.devMode) {
                    warnings.push(`Updated ${input.xllStatus.updated} XLL file(s)`);
                }
                break;
            case 'source-missing':
                xllOutcome = {
                    action: 'hard-exit',
                    reason: 'source-missing',
                    missingPaths: input.xllStatus.missingPaths
                };
                break;
            case 'install-failed':
                xllOutcome = { action: 'hard-exit', reason: 'install-failed' };
                break;
            case 'degraded':
                xllOutcome = { action: 'degraded-warning' };
                warnings.push('XLL sync failed — continuing with previously installed files.');
                break;
        }
    }
    // 3. Excel tool kind — new-sheet if enabled and available, COM otherwise
    const excelToolKind = effectiveNewSheetEnabled ? 'new-sheet' : 'com';
    // 4. Sandbox
    const sandboxActive = input.sandboxMode === 'enabled' && input.sandboxAvailable;
    const bashToolKind = sandboxActive ? 'sandbox' : 'regular';
    if (input.sandboxMode === 'enabled' && !input.sandboxAvailable) {
        warnings.push('Sandbox enabled but not installed.');
    }
    // 5. AgentController selection
    let agentKind;
    if (input.needsSetup) {
        agentKind = 'installation';
    }
    else if (input.agentMode === KNOWN_MODES.PLAN) {
        agentKind = 'plan';
    }
    else if (input.agentMode === KNOWN_MODES.ASK) {
        agentKind = 'ask';
    }
    else {
        agentKind = 'action';
    }
    return {
        requiresLocalXll,
        xllOutcome,
        excelToolKind,
        bashToolKind,
        agentKind,
        sandboxActive,
        warnings
    };
}
//# sourceMappingURL=runtime-routing.js.map