From d32d5691d86aee0848f0d0346e01ca13fb1fc0b2 Mon Sep 17 00:00:00 2001 From: bmad Date: Sat, 28 Nov 2026 22:51:35 -0600 Subject: [PATCH] feat: add v6 upgrade guardrails and allow installs without uv --- README.md | 14 ++++- messages.yaml | 32 ++++++++--- src/commands/apply.js | 14 +++-- src/commands/ending.js | 22 ++++++-- src/commands/existing-install.js | 8 ++- src/commands/install.js | 30 +++++++--- src/commands/status.js | 29 +++++----- src/commands/update.js | 29 ++++++---- src/preflight.js | 10 ++-- src/report.js | 53 ++++++++++++----- test/commands/install.test.js | 97 ++++++++++++++++++++++++++++++++ test/commands/status.test.js | 33 +++++++++-- test/commands/update.test.js | 54 +++++++++++++++++- test/helpers/command-fakes.js | 10 +++- test/messages.test.js | 7 ++- test/preflight.test.js | 31 ++++++---- test/report.test.js | 15 +++++ tools/release.md | 2 + 18 files changed, 389 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index 213fff3..e68f68f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Install commands -Needs Node 22 or newer and [uv](https://docs.astral.sh/uv/getting-started/installation/) on your PATH. +Needs Node 22 or newer (required by the skills CLI). [uv](https://docs.astral.sh/uv/getting-started/installation/) is recommended for BMad setup and helper scripts; without it, the installer warns and still installs your skills, with a more manual setup experience until uv is added. ``` npx bmad-method install into the current directory @@ -87,6 +87,18 @@ Three routes: ask the BMad Agent, run `npx bmad-method update`, or run `npx skil After adding or updating any skill by any route, ask the BMad Agent to update. Only it reconciles what is installed. +## Staying on or upgrading from BMad v6 + +To stay on or update an existing BMad v6 install (e.g. `6.4` to `6.12`), run the v6 installer: + +``` +npx bmad-method@6 install +``` + +Or pin an exact version such as `npx bmad-method@6.12.4 install`. + +When this v7 installer detects `_bmad/_config/manifest.yaml` in a project without v7 skills yet, it warns you, points you to `npx bmad-method@6 install`, and (in interactive mode) asks you to confirm before installing v7. Back up `_bmad/` and `_bmad-output/` before upgrading; `bmad setup` handles v6 cleanup and migrations once v7 skills are installed. `update` and `status` stop on a v6-only project and remind you which command to run. + ## Removing Ask the BMad Agent to remove a module (it previews every affected skill folder, lock entry, and `_bmad//`, and preserves `_bmad/custom/`), or run `npx skills remove` for individual skills. This installer has no uninstall command and never removes anything. diff --git a/messages.yaml b/messages.yaml index 69a6a48..62a595d 100644 --- a/messages.yaml +++ b/messages.yaml @@ -29,16 +29,18 @@ updateAvailable: |- npm cache clean --force && npx bmad-method@{tag} install nodeTooOld: |- - Node {version} is too old. This installer needs Node 22 or newer. - Install Node 22, then run this again. + Node {version} is too old. BMad v7 (and the skills CLI) need Node 22+. + Upgrade Node and try again, or run npx bmad-method@6 install for v6. nodeBelowSkillsFloor: |- Node {version} is below the 22.20.0 the skills CLI asks for, which may be why this failed. Upgrade Node and try again. uvMissing: |- - uv is not installed. The BMad scripts need it. - Install it with: + uv was not found on your PATH — continuing anyway. + BMad skills still install fine, though setup and helper scripts work + best with uv (without it, you'll have a more manual experience). + Install uv anytime (or ask your coding agent to install it): {installCommand} More ways: https://docs.astral.sh/uv/getting-started/installation/ @@ -66,9 +68,19 @@ directoryCreateConfirm: "{directory} does not exist. Create it?" directoryConfirm: "Install into {directory}?" legacyManifest: |- - Found an older BMad install at _bmad/_config/manifest.yaml. - This installer leaves it alone. Back up _bmad/ and _bmad-output/ - first; bmad setup handles v6 cleanup and migrations. + Found a BMad v6 install at _bmad/_config/manifest.yaml. + This is the BMad v7 installer (skills). To stay on or update v6, + run: npx bmad-method@6 install + To upgrade to v7, back up _bmad/ and _bmad-output/ first; + bmad setup handles v6 cleanup and migrations. + +legacyUpgradeConfirm: "Install BMad v7 into this v6 project?" + +legacyNoV7: |- + Found a BMad v6 install at _bmad/_config/manifest.yaml. + To stay on or update v6, run: npx bmad-method@6 install + To upgrade to v7, back up _bmad/ and _bmad-output/, then run: + npx bmad-method install existingInstallPrompt: "BMad is already installed here. What do you want to do?" @@ -118,6 +130,12 @@ nothingToUpdate: "No BMad install here to update. Run npx bmad-method install fi nothingInstalled: "There is no BMad install here. Run npx bmad-method install first." +statusNoUv: |- + BMad install (limited check — uv is not installed) + Modules: {modules} + Skills installed: {count} + Install uv for full status, setup, and helper scripts. + updatingSpinner: "Updating {what}" updateUnreadInstall: |- Could not read the install before updating, so only the modules this installer lists were updated. diff --git a/src/commands/apply.js b/src/commands/apply.js index 9781410..7b787e6 100644 --- a/src/commands/apply.js +++ b/src/commands/apply.js @@ -3,16 +3,17 @@ import { message } from '../messages.js' /** @typedef {import('../bmad-scripts.js').StatusReport} StatusReport */ /** @typedef {import('../skills-cli.js').AddResult} AddResult */ +/** @typedef {import('../skills-cli.js').ListedSkill} ListedSkill */ /** @typedef {import('./deps.js').CommandDeps} CommandDeps */ /** @typedef {import('./install-plan.js').InstallCall} InstallCall */ /** * Runs one `skills add` per call under a single spinner, then reads the install back. `plan` runs * inside the spinner, so a plan that has to read the install first shows no second spinner. - * `report` is null only when the `bmad` skill is nowhere in the project afterwards. + * `report` is null when the `bmad` skill is nowhere in the project afterwards or when `hasUv` is false. * @param {CommandDeps} deps - * @param {{ directory: string, agents: string[], spinner: 'installingSpinner' | 'updatingSpinner', plan: () => Promise | InstallCall[], bmadSkillDir?: string | null }} run - * @returns {Promise<{ failures: AddResult[], bmadSkillDir: string | null, report: StatusReport | null }>} + * @param {{ directory: string, agents: string[], spinner: 'installingSpinner' | 'updatingSpinner', plan: () => Promise | InstallCall[], bmadSkillDir?: string | null, hasUv?: boolean }} run + * @returns {Promise<{ failures: AddResult[], bmadSkillDir: string | null, report: StatusReport | null, skills: ListedSkill[] }>} */ export async function applyCalls(deps, run) { const { bmadScripts, messages, prompts, skillsCli } = deps @@ -26,10 +27,11 @@ export async function applyCalls(deps, run) { const results = await skillsCli.add({ source: call.source, skills: call.skills, agents, cwd: directory }) failures.push(...results.filter((entry) => entry.status !== 'installed')) } - const bmadSkillDir = (await inspectInstall(directory, skillsCli)).bmadSkillDir ?? run.bmadSkillDir ?? null - if (!bmadSkillDir) return { failures, bmadSkillDir, report: null } + const after = await inspectInstall(directory, skillsCli) + const bmadSkillDir = after.bmadSkillDir ?? run.bmadSkillDir ?? null + if (!bmadSkillDir || run.hasUv === false) return { failures, bmadSkillDir, report: null, skills: after.skills } progress.update(message(messages, 'statusSpinner')) - return { failures, bmadSkillDir, report: await bmadScripts.status(bmadSkillDir, directory) } + return { failures, bmadSkillDir, report: await bmadScripts.status(bmadSkillDir, directory), skills: after.skills } } finally { progress.stop() } diff --git a/src/commands/ending.js b/src/commands/ending.js index b901be2..bf1d203 100644 --- a/src/commands/ending.js +++ b/src/commands/ending.js @@ -13,14 +13,16 @@ import { selectMigrations, versionsByCode } from './install-plan.js' * wrong if anything, the summary, the commands people reuse, and the links. `before` holds the * module versions from before the run. * @param {CommandDeps} deps - * @param {{ report: StatusReport, bmadSkillDir: string, before: Record, failures: AddResult[], directory: string, agents?: string[], repeat?: string, updated?: boolean }} run + * @param {{ report: StatusReport | null, bmadSkillDir: string, before: Record, failures: AddResult[], directory: string, agents?: string[], repeat?: string, updated?: boolean, fallbackModules?: string[] }} run */ export async function endRun(deps, run) { const { bmadScripts, messages, modules, prompts } = deps - const migrations = selectMigrations(await bmadScripts.migrations(run.bmadSkillDir), { - before: run.before, - after: versionsByCode(run.report), - }) + const migrations = run.report + ? selectMigrations(await bmadScripts.migrations(run.bmadSkillDir), { + before: run.before, + after: versionsByCode(run.report), + }) + : [] if (migrations.length > 0) prompts.showNote(renderMigrations(migrations, messages)) const problems = problemLines(run.report, run.failures, messages) @@ -31,7 +33,15 @@ export async function endRun(deps, run) { const agents = run.agents?.map((id) => (id === UNIVERSAL_AGENT ? message(messages, 'universalAgentName') : deps.agents.find((agent) => agent.id === id)?.name ?? id)) - const summary = renderSummary(run.report, { messages, modules, directory: run.directory, agents, problems: problems.length > 0, updated: run.updated }) + const summary = renderSummary(run.report, { + messages, + modules, + directory: run.directory, + agents, + problems: problems.length > 0, + updated: run.updated, + fallbackModules: run.fallbackModules, + }) prompts.showNote(summary.body, summary.title) if (!run.updated) { diff --git a/src/commands/existing-install.js b/src/commands/existing-install.js index 3f01ed6..3a017cf 100644 --- a/src/commands/existing-install.js +++ b/src/commands/existing-install.js @@ -28,18 +28,20 @@ export async function statusWithSpinner(deps, bmadSkillDir, projectRoot) { * What is already installed in the project, said out loud when there is something. * @param {string} directory * @param {CommandDeps} deps + * @param {{ hasUv?: boolean }} [options] * @returns {Promise} */ -export async function readExisting(directory, deps) { +export async function readExisting(directory, deps, options = {}) { + const { hasUv = true } = options const { messages, modules, prompts, skillsCli } = deps const state = await inspectInstall(directory, skillsCli) - const report = state.bmadSkillDir + const report = state.bmadSkillDir && hasUv ? await statusWithSpinner(deps, state.bmadSkillDir, directory).catch(() => null) : null const codes = report ? report.modules.map((entry) => entry.module) : installedModuleCodes(state, modules) const versions = versionsByCode(report) - if (state.legacyManifest) prompts.say(message(messages, 'legacyManifest')) + if (state.legacyManifest) prompts.warn(message(messages, 'legacyManifest')) if (codes.length > 0) { const names = codes.map((code) => installedLabel(messages, findModule(modules, code)?.name ?? code, versions[code])) prompts.say([message(messages, 'foundModules'), ...names].join('\n')) diff --git a/src/commands/install.js b/src/commands/install.js index d985781..79ccc7f 100644 --- a/src/commands/install.js +++ b/src/commands/install.js @@ -1,7 +1,9 @@ import { detectContext, everyAgentHolds } from '../agents.js' import { SETUP_NEXT } from '../bmad-scripts.js' +import { installedModuleCodes } from '../installed.js' import { message } from '../messages.js' -import { nodeFailureHint, runPreflight } from '../preflight.js' +import { nodeFailureHint, runPreflight, uvInstallCommand } from '../preflight.js' +import { Cancelled } from '../prompts.js' import { renderFailures } from '../report.js' import { agentsToInstall } from './agent-choice.js' import { applyCalls } from './apply.js' @@ -25,12 +27,17 @@ export async function install(options, deps) { prompts.showIntro(messages) await announceUpdate(deps) - await runPreflight({ interactive, runner, messages, terminal: deps.terminal, agent: deps.agent }) + const { uv } = await runPreflight({ interactive, runner, messages, terminal: deps.terminal, agent: deps.agent }) + const hasUv = uv !== null + if (!hasUv) prompts.warn(message(messages, 'uvMissing', { installCommand: uvInstallCommand(messages) })) const directory = await resolveDirectory(options, deps, interactive) - const existing = await readExisting(directory, deps) + const existing = await readExisting(directory, deps, { hasUv }) + if (existing.state.legacyManifest && existing.codes.length === 0 && interactive) { + if (!(await prompts.confirm(message(messages, 'legacyUpgradeConfirm'), false))) throw new Cancelled() + } if (existing.codes.length > 0 && interactive && (await prompts.chooseExistingAction(messages)) === 'update') { - return update({ ...options, directory }, deps, { checked: true }) + return update({ ...options, directory }, deps, { checked: true, hasUv }) } const picked = await pickModuleCodes(options, deps, existing) @@ -51,22 +58,29 @@ export async function install(options, deps) { } const agents = await agentsToInstall(options, deps, directory, interactive) - const { failures, bmadSkillDir, report } = await applyCalls(deps, { + const { failures, bmadSkillDir, report, skills } = await applyCalls(deps, { directory, agents, spinner: 'installingSpinner', + hasUv, plan: () => { const context = (deps.detect ?? detectContext)(directory) return moduleCalls(chosen, existing.report, (record) => everyAgentHolds(deps.agents, agents, record, context)) }, }) - if (!bmadSkillDir || !report) { + if (!bmadSkillDir || (hasUv && !report)) { prompts.fail(failures.length > 0 ? [renderFailures(failures, messages), nodeFailureHint(messages, deps.node)].filter(Boolean).join('\n') : message(messages, 'firstInstallNotInProject', { directory })) return 1 } - await endRun(deps, { report, bmadSkillDir, before: existing.versions, failures, directory, agents, repeat: repeatCommand(chosen, agents) }) - return failures.length === 0 && (report.current || report.next === SETUP_NEXT) ? 0 : 1 + const fallbackModules = report + ? undefined + : [...new Set([ + ...installedModuleCodes({ skills, bmadSkillDir, legacyManifest: false }, modules), + ...chosen.filter((module) => module.custom).map((module) => module.code), + ])] + await endRun(deps, { report, bmadSkillDir, before: existing.versions, failures, directory, agents, repeat: repeatCommand(chosen, agents), fallbackModules }) + return failures.length === 0 && (!report || report.current || report.next === SETUP_NEXT) ? 0 : 1 } diff --git a/src/commands/status.js b/src/commands/status.js index b87f675..c7d7a81 100644 --- a/src/commands/status.js +++ b/src/commands/status.js @@ -1,23 +1,14 @@ import { resolve } from 'node:path' -import { inspectInstall } from '../installed.js' +import { inspectInstall, installedModuleCodes } from '../installed.js' import { message } from '../messages.js' -import { PreflightError, uvInstallCommand, uvVersion } from '../preflight.js' +import { findModule } from '../modules.js' +import { uvInstallCommand, uvVersion } from '../preflight.js' import { renderStatus } from '../report.js' import { statusWithSpinner } from './existing-install.js' /** @typedef {import('../cli.js').CliOptions} CliOptions */ /** @typedef {import('./deps.js').CommandDeps} CommandDeps */ -/** - * @param {CommandDeps} deps - * @returns {Promise} - */ -async function requireUv(deps) { - if (await uvVersion(deps.runner) !== null) return - const installCommand = uvInstallCommand(deps.messages) - throw new PreflightError(message(deps.messages, 'uvMissing', { installCommand })) -} - /** * @param {CliOptions} options * @param {CommandDeps} deps @@ -25,12 +16,20 @@ async function requireUv(deps) { */ export async function status(options, deps) { const { messages, modules, prompts, skillsCli, cwd } = deps - await requireUv(deps) - const directory = resolve(cwd, options.directory ?? cwd) const state = await inspectInstall(directory, skillsCli) if (!state.bmadSkillDir) { - prompts.fail(message(messages, 'nothingInstalled')) + prompts.fail(message(messages, state.legacyManifest ? 'legacyNoV7' : 'nothingInstalled')) + return 1 + } + + if (await uvVersion(deps.runner) === null) { + prompts.warn(message(messages, 'uvMissing', { installCommand: uvInstallCommand(messages) })) + const names = installedModuleCodes(state, modules).map((code) => findModule(modules, code)?.name ?? code) + prompts.showNote(message(messages, 'statusNoUv', { + modules: names.length > 0 ? names.join(', ') : 'BMad', + count: state.skills.length, + })) return 1 } diff --git a/src/commands/update.js b/src/commands/update.js index 6f6e802..bd13af2 100644 --- a/src/commands/update.js +++ b/src/commands/update.js @@ -2,7 +2,7 @@ import { resolve } from 'node:path' import { inspectInstall, installedModuleCodes } from '../installed.js' import { message } from '../messages.js' import { findModule, sourceAtRef } from '../modules.js' -import { runPreflight } from '../preflight.js' +import { runPreflight, uvInstallCommand } from '../preflight.js' import { lockedRef, moduleSourceFromLock, readProjectLock } from '../project-lock.js' import { agentsToUpdate } from './agent-choice.js' import { applyCalls } from './apply.js' @@ -52,18 +52,23 @@ async function updateCalls(deps, directory, codes, installed) { * `checked` is set when install already ran the preflight checks and hands over to update. * @param {CliOptions} options * @param {CommandDeps} deps - * @param {{ checked?: boolean }} [context] + * @param {{ checked?: boolean, hasUv?: boolean }} [context] * @returns {Promise} */ export async function update(options, deps, context = {}) { const { bmadScripts, messages, modules, prompts, runner, skillsCli, cwd } = deps - if (!context.checked) await runPreflight({ interactive: false, runner, messages }) + const hasUv = context.checked + ? (context.hasUv ?? true) + : (await runPreflight({ interactive: false, runner, messages })).uv !== null + if (!context.checked && !hasUv) { + prompts.warn(message(messages, 'uvMissing', { installCommand: uvInstallCommand(messages) })) + } const directory = resolve(cwd, options.directory ?? cwd) const before = await inspectInstall(directory, skillsCli) const installedSkillDir = before.bmadSkillDir if (!installedSkillDir) { - prompts.fail(message(messages, 'nothingToUpdate')) + prompts.fail(message(messages, before.legacyManifest ? 'legacyNoV7' : 'nothingToUpdate')) return 1 } @@ -71,27 +76,31 @@ export async function update(options, deps, context = {}) { let wasInstalled = null /** @type {string[]} */ let unplaced = [] - const { failures, bmadSkillDir, report } = await applyCalls(deps, { + const { failures, bmadSkillDir, report, skills } = await applyCalls(deps, { directory, agents: agentsToUpdate(deps, directory), spinner: 'updatingSpinner', bmadSkillDir: installedSkillDir, + hasUv, plan: async () => { - wasInstalled = await bmadScripts.status(installedSkillDir, directory).catch(() => null) + wasInstalled = hasUv ? await bmadScripts.status(installedSkillDir, directory).catch(() => null) : null const codes = wasInstalled ? wasInstalled.modules.map((entry) => entry.module) : installedModuleCodes(before, modules) const planned = await updateCalls(deps, directory, codes, wasInstalled) unplaced = planned.unplaced return planned.calls }, }) - if (!bmadSkillDir || !report) { + if (!bmadSkillDir || (hasUv && !report)) { prompts.fail(message(messages, 'nothingToUpdate')) return 1 } if (unplaced.length > 0) prompts.say(message(messages, 'updateNotListed', { modules: unplaced.join(', ') })) // Without the first status there is no telling which modules beyond modules.yaml were installed. - if (!wasInstalled) prompts.warn(message(messages, 'updateUnreadInstall')) + if (hasUv && !wasInstalled) prompts.warn(message(messages, 'updateUnreadInstall')) - await endRun(deps, { report, bmadSkillDir, before: versionsByCode(wasInstalled), failures, directory, updated: true }) - return failures.length === 0 && wasInstalled ? 0 : 1 + const fallbackModules = report + ? undefined + : installedModuleCodes({ skills, bmadSkillDir, legacyManifest: false }, modules) + await endRun(deps, { report, bmadSkillDir, before: versionsByCode(wasInstalled), failures, directory, updated: true, fallbackModules }) + return failures.length === 0 && (!hasUv || Boolean(wasInstalled)) ? 0 : 1 } diff --git a/src/preflight.js b/src/preflight.js index 4c0cb80..0a8b3ea 100644 --- a/src/preflight.js +++ b/src/preflight.js @@ -91,8 +91,9 @@ export function uvInstallCommand(messages, platform = process.platform) { /** * `terminal` and `agent` are injectable so the command tests can drive the interactive path. + * Missing `uv` does not stop the run; callers decide how to warn and degrade when `uv` is null. * @param {{ interactive: boolean, runner: Runner, messages: Record, platform?: string, terminal?: () => boolean, agent?: () => Promise }} options - * @returns {Promise} + * @returns {Promise<{ uv: string | null }>} */ export async function runPreflight(options) { const { @@ -111,14 +112,13 @@ export async function runPreflight(options) { if (wsl) throw new PreflightError(message(messages, 'wslWindowsNode')) const uv = await uvVersion(runner) - if (uv === null) { - throw new PreflightError(message(messages, 'uvMissing', { installCommand: uvInstallCommand(messages, platform) })) - } - if (!interactive) return + if (!interactive) return { uv } if (!terminal()) throw new PreflightError(message(messages, 'needsTerminal')) const agent = await readAgent() if (agent) throw new PreflightError(message(messages, 'insideAgent', { agent })) + + return { uv } } diff --git a/src/report.js b/src/report.js index f9eed81..7d4b197 100644 --- a/src/report.js +++ b/src/report.js @@ -86,7 +86,7 @@ export function renderMigrations(migrations, messages) { /** * What failed or is still missing, one line each; empty when nothing is wrong. - * @param {StatusReport} report + * @param {StatusReport | null} report * @param {AddResult[]} failures * @param {Messages} messages * @returns {string[]} @@ -94,6 +94,7 @@ export function renderMigrations(migrations, messages) { export function problemLines(report, failures, messages) { const lines = [] if (failures.length > 0) lines.push(renderFailures(failures, messages)) + if (!report) return lines for (const record of report.missing_module_records) { lines.push(message(messages, 'reportMissingRecord', { install: record.install ?? '' })) } @@ -114,35 +115,57 @@ export function problemLines(report, failures, messages) { /** * The closing summary of an install or update: where, which modules, which agents, what next. - * @param {StatusReport} report - * @param {{ messages: Messages, modules: ModuleDefinition[], directory: string, agents?: string[], problems: boolean, updated?: boolean }} options + * When `report` is null (e.g. without uv), module names come from `fallbackModules` without versions. + * @param {StatusReport | null} report + * @param {{ messages: Messages, modules: ModuleDefinition[], directory: string, agents?: string[], problems: boolean, updated?: boolean, fallbackModules?: string[] }} options * @returns {{ title: string, body: string }} */ export function renderSummary(report, options) { - const { messages, modules, directory, agents, problems, updated } = options - /** @type {Map} */ - const byVersion = new Map() - for (const entry of report.modules) { - // The summary sits under "BMad is installed", so the brand prefix would only push the line past the box width. - const name = moduleName(modules, entry.module).replace(/^BMad /, '') - byVersion.set(entry.version, [...(byVersion.get(entry.version) ?? []), name]) - } - const installed = [...byVersion] - .map(([version, names]) => message(messages, 'summaryModuleGroup', { names: names.join(', '), version })) - .join('; ') + const { messages, modules, directory, agents, problems, updated, fallbackModules = [] } = options + const installed = report + ? groupedModules(report, modules, messages) + : fallbackModules.map((code) => shortModuleName(modules, code)).join(', ') const lines = [ message(messages, 'summaryProject', { directory }), message(messages, 'summaryModules', { modules: installed }), ] if (agents) lines.push(message(messages, 'summaryAgents', { agents: agents.join(', ') })) lines.push('') - if (report.current) lines.push(message(messages, 'summaryNextCurrent')) + if (!report) lines.push(message(messages, 'summaryNextSetup')) + else if (report.current) lines.push(message(messages, 'summaryNextCurrent')) else if (report.next === SETUP_NEXT) lines.push(message(messages, 'summaryNextSetup')) else lines.push(message(messages, 'summaryNextOther', { next: report.next ?? '' })) const title = updated ? (problems ? 'summaryTitleUpdatedProblems' : 'summaryTitleUpdated') : (problems ? 'summaryTitleProblems' : 'summaryTitle') return { title: message(messages, title), body: lines.join('\n') } } +/** + * @param {StatusReport} report + * @param {ModuleDefinition[]} modules + * @param {Messages} messages + * @returns {string} + */ +function groupedModules(report, modules, messages) { + /** @type {Map} */ + const byVersion = new Map() + for (const entry of report.modules) { + byVersion.set(entry.version, [...(byVersion.get(entry.version) ?? []), shortModuleName(modules, entry.module)]) + } + return [...byVersion] + .map(([version, names]) => message(messages, 'summaryModuleGroup', { names: names.join(', '), version })) + .join('; ') +} + +/** + * The summary sits under "BMad is installed", so the brand prefix would only push the line past the box width. + * @param {ModuleDefinition[]} modules + * @param {string} code + * @returns {string} + */ +function shortModuleName(modules, code) { + return moduleName(modules, code).replace(/^BMad /, '') +} + /** * A module's name with the version it is installed at. * @param {Messages} messages diff --git a/test/commands/install.test.js b/test/commands/install.test.js index 1974bad..37d0600 100644 --- a/test/commands/install.test.js +++ b/test/commands/install.test.js @@ -1,7 +1,10 @@ import { test } from 'node:test' import assert from 'node:assert/strict' +import { mkdir, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { install } from '../../src/commands/install.js' +import { uvInstallCommand } from '../../src/preflight.js' +import { Cancelled } from '../../src/prompts.js' import { createSkillsCli } from '../../src/skills-cli.js' import { RECORDS, @@ -339,3 +342,97 @@ test('a project with only missing locked skills installs as a fresh project', as assert.equal(asked.includes('existing'), false) assert.equal(said.warns.some((warning) => warning.includes('Still installed')), false) }) + +test('installing without uv warns uvMissing, skips bmad scripts, and still prints the summary', async (t) => { + const dir = await tempDir(t) + const { prompts, said } = fakePrompts() + const { cli, requests } = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const { runner } = fakeRunner({ uv: false }) + let migrationsCalled = false + const scripts = /** @type {any} */ ({ + async status() { + throw new Error('setup.py --status should not run without uv') + }, + async migrations() { + migrationsCalled = true + return [] + }, + }) + + const code = await install( + options({ directory: dir, yes: true, tools: 'claude-code' }), + makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, cwd: dir, runner }), + ) + + assert.equal(code, 0) + assert.equal(migrationsCalled, false) + assert.equal(only(requests).length, 3) + assert.ok(said.warns.includes(messages.uvMissing.replace('{installCommand}', uvInstallCommand(messages)))) + const summary = said.notes.at(-1) ?? '' + assert.ok(summary.startsWith(messages.summaryTitle)) + assert.ok(summary.includes('Core Tools, Method')) + assert.ok(summary.includes('bmad setup')) +}) + +test('interactive install in a v6-only project warns and asks to confirm before upgrading', async (t) => { + const dir = await tempDir(t) + await mkdir(join(dir, '_bmad', '_config'), { recursive: true }) + await writeFile(join(dir, '_bmad', '_config', 'manifest.yaml'), 'modules: []\n') + + const declined = fakePrompts({ confirm: (/** @type {string} */ question) => question !== messages.legacyUpgradeConfirm }) + const declinedCli = fakeSkillsCli({ lists: [[]] }) + const { scripts } = fakeBmadScripts({ statuses: [statusOf()] }) + await assert.rejects( + () => install(options({ directory: dir }), makeDeps({ prompts: declined.prompts, skillsCli: declinedCli.cli, bmadScripts: scripts, cwd: dir })), + Cancelled, + ) + assert.ok(declined.said.warns.includes(messages.legacyManifest)) + assert.ok(declined.confirmations.some((entry) => entry.message === messages.legacyUpgradeConfirm && entry.initial === false)) + assert.equal(only(declinedCli.requests).length, 0) + + const accepted = fakePrompts({ confirm: true, modules: ['method'] }) + const acceptedCli = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const code = await install( + options({ directory: dir }), + makeDeps({ prompts: accepted.prompts, skillsCli: acceptedCli.cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf()] }).scripts, cwd: dir }), + ) + assert.equal(code, 0) + assert.ok(accepted.confirmations.some((entry) => entry.message === messages.legacyUpgradeConfirm && entry.initial === false)) + assert.equal(only(acceptedCli.requests).length, 2) +}) + +test('headless install in a v6-only project warns without confirming and proceeds', async (t) => { + const dir = await tempDir(t) + await mkdir(join(dir, '_bmad', '_config'), { recursive: true }) + await writeFile(join(dir, '_bmad', '_config', 'manifest.yaml'), 'modules: []\n') + + const { prompts, asked, said } = fakePrompts() + const { cli, requests } = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const code = await install( + options({ directory: dir, yes: true, tools: 'claude-code' }), + makeDeps({ prompts, skillsCli: cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf()] }).scripts, cwd: dir }), + ) + + assert.equal(code, 0) + assert.ok(said.warns.includes(messages.legacyManifest)) + assert.equal(asked.includes('confirm'), false) + assert.equal(only(requests).length, 3) +}) + +test('interactive install with both v7 skills and a legacy manifest does not ask legacyUpgradeConfirm', async (t) => { + const dir = await tempDir(t) + await mkdir(join(dir, '_bmad', '_config'), { recursive: true }) + await writeFile(join(dir, '_bmad', '_config', 'manifest.yaml'), 'modules: []\n') + + const { prompts, asked, said, confirmations } = fakePrompts({ existing: 'update' }) + const { cli } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-method')]] }) + const code = await install( + options({ directory: dir }), + makeDeps({ prompts, skillsCli: cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf(), statusOf()] }).scripts, cwd: dir }), + ) + + assert.equal(code, 0) + assert.ok(said.warns.includes(messages.legacyManifest)) + assert.ok(asked.includes('existing')) + assert.equal(confirmations.some((entry) => entry.message === messages.legacyUpgradeConfirm), false) +}) diff --git a/test/commands/status.test.js b/test/commands/status.test.js index 0737104..9d174ef 100644 --- a/test/commands/status.test.js +++ b/test/commands/status.test.js @@ -1,7 +1,9 @@ import { test } from 'node:test' import assert from 'node:assert/strict' +import { mkdir, writeFile } from 'node:fs/promises' +import { join } from 'node:path' import { status } from '../../src/commands/status.js' -import { PreflightError } from '../../src/preflight.js' +import { uvInstallCommand } from '../../src/preflight.js' import { fakeBmadScripts, fakePrompts, @@ -12,18 +14,19 @@ import { messages, options, statusOf, + tempDir, } from '../helpers/command-fakes.js' /** @typedef {import('../../src/bmad-scripts.js').StatusReport} StatusReport */ /** @typedef {import('../../src/skills-cli.js').ListedSkill} ListedSkill */ -/** @param {{ uv?: boolean, lists: ListedSkill[][], report?: StatusReport }} script */ +/** @param {{ uv?: boolean, lists: ListedSkill[][], report?: StatusReport, cwd?: string }} script */ function statusDeps(script) { const { prompts, said } = fakePrompts() const { runner, calls } = fakeRunner({ uv: script.uv }) const { cli } = fakeSkillsCli({ lists: script.lists }) const { scripts } = fakeBmadScripts({ statuses: [script.report ?? statusOf()] }) - return { deps: makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, runner }), said, calls } + return { deps: makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, runner, cwd: script.cwd }), said, calls } } /** @param {Partial} [patch] */ @@ -31,9 +34,27 @@ function statusOptions(patch = {}) { return options({ command: 'status', yes: true, ...patch }) } -test('a missing uv stops the status before anything is read', async () => { - const { deps } = statusDeps({ uv: false, lists: [[listed('bmad')]] }) - await assert.rejects(() => status(statusOptions(), deps), PreflightError) +test('status without uv warns uvMissing, prints a limited summary, and exits 1', async () => { + const { deps, said } = statusDeps({ uv: false, lists: [[listed('bmad'), listed('bmod-core-tools'), listed('bmod-method')]] }) + + assert.equal(await status(statusOptions(), deps), 1) + assert.ok(said.warns.includes(messages.uvMissing.replace('{installCommand}', uvInstallCommand(messages)))) + assert.equal(said.notes.length, 1) + assert.ok(said.notes[0].includes('BMad Core Tools, BMad Method')) + assert.ok(said.notes[0].includes('Skills installed: 3')) +}) + +test('status in a v6-only project fails with legacyNoV7 and exits 1', async (t) => { + const dir = await tempDir(t) + await mkdir(join(dir, '_bmad', '_config'), { recursive: true }) + await writeFile(join(dir, '_bmad', '_config', 'manifest.yaml'), 'modules: []\n') + + for (const uv of [true, false]) { + const { deps, said } = statusDeps({ uv, lists: [[]], cwd: dir }) + assert.equal(await status(statusOptions({ directory: dir }), deps), 1) + assert.deepEqual(said.fails, [messages.legacyNoV7]) + assert.deepEqual(said.notes, []) + } }) test('nothing installed without the bmad skill', async () => { diff --git a/test/commands/update.test.js b/test/commands/update.test.js index 6480aa3..e2a3629 100644 --- a/test/commands/update.test.js +++ b/test/commands/update.test.js @@ -1,13 +1,15 @@ import { test } from 'node:test' import assert from 'node:assert/strict' -import { writeFile } from 'node:fs/promises' +import { mkdir, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { update } from '../../src/commands/update.js' +import { uvInstallCommand } from '../../src/preflight.js' import { HOME, detectWith, fakeBmadScripts, fakePrompts, + fakeRunner, fakeSkillsCli, listed, makeDeps, @@ -38,7 +40,7 @@ test('nothing to update without the bmad skill', async () => { test('the update re-adds each installed module whole to the agents holding bmad, then reports and closes', async (t) => { const dir = await tempDir(t) const { prompts, said } = fakePrompts() - const { cli, requests } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-method')]] }) + const { cli, requests } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-core-tools'), listed('bmod-method')]] }) const { scripts, seen } = fakeBmadScripts({ statuses: [statusOf(), statusOf()] }) const detect = detectWith([join(HOME, '.grok'), join(dir, '.claude', 'skills', 'bmad'), join(dir, '.agents', 'skills', 'bmad')]) @@ -147,7 +149,7 @@ test('a listed module stays on the branch the project lock recorded for its reco test('an update that could not read the install first says so and exits 1', async () => { const { prompts, said } = fakePrompts() - const { cli, requests } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-method')]] }) + const { cli, requests } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-core-tools'), listed('bmod-method')]] }) let calls = 0 const scripts = /** @type {any} */ ({ async status() { @@ -187,3 +189,49 @@ test('an update of a project holding the old suite installs Creative in its plac 'bmad-code-org/BMAD-METHOD/skills/creative', ]) }) + +test('update in a v6-only project stops with legacyNoV7 and exits 1', async (t) => { + const dir = await tempDir(t) + await mkdir(join(dir, '_bmad', '_config'), { recursive: true }) + await writeFile(join(dir, '_bmad', '_config', 'manifest.yaml'), 'modules: []\n') + const { prompts, said } = fakePrompts() + const { cli, requests } = fakeSkillsCli({ lists: [[]] }) + + const code = await update(updateOptions({ directory: dir }), makeDeps({ prompts, skillsCli: cli, bmadScripts: fakeBmadScripts({ statuses: [] }).scripts, cwd: dir })) + + assert.equal(code, 1) + assert.deepEqual(said.fails, [messages.legacyNoV7]) + assert.equal(only(requests).length, 0) +}) + +test('update without uv warns uvMissing, updates listed modules, skips bmadScripts, and exits 0', async (t) => { + const dir = await tempDir(t) + const { prompts, said } = fakePrompts() + const { cli, requests } = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-core-tools'), listed('bmod-method')]] }) + const { runner } = fakeRunner({ uv: false }) + let scriptsCalled = false + const scripts = /** @type {any} */ ({ + async status() { + scriptsCalled = true + return statusOf() + }, + async migrations() { + scriptsCalled = true + return [] + }, + }) + + const code = await update(updateOptions({ directory: dir }), makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, cwd: dir, runner })) + + assert.equal(code, 0) + assert.equal(scriptsCalled, false) + assert.deepEqual(only(requests).map((request) => request.source), [ + 'bmad-code-org/BMAD-METHOD/skills/core-tools', + 'bmad-code-org/BMAD-METHOD/skills/method', + ]) + assert.ok(said.warns.includes(messages.uvMissing.replace('{installCommand}', uvInstallCommand(messages)))) + assert.equal(said.warns.includes(messages.updateUnreadInstall), false) + const summary = said.notes.at(-1) ?? '' + assert.ok(summary.startsWith(messages.summaryTitleUpdated)) + assert.ok(summary.includes('Core Tools, Method')) +}) diff --git a/test/helpers/command-fakes.js b/test/helpers/command-fakes.js index 48954be..c16a023 100644 --- a/test/helpers/command-fakes.js +++ b/test/helpers/command-fakes.js @@ -50,6 +50,8 @@ export function fakePrompts(answers = {}) { const asked = [] /** @type {{ initial: string[] }[]} */ const pickers = [] + /** @type {{ message: string, initial: boolean | undefined }[]} */ + const confirmations = [] const prompts = /** @type {any} */ ({ showIntro: () => asked.push('intro'), showNote: (/** @type {string} */ t, /** @type {string | undefined} */ title) => said.notes.push(title ? `${title}\n${t}` : t), @@ -60,7 +62,11 @@ export function fakePrompts(answers = {}) { finish: (/** @type {string} */ t) => said.finish.push(t), startSpinner: () => ({ stop: () => {}, update: () => {} }), askDirectory: async (/** @type {any} */ _m, /** @type {string} */ d) => (asked.push('directory'), d), - confirm: async () => (asked.push('confirm'), answers.confirm ?? true), + confirm: async (/** @type {string} */ question, /** @type {boolean | undefined} */ initial) => ( + asked.push('confirm'), + confirmations.push({ message: question, initial }), + typeof answers.confirm === 'function' ? answers.confirm(question, initial) : (answers.confirm ?? true) + ), chooseModules: async () => (asked.push('modules'), answers.modules ?? ['method']), chooseAgents: async (/** @type {any} */ _m, /** @type {any} */ _a, /** @type {{ initial: string[] }} */ picker) => { asked.push('agents') @@ -69,7 +75,7 @@ export function fakePrompts(answers = {}) { }, chooseExistingAction: async () => (asked.push('existing'), answers.existing ?? 'modify'), }) - return { prompts, said, asked, pickers } + return { prompts, said, asked, pickers, confirmations } } /** diff --git a/test/messages.test.js b/test/messages.test.js index 8c207a0..7568834 100644 --- a/test/messages.test.js +++ b/test/messages.test.js @@ -25,6 +25,8 @@ const keysWithValues = { directoryCreateConfirm: { directory: '/tmp/project' }, directoryConfirm: { directory: '/tmp/project' }, legacyManifest: {}, + legacyUpgradeConfirm: {}, + legacyNoV7: {}, existingInstallPrompt: {}, existingInstallModify: {}, existingInstallUpdate: {}, @@ -42,6 +44,7 @@ const keysWithValues = { statusSpinner: {}, nothingToUpdate: {}, nothingInstalled: {}, + statusNoUv: { modules: 'BMad Core Tools, BMad Method', count: 24 }, updatingSpinner: { what: 'BMad Method' }, modulesRequired: { modules: 'BMad Method' }, modulesKept: { modules: 'BMad Method' }, @@ -151,8 +154,8 @@ test('the ending names setup, the update command and every link once', () => { test('the prose blocks fit the clack note box without rewrapping', () => { const blocks = [ 'intro', 'updateAvailable', 'nodeTooOld', 'nodeBelowSkillsFloor', 'uvMissing', 'wslWindowsNode', - 'needsTerminal', 'insideAgent', 'legacyManifest', 'modulesKept', 'firstInstallNotInProject', 'unknownTools', 'repeatInstall', - 'nothingInstalled', 'nothingToUpdate', 'cancelled', 'summaryNextSetup', 'summaryNextCurrent', 'thanks', 'droppedUninstall', + 'needsTerminal', 'insideAgent', 'legacyManifest', 'legacyNoV7', 'modulesKept', 'firstInstallNotInProject', 'unknownTools', 'repeatInstall', + 'nothingInstalled', 'nothingToUpdate', 'statusNoUv', 'cancelled', 'summaryNextSetup', 'summaryNextCurrent', 'thanks', 'droppedUninstall', ] for (const key of blocks) { for (const line of message(loaded, key, keysWithValues[key]).split('\n')) { diff --git a/test/preflight.test.js b/test/preflight.test.js index 46ea2b9..0f0aa53 100644 --- a/test/preflight.test.js +++ b/test/preflight.test.js @@ -6,6 +6,7 @@ import { nodeFailureHint, nodeVersionState, runPreflight, + uvInstallCommand, uvVersion, wslRunningWindowsNode, } from '../src/preflight.js' @@ -118,8 +119,11 @@ test('hasTerminal needs both streams to be a TTY', () => { assert.equal(hasTerminal(unknown, tty), false) }) -test('runPreflight passes when uv answers', async () => { - await runPreflight({ interactive: false, runner: uvOk(), messages, platform: 'darwin' }) +test('runPreflight passes and reports uv when uv answers', async () => { + assert.deepEqual( + await runPreflight({ interactive: false, runner: uvOk(), messages, platform: 'darwin' }), + { uv: '0.5.31' }, + ) }) test('nodeFailureHint speaks only for a Node below the skills CLI floor', () => { @@ -128,30 +132,33 @@ test('nodeFailureHint speaks only for a Node below the skills CLI floor', () => assert.equal(nodeFailureHint(messages, '24.1.0'), null) }) -test('runPreflight stops with the platform install command when uv is missing', async () => { - await assert.rejects( - () => runPreflight({ +test('runPreflight allows progression with uv null when uv is missing', async () => { + assert.deepEqual( + await runPreflight({ interactive: false, runner: fakeRunner({ code: null, error: 'spawn uv ENOENT' }), messages, platform: 'darwin', }), - (error) => error instanceof PreflightError && error.message === 'uv is missing. Install it with brew install uv', + { uv: null }, ) -}) - -test('runPreflight falls back to the linux install command', async () => { - await assert.rejects( - () => runPreflight({ + assert.deepEqual( + await runPreflight({ interactive: false, runner: fakeRunner({ code: 1 }), messages, platform: 'freebsd', }), - (error) => error instanceof PreflightError && error.message === 'uv is missing. Install it with curl uv', + { uv: null }, ) }) +test('uvInstallCommand returns the platform command and falls back to linux', () => { + assert.equal(uvInstallCommand(messages, 'darwin'), 'brew install uv') + assert.equal(uvInstallCommand(messages, 'win32'), 'irm uv') + assert.equal(uvInstallCommand(messages, 'freebsd'), 'curl uv') +}) + test('runPreflight stops a Windows node launched from a WSL shell', async () => { process.env.WSL_DISTRO_NAME = 'Ubuntu' try { diff --git a/test/report.test.js b/test/report.test.js index 6d637d0..ef41837 100644 --- a/test/report.test.js +++ b/test/report.test.js @@ -207,10 +207,25 @@ test('renderSummary groups modules by version, drops the brand prefix and picks report.current = false report.next = 'npx skills update' assert.ok(renderSummary(report, { messages, modules, directory: '/d', problems: false }).body.endsWith('Next: npx skills update')) + + const fallback = renderSummary(null, { + messages, + modules, + directory: '/tmp/demo', + agents: ['Claude Code'], + problems: false, + fallbackModules: ['core-tools', 'method'], + }) + assert.equal(fallback.title, 'Installed') + assert.equal(fallback.body, 'Project /tmp/demo\nModules Core Tools, Method\nAgents Claude Code\n\nNext: bmad setup') }) test('problemLines lists failures first and is empty for a clean report', () => { assert.deepEqual(problemLines(fixture('status-fresh.json'), [], messages), []) + assert.deepEqual(problemLines(null, [], messages), []) + assert.deepEqual(problemLines(null, [{ name: 'bmad-x', status: 'failed', error: 'network' }], messages), [ + 'Failed: bmad-x (network)', + ]) const report = fixture('status-fresh.json') report.problems = [{ kind: 'duplicate', message: 'two copies of bmad' }] assert.deepEqual(problemLines(report, [{ name: 'bmad-x', status: 'failed', error: 'network' }], messages), [ diff --git a/tools/release.md b/tools/release.md index 208a034..109ec50 100644 --- a/tools/release.md +++ b/tools/release.md @@ -6,6 +6,8 @@ Push the tag: `git push origin vX.Y.Z`. The `publish.yml` workflow runs on that Once you've verified the published version works, move the `latest` dist-tag by hand: `npm dist-tag add bmad-method@X.Y.Z latest`. +After promoting `latest` to `7.x`, `npx bmad-method@6` continues resolving to the latest `6.x` release (`6.12.4`+). Optionally add a `v6` dist-tag if desired: `npm dist-tag add bmad-method@6.12.4 v6`. + The npm trusted publisher for this package must point at `bmad-code-org/bmad-installer`; if it points anywhere else, `npm publish --provenance` in the workflow fails. To move to a newer skills CLI, set the exact version in `package.json` (no `^`), run `npm install`, then `npm run agents` to regenerate `agents.json`. Commit both together; `npm test` fails while they disagree.