fix(3815): phase.insert handles checked-bullet ROADMAP format (#79)
* fix(3815): phase.insert parser handles checked-bullet ROADMAP format
phaseInsert (TS) and cmdPhaseInsert (CJS) previously used a heading-only
regex (#{2,4}\s*Phase\s+N:) to locate the target phase. On projects whose
ROADMAP uses the checked-bullet format (- [ ] **Phase N: name** or
- [ ] Phase N: name), the lookup always failed with "Phase N not found".
Extend the locator to also accept the bullet form — mirroring the patterns
already used by phaseRemove and phaseComplete. When bullet-style is
detected, insert a new bullet entry after the matched line (preserving
bold/plain style to match surrounding entries). The heading-style code
path is unchanged.
Also fix a pre-existing test timeout: the first registry-integration test in
phase-lifecycle.test.ts was failing with STACK_TRACE_ERROR (masked timeout)
because the cold import of index.js takes >5 s. Added { timeout: 30_000 }.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(3815): refine hybrid-ROADMAP detection, preserve #3098 parity
Tighten the bullet-style branch guard: only treat a ROADMAP as
bullet-style (and apply the bullet-insert path) when it contains
ZERO heading-style phase entries (anyHeadingPattern test). A
mixed (hybrid) ROADMAP — headings for some phases, bullet summaries
for others — is the #3098 case where the detail section is absent;
that path must still error with "missing a detail section".
Adds a regression test (#3098 preserved) in both TS and CJS to
confirm that a heading-style ROADMAP with a bullet-only entry for
the target phase still fires the "missing a detail section" error,
not the bullet-insert path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: add changeset for #3815 phase.insert bullet-roadmap fix
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -409,12 +409,34 @@ export const phaseInsert: QueryHandler = async (args, projectDir, workstream) =>
|
||||
const unpadded = normalizedAfter.replace(/^0+/, '');
|
||||
const afterPhaseEscaped = unpadded.replace(/\./g, '\\.');
|
||||
const targetPattern = new RegExp(`#{2,4}\\s*Phase\\s+0*${afterPhaseEscaped}:`, 'i');
|
||||
if (!targetPattern.test(content)) {
|
||||
// Bug #3098 parity: when only the summary checklist exists for this
|
||||
// phase (no `### Phase N:` detail section), point the user at the
|
||||
// missing detail section rather than implying the phase is absent.
|
||||
const headingMatch = targetPattern.test(content);
|
||||
|
||||
// #3815: also recognise the checked-bullet phase format used by projects
|
||||
// that list phases as `- [ ] **Phase N: name**` or `- [ ] Phase N: name`
|
||||
// (both bold and plain variants). This mirrors the patterns already used
|
||||
// by phaseRemove / phaseComplete so insert is consistent with its siblings.
|
||||
//
|
||||
// Bullet-style is only used when there are NO heading-style phases at all in
|
||||
// the milestone content. If the ROADMAP mixes headings + bullets (hybrid
|
||||
// format), a bullet-only match means the detail section is missing — that
|
||||
// is the #3098 case and must continue to produce the "missing a detail
|
||||
// section" error. Only a purely bullet-style ROADMAP (zero heading-style
|
||||
// phase entries in the milestone) goes through the bullet insert path.
|
||||
const bulletPattern = new RegExp(
|
||||
`-\\s*\\[[ x]\\]\\s*(?:\\*\\*)?Phase\\s+0*${afterPhaseEscaped}[:\\s]`,
|
||||
'i',
|
||||
);
|
||||
const anyHeadingPattern = /#{2,4}\s*Phase\s+\d/i;
|
||||
const roadmapHasHeadingPhases = anyHeadingPattern.test(content);
|
||||
const isBulletStyle = !headingMatch && bulletPattern.test(content) && !roadmapHasHeadingPhases;
|
||||
|
||||
if (!headingMatch && !isBulletStyle) {
|
||||
// Bug #3098 parity: when the ROADMAP uses heading-style phases and only
|
||||
// the summary checklist exists for this phase (no `### Phase N:` detail
|
||||
// section), point the user at the missing detail section rather than
|
||||
// implying the phase is absent.
|
||||
const checklistPattern = new RegExp(
|
||||
`-\\s*\\[[ x]\\]\\s*\\*\\*Phase\\s+0*${afterPhaseEscaped}:`,
|
||||
`-\\s*\\[[ x]\\]\\s*(?:\\*\\*)?Phase\\s+0*${afterPhaseEscaped}[:\\s]`,
|
||||
'i',
|
||||
);
|
||||
if (checklistPattern.test(content)) {
|
||||
@@ -459,6 +481,46 @@ export const phaseInsert: QueryHandler = async (args, projectDir, workstream) =>
|
||||
// Create directory with .gitkeep
|
||||
await ensureDirectoryWithGitkeep(dirPath);
|
||||
|
||||
if (isBulletStyle) {
|
||||
// #3815: Insert in checked-bullet format, mirroring the style of the
|
||||
// surrounding entries. Detect whether the matched bullet uses bold
|
||||
// (`**Phase N: …**`) to preserve file-internal format consistency.
|
||||
const boldBulletPattern = new RegExp(
|
||||
`-\\s*\\[[ x]\\]\\s*\\*\\*Phase\\s+0*${afterPhaseEscaped}:`,
|
||||
'i',
|
||||
);
|
||||
const useBold = boldBulletPattern.test(content);
|
||||
const phaseLabel = useBold
|
||||
? `**Phase ${decimalPhase}: ${description}**`
|
||||
: `Phase ${decimalPhase}: ${description}`;
|
||||
const bulletEntry = `\n- [ ] ${phaseLabel}`;
|
||||
|
||||
// Locate the target bullet line in the raw content
|
||||
const targetBulletPattern = new RegExp(
|
||||
`(-\\s*\\[[ x]\\]\\s*(?:\\*\\*)?Phase\\s+0*${afterPhaseEscaped}[:\\s][^\\n]*)`,
|
||||
'i',
|
||||
);
|
||||
const bulletMatchResult = rawContent.match(targetBulletPattern);
|
||||
if (!bulletMatchResult) {
|
||||
throw new GSDError(`Could not find Phase ${afterPhase} bullet line`, ErrorClassification.Execution);
|
||||
}
|
||||
|
||||
const bulletLineEnd = rawContent.indexOf(bulletMatchResult[0]) + bulletMatchResult[0].length;
|
||||
// Find where the next phase bullet starts (or use end of content)
|
||||
const afterBullet = rawContent.slice(bulletLineEnd);
|
||||
const nextBulletMatch = afterBullet.match(/\n-\s*\[[ x]\]\s*(?:\*\*)?Phase\s+\d/i);
|
||||
|
||||
let insertIdx: number;
|
||||
if (nextBulletMatch && nextBulletMatch.index !== undefined) {
|
||||
insertIdx = bulletLineEnd + nextBulletMatch.index;
|
||||
} else {
|
||||
insertIdx = bulletLineEnd;
|
||||
}
|
||||
|
||||
return rawContent.slice(0, insertIdx) + bulletEntry + rawContent.slice(insertIdx);
|
||||
}
|
||||
|
||||
// Heading-style insert (original path)
|
||||
// Build phase entry
|
||||
const phaseEntry = `\n### Phase ${decimalPhase}: ${description} (INSERTED)\n\n**Goal:** [Urgent work - to be planned]\n**Requirements**: TBD\n**Depends on:** Phase ${afterPhase}\n**Plans:** 0 plans\n\nPlans:\n- [ ] TBD (run /gsd-plan-phase ${decimalPhase} to break down)\n`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user