bmad-stella 1.0.0

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.
Files changed (398) hide show
  1. package/.github/FORK_GUIDE.md +106 -0
  2. package/.github/FUNDING.yaml +15 -0
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
  5. package/.github/workflows/discord.yaml +26 -0
  6. package/.github/workflows/format-check.yaml +44 -0
  7. package/.github/workflows/manual-release.yaml +174 -0
  8. package/.github/workflows/pr-validation.yaml +55 -0
  9. package/.husky/pre-commit +3 -0
  10. package/.vscode/settings.json +69 -0
  11. package/CHANGELOG.md +686 -0
  12. package/CONTRIBUTING.md +243 -0
  13. package/LICENSE +26 -0
  14. package/PR-opencode-agents-generator.md +40 -0
  15. package/README.md +159 -0
  16. package/REVIEWER-AGENT-SIMPLE.md +66 -0
  17. package/bmad-core/agent-teams/team-all.yaml +15 -0
  18. package/bmad-core/agent-teams/team-fullstack.yaml +19 -0
  19. package/bmad-core/agent-teams/team-ide-minimal.yaml +11 -0
  20. package/bmad-core/agent-teams/team-no-ui.yaml +14 -0
  21. package/bmad-core/agents/analyst.md +84 -0
  22. package/bmad-core/agents/architect.md +85 -0
  23. package/bmad-core/agents/bmad-master.md +110 -0
  24. package/bmad-core/agents/bmad-orchestrator.md +147 -0
  25. package/bmad-core/agents/dev.md +96 -0
  26. package/bmad-core/agents/planner.md +86 -0
  27. package/bmad-core/agents/pm.md +84 -0
  28. package/bmad-core/agents/po.md +79 -0
  29. package/bmad-core/agents/qa.md +80 -0
  30. package/bmad-core/agents/reviewer.md +61 -0
  31. package/bmad-core/agents/sm.md +65 -0
  32. package/bmad-core/agents/ux-expert.md +69 -0
  33. package/bmad-core/checklists/architect-checklist.md +440 -0
  34. package/bmad-core/checklists/change-checklist.md +184 -0
  35. package/bmad-core/checklists/planner-validation-checklist.md +167 -0
  36. package/bmad-core/checklists/pm-checklist.md +372 -0
  37. package/bmad-core/checklists/po-master-checklist.md +434 -0
  38. package/bmad-core/checklists/story-dod-checklist.md +96 -0
  39. package/bmad-core/checklists/story-draft-checklist.md +155 -0
  40. package/bmad-core/checklists/task-dod-checklist.md +110 -0
  41. package/bmad-core/core-config.yaml +26 -0
  42. package/bmad-core/data/bmad-kb.md +809 -0
  43. package/bmad-core/data/brainstorming-techniques.md +38 -0
  44. package/bmad-core/data/elicitation-methods.md +156 -0
  45. package/bmad-core/data/technical-preferences.md +5 -0
  46. package/bmad-core/data/test-levels-framework.md +148 -0
  47. package/bmad-core/data/test-priorities-matrix.md +174 -0
  48. package/bmad-core/tasks/advanced-elicitation.md +119 -0
  49. package/bmad-core/tasks/apply-qa-fixes.md +150 -0
  50. package/bmad-core/tasks/brownfield-create-epic.md +162 -0
  51. package/bmad-core/tasks/brownfield-create-story.md +149 -0
  52. package/bmad-core/tasks/correct-course.md +72 -0
  53. package/bmad-core/tasks/create-brownfield-story.md +314 -0
  54. package/bmad-core/tasks/create-deep-research-prompt.md +280 -0
  55. package/bmad-core/tasks/create-implementation-plan.md +298 -0
  56. package/bmad-core/tasks/create-next-story.md +114 -0
  57. package/bmad-core/tasks/decompose-task.md +162 -0
  58. package/bmad-core/tasks/document-project.md +345 -0
  59. package/bmad-core/tasks/facilitate-brainstorming-session.md +138 -0
  60. package/bmad-core/tasks/generate-ai-frontend-prompt.md +53 -0
  61. package/bmad-core/tasks/identify-dependencies.md +347 -0
  62. package/bmad-core/tasks/implement-test.md +188 -0
  63. package/bmad-core/tasks/index-docs.md +175 -0
  64. package/bmad-core/tasks/kb-mode-interaction.md +77 -0
  65. package/bmad-core/tasks/nfr-assess.md +345 -0
  66. package/bmad-core/tasks/qa-gate.md +163 -0
  67. package/bmad-core/tasks/review-and-improve.md +95 -0
  68. package/bmad-core/tasks/review-story.md +316 -0
  69. package/bmad-core/tasks/risk-profile.md +355 -0
  70. package/bmad-core/tasks/shard-doc.md +187 -0
  71. package/bmad-core/tasks/test-design.md +176 -0
  72. package/bmad-core/tasks/trace-requirements.md +266 -0
  73. package/bmad-core/tasks/validate-next-story.md +136 -0
  74. package/bmad-core/templates/architecture-tmpl.yaml +651 -0
  75. package/bmad-core/templates/brainstorming-output-tmpl.yaml +156 -0
  76. package/bmad-core/templates/brownfield-architecture-tmpl.yaml +477 -0
  77. package/bmad-core/templates/brownfield-prd-tmpl.yaml +281 -0
  78. package/bmad-core/templates/competitor-analysis-tmpl.yaml +307 -0
  79. package/bmad-core/templates/front-end-architecture-tmpl.yaml +219 -0
  80. package/bmad-core/templates/front-end-spec-tmpl.yaml +350 -0
  81. package/bmad-core/templates/fullstack-architecture-tmpl.yaml +824 -0
  82. package/bmad-core/templates/implementation-plan-tmpl.yaml +224 -0
  83. package/bmad-core/templates/market-research-tmpl.yaml +253 -0
  84. package/bmad-core/templates/prd-tmpl.yaml +203 -0
  85. package/bmad-core/templates/project-brief-tmpl.yaml +222 -0
  86. package/bmad-core/templates/qa-gate-tmpl.yaml +103 -0
  87. package/bmad-core/templates/story-tmpl.yaml +138 -0
  88. package/bmad-core/workflows/brownfield-fullstack.yaml +298 -0
  89. package/bmad-core/workflows/brownfield-service.yaml +188 -0
  90. package/bmad-core/workflows/brownfield-ui.yaml +198 -0
  91. package/bmad-core/workflows/greenfield-fullstack.yaml +241 -0
  92. package/bmad-core/workflows/greenfield-service.yaml +207 -0
  93. package/bmad-core/workflows/greenfield-ui.yaml +236 -0
  94. package/common/tasks/create-doc.md +103 -0
  95. package/common/tasks/execute-checklist.md +88 -0
  96. package/common/utils/bmad-doc-template.md +327 -0
  97. package/common/utils/workflow-management.md +71 -0
  98. package/dist/agents/analyst.txt +2907 -0
  99. package/dist/agents/architect.txt +3567 -0
  100. package/dist/agents/bmad-master.txt +8828 -0
  101. package/dist/agents/bmad-orchestrator.txt +1520 -0
  102. package/dist/agents/dev.txt +576 -0
  103. package/dist/agents/pm.txt +2226 -0
  104. package/dist/agents/po.txt +1359 -0
  105. package/dist/agents/qa.txt +2001 -0
  106. package/dist/agents/sm.txt +667 -0
  107. package/dist/agents/ux-expert.txt +703 -0
  108. package/dist/expansion-packs/bmad-2d-phaser-game-dev/agents/game-designer.txt +2386 -0
  109. package/dist/expansion-packs/bmad-2d-phaser-game-dev/agents/game-developer.txt +1627 -0
  110. package/dist/expansion-packs/bmad-2d-phaser-game-dev/agents/game-sm.txt +822 -0
  111. package/dist/expansion-packs/bmad-2d-phaser-game-dev/teams/phaser-2d-nodejs-game-team.txt +11008 -0
  112. package/dist/expansion-packs/bmad-2d-unity-game-dev/agents/game-architect.txt +4031 -0
  113. package/dist/expansion-packs/bmad-2d-unity-game-dev/agents/game-designer.txt +3717 -0
  114. package/dist/expansion-packs/bmad-2d-unity-game-dev/agents/game-developer.txt +456 -0
  115. package/dist/expansion-packs/bmad-2d-unity-game-dev/agents/game-sm.txt +982 -0
  116. package/dist/expansion-packs/bmad-2d-unity-game-dev/teams/unity-2d-game-team.txt +15450 -0
  117. package/dist/expansion-packs/bmad-creative-writing/agents/beta-reader.txt +921 -0
  118. package/dist/expansion-packs/bmad-creative-writing/agents/book-critic.txt +81 -0
  119. package/dist/expansion-packs/bmad-creative-writing/agents/character-psychologist.txt +886 -0
  120. package/dist/expansion-packs/bmad-creative-writing/agents/cover-designer.txt +85 -0
  121. package/dist/expansion-packs/bmad-creative-writing/agents/dialog-specialist.txt +903 -0
  122. package/dist/expansion-packs/bmad-creative-writing/agents/editor.txt +837 -0
  123. package/dist/expansion-packs/bmad-creative-writing/agents/genre-specialist.txt +989 -0
  124. package/dist/expansion-packs/bmad-creative-writing/agents/narrative-designer.txt +888 -0
  125. package/dist/expansion-packs/bmad-creative-writing/agents/plot-architect.txt +1173 -0
  126. package/dist/expansion-packs/bmad-creative-writing/agents/world-builder.txt +914 -0
  127. package/dist/expansion-packs/bmad-creative-writing/teams/agent-team.txt +6511 -0
  128. package/dist/expansion-packs/bmad-godot-game-dev/agents/bmad-orchestrator.txt +1513 -0
  129. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-analyst.txt +3190 -0
  130. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-architect.txt +4499 -0
  131. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-designer.txt +3925 -0
  132. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-developer.txt +666 -0
  133. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-pm.txt +2381 -0
  134. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-po.txt +1612 -0
  135. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-qa.txt +1741 -0
  136. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-sm.txt +1208 -0
  137. package/dist/expansion-packs/bmad-godot-game-dev/agents/game-ux-expert.txt +958 -0
  138. package/dist/expansion-packs/bmad-godot-game-dev/teams/godot-game-team.txt +27717 -0
  139. package/dist/expansion-packs/bmad-infrastructure-devops/agents/infra-devops-platform.txt +2087 -0
  140. package/dist/teams/team-all.txt +12911 -0
  141. package/dist/teams/team-fullstack.txt +10477 -0
  142. package/dist/teams/team-ide-minimal.txt +5299 -0
  143. package/dist/teams/team-no-ui.txt +9029 -0
  144. package/docs/GUIDING-PRINCIPLES.md +91 -0
  145. package/docs/core-architecture.md +219 -0
  146. package/docs/enhanced-ide-development-workflow.md +248 -0
  147. package/docs/expansion-packs.md +200 -0
  148. package/docs/flattener.md +91 -0
  149. package/docs/how-to-contribute-with-pull-requests.md +158 -0
  150. package/docs/stella-user-guide.md +637 -0
  151. package/docs/user-guide.md +577 -0
  152. package/docs/versioning-and-releases.md +155 -0
  153. package/docs/versions.md +48 -0
  154. package/docs/working-in-the-brownfield.md +606 -0
  155. package/eslint.config.mjs +119 -0
  156. package/expansion-packs/README.md +3 -0
  157. package/expansion-packs/bmad-2d-phaser-game-dev/agent-teams/phaser-2d-nodejs-game-team.yaml +14 -0
  158. package/expansion-packs/bmad-2d-phaser-game-dev/agents/game-designer.md +73 -0
  159. package/expansion-packs/bmad-2d-phaser-game-dev/agents/game-developer.md +80 -0
  160. package/expansion-packs/bmad-2d-phaser-game-dev/agents/game-sm.md +66 -0
  161. package/expansion-packs/bmad-2d-phaser-game-dev/checklists/game-design-checklist.md +203 -0
  162. package/expansion-packs/bmad-2d-phaser-game-dev/checklists/game-story-dod-checklist.md +162 -0
  163. package/expansion-packs/bmad-2d-phaser-game-dev/config.yaml +9 -0
  164. package/expansion-packs/bmad-2d-phaser-game-dev/data/bmad-kb.md +252 -0
  165. package/expansion-packs/bmad-2d-phaser-game-dev/data/development-guidelines.md +649 -0
  166. package/expansion-packs/bmad-2d-phaser-game-dev/tasks/advanced-elicitation.md +112 -0
  167. package/expansion-packs/bmad-2d-phaser-game-dev/tasks/create-game-story.md +218 -0
  168. package/expansion-packs/bmad-2d-phaser-game-dev/tasks/game-design-brainstorming.md +292 -0
  169. package/expansion-packs/bmad-2d-phaser-game-dev/templates/game-architecture-tmpl.yaml +614 -0
  170. package/expansion-packs/bmad-2d-phaser-game-dev/templates/game-brief-tmpl.yaml +357 -0
  171. package/expansion-packs/bmad-2d-phaser-game-dev/templates/game-design-doc-tmpl.yaml +344 -0
  172. package/expansion-packs/bmad-2d-phaser-game-dev/templates/game-story-tmpl.yaml +254 -0
  173. package/expansion-packs/bmad-2d-phaser-game-dev/templates/level-design-doc-tmpl.yaml +485 -0
  174. package/expansion-packs/bmad-2d-phaser-game-dev/workflows/game-dev-greenfield.yaml +184 -0
  175. package/expansion-packs/bmad-2d-phaser-game-dev/workflows/game-prototype.yaml +176 -0
  176. package/expansion-packs/bmad-2d-unity-game-dev/agent-teams/unity-2d-game-team.yaml +15 -0
  177. package/expansion-packs/bmad-2d-unity-game-dev/agents/game-architect.md +82 -0
  178. package/expansion-packs/bmad-2d-unity-game-dev/agents/game-designer.md +79 -0
  179. package/expansion-packs/bmad-2d-unity-game-dev/agents/game-developer.md +80 -0
  180. package/expansion-packs/bmad-2d-unity-game-dev/agents/game-sm.md +67 -0
  181. package/expansion-packs/bmad-2d-unity-game-dev/checklists/game-architect-checklist.md +393 -0
  182. package/expansion-packs/bmad-2d-unity-game-dev/checklists/game-change-checklist.md +205 -0
  183. package/expansion-packs/bmad-2d-unity-game-dev/checklists/game-design-checklist.md +203 -0
  184. package/expansion-packs/bmad-2d-unity-game-dev/checklists/game-story-dod-checklist.md +126 -0
  185. package/expansion-packs/bmad-2d-unity-game-dev/config.yaml +7 -0
  186. package/expansion-packs/bmad-2d-unity-game-dev/data/bmad-kb.md +771 -0
  187. package/expansion-packs/bmad-2d-unity-game-dev/data/development-guidelines.md +588 -0
  188. package/expansion-packs/bmad-2d-unity-game-dev/tasks/advanced-elicitation.md +112 -0
  189. package/expansion-packs/bmad-2d-unity-game-dev/tasks/correct-course-game.md +143 -0
  190. package/expansion-packs/bmad-2d-unity-game-dev/tasks/create-game-story.md +186 -0
  191. package/expansion-packs/bmad-2d-unity-game-dev/tasks/game-design-brainstorming.md +292 -0
  192. package/expansion-packs/bmad-2d-unity-game-dev/tasks/validate-game-story.md +202 -0
  193. package/expansion-packs/bmad-2d-unity-game-dev/templates/game-architecture-tmpl.yaml +1031 -0
  194. package/expansion-packs/bmad-2d-unity-game-dev/templates/game-brief-tmpl.yaml +357 -0
  195. package/expansion-packs/bmad-2d-unity-game-dev/templates/game-design-doc-tmpl.yaml +706 -0
  196. package/expansion-packs/bmad-2d-unity-game-dev/templates/game-story-tmpl.yaml +257 -0
  197. package/expansion-packs/bmad-2d-unity-game-dev/templates/level-design-doc-tmpl.yaml +485 -0
  198. package/expansion-packs/bmad-2d-unity-game-dev/workflows/game-dev-greenfield.yaml +184 -0
  199. package/expansion-packs/bmad-2d-unity-game-dev/workflows/game-prototype.yaml +176 -0
  200. package/expansion-packs/bmad-creative-writing/README.md +146 -0
  201. package/expansion-packs/bmad-creative-writing/agent-teams/agent-team.yaml +20 -0
  202. package/expansion-packs/bmad-creative-writing/agents/beta-reader.md +94 -0
  203. package/expansion-packs/bmad-creative-writing/agents/book-critic.md +40 -0
  204. package/expansion-packs/bmad-creative-writing/agents/character-psychologist.md +93 -0
  205. package/expansion-packs/bmad-creative-writing/agents/cover-designer.md +46 -0
  206. package/expansion-packs/bmad-creative-writing/agents/dialog-specialist.md +92 -0
  207. package/expansion-packs/bmad-creative-writing/agents/editor.md +93 -0
  208. package/expansion-packs/bmad-creative-writing/agents/genre-specialist.md +95 -0
  209. package/expansion-packs/bmad-creative-writing/agents/narrative-designer.md +93 -0
  210. package/expansion-packs/bmad-creative-writing/agents/plot-architect.md +95 -0
  211. package/expansion-packs/bmad-creative-writing/agents/world-builder.md +94 -0
  212. package/expansion-packs/bmad-creative-writing/checklists/beta-feedback-closure-checklist.md +23 -0
  213. package/expansion-packs/bmad-creative-writing/checklists/character-consistency-checklist.md +23 -0
  214. package/expansion-packs/bmad-creative-writing/checklists/comedic-timing-checklist.md +23 -0
  215. package/expansion-packs/bmad-creative-writing/checklists/cyberpunk-aesthetic-checklist.md +23 -0
  216. package/expansion-packs/bmad-creative-writing/checklists/ebook-formatting-checklist.md +21 -0
  217. package/expansion-packs/bmad-creative-writing/checklists/epic-poetry-meter-checklist.md +23 -0
  218. package/expansion-packs/bmad-creative-writing/checklists/fantasy-magic-system-checklist.md +23 -0
  219. package/expansion-packs/bmad-creative-writing/checklists/foreshadowing-payoff-checklist.md +22 -0
  220. package/expansion-packs/bmad-creative-writing/checklists/genre-tropes-checklist.md +22 -0
  221. package/expansion-packs/bmad-creative-writing/checklists/historical-accuracy-checklist.md +23 -0
  222. package/expansion-packs/bmad-creative-writing/checklists/horror-suspense-checklist.md +23 -0
  223. package/expansion-packs/bmad-creative-writing/checklists/kdp-cover-ready-checklist.md +25 -0
  224. package/expansion-packs/bmad-creative-writing/checklists/line-edit-quality-checklist.md +23 -0
  225. package/expansion-packs/bmad-creative-writing/checklists/marketing-copy-checklist.md +23 -0
  226. package/expansion-packs/bmad-creative-writing/checklists/mystery-clue-trail-checklist.md +23 -0
  227. package/expansion-packs/bmad-creative-writing/checklists/orbital-mechanics-checklist.md +23 -0
  228. package/expansion-packs/bmad-creative-writing/checklists/plot-structure-checklist.md +59 -0
  229. package/expansion-packs/bmad-creative-writing/checklists/publication-readiness-checklist.md +23 -0
  230. package/expansion-packs/bmad-creative-writing/checklists/romance-emotional-beats-checklist.md +23 -0
  231. package/expansion-packs/bmad-creative-writing/checklists/scene-quality-checklist.md +23 -0
  232. package/expansion-packs/bmad-creative-writing/checklists/scifi-technology-plausibility-checklist.md +22 -0
  233. package/expansion-packs/bmad-creative-writing/checklists/sensitivity-representation-checklist.md +23 -0
  234. package/expansion-packs/bmad-creative-writing/checklists/steampunk-gadget-checklist.md +23 -0
  235. package/expansion-packs/bmad-creative-writing/checklists/thriller-pacing-stakes-checklist.md +23 -0
  236. package/expansion-packs/bmad-creative-writing/checklists/timeline-continuity-checklist.md +23 -0
  237. package/expansion-packs/bmad-creative-writing/checklists/world-building-continuity-checklist.md +23 -0
  238. package/expansion-packs/bmad-creative-writing/checklists/ya-appropriateness-checklist.md +23 -0
  239. package/expansion-packs/bmad-creative-writing/config.yaml +12 -0
  240. package/expansion-packs/bmad-creative-writing/data/bmad-kb.md +209 -0
  241. package/expansion-packs/bmad-creative-writing/data/story-structures.md +67 -0
  242. package/expansion-packs/bmad-creative-writing/docs/brief.md +212 -0
  243. package/expansion-packs/bmad-creative-writing/tasks/advanced-elicitation.md +119 -0
  244. package/expansion-packs/bmad-creative-writing/tasks/analyze-reader-feedback.md +23 -0
  245. package/expansion-packs/bmad-creative-writing/tasks/analyze-story-structure.md +67 -0
  246. package/expansion-packs/bmad-creative-writing/tasks/assemble-kdp-package.md +29 -0
  247. package/expansion-packs/bmad-creative-writing/tasks/brainstorm-premise.md +23 -0
  248. package/expansion-packs/bmad-creative-writing/tasks/build-world.md +24 -0
  249. package/expansion-packs/bmad-creative-writing/tasks/character-depth-pass.md +22 -0
  250. package/expansion-packs/bmad-creative-writing/tasks/create-doc.md +103 -0
  251. package/expansion-packs/bmad-creative-writing/tasks/create-draft-section.md +26 -0
  252. package/expansion-packs/bmad-creative-writing/tasks/critical-review.md +26 -0
  253. package/expansion-packs/bmad-creative-writing/tasks/develop-character.md +24 -0
  254. package/expansion-packs/bmad-creative-writing/tasks/execute-checklist.md +88 -0
  255. package/expansion-packs/bmad-creative-writing/tasks/expand-premise.md +23 -0
  256. package/expansion-packs/bmad-creative-writing/tasks/expand-synopsis.md +23 -0
  257. package/expansion-packs/bmad-creative-writing/tasks/final-polish.md +23 -0
  258. package/expansion-packs/bmad-creative-writing/tasks/generate-cover-brief.md +25 -0
  259. package/expansion-packs/bmad-creative-writing/tasks/generate-cover-prompts.md +26 -0
  260. package/expansion-packs/bmad-creative-writing/tasks/generate-scene-list.md +23 -0
  261. package/expansion-packs/bmad-creative-writing/tasks/incorporate-feedback.md +25 -0
  262. package/expansion-packs/bmad-creative-writing/tasks/outline-scenes.md +23 -0
  263. package/expansion-packs/bmad-creative-writing/tasks/provide-feedback.md +24 -0
  264. package/expansion-packs/bmad-creative-writing/tasks/publish-chapter.md +23 -0
  265. package/expansion-packs/bmad-creative-writing/tasks/quick-feedback.md +22 -0
  266. package/expansion-packs/bmad-creative-writing/tasks/select-next-arc.md +23 -0
  267. package/expansion-packs/bmad-creative-writing/tasks/workshop-dialog.md +64 -0
  268. package/expansion-packs/bmad-creative-writing/templates/beta-feedback-form.yaml +97 -0
  269. package/expansion-packs/bmad-creative-writing/templates/chapter-draft-tmpl.yaml +82 -0
  270. package/expansion-packs/bmad-creative-writing/templates/character-profile-tmpl.yaml +92 -0
  271. package/expansion-packs/bmad-creative-writing/templates/cover-design-brief-tmpl.yaml +98 -0
  272. package/expansion-packs/bmad-creative-writing/templates/premise-brief-tmpl.yaml +78 -0
  273. package/expansion-packs/bmad-creative-writing/templates/scene-list-tmpl.yaml +55 -0
  274. package/expansion-packs/bmad-creative-writing/templates/story-outline-tmpl.yaml +96 -0
  275. package/expansion-packs/bmad-creative-writing/templates/world-guide-tmpl.yaml +89 -0
  276. package/expansion-packs/bmad-creative-writing/workflows/book-cover-design-workflow.md +218 -0
  277. package/expansion-packs/bmad-creative-writing/workflows/novel-greenfield-workflow.yaml +56 -0
  278. package/expansion-packs/bmad-creative-writing/workflows/novel-serial-workflow.yaml +50 -0
  279. package/expansion-packs/bmad-creative-writing/workflows/novel-snowflake-workflow.yaml +69 -0
  280. package/expansion-packs/bmad-creative-writing/workflows/novel-writing.yaml +91 -0
  281. package/expansion-packs/bmad-creative-writing/workflows/screenplay-development.yaml +85 -0
  282. package/expansion-packs/bmad-creative-writing/workflows/series-planning.yaml +78 -0
  283. package/expansion-packs/bmad-creative-writing/workflows/short-story-creation.yaml +64 -0
  284. package/expansion-packs/bmad-godot-game-dev/README.md +244 -0
  285. package/expansion-packs/bmad-godot-game-dev/agent-teams/godot-game-team.yaml +18 -0
  286. package/expansion-packs/bmad-godot-game-dev/agents/bmad-orchestrator.md +147 -0
  287. package/expansion-packs/bmad-godot-game-dev/agents/game-analyst.md +84 -0
  288. package/expansion-packs/bmad-godot-game-dev/agents/game-architect.md +146 -0
  289. package/expansion-packs/bmad-godot-game-dev/agents/game-designer.md +78 -0
  290. package/expansion-packs/bmad-godot-game-dev/agents/game-developer.md +124 -0
  291. package/expansion-packs/bmad-godot-game-dev/agents/game-pm.md +82 -0
  292. package/expansion-packs/bmad-godot-game-dev/agents/game-po.md +115 -0
  293. package/expansion-packs/bmad-godot-game-dev/agents/game-qa.md +159 -0
  294. package/expansion-packs/bmad-godot-game-dev/agents/game-sm.md +66 -0
  295. package/expansion-packs/bmad-godot-game-dev/agents/game-ux-expert.md +75 -0
  296. package/expansion-packs/bmad-godot-game-dev/checklists/game-architect-checklist.md +377 -0
  297. package/expansion-packs/bmad-godot-game-dev/checklists/game-change-checklist.md +250 -0
  298. package/expansion-packs/bmad-godot-game-dev/checklists/game-design-checklist.md +225 -0
  299. package/expansion-packs/bmad-godot-game-dev/checklists/game-po-checklist.md +448 -0
  300. package/expansion-packs/bmad-godot-game-dev/checklists/game-story-dod-checklist.md +202 -0
  301. package/expansion-packs/bmad-godot-game-dev/config.yaml +30 -0
  302. package/expansion-packs/bmad-godot-game-dev/data/bmad-kb.md +811 -0
  303. package/expansion-packs/bmad-godot-game-dev/data/brainstorming-techniques.md +36 -0
  304. package/expansion-packs/bmad-godot-game-dev/data/development-guidelines.md +893 -0
  305. package/expansion-packs/bmad-godot-game-dev/data/elicitation-methods.md +156 -0
  306. package/expansion-packs/bmad-godot-game-dev/data/technical-preferences.md +3 -0
  307. package/expansion-packs/bmad-godot-game-dev/tasks/advanced-elicitation.md +110 -0
  308. package/expansion-packs/bmad-godot-game-dev/tasks/apply-qa-fixes.md +224 -0
  309. package/expansion-packs/bmad-godot-game-dev/tasks/brownfield-create-epic.md +162 -0
  310. package/expansion-packs/bmad-godot-game-dev/tasks/brownfield-create-story.md +149 -0
  311. package/expansion-packs/bmad-godot-game-dev/tasks/correct-course-game.md +159 -0
  312. package/expansion-packs/bmad-godot-game-dev/tasks/create-deep-research-prompt.md +278 -0
  313. package/expansion-packs/bmad-godot-game-dev/tasks/create-doc.md +103 -0
  314. package/expansion-packs/bmad-godot-game-dev/tasks/create-game-story.md +202 -0
  315. package/expansion-packs/bmad-godot-game-dev/tasks/document-project.md +343 -0
  316. package/expansion-packs/bmad-godot-game-dev/tasks/execute-checklist.md +88 -0
  317. package/expansion-packs/bmad-godot-game-dev/tasks/facilitate-brainstorming-session.md +136 -0
  318. package/expansion-packs/bmad-godot-game-dev/tasks/game-brownfield-create-epic.md +160 -0
  319. package/expansion-packs/bmad-godot-game-dev/tasks/game-brownfield-create-story.md +147 -0
  320. package/expansion-packs/bmad-godot-game-dev/tasks/game-design-brainstorming.md +290 -0
  321. package/expansion-packs/bmad-godot-game-dev/tasks/game-risk-profile.md +368 -0
  322. package/expansion-packs/bmad-godot-game-dev/tasks/game-test-design.md +219 -0
  323. package/expansion-packs/bmad-godot-game-dev/tasks/generate-ai-frontend-prompt.md +51 -0
  324. package/expansion-packs/bmad-godot-game-dev/tasks/kb-mode-interaction.md +77 -0
  325. package/expansion-packs/bmad-godot-game-dev/tasks/review-game-story.md +364 -0
  326. package/expansion-packs/bmad-godot-game-dev/tasks/shard-doc.md +187 -0
  327. package/expansion-packs/bmad-godot-game-dev/tasks/validate-game-story.md +208 -0
  328. package/expansion-packs/bmad-godot-game-dev/templates/brainstorming-output-tmpl.yaml +156 -0
  329. package/expansion-packs/bmad-godot-game-dev/templates/brownfield-prd-tmpl.yaml +281 -0
  330. package/expansion-packs/bmad-godot-game-dev/templates/competitor-analysis-tmpl.yaml +306 -0
  331. package/expansion-packs/bmad-godot-game-dev/templates/game-architecture-tmpl.yaml +1111 -0
  332. package/expansion-packs/bmad-godot-game-dev/templates/game-brief-tmpl.yaml +356 -0
  333. package/expansion-packs/bmad-godot-game-dev/templates/game-design-doc-tmpl.yaml +724 -0
  334. package/expansion-packs/bmad-godot-game-dev/templates/game-prd-tmpl.yaml +209 -0
  335. package/expansion-packs/bmad-godot-game-dev/templates/game-qa-gate-tmpl.yaml +186 -0
  336. package/expansion-packs/bmad-godot-game-dev/templates/game-story-tmpl.yaml +406 -0
  337. package/expansion-packs/bmad-godot-game-dev/templates/game-ui-spec-tmpl.yaml +601 -0
  338. package/expansion-packs/bmad-godot-game-dev/templates/level-design-doc-tmpl.yaml +620 -0
  339. package/expansion-packs/bmad-godot-game-dev/templates/market-research-tmpl.yaml +418 -0
  340. package/expansion-packs/bmad-godot-game-dev/utils/bmad-doc-template.md +327 -0
  341. package/expansion-packs/bmad-godot-game-dev/utils/workflow-management.md +71 -0
  342. package/expansion-packs/bmad-godot-game-dev/workflows/game-dev-greenfield.yaml +245 -0
  343. package/expansion-packs/bmad-godot-game-dev/workflows/game-prototype.yaml +213 -0
  344. package/expansion-packs/bmad-infrastructure-devops/README.md +147 -0
  345. package/expansion-packs/bmad-infrastructure-devops/agents/infra-devops-platform.md +73 -0
  346. package/expansion-packs/bmad-infrastructure-devops/checklists/infrastructure-checklist.md +486 -0
  347. package/expansion-packs/bmad-infrastructure-devops/config.yaml +10 -0
  348. package/expansion-packs/bmad-infrastructure-devops/data/bmad-kb.md +307 -0
  349. package/expansion-packs/bmad-infrastructure-devops/tasks/review-infrastructure.md +161 -0
  350. package/expansion-packs/bmad-infrastructure-devops/tasks/validate-infrastructure.md +155 -0
  351. package/expansion-packs/bmad-infrastructure-devops/templates/infrastructure-architecture-tmpl.yaml +425 -0
  352. package/expansion-packs/bmad-infrastructure-devops/templates/infrastructure-platform-from-arch-tmpl.yaml +630 -0
  353. package/package.json +116 -0
  354. package/prettier.config.mjs +32 -0
  355. package/tools/bmad-npx-wrapper.js +39 -0
  356. package/tools/builders/web-builder.js +675 -0
  357. package/tools/bump-all-versions.js +115 -0
  358. package/tools/bump-expansion-version.js +90 -0
  359. package/tools/cli.js +152 -0
  360. package/tools/flattener/aggregate.js +76 -0
  361. package/tools/flattener/binary.js +80 -0
  362. package/tools/flattener/discovery.js +71 -0
  363. package/tools/flattener/files.js +35 -0
  364. package/tools/flattener/ignoreRules.js +178 -0
  365. package/tools/flattener/main.js +568 -0
  366. package/tools/flattener/projectRoot.js +206 -0
  367. package/tools/flattener/prompts.js +44 -0
  368. package/tools/flattener/stats.helpers.js +395 -0
  369. package/tools/flattener/stats.js +80 -0
  370. package/tools/flattener/test-matrix.js +413 -0
  371. package/tools/flattener/xml.js +88 -0
  372. package/tools/implement-fork-friendly-ci.sh +229 -0
  373. package/tools/installer/README.md +8 -0
  374. package/tools/installer/bin/bmad.js +633 -0
  375. package/tools/installer/config/ide-agent-config.yaml +58 -0
  376. package/tools/installer/config/install.config.yaml +184 -0
  377. package/tools/installer/lib/config-loader.js +257 -0
  378. package/tools/installer/lib/dependency-manager.js +383 -0
  379. package/tools/installer/lib/file-manager.js +394 -0
  380. package/tools/installer/lib/ide-base-setup.js +228 -0
  381. package/tools/installer/lib/ide-setup.js +2461 -0
  382. package/tools/installer/lib/installer.js +2094 -0
  383. package/tools/installer/lib/memory-profiler.js +225 -0
  384. package/tools/installer/lib/module-manager.js +114 -0
  385. package/tools/installer/lib/resource-locator.js +308 -0
  386. package/tools/installer/package.json +47 -0
  387. package/tools/lib/dependency-resolver.js +175 -0
  388. package/tools/lib/yaml-utils.js +29 -0
  389. package/tools/md-assets/web-agent-startup-instructions.md +39 -0
  390. package/tools/preview-release-notes.js +66 -0
  391. package/tools/setup-hooks.sh +37 -0
  392. package/tools/shared/bannerArt.js +105 -0
  393. package/tools/sync-installer-version.js +32 -0
  394. package/tools/sync-version.sh +23 -0
  395. package/tools/update-expansion-version.js +53 -0
  396. package/tools/upgraders/v3-to-v4-upgrader.js +673 -0
  397. package/tools/version-bump.js +94 -0
  398. package/tools/yaml-format.js +253 -0
