diff --git a/messages.yaml b/messages.yaml index 0fd2cd0..8ea498b 100644 --- a/messages.yaml +++ b/messages.yaml @@ -230,12 +230,19 @@ repeatInstall: |- thanks: |- Thanks for installing BMad. - Read the blog https://blog.bmadcode.com - Star the repo https://github.com/bmad-code-org/BMAD-METHOD - Join Discord https://discord.gg/gk8jAdXWmj - Watch https://www.youtube.com/@BMadCode - Buy a coffee https://buymeacoffee.com/bmad - Support and contact https://bmadcode.com/#contact + Blog & newsletter https://blog.bmadcode.com + YouTube tutorials https://www.youtube.com/@BMadCode + Join Discord https://discord.gg/gk8jAdXWmj + Training & consulting https://bmadcode.com/#contact + contact@bmadcode.com + Buy a coffee https://buymeacoffee.com/bmad + +starPrompt: "BMad is 100% free & open source — help others find it with a GitHub star?" + +starThanks: |- + Thank you! It only takes 5 seconds: + 1. Open: https://github.com/bmad-code-org/BMAD-METHOD + 2. Click the Star button in the top-right corner. cancelled: "Cancelled. Anything already installed is still there." diff --git a/src/commands/ending.js b/src/commands/ending.js index 946eaae..1918715 100644 --- a/src/commands/ending.js +++ b/src/commands/ending.js @@ -1,6 +1,8 @@ import { UNIVERSAL_AGENT } from '../agents.js' +import { SETUP_NEXT } from '../bmad-scripts.js' import { message } from '../messages.js' import { nodeFailureHint } from '../preflight.js' +import { Cancelled } from '../prompts.js' import { problemLines, renderMigrations, renderSummary } from '../report.js' import { selectMigrations, versionsByCode } from './install-plan.js' @@ -13,7 +15,7 @@ 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 | null, bmadSkillDir: string, before: Record, failures: AddResult[], directory: string, agents?: string[], repeat?: string, updated?: boolean, fallbackModules?: string[] }} run + * @param {{ report: StatusReport | null, bmadSkillDir: string, before: Record, failures: AddResult[], directory: string, agents?: string[], repeat?: string, updated?: boolean, fallbackModules?: string[], interactive?: boolean }} run */ export async function endRun(deps, run) { const { bmadScripts, messages, modules, prompts } = deps @@ -50,5 +52,15 @@ export async function endRun(deps, run) { prompts.plain(commands.join('\n')) } prompts.plain(message(messages, 'thanks')) + const installSucceeded = run.failures.length === 0 && (!run.report || run.report.current || run.report.next === SETUP_NEXT) + if (run.interactive && !run.updated && installSucceeded) { + try { + if (await prompts.confirm(message(messages, 'starPrompt'), false)) { + prompts.plain(message(messages, 'starThanks')) + } + } catch (error) { + if (!(error instanceof Cancelled)) throw error + } + } prompts.finish('') } diff --git a/src/commands/install.js b/src/commands/install.js index 1e8a7d2..e917e2c 100644 --- a/src/commands/install.js +++ b/src/commands/install.js @@ -81,6 +81,6 @@ export async function install(options, deps) { ...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 }) + await endRun(deps, { report, bmadSkillDir, before: existing.versions, failures, directory, agents, repeat: repeatCommand(chosen, agents), fallbackModules, interactive }) return failures.length === 0 && (!report || report.current || report.next === SETUP_NEXT) ? 0 : 1 } diff --git a/src/run.js b/src/run.js index 7f91d9f..bdc1b63 100644 --- a/src/run.js +++ b/src/run.js @@ -71,11 +71,15 @@ function spawnAndWait(request) { }, timeoutMs) } + let settled = false + /** * @param {number | null} code * @param {string} [error] */ const settle = async (code, error) => { + if (settled) return + settled = true if (timer) clearTimeout(timer) const stdout = await capture.read() resolve(error === undefined diff --git a/test/commands/install-agents.test.js b/test/commands/install-agents.test.js index ba00682..5d435a0 100644 --- a/test/commands/install-agents.test.js +++ b/test/commands/install-agents.test.js @@ -96,7 +96,7 @@ test('the picker runs after the module prompt and its answer goes to every call' ) assert.equal(code, 0) - assert.deepEqual(asked, ['intro', 'confirm', 'modules', 'agents']) + assert.deepEqual(asked, ['intro', 'confirm', 'modules', 'agents', 'confirm']) assert.deepEqual(pickers[0], { initial: [] }, 'an agent with a config folder is not ticked') for (const request of only(requests)) assert.deepEqual(request.agents, ['codex', 'claude-code']) assert.ok(said.plain.some((text) => text.includes('npx bmad-method install -m method -t codex,claude-code -y'))) diff --git a/test/commands/install.test.js b/test/commands/install.test.js index 4ff6186..8ef4101 100644 --- a/test/commands/install.test.js +++ b/test/commands/install.test.js @@ -445,3 +445,90 @@ test('interactive install with both v7 skills and a legacy manifest does not ask assert.ok(asked.includes('existing')) assert.equal(confirmations.some((entry) => entry.message === messages.legacyUpgradeConfirm), false) }) + +test('interactive clean install asks starPrompt defaulting false and prints starThanks when accepted', async (t) => { + const dir = await tempDir(t) + const { prompts, said, confirmations } = fakePrompts() + const { cli } = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const { scripts } = fakeBmadScripts({ statuses: [statusOf(), statusOf()] }) + + const code = await install( + options({ directory: dir, tools: 'claude-code' }), + makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, cwd: dir }), + ) + + assert.equal(code, 0) + assert.ok(confirmations.some((entry) => entry.message === messages.starPrompt && entry.initial === false)) + assert.ok(said.plain.includes(messages.starThanks)) + assert.ok(messages.starThanks.includes('https://github.com/bmad-code-org/BMAD-METHOD')) + assert.ok(messages.starThanks.includes('top-right')) +}) + +test('interactive clean install skips starThanks when starPrompt is declined or cancelled', async (t) => { + const dir = await tempDir(t) + const declined = fakePrompts({ + confirm: (/** @type {string} */ question) => question !== messages.starPrompt, + }) + const declinedCli = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const declinedCode = await install( + options({ directory: dir, tools: 'claude-code' }), + makeDeps({ prompts: declined.prompts, skillsCli: declinedCli.cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf(), statusOf()] }).scripts, cwd: dir }), + ) + assert.equal(declinedCode, 0) + assert.ok(declined.confirmations.some((entry) => entry.message === messages.starPrompt && entry.initial === false)) + assert.equal(declined.said.plain.includes(messages.starThanks), false) + + const cancelled = fakePrompts({ + confirm: (/** @type {string} */ question) => { + if (question === messages.starPrompt) throw new Cancelled() + return true + }, + }) + const cancelledCli = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const cancelledCode = await install( + options({ directory: dir, tools: 'claude-code' }), + makeDeps({ prompts: cancelled.prompts, skillsCli: cancelledCli.cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf(), statusOf()] }).scripts, cwd: dir }), + ) + assert.equal(cancelledCode, 0) + assert.equal(cancelled.said.plain.includes(messages.starThanks), false) +}) + +test('headless install and quick update never ask starPrompt', async (t) => { + const dir = await tempDir(t) + const headless = fakePrompts() + const headlessCli = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const headlessCode = await install( + options({ directory: dir, yes: true, tools: 'claude-code' }), + makeDeps({ prompts: headless.prompts, skillsCli: headlessCli.cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf(), statusOf()] }).scripts, cwd: dir }), + ) + assert.equal(headlessCode, 0) + assert.equal(headless.confirmations.some((entry) => entry.message === messages.starPrompt), false) + assert.equal(headless.said.plain.includes(messages.starThanks), false) + + const updated = fakePrompts({ existing: 'update' }) + const updatedCli = fakeSkillsCli({ lists: [[listed('bmad'), listed('bmod-method')]] }) + const updatedCode = await install( + options({ directory: dir }), + makeDeps({ prompts: updated.prompts, skillsCli: updatedCli.cli, bmadScripts: fakeBmadScripts({ statuses: [statusOf(), statusOf()] }).scripts, cwd: dir }), + ) + assert.equal(updatedCode, 0) + assert.equal(updated.confirmations.some((entry) => entry.message === messages.starPrompt), false) + assert.equal(updated.said.plain.includes(messages.starThanks), false) +}) + +test('interactive install skips starPrompt when the final report is unsuccessful', async (t) => { + const dir = await tempDir(t) + const { prompts, said, confirmations } = fakePrompts() + const { cli } = fakeSkillsCli({ lists: [[], RECORDS.map(listed)] }) + const incomplete = statusOf({ current: false, next: 'npx skills update' }) + const { scripts } = fakeBmadScripts({ statuses: [incomplete, incomplete] }) + + const code = await install( + options({ directory: dir, tools: 'claude-code' }), + makeDeps({ prompts, skillsCli: cli, bmadScripts: scripts, cwd: dir }), + ) + + assert.equal(code, 1) + assert.equal(confirmations.some((entry) => entry.message === messages.starPrompt), false) + assert.equal(said.plain.includes(messages.starThanks), false) +}) diff --git a/test/messages.test.js b/test/messages.test.js index 8f1fc87..2813b7d 100644 --- a/test/messages.test.js +++ b/test/messages.test.js @@ -95,6 +95,8 @@ const keysWithValues = { universalAgentName: {}, updateLater: {}, thanks: {}, + starPrompt: {}, + starThanks: {}, cancelled: {}, droppedUninstall: {}, } @@ -153,26 +155,37 @@ test('the ending names setup, the update command and every link once', () => { assert.ok(updateLater.includes("'bmad update'")) assert.ok(updateLater.includes('npx bmad-method update')) const thanks = message(loaded, 'thanks') + assert.equal(thanks.includes('https://github.com/bmad-code-org/BMAD-METHOD'), false) for (const link of [ 'https://blog.bmadcode.com', - 'https://github.com/bmad-code-org/BMAD-METHOD', 'https://discord.gg/gk8jAdXWmj', 'https://www.youtube.com/@BMadCode', 'https://buymeacoffee.com/bmad', 'https://bmadcode.com/#contact', + 'contact@bmadcode.com', ]) { assert.ok(thanks.includes(link), `thanks is missing: ${link}`) for (const bannerKey of ['eyebrow', 'intro', 'credit']) { assert.equal(message(loaded, bannerKey).includes(link), false, `${bannerKey} repeats ${link}`) } } + const starThanks = message(loaded, 'starThanks') + assert.ok(starThanks.includes('https://github.com/bmad-code-org/BMAD-METHOD')) + assert.ok(starThanks.includes('top-right')) + for (const bannerKey of ['eyebrow', 'intro', 'credit']) { + assert.equal( + message(loaded, bannerKey).includes('https://github.com/bmad-code-org/BMAD-METHOD'), + false, + `${bannerKey} repeats https://github.com/bmad-code-org/BMAD-METHOD`, + ) + } }) test('the prose blocks fit the clack note box without rewrapping', () => { const blocks = [ 'eyebrow', 'intro', 'credit', 'updateAvailable', 'nodeTooOld', 'nodeBelowSkillsFloor', 'uvMissing', 'wslWindowsNode', 'needsTerminal', 'insideAgent', 'legacyManifest', 'legacyNoV7', 'modulesKept', 'firstInstallNotInProject', 'unknownTools', 'repeatInstall', - 'nothingInstalled', 'nothingToUpdate', 'statusNoUv', 'cancelled', 'summaryNextSetup', 'summaryNextCurrent', 'thanks', 'droppedUninstall', + 'nothingInstalled', 'nothingToUpdate', 'statusNoUv', 'cancelled', 'summaryNextSetup', 'summaryNextCurrent', 'thanks', 'starPrompt', 'starThanks', 'droppedUninstall', ] for (const key of blocks) { for (const line of message(loaded, key, keysWithValues[key]).split('\n')) {