/**
 * host/resolve.mjs — orchestration-mode resolver (C29).
 */
import { detectHost } from './detect.mjs';
/**
 * Resolve each orchestration preference against actual host capabilities.
 * "auto" picks the best available; explicit modes degrade gracefully.
 */
export function resolveMode(requested, capabilities, fieldName) {
    const downgradeChain = ['agent-team', 'sub-agents', 'sequential'];
    function bestAvailable() {
        if (capabilities.agent_teams)
            return 'agent-team';
        if (capabilities.sub_agents)
            return 'sub-agents';
        return 'sequential';
    }
    if (requested === 'auto') {
        return { resolved: bestAvailable(), downgrade: null };
    }
    // Explicit mode: check if the requested mode is available
    if (requested === 'agent-team' && !capabilities.agent_teams) {
        const fallback = capabilities.sub_agents ? 'sub-agents' : 'sequential';
        return {
            resolved: fallback,
            downgrade: {
                field: fieldName,
                requested: 'agent-team',
                resolved: fallback,
                reason: capabilities.sub_agents
                    ? `Host '${detectHost().cli}' does not support agent_teams (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS not set)`
                    : `Host '${detectHost().cli}' does not support agent_teams or sub_agents`,
            },
        };
    }
    if (requested === 'sub-agents' && !capabilities.sub_agents) {
        return {
            resolved: 'sequential',
            downgrade: {
                field: fieldName,
                requested: 'sub-agents',
                resolved: 'sequential',
                reason: `Host '${detectHost().cli}' does not support sub_agents`,
            },
        };
    }
    // Requested mode is available
    return { resolved: requested, downgrade: null };
}
//# sourceMappingURL=resolve.mjs.map