@@ -0,0 +1,2094 @@
1
+ const path = require('node:path');
2
+ const fs = require('fs-extra');
3
+ const chalk = require('chalk');
4
+ const ora = require('ora');
5
+ const inquirer = require('inquirer');
6
+ const fileManager = require('./file-manager');
7
+ const configLoader = require('./config-loader');
8
+ const ideSetup = require('./ide-setup');
9
+ const { extractYamlFromAgent } = require('../../lib/yaml-utils');
10
+ const resourceLocator = require('./resource-locator');
11
+ const dependencyManager = require('./dependency-manager');
12
+
13
+ class Installer {
14
+ async getCoreVersion() {
15
+ try {
16
+ // Always use package.json version
17
+ const packagePath = path.join(__dirname, '..', '..', '..', 'package.json');
18
+ const packageJson = require(packagePath);
19
+ return packageJson.version;
20
+ } catch {
21
+ console.warn("Could not read version from package.json, using 'unknown'");
22
+ return 'unknown';
23
+ }
24
+ }
25
+
26
+ async install(config) {
27
+ const spinner = ora('Analyzing installation directory...').start();
28
+
29
+ try {
30
+ // Store the original CWD where npx was executed
31
+ const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd();
32
+
33
+ // Resolve installation directory relative to where the user ran the command
34
+ let installDir = path.isAbsolute(config.directory)
35
+ ? config.directory
36
+ : path.resolve(originalCwd, config.directory);
37
+
38
+ if (path.basename(installDir) === '.bmad-core') {
39
+ // If user points directly to .bmad-core, treat its parent as the project root
40
+ installDir = path.dirname(installDir);
41
+ }
42
+
43
+ // Log resolved path for clarity
44
+ if (!path.isAbsolute(config.directory)) {
45
+ spinner.text = `Resolving "${config.directory}" to: ${installDir}`;
46
+ }
47
+
48
+ // Check if directory exists and handle non-existent directories
49
+ if (!(await fileManager.pathExists(installDir))) {
50
+ spinner.stop();
51
+ console.log(`\nThe directory ${installDir} does not exist.`);
52
+
53
+ const { action } = await inquirer.prompt([
54
+ {
55
+ type: 'list',
56
+ name: 'action',
57
+ message: 'What would you like to do?',
58
+ choices: [
59
+ {
60
+ name: 'Create the directory and continue',
61
+ value: 'create',
62
+ },
63
+ {
64
+ name: 'Choose a different directory',
65
+ value: 'change',
66
+ },
67
+ {
68
+ name: 'Cancel installation',
69
+ value: 'cancel',
70
+ },
71
+ ],
72
+ },
73
+ ]);
74
+
75
+ switch (action) {
76
+ case 'cancel': {
77
+ console.log('Installation cancelled.');
78
+ process.exit(0);
79
+
80
+ break;
81
+ }
82
+ case 'change': {
83
+ const { newDirectory } = await inquirer.prompt([
84
+ {
85
+ type: 'input',
86
+ name: 'newDirectory',
87
+ message: 'Enter the new directory path:',
88
+ validate: (input) => {
89
+ if (!input.trim()) {
90
+ return 'Please enter a valid directory path';
91
+ }
92
+ return true;
93
+ },
94
+ },
95
+ ]);
96
+ // Preserve the original CWD for the recursive call
97
+ config.directory = newDirectory;
98
+ return await this.install(config); // Recursive call with new directory
99
+ }
100
+ case 'create': {
101
+ try {
102
+ await fileManager.ensureDirectory(installDir);
103
+ console.log(`✓ Created directory: ${installDir}`);
104
+ } catch (error) {
105
+ console.error(`Failed to create directory: ${error.message}`);
106
+ console.error('You may need to check permissions or use a different path.');
107
+ process.exit(1);
108
+ }
109
+
110
+ break;
111
+ }
112
+ // No default
113
+ }
114
+
115
+ spinner.start('Analyzing installation directory...');
116
+ }
117
+
118
+ // If this is an update request from early detection, handle it directly
119
+ if (config.installType === 'update') {
120
+ const state = await this.detectInstallationState(installDir);
121
+ if (state.type === 'v4_existing') {
122
+ return await this.performUpdate(config, installDir, state.manifest, spinner);
123
+ } else {
124
+ spinner.fail('No existing v4 installation found to update');
125
+ throw new Error('No existing v4 installation found');
126
+ }
127
+ }
128
+
129
+ // Detect current state
130
+ const state = await this.detectInstallationState(installDir);
131
+
132
+ // Handle different states
133
+ switch (state.type) {
134
+ case 'clean': {
135
+ return await this.performFreshInstall(config, installDir, spinner);
136
+ }
137
+
138
+ case 'v4_existing': {
139
+ return await this.handleExistingV4Installation(config, installDir, state, spinner);
140
+ }
141
+
142
+ case 'v3_existing': {
143
+ return await this.handleV3Installation(config, installDir, state, spinner);
144
+ }
145
+
146
+ case 'unknown_existing': {
147
+ return await this.handleUnknownInstallation(config, installDir, state, spinner);
148
+ }
149
+ }
150
+ } catch (error) {
151
+ // Check if modules were initialized
152
+ if (spinner) {
153
+ spinner.fail('Installation failed');
154
+ } else {
155
+ console.error('Installation failed:', error.message);
156
+ }
157
+ throw error;
158
+ }
159
+ }
160
+
161
+ async detectInstallationState(installDir) {
162
+ const state = {
163
+ type: 'clean',
164
+ hasV4Manifest: false,
165
+ hasV3Structure: false,
166
+ hasBmadCore: false,
167
+ hasOtherFiles: false,
168
+ manifest: null,
169
+ expansionPacks: {},
170
+ };
171
+
172
+ // Check if directory exists
173
+ if (!(await fileManager.pathExists(installDir))) {
174
+ return state; // clean install
175
+ }
176
+
177
+ // Check for V4 installation (has .bmad-core with manifest)
178
+ const bmadCorePath = path.join(installDir, '.bmad-core');
179
+ const manifestPath = path.join(bmadCorePath, 'install-manifest.yaml');
180
+
181
+ if (await fileManager.pathExists(manifestPath)) {
182
+ state.type = 'v4_existing';
183
+ state.hasV4Manifest = true;
184
+ state.hasBmadCore = true;
185
+ state.manifest = await fileManager.readManifest(installDir);
186
+ return state;
187
+ }
188
+
189
+ // Check for V3 installation (has bmad-agent directory)
190
+ const bmadAgentPath = path.join(installDir, 'bmad-agent');
191
+ if (await fileManager.pathExists(bmadAgentPath)) {
192
+ state.type = 'v3_existing';
193
+ state.hasV3Structure = true;
194
+ return state;
195
+ }
196
+
197
+ // Check for .bmad-core without manifest (broken V4 or manual copy)
198
+ if (await fileManager.pathExists(bmadCorePath)) {
199
+ state.type = 'unknown_existing';
200
+ state.hasBmadCore = true;
201
+ return state;
202
+ }
203
+
204
+ // Check if directory has other files
205
+ const files = await resourceLocator.findFiles('**/*', {
206
+ cwd: installDir,
207
+ nodir: true,
208
+ ignore: ['**/.git/**', '**/node_modules/**'],
209
+ });
210
+
211
+ if (files.length > 0) {
212
+ // Directory has other files, but no BMad installation.
213
+ // Treat as clean install but record that it isn't empty.
214
+ state.hasOtherFiles = true;
215
+ }
216
+
217
+ // Check for expansion packs (folders starting with .)
218
+ const expansionPacks = await this.detectExpansionPacks(installDir);
219
+ state.expansionPacks = expansionPacks;
220
+
221
+ return state; // clean install
222
+ }
223
+
224
+ async performFreshInstall(config, installDir, spinner, options = {}) {
225
+ spinner.text = 'Installing BMad Method...';
226
+
227
+ let files = [];
228
+
229
+ switch (config.installType) {
230
+ case 'full': {
231
+ // Full installation - copy entire .bmad-core folder as a subdirectory
232
+ spinner.text = 'Copying complete .bmad-core folder...';
233
+ const sourceDir = resourceLocator.getBmadCorePath();
234
+ const bmadCoreDestDir = path.join(installDir, '.bmad-core');
235
+ await fileManager.copyDirectoryWithRootReplacement(
236
+ sourceDir,
237
+ bmadCoreDestDir,
238
+ '.bmad-core',
239
+ );
240
+
241
+ // Copy common/ items to .bmad-core
242
+ spinner.text = 'Copying common utilities...';
243
+ await this.copyCommonItems(installDir, '.bmad-core', spinner);
244
+
245
+ // Copy documentation files from docs/ to .bmad-core
246
+ spinner.text = 'Copying documentation files...';
247
+ await this.copyDocsItems(installDir, '.bmad-core', spinner);
248
+
249
+ // Get list of all files for manifest
250
+ const foundFiles = await resourceLocator.findFiles('**/*', {
251
+ cwd: bmadCoreDestDir,
252
+ nodir: true,
253
+ ignore: ['**/.git/**', '**/node_modules/**'],
254
+ });
255
+ files = foundFiles.map((file) => path.join('.bmad-core', file));
256
+
257
+ break;
258
+ }
259
+ case 'single-agent': {
260
+ // Single agent installation
261
+ spinner.text = `Installing ${config.agent} agent...`;
262
+
263
+ // Copy agent file with {root} replacement
264
+ const agentPath = configLoader.getAgentPath(config.agent);
265
+ const destinationAgentPath = path.join(
266
+ installDir,
267
+ '.bmad-core',
268
+ 'agents',
269
+ `${config.agent}.md`,
270
+ );
271
+ await fileManager.copyFileWithRootReplacement(
272
+ agentPath,
273
+ destinationAgentPath,
274
+ '.bmad-core',
275
+ );
276
+ files.push(`.bmad-core/agents/${config.agent}.md`);
277
+
278
+ // Copy dependencies
279
+ const { all: dependencies } = await resourceLocator.getAgentDependencies(config.agent);
280
+ const sourceBase = resourceLocator.getBmadCorePath();
281
+
282
+ for (const dep of dependencies) {
283
+ spinner.text = `Copying dependency: ${dep}`;
284
+
285
+ if (dep.includes('*')) {
286
+ // Handle glob patterns with {root} replacement
287
+ const copiedFiles = await fileManager.copyGlobPattern(
288
+ dep.replace('.bmad-core/', ''),
289
+ sourceBase,
290
+ path.join(installDir, '.bmad-core'),
291
+ '.bmad-core',
292
+ );
293
+ files.push(...copiedFiles.map((f) => `.bmad-core/${f}`));
294
+ } else {
295
+ // Handle single files with {root} replacement if needed
296
+ const sourcePath = path.join(sourceBase, dep.replace('.bmad-core/', ''));
297
+ const destinationPath = path.join(installDir, dep);
298
+
299
+ const needsRootReplacement =
300
+ dep.endsWith('.md') || dep.endsWith('.yaml') || dep.endsWith('.yml');
301
+ let success = false;
302
+
303
+ success = await (needsRootReplacement
304
+ ? fileManager.copyFileWithRootReplacement(sourcePath, destinationPath, '.bmad-core')
305
+ : fileManager.copyFile(sourcePath, destinationPath));
306
+
307
+ if (success) {
308
+ files.push(dep);
309
+ }
310
+ }
311
+ }
312
+
313
+ // Copy common/ items to .bmad-core
314
+ spinner.text = 'Copying common utilities...';
315
+ const commonFiles = await this.copyCommonItems(installDir, '.bmad-core', spinner);
316
+ files.push(...commonFiles);
317
+
318
+ // Copy documentation files from docs/ to .bmad-core
319
+ spinner.text = 'Copying documentation files...';
320
+ const documentFiles = await this.copyDocsItems(installDir, '.bmad-core', spinner);
321
+ files.push(...documentFiles);
322
+
323
+ break;
324
+ }
325
+ case 'team': {
326
+ // Team installation
327
+ spinner.text = `Installing ${config.team} team...`;
328
+
329
+ // Get team dependencies
330
+ const teamDependencies = await configLoader.getTeamDependencies(config.team);
331
+ const sourceBase = resourceLocator.getBmadCorePath();
332
+
333
+ // Install all team dependencies
334
+ for (const dep of teamDependencies) {
335
+ spinner.text = `Copying team dependency: ${dep}`;
336
+
337
+ if (dep.includes('*')) {
338
+ // Handle glob patterns with {root} replacement
339
+ const copiedFiles = await fileManager.copyGlobPattern(
340
+ dep.replace('.bmad-core/', ''),
341
+ sourceBase,
342
+ path.join(installDir, '.bmad-core'),
343
+ '.bmad-core',
344
+ );
345
+ files.push(...copiedFiles.map((f) => `.bmad-core/${f}`));
346
+ } else {
347
+ // Handle single files with {root} replacement if needed
348
+ const sourcePath = path.join(sourceBase, dep.replace('.bmad-core/', ''));
349
+ const destinationPath = path.join(installDir, dep);
350
+
351
+ const needsRootReplacement =
352
+ dep.endsWith('.md') || dep.endsWith('.yaml') || dep.endsWith('.yml');
353
+ let success = false;
354
+
355
+ success = await (needsRootReplacement
356
+ ? fileManager.copyFileWithRootReplacement(sourcePath, destinationPath, '.bmad-core')
357
+ : fileManager.copyFile(sourcePath, destinationPath));
358
+
359
+ if (success) {
360
+ files.push(dep);
361
+ }
362
+ }
363
+ }
364
+
365
+ // Copy common/ items to .bmad-core
366
+ spinner.text = 'Copying common utilities...';
367
+ const commonFiles = await this.copyCommonItems(installDir, '.bmad-core', spinner);
368
+ files.push(...commonFiles);
369
+
370
+ // Copy documentation files from docs/ to .bmad-core
371
+ spinner.text = 'Copying documentation files...';
372
+ const documentFiles = await this.copyDocsItems(installDir, '.bmad-core', spinner);
373
+ files.push(...documentFiles);
374
+
375
+ break;
376
+ }
377
+ case 'expansion-only': {
378
+ // Expansion-only installation - DO NOT create .bmad-core
379
+ // Only install expansion packs
380
+ spinner.text = 'Installing expansion packs only...';
381
+
382
+ break;
383
+ }
384
+ // No default
385
+ }
386
+
387
+ // Install expansion packs if requested
388
+ const expansionFiles = await this.installExpansionPacks(
389
+ installDir,
390
+ config.expansionPacks,
391
+ spinner,
392
+ config,
393
+ );
394
+ files.push(...expansionFiles);
395
+
396
+ // Install web bundles if requested
397
+ if (config.includeWebBundles && config.webBundlesDirectory) {
398
+ spinner.text = 'Installing web bundles...';
399
+ // Resolve web bundles directory using the same logic as the main installation directory
400
+ const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd();
401
+ let resolvedWebBundlesDir = path.isAbsolute(config.webBundlesDirectory)
402
+ ? config.webBundlesDirectory
403
+ : path.resolve(originalCwd, config.webBundlesDirectory);
404
+ await this.installWebBundles(resolvedWebBundlesDir, config, spinner);
405
+ }
406
+
407
+ // Set up IDE integration if requested
408
+ const ides = config.ides || (config.ide ? [config.ide] : []);
409
+ if (ides.length > 0) {
410
+ for (const ide of ides) {
411
+ spinner.text = `Setting up ${ide} integration...`;
412
+ let preConfiguredSettings = null;
413
+ switch (ide) {
414
+ case 'github-copilot': {
415
+ preConfiguredSettings = config.githubCopilotConfig;
416
+ break;
417
+ }
418
+ case 'auggie-cli': {
419
+ preConfiguredSettings = config.augmentCodeConfig;
420
+ break;
421
+ }
422
+ case 'opencode': {
423
+ preConfiguredSettings = config.openCodeConfig;
424
+ break;
425
+ }
426
+ default: {
427
+ // no pre-configured settings
428
+ break;
429
+ }
430
+ }
431
+ await ideSetup.setup(ide, installDir, config.agent, spinner, preConfiguredSettings);
432
+ }
433
+ }
434
+
435
+ // Check and configure required MCP servers (e.g., Atlassian MCP for JIRA integration)
436
+ if (config.installType !== 'expansion-only') {
437
+ spinner.text = 'Checking required MCP servers...';
438
+ const mcpResults = await dependencyManager.checkAndInstallMcpServers(installDir, spinner);
439
+ await dependencyManager.showInstallationSummary(mcpResults, installDir);
440
+ }
441
+
442
+ // Modify core-config.yaml if sharding preferences were provided
443
+ if (
444
+ config.installType !== 'expansion-only' &&
445
+ (config.prdSharded !== undefined ||
446
+ config.architectureSharded !== undefined ||
447
+ config.architectureFolderUrl !== undefined)
448
+ ) {
449
+ spinner.text = 'Configuring document sharding settings...';
450
+ await fileManager.modifyCoreConfig(installDir, config);
451
+ }
452
+
453
+ // Update .gitignore with BMad directories
454
+ if (config.installType !== 'expansion-only') {
455
+ spinner.text = 'Updating .gitignore...';
456
+ spinner.stop();
457
+ await this.updateGitignore(installDir);
458
+ spinner.start();
459
+ }
460
+
461
+ // Create manifest (skip for expansion-only installations)
462
+ if (config.installType !== 'expansion-only') {
463
+ spinner.text = 'Creating installation manifest...';
464
+ await fileManager.createManifest(installDir, config, files);
465
+ }
466
+
467
+ spinner.succeed('Installation complete!');
468
+ this.showSuccessMessage(config, installDir, options);
469
+ }
470
+
471
+ async handleExistingV4Installation(config, installDir, state, spinner) {
472
+ spinner.stop();
473
+
474
+ const currentVersion = state.manifest.version;
475
+ const newVersion = await this.getCoreVersion();
476
+ const versionCompare = this.compareVersions(currentVersion, newVersion);
477
+
478
+ console.log(chalk.yellow('\n🔍 Found existing BMad v4 installation'));
479
+ console.log(` Directory: ${installDir}`);
480
+ console.log(` Current version: ${currentVersion}`);
481
+ console.log(` Available version: ${newVersion}`);
482
+ console.log(` Installed: ${new Date(state.manifest.installed_at).toLocaleDateString()}`);
483
+
484
+ // Check file integrity
485
+ spinner.start('Checking installation integrity...');
486
+ const integrity = await fileManager.checkFileIntegrity(installDir, state.manifest);
487
+ spinner.stop();
488
+
489
+ const hasMissingFiles = integrity.missing.length > 0;
490
+ const hasModifiedFiles = integrity.modified.length > 0;
491
+ const hasIntegrityIssues = hasMissingFiles || hasModifiedFiles;
492
+
493
+ if (hasIntegrityIssues) {
494
+ console.log(chalk.red('\n⚠️ Installation issues detected:'));
495
+ if (hasMissingFiles) {
496
+ console.log(chalk.red(` Missing files: ${integrity.missing.length}`));
497
+ if (integrity.missing.length <= 5) {
498
+ for (const file of integrity.missing) console.log(chalk.dim(` - ${file}`));
499
+ }
500
+ }
501
+ if (hasModifiedFiles) {
502
+ console.log(chalk.yellow(` Modified files: ${integrity.modified.length}`));
503
+ if (integrity.modified.length <= 5) {
504
+ for (const file of integrity.modified) console.log(chalk.dim(` - ${file}`));
505
+ }
506
+ }
507
+ }
508
+
509
+ // Show existing expansion packs
510
+ if (Object.keys(state.expansionPacks).length > 0) {
511
+ console.log(chalk.cyan('\n📦 Installed expansion packs:'));
512
+ for (const [packId, packInfo] of Object.entries(state.expansionPacks)) {
513
+ if (packInfo.hasManifest && packInfo.manifest) {
514
+ console.log(` - ${packId} (v${packInfo.manifest.version || 'unknown'})`);
515
+ } else {
516
+ console.log(` - ${packId} (no manifest)`);
517
+ }
518
+ }
519
+ }
520
+
521
+ let choices = [];
522
+
523
+ if (versionCompare < 0) {
524
+ console.log(chalk.cyan('\n⬆️ Upgrade available for BMad core'));
525
+ choices.push({
526
+ name: `Upgrade BMad core (v${currentVersion} → v${newVersion})`,
527
+ value: 'upgrade',
528
+ });
529
+ } else if (versionCompare === 0) {
530
+ if (hasIntegrityIssues) {
531
+ // Offer repair option when files are missing or modified
532
+ choices.push({
533
+ name: 'Repair installation (restore missing/modified files)',
534
+ value: 'repair',
535
+ });
536
+ }
537
+ console.log(chalk.yellow('\n⚠️ Same version already installed'));
538
+ choices.push({
539
+ name: `Force reinstall BMad core (v${currentVersion} - reinstall)`,
540
+ value: 'reinstall',
541
+ });
542
+ } else {
543
+ console.log(chalk.yellow('\n⬇️ Installed version is newer than available'));
544
+ choices.push({
545
+ name: `Downgrade BMad core (v${currentVersion} → v${newVersion})`,
546
+ value: 'reinstall',
547
+ });
548
+ }
549
+
550
+ choices.push(
551
+ { name: 'Add/update expansion packs only', value: 'expansions' },
552
+ { name: 'Cancel', value: 'cancel' },
553
+ );
554
+
555
+ const { action } = await inquirer.prompt([
556
+ {
557
+ type: 'list',
558
+ name: 'action',
559
+ message: 'What would you like to do?',
560
+ choices: choices,
561
+ },
562
+ ]);
563
+
564
+ switch (action) {
565
+ case 'upgrade': {
566
+ return await this.performUpdate(config, installDir, state.manifest, spinner);
567
+ }
568
+ case 'repair': {
569
+ // For repair, restore missing/modified files while backing up modified ones
570
+ return await this.performRepair(config, installDir, state.manifest, integrity, spinner);
571
+ }
572
+ case 'reinstall': {
573
+ // For reinstall, don't check for modifications - just overwrite
574
+ return await this.performReinstall(config, installDir, spinner);
575
+ }
576
+ case 'expansions': {
577
+ // Ask which expansion packs to install
578
+ const availableExpansionPacks = await resourceLocator.getExpansionPacks();
579
+
580
+ if (availableExpansionPacks.length === 0) {
581
+ console.log(chalk.yellow('No expansion packs available.'));
582
+ return;
583
+ }
584
+
585
+ const { selectedPacks } = await inquirer.prompt([
586
+ {
587
+ type: 'checkbox',
588
+ name: 'selectedPacks',
589
+ message: 'Select expansion packs to install/update:',
590
+ choices: availableExpansionPacks.map((pack) => ({
591
+ name: `${pack.name} (v${pack.version}) .${pack.id}`,
592
+ value: pack.id,
593
+ checked: state.expansionPacks[pack.id] !== undefined,
594
+ })),
595
+ },
596
+ ]);
597
+
598
+ if (selectedPacks.length === 0) {
599
+ console.log(chalk.yellow('No expansion packs selected.'));
600
+ return;
601
+ }
602
+
603
+ spinner.start('Installing expansion packs...');
604
+ const expansionFiles = await this.installExpansionPacks(
605
+ installDir,
606
+ selectedPacks,
607
+ spinner,
608
+ { ides: config.ides || [] },
609
+ );
610
+ spinner.succeed('Expansion packs installed successfully!');
611
+
612
+ console.log(chalk.green('\n✓ Installation complete!'));
613
+ console.log(chalk.green(`✓ Expansion packs installed/updated:`));
614
+ for (const packId of selectedPacks) {
615
+ console.log(chalk.green(` - ${packId} → .${packId}/`));
616
+ }
617
+ return;
618
+ }
619
+ case 'cancel': {
620
+ console.log('Installation cancelled.');
621
+ return;
622
+ }
623
+ }
624
+ }
625
+
626
+ async handleV3Installation(config, installDir, state, spinner) {
627
+ spinner.stop();
628
+
629
+ console.log(chalk.yellow('\n🔍 Found BMad v3 installation (bmad-agent/ directory)'));
630
+ console.log(` Directory: ${installDir}`);
631
+
632
+ const { action } = await inquirer.prompt([
633
+ {
634
+ type: 'list',
635
+ name: 'action',
636
+ message: 'What would you like to do?',
637
+ choices: [
638
+ { name: 'Upgrade from v3 to v4 (recommended)', value: 'upgrade' },
639
+ { name: 'Install v4 alongside v3', value: 'alongside' },
640
+ { name: 'Cancel', value: 'cancel' },
641
+ ],
642
+ },
643
+ ]);
644
+
645
+ switch (action) {
646
+ case 'upgrade': {
647
+ console.log(chalk.cyan('\n📦 Starting v3 to v4 upgrade process...'));
648
+ const V3ToV4Upgrader = require('../../upgraders/v3-to-v4-upgrader');
649
+ const upgrader = new V3ToV4Upgrader();
650
+ return await upgrader.upgrade({
651
+ projectPath: installDir,
652
+ ides: config.ides || [], // Pass IDE selections from initial config
653
+ });
654
+ }
655
+ case 'alongside': {
656
+ return await this.performFreshInstall(config, installDir, spinner);
657
+ }
658
+ case 'cancel': {
659
+ console.log('Installation cancelled.');
660
+ return;
661
+ }
662
+ }
663
+ }
664
+
665
+ async handleUnknownInstallation(config, installDir, state, spinner) {
666
+ spinner.stop();
667
+
668
+ console.log(chalk.yellow('\n⚠️ Directory contains existing files'));
669
+ console.log(` Directory: ${installDir}`);
670
+
671
+ if (state.hasBmadCore) {
672
+ console.log(' Found: .bmad-core directory (but no manifest)');
673
+ }
674
+ if (state.hasOtherFiles) {
675
+ console.log(' Found: Other files in directory');
676
+ }
677
+
678
+ const { action } = await inquirer.prompt([
679
+ {
680
+ type: 'list',
681
+ name: 'action',
682
+ message: 'What would you like to do?',
683
+ choices: [
684
+ { name: 'Install anyway (may overwrite files)', value: 'force' },
685
+ { name: 'Choose different directory', value: 'different' },
686
+ { name: 'Cancel', value: 'cancel' },
687
+ ],
688
+ },
689
+ ]);
690
+
691
+ switch (action) {
692
+ case 'force': {
693
+ return await this.performFreshInstall(config, installDir, spinner);
694
+ }
695
+ case 'different': {
696
+ const { newDir } = await inquirer.prompt([
697
+ {
698
+ type: 'input',
699
+ name: 'newDir',
700
+ message: 'Enter new installation directory:',
701
+ default: path.join(path.dirname(installDir), 'bmad-project'),
702
+ },
703
+ ]);
704
+ config.directory = newDir;
705
+ return await this.install(config);
706
+ }
707
+ case 'cancel': {
708
+ console.log('Installation cancelled.');
709
+ return;
710
+ }
711
+ }
712
+ }
713
+
714
+ async performUpdate(newConfig, installDir, manifest, spinner) {
715
+ spinner.start('Checking for updates...');
716
+
717
+ try {
718
+ // Get current and new versions
719
+ const currentVersion = manifest.version;
720
+ const newVersion = await this.getCoreVersion();
721
+ const versionCompare = this.compareVersions(currentVersion, newVersion);
722
+
723
+ // Only check for modified files if it's an actual version upgrade
724
+ let modifiedFiles = [];
725
+ if (versionCompare !== 0) {
726
+ spinner.text = 'Checking for modified files...';
727
+ modifiedFiles = await fileManager.checkModifiedFiles(installDir, manifest);
728
+ }
729
+
730
+ if (modifiedFiles.length > 0) {
731
+ spinner.warn('Found modified files');
732
+ console.log(chalk.yellow('\nThe following files have been modified:'));
733
+ for (const file of modifiedFiles) {
734
+ console.log(` - ${file}`);
735
+ }
736
+
737
+ const { action } = await inquirer.prompt([
738
+ {
739
+ type: 'list',
740
+ name: 'action',
741
+ message: 'How would you like to proceed?',
742
+ choices: [
743
+ { name: 'Backup and overwrite modified files', value: 'backup' },
744
+ { name: 'Skip modified files', value: 'skip' },
745
+ { name: 'Cancel update', value: 'cancel' },
746
+ ],
747
+ },
748
+ ]);
749
+
750
+ if (action === 'cancel') {
751
+ console.log('Update cancelled.');
752
+ return;
753
+ }
754
+
755
+ if (action === 'backup') {
756
+ spinner.start('Backing up modified files...');
757
+ for (const file of modifiedFiles) {
758
+ const filePath = path.join(installDir, file);
759
+ const backupPath = await fileManager.backupFile(filePath);
760
+ console.log(chalk.dim(` Backed up: ${file} → ${path.basename(backupPath)}`));
761
+ }
762
+ }
763
+ }
764
+
765
+ // Perform update by re-running installation
766
+ spinner.text = versionCompare === 0 ? 'Reinstalling files...' : 'Updating files...';
767
+ const config = {
768
+ installType: manifest.install_type,
769
+ agent: manifest.agent,
770
+ directory: installDir,
771
+ ides: newConfig?.ides || manifest.ides_setup || [],
772
+ };
773
+
774
+ await this.performFreshInstall(config, installDir, spinner, { isUpdate: true });
775
+
776
+ // Clean up .yml files that now have .yaml counterparts
777
+ spinner.text = 'Cleaning up legacy .yml files...';
778
+ await this.cleanupLegacyYmlFiles(installDir, spinner);
779
+ } catch (error) {
780
+ spinner.fail('Update failed');
781
+ throw error;
782
+ }
783
+ }
784
+
785
+ async performRepair(config, installDir, manifest, integrity, spinner) {
786
+ spinner.start('Preparing to repair installation...');
787
+
788
+ try {
789
+ // Back up modified files
790
+ if (integrity.modified.length > 0) {
791
+ spinner.text = 'Backing up modified files...';
792
+ for (const file of integrity.modified) {
793
+ const filePath = path.join(installDir, file);
794
+ if (await fileManager.pathExists(filePath)) {
795
+ const backupPath = await fileManager.backupFile(filePath);
796
+ console.log(chalk.dim(` Backed up: ${file} → ${path.basename(backupPath)}`));
797
+ }
798
+ }
799
+ }
800
+
801
+ // Restore missing and modified files
802
+ spinner.text = 'Restoring files...';
803
+ const sourceBase = resourceLocator.getBmadCorePath();
804
+ const filesToRestore = [...integrity.missing, ...integrity.modified];
805
+
806
+ for (const file of filesToRestore) {
807
+ // Skip the manifest file itself
808
+ if (file.endsWith('install-manifest.yaml')) continue;
809
+
810
+ const relativePath = file.replace('.bmad-core/', '');
811
+ const destinationPath = path.join(installDir, file);
812
+
813
+ // Check if this is a common/ file that needs special processing
814
+ const commonBase = path.dirname(path.dirname(path.dirname(path.dirname(__filename))));
815
+ const commonSourcePath = path.join(commonBase, 'common', relativePath);
816
+
817
+ if (await fileManager.pathExists(commonSourcePath)) {
818
+ // This is a common/ file - needs template processing
819
+ const fs = require('node:fs').promises;
820
+ const content = await fs.readFile(commonSourcePath, 'utf8');
821
+ const updatedContent = content.replaceAll('{root}', '.bmad-core');
822
+ await fileManager.ensureDirectory(path.dirname(destinationPath));
823
+ await fs.writeFile(destinationPath, updatedContent, 'utf8');
824
+ spinner.text = `Restored: ${file}`;
825
+ } else {
826
+ // Regular file from bmad-core
827
+ const sourcePath = path.join(sourceBase, relativePath);
828
+ if (await fileManager.pathExists(sourcePath)) {
829
+ await fileManager.copyFile(sourcePath, destinationPath);
830
+ spinner.text = `Restored: ${file}`;
831
+
832
+ // If this is a .yaml file, check for and remove corresponding .yml file
833
+ if (file.endsWith('.yaml')) {
834
+ const ymlFile = file.replace(/\.yaml$/, '.yml');
835
+ const ymlPath = path.join(installDir, ymlFile);
836
+ if (await fileManager.pathExists(ymlPath)) {
837
+ const fs = require('node:fs').promises;
838
+ await fs.unlink(ymlPath);
839
+ console.log(chalk.dim(` Removed legacy: ${ymlFile} (replaced by ${file})`));
840
+ }
841
+ }
842
+ } else {
843
+ console.warn(chalk.yellow(` Warning: Source file not found: ${file}`));
844
+ }
845
+ }
846
+ }
847
+
848
+ // Clean up .yml files that now have .yaml counterparts
849
+ spinner.text = 'Cleaning up legacy .yml files...';
850
+ await this.cleanupLegacyYmlFiles(installDir, spinner);
851
+
852
+ spinner.succeed('Repair completed successfully!');
853
+
854
+ // Show summary
855
+ console.log(chalk.green('\n✓ Installation repaired!'));
856
+ if (integrity.missing.length > 0) {
857
+ console.log(chalk.green(` Restored ${integrity.missing.length} missing files`));
858
+ }
859
+ if (integrity.modified.length > 0) {
860
+ console.log(
861
+ chalk.green(` Restored ${integrity.modified.length} modified files (backups created)`),
862
+ );
863
+ }
864
+
865
+ // Warning for Cursor custom modes if agents were repaired
866
+ const ides = manifest.ides_setup || [];
867
+ if (ides.includes('cursor')) {
868
+ console.log(chalk.yellow.bold('\n⚠️ IMPORTANT: Cursor Custom Modes Update Required'));
869
+ console.log(
870
+ chalk.yellow(
871
+ 'Since agent files have been repaired, you need to update any custom agent modes configured in the Cursor custom agent GUI per the Cursor docs.',
872
+ ),
873
+ );
874
+ }
875
+ } catch (error) {
876
+ spinner.fail('Repair failed');
877
+ throw error;
878
+ }
879
+ }
880
+
881
+ async performReinstall(config, installDir, spinner) {
882
+ spinner.start('Preparing to reinstall BMad Method...');
883
+
884
+ // Remove existing .bmad-core
885
+ const bmadCorePath = path.join(installDir, '.bmad-core');
886
+ if (await fileManager.pathExists(bmadCorePath)) {
887
+ spinner.text = 'Removing existing installation...';
888
+ await fileManager.removeDirectory(bmadCorePath);
889
+ }
890
+
891
+ spinner.text = 'Installing fresh copy...';
892
+ const result = await this.performFreshInstall(config, installDir, spinner, { isUpdate: true });
893
+
894
+ // Clean up .yml files that now have .yaml counterparts
895
+ spinner.text = 'Cleaning up legacy .yml files...';
896
+ await this.cleanupLegacyYmlFiles(installDir, spinner);
897
+
898
+ return result;
899
+ }
900
+
901
+ showSuccessMessage(config, installDir, options = {}) {
902
+ console.log(chalk.green('\n✓ BMad Method installed successfully!\n'));
903
+
904
+ const ides = config.ides || (config.ide ? [config.ide] : []);
905
+ if (ides.length > 0) {
906
+ for (const ide of ides) {
907
+ const ideConfig = configLoader.getIdeConfiguration(ide);
908
+ if (ideConfig?.instructions) {
909
+ console.log(chalk.bold(`To use BMad agents in ${ideConfig.name}:`));
910
+ console.log(ideConfig.instructions);
911
+ }
912
+ }
913
+ } else {
914
+ console.log(chalk.yellow('No IDE configuration was set up.'));
915
+ console.log('You can manually configure your IDE using the agent files in:', installDir);
916
+ }
917
+
918
+ // Information about installation components
919
+ console.log(chalk.bold('\n🎯 Installation Summary:'));
920
+ if (config.installType !== 'expansion-only') {
921
+ console.log(chalk.green('✓ .bmad-core framework installed with all agents and workflows'));
922
+ }
923
+
924
+ if (config.expansionPacks && config.expansionPacks.length > 0) {
925
+ console.log(chalk.green(`✓ Expansion packs installed:`));
926
+ for (const packId of config.expansionPacks) {
927
+ console.log(chalk.green(` - ${packId} → .${packId}/`));
928
+ }
929
+ }
930
+
931
+ if (config.includeWebBundles && config.webBundlesDirectory) {
932
+ const bundleInfo = this.getWebBundleInfo(config);
933
+ // Resolve the web bundles directory for display
934
+ const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd();
935
+ const resolvedWebBundlesDir = path.isAbsolute(config.webBundlesDirectory)
936
+ ? config.webBundlesDirectory
937
+ : path.resolve(originalCwd, config.webBundlesDirectory);
938
+ console.log(
939
+ chalk.green(`✓ Web bundles (${bundleInfo}) installed to: ${resolvedWebBundlesDir}`),
940
+ );
941
+ }
942
+
943
+ if (ides.length > 0) {
944
+ const ideNames = ides
945
+ .map((ide) => {
946
+ const ideConfig = configLoader.getIdeConfiguration(ide);
947
+ return ideConfig?.name || ide;
948
+ })
949
+ .join(', ');
950
+ console.log(chalk.green(`✓ IDE rules and configurations set up for: ${ideNames}`));
951
+ }
952
+
953
+ // Information about web bundles
954
+ if (!config.includeWebBundles) {
955
+ console.log(chalk.bold('\n📦 Web Bundles Available:'));
956
+ console.log('Pre-built web bundles are available and can be added later:');
957
+ console.log(chalk.cyan(' Run the installer again to add them to your project'));
958
+ console.log('These bundles work independently and can be shared, moved, or used');
959
+ console.log('in other projects as standalone files.');
960
+ }
961
+
962
+ if (config.installType === 'single-agent') {
963
+ console.log(chalk.dim('\nNeed other agents? Run: npx bmad-method install --agent=<name>'));
964
+ console.log(chalk.dim('Need everything? Run: npx bmad-method install --full'));
965
+ }
966
+
967
+ // Warning for Cursor custom modes if agents were updated
968
+ if (options.isUpdate && ides.includes('cursor')) {
969
+ console.log(chalk.yellow.bold('\n⚠️ IMPORTANT: Cursor Custom Modes Update Required'));
970
+ console.log(
971
+ chalk.yellow(
972
+ 'Since agents have been updated, you need to update any custom agent modes configured in the Cursor custom agent GUI per the Cursor docs.',
973
+ ),
974
+ );
975
+ }
976
+
977
+ // Important notice to read the user guide
978
+ console.log(
979
+ chalk.red.bold('\n📖 IMPORTANT: Please read the user guide at .bmad-core/stella-user-guide'),
980
+ );
981
+ console.log(
982
+ chalk.red(
983
+ 'This guide contains essential information about the BMad-Stella workflow and how to use the agents effectively.',
984
+ ),
985
+ );
986
+ }
987
+
988
+ // Legacy method for backward compatibility
989
+ async update() {
990
+ console.log(chalk.yellow('The "update" command is deprecated.'));
991
+ console.log(
992
+ 'Please use "install" instead - it will detect and offer to update existing installations.',
993
+ );
994
+
995
+ const installDir = await this.findInstallation();
996
+ if (installDir) {
997
+ const config = {
998
+ installType: 'full',
999
+ directory: path.dirname(installDir),
1000
+ ide: null,
1001
+ };
1002
+ return await this.install(config);
1003
+ }
1004
+ console.log(chalk.red('No BMad installation found.'));
1005
+ }
1006
+
1007
+ async listAgents() {
1008
+ const agents = await resourceLocator.getAvailableAgents();
1009
+
1010
+ console.log(chalk.bold('\nAvailable BMad Agents:\n'));
1011
+
1012
+ for (const agent of agents) {
1013
+ console.log(chalk.cyan(` ${agent.id.padEnd(20)}`), agent.description);
1014
+ }
1015
+
1016
+ console.log(chalk.dim('\nInstall with: npx bmad-method install --agent=<id>\n'));
1017
+ }
1018
+
1019
+ async listExpansionPacks() {
1020
+ const expansionPacks = await resourceLocator.getExpansionPacks();
1021
+
1022
+ console.log(chalk.bold('\nAvailable BMad Expansion Packs:\n'));
1023
+
1024
+ if (expansionPacks.length === 0) {
1025
+ console.log(chalk.yellow('No expansion packs found.'));
1026
+ return;
1027
+ }
1028
+
1029
+ for (const pack of expansionPacks) {
1030
+ console.log(chalk.cyan(` ${pack.id.padEnd(20)}`), `${pack.name} v${pack.version}`);
1031
+ console.log(chalk.dim(` ${' '.repeat(22)}${pack.description}`));
1032
+ if (pack.author && pack.author !== 'Unknown') {
1033
+ console.log(chalk.dim(` ${' '.repeat(22)}by ${pack.author}`));
1034
+ }
1035
+ console.log();
1036
+ }
1037
+
1038
+ console.log(chalk.dim('Install with: npx bmad-method install --full --expansion-packs <id>\n'));
1039
+ }
1040
+
1041
+ async showStatus() {
1042
+ const installDir = await this.findInstallation();
1043
+
1044
+ if (!installDir) {
1045
+ console.log(chalk.yellow('No BMad installation found in current directory tree'));
1046
+ return;
1047
+ }
1048
+
1049
+ const manifest = await fileManager.readManifest(installDir);
1050
+
1051
+ if (!manifest) {
1052
+ console.log(chalk.red('Invalid installation - manifest not found'));
1053
+ return;
1054
+ }
1055
+
1056
+ console.log(chalk.bold('\nBMad Installation Status:\n'));
1057
+ console.log(` Directory: ${installDir}`);
1058
+ console.log(` Version: ${manifest.version}`);
1059
+ console.log(` Installed: ${new Date(manifest.installed_at).toLocaleDateString()}`);
1060
+ console.log(` Type: ${manifest.install_type}`);
1061
+
1062
+ if (manifest.agent) {
1063
+ console.log(` Agent: ${manifest.agent}`);
1064
+ }
1065
+
1066
+ if (manifest.ides_setup && manifest.ides_setup.length > 0) {
1067
+ console.log(` IDE Setup: ${manifest.ides_setup.join(', ')}`);
1068
+ }
1069
+
1070
+ console.log(` Total Files: ${manifest.files.length}`);
1071
+
1072
+ // Check for modifications
1073
+ const modifiedFiles = await fileManager.checkModifiedFiles(installDir, manifest);
1074
+ if (modifiedFiles.length > 0) {
1075
+ console.log(chalk.yellow(` Modified Files: ${modifiedFiles.length}`));
1076
+ }
1077
+
1078
+ console.log('');
1079
+ }
1080
+
1081
+ async getAvailableAgents() {
1082
+ return resourceLocator.getAvailableAgents();
1083
+ }
1084
+
1085
+ async getAvailableExpansionPacks() {
1086
+ return resourceLocator.getExpansionPacks();
1087
+ }
1088
+
1089
+ async getAvailableTeams() {
1090
+ return configLoader.getAvailableTeams();
1091
+ }
1092
+
1093
+ async installExpansionPacks(installDir, selectedPacks, spinner, config = {}) {
1094
+ if (!selectedPacks || selectedPacks.length === 0) {
1095
+ return [];
1096
+ }
1097
+
1098
+ const installedFiles = [];
1099
+
1100
+ for (const packId of selectedPacks) {
1101
+ spinner.text = `Installing expansion pack: ${packId}...`;
1102
+
1103
+ try {
1104
+ const expansionPacks = await resourceLocator.getExpansionPacks();
1105
+ const pack = expansionPacks.find((p) => p.id === packId);
1106
+
1107
+ if (!pack) {
1108
+ console.warn(`Expansion pack ${packId} not found, skipping...`);
1109
+ continue;
1110
+ }
1111
+
1112
+ // Check if expansion pack already exists
1113
+ let expansionDotFolder = path.join(installDir, `.${packId}`);
1114
+ const existingManifestPath = path.join(expansionDotFolder, 'install-manifest.yaml');
1115
+
1116
+ if (await fileManager.pathExists(existingManifestPath)) {
1117
+ spinner.stop();
1118
+ const existingManifest = await fileManager.readExpansionPackManifest(installDir, packId);
1119
+
1120
+ console.log(chalk.yellow(`\n🔍 Found existing ${pack.name} installation`));
1121
+ console.log(` Current version: ${existingManifest.version || 'unknown'}`);
1122
+ console.log(` New version: ${pack.version}`);
1123
+
1124
+ // Check integrity of existing expansion pack
1125
+ const packIntegrity = await fileManager.checkFileIntegrity(installDir, existingManifest);
1126
+ const hasPackIntegrityIssues =
1127
+ packIntegrity.missing.length > 0 || packIntegrity.modified.length > 0;
1128
+
1129
+ if (hasPackIntegrityIssues) {
1130
+ console.log(chalk.red(' ⚠️ Installation issues detected:'));
1131
+ if (packIntegrity.missing.length > 0) {
1132
+ console.log(chalk.red(` Missing files: ${packIntegrity.missing.length}`));
1133
+ }
1134
+ if (packIntegrity.modified.length > 0) {
1135
+ console.log(chalk.yellow(` Modified files: ${packIntegrity.modified.length}`));
1136
+ }
1137
+ }
1138
+
1139
+ const versionCompare = this.compareVersions(
1140
+ existingManifest.version || '0.0.0',
1141
+ pack.version,
1142
+ );
1143
+
1144
+ if (versionCompare === 0) {
1145
+ console.log(chalk.yellow(' ⚠️ Same version already installed'));
1146
+
1147
+ const choices = [];
1148
+ if (hasPackIntegrityIssues) {
1149
+ choices.push({ name: 'Repair (restore missing/modified files)', value: 'repair' });
1150
+ }
1151
+ choices.push(
1152
+ { name: 'Force reinstall (overwrite)', value: 'overwrite' },
1153
+ { name: 'Skip this expansion pack', value: 'skip' },
1154
+ { name: 'Cancel installation', value: 'cancel' },
1155
+ );
1156
+
1157
+ const { action } = await inquirer.prompt([
1158
+ {
1159
+ type: 'list',
1160
+ name: 'action',
1161
+ message: `${pack.name} v${pack.version} is already installed. What would you like to do?`,
1162
+ choices: choices,
1163
+ },
1164
+ ]);
1165
+
1166
+ switch (action) {
1167
+ case 'skip': {
1168
+ spinner.start();
1169
+ continue;
1170
+
1171
+ break;
1172
+ }
1173
+ case 'cancel': {
1174
+ console.log('Installation cancelled.');
1175
+ process.exit(0);
1176
+
1177
+ break;
1178
+ }
1179
+ case 'repair': {
1180
+ // Repair the expansion pack
1181
+ await this.repairExpansionPack(installDir, packId, pack, packIntegrity, spinner);
1182
+ continue;
1183
+
1184
+ break;
1185
+ }
1186
+ // No default
1187
+ }
1188
+ } else if (versionCompare < 0) {
1189
+ console.log(chalk.cyan(' ⬆️ Upgrade available'));
1190
+
1191
+ const { proceed } = await inquirer.prompt([
1192
+ {
1193
+ type: 'confirm',
1194
+ name: 'proceed',
1195
+ message: `Upgrade ${pack.name} from v${existingManifest.version} to v${pack.version}?`,
1196
+ default: true,
1197
+ },
1198
+ ]);
1199
+
1200
+ if (!proceed) {
1201
+ spinner.start();
1202
+ continue;
1203
+ }
1204
+ } else {
1205
+ console.log(chalk.yellow(' ⬇️ Installed version is newer than available version'));
1206
+
1207
+ const { action } = await inquirer.prompt([
1208
+ {
1209
+ type: 'list',
1210
+ name: 'action',
1211
+ message: 'What would you like to do?',
1212
+ choices: [
1213
+ { name: 'Keep current version', value: 'skip' },
1214
+ { name: 'Downgrade to available version', value: 'downgrade' },
1215
+ { name: 'Cancel installation', value: 'cancel' },
1216
+ ],
1217
+ },
1218
+ ]);
1219
+
1220
+ if (action === 'skip') {
1221
+ spinner.start();
1222
+ continue;
1223
+ } else if (action === 'cancel') {
1224
+ console.log('Installation cancelled.');
1225
+ process.exit(0);
1226
+ }
1227
+ }
1228
+
1229
+ // If we get here, we're proceeding with installation
1230
+ spinner.start(`Removing old ${pack.name} installation...`);
1231
+ await fileManager.removeDirectory(expansionDotFolder);
1232
+ }
1233
+
1234
+ const expansionPackDir = pack.path;
1235
+
1236
+ // Ensure dedicated dot folder exists for this expansion pack
1237
+ expansionDotFolder = path.join(installDir, `.${packId}`);
1238
+ await fileManager.ensureDirectory(expansionDotFolder);
1239
+
1240
+ // Define the folders to copy from expansion packs
1241
+ const foldersToSync = [
1242
+ 'agents',
1243
+ 'agent-teams',
1244
+ 'templates',
1245
+ 'tasks',
1246
+ 'checklists',
1247
+ 'workflows',
1248
+ 'data',
1249
+ 'utils',
1250
+ 'schemas',
1251
+ ];
1252
+
1253
+ // Copy each folder if it exists
1254
+ for (const folder of foldersToSync) {
1255
+ const sourceFolder = path.join(expansionPackDir, folder);
1256
+
1257
+ // Check if folder exists in expansion pack
1258
+ if (await fileManager.pathExists(sourceFolder)) {
1259
+ // Get all files in this folder
1260
+ const files = await resourceLocator.findFiles('**/*', {
1261
+ cwd: sourceFolder,
1262
+ nodir: true,
1263
+ });
1264
+
1265
+ // Copy each file to the expansion pack's dot folder with {root} replacement
1266
+ for (const file of files) {
1267
+ const sourcePath = path.join(sourceFolder, file);
1268
+ const destinationPath = path.join(expansionDotFolder, folder, file);
1269
+
1270
+ const needsRootReplacement =
1271
+ file.endsWith('.md') || file.endsWith('.yaml') || file.endsWith('.yml');
1272
+ let success = false;
1273
+
1274
+ success = await (needsRootReplacement
1275
+ ? fileManager.copyFileWithRootReplacement(sourcePath, destinationPath, `.${packId}`)
1276
+ : fileManager.copyFile(sourcePath, destinationPath));
1277
+
1278
+ if (success) {
1279
+ installedFiles.push(path.join(`.${packId}`, folder, file));
1280
+ }
1281
+ }
1282
+ }
1283
+ }
1284
+
1285
+ // Copy config.yaml with {root} replacement
1286
+ const configPath = path.join(expansionPackDir, 'config.yaml');
1287
+ if (await fileManager.pathExists(configPath)) {
1288
+ const configDestinationPath = path.join(expansionDotFolder, 'config.yaml');
1289
+ if (
1290
+ await fileManager.copyFileWithRootReplacement(
1291
+ configPath,
1292
+ configDestinationPath,
1293
+ `.${packId}`,
1294
+ )
1295
+ ) {
1296
+ installedFiles.push(path.join(`.${packId}`, 'config.yaml'));
1297
+ }
1298
+ }
1299
+
1300
+ // Copy README if it exists with {root} replacement
1301
+ const readmePath = path.join(expansionPackDir, 'README.md');
1302
+ if (await fileManager.pathExists(readmePath)) {
1303
+ const readmeDestinationPath = path.join(expansionDotFolder, 'README.md');
1304
+ if (
1305
+ await fileManager.copyFileWithRootReplacement(
1306
+ readmePath,
1307
+ readmeDestinationPath,
1308
+ `.${packId}`,
1309
+ )
1310
+ ) {
1311
+ installedFiles.push(path.join(`.${packId}`, 'README.md'));
1312
+ }
1313
+ }
1314
+
1315
+ // Copy common/ items to expansion pack folder
1316
+ spinner.text = `Copying common utilities to ${packId}...`;
1317
+ await this.copyCommonItems(installDir, `.${packId}`, spinner);
1318
+
1319
+ // Check and resolve core dependencies
1320
+ await this.resolveExpansionPackCoreDependencies(
1321
+ installDir,
1322
+ expansionDotFolder,
1323
+ packId,
1324
+ pack,
1325
+ spinner,
1326
+ );
1327
+
1328
+ // Check and resolve core agents referenced by teams
1329
+ await this.resolveExpansionPackCoreAgents(installDir, expansionDotFolder, packId, spinner);
1330
+
1331
+ // Create manifest for this expansion pack
1332
+ spinner.text = `Creating manifest for ${packId}...`;
1333
+ const expansionConfig = {
1334
+ installType: 'expansion-pack',
1335
+ expansionPackId: packId,
1336
+ expansionPackName: pack.name,
1337
+ expansionPackVersion: pack.version,
1338
+ ides: config.ides || [], // Use ides_setup instead of ide_setup
1339
+ };
1340
+
1341
+ // Get all files installed in this expansion pack
1342
+ const foundFiles = await resourceLocator.findFiles('**/*', {
1343
+ cwd: expansionDotFolder,
1344
+ nodir: true,
1345
+ });
1346
+ const expansionPackFiles = foundFiles.map((f) => path.join(`.${packId}`, f));
1347
+
1348
+ await fileManager.createExpansionPackManifest(
1349
+ installDir,
1350
+ packId,
1351
+ expansionConfig,
1352
+ expansionPackFiles,
1353
+ );
1354
+
1355
+ console.log(chalk.green(`✓ Installed expansion pack: ${pack.name} to ${`.${packId}`}`));
1356
+ } catch (error) {
1357
+ console.error(`Failed to install expansion pack ${packId}: ${error.message}`);
1358
+ console.error(`Stack trace: ${error.stack}`);
1359
+ }
1360
+ }
1361
+
1362
+ return installedFiles;
1363
+ }
1364
+
1365
+ async resolveExpansionPackCoreDependencies(
1366
+ installDir,
1367
+ expansionDotFolder,
1368
+ packId,
1369
+ pack,
1370
+ spinner,
1371
+ ) {
1372
+ const yaml = require('js-yaml');
1373
+ const fs = require('node:fs').promises;
1374
+
1375
+ // Find all agent files in the expansion pack
1376
+ const agentFiles = await resourceLocator.findFiles('agents/*.md', {
1377
+ cwd: expansionDotFolder,
1378
+ });
1379
+
1380
+ for (const agentFile of agentFiles) {
1381
+ const agentPath = path.join(expansionDotFolder, agentFile);
1382
+ const agentContent = await fs.readFile(agentPath, 'utf8');
1383
+
1384
+ // Extract YAML frontmatter to check dependencies
1385
+ const yamlContent = extractYamlFromAgent(agentContent);
1386
+ if (yamlContent) {
1387
+ try {
1388
+ const agentConfig = yaml.load(yamlContent);
1389
+ const dependencies = agentConfig.dependencies || {};
1390
+
1391
+ // Check for core dependencies (those that don't exist in the expansion pack)
1392
+ for (const depType of [
1393
+ 'tasks',
1394
+ 'templates',
1395
+ 'checklists',
1396
+ 'workflows',
1397
+ 'utils',
1398
+ 'data',
1399
+ ]) {
1400
+ const deps = dependencies[depType] || [];
1401
+
1402
+ for (const dep of deps) {
1403
+ const depFileName =
1404
+ dep.endsWith('.md') || dep.endsWith('.yaml')
1405
+ ? dep
1406
+ : depType === 'templates'
1407
+ ? `${dep}.yaml`
1408
+ : `${dep}.md`;
1409
+ const expansionDepPath = path.join(expansionDotFolder, depType, depFileName);
1410
+
1411
+ // Check if dependency exists in expansion pack dot folder
1412
+ if (!(await fileManager.pathExists(expansionDepPath))) {
1413
+ // Try to find it in expansion pack source
1414
+ const sourceDepPath = path.join(pack.path, depType, depFileName);
1415
+
1416
+ if (await fileManager.pathExists(sourceDepPath)) {
1417
+ // Copy from expansion pack source
1418
+ spinner.text = `Copying ${packId} dependency ${dep}...`;
1419
+ const destinationPath = path.join(expansionDotFolder, depType, depFileName);
1420
+ await fileManager.copyFileWithRootReplacement(
1421
+ sourceDepPath,
1422
+ destinationPath,
1423
+ `.${packId}`,
1424
+ );
1425
+ console.log(chalk.dim(` Added ${packId} dependency: ${depType}/${depFileName}`));
1426
+ } else {
1427
+ // Try to find it in core
1428
+ const coreDepPath = path.join(
1429
+ resourceLocator.getBmadCorePath(),
1430
+ depType,
1431
+ depFileName,
1432
+ );
1433
+
1434
+ if (await fileManager.pathExists(coreDepPath)) {
1435
+ spinner.text = `Copying core dependency ${dep} for ${packId}...`;
1436
+
1437
+ // Copy from core to expansion pack dot folder with {root} replacement
1438
+ const destinationPath = path.join(expansionDotFolder, depType, depFileName);
1439
+ await fileManager.copyFileWithRootReplacement(
1440
+ coreDepPath,
1441
+ destinationPath,
1442
+ `.${packId}`,
1443
+ );
1444
+
1445
+ console.log(chalk.dim(` Added core dependency: ${depType}/${depFileName}`));
1446
+ } else {
1447
+ console.warn(
1448
+ chalk.yellow(
1449
+ ` Warning: Dependency ${depType}/${dep} not found in core or expansion pack`,
1450
+ ),
1451
+ );
1452
+ }
1453
+ }
1454
+ }
1455
+ }
1456
+ }
1457
+ } catch (error) {
1458
+ console.warn(` Warning: Could not parse agent dependencies: ${error.message}`);
1459
+ }
1460
+ }
1461
+ }
1462
+ }
1463
+
1464
+ async resolveExpansionPackCoreAgents(installDir, expansionDotFolder, packId, spinner) {
1465
+ const yaml = require('js-yaml');
1466
+ const fs = require('node:fs').promises;
1467
+
1468
+ // Find all team files in the expansion pack
1469
+ const teamFiles = await resourceLocator.findFiles('agent-teams/*.yaml', {
1470
+ cwd: expansionDotFolder,
1471
+ });
1472
+
1473
+ // Also get existing agents in the expansion pack
1474
+ const existingAgents = new Set();
1475
+ const agentFiles = await resourceLocator.findFiles('agents/*.md', {
1476
+ cwd: expansionDotFolder,
1477
+ });
1478
+ for (const agentFile of agentFiles) {
1479
+ const agentName = path.basename(agentFile, '.md');
1480
+ existingAgents.add(agentName);
1481
+ }
1482
+
1483
+ // Process each team file
1484
+ for (const teamFile of teamFiles) {
1485
+ const teamPath = path.join(expansionDotFolder, teamFile);
1486
+ const teamContent = await fs.readFile(teamPath, 'utf8');
1487
+
1488
+ try {
1489
+ const teamConfig = yaml.load(teamContent);
1490
+ const agents = teamConfig.agents || [];
1491
+
1492
+ // Add bmad-orchestrator if not present (required for all teams)
1493
+ if (!agents.includes('bmad-orchestrator')) {
1494
+ agents.unshift('bmad-orchestrator');
1495
+ }
1496
+
1497
+ // Check each agent in the team
1498
+ for (const agentId of agents) {
1499
+ if (!existingAgents.has(agentId)) {
1500
+ // Agent not in expansion pack, try to get from core
1501
+ const coreAgentPath = path.join(
1502
+ resourceLocator.getBmadCorePath(),
1503
+ 'agents',
1504
+ `${agentId}.md`,
1505
+ );
1506
+
1507
+ if (await fileManager.pathExists(coreAgentPath)) {
1508
+ spinner.text = `Copying core agent ${agentId} for ${packId}...`;
1509
+
1510
+ // Copy agent file with {root} replacement
1511
+ const destinationPath = path.join(expansionDotFolder, 'agents', `${agentId}.md`);
1512
+ await fileManager.copyFileWithRootReplacement(
1513
+ coreAgentPath,
1514
+ destinationPath,
1515
+ `.${packId}`,
1516
+ );
1517
+ existingAgents.add(agentId);
1518
+
1519
+ console.log(chalk.dim(` Added core agent: ${agentId}`));
1520
+
1521
+ // Now resolve this agent's dependencies too
1522
+ const agentContent = await fs.readFile(coreAgentPath, 'utf8');
1523
+ const yamlContent = extractYamlFromAgent(agentContent, true);
1524
+
1525
+ if (yamlContent) {
1526
+ try {
1527
+ const agentConfig = yaml.load(yamlContent);
1528
+ const dependencies = agentConfig.dependencies || {};
1529
+
1530
+ // Copy all dependencies for this agent
1531
+ for (const depType of [
1532
+ 'tasks',
1533
+ 'templates',
1534
+ 'checklists',
1535
+ 'workflows',
1536
+ 'utils',
1537
+ 'data',
1538
+ ]) {
1539
+ const deps = dependencies[depType] || [];
1540
+
1541
+ for (const dep of deps) {
1542
+ const depFileName =
1543
+ dep.endsWith('.md') || dep.endsWith('.yaml')
1544
+ ? dep
1545
+ : depType === 'templates'
1546
+ ? `${dep}.yaml`
1547
+ : `${dep}.md`;
1548
+ const expansionDepPath = path.join(expansionDotFolder, depType, depFileName);
1549
+
1550
+ // Check if dependency exists in expansion pack
1551
+ if (!(await fileManager.pathExists(expansionDepPath))) {
1552
+ // Try to find it in core
1553
+ const coreDepPath = path.join(
1554
+ resourceLocator.getBmadCorePath(),
1555
+ depType,
1556
+ depFileName,
1557
+ );
1558
+
1559
+ if (await fileManager.pathExists(coreDepPath)) {
1560
+ const destinationDepPath = path.join(
1561
+ expansionDotFolder,
1562
+ depType,
1563
+ depFileName,
1564
+ );
1565
+ await fileManager.copyFileWithRootReplacement(
1566
+ coreDepPath,
1567
+ destinationDepPath,
1568
+ `.${packId}`,
1569
+ );
1570
+ console.log(
1571
+ chalk.dim(` Added agent dependency: ${depType}/${depFileName}`),
1572
+ );
1573
+ } else {
1574
+ // Try common folder
1575
+ const sourceBase = path.dirname(
1576
+ path.dirname(path.dirname(path.dirname(__filename))),
1577
+ ); // Go up to project root
1578
+ const commonDepPath = path.join(
1579
+ sourceBase,
1580
+ 'common',
1581
+ depType,
1582
+ depFileName,
1583
+ );
1584
+ if (await fileManager.pathExists(commonDepPath)) {
1585
+ const destinationDepPath = path.join(
1586
+ expansionDotFolder,
1587
+ depType,
1588
+ depFileName,
1589
+ );
1590
+ await fileManager.copyFile(commonDepPath, destinationDepPath);
1591
+ console.log(
1592
+ chalk.dim(
1593
+ ` Added agent dependency from common: ${depType}/${depFileName}`,
1594
+ ),
1595
+ );
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+ }
1601
+ } catch (error) {
1602
+ console.warn(
1603
+ ` Warning: Could not parse agent ${agentId} dependencies: ${error.message}`,
1604
+ );
1605
+ }
1606
+ }
1607
+ } else {
1608
+ console.warn(
1609
+ chalk.yellow(
1610
+ ` Warning: Core agent ${agentId} not found for team ${path.basename(teamFile, '.yaml')}`,
1611
+ ),
1612
+ );
1613
+ }
1614
+ }
1615
+ }
1616
+ } catch (error) {
1617
+ console.warn(` Warning: Could not parse team file ${teamFile}: ${error.message}`);
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ getWebBundleInfo(config) {
1623
+ const webBundleType = config.webBundleType || 'all';
1624
+
1625
+ switch (webBundleType) {
1626
+ case 'all': {
1627
+ return 'all bundles';
1628
+ }
1629
+ case 'agents': {
1630
+ return 'individual agents only';
1631
+ }
1632
+ case 'teams': {
1633
+ return config.selectedWebBundleTeams
1634
+ ? `teams: ${config.selectedWebBundleTeams.join(', ')}`
1635
+ : 'selected teams';
1636
+ }
1637
+ case 'custom': {
1638
+ const parts = [];
1639
+ if (config.selectedWebBundleTeams && config.selectedWebBundleTeams.length > 0) {
1640
+ parts.push(`teams: ${config.selectedWebBundleTeams.join(', ')}`);
1641
+ }
1642
+ if (config.includeIndividualAgents) {
1643
+ parts.push('individual agents');
1644
+ }
1645
+ return parts.length > 0 ? parts.join(' + ') : 'custom selection';
1646
+ }
1647
+ default: {
1648
+ return 'selected bundles';
1649
+ }
1650
+ }
1651
+ }
1652
+
1653
+ async installWebBundles(webBundlesDirectory, config, spinner) {
1654
+ try {
1655
+ // Find the dist directory in the BMad installation
1656
+ const distDir = configLoader.getDistPath();
1657
+
1658
+ if (!(await fileManager.pathExists(distDir))) {
1659
+ console.warn('Web bundles not found. Run "npm run build" to generate them.');
1660
+ return;
1661
+ }
1662
+
1663
+ // Ensure web bundles directory exists
1664
+ await fileManager.ensureDirectory(webBundlesDirectory);
1665
+
1666
+ const webBundleType = config.webBundleType || 'all';
1667
+
1668
+ if (webBundleType === 'all') {
1669
+ // Copy the entire dist directory structure
1670
+ await fileManager.copyDirectory(distDir, webBundlesDirectory);
1671
+ console.log(chalk.green(`✓ Installed all web bundles to: ${webBundlesDirectory}`));
1672
+ } else {
1673
+ let copiedCount = 0;
1674
+
1675
+ // Copy specific selections based on type
1676
+ if (
1677
+ webBundleType === 'agents' ||
1678
+ (webBundleType === 'custom' && config.includeIndividualAgents)
1679
+ ) {
1680
+ const agentsSource = path.join(distDir, 'agents');
1681
+ const agentsTarget = path.join(webBundlesDirectory, 'agents');
1682
+ if (await fileManager.pathExists(agentsSource)) {
1683
+ await fileManager.copyDirectory(agentsSource, agentsTarget);
1684
+ console.log(chalk.green(`✓ Copied individual agent bundles`));
1685
+ copiedCount += 10; // Approximate count for agents
1686
+ }
1687
+ }
1688
+
1689
+ if (
1690
+ (webBundleType === 'teams' || webBundleType === 'custom') &&
1691
+ config.selectedWebBundleTeams &&
1692
+ config.selectedWebBundleTeams.length > 0
1693
+ ) {
1694
+ const teamsSource = path.join(distDir, 'teams');
1695
+ const teamsTarget = path.join(webBundlesDirectory, 'teams');
1696
+ await fileManager.ensureDirectory(teamsTarget);
1697
+
1698
+ for (const teamId of config.selectedWebBundleTeams) {
1699
+ const teamFile = `${teamId}.txt`;
1700
+ const sourcePath = path.join(teamsSource, teamFile);
1701
+ const targetPath = path.join(teamsTarget, teamFile);
1702
+
1703
+ if (await fileManager.pathExists(sourcePath)) {
1704
+ await fileManager.copyFile(sourcePath, targetPath);
1705
+ copiedCount++;
1706
+ console.log(chalk.green(`✓ Copied team bundle: ${teamId}`));
1707
+ }
1708
+ }
1709
+ }
1710
+
1711
+ // Always copy expansion packs if they exist
1712
+ const expansionSource = path.join(distDir, 'expansion-packs');
1713
+ const expansionTarget = path.join(webBundlesDirectory, 'expansion-packs');
1714
+ if (await fileManager.pathExists(expansionSource)) {
1715
+ await fileManager.copyDirectory(expansionSource, expansionTarget);
1716
+ console.log(chalk.green(`✓ Copied expansion pack bundles`));
1717
+ }
1718
+
1719
+ console.log(
1720
+ chalk.green(`✓ Installed ${copiedCount} selected web bundles to: ${webBundlesDirectory}`),
1721
+ );
1722
+ }
1723
+ } catch (error) {
1724
+ console.error(`Failed to install web bundles: ${error.message}`);
1725
+ }
1726
+ }
1727
+
1728
+ async copyCommonItems(installDir, targetSubdir, spinner) {
1729
+ const fs = require('node:fs').promises;
1730
+ const sourceBase = path.dirname(path.dirname(path.dirname(path.dirname(__filename)))); // Go up to project root
1731
+ const commonPath = path.join(sourceBase, 'common');
1732
+ const targetPath = path.join(installDir, targetSubdir);
1733
+ const copiedFiles = [];
1734
+
1735
+ // Check if common/ exists
1736
+ if (!(await fileManager.pathExists(commonPath))) {
1737
+ console.warn('Warning: common/ folder not found');
1738
+ return copiedFiles;
1739
+ }
1740
+
1741
+ // Copy all items from common/ to target
1742
+ const commonItems = await resourceLocator.findFiles('**/*', {
1743
+ cwd: commonPath,
1744
+ nodir: true,
1745
+ });
1746
+
1747
+ for (const item of commonItems) {
1748
+ const sourcePath = path.join(commonPath, item);
1749
+ const destinationPath = path.join(targetPath, item);
1750
+
1751
+ // Read the file content
1752
+ const content = await fs.readFile(sourcePath, 'utf8');
1753
+
1754
+ // Replace {root} with the target subdirectory
1755
+ const updatedContent = content.replaceAll('{root}', targetSubdir);
1756
+
1757
+ // Ensure directory exists
1758
+ await fileManager.ensureDirectory(path.dirname(destinationPath));
1759
+
1760
+ // Write the updated content
1761
+ await fs.writeFile(destinationPath, updatedContent, 'utf8');
1762
+ copiedFiles.push(path.join(targetSubdir, item));
1763
+ }
1764
+
1765
+ console.log(chalk.dim(` Added ${commonItems.length} common utilities`));
1766
+ return copiedFiles;
1767
+ }
1768
+
1769
+ async copyDocsItems(installDir, targetSubdir, spinner) {
1770
+ const fs = require('node:fs').promises;
1771
+ const sourceBase = path.dirname(path.dirname(path.dirname(path.dirname(__filename)))); // Go up to project root
1772
+ const docsPath = path.join(sourceBase, 'docs');
1773
+ const targetPath = path.join(installDir, targetSubdir);
1774
+ const copiedFiles = [];
1775
+
1776
+ // Specific documentation files to copy
1777
+ const documentFiles = [
1778
+ 'enhanced-ide-development-workflow.md',
1779
+ 'stella-user-guide.md',
1780
+ 'working-in-the-brownfield.md',
1781
+ ];
1782
+
1783
+ // Check if docs/ exists
1784
+ if (!(await fileManager.pathExists(docsPath))) {
1785
+ console.warn('Warning: docs/ folder not found');
1786
+ return copiedFiles;
1787
+ }
1788
+
1789
+ // Copy specific documentation files from docs/ to target
1790
+ for (const documentFile of documentFiles) {
1791
+ const sourcePath = path.join(docsPath, documentFile);
1792
+ const destinationPath = path.join(targetPath, documentFile);
1793
+
1794
+ // Check if the source file exists
1795
+ if (await fileManager.pathExists(sourcePath)) {
1796
+ // Read the file content
1797
+ const content = await fs.readFile(sourcePath, 'utf8');
1798
+
1799
+ // Replace {root} with the target subdirectory
1800
+ const updatedContent = content.replaceAll('{root}', targetSubdir);
1801
+
1802
+ // Ensure directory exists
1803
+ await fileManager.ensureDirectory(path.dirname(destinationPath));
1804
+
1805
+ // Write the updated content
1806
+ await fs.writeFile(destinationPath, updatedContent, 'utf8');
1807
+ copiedFiles.push(path.join(targetSubdir, documentFile));
1808
+ }
1809
+ }
1810
+
1811
+ if (copiedFiles.length > 0) {
1812
+ console.log(chalk.dim(` Added ${copiedFiles.length} documentation files`));
1813
+ }
1814
+ return copiedFiles;
1815
+ }
1816
+
1817
+ async detectExpansionPacks(installDir) {
1818
+ const expansionPacks = {};
1819
+ const glob = require('glob');
1820
+
1821
+ // Find all dot folders that might be expansion packs
1822
+ const dotFolders = glob.sync('.*', {
1823
+ cwd: installDir,
1824
+ ignore: ['.git', '.git/**', '.bmad-core', '.bmad-core/**'],
1825
+ });
1826
+
1827
+ for (const folder of dotFolders) {
1828
+ const folderPath = path.join(installDir, folder);
1829
+ const stats = await fileManager.pathExists(folderPath);
1830
+
1831
+ if (stats) {
1832
+ // Check if it has a manifest
1833
+ const manifestPath = path.join(folderPath, 'install-manifest.yaml');
1834
+ if (await fileManager.pathExists(manifestPath)) {
1835
+ const manifest = await fileManager.readExpansionPackManifest(installDir, folder.slice(1));
1836
+ if (manifest) {
1837
+ expansionPacks[folder.slice(1)] = {
1838
+ path: folderPath,
1839
+ manifest: manifest,
1840
+ hasManifest: true,
1841
+ };
1842
+ }
1843
+ } else {
1844
+ // Check if it has a config.yaml (expansion pack without manifest)
1845
+ const configPath = path.join(folderPath, 'config.yaml');
1846
+ if (await fileManager.pathExists(configPath)) {
1847
+ expansionPacks[folder.slice(1)] = {
1848
+ path: folderPath,
1849
+ manifest: null,
1850
+ hasManifest: false,
1851
+ };
1852
+ }
1853
+ }
1854
+ }
1855
+ }
1856
+
1857
+ return expansionPacks;
1858
+ }
1859
+
1860
+ async repairExpansionPack(installDir, packId, pack, integrity, spinner) {
1861
+ spinner.start(`Repairing ${pack.name}...`);
1862
+
1863
+ try {
1864
+ const expansionDotFolder = path.join(installDir, `.${packId}`);
1865
+
1866
+ // Back up modified files
1867
+ if (integrity.modified.length > 0) {
1868
+ spinner.text = 'Backing up modified files...';
1869
+ for (const file of integrity.modified) {
1870
+ const filePath = path.join(installDir, file);
1871
+ if (await fileManager.pathExists(filePath)) {
1872
+ const backupPath = await fileManager.backupFile(filePath);
1873
+ console.log(chalk.dim(` Backed up: ${file} → ${path.basename(backupPath)}`));
1874
+ }
1875
+ }
1876
+ }
1877
+
1878
+ // Restore missing and modified files
1879
+ spinner.text = 'Restoring files...';
1880
+ const filesToRestore = [...integrity.missing, ...integrity.modified];
1881
+
1882
+ for (const file of filesToRestore) {
1883
+ // Skip the manifest file itself
1884
+ if (file.endsWith('install-manifest.yaml')) continue;
1885
+
1886
+ const relativePath = file.replace(`.${packId}/`, '');
1887
+ const sourcePath = path.join(pack.path, relativePath);
1888
+ const destinationPath = path.join(installDir, file);
1889
+
1890
+ // Check if this is a common/ file that needs special processing
1891
+ const commonBase = path.dirname(path.dirname(path.dirname(path.dirname(__filename))));
1892
+ const commonSourcePath = path.join(commonBase, 'common', relativePath);
1893
+
1894
+ if (await fileManager.pathExists(commonSourcePath)) {
1895
+ // This is a common/ file - needs template processing
1896
+ const fs = require('node:fs').promises;
1897
+ const content = await fs.readFile(commonSourcePath, 'utf8');
1898
+ const updatedContent = content.replaceAll('{root}', `.${packId}`);
1899
+ await fileManager.ensureDirectory(path.dirname(destinationPath));
1900
+ await fs.writeFile(destinationPath, updatedContent, 'utf8');
1901
+ spinner.text = `Restored: ${file}`;
1902
+ } else if (await fileManager.pathExists(sourcePath)) {
1903
+ // Regular file from expansion pack
1904
+ await fileManager.copyFile(sourcePath, destinationPath);
1905
+ spinner.text = `Restored: ${file}`;
1906
+ } else {
1907
+ console.warn(chalk.yellow(` Warning: Source file not found: ${file}`));
1908
+ }
1909
+ }
1910
+
1911
+ spinner.succeed(`${pack.name} repaired successfully!`);
1912
+
1913
+ // Show summary
1914
+ console.log(chalk.green(`\n✓ ${pack.name} repaired!`));
1915
+ if (integrity.missing.length > 0) {
1916
+ console.log(chalk.green(` Restored ${integrity.missing.length} missing files`));
1917
+ }
1918
+ if (integrity.modified.length > 0) {
1919
+ console.log(
1920
+ chalk.green(` Restored ${integrity.modified.length} modified files (backups created)`),
1921
+ );
1922
+ }
1923
+ } catch (error) {
1924
+ if (spinner) spinner.fail(`Failed to repair ${pack.name}`);
1925
+ console.error(`Error: ${error.message}`);
1926
+ }
1927
+ }
1928
+
1929
+ compareVersions(v1, v2) {
1930
+ // Simple semver comparison
1931
+ const parts1 = v1.split('.').map(Number);
1932
+ const parts2 = v2.split('.').map(Number);
1933
+
1934
+ for (let index = 0; index < 3; index++) {
1935
+ const part1 = parts1[index] || 0;
1936
+ const part2 = parts2[index] || 0;
1937
+
1938
+ if (part1 > part2) return 1;
1939
+ if (part1 < part2) return -1;
1940
+ }
1941
+
1942
+ return 0;
1943
+ }
1944
+
1945
+ async cleanupLegacyYmlFiles(installDir, spinner) {
1946
+ const glob = require('glob');
1947
+ const fs = require('node:fs').promises;
1948
+
1949
+ try {
1950
+ // Find all .yml files in the installation directory
1951
+ const ymlFiles = glob.sync('**/*.yml', {
1952
+ cwd: installDir,
1953
+ ignore: ['**/node_modules/**', '**/.git/**'],
1954
+ });
1955
+
1956
+ let deletedCount = 0;
1957
+
1958
+ for (const ymlFile of ymlFiles) {
1959
+ // Check if corresponding .yaml file exists
1960
+ const yamlFile = ymlFile.replace(/\.yml$/, '.yaml');
1961
+ const ymlPath = path.join(installDir, ymlFile);
1962
+ const yamlPath = path.join(installDir, yamlFile);
1963
+
1964
+ if (await fileManager.pathExists(yamlPath)) {
1965
+ // .yaml counterpart exists, delete the .yml file
1966
+ await fs.unlink(ymlPath);
1967
+ deletedCount++;
1968
+ console.log(chalk.dim(` Removed legacy: ${ymlFile} (replaced by ${yamlFile})`));
1969
+ }
1970
+ }
1971
+
1972
+ if (deletedCount > 0) {
1973
+ console.log(chalk.green(`✓ Cleaned up ${deletedCount} legacy .yml files`));
1974
+ }
1975
+ } catch (error) {
1976
+ console.warn(`Warning: Could not cleanup legacy .yml files: ${error.message}`);
1977
+ }
1978
+ }
1979
+
1980
+ async updateGitignore(installDir) {
1981
+ try {
1982
+ const gitignorePath = path.join(installDir, '.gitignore');
1983
+ const bmadIgnoreEntries = ['bmad-docs/', '.claude/', '.bmad-core/'];
1984
+
1985
+ // Check if .gitignore exists
1986
+ const exists = await fileManager.pathExists(gitignorePath);
1987
+
1988
+ let content = '';
1989
+ if (exists) {
1990
+ content = await fileManager.readFile(gitignorePath);
1991
+ }
1992
+
1993
+ // Parse .gitignore line by line to find existing patterns
1994
+ const lines = content.split('\n');
1995
+ const existingPatterns = new Set();
1996
+
1997
+ for (const line of lines) {
1998
+ const trimmed = line.trim();
1999
+ // Skip empty lines and comments
2000
+ if (trimmed && !trimmed.startsWith('#')) {
2001
+ existingPatterns.add(trimmed);
2002
+ }
2003
+ }
2004
+
2005
+ // Check which entries are missing
2006
+ const missingEntries = bmadIgnoreEntries.filter((entry) => {
2007
+ // Check exact match and without trailing slash
2008
+ const withoutSlash = entry.endsWith('/') ? entry.slice(0, -1) : entry;
2009
+ const withSlash = entry.endsWith('/') ? entry : entry + '/';
2010
+
2011
+ // Pattern exists if we find exact match, with slash, without slash, or with wildcards
2012
+ return (
2013
+ !existingPatterns.has(entry) &&
2014
+ !existingPatterns.has(withoutSlash) &&
2015
+ !existingPatterns.has(withSlash) &&
2016
+ !existingPatterns.has(`/${entry}`) && // root-only pattern
2017
+ !existingPatterns.has(`**/${entry}`) && // any depth pattern
2018
+ !existingPatterns.has(`${withoutSlash}/*`)
2019
+ ); // contents pattern
2020
+ });
2021
+
2022
+ if (missingEntries.length > 0) {
2023
+ // Check if BMad header already exists
2024
+ const hasBmadHeader = lines.some((line) => {
2025
+ const trimmed = line.trim();
2026
+ return trimmed === '# BMad directories' || trimmed === '# BMad';
2027
+ });
2028
+
2029
+ // Build new content
2030
+ const separator = content.length > 0 && !content.endsWith('\n') ? '\n' : '';
2031
+ const header = hasBmadHeader ? '' : '\n# BMad directories\n';
2032
+ const newContent = content + separator + header + missingEntries.join('\n') + '\n';
2033
+
2034
+ await fileManager.writeFile(gitignorePath, newContent);
2035
+ console.log(chalk.green('✓ Updated .gitignore with BMad directories'));
2036
+ console.log(chalk.dim(` Added: ${missingEntries.join(', ')}`));
2037
+ } else {
2038
+ console.log(chalk.dim(' .gitignore already includes BMad directories'));
2039
+ }
2040
+ } catch (error) {
2041
+ console.log(chalk.yellow(`⚠️ Could not update .gitignore: ${error.message}`));
2042
+ }
2043
+ }
2044
+
2045
+ async findInstallation() {
2046
+ // Look for .bmad-core in current directory or parent directories
2047
+ let currentDir = process.cwd();
2048
+
2049
+ while (currentDir !== path.dirname(currentDir)) {
2050
+ const bmadDir = path.join(currentDir, '.bmad-core');
2051
+ const manifestPath = path.join(bmadDir, 'install-manifest.yaml');
2052
+
2053
+ if (await fileManager.pathExists(manifestPath)) {
2054
+ return currentDir; // Return parent directory, not .bmad-core itself
2055
+ }
2056
+
2057
+ currentDir = path.dirname(currentDir);
2058
+ }
2059
+
2060
+ // Also check if we're inside a .bmad-core directory
2061
+ if (path.basename(process.cwd()) === '.bmad-core') {
2062
+ const manifestPath = path.join(process.cwd(), 'install-manifest.yaml');
2063
+ if (await fileManager.pathExists(manifestPath)) {
2064
+ return path.dirname(process.cwd()); // Return parent directory
2065
+ }
2066
+ }
2067
+
2068
+ return null;
2069
+ }
2070
+
2071
+ async flatten(options) {
2072
+ const { spawn } = require('node:child_process');
2073
+ const flattenerPath = path.join(__dirname, '..', '..', 'flattener', 'main.js');
2074
+
2075
+ const arguments_ = [];
2076
+ if (options.input) {
2077
+ arguments_.push('--input', options.input);
2078
+ }
2079
+ if (options.output) {
2080
+ arguments_.push('--output', options.output);
2081
+ }
2082
+
2083
+ const child = spawn('node', [flattenerPath, ...arguments_], {
2084
+ stdio: 'inherit',
2085
+ cwd: process.cwd(),
2086
+ });
2087
+
2088
+ child.on('exit', (code) => {
2089
+ process.exit(code);
2090
+ });
2091
+ }
2092
+ }
2093
+
2094
+ module.exports = new Installer();