diff --git a/tools/bmad-npx-wrapper.js b/tools/bmad-npx-wrapper.js index 9c6daeee..bbde964f 100755 --- a/tools/bmad-npx-wrapper.js +++ b/tools/bmad-npx-wrapper.js @@ -26,9 +26,12 @@ if (isNpxExecution) { } try { + // Honor the directory where the user invoked npx from + const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd(); execSync(`node "${bmadScriptPath}" ${arguments_.join(' ')}`, { stdio: 'inherit', - cwd: path.dirname(__dirname), + cwd: originalCwd, + env: { ...process.env, BMAD_ORIGINAL_CWD: originalCwd }, }); } catch (error) { process.exit(error.status || 1); diff --git a/tools/installer/bin/bmad.js b/tools/installer/bin/bmad.js index b8272c14..8cd975f0 100755 --- a/tools/installer/bin/bmad.js +++ b/tools/installer/bin/bmad.js @@ -208,6 +208,7 @@ async function promptInstallation() { console.log(chalk.bold.magenta('🚀 Universal AI Agent Framework for Any Domain')); console.log(chalk.bold.blue(`✨ Installer v${version}\n`)); + const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd(); const answers = {}; // Ask for installation directory first @@ -216,7 +217,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: originalCwd, validate: (input) => { if (!input.trim()) { return 'Please enter a valid project path'; diff --git a/tools/installer/lib/ide-setup.js b/tools/installer/lib/ide-setup.js index b6944ad1..5581d7a6 100644 --- a/tools/installer/lib/ide-setup.js +++ b/tools/installer/lib/ide-setup.js @@ -520,15 +520,14 @@ class IdeSetup extends BaseIdeSetup { } if (await fileManager.pathExists(tasksDir)) { - const glob = require('glob'); - const taskFiles = glob.sync('*.md', { cwd: tasksDir }); + const taskFiles = await resourceLocator.findFiles('*.md', { cwd: tasksDir }); allTaskIds.push(...taskFiles.map((file) => path.basename(file, '.md'))); } // Check common tasks const commonTasksDir = path.join(installDir, 'common', 'tasks'); if (await fileManager.pathExists(commonTasksDir)) { - const commonTaskFiles = glob.sync('*.md', { cwd: commonTasksDir }); + const commonTaskFiles = await resourceLocator.findFiles('*.md', { cwd: commonTasksDir }); allTaskIds.push(...commonTaskFiles.map((file) => path.basename(file, '.md'))); } diff --git a/tools/installer/lib/installer.js b/tools/installer/lib/installer.js index e709b4cf..8b8421f1 100644 --- a/tools/installer/lib/installer.js +++ b/tools/installer/lib/installer.js @@ -27,7 +27,8 @@ class Installer { try { // Store the original CWD where npx was executed - const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd(); + const originalCwd = + process.env.BMAD_ORIGINAL_CWD || process.env.INIT_CWD || process.env.PWD || process.cwd(); // Resolve installation directory relative to where the user ran the command let installDir = path.isAbsolute(config.directory)