bmad-method 6.8.1-next.8 → 6.8.1-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const { spawnSync } = require('node:child_process');
|
|
2
|
+
const prompts = require('../prompts');
|
|
3
|
+
|
|
4
|
+
// Python 3.11 added stdlib `tomllib` (PEP 680), which the shared scripts in
|
|
5
|
+
// src/scripts/ (resolve_config.py, resolve_customization.py) require to read
|
|
6
|
+
// BMAD's TOML config files. memlog.py is more lenient and runs on 3.8+.
|
|
7
|
+
const PYTHON_FULL_SUPPORT = { major: 3, minor: 11 };
|
|
8
|
+
const PYTHON_PARTIAL_SUPPORT = { major: 3, minor: 8 };
|
|
9
|
+
|
|
10
|
+
// Every runtime call site (skill steps, on_complete hooks) invokes a literal
|
|
11
|
+
// `python3`, so only that command's version vouches for BMAD features. The
|
|
12
|
+
// fallback probes exist to tell the user "Python is installed, but not under
|
|
13
|
+
// the name BMAD uses" instead of a misleading "No Python found".
|
|
14
|
+
const RUNTIME_COMMAND = 'python3';
|
|
15
|
+
const PROBE_CANDIDATES =
|
|
16
|
+
process.platform === 'win32'
|
|
17
|
+
? [
|
|
18
|
+
{ command: 'python3', args: ['--version'] },
|
|
19
|
+
{ command: 'py', args: ['-3', '--version'] },
|
|
20
|
+
{ command: 'python', args: ['--version'] },
|
|
21
|
+
]
|
|
22
|
+
: [
|
|
23
|
+
{ command: 'python3', args: ['--version'] },
|
|
24
|
+
{ command: 'python', args: ['--version'] },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse a `python --version` output line into version parts.
|
|
29
|
+
* Python 3 prints to stdout; Python 2 printed to stderr — callers pass both.
|
|
30
|
+
* @param {string} output - Combined stdout/stderr from `python --version`
|
|
31
|
+
* @returns {{major: number, minor: number, patch: number, raw: string}|null}
|
|
32
|
+
*/
|
|
33
|
+
function parsePythonVersion(output) {
|
|
34
|
+
if (!output) return null;
|
|
35
|
+
const match = output.match(/Python\s+(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
36
|
+
if (!match) return null;
|
|
37
|
+
return {
|
|
38
|
+
major: Number(match[1]),
|
|
39
|
+
minor: Number(match[2]),
|
|
40
|
+
patch: Number(match[3] || 0),
|
|
41
|
+
raw: `${match[1]}.${match[2]}.${match[3] || 0}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Classify a detected Python version against BMAD's feature requirements.
|
|
47
|
+
* @param {{major: number, minor: number}|null} version
|
|
48
|
+
* @returns {'full'|'partial'|'unsupported'|'none'}
|
|
49
|
+
*/
|
|
50
|
+
function classifyPython(version) {
|
|
51
|
+
if (!version) return 'none';
|
|
52
|
+
const { major, minor } = version;
|
|
53
|
+
if (major > PYTHON_FULL_SUPPORT.major || (major === PYTHON_FULL_SUPPORT.major && minor >= PYTHON_FULL_SUPPORT.minor)) {
|
|
54
|
+
return 'full';
|
|
55
|
+
}
|
|
56
|
+
if (major === PYTHON_PARTIAL_SUPPORT.major && minor >= PYTHON_PARTIAL_SUPPORT.minor) {
|
|
57
|
+
return 'partial';
|
|
58
|
+
}
|
|
59
|
+
return 'unsupported';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Run one probe candidate and return its parsed version, or null.
|
|
64
|
+
* @param {{command: string, args: string[]}} candidate
|
|
65
|
+
* @returns {{major: number, minor: number, patch: number, raw: string}|null}
|
|
66
|
+
*/
|
|
67
|
+
function probeVersion(candidate) {
|
|
68
|
+
const run = (extra = {}) =>
|
|
69
|
+
spawnSync(candidate.command, candidate.args, {
|
|
70
|
+
encoding: 'utf8',
|
|
71
|
+
timeout: 5000,
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
...extra,
|
|
74
|
+
});
|
|
75
|
+
let result = run();
|
|
76
|
+
// Node >=18.20/20.12 refuses to spawn .bat/.cmd without a shell
|
|
77
|
+
// (CVE-2024-27980 hardening) and reports EINVAL — pyenv-win ships its
|
|
78
|
+
// python shims as .bat. Args here are static literals, so a shell retry
|
|
79
|
+
// is injection-safe.
|
|
80
|
+
if (result.error && result.error.code === 'EINVAL' && process.platform === 'win32') {
|
|
81
|
+
result = run({ shell: true });
|
|
82
|
+
}
|
|
83
|
+
if (result.error) return null;
|
|
84
|
+
return parsePythonVersion(`${result.stdout || ''}\n${result.stderr || ''}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Probe the local environment for a Python interpreter.
|
|
89
|
+
* Tries each candidate command and returns the first that reports a version.
|
|
90
|
+
* `isRuntimeCommand` is true only when the match is `python3` — the command
|
|
91
|
+
* BMAD scripts actually invoke.
|
|
92
|
+
* @returns {{command: string, version: {major: number, minor: number, patch: number, raw: string}, isRuntimeCommand: boolean}|null}
|
|
93
|
+
*/
|
|
94
|
+
function detectPython() {
|
|
95
|
+
for (const candidate of PROBE_CANDIDATES) {
|
|
96
|
+
try {
|
|
97
|
+
const version = probeVersion(candidate);
|
|
98
|
+
if (version) {
|
|
99
|
+
const display = candidate.args.length > 1 ? `${candidate.command} ${candidate.args.slice(0, -1).join(' ')}` : candidate.command;
|
|
100
|
+
return { command: display, version, isRuntimeCommand: candidate.command === RUNTIME_COMMAND };
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
// Candidate not runnable — try the next one.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function upgradeHints() {
|
|
110
|
+
return [
|
|
111
|
+
'How to get Python 3.11+ (as `python3`):',
|
|
112
|
+
' macOS: brew install python3',
|
|
113
|
+
' Windows: winget install Python.Python.3.12 (then ensure `python3` resolves, e.g. enable the python3 alias)',
|
|
114
|
+
' Linux/WSL: sudo apt install python3 (Ubuntu 24.04+ ships 3.12; older distros: use pyenv or deadsnakes)',
|
|
115
|
+
' Docker: add python3 to your image (e.g. apk add python3 / apt-get install -y python3)',
|
|
116
|
+
].join('\n');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Check the local Python environment and warn about degraded BMAD features.
|
|
121
|
+
*
|
|
122
|
+
* Warn-don't-block: most of BMAD works without Python, so the install always
|
|
123
|
+
* may proceed — but the user must explicitly acknowledge the warning so it
|
|
124
|
+
* can't scroll past unseen. In non-interactive runs (--yes, or stdin is not
|
|
125
|
+
* a TTY) the warning is logged and the install continues without a prompt.
|
|
126
|
+
*
|
|
127
|
+
* @param {Object} [options]
|
|
128
|
+
* @param {boolean} [options.nonInteractive=false] - Skip the ack prompt (--yes, or no TTY)
|
|
129
|
+
* @returns {Promise<{status: string, detected: Object|null}>}
|
|
130
|
+
*/
|
|
131
|
+
async function checkPythonEnvironment({ nonInteractive = false } = {}) {
|
|
132
|
+
// Called via module.exports so tests can stub detection.
|
|
133
|
+
const detected = module.exports.detectPython();
|
|
134
|
+
const status = classifyPython(detected ? detected.version : null);
|
|
135
|
+
|
|
136
|
+
if (status === 'full' && detected.isRuntimeCommand) {
|
|
137
|
+
await prompts.log.success(`Python ${detected.version.raw} detected (${detected.command}) — all BMAD features supported.`);
|
|
138
|
+
return { status, detected };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (detected && !detected.isRuntimeCommand) {
|
|
142
|
+
await prompts.log.warn(
|
|
143
|
+
`Python ${detected.version.raw} found via \`${detected.command}\`, but BMAD scripts invoke \`python3\`, which is not on PATH.\n` +
|
|
144
|
+
`Python-powered features (memlog session memory, TOML config resolution) won't run until \`python3\` resolves —\n` +
|
|
145
|
+
`add a python3 alias/shim, or reinstall Python with the python3 launcher enabled.`,
|
|
146
|
+
);
|
|
147
|
+
} else if (status === 'partial') {
|
|
148
|
+
await prompts.log.warn(
|
|
149
|
+
`Python ${detected.version.raw} detected (${detected.command}) — BMAD's TOML config tools need Python 3.11+ (stdlib tomllib).\n` +
|
|
150
|
+
`Works: memlog session memory. Won't work: config/customization resolution scripts.`,
|
|
151
|
+
);
|
|
152
|
+
} else {
|
|
153
|
+
const found =
|
|
154
|
+
status === 'unsupported' ? `Python ${detected.version.raw} detected (${detected.command}) — too old.` : 'No Python found on PATH.';
|
|
155
|
+
await prompts.log.warn(
|
|
156
|
+
`${found} BMAD installs fine without it, but Python-powered features\n` +
|
|
157
|
+
`(memlog session memory, TOML config resolution) won't run until Python 3.11+ is available.`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
await prompts.note(upgradeHints(), 'Python 3.11+ recommended');
|
|
161
|
+
|
|
162
|
+
if (nonInteractive) {
|
|
163
|
+
await prompts.log.info('Continuing anyway (non-interactive run). You can fix Python later — no reinstall needed.');
|
|
164
|
+
return { status, detected };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const choice = await prompts.select({
|
|
168
|
+
message: "BMAD's Python-powered features won't work yet. How do you want to proceed?",
|
|
169
|
+
choices: [
|
|
170
|
+
{
|
|
171
|
+
name: 'Continue install',
|
|
172
|
+
value: 'continue',
|
|
173
|
+
hint: 'BMAD works without Python — you can fix Python later, no reinstall needed',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'Quit and fix Python first',
|
|
177
|
+
value: 'quit',
|
|
178
|
+
hint: 'make Python 3.11+ available as python3, then re-run the installer',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
default: 'continue',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (choice === 'quit') {
|
|
185
|
+
await prompts.cancel('Make Python 3.11+ available as `python3` (see hints above), then re-run the installer.');
|
|
186
|
+
process.exit(0);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return { status, detected };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = {
|
|
193
|
+
checkPythonEnvironment,
|
|
194
|
+
detectPython,
|
|
195
|
+
parsePythonVersion,
|
|
196
|
+
classifyPython,
|
|
197
|
+
PYTHON_FULL_SUPPORT,
|
|
198
|
+
PYTHON_PARTIAL_SUPPORT,
|
|
199
|
+
};
|
package/tools/installer/ui.js
CHANGED
|
@@ -161,6 +161,16 @@ class UI {
|
|
|
161
161
|
const messageLoader = new MessageLoader();
|
|
162
162
|
await messageLoader.displayStartMessage();
|
|
163
163
|
|
|
164
|
+
// Probe the local Python before any other prompts: several BMAD features
|
|
165
|
+
// (memlog session memory, TOML config resolution) need Python 3.11+ at
|
|
166
|
+
// runtime. Warn-don't-block, but require an explicit ack so the warning
|
|
167
|
+
// can't scroll past unseen. The installer runs in the destination
|
|
168
|
+
// environment, so probing PATH here tests the right machine.
|
|
169
|
+
// Skip the ack when stdin isn't a TTY (CI/Docker/piped): clack's select
|
|
170
|
+
// on closed stdin resolves to cancel, which would silently exit 0.
|
|
171
|
+
const { checkPythonEnvironment } = require('./core/python-check');
|
|
172
|
+
await checkPythonEnvironment({ nonInteractive: !!options.yes || !process.stdin.isTTY });
|
|
173
|
+
|
|
164
174
|
// Parse channel flags (--channel/--all-*/--next=/--pin) once. Warnings
|
|
165
175
|
// are surfaced immediately so the user sees them before any git ops run.
|
|
166
176
|
const channelOptions = parseChannelOptions(options);
|