From 057864ca3dd3e869c4444e6da9d26266b354d60b Mon Sep 17 00:00:00 2001 From: jheyworth <8269695+jheyworth@users.noreply.github.com> Date: Mon, 9 Feb 2026 11:29:10 +0000 Subject: [PATCH] fix: prevent cleanup from stripping copilot-instructions.md markers before generation The cleanup() method was removing the BMAD marker section from copilot-instructions.md, leaving user content without markers. generateCopilotInstructions() then treated the markerless file as legacy, backed it up, and overwrote user content. Fix: remove the copilot-instructions.md block from cleanup() entirely. generateCopilotInstructions() already handles marker-based replacement in a single read-modify-write pass that correctly preserves user content. Co-Authored-By: Claude Opus 4.6 --- .../cli/installers/lib/ide/github-copilot.js | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/tools/cli/installers/lib/ide/github-copilot.js b/tools/cli/installers/lib/ide/github-copilot.js index e32950704..77db771a1 100644 --- a/tools/cli/installers/lib/ide/github-copilot.js +++ b/tools/cli/installers/lib/ide/github-copilot.js @@ -666,34 +666,11 @@ Type \`/bmad-\` in Copilot Chat to see all available BMAD workflows and agent ac } } - // Clean up BMAD section from copilot-instructions.md (preserve user content) - const instructionsPath = path.join(projectDir, this.githubDir, 'copilot-instructions.md'); - if (await fs.pathExists(instructionsPath)) { - const existing = await fs.readFile(instructionsPath, 'utf8'); - const markerStart = ''; - const markerEnd = ''; - const startIdx = existing.indexOf(markerStart); - const endIdx = existing.indexOf(markerEnd); - - if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) { - // Remove only the BMAD section between markers (inclusive) - const before = existing.slice(0, startIdx); - const after = existing.slice(endIdx + markerEnd.length); - const remaining = (before + after).trim(); - - if (remaining.length > 0) { - await fs.writeFile(instructionsPath, `${remaining}\n`); - console.log(chalk.dim(' Cleaned up BMAD section from copilot-instructions.md (user content preserved)')); - } else { - await fs.remove(instructionsPath); - console.log(chalk.dim(' Cleaned up copilot-instructions.md')); - } - } else { - // No markers — file is either entirely BMAD-generated or entirely user content. - // Leave it alone during cleanup to avoid destroying user content. - console.log(chalk.dim(' Skipped copilot-instructions.md (no BMAD markers found, not modified)')); - } - } + // Note: copilot-instructions.md is NOT cleaned up here. + // generateCopilotInstructions() handles marker-based replacement in a single + // read-modify-write pass, which correctly preserves user content outside the markers. + // Stripping markers here would cause generation to treat the file as legacy (no markers) + // and overwrite user content. } }