Compare commits
9 Commits
a0b762bee5
...
990cdaada4
| Author | SHA1 | Date |
|---|---|---|
|
|
990cdaada4 | |
|
|
2d134314c9 | |
|
|
a5e2b1c63a | |
|
|
0db123dd0b | |
|
|
bcb2ec5dfc | |
|
|
99c78835fb | |
|
|
d0985170c9 | |
|
|
9e4e37666f | |
|
|
1b57ae9c66 |
|
|
@ -25,6 +25,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"bmad:install": "node tools/cli/bmad-cli.js install",
|
||||
"bmad:uninstall": "node tools/cli/bmad-cli.js uninstall",
|
||||
"docs:build": "node tools/build-docs.mjs",
|
||||
"docs:dev": "astro dev --root website",
|
||||
"docs:fix-links": "node tools/fix-doc-links.js",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ This is a COMPETITION to create the **ULTIMATE story context** that makes LLM de
|
|||
|
||||
- The `{project-root}/_bmad/core/tasks/validate-workflow.xml` framework will automatically:
|
||||
- Load this checklist file
|
||||
- Load the newly created story file (`{story_file_path}`)
|
||||
- Load the story file (`{story_file}` when provided, otherwise `{default_output_file}`)
|
||||
- Load workflow variables from `{installed_path}/workflow.yaml`
|
||||
- Execute the validation process
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ This is a COMPETITION to create the **ULTIMATE story context** that makes LLM de
|
|||
- **Story file**: The story file to review and improve
|
||||
- **Workflow variables**: From workflow.yaml (implementation_artifacts, epics_file, etc.)
|
||||
- **Source documents**: Epics, architecture, etc. (discovered or provided)
|
||||
- **Validation framework**: `validate-workflow.xml` (handles checklist execution)
|
||||
- **Validation framework**: `validate-workflow.xml` (handles checklist execution and report generation)
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -62,10 +62,20 @@ You will systematically re-do the entire story creation process, but with a crit
|
|||
### **Step 1: Load and Understand the Target**
|
||||
|
||||
1. **Load the workflow configuration**: `{installed_path}/workflow.yaml` for variable inclusion
|
||||
2. **Load the story file**: `{story_file_path}` (provided by user or discovered)
|
||||
2. **Load the story file**: `{story_file}` first, fallback to `{default_output_file}` (or explicit `{document}` input)
|
||||
3. **Load validation framework**: `{project-root}/_bmad/core/tasks/validate-workflow.xml`
|
||||
4. **Extract metadata**: epic_num, story_num, story_key, story_title from story file
|
||||
5. **Resolve all workflow variables**: implementation_artifacts, epics_file, architecture_file, etc.
|
||||
4. **Resolve variables deterministically**:
|
||||
- Load config_source file if present
|
||||
- Parse workflow.yaml key/value pairs
|
||||
- For any value matching `{config_source}:key`, resolve from the loaded config source
|
||||
- Resolve system path variables (for example `{project-root}`, `{installed_path}`) in every path value
|
||||
- Resolve system-generated values (for example `{date}`) using current execution context
|
||||
- Required for this checklist flow: `{epics_file}`, `{architecture_file}`, `{implementation_artifacts}`, `{project-root}`, `{installed_path}`, and at least one story locator (`{story_file}` or `{default_output_file}`)
|
||||
- Optional/fallback-capable values: validation `{checklist}` input and validation `{report}` input
|
||||
- Validation task input contract: `workflow` is required; `checklist`, `document`, and `report` are optional with deterministic fallback
|
||||
- Note: create-story invoke-task passes `document={default_output_file}` explicitly, which overrides fallback discovery
|
||||
- If any required value remains unresolved, stop and request explicit user input before continuing
|
||||
5. **Extract metadata**: epic_num, story_num, story_key, story_title from story file
|
||||
6. **Understand current status**: What story implementation guidance is currently provided?
|
||||
|
||||
**Note:** If running in fresh context, user should provide the story file path being reviewed. If running from create-story workflow, the validation framework will automatically discover the checklist and story file.
|
||||
|
|
|
|||
|
|
@ -280,21 +280,16 @@
|
|||
<template-output file="{default_output_file}">testing_requirements</template-output>
|
||||
|
||||
<!-- Previous story intelligence -->
|
||||
<check
|
||||
if="previous story learnings available">
|
||||
<action>If previous story learnings are unavailable (for example this is story 1 in epic), set previous_story_intelligence to the canonical format: N/A: {one-line reason}</action>
|
||||
<template-output file="{default_output_file}">previous_story_intelligence</template-output>
|
||||
</check>
|
||||
|
||||
<!-- Git intelligence -->
|
||||
<check
|
||||
if="git analysis completed">
|
||||
<action>If git analysis is unavailable or not relevant, set git_intelligence_summary to the canonical format: N/A: {one-line reason}</action>
|
||||
<template-output file="{default_output_file}">git_intelligence_summary</template-output>
|
||||
</check>
|
||||
|
||||
<!-- Latest technical specifics -->
|
||||
<check if="web research completed">
|
||||
<action>If web research was not completed or not needed, set latest_tech_information to the canonical format: N/A: {one-line reason}</action>
|
||||
<template-output file="{default_output_file}">latest_tech_information</template-output>
|
||||
</check>
|
||||
|
||||
<!-- Project context reference -->
|
||||
<template-output
|
||||
|
|
@ -311,8 +306,8 @@
|
|||
</step>
|
||||
|
||||
<step n="6" goal="Update sprint status and finalize">
|
||||
<invoke-task>Validate against checklist at {installed_path}/checklist.md using _bmad/core/tasks/validate-workflow.xml</invoke-task>
|
||||
<action>Save story document unconditionally</action>
|
||||
<invoke-task>Run {project-root}/_bmad/core/tasks/validate-workflow.xml with workflow={installed_path}/workflow.yaml checklist={installed_path}/checklist.md document={default_output_file}</invoke-task>
|
||||
|
||||
<!-- Update sprint status -->
|
||||
<check if="sprint status file exists">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,179 @@
|
|||
<task id="_bmad/core/tasks/validate-workflow.xml"
|
||||
name="Validate Workflow Output"
|
||||
description="Run a workflow checklist against a target document and produce an evidence-backed validation report">
|
||||
|
||||
<objective>Validate a generated document against checklist requirements with deterministic variable resolution and produce an actionable pass/fail report</objective>
|
||||
|
||||
<inputs>
|
||||
<input name="workflow" required="true" desc="Workflow yaml path used to resolve variables and checklist location" />
|
||||
<input name="checklist" required="false" desc="Checklist file path. Defaults to workflow.yaml validation field, then checklist.md beside workflow" />
|
||||
<input name="document" required="false" desc="Document to validate. If omitted, resolve from workflow variables only" />
|
||||
<input name="report" required="false" desc="Output report file path. Defaults to document folder validation-report-{timestamp_utc}.md" />
|
||||
</inputs>
|
||||
|
||||
<llm critical="true">
|
||||
<i>MANDATORY: Execute ALL steps in order. Do not skip any checklist item.</i>
|
||||
<i>Always read COMPLETE files; do not sample with offsets.</i>
|
||||
<i>If a file cannot be loaded in one read, read it in deterministic sequential chunks until full coverage is achieved and recorded.</i>
|
||||
<i>Every non-N/A judgment must include concrete evidence from the document.</i>
|
||||
<i>If a required path cannot be resolved, stop and ask for explicit user input.</i>
|
||||
<i>Be strict and objective: no assumptions without evidence.</i>
|
||||
<i>N/A is allowed only when an explicit conditional requirement is not applicable; never use N/A due to missing evidence.</i>
|
||||
</llm>
|
||||
|
||||
<flow>
|
||||
<step n="1" title="Load Workflow Context">
|
||||
<action>Load workflow yaml from input {workflow}</action>
|
||||
<action>Resolve variables in this order:
|
||||
1) load config_source file if present
|
||||
2) resolve all {config_source}:key references
|
||||
3) resolve system path variables ({project-root}, {installed_path})
|
||||
4) resolve system-generated values (date)
|
||||
</action>
|
||||
<action>Determine checklist path in priority order:
|
||||
- explicit input {checklist}
|
||||
- workflow.yaml field "validation"
|
||||
- sibling file checklist.md in workflow directory
|
||||
</action>
|
||||
<action>Determine document path in priority order:
|
||||
- explicit input {document}
|
||||
- resolved variable {story_file} if present
|
||||
- resolved variable {default_output_file} if present
|
||||
</action>
|
||||
<action if="still unresolved">Ask user: "Which document should I validate?" and WAIT</action>
|
||||
<action>Normalize resolved workflow/checklist/document paths to absolute paths before loading files</action>
|
||||
</step>
|
||||
|
||||
<step n="2" title="Load Checklist and Target Document" critical="true">
|
||||
<action>Load full checklist content (use chunked sequential reads only when needed for large files, and record covered ranges)</action>
|
||||
<action>Load full target document content (use chunked sequential reads only when needed for large files, and record covered ranges)</action>
|
||||
<action>Extract story metadata when available (epic_num, story_num, story_id, story_key, title) from filename, heading, or frontmatter</action>
|
||||
<action>Parse checklist into ordered sections and atomic validation items; assign each item a stable id (section_index.item_index)</action>
|
||||
<action>Compute parsed_item_count and expected_item_count (from raw checklist requirement markers such as - [ ], - [x], and requirement list lines)</action>
|
||||
<action if="expected_item_count > 0 AND parsed_item_count < expected_item_count * 0.9">HALT with error: "Checklist parse divergence too large (parsed={parsed_item_count}, expected~={expected_item_count}); fix checklist formatting before validation"</action>
|
||||
<action>Determine critical checks from explicit signals only:
|
||||
- item-level markers: [CRITICAL], critical:true, MUST FIX
|
||||
- section-level markers: headings containing CRITICAL (case-insensitive), MUST FIX, MUST-FIX, or the exact phrase "Must Fix Before Proceeding"
|
||||
- XML section attributes: critical="true" or critical="yes"
|
||||
- do not infer criticality from generic keywords alone
|
||||
</action>
|
||||
<action>Detect conditional expressions in checklist items (for example: if/when/unless + variable references)</action>
|
||||
<action if="no checklist items parsed">HALT with error: "Checklist is empty or unparsable"</action>
|
||||
<action if="conditional items reference metadata and metadata is missing">Ask user to provide all missing referenced metadata fields (epic_num, story_num, story_id, story_key, title/story_title) and WAIT before evaluating checklist items</action>
|
||||
</step>
|
||||
|
||||
<step n="3" title="Validate Every Checklist Item" critical="true">
|
||||
<mandate>For every checklist item, evaluate one of: PASS, PARTIAL, FAIL, N/A</mandate>
|
||||
<action>Initialize counters to zero before evaluation:
|
||||
- pass_count, partial_count, fail_count, na_count
|
||||
- critical_fail_count, critical_partial_count
|
||||
- applicable_count, total_item_count, processed_item_count
|
||||
- total_section_count, processed_section_count
|
||||
</action>
|
||||
<action>For each item:
|
||||
- restate requirement in one short sentence
|
||||
- if item contains explicit condition (for example "If story_num > 1") and condition is false, mark N/A with the exact reason
|
||||
- locate explicit evidence in document (include line references when possible)
|
||||
- consider implied coverage only when explicit text is absent
|
||||
- assign verdict and rationale
|
||||
- if PARTIAL/FAIL, describe impact and a concrete fix
|
||||
- update all counters immediately after each verdict
|
||||
</action>
|
||||
<action>Process sections in deterministic order and increment processed_section_count after each section completes</action>
|
||||
<action if="processed_section_count != total_section_count">HALT with error: "Validation incomplete: one or more checklist sections were not processed"</action>
|
||||
<action if="processed_item_count != total_item_count">HALT with error: "Validation incomplete: one or more checklist items were not processed"</action>
|
||||
<action>Compute applicable_count = pass_count + partial_count + fail_count</action>
|
||||
<action>Compute pass_percent using applicable_count (if 0, set pass_percent=0)</action>
|
||||
<action>Set gate_warning:
|
||||
- "No applicable checklist items were evaluated; manual confirmation required" if applicable_count == 0
|
||||
- "N/A" otherwise
|
||||
</action>
|
||||
<action>Set gate decision deterministically:
|
||||
- NEEDS_REVIEW if applicable_count == 0
|
||||
- FAIL if critical_fail_count > 0
|
||||
- FAIL if critical_partial_count > 0
|
||||
- FAIL if fail_count > 0
|
||||
- PASS otherwise
|
||||
</action>
|
||||
<critical>DO NOT SKIP ANY ITEM OR SECTION</critical>
|
||||
</step>
|
||||
|
||||
<step n="4" title="Generate Validation Report">
|
||||
<action>Generate timestamp values:
|
||||
- timestamp_utc for filenames in YYYYMMDD-HHmmss (UTC)
|
||||
- generated_at_utc for report display in ISO-8601 UTC
|
||||
</action>
|
||||
<action>Set report path:
|
||||
- use explicit input {report} when provided
|
||||
- else save to target document folder as validation-report-{timestamp_utc}.md
|
||||
</action>
|
||||
<action>Write report with the format below</action>
|
||||
<action if="report write/save fails">HALT with error: "Validation report could not be saved"</action>
|
||||
|
||||
<report-format>
|
||||
# Validation Report
|
||||
|
||||
- Document: {document}
|
||||
- Checklist: {checklist}
|
||||
- Workflow: {workflow}
|
||||
- Date: {generated_at_utc}
|
||||
|
||||
## Summary
|
||||
- Overall pass rate: {pass_count}/{applicable_count} ({pass_percent}%)
|
||||
- Critical failures: {critical_fail_count}
|
||||
- Critical partials: {critical_partial_count}
|
||||
- Gate decision: {PASS|FAIL|NEEDS_REVIEW}
|
||||
- Gate warning: {gate_warning}
|
||||
|
||||
## Section Results
|
||||
### {Section Name}
|
||||
- PASS: {count}
|
||||
- PARTIAL: {count}
|
||||
- FAIL: {count}
|
||||
- N/A: {count}
|
||||
|
||||
For each checklist item:
|
||||
- [MARK] {item}
|
||||
- Evidence: {quote or line reference}
|
||||
- Analysis: {why mark is correct}
|
||||
- Action (if PARTIAL/FAIL): {specific remediation}
|
||||
|
||||
## Must Fix Before Proceeding
|
||||
- {all critical FAIL and critical PARTIAL items}
|
||||
|
||||
## Should Improve
|
||||
- {all non-critical FAIL and non-critical PARTIAL items}
|
||||
|
||||
## Final Recommendation
|
||||
1. {highest-priority fix}
|
||||
2. {second-priority fix}
|
||||
3. {third-priority fix}
|
||||
</report-format>
|
||||
</step>
|
||||
|
||||
<step n="5" title="Return Decision and Halt">
|
||||
<action>Present concise summary with counts and gate decision</action>
|
||||
<action>Provide report path</action>
|
||||
<action if="critical failures exist">State clearly that workflow should not proceed until fixes are applied</action>
|
||||
<action if="gate decision == PASS">Return control immediately and continue calling workflow execution</action>
|
||||
<action if="gate decision == FAIL OR gate decision == NEEDS_REVIEW">HALT and wait for user direction</action>
|
||||
</step>
|
||||
</flow>
|
||||
|
||||
<halt-conditions>
|
||||
<condition>HALT if workflow file cannot be loaded</condition>
|
||||
<condition>HALT if checklist file cannot be loaded</condition>
|
||||
<condition>HALT if target document cannot be determined after user prompt</condition>
|
||||
<condition>HALT if any checklist section is skipped</condition>
|
||||
<condition>HALT if validation report cannot be saved</condition>
|
||||
</halt-conditions>
|
||||
|
||||
<critical-rules>
|
||||
<rule>Never skip checklist items</rule>
|
||||
<rule>Every PASS/PARTIAL/FAIL must have evidence</rule>
|
||||
<rule>Use deterministic variable resolution before asking the user</rule>
|
||||
<rule>Always save a validation report file</rule>
|
||||
<rule>N/A is valid only for explicit conditional non-applicability</rule>
|
||||
<rule>Criticality must come from explicit checklist markers or critical sections</rule>
|
||||
</critical-rules>
|
||||
</task>
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
const path = require('node:path');
|
||||
const fs = require('fs-extra');
|
||||
const prompts = require('../lib/prompts');
|
||||
const { Installer } = require('../installers/lib/core/installer');
|
||||
|
||||
const installer = new Installer();
|
||||
|
||||
module.exports = {
|
||||
command: 'uninstall',
|
||||
description: 'Remove BMAD installation from the current project',
|
||||
options: [
|
||||
['-y, --yes', 'Remove all BMAD components without prompting (preserves user artifacts)'],
|
||||
['--directory <path>', 'Project directory (default: current directory)'],
|
||||
],
|
||||
action: async (options) => {
|
||||
try {
|
||||
let projectDir;
|
||||
|
||||
if (options.directory) {
|
||||
// Explicit --directory flag takes precedence
|
||||
projectDir = path.resolve(options.directory);
|
||||
} else if (options.yes) {
|
||||
// Non-interactive mode: use current directory
|
||||
projectDir = process.cwd();
|
||||
} else {
|
||||
// Interactive: ask user which directory to uninstall from
|
||||
// select() handles cancellation internally (exits process)
|
||||
const dirChoice = await prompts.select({
|
||||
message: 'Where do you want to uninstall BMAD from?',
|
||||
choices: [
|
||||
{ value: 'cwd', name: `Current directory (${process.cwd()})` },
|
||||
{ value: 'other', name: 'Another directory...' },
|
||||
],
|
||||
});
|
||||
|
||||
if (dirChoice === 'other') {
|
||||
// text() handles cancellation internally (exits process)
|
||||
const customDir = await prompts.text({
|
||||
message: 'Enter the project directory path:',
|
||||
placeholder: process.cwd(),
|
||||
validate: (value) => {
|
||||
if (!value || value.trim().length === 0) return 'Directory path is required';
|
||||
},
|
||||
});
|
||||
|
||||
projectDir = path.resolve(customDir.trim());
|
||||
} else {
|
||||
projectDir = process.cwd();
|
||||
}
|
||||
}
|
||||
|
||||
if (!(await fs.pathExists(projectDir))) {
|
||||
await prompts.log.error(`Directory does not exist: ${projectDir}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { bmadDir } = await installer.findBmadDir(projectDir);
|
||||
|
||||
if (!(await fs.pathExists(bmadDir))) {
|
||||
await prompts.log.warn('No BMAD installation found.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const existingInstall = await installer.getStatus(projectDir);
|
||||
const version = existingInstall.version || 'unknown';
|
||||
const modules = (existingInstall.modules || []).map((m) => m.id || m.name).join(', ');
|
||||
const ides = (existingInstall.ides || []).join(', ');
|
||||
|
||||
const outputFolder = await installer.getOutputFolder(projectDir);
|
||||
|
||||
await prompts.intro('BMAD Uninstall');
|
||||
await prompts.note(`Version: ${version}\nModules: ${modules}\nIDE integrations: ${ides}`, 'Current Installation');
|
||||
|
||||
let removeModules = true;
|
||||
let removeIdeConfigs = true;
|
||||
let removeOutputFolder = false;
|
||||
|
||||
if (!options.yes) {
|
||||
// multiselect() handles cancellation internally (exits process)
|
||||
const selected = await prompts.multiselect({
|
||||
message: 'Select components to remove:',
|
||||
options: [
|
||||
{
|
||||
value: 'modules',
|
||||
label: `BMAD Modules & data (${installer.bmadFolderName}/)`,
|
||||
hint: 'Core installation, agents, workflows, config',
|
||||
},
|
||||
{ value: 'ide', label: 'IDE integrations', hint: ides || 'No IDEs configured' },
|
||||
{ value: 'output', label: `User artifacts (${outputFolder}/)`, hint: 'WARNING: Contains your work products' },
|
||||
],
|
||||
initialValues: ['modules', 'ide'],
|
||||
required: true,
|
||||
});
|
||||
|
||||
removeModules = selected.includes('modules');
|
||||
removeIdeConfigs = selected.includes('ide');
|
||||
removeOutputFolder = selected.includes('output');
|
||||
|
||||
const red = (s) => `\u001B[31m${s}\u001B[0m`;
|
||||
await prompts.note(
|
||||
red('💀 This action is IRREVERSIBLE! Removed files cannot be recovered!') +
|
||||
'\n' +
|
||||
red('💀 IDE configurations and modules will need to be reinstalled.') +
|
||||
'\n' +
|
||||
red('💀 User artifacts are preserved unless explicitly selected.'),
|
||||
'!! DESTRUCTIVE ACTION !!',
|
||||
);
|
||||
|
||||
const confirmed = await prompts.confirm({
|
||||
message: 'Proceed with uninstall?',
|
||||
default: false,
|
||||
});
|
||||
|
||||
if (!confirmed) {
|
||||
await prompts.outro('Uninstall cancelled.');
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 1: IDE integrations
|
||||
if (removeIdeConfigs) {
|
||||
const s = await prompts.spinner();
|
||||
s.start('Removing IDE integrations...');
|
||||
await installer.uninstallIdeConfigs(projectDir, existingInstall, { silent: true });
|
||||
s.stop(`Removed IDE integrations (${ides || 'none'})`);
|
||||
}
|
||||
|
||||
// Phase 2: User artifacts
|
||||
if (removeOutputFolder) {
|
||||
const s = await prompts.spinner();
|
||||
s.start(`Removing user artifacts (${outputFolder}/)...`);
|
||||
await installer.uninstallOutputFolder(projectDir, outputFolder);
|
||||
s.stop('User artifacts removed');
|
||||
}
|
||||
|
||||
// Phase 3: BMAD modules & data (last — other phases may need _bmad/)
|
||||
if (removeModules) {
|
||||
const s = await prompts.spinner();
|
||||
s.start(`Removing BMAD modules & data (${installer.bmadFolderName}/)...`);
|
||||
await installer.uninstallModules(projectDir);
|
||||
s.stop('Modules & data removed');
|
||||
}
|
||||
|
||||
const summary = [];
|
||||
if (removeIdeConfigs) summary.push('IDE integrations cleaned');
|
||||
if (removeModules) summary.push('Modules & data removed');
|
||||
if (removeOutputFolder) summary.push('User artifacts removed');
|
||||
if (!removeOutputFolder) summary.push(`User artifacts preserved in ${outputFolder}/`);
|
||||
|
||||
await prompts.note(summary.join('\n'), 'Summary');
|
||||
await prompts.outro('To reinstall, run: npx bmad-method install');
|
||||
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
try {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
await prompts.log.error(`Uninstall failed: ${errorMessage}`);
|
||||
if (error instanceof Error && error.stack) {
|
||||
await prompts.log.message(error.stack);
|
||||
}
|
||||
} catch {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
@ -34,7 +34,7 @@ startMessage: |
|
|||
- Subscribe on YouTube: https://www.youtube.com/@BMadCode
|
||||
- Every star & sub helps us reach more developers!
|
||||
|
||||
Latest updates: https://github.com/bmad-code-org/BMAD-METHOD/CHANGELOG.md
|
||||
Latest updates: https://github.com/bmad-code-org/BMAD-METHOD/blob/main/CHANGELOG.md
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
|
|
|
|||
|
|
@ -1528,20 +1528,157 @@ class Installer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Uninstall BMAD
|
||||
* Uninstall BMAD with selective removal options
|
||||
* @param {string} directory - Project directory
|
||||
* @param {Object} options - Uninstall options
|
||||
* @param {boolean} [options.removeModules=true] - Remove _bmad/ directory
|
||||
* @param {boolean} [options.removeIdeConfigs=true] - Remove IDE configurations
|
||||
* @param {boolean} [options.removeOutputFolder=false] - Remove user artifacts output folder
|
||||
* @returns {Object} Result with success status and removed components
|
||||
*/
|
||||
async uninstall(directory) {
|
||||
async uninstall(directory, options = {}) {
|
||||
const projectDir = path.resolve(directory);
|
||||
const { bmadDir } = await this.findBmadDir(projectDir);
|
||||
|
||||
if (await fs.pathExists(bmadDir)) {
|
||||
await fs.remove(bmadDir);
|
||||
if (!(await fs.pathExists(bmadDir))) {
|
||||
return { success: false, reason: 'not-installed' };
|
||||
}
|
||||
|
||||
// Clean up IDE configurations
|
||||
await this.ideManager.cleanup(projectDir);
|
||||
// 1. DETECT: Read state BEFORE deleting anything
|
||||
const existingInstall = await this.detector.detect(bmadDir);
|
||||
const outputFolder = await this._readOutputFolder(bmadDir);
|
||||
|
||||
return { success: true };
|
||||
const removed = { modules: false, ideConfigs: false, outputFolder: false };
|
||||
|
||||
// 2. IDE CLEANUP (before _bmad/ deletion so configs are accessible)
|
||||
if (options.removeIdeConfigs !== false) {
|
||||
await this.uninstallIdeConfigs(projectDir, existingInstall, { silent: options.silent });
|
||||
removed.ideConfigs = true;
|
||||
}
|
||||
|
||||
// 3. OUTPUT FOLDER (only if explicitly requested)
|
||||
if (options.removeOutputFolder === true && outputFolder) {
|
||||
removed.outputFolder = await this.uninstallOutputFolder(projectDir, outputFolder);
|
||||
}
|
||||
|
||||
// 4. BMAD DIRECTORY (last, after everything that needs it)
|
||||
if (options.removeModules !== false) {
|
||||
removed.modules = await this.uninstallModules(projectDir);
|
||||
}
|
||||
|
||||
return { success: true, removed, version: existingInstall.version };
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall IDE configurations only
|
||||
* @param {string} projectDir - Project directory
|
||||
* @param {Object} existingInstall - Detection result from detector.detect()
|
||||
* @param {Object} [options] - Options (e.g. { silent: true })
|
||||
* @returns {Promise<Object>} Results from IDE cleanup
|
||||
*/
|
||||
async uninstallIdeConfigs(projectDir, existingInstall, options = {}) {
|
||||
await this.ideManager.ensureInitialized();
|
||||
const cleanupOptions = { isUninstall: true, silent: options.silent };
|
||||
const ideList = existingInstall.ides || [];
|
||||
if (ideList.length > 0) {
|
||||
return this.ideManager.cleanupByList(projectDir, ideList, cleanupOptions);
|
||||
}
|
||||
return this.ideManager.cleanup(projectDir, cleanupOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove user artifacts output folder
|
||||
* @param {string} projectDir - Project directory
|
||||
* @param {string} outputFolder - Output folder name (relative)
|
||||
* @returns {Promise<boolean>} Whether the folder was removed
|
||||
*/
|
||||
async uninstallOutputFolder(projectDir, outputFolder) {
|
||||
if (!outputFolder) return false;
|
||||
const resolvedProject = path.resolve(projectDir);
|
||||
const outputPath = path.resolve(resolvedProject, outputFolder);
|
||||
if (!outputPath.startsWith(resolvedProject + path.sep)) {
|
||||
return false;
|
||||
}
|
||||
if (await fs.pathExists(outputPath)) {
|
||||
await fs.remove(outputPath);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the _bmad/ directory
|
||||
* @param {string} projectDir - Project directory
|
||||
* @returns {Promise<boolean>} Whether the directory was removed
|
||||
*/
|
||||
async uninstallModules(projectDir) {
|
||||
const { bmadDir } = await this.findBmadDir(projectDir);
|
||||
if (await fs.pathExists(bmadDir)) {
|
||||
await fs.remove(bmadDir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configured output folder name for a project
|
||||
* Resolves bmadDir internally from projectDir
|
||||
* @param {string} projectDir - Project directory
|
||||
* @returns {string} Output folder name (relative, default: '_bmad-output')
|
||||
*/
|
||||
async getOutputFolder(projectDir) {
|
||||
const { bmadDir } = await this.findBmadDir(projectDir);
|
||||
return this._readOutputFolder(bmadDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the output_folder setting from module config files
|
||||
* Checks bmm/config.yaml first, then other module configs
|
||||
* @param {string} bmadDir - BMAD installation directory
|
||||
* @returns {string} Output folder path or default
|
||||
*/
|
||||
async _readOutputFolder(bmadDir) {
|
||||
const yaml = require('yaml');
|
||||
|
||||
// Check bmm/config.yaml first (most common)
|
||||
const bmmConfigPath = path.join(bmadDir, 'bmm', 'config.yaml');
|
||||
if (await fs.pathExists(bmmConfigPath)) {
|
||||
try {
|
||||
const content = await fs.readFile(bmmConfigPath, 'utf8');
|
||||
const config = yaml.parse(content);
|
||||
if (config && config.output_folder) {
|
||||
// Strip {project-root}/ prefix if present
|
||||
return config.output_folder.replace(/^\{project-root\}[/\\]/, '');
|
||||
}
|
||||
} catch {
|
||||
// Fall through to other modules
|
||||
}
|
||||
}
|
||||
|
||||
// Scan other module config.yaml files
|
||||
try {
|
||||
const entries = await fs.readdir(bmadDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory() || entry.name === 'bmm' || entry.name.startsWith('_')) continue;
|
||||
const configPath = path.join(bmadDir, entry.name, 'config.yaml');
|
||||
if (await fs.pathExists(configPath)) {
|
||||
try {
|
||||
const content = await fs.readFile(configPath, 'utf8');
|
||||
const config = yaml.parse(content);
|
||||
if (config && config.output_folder) {
|
||||
return config.output_folder.replace(/^\{project-root\}[/\\]/, '');
|
||||
}
|
||||
} catch {
|
||||
// Continue scanning
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Directory scan failed
|
||||
}
|
||||
|
||||
// Default fallback
|
||||
return '_bmad-output';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -456,8 +456,18 @@ LOAD and execute from: {project-root}/{{bmadFolderName}}/{{path}}
|
|||
async cleanup(projectDir, options = {}) {
|
||||
// Clean all target directories
|
||||
if (this.installerConfig?.targets) {
|
||||
const parentDirs = new Set();
|
||||
for (const target of this.installerConfig.targets) {
|
||||
await this.cleanupTarget(projectDir, target.target_dir, options);
|
||||
// Track parent directories for empty-dir cleanup
|
||||
const parentDir = path.dirname(target.target_dir);
|
||||
if (parentDir && parentDir !== '.') {
|
||||
parentDirs.add(parentDir);
|
||||
}
|
||||
}
|
||||
// After all targets cleaned, remove empty parent directories (recursive up to projectDir)
|
||||
for (const parentDir of parentDirs) {
|
||||
await this.removeEmptyParents(projectDir, parentDir);
|
||||
}
|
||||
} else if (this.installerConfig?.target_dir) {
|
||||
await this.cleanupTarget(projectDir, this.installerConfig.target_dir, options);
|
||||
|
|
@ -509,6 +519,41 @@ LOAD and execute from: {project-root}/{{bmadFolderName}}/{{path}}
|
|||
if (removedCount > 0 && !options.silent) {
|
||||
await prompts.log.message(` Cleaned ${removedCount} BMAD files from ${targetDir}`);
|
||||
}
|
||||
|
||||
// Remove empty directory after cleanup
|
||||
if (removedCount > 0) {
|
||||
try {
|
||||
const remaining = await fs.readdir(targetPath);
|
||||
if (remaining.length === 0) {
|
||||
await fs.remove(targetPath);
|
||||
}
|
||||
} catch {
|
||||
// Directory may already be gone or in use — skip
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Recursively remove empty directories walking up from dir toward projectDir
|
||||
* Stops at projectDir boundary — never removes projectDir itself
|
||||
* @param {string} projectDir - Project root (boundary)
|
||||
* @param {string} relativeDir - Relative directory to start from
|
||||
*/
|
||||
async removeEmptyParents(projectDir, relativeDir) {
|
||||
let current = relativeDir;
|
||||
let last = null;
|
||||
while (current && current !== '.' && current !== last) {
|
||||
last = current;
|
||||
const fullPath = path.join(projectDir, current);
|
||||
try {
|
||||
if (!(await fs.pathExists(fullPath))) break;
|
||||
const remaining = await fs.readdir(fullPath);
|
||||
if (remaining.length > 0) break;
|
||||
await fs.rmdir(fullPath);
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
current = path.dirname(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const path = require('node:path');
|
||||
const { BaseIdeSetup } = require('./_base-ide');
|
||||
const chalk = require('chalk');
|
||||
const prompts = require('../../../lib/prompts');
|
||||
const { AgentCommandGenerator } = require('./shared/agent-command-generator');
|
||||
const { BMAD_FOLDER_NAME, toDashPath } = require('./shared/path-utils');
|
||||
const fs = require('fs-extra');
|
||||
|
|
@ -31,7 +31,7 @@ class GitHubCopilotSetup extends BaseIdeSetup {
|
|||
* @param {Object} options - Setup options
|
||||
*/
|
||||
async setup(projectDir, bmadDir, options = {}) {
|
||||
console.log(chalk.cyan(`Setting up ${this.name}...`));
|
||||
if (!options.silent) await prompts.log.info(`Setting up ${this.name}...`);
|
||||
|
||||
// Create .github/agents and .github/prompts directories
|
||||
const githubDir = path.join(projectDir, this.githubDir);
|
||||
|
|
@ -66,21 +66,15 @@ class GitHubCopilotSetup extends BaseIdeSetup {
|
|||
const targetPath = path.join(agentsDir, fileName);
|
||||
await this.writeFile(targetPath, agentContent);
|
||||
agentCount++;
|
||||
|
||||
console.log(chalk.green(` ✓ Created agent: ${fileName}`));
|
||||
}
|
||||
|
||||
// Generate prompt files from bmad-help.csv
|
||||
const promptCount = await this.generatePromptFiles(projectDir, bmadDir, agentArtifacts, agentManifest);
|
||||
|
||||
// Generate copilot-instructions.md
|
||||
await this.generateCopilotInstructions(projectDir, bmadDir, agentManifest);
|
||||
await this.generateCopilotInstructions(projectDir, bmadDir, agentManifest, options);
|
||||
|
||||
console.log(chalk.green(`\n✓ ${this.name} configured:`));
|
||||
console.log(chalk.dim(` - ${agentCount} agents created in .github/agents/`));
|
||||
console.log(chalk.dim(` - ${promptCount} prompts created in .github/prompts/`));
|
||||
console.log(chalk.dim(` - copilot-instructions.md generated`));
|
||||
console.log(chalk.dim(` - Destination: .github/`));
|
||||
if (!options.silent) await prompts.log.success(`${this.name} configured: ${agentCount} agents, ${promptCount} prompts → .github/`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
|
|
@ -406,7 +400,7 @@ tools: ${toolsStr}
|
|||
* @param {string} bmadDir - BMAD installation directory
|
||||
* @param {Map} agentManifest - Agent manifest data
|
||||
*/
|
||||
async generateCopilotInstructions(projectDir, bmadDir, agentManifest) {
|
||||
async generateCopilotInstructions(projectDir, bmadDir, agentManifest, options = {}) {
|
||||
const configVars = await this.loadModuleConfig(bmadDir);
|
||||
|
||||
// Build the agents table from the manifest
|
||||
|
|
@ -495,19 +489,16 @@ Type \`/bmad-\` in Copilot Chat to see all available BMAD workflows and agent ac
|
|||
const after = existing.slice(endIdx + markerEnd.length);
|
||||
const merged = `${before}${markedContent}${after}`;
|
||||
await this.writeFile(instructionsPath, merged);
|
||||
console.log(chalk.green(' ✓ Updated BMAD section in copilot-instructions.md'));
|
||||
} else {
|
||||
// Existing file without markers — back it up before overwriting
|
||||
const backupPath = `${instructionsPath}.bak`;
|
||||
await fs.copy(instructionsPath, backupPath);
|
||||
console.log(chalk.yellow(` ⚠ Backed up existing copilot-instructions.md → copilot-instructions.md.bak`));
|
||||
if (!options.silent) await prompts.log.warn(` Backed up copilot-instructions.md → .bak`);
|
||||
await this.writeFile(instructionsPath, `${markedContent}\n`);
|
||||
console.log(chalk.green(' ✓ Generated copilot-instructions.md (with BMAD markers)'));
|
||||
}
|
||||
} else {
|
||||
// No existing file — create fresh with markers
|
||||
await this.writeFile(instructionsPath, `${markedContent}\n`);
|
||||
console.log(chalk.green(' ✓ Generated copilot-instructions.md'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -607,7 +598,7 @@ Type \`/bmad-\` in Copilot Chat to see all available BMAD workflows and agent ac
|
|||
/**
|
||||
* Cleanup GitHub Copilot configuration - surgically remove only BMAD files
|
||||
*/
|
||||
async cleanup(projectDir) {
|
||||
async cleanup(projectDir, options = {}) {
|
||||
// Clean up agents directory
|
||||
const agentsDir = path.join(projectDir, this.githubDir, this.agentsDir);
|
||||
if (await fs.pathExists(agentsDir)) {
|
||||
|
|
@ -621,8 +612,8 @@ Type \`/bmad-\` in Copilot Chat to see all available BMAD workflows and agent ac
|
|||
}
|
||||
}
|
||||
|
||||
if (removed > 0) {
|
||||
console.log(chalk.dim(` Cleaned up ${removed} existing BMAD agents`));
|
||||
if (removed > 0 && !options.silent) {
|
||||
await prompts.log.message(` Cleaned up ${removed} existing BMAD agents`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -639,16 +630,70 @@ Type \`/bmad-\` in Copilot Chat to see all available BMAD workflows and agent ac
|
|||
}
|
||||
}
|
||||
|
||||
if (removed > 0) {
|
||||
console.log(chalk.dim(` Cleaned up ${removed} existing BMAD prompts`));
|
||||
if (removed > 0 && !options.silent) {
|
||||
await prompts.log.message(` Cleaned up ${removed} existing BMAD prompts`);
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
// During uninstall, also strip BMAD markers from copilot-instructions.md.
|
||||
// During reinstall (default), this is skipped because generateCopilotInstructions()
|
||||
// handles marker-based replacement in a single read-modify-write pass,
|
||||
// which correctly preserves user content outside the markers.
|
||||
if (options.isUninstall) {
|
||||
await this.cleanupCopilotInstructions(projectDir, options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip BMAD marker section from copilot-instructions.md
|
||||
* If file becomes empty after stripping, delete it.
|
||||
* If a .bak backup exists and the main file was deleted, restore the backup.
|
||||
* @param {string} projectDir - Project directory
|
||||
* @param {Object} [options] - Options (e.g. { silent: true })
|
||||
*/
|
||||
async cleanupCopilotInstructions(projectDir, options = {}) {
|
||||
const instructionsPath = path.join(projectDir, this.githubDir, 'copilot-instructions.md');
|
||||
const backupPath = `${instructionsPath}.bak`;
|
||||
|
||||
if (!(await fs.pathExists(instructionsPath))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const content = await fs.readFile(instructionsPath, 'utf8');
|
||||
const markerStart = '<!-- BMAD:START -->';
|
||||
const markerEnd = '<!-- BMAD:END -->';
|
||||
const startIdx = content.indexOf(markerStart);
|
||||
const endIdx = content.indexOf(markerEnd);
|
||||
|
||||
if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) {
|
||||
return; // No valid markers found
|
||||
}
|
||||
|
||||
// Strip the marker section (including markers)
|
||||
const before = content.slice(0, startIdx);
|
||||
const after = content.slice(endIdx + markerEnd.length);
|
||||
const cleaned = before + after;
|
||||
|
||||
if (cleaned.trim().length === 0) {
|
||||
// File is empty after stripping — delete it
|
||||
await fs.remove(instructionsPath);
|
||||
|
||||
// If backup exists, restore it
|
||||
if (await fs.pathExists(backupPath)) {
|
||||
await fs.rename(backupPath, instructionsPath);
|
||||
if (!options.silent) {
|
||||
await prompts.log.message(' Restored copilot-instructions.md from backup');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Write cleaned content back (preserve original whitespace)
|
||||
await fs.writeFile(instructionsPath, cleaned, 'utf8');
|
||||
|
||||
// If backup exists, it's stale now — remove it
|
||||
if (await fs.pathExists(backupPath)) {
|
||||
await fs.remove(backupPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -216,13 +216,14 @@ class IdeManager {
|
|||
/**
|
||||
* Cleanup IDE configurations
|
||||
* @param {string} projectDir - Project directory
|
||||
* @param {Object} [options] - Cleanup options passed through to handlers
|
||||
*/
|
||||
async cleanup(projectDir) {
|
||||
async cleanup(projectDir, options = {}) {
|
||||
const results = [];
|
||||
|
||||
for (const [name, handler] of this.handlers) {
|
||||
try {
|
||||
await handler.cleanup(projectDir);
|
||||
await handler.cleanup(projectDir, options);
|
||||
results.push({ ide: name, success: true });
|
||||
} catch (error) {
|
||||
results.push({ ide: name, success: false, error: error.message });
|
||||
|
|
@ -232,6 +233,40 @@ class IdeManager {
|
|||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup only the IDEs in the provided list
|
||||
* Falls back to cleanup() (all handlers) if ideList is empty or undefined
|
||||
* @param {string} projectDir - Project directory
|
||||
* @param {Array<string>} ideList - List of IDE names to clean up
|
||||
* @param {Object} [options] - Cleanup options passed through to handlers
|
||||
* @returns {Array} Results array
|
||||
*/
|
||||
async cleanupByList(projectDir, ideList, options = {}) {
|
||||
if (!ideList || ideList.length === 0) {
|
||||
return this.cleanup(projectDir, options);
|
||||
}
|
||||
|
||||
await this.ensureInitialized();
|
||||
const results = [];
|
||||
|
||||
// Build lowercase lookup for case-insensitive matching
|
||||
const lowercaseHandlers = new Map([...this.handlers.entries()].map(([k, v]) => [k.toLowerCase(), v]));
|
||||
|
||||
for (const ideName of ideList) {
|
||||
const handler = lowercaseHandlers.get(ideName.toLowerCase());
|
||||
if (!handler) continue;
|
||||
|
||||
try {
|
||||
await handler.cleanup(projectDir, options);
|
||||
results.push({ ide: ideName, success: true });
|
||||
} catch (error) {
|
||||
results.push({ ide: ideName, success: false, error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of supported IDEs
|
||||
* @returns {Array} List of supported IDE names
|
||||
|
|
|
|||
Loading…
Reference in New Issue