diff --git a/get-shit-done/bin/lib/roadmap.cjs b/get-shit-done/bin/lib/roadmap.cjs index f6b3d1c28..638f24897 100644 --- a/get-shit-done/bin/lib/roadmap.cjs +++ b/get-shit-done/bin/lib/roadmap.cjs @@ -129,6 +129,15 @@ function cmdRoadmapAnalyze(cwd, raw) { const phases = []; let match; + // Build phase directory lookup once (O(1) readdir instead of O(N) per phase) + const _phaseDirNames = (() => { + try { + return fs.readdirSync(phasesDir, { withFileTypes: true }) + .filter(e => e.isDirectory()) + .map(e => e.name); + } catch { return []; } + })(); + while ((match = phasePattern.exec(content)) !== null) { const phaseNum = match[1]; const phaseName = match[2].replace(/\(INSERTED\)/i, '').trim(); @@ -155,9 +164,7 @@ function cmdRoadmapAnalyze(cwd, raw) { let hasResearch = false; try { - const entries = fs.readdirSync(phasesDir, { withFileTypes: true }); - const dirs = entries.filter(e => e.isDirectory()).map(e => e.name); - const dirMatch = dirs.find(d => phaseTokenMatches(d, normalized)); + const dirMatch = _phaseDirNames.find(d => phaseTokenMatches(d, normalized)); if (dirMatch) { const phaseFiles = fs.readdirSync(path.join(phasesDir, dirMatch));