// spec-migrator/path-utils.ts — Path rewriting and flattening utilities
export const LEGACY_TO_MODERN_NAMES = {
    'HU.md': 'spec.md',
    'FICHA-TECNICA.md': 'technical.md',
    'PROGRESS.md': 'progress.md',
};
/**
 * Rewrite a legacy spec file path to its modern equivalent.
 * Handles docs/sdd/specs → planu/specs, legacy filenames, and flattening.
 */
export function rewritePath(path) {
    const modernized = path
        .replace(/docs\/sdd\/specs/, 'planu/specs')
        .replace(/\/HU\.md$/, '/spec.md')
        .replace(/\/FICHA-TECNICA\.md$/, '/technical.md')
        .replace(/\/PROGRESS\.md$/, '/progress.md');
    return flattenSpecPath(modernized);
}
/**
 * Flatten nested spec paths to the new flat structure.
 * Converts `planu/specs/{category}/{slug}/file.md` to `planu/specs/{slug}/file.md`.
 * Already-flat paths are returned unchanged.
 */
export function flattenSpecPath(p) {
    // Match: planu/specs/{category}/{specFolder}[/rest]
    // A spec folder starts with SPEC- or is the direct slug folder.
    // We detect nesting by counting segments after planu/specs/.
    const match = /^(planu\/specs\/)([^/]+)\/([^/]+)(\/.*)?$/.exec(p);
    if (!match) {
        return p;
    }
    const [, prefix, segment1, segment2, rest] = match;
    // If segment1 is already a spec folder (starts with SPEC-), it's flat — no change.
    if (segment1?.startsWith('SPEC-')) {
        return p;
    }
    // segment1 is a subcategory — remove it, promote segment2 to direct child.
    return `${prefix}${segment2}${rest ?? ''}`;
}
//# sourceMappingURL=path-utils.js.map