Skip to content

Commit 6e63bf2

Browse files
Brian Madisonclaude
authored andcommitted
Fix npx execution issue with bmad CLI
- Added wrapper script (bmad.js) at root to handle npx execution context - Fixed module resolution in tools/installer/bin/bmad.js for both local and npx contexts - Updated package.json bin paths to use the wrapper script - Handles temporary npx directories properly using execSync This fixes the issue where `npx github:bmadcode/BMAD-METHOD#v4-alpha bmad` was dropping into a shell instead of executing the command. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8d788b6 commit 6e63bf2

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ BMAD-METHOD (Breakthrough Method of AgileAI Driven Development) transforms softw
1818
- Scrum Master: Story generation and sprint planning
1919
- Developer: Code implementation
2020
- QA Specialist: Testing and quality assurance
21-
- BMAD Orchestrator: Role transformation via slash commands
22-
- BMAD Master: Universal executor of all capabilities
21+
- BMAD Orchestrator: Role transformation via slash commands and BMAD Method Tutor
22+
- BMAD Master: Universal executor of all capabilities without role switching
2323

2424
### Team Configurations
2525

@@ -37,10 +37,10 @@ BMAD-METHOD (Breakthrough Method of AgileAI Driven Development) transforms softw
3737

3838
### Option 1: Web Bundles (No Installation)
3939

40-
1. Download pre-built bundles from `web-bundles/`
40+
1. Download pre-built bundles from `bmad-core/web-bundles/`
4141
2. Upload to ChatGPT or Gemini
4242
3. Set instructions: "Your critical operating instructions are attached, you ARE the BMad Agent..."
43-
4. Start with `/help` command
43+
4. Start with `/help` command if unsure what to do!
4444

4545
### Option 2: IDE Integration
4646

bmad.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* BMAD Method CLI - Direct execution wrapper for npx
5+
* This file ensures proper execution when run via npx from GitHub
6+
*/
7+
8+
const { execSync } = require('child_process');
9+
const path = require('path');
10+
const fs = require('fs');
11+
12+
// Check if we're running in an npx temporary directory
13+
const isNpxExecution = __dirname.includes('_npx') || __dirname.includes('.npm');
14+
15+
// If running via npx, we need to handle things differently
16+
if (isNpxExecution) {
17+
// The actual bmad.js is in tools/installer/bin/
18+
const bmadScriptPath = path.join(__dirname, 'tools', 'installer', 'bin', 'bmad.js');
19+
20+
// Verify the file exists
21+
if (!fs.existsSync(bmadScriptPath)) {
22+
console.error('Error: Could not find bmad.js at', bmadScriptPath);
23+
console.error('Current directory:', __dirname);
24+
process.exit(1);
25+
}
26+
27+
// Execute with proper working directory
28+
try {
29+
execSync(`node "${bmadScriptPath}" ${process.argv.slice(2).join(' ')}`, {
30+
stdio: 'inherit',
31+
cwd: __dirname
32+
});
33+
} catch (error) {
34+
// execSync will throw if the command exits with non-zero
35+
// But the stdio is inherited, so the error is already displayed
36+
process.exit(error.status || 1);
37+
}
38+
} else {
39+
// Local execution - just require the installer directly
40+
require('./tools/installer/bin/bmad.js');
41+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Breakthrough Method of Agile AI-driven Development",
55
"main": "tools/cli.js",
66
"bin": {
7-
"bmad": "./tools/installer/bin/bmad.js",
8-
"bmad-method": "./tools/installer/bin/bmad.js"
7+
"bmad": "./bmad.js",
8+
"bmad-method": "./bmad.js"
99
},
1010
"scripts": {
1111
"build": "node tools/cli.js build",

tools/installer/bin/bmad.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@ const { program } = require('commander');
44
const inquirer = require('inquirer');
55
const chalk = require('chalk');
66
const path = require('path');
7-
const { version } = require('../package.json');
8-
const installer = require('../lib/installer');
7+
8+
// Handle both execution contexts (from root via npx or from installer directory)
9+
let version, installer;
10+
try {
11+
// Try installer context first (when run from tools/installer/)
12+
version = require('../package.json').version;
13+
installer = require('../lib/installer');
14+
} catch (e) {
15+
// Fall back to root context (when run via npx from GitHub)
16+
try {
17+
version = require('../../../package.json').version;
18+
installer = require('../../../tools/installer/lib/installer');
19+
} catch (e2) {
20+
console.error(chalk.red('Error: Could not load required modules. Please ensure you are running from the correct directory.'));
21+
console.error(chalk.yellow('Debug info:'), {
22+
__dirname,
23+
cwd: process.cwd(),
24+
error: e2.message
25+
});
26+
process.exit(1);
27+
}
28+
}
929

1030
program
1131
.version(version)

0 commit comments

Comments
 (0)