export function evaluateOrchestrationSpawn(input) {
    const maxAgents = input.overrides?.maxAgents ?? (input.configManager.get('orchestration.maxActiveAgents') ?? 8);
    const maxDepth = input.overrides?.maxDepth ?? (input.configManager.get('orchestration.maxDepth') ?? 0);
    const recursionEnabled = input.overrides?.recursionEnabled ?? (input.configManager.get('orchestration.recursionEnabled') ?? false);
    const requestedDepth = input.requestedDepth ?? 0;
    const availableSlots = Math.max(0, maxAgents - input.activeAgents);
    if (input.mode === 'recursive-child' || input.mode === 'plan-auto') {
        if (!recursionEnabled) {
            return {
                allowed: false,
                reason: 'recursive orchestration is disabled',
                maxAgents,
                activeAgents: input.activeAgents,
                availableSlots,
                requestedDepth,
                maxDepth,
                mode: input.mode,
            };
        }
    }
    if (input.mode === 'recursive-child' && requestedDepth > maxDepth) {
        return {
            allowed: false,
            reason: `requested depth ${requestedDepth} exceeds configured recursion depth ${maxDepth}`,
            maxAgents,
            activeAgents: input.activeAgents,
            availableSlots,
            requestedDepth,
            maxDepth,
            mode: input.mode,
        };
    }
    if (availableSlots <= 0) {
        return {
            allowed: false,
            reason: `agent capacity reached (${input.activeAgents}/${maxAgents})`,
            maxAgents,
            activeAgents: input.activeAgents,
            availableSlots,
            requestedDepth,
            maxDepth,
            mode: input.mode,
        };
    }
    return {
        allowed: true,
        maxAgents,
        activeAgents: input.activeAgents,
        availableSlots,
        requestedDepth,
        maxDepth,
        mode: input.mode,
    };
}
