From 97b7416a1c6a9b45013dd067b2c6852e121cbe0b Mon Sep 17 00:00:00 2001 From: yangjun <290968698@qq.com> Date: Thu, 18 Sep 2025 20:20:48 +0800 Subject: [PATCH] use INIT_CWD as default dir cause it's current working dir --- tools/builders/web-builder.js | 2 +- tools/cli.js | 10 +++++----- tools/flattener/main.js | 14 ++++++++++---- tools/installer/bin/bmad.js | 4 ++-- tools/installer/lib/installer.js | 13 ++++++++----- tools/upgraders/v3-to-v4-upgrader.js | 2 +- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/builders/web-builder.js b/tools/builders/web-builder.js index 4ea30da4..4c0685db 100644 --- a/tools/builders/web-builder.js +++ b/tools/builders/web-builder.js @@ -5,7 +5,7 @@ const yamlUtilities = require('../lib/yaml-utils'); class WebBuilder { constructor(options = {}) { - this.rootDir = options.rootDir || process.cwd(); + this.rootDir = options.rootDir || process.env.INIT_CWD || process.cwd(); this.outputDirs = options.outputDirs || [path.join(this.rootDir, 'dist')]; this.resolver = new DependencyResolver(this.rootDir); this.templatePath = path.join( diff --git a/tools/cli.js b/tools/cli.js index 5014cf06..26320be3 100644 --- a/tools/cli.js +++ b/tools/cli.js @@ -21,7 +21,7 @@ program .option('--no-clean', 'Skip cleaning output directories') .action(async (options) => { const builder = new WebBuilder({ - rootDir: process.cwd(), + rootDir: process.env.INIT_CWD || process.cwd(), }); try { @@ -64,7 +64,7 @@ program .option('--no-clean', 'Skip cleaning output directories') .action(async (options) => { const builder = new WebBuilder({ - rootDir: process.cwd(), + rootDir: process.env.INIT_CWD || process.cwd(), }); try { @@ -87,7 +87,7 @@ program .command('list:agents') .description('List all available agents') .action(async () => { - const builder = new WebBuilder({ rootDir: process.cwd() }); + const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() }); const agents = await builder.resolver.listAgents(); console.log('Available agents:'); for (const agent of agents) console.log(` - ${agent}`); @@ -98,7 +98,7 @@ program .command('list:expansions') .description('List all available expansion packs') .action(async () => { - const builder = new WebBuilder({ rootDir: process.cwd() }); + const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() }); const expansions = await builder.listExpansionPacks(); console.log('Available expansion packs:'); for (const expansion of expansions) console.log(` - ${expansion}`); @@ -109,7 +109,7 @@ program .command('validate') .description('Validate agent and team configurations') .action(async () => { - const builder = new WebBuilder({ rootDir: process.cwd() }); + const builder = new WebBuilder({ rootDir: process.env.INIT_CWD || process.cwd() }); try { // Validate by attempting to build all agents and teams const agents = await builder.resolver.listAgents(); diff --git a/tools/flattener/main.js b/tools/flattener/main.js index 50a831bf..665d79e4 100644 --- a/tools/flattener/main.js +++ b/tools/flattener/main.js @@ -70,7 +70,7 @@ program .name('bmad-flatten') .description('BMAD-METHODâ„¢ codebase flattener tool') .version('1.0.0') - .option('-i, --input ', 'Input directory to flatten', process.cwd()) + .option('-i, --input ', 'Input directory to flatten', process.env.INIT_CWD || process.cwd()) .option('-o, --output ', 'Output file path', 'flattened-codebase.xml') .action(async (options) => { let inputDir = path.resolve(options.input); @@ -87,7 +87,7 @@ program const noPathArguments = !userSpecifiedInput && !userSpecifiedOutput; if (noPathArguments) { - const detectedRoot = await findProjectRoot(process.cwd()); + const detectedRoot = await findProjectRoot(process.env.INIT_CWD || process.cwd()); const suggestedOutput = detectedRoot ? path.join(detectedRoot, 'flattened-codebase.xml') : path.resolve('flattened-codebase.xml'); @@ -101,7 +101,10 @@ program inputDir = detectedRoot; outputPath = suggestedOutput; } else { - inputDir = await promptPath('Enter input directory path', process.cwd()); + inputDir = await promptPath( + 'Enter input directory path', + process.env.INIT_CWD || process.cwd(), + ); outputPath = await promptPath( 'Enter output file path', path.join(inputDir, 'flattened-codebase.xml'), @@ -109,7 +112,10 @@ program } } else { console.log('Could not auto-detect a project root.'); - inputDir = await promptPath('Enter input directory path', process.cwd()); + inputDir = await promptPath( + 'Enter input directory path', + process.env.INIT_CWD || process.cwd(), + ); outputPath = await promptPath( 'Enter output file path', path.join(inputDir, 'flattened-codebase.xml'), diff --git a/tools/installer/bin/bmad.js b/tools/installer/bin/bmad.js index d016b268..27244c04 100755 --- a/tools/installer/bin/bmad.js +++ b/tools/installer/bin/bmad.js @@ -181,7 +181,7 @@ program program .command('flatten') .description('Flatten codebase to XML format') - .option('-i, --input ', 'Input directory to flatten', process.cwd()) + .option('-i, --input ', 'Input directory to flatten', process.env.INIT_CWD || process.cwd()) .option('-o, --output ', 'Output file path', 'flattened-codebase.xml') .action(async (options) => { try { @@ -216,7 +216,7 @@ async function promptInstallation() { type: 'input', name: 'directory', message: 'Enter the full path to your project directory where BMad should be installed:', - default: path.resolve('.'), + default: path.resolve(process.env.INIT_CWD || '.'), validate: (input) => { if (!input.trim()) { return 'Please enter a valid project path'; diff --git a/tools/installer/lib/installer.js b/tools/installer/lib/installer.js index d04830d7..f988575b 100644 --- a/tools/installer/lib/installer.js +++ b/tools/installer/lib/installer.js @@ -1963,7 +1963,7 @@ class Installer { async findInstallation() { // Look for .bmad-core in current directory or parent directories - let currentDir = process.cwd(); + let currentDir = process.env.INIT_CWD || process.cwd(); while (currentDir !== path.dirname(currentDir)) { const bmadDir = path.join(currentDir, '.bmad-core'); @@ -1977,10 +1977,13 @@ class Installer { } // Also check if we're inside a .bmad-core directory - if (path.basename(process.cwd()) === '.bmad-core') { - const manifestPath = path.join(process.cwd(), 'install-manifest.yaml'); + if (path.basename(process.env.INIT_CWD || process.cwd()) === '.bmad-core') { + const manifestPath = path.join( + process.env.INIT_CWD || process.cwd(), + 'install-manifest.yaml', + ); if (await fileManager.pathExists(manifestPath)) { - return path.dirname(process.cwd()); // Return parent directory + return path.dirname(process.env.INIT_CWD || process.cwd()); // Return parent directory } } @@ -2001,7 +2004,7 @@ class Installer { const child = spawn('node', [flattenerPath, ...arguments_], { stdio: 'inherit', - cwd: process.cwd(), + cwd: process.env.INIT_CWD || process.cwd(), }); child.on('exit', (code) => { diff --git a/tools/upgraders/v3-to-v4-upgrader.js b/tools/upgraders/v3-to-v4-upgrader.js index 94c72563..dcc126b8 100644 --- a/tools/upgraders/v3-to-v4-upgrader.js +++ b/tools/upgraders/v3-to-v4-upgrader.js @@ -109,7 +109,7 @@ class V3ToV4Upgrader { type: 'input', name: 'projectPath', message: 'Please enter the path to your V3 project:', - default: process.cwd(), + default: process.env.INIT_CWD || process.cwd(), }, ]);