// tools/init-project/tool-group-activator.ts — SPEC-568: wire stack detection
// into tool-group auto-activation. Keeps the init_project handler thin.
import { computeGroupActivations } from '../../engine/tool-groups/stack-activator.js';
import { getGroupManager } from '../tool-group-handler.js';
/**
 * Auto-enable/disable tool groups based on the project's detected stack.
 *
 * Returns a snapshot of which groups were actually activated/deactivated,
 * or null if the GroupManager singleton is not initialized (e.g. tests,
 * early startup). Never throws — best-effort.
 */
export function applyStackBasedGroupActivations(detectedStack) {
    const manager = getGroupManager();
    if (!manager) {
        return null;
    }
    try {
        const currentGroups = manager.getGroupStatus();
        const plan = computeGroupActivations(detectedStack, currentGroups);
        const activated = [];
        const deactivated = [];
        for (const id of plan.toEnable) {
            const result = manager.enableGroup(id);
            if (result.success) {
                activated.push(id);
            }
        }
        for (const id of plan.toDisable) {
            const result = manager.disableGroup(id);
            if (result.success) {
                deactivated.push(id);
            }
        }
        if (activated.length === 0 && deactivated.length === 0) {
            return null;
        }
        return {
            autoActivated: activated,
            autoDeactivated: deactivated,
            detectedAt: new Date().toISOString(),
        };
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=tool-group-activator.js.map