/**
 * paths.mjs — roadmap scope path helpers (C29).
 *
 * Per-scope roadmap layout:
 *   .aperant/roadmap/{scope}/milestones.json   (structured)
 *   .aperant/roadmap/{scope}/ROADMAP.md        (rendered)
 *
 * Each scope is fully independent — its own milestone/phase namespace, its
 * own lock, its own rendered markdown. There is no top-level milestones.json
 * or ROADMAP.md.
 */
import { existsSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
export function roadmapScopePaths(targetDir, scope) {
    const scopeDir = join(targetDir, '.aperant', 'roadmap', scope);
    return {
        scopeDir,
        jsonPath: join(scopeDir, 'milestones.json'),
        mdPath: join(scopeDir, 'ROADMAP.md'),
        // R5 (subtask 10): per-phase JSON layout lives alongside the legacy
        // milestones.json. Exposed here so io.mjs and CLI commands share the
        // same path construction.
        phasesDir: join(scopeDir, 'phases'),
    };
}
export function phasesPath(targetDir, scope) {
    return join(targetDir, '.aperant', 'roadmap', scope, 'phases');
}
export function listRoadmapScopes(targetDir) {
    const roadmapRoot = join(targetDir, '.aperant', 'roadmap');
    if (!existsSync(roadmapRoot))
        return [];
    const out = [];
    for (const name of readdirSync(roadmapRoot)) {
        const sub = join(roadmapRoot, name);
        try {
            if (!statSync(sub).isDirectory())
                continue;
        }
        catch {
            continue;
        }
        // R5: a scope is considered initialized if it has a legacy milestones.json
        // OR a populated phases/ directory (the new canonical layout).
        if (existsSync(join(sub, 'milestones.json')) || existsSync(join(sub, 'phases'))) {
            out.push(name);
        }
    }
    out.sort((a, b) => {
        if (a === b)
            return 0;
        if (a === 'project')
            return -1;
        if (b === 'project')
            return 1;
        return a.localeCompare(b);
    });
    return out;
}
//# sourceMappingURL=paths.mjs.map