// engine/spec-migrator/find-legacy-multifile-specs.ts — SPEC-752
// Enumerates spec dirs that still carry technical.md or progress.md alongside spec.md.
import { readFile, readdir } from 'node:fs/promises';
import { join } from 'node:path';
/** Extract the spec-id slug from a directory name like "SPEC-123-some-title". */
function extractSpecId(dirName) {
    const match = /^(SPEC-\d+)/i.exec(dirName);
    return match?.[1] ?? dirName;
}
/** Extract the status from spec.md frontmatter (best-effort). */
async function readSpecStatus(specPath) {
    try {
        const content = await readFile(specPath, 'utf-8');
        const match = /^status:\s*(\S+)/m.exec(content);
        return match?.[1]?.replace(/['"]/g, '') ?? '';
    }
    catch {
        return '';
    }
}
/**
 * Scan projectPath/planu/specs/SPEC-* and return every directory that still
 * has technical.md or progress.md alongside spec.md.
 */
export async function findLegacyMultiFileSpecs(projectPath) {
    const { glob } = await import('glob');
    const dirs = await glob(join(projectPath, 'planu/specs/SPEC-*'));
    const results = [];
    for (const specDir of dirs) {
        let files;
        try {
            files = await readdir(specDir);
        }
        catch {
            continue;
        }
        const hasTechnicalMd = files.includes('technical.md');
        const hasProgressMd = files.includes('progress.md');
        if (!hasTechnicalMd && !hasProgressMd) {
            continue;
        }
        const dirName = specDir.split('/').pop() ?? specDir;
        const specId = extractSpecId(dirName);
        const status = await readSpecStatus(join(specDir, 'spec.md'));
        results.push({
            specDir,
            specId,
            hasTechnicalMd,
            hasProgressMd,
            isDone: status === 'done',
        });
    }
    return results;
}
//# sourceMappingURL=find-legacy-multifile-specs.js.map