// engine/spec-decomposer/index.ts — Barrel export + main decomposeSpec() (SPEC-157)
export { analyzeSpec, groupCriteriaIntoUnits, extractCriteriaFromContent, extractFilesFromTechnical, } from './analyzer.js';
export { mapUnitsToFiles, deduplicateMappedFiles } from './file-mapper.js';
export { resolveFileOwnership } from './ownership-resolver.js';
import { analyzeSpec } from './analyzer.js';
import { mapUnitsToFiles, deduplicateMappedFiles } from './file-mapper.js';
import { resolveFileOwnership } from './ownership-resolver.js';
import { routeCriteria } from './criterion-router.js';
/** Default maximum number of agent tasks to generate. */
const DEFAULT_MAX_TASKS = 5;
/**
 * Main entry point: decompose a spec into parallelizable agent tasks.
 *
 * @param specPath     Absolute path to the spec's spec.md file.
 * @param technicalPath Absolute path to the spec's technical.md file.
 * @param specId       Spec identifier (e.g. "SPEC-042").
 * @param maxTasks     Maximum number of tasks to generate (default: 5).
 */
export async function decomposeSpec(specPath, technicalPath, specId, maxTasks = DEFAULT_MAX_TASKS) {
    const clampedMax = Math.max(1, Math.min(maxTasks, 20));
    // Step 1: Analyze spec content → raw work units
    const workUnits = await analyzeSpec(specPath, technicalPath, clampedMax);
    // Step 2: Map each work unit to concrete file paths
    const allFiles = workUnits.flatMap((u) => u.suggestedFiles);
    const rawMapped = mapUnitsToFiles(workUnits, allFiles);
    const mapped = deduplicateMappedFiles(rawMapped);
    // Step 3: Resolve file ownership conflicts + build tasks
    const { tasks, fileOwnership, conflicts, executionPhases } = resolveFileOwnership(mapped);
    // Step 3b: SPEC-641 — attach per-criterion model routes
    for (const task of tasks) {
        task.criterionRoutes = routeCriteria(task.criteria);
    }
    // Step 4: Build warnings
    const warnings = [];
    for (const task of tasks) {
        if (task.ownedFiles.length === 0) {
            warnings.push(`Task "${task.id}" has no owned files — it may be too abstract.`);
        }
    }
    if (tasks.length === 1) {
        warnings.push('Only one task was generated — the spec may be too small for parallel execution.');
    }
    const orchestrationReady = tasks.length > 0 && warnings.filter((w) => w.includes('no owned')).length === 0;
    return {
        specId,
        taskCount: tasks.length,
        tasks,
        fileOwnership,
        conflicts,
        executionPhases,
        warnings,
        orchestrationReady,
    };
}
//# sourceMappingURL=index.js.map