From 3977cf3947c866c32888fc0f33ff2b27c9650ce3 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Mon, 16 Mar 2026 10:53:29 -0400 Subject: [PATCH] fix(verify): add CWD guard and strip archived milestones in health checks (#1076) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two fixes to verify.cjs: 1. Add CWD guard to cmdValidateHealth — detects when CWD is the home directory (likely accidental) and returns error E010 before running checks that would read the wrong .planning/ directory. 2. Import and apply stripShippedMilestones to both cmdValidateConsistency and cmdValidateHealth (Check 8) — prevents false warnings when archived milestones reuse phase numbers. This PR subsumes #1071 (strip archived milestones) to avoid merge conflicts on the same import line. Addresses patch 2 from #899, fixes #1060 --- get-shit-done/bin/lib/verify.cjs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/get-shit-done/bin/lib/verify.cjs b/get-shit-done/bin/lib/verify.cjs index 09edcb6b5..9f8a08546 100644 --- a/get-shit-done/bin/lib/verify.cjs +++ b/get-shit-done/bin/lib/verify.cjs @@ -4,7 +4,8 @@ const fs = require('fs'); const path = require('path'); -const { safeReadFile, normalizePhaseName, execGit, findPhaseInternal, getMilestoneInfo, output, error } = require('./core.cjs'); +const os = require('os'); +const { safeReadFile, normalizePhaseName, execGit, findPhaseInternal, getMilestoneInfo, stripShippedMilestones, output, error } = require('./core.cjs'); const { extractFrontmatter, parseMustHavesBlock } = require('./frontmatter.cjs'); const { writeStateMd } = require('./state.cjs'); @@ -407,9 +408,10 @@ function cmdValidateConsistency(cwd, raw) { return; } - const roadmapContent = fs.readFileSync(roadmapPath, 'utf-8'); + const roadmapContentRaw = fs.readFileSync(roadmapPath, 'utf-8'); + const roadmapContent = stripShippedMilestones(roadmapContentRaw); - // Extract phases from ROADMAP + // Extract phases from ROADMAP (archived milestones already stripped) const roadmapPhases = new Set(); const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi; let m; @@ -515,6 +517,19 @@ function cmdValidateConsistency(cwd, raw) { } function cmdValidateHealth(cwd, options, raw) { + // Guard: detect if CWD is the home directory (likely accidental) + const resolved = path.resolve(cwd); + if (resolved === os.homedir()) { + output({ + status: 'error', + errors: [{ code: 'E010', message: `CWD is home directory (${resolved}) — health check would read the wrong .planning/ directory. Run from your project root instead.`, fix: 'cd into your project directory and retry' }], + warnings: [], + info: [{ code: 'I010', message: `Resolved CWD: ${resolved}` }], + repairable_count: 0, + }, raw); + return; + } + const planningDir = path.join(cwd, '.planning'); const projectPath = path.join(planningDir, 'PROJECT.md'); const roadmapPath = path.join(planningDir, 'ROADMAP.md'); @@ -679,7 +694,8 @@ function cmdValidateHealth(cwd, options, raw) { // ─── Check 8: Run existing consistency checks ───────────────────────────── // Inline subset of cmdValidateConsistency if (fs.existsSync(roadmapPath)) { - const roadmapContent = fs.readFileSync(roadmapPath, 'utf-8'); + const roadmapContentRaw = fs.readFileSync(roadmapPath, 'utf-8'); + const roadmapContent = stripShippedMilestones(roadmapContentRaw); const roadmapPhases = new Set(); const phasePattern = /#{2,4}\s*Phase\s+(\d+[A-Z]?(?:\.\d+)*)\s*:/gi; let m;