// Planu — Scope Filter Engine
// Determines which filters/tools to suggest based on spec scope
// === Filter mapping by scope ===
const SCOPE_FILTER_MAP = {
    trivial: ['generate_execution_plan'],
    feature: ['generate_adr', 'generate_execution_plan'],
    'cross-module': [
        'generate_adr',
        'design_schema',
        'define_ui_contract',
        'challenge_spec',
        'generate_execution_plan',
    ],
    architectural: [
        'generate_adr',
        'design_schema',
        'define_ui_contract',
        'challenge_spec',
        'generate_execution_plan',
    ],
};
// === Public API ===
/**
 * Get the recommended filter configuration for a given scope.
 * Optionally adjusts based on whether the spec involves DB or UI.
 */
export function getScopeFilters(scope, options = {}) {
    const baseFilters = [...SCOPE_FILTER_MAP[scope]];
    // For 'feature' scope, conditionally add schema and ui_contract
    if (scope === 'feature') {
        if (options.hasDatabase && !baseFilters.includes('design_schema')) {
            // Insert before generate_execution_plan
            const planIdx = baseFilters.indexOf('generate_execution_plan');
            baseFilters.splice(planIdx, 0, 'design_schema');
        }
        if (options.hasUi && !baseFilters.includes('define_ui_contract')) {
            const planIdx = baseFilters.indexOf('generate_execution_plan');
            baseFilters.splice(planIdx, 0, 'define_ui_contract');
        }
    }
    return {
        scope,
        filters: baseFilters,
        allowManualOverride: true,
    };
}
/**
 * Apply manual overrides to a filter configuration.
 * Allows forcing or skipping specific filters.
 */
export function applyFilterOverrides(config, overrides) {
    let filters = [...config.filters];
    // Add forced filters that aren't already present
    if (overrides.force) {
        for (const f of overrides.force) {
            if (!filters.includes(f)) {
                // Insert before generate_execution_plan (which is always last)
                const planIdx = filters.indexOf('generate_execution_plan');
                if (planIdx >= 0) {
                    filters.splice(planIdx, 0, f);
                }
                else {
                    filters.push(f);
                }
            }
        }
    }
    // Remove skipped filters
    if (overrides.skip) {
        const skipList = overrides.skip;
        filters = filters.filter((f) => !skipList.includes(f));
    }
    return {
        ...config,
        filters,
    };
}
/**
 * Check if a scope should use extended challenge_spec (architectural).
 */
export function isExtendedChallenge(scope) {
    return scope === 'architectural';
}
/**
 * Get a human-readable description of the filter configuration.
 */
export function describeFilters(config) {
    if (config.filters.length === 0) {
        return 'No filters recommended for this scope.';
    }
    const filterNames = {
        generate_adr: 'Architecture Decision Records',
        design_schema: 'Database Schema Design',
        define_ui_contract: 'UI Contract Definition',
        challenge_spec: 'Spec Challenge Review',
        generate_execution_plan: 'Execution Plan Generation',
    };
    const names = config.filters.map((f) => filterNames[f]);
    const isExtended = isExtendedChallenge(config.scope);
    let description = `Recommended filters for ${config.scope} scope: ${names.join(', ')}.`;
    if (isExtended) {
        description += ' Challenge review will use extended mode (deeper analysis).';
    }
    if (config.allowManualOverride) {
        description += ' You can force or skip filters as needed.';
    }
    return description;
}
//# sourceMappingURL=scope-filter.js.map