fix(gsd-tools): support .planning/milestones/v*-phases/ layout in validators and find-phase
Fixes #3164 Validators and find-phase hardcoded phasesDir = .planning/phases/, so projects using the milestone-archive layout (.planning/milestones/v*-phases/) had an empty diskPhases set, triggering W006 for every active phase and find-phase returning found:false. Add collectDiskPhases(planBase) helper that scans both flat layout and all .planning/milestones/v*-phases/ subdirs. Wire it into cmdValidateConsistency, cmdValidateHealth (both the Check 4 validPhases set and Check 8 diskPhases), and refactor cmdFindPhase to iterate candidate search dirs so it also searches milestone-archive dirs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -212,48 +212,61 @@ function cmdFindPhase(cwd, phase, raw) {
|
||||
error('phase identifier required');
|
||||
}
|
||||
|
||||
const phasesDir = path.join(planningDir(cwd), 'phases');
|
||||
const planBase = planningDir(cwd);
|
||||
const normalized = normalizePhaseName(phase);
|
||||
|
||||
const notFound = { found: false, directory: null, phase_number: null, phase_name: null, plans: [], summaries: [] };
|
||||
|
||||
// Build candidate search dirs: flat layout first, then milestone-archive layout.
|
||||
const searchDirs = [];
|
||||
const flatPhasesDir = path.join(planBase, 'phases');
|
||||
if (fs.existsSync(flatPhasesDir)) searchDirs.push(flatPhasesDir);
|
||||
try {
|
||||
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
||||
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
|
||||
|
||||
const match = dirs.find(d => phaseTokenMatches(d, normalized));
|
||||
if (!match) {
|
||||
output(notFound, raw, '');
|
||||
return;
|
||||
const milestonesDir = path.join(planBase, 'milestones');
|
||||
const entries = fs.readdirSync(milestonesDir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory() && /^v\d+.*-phases$/.test(e.name)) {
|
||||
searchDirs.push(path.join(milestonesDir, e.name));
|
||||
}
|
||||
}
|
||||
} catch { /* no milestones dir */ }
|
||||
|
||||
// Extract phase number — supports project-code-prefixed (CK-01-name), numeric (01-name), and custom IDs
|
||||
const dirMatch = match.match(/^(?:[A-Z]{1,6}-)(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i)
|
||||
|| match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
|
||||
const phaseNumber = dirMatch ? dirMatch[1] : normalized;
|
||||
const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
|
||||
for (const searchDir of searchDirs) {
|
||||
try {
|
||||
const entries = fs.readdirSync(searchDir, { withFileTypes: true });
|
||||
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name).sort((a, b) => comparePhaseNum(a, b));
|
||||
|
||||
const phaseDir = path.join(phasesDir, match);
|
||||
const phaseFiles = fs.readdirSync(phaseDir);
|
||||
const plans = phaseFiles.filter(isCanonicalPlanFile).sort();
|
||||
const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
|
||||
// #2893 — same diagnostic as phase-plan-index for consistency.
|
||||
const planNamingWarning = describeNonCanonicalPlans(phaseFiles, plans);
|
||||
const match = dirs.find(d => phaseTokenMatches(d, normalized));
|
||||
if (!match) continue;
|
||||
|
||||
const result = {
|
||||
found: true,
|
||||
directory: toPosixPath(path.join(path.relative(cwd, planningDir(cwd)), 'phases', match)),
|
||||
phase_number: phaseNumber,
|
||||
phase_name: phaseName,
|
||||
plans,
|
||||
summaries,
|
||||
};
|
||||
if (planNamingWarning) result.warning = planNamingWarning;
|
||||
// Extract phase number — supports project-code-prefixed (CK-01-name), numeric (01-name), and custom IDs
|
||||
const dirMatch = match.match(/^(?:[A-Z]{1,6}-)(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i)
|
||||
|| match.match(/^(\d+[A-Z]?(?:\.\d+)*)-?(.*)/i);
|
||||
const phaseNumber = dirMatch ? dirMatch[1] : normalized;
|
||||
const phaseName = dirMatch && dirMatch[2] ? dirMatch[2] : null;
|
||||
|
||||
output(result, raw, result.directory);
|
||||
} catch {
|
||||
output(notFound, raw, '');
|
||||
const phaseDir = path.join(searchDir, match);
|
||||
const phaseFiles = fs.readdirSync(phaseDir);
|
||||
const plans = phaseFiles.filter(isCanonicalPlanFile).sort();
|
||||
const summaries = phaseFiles.filter(f => f.endsWith('-SUMMARY.md') || f === 'SUMMARY.md').sort();
|
||||
// #2893 — same diagnostic as phase-plan-index for consistency.
|
||||
const planNamingWarning = describeNonCanonicalPlans(phaseFiles, plans);
|
||||
|
||||
const result = {
|
||||
found: true,
|
||||
directory: toPosixPath(path.join(path.relative(cwd, planBase), path.relative(planBase, searchDir), match)),
|
||||
phase_number: phaseNumber,
|
||||
phase_name: phaseName,
|
||||
plans,
|
||||
summaries,
|
||||
};
|
||||
if (planNamingWarning) result.warning = planNamingWarning;
|
||||
|
||||
output(result, raw, result.directory);
|
||||
return;
|
||||
} catch { continue; }
|
||||
}
|
||||
|
||||
output(notFound, raw, '');
|
||||
}
|
||||
|
||||
function extractObjective(content) {
|
||||
|
||||
@@ -396,6 +396,37 @@ function cmdVerifyKeyLinks(cwd, planFilePath, raw) {
|
||||
}, raw, verified === results.length ? 'valid' : 'invalid');
|
||||
}
|
||||
|
||||
// Returns a Set of phase numbers found on disk, scanning both the flat
|
||||
// .planning/phases/ layout and the milestone-archive .planning/milestones/v*-phases/ layout.
|
||||
function collectDiskPhases(planBase) {
|
||||
const diskPhases = new Set();
|
||||
const scanDir = (dir) => {
|
||||
try {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory()) {
|
||||
const m = e.name.match(/^(\d+[A-Z]?(?:\.\d+)*)/i);
|
||||
if (m) diskPhases.add(m[1]);
|
||||
}
|
||||
}
|
||||
} catch { /* dir absent */ }
|
||||
};
|
||||
|
||||
scanDir(path.join(planBase, 'phases'));
|
||||
|
||||
try {
|
||||
const milestonesDir = path.join(planBase, 'milestones');
|
||||
const entries = fs.readdirSync(milestonesDir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory() && /^v\d+.*-phases$/.test(e.name)) {
|
||||
scanDir(path.join(milestonesDir, e.name));
|
||||
}
|
||||
}
|
||||
} catch { /* no milestones dir */ }
|
||||
|
||||
return diskPhases;
|
||||
}
|
||||
|
||||
function cmdValidateConsistency(cwd, raw) {
|
||||
const roadmapPath = path.join(planningDir(cwd), 'ROADMAP.md');
|
||||
const phasesDir = path.join(planningDir(cwd), 'phases');
|
||||
@@ -420,16 +451,8 @@ function cmdValidateConsistency(cwd, raw) {
|
||||
roadmapPhases.add(m[1]);
|
||||
}
|
||||
|
||||
// Get phases on disk
|
||||
const diskPhases = new Set();
|
||||
try {
|
||||
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
||||
const dirs = entries.filter(e => e.isDirectory()).map(e => e.name);
|
||||
for (const dir of dirs) {
|
||||
const dm = dir.match(/^(\d+[A-Z]?(?:\.\d+)*)/i);
|
||||
if (dm) diskPhases.add(dm[1]);
|
||||
}
|
||||
} catch { /* intentionally empty */ }
|
||||
// Get phases on disk (flat layout + milestone-archive layout)
|
||||
const diskPhases = collectDiskPhases(planningDir(cwd));
|
||||
|
||||
// Check: phases in ROADMAP but not on disk
|
||||
for (const p of roadmapPhases) {
|
||||
@@ -598,16 +621,7 @@ function cmdValidateHealth(cwd, options, raw) {
|
||||
// (not yet materialized on disk) and shipped-milestone history phases
|
||||
// (archived / cleared off disk). Matching only against on-disk dirs
|
||||
// produces false W002 warnings in both cases.
|
||||
const validPhases = new Set();
|
||||
try {
|
||||
const entries = fs.readdirSync(phasesDir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory()) {
|
||||
const m = e.name.match(/^(\d+[A-Z]?(?:\.\d+)*)/);
|
||||
if (m) validPhases.add(m[1]);
|
||||
}
|
||||
}
|
||||
} catch { /* intentionally empty */ }
|
||||
const validPhases = collectDiskPhases(planBase);
|
||||
// Union in every phase declared anywhere in ROADMAP.md (current + shipped + backlog).
|
||||
try {
|
||||
if (fs.existsSync(roadmapPath)) {
|
||||
@@ -765,11 +779,7 @@ function cmdValidateHealth(cwd, options, raw) {
|
||||
roadmapPhases.add(m[1]);
|
||||
}
|
||||
|
||||
const diskPhases = new Set();
|
||||
for (const e of phaseDirEntries) {
|
||||
const dm = e.name.match(/^(\d+[A-Z]?(?:\.\d+)*)/i);
|
||||
if (dm) diskPhases.add(dm[1]);
|
||||
}
|
||||
const diskPhases = collectDiskPhases(planBase);
|
||||
|
||||
// Build a set of phases explicitly marked not-yet-started in the ROADMAP
|
||||
// summary list (- [ ] **Phase N:**). These phases are intentionally absent
|
||||
|
||||
Reference in New Issue
Block a user