Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
14 changes: 13 additions & 1 deletion src/commands/ending.js
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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<string, string>, failures: AddResult[], directory: string, agents?: string[], repeat?: string, updated?: boolean, fallbackModules?: string[] }} run
* @param {{ report: StatusReport | null, bmadSkillDir: string, before: Record<string, string>, 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
Expand Down Expand Up @@ -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('')
}
2 changes: 1 addition & 1 deletion src/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/commands/install-agents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
87 changes: 87 additions & 0 deletions test/commands/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
17 changes: 15 additions & 2 deletions test/messages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const keysWithValues = {
universalAgentName: {},
updateLater: {},
thanks: {},
starPrompt: {},
starThanks: {},
cancelled: {},
droppedUninstall: {},
}
Expand Down Expand Up @@ -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')) {
Expand Down
Loading