fix(sdk): extractCurrentMilestone preserves generic Phase Details heading (#3493)
When a roadmap places shared phase-detail bodies under a non-version-prefixed `## Phase Details` heading AFTER a `### 📋 vX.Y+ (Planned)` sibling in document order, the entire Phase Details section fell outside the slice returned by `extractCurrentMilestone`. `gsd-sdk query phase.insert N` then reported "Phase N not found in ROADMAP.md" even though `### Phase N:` was unambiguously present. PR #2455 (closing #2422) added a same-version `continue` branch that already handles the version-prefixed variant (e.g. `## v2.0 Phase Details`). This fix extends the same intent to the generic-label variant: after the initial boundary scan, look for a literal `^#{1,3}\s+Phase\s+Details\b` heading past `sectionEnd` and, if found, append the Phase Details block (up to the next real milestone boundary — version-bearing or milestone-emoji-bearing heading — or EOF) to the returned slice. The intervening planned-milestone content is skipped so it does not leak into the active-milestone view. Bounded to a single append so a malformed roadmap can't loop. Only matches the literal `Phase Details` label (canonical per GSD ROADMAP template); anything else continues to terminate the slice. Does not regress the v2.0/v2.1+ version-prefixed handling shipped by #2455 (existing `bug-2422` test still passes). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -313,9 +313,57 @@ export async function extractCurrentMilestone(content: string, projectDir: strin
|
||||
break;
|
||||
}
|
||||
|
||||
// Issue #3493: a generic, non-version-prefixed `## Phase Details` (or
|
||||
// `### Phase Details`) heading sometimes sits AFTER a planned-milestone
|
||||
// sibling (e.g. `### 📋 v2.1+ (Planned)`) in document order but holds the
|
||||
// detail bodies (`### Phase N: ...`) for the *active* milestone. Issue #2422
|
||||
// / PR #2455 handled the version-prefixed variant `## v2.0 Phase Details`
|
||||
// via the same-version `continue` above; this branch handles the generic-
|
||||
// label variant. When such a heading is found after the initial sectionEnd,
|
||||
// append the Phase Details block to the returned slice (skipping the
|
||||
// intervening planned-milestone content so it does not leak in), stopping
|
||||
// at the next real milestone boundary (version-bearing or milestone-emoji-
|
||||
// bearing heading) or EOF.
|
||||
//
|
||||
// Bounded to a single append so a malformed roadmap can't loop. Only
|
||||
// matches the literal `Phase Details` label (canonical per GSD ROADMAP
|
||||
// template); anything else continues to terminate the slice.
|
||||
let phaseDetailsTail = '';
|
||||
if (sectionEnd < content.length) {
|
||||
const afterEnd = content.slice(sectionEnd);
|
||||
const genericPhaseDetailsRegex = /^(#{1,3})\s+Phase\s+Details\b[^\n]*$/im;
|
||||
const phaseDetailsMatch = afterEnd.match(genericPhaseDetailsRegex);
|
||||
if (phaseDetailsMatch && phaseDetailsMatch.index !== undefined) {
|
||||
const pdStart = sectionEnd + phaseDetailsMatch.index;
|
||||
const pdHeadingLen = phaseDetailsMatch[0].length;
|
||||
const pdLevel = phaseDetailsMatch[1].length;
|
||||
// Scan from after the Phase Details heading for the next real milestone
|
||||
// boundary (different version OR milestone emoji). Reuses the same
|
||||
// (?!Phase\s+\S) phase-heading guard from #2619, plus a
|
||||
// (?!Phase\s+Details\b) guard so a sibling Phase Details heading
|
||||
// doesn't terminate the block prematurely.
|
||||
const afterPdHeading = content.slice(pdStart + pdHeadingLen);
|
||||
const nextRealMilestoneRegex = new RegExp(
|
||||
`^#{1,${pdLevel}}\\s+(?!Phase\\s+\\S)(?!Phase\\s+Details\\b)(?:.*v(\\d+(?:\\.\\d+)+)[^\\n]*|.*(?:✅|📋|🚧|🟡))`,
|
||||
'gmi'
|
||||
);
|
||||
let pdEnd = content.length;
|
||||
let mm: RegExpExecArray | null;
|
||||
while ((mm = nextRealMilestoneRegex.exec(afterPdHeading)) !== null) {
|
||||
const mv = mm[1];
|
||||
if (mv && currentVersionStr && mv === currentVersionStr) continue;
|
||||
pdEnd = pdStart + pdHeadingLen + mm.index;
|
||||
break;
|
||||
}
|
||||
phaseDetailsTail = '\n' + content.slice(pdStart, pdEnd);
|
||||
}
|
||||
}
|
||||
|
||||
// Return only the current milestone section — never include the preamble, which
|
||||
// may contain ## Backlog and other non-current-milestone phases.
|
||||
return content.slice(sectionStart, sectionEnd);
|
||||
// may contain ## Backlog and other non-current-milestone phases. Append any
|
||||
// generic Phase Details block discovered above (#3493) so detail-section
|
||||
// lookups for the active milestone succeed.
|
||||
return content.slice(sectionStart, sectionEnd) + phaseDetailsTail;
|
||||
}
|
||||
|
||||
// ─── Next-milestone helpers (issue #2497) ─────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user