observer-ggboy-bmad-method 6.0.0-alpha.23

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 (604) hide show
  1. package/.coderabbit.yaml +40 -0
  2. package/.github/CODE_OF_CONDUCT.md +128 -0
  3. package/.github/FUNDING.yaml +15 -0
  4. package/.github/ISSUE_TEMPLATE/config.yaml +8 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
  6. package/.github/ISSUE_TEMPLATE/issue.md +32 -0
  7. package/.github/scripts/discord-helpers.sh +34 -0
  8. package/.github/workflows/bundle-latest.yaml +330 -0
  9. package/.github/workflows/discord.yaml +90 -0
  10. package/.github/workflows/docs.yaml +63 -0
  11. package/.github/workflows/manual-release.yaml +190 -0
  12. package/.github/workflows/quality.yaml +115 -0
  13. package/.health-status.json +7 -0
  14. package/.husky/pre-commit +20 -0
  15. package/.markdownlint-cli2.yaml +41 -0
  16. package/.nvmrc +1 -0
  17. package/.prettierignore +9 -0
  18. package/.vscode/settings.json +97 -0
  19. package/CHANGELOG.md +1394 -0
  20. package/CNAME +1 -0
  21. package/CONTRIBUTING.md +167 -0
  22. package/CONTRIBUTORS.md +32 -0
  23. package/LICENSE +30 -0
  24. package/README.md +100 -0
  25. package/SECURITY.md +85 -0
  26. package/TRADEMARK.md +55 -0
  27. package/Wordmark.png +0 -0
  28. package/banner-bmad-method.png +0 -0
  29. package/bmad-method-6.0.0-alpha.23.tgz +0 -0
  30. package/docs/404.md +9 -0
  31. package/docs/_README_WORKFLOW_DIAGRAMS.md +40 -0
  32. package/docs/_STYLE_GUIDE.md +367 -0
  33. package/docs/_archive/customize-workflows.md +30 -0
  34. package/docs/_archive/getting-started-bmadv4.md +247 -0
  35. package/docs/_archive/vendor-workflows.md +52 -0
  36. package/docs/downloads.md +72 -0
  37. package/docs/explanation/agents/barry-quick-flow.md +328 -0
  38. package/docs/explanation/agents/index.md +19 -0
  39. package/docs/explanation/architecture/four-phases.md +107 -0
  40. package/docs/explanation/architecture/preventing-agent-conflicts.md +111 -0
  41. package/docs/explanation/architecture/why-solutioning-matters.md +75 -0
  42. package/docs/explanation/bmm/index.md +131 -0
  43. package/docs/explanation/core/index.md +18 -0
  44. package/docs/explanation/core-concepts/agent-roles.md +179 -0
  45. package/docs/explanation/core-concepts/index.md +35 -0
  46. package/docs/explanation/core-concepts/what-are-agents.md +97 -0
  47. package/docs/explanation/core-concepts/what-are-modules.md +85 -0
  48. package/docs/explanation/core-concepts/what-are-workflows.md +204 -0
  49. package/docs/explanation/faq/brownfield-faq.md +73 -0
  50. package/docs/explanation/faq/getting-started-faq.md +67 -0
  51. package/docs/explanation/faq/implementation-faq.md +52 -0
  52. package/docs/explanation/faq/index.md +16 -0
  53. package/docs/explanation/faq/levels-and-tracks-faq.md +52 -0
  54. package/docs/explanation/faq/planning-faq.md +41 -0
  55. package/docs/explanation/faq/tools-faq.md +277 -0
  56. package/docs/explanation/faq/workflows-faq.md +61 -0
  57. package/docs/explanation/features/advanced-elicitation.md +95 -0
  58. package/docs/explanation/features/brainstorming-techniques.md +92 -0
  59. package/docs/explanation/features/party-mode.md +95 -0
  60. package/docs/explanation/features/quick-flow.md +149 -0
  61. package/docs/explanation/features/tea-overview.md +410 -0
  62. package/docs/explanation/features/web-bundles.md +34 -0
  63. package/docs/explanation/philosophy/facilitation-over-generation.md +333 -0
  64. package/docs/explanation/philosophy/testing-as-engineering.md +112 -0
  65. package/docs/explanation/tea/engagement-models.md +710 -0
  66. package/docs/explanation/tea/fixture-architecture.md +457 -0
  67. package/docs/explanation/tea/knowledge-base-system.md +554 -0
  68. package/docs/explanation/tea/network-first-patterns.md +853 -0
  69. package/docs/explanation/tea/risk-based-testing.md +586 -0
  70. package/docs/explanation/tea/test-quality-standards.md +907 -0
  71. package/docs/how-to/brownfield/add-feature-to-existing.md +74 -0
  72. package/docs/how-to/brownfield/document-existing-project.md +66 -0
  73. package/docs/how-to/brownfield/index.md +84 -0
  74. package/docs/how-to/brownfield/quick-fix-in-brownfield.md +77 -0
  75. package/docs/how-to/brownfield/use-tea-for-enterprise.md +525 -0
  76. package/docs/how-to/brownfield/use-tea-with-existing-tests.md +577 -0
  77. package/docs/how-to/customization/customize-agents.md +212 -0
  78. package/docs/how-to/customization/enable-tea-mcp-enhancements.md +424 -0
  79. package/docs/how-to/customization/index.md +23 -0
  80. package/docs/how-to/customization/integrate-playwright-utils.md +813 -0
  81. package/docs/how-to/customization/shard-large-documents.md +101 -0
  82. package/docs/how-to/get-answers-about-bmad.md +102 -0
  83. package/docs/how-to/installation/index.md +12 -0
  84. package/docs/how-to/installation/install-bmad.md +111 -0
  85. package/docs/how-to/installation/install-custom-modules.md +118 -0
  86. package/docs/how-to/installation/upgrade-to-v6.md +131 -0
  87. package/docs/how-to/workflows/bmgd-quick-flow.md +156 -0
  88. package/docs/how-to/workflows/conduct-research.md +97 -0
  89. package/docs/how-to/workflows/create-architecture.md +119 -0
  90. package/docs/how-to/workflows/create-epics-and-stories.md +109 -0
  91. package/docs/how-to/workflows/create-prd.md +91 -0
  92. package/docs/how-to/workflows/create-product-brief.md +94 -0
  93. package/docs/how-to/workflows/create-story.md +102 -0
  94. package/docs/how-to/workflows/create-ux-design.md +100 -0
  95. package/docs/how-to/workflows/implement-story.md +97 -0
  96. package/docs/how-to/workflows/quick-spec.md +122 -0
  97. package/docs/how-to/workflows/run-atdd.md +436 -0
  98. package/docs/how-to/workflows/run-automate.md +653 -0
  99. package/docs/how-to/workflows/run-brainstorming-session.md +73 -0
  100. package/docs/how-to/workflows/run-code-review.md +89 -0
  101. package/docs/how-to/workflows/run-implementation-readiness.md +125 -0
  102. package/docs/how-to/workflows/run-nfr-assess.md +679 -0
  103. package/docs/how-to/workflows/run-sprint-planning.md +94 -0
  104. package/docs/how-to/workflows/run-test-design.md +135 -0
  105. package/docs/how-to/workflows/run-test-review.md +605 -0
  106. package/docs/how-to/workflows/run-trace.md +883 -0
  107. package/docs/how-to/workflows/setup-ci.md +712 -0
  108. package/docs/how-to/workflows/setup-party-mode.md +89 -0
  109. package/docs/how-to/workflows/setup-test-framework.md +98 -0
  110. package/docs/index.md +63 -0
  111. package/docs/reference/agents/index.md +109 -0
  112. package/docs/reference/configuration/core-tasks.md +67 -0
  113. package/docs/reference/configuration/global-config.md +28 -0
  114. package/docs/reference/glossary/index.md +159 -0
  115. package/docs/reference/tea/commands.md +276 -0
  116. package/docs/reference/tea/configuration.md +678 -0
  117. package/docs/reference/tea/knowledge-base.md +340 -0
  118. package/docs/reference/workflows/core-workflows.md +32 -0
  119. package/docs/reference/workflows/document-project.md +73 -0
  120. package/docs/reference/workflows/index.md +12 -0
  121. package/docs/tutorials/getting-started/getting-started-bmadv6.md +246 -0
  122. package/docs/tutorials/getting-started/images/workflow-method-greenfield.excalidraw +5034 -0
  123. package/docs/tutorials/getting-started/images/workflow-method-greenfield.svg +4 -0
  124. package/docs/tutorials/getting-started/images/workflow-overview.jpg +0 -0
  125. package/docs/tutorials/getting-started/tea-lite-quickstart.md +444 -0
  126. package/docs/tutorials/getting-started/workflow-overview.jpg +0 -0
  127. package/eslint.config.mjs +152 -0
  128. package/package.json +117 -0
  129. package/prettier.config.mjs +32 -0
  130. package/src/bmm/_module-installer/installer.js +48 -0
  131. package/src/bmm/_module-installer/platform-specifics/claude-code.js +35 -0
  132. package/src/bmm/_module-installer/platform-specifics/windsurf.js +32 -0
  133. package/src/bmm/agents/analyst.agent.yaml +36 -0
  134. package/src/bmm/agents/architect.agent.yaml +28 -0
  135. package/src/bmm/agents/dev.agent.yaml +38 -0
  136. package/src/bmm/agents/pm.agent.yaml +46 -0
  137. package/src/bmm/agents/quick-flow-solo-dev.agent.yaml +32 -0
  138. package/src/bmm/agents/sm.agent.yaml +36 -0
  139. package/src/bmm/agents/tea.agent.yaml +63 -0
  140. package/src/bmm/agents/tech-writer/tech-writer-sidecar/documentation-standards.md +224 -0
  141. package/src/bmm/agents/tech-writer/tech-writer.agent.yaml +45 -0
  142. package/src/bmm/agents/ux-designer.agent.yaml +26 -0
  143. package/src/bmm/data/project-context-template.md +26 -0
  144. package/src/bmm/module-help.csv +32 -0
  145. package/src/bmm/module.yaml +44 -0
  146. package/src/bmm/sub-modules/claude-code/config.yaml +4 -0
  147. package/src/bmm/sub-modules/claude-code/injections.yaml +242 -0
  148. package/src/bmm/sub-modules/claude-code/readme.md +87 -0
  149. package/src/bmm/teams/default-party.csv +21 -0
  150. package/src/bmm/teams/team-fullstack.yaml +12 -0
  151. package/src/bmm/testarch/knowledge/adr-quality-readiness-checklist.md +350 -0
  152. package/src/bmm/testarch/knowledge/api-request.md +442 -0
  153. package/src/bmm/testarch/knowledge/api-testing-patterns.md +843 -0
  154. package/src/bmm/testarch/knowledge/auth-session.md +552 -0
  155. package/src/bmm/testarch/knowledge/burn-in.md +273 -0
  156. package/src/bmm/testarch/knowledge/ci-burn-in.md +675 -0
  157. package/src/bmm/testarch/knowledge/component-tdd.md +486 -0
  158. package/src/bmm/testarch/knowledge/contract-testing.md +957 -0
  159. package/src/bmm/testarch/knowledge/data-factories.md +500 -0
  160. package/src/bmm/testarch/knowledge/email-auth.md +721 -0
  161. package/src/bmm/testarch/knowledge/error-handling.md +725 -0
  162. package/src/bmm/testarch/knowledge/feature-flags.md +750 -0
  163. package/src/bmm/testarch/knowledge/file-utils.md +463 -0
  164. package/src/bmm/testarch/knowledge/fixture-architecture.md +401 -0
  165. package/src/bmm/testarch/knowledge/fixtures-composition.md +382 -0
  166. package/src/bmm/testarch/knowledge/intercept-network-call.md +430 -0
  167. package/src/bmm/testarch/knowledge/log.md +429 -0
  168. package/src/bmm/testarch/knowledge/network-error-monitor.md +405 -0
  169. package/src/bmm/testarch/knowledge/network-first.md +486 -0
  170. package/src/bmm/testarch/knowledge/network-recorder.md +527 -0
  171. package/src/bmm/testarch/knowledge/nfr-criteria.md +670 -0
  172. package/src/bmm/testarch/knowledge/overview.md +286 -0
  173. package/src/bmm/testarch/knowledge/playwright-config.md +730 -0
  174. package/src/bmm/testarch/knowledge/probability-impact.md +601 -0
  175. package/src/bmm/testarch/knowledge/recurse.md +421 -0
  176. package/src/bmm/testarch/knowledge/risk-governance.md +615 -0
  177. package/src/bmm/testarch/knowledge/selective-testing.md +732 -0
  178. package/src/bmm/testarch/knowledge/selector-resilience.md +527 -0
  179. package/src/bmm/testarch/knowledge/test-healing-patterns.md +644 -0
  180. package/src/bmm/testarch/knowledge/test-levels-framework.md +473 -0
  181. package/src/bmm/testarch/knowledge/test-priorities-matrix.md +373 -0
  182. package/src/bmm/testarch/knowledge/test-quality.md +664 -0
  183. package/src/bmm/testarch/knowledge/timing-debugging.md +372 -0
  184. package/src/bmm/testarch/knowledge/visual-debugging.md +524 -0
  185. package/src/bmm/testarch/tea-index.csv +35 -0
  186. package/src/bmm/workflows/1-analysis/create-product-brief/product-brief.template.md +10 -0
  187. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-01-init.md +177 -0
  188. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-01b-continue.md +161 -0
  189. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-02-vision.md +199 -0
  190. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-03-users.md +202 -0
  191. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-04-metrics.md +205 -0
  192. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-05-scope.md +219 -0
  193. package/src/bmm/workflows/1-analysis/create-product-brief/steps/step-06-complete.md +162 -0
  194. package/src/bmm/workflows/1-analysis/create-product-brief/workflow.md +58 -0
  195. package/src/bmm/workflows/1-analysis/research/domain-steps/step-01-init.md +137 -0
  196. package/src/bmm/workflows/1-analysis/research/domain-steps/step-02-domain-analysis.md +229 -0
  197. package/src/bmm/workflows/1-analysis/research/domain-steps/step-03-competitive-landscape.md +238 -0
  198. package/src/bmm/workflows/1-analysis/research/domain-steps/step-04-regulatory-focus.md +206 -0
  199. package/src/bmm/workflows/1-analysis/research/domain-steps/step-05-technical-trends.md +234 -0
  200. package/src/bmm/workflows/1-analysis/research/domain-steps/step-06-research-synthesis.md +443 -0
  201. package/src/bmm/workflows/1-analysis/research/market-steps/step-01-init.md +182 -0
  202. package/src/bmm/workflows/1-analysis/research/market-steps/step-02-customer-behavior.md +237 -0
  203. package/src/bmm/workflows/1-analysis/research/market-steps/step-02-customer-insights.md +200 -0
  204. package/src/bmm/workflows/1-analysis/research/market-steps/step-03-customer-pain-points.md +249 -0
  205. package/src/bmm/workflows/1-analysis/research/market-steps/step-04-customer-decisions.md +259 -0
  206. package/src/bmm/workflows/1-analysis/research/market-steps/step-05-competitive-analysis.md +177 -0
  207. package/src/bmm/workflows/1-analysis/research/market-steps/step-06-research-completion.md +475 -0
  208. package/src/bmm/workflows/1-analysis/research/research.template.md +29 -0
  209. package/src/bmm/workflows/1-analysis/research/technical-steps/step-01-init.md +137 -0
  210. package/src/bmm/workflows/1-analysis/research/technical-steps/step-02-technical-overview.md +239 -0
  211. package/src/bmm/workflows/1-analysis/research/technical-steps/step-03-integration-patterns.md +248 -0
  212. package/src/bmm/workflows/1-analysis/research/technical-steps/step-04-architectural-patterns.md +202 -0
  213. package/src/bmm/workflows/1-analysis/research/technical-steps/step-05-implementation-research.md +239 -0
  214. package/src/bmm/workflows/1-analysis/research/technical-steps/step-06-research-synthesis.md +486 -0
  215. package/src/bmm/workflows/1-analysis/research/workflow.md +173 -0
  216. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-01-init.md +135 -0
  217. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-01b-continue.md +127 -0
  218. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-02-discovery.md +190 -0
  219. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-03-core-experience.md +216 -0
  220. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-04-emotional-response.md +219 -0
  221. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-05-inspiration.md +234 -0
  222. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-06-design-system.md +252 -0
  223. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-07-defining-experience.md +254 -0
  224. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-08-visual-foundation.md +224 -0
  225. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-09-design-directions.md +224 -0
  226. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-10-user-journeys.md +241 -0
  227. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-11-component-strategy.md +248 -0
  228. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-12-ux-patterns.md +237 -0
  229. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-13-responsive-accessibility.md +264 -0
  230. package/src/bmm/workflows/2-plan-workflows/create-ux-design/steps/step-14-complete.md +171 -0
  231. package/src/bmm/workflows/2-plan-workflows/create-ux-design/ux-design-template.md +13 -0
  232. package/src/bmm/workflows/2-plan-workflows/create-ux-design/workflow.md +43 -0
  233. package/src/bmm/workflows/2-plan-workflows/prd/data/domain-complexity.csv +13 -0
  234. package/src/bmm/workflows/2-plan-workflows/prd/data/prd-purpose.md +197 -0
  235. package/src/bmm/workflows/2-plan-workflows/prd/data/project-types.csv +11 -0
  236. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-01-init.md +191 -0
  237. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-01b-continue.md +153 -0
  238. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-02-discovery.md +224 -0
  239. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-03-success.md +226 -0
  240. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-04-journeys.md +213 -0
  241. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-05-domain.md +207 -0
  242. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-06-innovation.md +226 -0
  243. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-07-project-type.md +237 -0
  244. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-08-scoping.md +228 -0
  245. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-09-functional.md +231 -0
  246. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-10-nonfunctional.md +242 -0
  247. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-11-polish.md +217 -0
  248. package/src/bmm/workflows/2-plan-workflows/prd/steps-c/step-12-complete.md +124 -0
  249. package/src/bmm/workflows/2-plan-workflows/prd/steps-e/step-e-01-discovery.md +247 -0
  250. package/src/bmm/workflows/2-plan-workflows/prd/steps-e/step-e-01b-legacy-conversion.md +208 -0
  251. package/src/bmm/workflows/2-plan-workflows/prd/steps-e/step-e-02-review.md +249 -0
  252. package/src/bmm/workflows/2-plan-workflows/prd/steps-e/step-e-03-edit.md +253 -0
  253. package/src/bmm/workflows/2-plan-workflows/prd/steps-e/step-e-04-complete.md +168 -0
  254. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-01-discovery.md +218 -0
  255. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-02-format-detection.md +191 -0
  256. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-02b-parity-check.md +209 -0
  257. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-03-density-validation.md +174 -0
  258. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-04-brief-coverage-validation.md +214 -0
  259. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-05-measurability-validation.md +228 -0
  260. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-06-traceability-validation.md +217 -0
  261. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-07-implementation-leakage-validation.md +205 -0
  262. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-08-domain-compliance-validation.md +243 -0
  263. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-09-project-type-validation.md +263 -0
  264. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-10-smart-validation.md +209 -0
  265. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-11-holistic-quality-validation.md +264 -0
  266. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-12-completeness-validation.md +242 -0
  267. package/src/bmm/workflows/2-plan-workflows/prd/steps-v/step-v-13-report-complete.md +231 -0
  268. package/src/bmm/workflows/2-plan-workflows/prd/templates/prd-template.md +10 -0
  269. package/src/bmm/workflows/2-plan-workflows/prd/validation-report-prd-workflow.md +433 -0
  270. package/src/bmm/workflows/2-plan-workflows/prd/workflow.md +150 -0
  271. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-01-document-discovery.md +190 -0
  272. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-02-prd-analysis.md +178 -0
  273. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-03-epic-coverage-validation.md +179 -0
  274. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-04-ux-alignment.md +139 -0
  275. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-05-epic-quality-review.md +252 -0
  276. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/steps/step-06-final-assessment.md +135 -0
  277. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/templates/readiness-report-template.md +4 -0
  278. package/src/bmm/workflows/3-solutioning/check-implementation-readiness/workflow.md +55 -0
  279. package/src/bmm/workflows/3-solutioning/create-architecture/architecture-decision-template.md +12 -0
  280. package/src/bmm/workflows/3-solutioning/create-architecture/data/domain-complexity.csv +11 -0
  281. package/src/bmm/workflows/3-solutioning/create-architecture/data/project-types.csv +7 -0
  282. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-01-init.md +153 -0
  283. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-01b-continue.md +164 -0
  284. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-02-context.md +224 -0
  285. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-03-starter.md +331 -0
  286. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-04-decisions.md +318 -0
  287. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-05-patterns.md +359 -0
  288. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-06-structure.md +379 -0
  289. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-07-validation.md +359 -0
  290. package/src/bmm/workflows/3-solutioning/create-architecture/steps/step-08-complete.md +76 -0
  291. package/src/bmm/workflows/3-solutioning/create-architecture/workflow.md +50 -0
  292. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/steps/step-01-validate-prerequisites.md +259 -0
  293. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/steps/step-02-design-epics.md +233 -0
  294. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/steps/step-03-create-stories.md +272 -0
  295. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/steps/step-04-final-validation.md +149 -0
  296. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/templates/epics-template.md +57 -0
  297. package/src/bmm/workflows/3-solutioning/create-epics-and-stories/workflow.md +59 -0
  298. package/src/bmm/workflows/4-implementation/code-review/checklist.md +23 -0
  299. package/src/bmm/workflows/4-implementation/code-review/instructions.xml +227 -0
  300. package/src/bmm/workflows/4-implementation/code-review/workflow.yaml +51 -0
  301. package/src/bmm/workflows/4-implementation/correct-course/checklist.md +288 -0
  302. package/src/bmm/workflows/4-implementation/correct-course/instructions.md +206 -0
  303. package/src/bmm/workflows/4-implementation/correct-course/workflow.yaml +60 -0
  304. package/src/bmm/workflows/4-implementation/create-story/checklist.md +358 -0
  305. package/src/bmm/workflows/4-implementation/create-story/instructions.xml +345 -0
  306. package/src/bmm/workflows/4-implementation/create-story/template.md +49 -0
  307. package/src/bmm/workflows/4-implementation/create-story/workflow.yaml +61 -0
  308. package/src/bmm/workflows/4-implementation/dev-story/checklist.md +80 -0
  309. package/src/bmm/workflows/4-implementation/dev-story/instructions.xml +410 -0
  310. package/src/bmm/workflows/4-implementation/dev-story/workflow.yaml +27 -0
  311. package/src/bmm/workflows/4-implementation/retrospective/instructions.md +1443 -0
  312. package/src/bmm/workflows/4-implementation/retrospective/workflow.yaml +58 -0
  313. package/src/bmm/workflows/4-implementation/sprint-planning/checklist.md +33 -0
  314. package/src/bmm/workflows/4-implementation/sprint-planning/instructions.md +225 -0
  315. package/src/bmm/workflows/4-implementation/sprint-planning/sprint-status-template.yaml +55 -0
  316. package/src/bmm/workflows/4-implementation/sprint-planning/workflow.yaml +54 -0
  317. package/src/bmm/workflows/4-implementation/sprint-status/instructions.md +229 -0
  318. package/src/bmm/workflows/4-implementation/sprint-status/workflow.yaml +36 -0
  319. package/src/bmm/workflows/bmad-quick-flow/quick-dev/data/project-levels.yaml +59 -0
  320. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-01-mode-detection.md +156 -0
  321. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-02-context-gathering.md +120 -0
  322. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-03-execute.md +113 -0
  323. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-04-self-check.md +113 -0
  324. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-05-adversarial-review.md +106 -0
  325. package/src/bmm/workflows/bmad-quick-flow/quick-dev/steps/step-06-resolve-findings.md +140 -0
  326. package/src/bmm/workflows/bmad-quick-flow/quick-dev/workflow.md +50 -0
  327. package/src/bmm/workflows/bmad-quick-flow/quick-spec/steps/step-01-understand.md +189 -0
  328. package/src/bmm/workflows/bmad-quick-flow/quick-spec/steps/step-02-investigate.md +144 -0
  329. package/src/bmm/workflows/bmad-quick-flow/quick-spec/steps/step-03-generate.md +128 -0
  330. package/src/bmm/workflows/bmad-quick-flow/quick-spec/steps/step-04-review.md +191 -0
  331. package/src/bmm/workflows/bmad-quick-flow/quick-spec/tech-spec-template.md +74 -0
  332. package/src/bmm/workflows/bmad-quick-flow/quick-spec/workflow.md +79 -0
  333. package/src/bmm/workflows/document-project/checklist.md +245 -0
  334. package/src/bmm/workflows/document-project/documentation-requirements.csv +12 -0
  335. package/src/bmm/workflows/document-project/instructions.md +221 -0
  336. package/src/bmm/workflows/document-project/templates/deep-dive-template.md +345 -0
  337. package/src/bmm/workflows/document-project/templates/index-template.md +169 -0
  338. package/src/bmm/workflows/document-project/templates/project-overview-template.md +103 -0
  339. package/src/bmm/workflows/document-project/templates/project-scan-report-schema.json +160 -0
  340. package/src/bmm/workflows/document-project/templates/source-tree-template.md +135 -0
  341. package/src/bmm/workflows/document-project/workflow.yaml +30 -0
  342. package/src/bmm/workflows/document-project/workflows/deep-dive-instructions.md +298 -0
  343. package/src/bmm/workflows/document-project/workflows/deep-dive.yaml +31 -0
  344. package/src/bmm/workflows/document-project/workflows/full-scan-instructions.md +1106 -0
  345. package/src/bmm/workflows/document-project/workflows/full-scan.yaml +31 -0
  346. package/src/bmm/workflows/excalidraw-diagrams/_shared/excalidraw-library.json +90 -0
  347. package/src/bmm/workflows/excalidraw-diagrams/_shared/excalidraw-templates.yaml +127 -0
  348. package/src/bmm/workflows/excalidraw-diagrams/create-dataflow/checklist.md +39 -0
  349. package/src/bmm/workflows/excalidraw-diagrams/create-dataflow/instructions.md +130 -0
  350. package/src/bmm/workflows/excalidraw-diagrams/create-dataflow/workflow.yaml +27 -0
  351. package/src/bmm/workflows/excalidraw-diagrams/create-diagram/checklist.md +43 -0
  352. package/src/bmm/workflows/excalidraw-diagrams/create-diagram/instructions.md +141 -0
  353. package/src/bmm/workflows/excalidraw-diagrams/create-diagram/workflow.yaml +27 -0
  354. package/src/bmm/workflows/excalidraw-diagrams/create-flowchart/checklist.md +49 -0
  355. package/src/bmm/workflows/excalidraw-diagrams/create-flowchart/instructions.md +241 -0
  356. package/src/bmm/workflows/excalidraw-diagrams/create-flowchart/workflow.yaml +27 -0
  357. package/src/bmm/workflows/excalidraw-diagrams/create-wireframe/checklist.md +38 -0
  358. package/src/bmm/workflows/excalidraw-diagrams/create-wireframe/instructions.md +133 -0
  359. package/src/bmm/workflows/excalidraw-diagrams/create-wireframe/workflow.yaml +27 -0
  360. package/src/bmm/workflows/testarch/atdd/atdd-checklist-template.md +363 -0
  361. package/src/bmm/workflows/testarch/atdd/checklist.md +374 -0
  362. package/src/bmm/workflows/testarch/atdd/instructions.md +806 -0
  363. package/src/bmm/workflows/testarch/atdd/workflow.yaml +47 -0
  364. package/src/bmm/workflows/testarch/automate/checklist.md +582 -0
  365. package/src/bmm/workflows/testarch/automate/instructions.md +1324 -0
  366. package/src/bmm/workflows/testarch/automate/workflow.yaml +54 -0
  367. package/src/bmm/workflows/testarch/ci/checklist.md +247 -0
  368. package/src/bmm/workflows/testarch/ci/github-actions-template.yaml +198 -0
  369. package/src/bmm/workflows/testarch/ci/gitlab-ci-template.yaml +149 -0
  370. package/src/bmm/workflows/testarch/ci/instructions.md +536 -0
  371. package/src/bmm/workflows/testarch/ci/workflow.yaml +47 -0
  372. package/src/bmm/workflows/testarch/framework/checklist.md +320 -0
  373. package/src/bmm/workflows/testarch/framework/instructions.md +481 -0
  374. package/src/bmm/workflows/testarch/framework/workflow.yaml +49 -0
  375. package/src/bmm/workflows/testarch/nfr-assess/checklist.md +407 -0
  376. package/src/bmm/workflows/testarch/nfr-assess/instructions.md +726 -0
  377. package/src/bmm/workflows/testarch/nfr-assess/nfr-report-template.md +461 -0
  378. package/src/bmm/workflows/testarch/nfr-assess/workflow.yaml +49 -0
  379. package/src/bmm/workflows/testarch/test-design/checklist.md +407 -0
  380. package/src/bmm/workflows/testarch/test-design/instructions.md +1158 -0
  381. package/src/bmm/workflows/testarch/test-design/test-design-architecture-template.md +213 -0
  382. package/src/bmm/workflows/testarch/test-design/test-design-qa-template.md +286 -0
  383. package/src/bmm/workflows/testarch/test-design/test-design-template.md +294 -0
  384. package/src/bmm/workflows/testarch/test-design/workflow.yaml +71 -0
  385. package/src/bmm/workflows/testarch/test-review/checklist.md +472 -0
  386. package/src/bmm/workflows/testarch/test-review/instructions.md +628 -0
  387. package/src/bmm/workflows/testarch/test-review/test-review-template.md +390 -0
  388. package/src/bmm/workflows/testarch/test-review/workflow.yaml +48 -0
  389. package/src/bmm/workflows/testarch/trace/checklist.md +642 -0
  390. package/src/bmm/workflows/testarch/trace/instructions.md +1030 -0
  391. package/src/bmm/workflows/testarch/trace/trace-template.md +675 -0
  392. package/src/bmm/workflows/testarch/trace/workflow.yaml +57 -0
  393. package/src/core/_module-installer/installer.js +60 -0
  394. package/src/core/agents/bmad-master.agent.yaml +29 -0
  395. package/src/core/module-help.csv +9 -0
  396. package/src/core/module.yaml +25 -0
  397. package/src/core/resources/excalidraw/README.md +160 -0
  398. package/src/core/resources/excalidraw/excalidraw-helpers.md +127 -0
  399. package/src/core/resources/excalidraw/library-loader.md +50 -0
  400. package/src/core/resources/excalidraw/validate-json-instructions.md +79 -0
  401. package/src/core/tasks/editorial-review-prose.xml +100 -0
  402. package/src/core/tasks/editorial-review-structure.xml +209 -0
  403. package/src/core/tasks/help.md +62 -0
  404. package/src/core/tasks/index-docs.xml +65 -0
  405. package/src/core/tasks/review-adversarial-general.xml +48 -0
  406. package/src/core/tasks/shard-doc.xml +109 -0
  407. package/src/core/tasks/workflow.xml +235 -0
  408. package/src/core/workflows/advanced-elicitation/methods.csv +51 -0
  409. package/src/core/workflows/advanced-elicitation/workflow.xml +117 -0
  410. package/src/core/workflows/brainstorming/brain-methods.csv +62 -0
  411. package/src/core/workflows/brainstorming/steps/step-01-session-setup.md +197 -0
  412. package/src/core/workflows/brainstorming/steps/step-01b-continue.md +122 -0
  413. package/src/core/workflows/brainstorming/steps/step-02a-user-selected.md +225 -0
  414. package/src/core/workflows/brainstorming/steps/step-02b-ai-recommended.md +237 -0
  415. package/src/core/workflows/brainstorming/steps/step-02c-random-selection.md +209 -0
  416. package/src/core/workflows/brainstorming/steps/step-02d-progressive-flow.md +264 -0
  417. package/src/core/workflows/brainstorming/steps/step-03-technique-execution.md +399 -0
  418. package/src/core/workflows/brainstorming/steps/step-04-idea-organization.md +303 -0
  419. package/src/core/workflows/brainstorming/template.md +15 -0
  420. package/src/core/workflows/brainstorming/workflow.md +58 -0
  421. package/src/core/workflows/party-mode/steps/step-01-agent-loading.md +138 -0
  422. package/src/core/workflows/party-mode/steps/step-02-discussion-orchestration.md +187 -0
  423. package/src/core/workflows/party-mode/steps/step-03-graceful-exit.md +157 -0
  424. package/src/core/workflows/party-mode/workflow.md +194 -0
  425. package/src/utility/agent-components/activation-rules.txt +6 -0
  426. package/src/utility/agent-components/activation-steps.txt +14 -0
  427. package/src/utility/agent-components/agent-command-header.md +1 -0
  428. package/src/utility/agent-components/agent.customize.template.yaml +41 -0
  429. package/src/utility/agent-components/handler-action.txt +4 -0
  430. package/src/utility/agent-components/handler-data.txt +5 -0
  431. package/src/utility/agent-components/handler-exec.txt +6 -0
  432. package/src/utility/agent-components/handler-multi.txt +14 -0
  433. package/src/utility/agent-components/handler-tmpl.txt +5 -0
  434. package/src/utility/agent-components/handler-validate-workflow.txt +7 -0
  435. package/src/utility/agent-components/handler-workflow.txt +10 -0
  436. package/src/utility/agent-components/menu-handlers.txt +6 -0
  437. package/test/README.md +295 -0
  438. package/test/adversarial-review-tests/README.md +56 -0
  439. package/test/adversarial-review-tests/sample-content.md +46 -0
  440. package/test/adversarial-review-tests/test-cases.yaml +103 -0
  441. package/test/fixtures/agent-schema/invalid/critical-actions/actions-as-string.agent.yaml +27 -0
  442. package/test/fixtures/agent-schema/invalid/critical-actions/empty-string-in-actions.agent.yaml +30 -0
  443. package/test/fixtures/agent-schema/invalid/menu/empty-menu.agent.yaml +22 -0
  444. package/test/fixtures/agent-schema/invalid/menu/missing-menu.agent.yaml +20 -0
  445. package/test/fixtures/agent-schema/invalid/menu-commands/empty-command-target.agent.yaml +25 -0
  446. package/test/fixtures/agent-schema/invalid/menu-commands/no-command-target.agent.yaml +24 -0
  447. package/test/fixtures/agent-schema/invalid/menu-triggers/camel-case.agent.yaml +25 -0
  448. package/test/fixtures/agent-schema/invalid/menu-triggers/compound-invalid-format.agent.yaml +25 -0
  449. package/test/fixtures/agent-schema/invalid/menu-triggers/compound-mismatched-kebab.agent.yaml +25 -0
  450. package/test/fixtures/agent-schema/invalid/menu-triggers/duplicate-triggers.agent.yaml +31 -0
  451. package/test/fixtures/agent-schema/invalid/menu-triggers/empty-trigger.agent.yaml +25 -0
  452. package/test/fixtures/agent-schema/invalid/menu-triggers/leading-asterisk.agent.yaml +25 -0
  453. package/test/fixtures/agent-schema/invalid/menu-triggers/snake-case.agent.yaml +25 -0
  454. package/test/fixtures/agent-schema/invalid/menu-triggers/trigger-with-spaces.agent.yaml +25 -0
  455. package/test/fixtures/agent-schema/invalid/metadata/empty-module-string.agent.yaml +26 -0
  456. package/test/fixtures/agent-schema/invalid/metadata/empty-name.agent.yaml +24 -0
  457. package/test/fixtures/agent-schema/invalid/metadata/extra-metadata-fields.agent.yaml +27 -0
  458. package/test/fixtures/agent-schema/invalid/metadata/missing-id.agent.yaml +23 -0
  459. package/test/fixtures/agent-schema/invalid/persona/empty-principles-array.agent.yaml +24 -0
  460. package/test/fixtures/agent-schema/invalid/persona/empty-string-in-principles.agent.yaml +27 -0
  461. package/test/fixtures/agent-schema/invalid/persona/extra-persona-fields.agent.yaml +27 -0
  462. package/test/fixtures/agent-schema/invalid/persona/missing-role.agent.yaml +24 -0
  463. package/test/fixtures/agent-schema/invalid/prompts/empty-content.agent.yaml +29 -0
  464. package/test/fixtures/agent-schema/invalid/prompts/extra-prompt-fields.agent.yaml +31 -0
  465. package/test/fixtures/agent-schema/invalid/prompts/missing-content.agent.yaml +28 -0
  466. package/test/fixtures/agent-schema/invalid/prompts/missing-id.agent.yaml +28 -0
  467. package/test/fixtures/agent-schema/invalid/top-level/empty-file.agent.yaml +5 -0
  468. package/test/fixtures/agent-schema/invalid/top-level/extra-top-level-keys.agent.yaml +28 -0
  469. package/test/fixtures/agent-schema/invalid/top-level/missing-agent-key.agent.yaml +11 -0
  470. package/test/fixtures/agent-schema/invalid/yaml-errors/invalid-indentation.agent.yaml +19 -0
  471. package/test/fixtures/agent-schema/invalid/yaml-errors/malformed-yaml.agent.yaml +18 -0
  472. package/test/fixtures/agent-schema/valid/critical-actions/empty-critical-actions.agent.yaml +24 -0
  473. package/test/fixtures/agent-schema/valid/critical-actions/no-critical-actions.agent.yaml +22 -0
  474. package/test/fixtures/agent-schema/valid/critical-actions/valid-critical-actions.agent.yaml +27 -0
  475. package/test/fixtures/agent-schema/valid/menu/multiple-menu-items.agent.yaml +31 -0
  476. package/test/fixtures/agent-schema/valid/menu/single-menu-item.agent.yaml +22 -0
  477. package/test/fixtures/agent-schema/valid/menu-commands/all-command-types.agent.yaml +38 -0
  478. package/test/fixtures/agent-schema/valid/menu-commands/multiple-commands.agent.yaml +24 -0
  479. package/test/fixtures/agent-schema/valid/menu-triggers/compound-triggers.agent.yaml +31 -0
  480. package/test/fixtures/agent-schema/valid/menu-triggers/kebab-case-triggers.agent.yaml +34 -0
  481. package/test/fixtures/agent-schema/valid/metadata/core-agent-with-module.agent.yaml +24 -0
  482. package/test/fixtures/agent-schema/valid/metadata/empty-module-name-in-path.agent.yaml +24 -0
  483. package/test/fixtures/agent-schema/valid/metadata/malformed-path-treated-as-core.agent.yaml +24 -0
  484. package/test/fixtures/agent-schema/valid/metadata/module-agent-correct.agent.yaml +24 -0
  485. package/test/fixtures/agent-schema/valid/metadata/module-agent-missing-module.agent.yaml +23 -0
  486. package/test/fixtures/agent-schema/valid/metadata/wrong-module-value.agent.yaml +24 -0
  487. package/test/fixtures/agent-schema/valid/persona/complete-persona.agent.yaml +24 -0
  488. package/test/fixtures/agent-schema/valid/prompts/empty-prompts.agent.yaml +24 -0
  489. package/test/fixtures/agent-schema/valid/prompts/no-prompts.agent.yaml +22 -0
  490. package/test/fixtures/agent-schema/valid/prompts/valid-prompts-minimal.agent.yaml +28 -0
  491. package/test/fixtures/agent-schema/valid/prompts/valid-prompts-with-description.agent.yaml +30 -0
  492. package/test/fixtures/agent-schema/valid/top-level/minimal-core-agent.agent.yaml +24 -0
  493. package/test/test-agent-schema.js +387 -0
  494. package/test/test-cli-integration.sh +159 -0
  495. package/test/test-installation-components.js +214 -0
  496. package/test/unit-test-schema.js +133 -0
  497. package/tools/bmad-npx-wrapper.js +38 -0
  498. package/tools/build-docs.js +577 -0
  499. package/tools/cli/README.md +7 -0
  500. package/tools/cli/bmad-cli.js +58 -0
  501. package/tools/cli/commands/install.js +87 -0
  502. package/tools/cli/commands/status.js +65 -0
  503. package/tools/cli/external-official-modules.yaml +56 -0
  504. package/tools/cli/installers/install-messages.yaml +58 -0
  505. package/tools/cli/installers/lib/core/config-collector.js +1079 -0
  506. package/tools/cli/installers/lib/core/custom-module-cache.js +259 -0
  507. package/tools/cli/installers/lib/core/dependency-resolver.js +739 -0
  508. package/tools/cli/installers/lib/core/detector.js +223 -0
  509. package/tools/cli/installers/lib/core/ide-config-manager.js +156 -0
  510. package/tools/cli/installers/lib/core/installer.js +2826 -0
  511. package/tools/cli/installers/lib/core/manifest-generator.js +1054 -0
  512. package/tools/cli/installers/lib/core/manifest.js +1036 -0
  513. package/tools/cli/installers/lib/custom/handler.js +363 -0
  514. package/tools/cli/installers/lib/ide/STANDARDIZATION_PLAN.md +208 -0
  515. package/tools/cli/installers/lib/ide/_base-ide.js +655 -0
  516. package/tools/cli/installers/lib/ide/antigravity.js +474 -0
  517. package/tools/cli/installers/lib/ide/auggie.js +244 -0
  518. package/tools/cli/installers/lib/ide/claude-code.js +506 -0
  519. package/tools/cli/installers/lib/ide/cline.js +272 -0
  520. package/tools/cli/installers/lib/ide/codex.js +412 -0
  521. package/tools/cli/installers/lib/ide/crush.js +149 -0
  522. package/tools/cli/installers/lib/ide/cursor.js +160 -0
  523. package/tools/cli/installers/lib/ide/gemini.js +301 -0
  524. package/tools/cli/installers/lib/ide/github-copilot.js +383 -0
  525. package/tools/cli/installers/lib/ide/iflow.js +191 -0
  526. package/tools/cli/installers/lib/ide/kilo.js +250 -0
  527. package/tools/cli/installers/lib/ide/kiro-cli.js +326 -0
  528. package/tools/cli/installers/lib/ide/manager.js +244 -0
  529. package/tools/cli/installers/lib/ide/opencode.js +257 -0
  530. package/tools/cli/installers/lib/ide/qwen.js +372 -0
  531. package/tools/cli/installers/lib/ide/roo.js +273 -0
  532. package/tools/cli/installers/lib/ide/rovo-dev.js +290 -0
  533. package/tools/cli/installers/lib/ide/shared/agent-command-generator.js +165 -0
  534. package/tools/cli/installers/lib/ide/shared/bmad-artifacts.js +158 -0
  535. package/tools/cli/installers/lib/ide/shared/module-injections.js +136 -0
  536. package/tools/cli/installers/lib/ide/shared/path-utils.js +165 -0
  537. package/tools/cli/installers/lib/ide/shared/task-tool-command-generator.js +268 -0
  538. package/tools/cli/installers/lib/ide/shared/workflow-command-generator.js +293 -0
  539. package/tools/cli/installers/lib/ide/templates/agent-command-template.md +14 -0
  540. package/tools/cli/installers/lib/ide/templates/gemini-agent-command.toml +14 -0
  541. package/tools/cli/installers/lib/ide/templates/gemini-task-command.toml +12 -0
  542. package/tools/cli/installers/lib/ide/templates/workflow-command-template.md +13 -0
  543. package/tools/cli/installers/lib/ide/templates/workflow-commander.md +5 -0
  544. package/tools/cli/installers/lib/ide/trae.js +313 -0
  545. package/tools/cli/installers/lib/ide/windsurf.js +258 -0
  546. package/tools/cli/installers/lib/message-loader.js +85 -0
  547. package/tools/cli/installers/lib/modules/external-manager.js +135 -0
  548. package/tools/cli/installers/lib/modules/manager.js +1375 -0
  549. package/tools/cli/lib/activation-builder.js +163 -0
  550. package/tools/cli/lib/agent/compiler.js +522 -0
  551. package/tools/cli/lib/agent/installer.js +716 -0
  552. package/tools/cli/lib/agent/template-engine.js +152 -0
  553. package/tools/cli/lib/agent-analyzer.js +109 -0
  554. package/tools/cli/lib/agent-party-generator.js +194 -0
  555. package/tools/cli/lib/cli-utils.js +227 -0
  556. package/tools/cli/lib/config.js +213 -0
  557. package/tools/cli/lib/file-ops.js +204 -0
  558. package/tools/cli/lib/platform-codes.js +116 -0
  559. package/tools/cli/lib/project-root.js +77 -0
  560. package/tools/cli/lib/prompts.js +433 -0
  561. package/tools/cli/lib/ui.js +1716 -0
  562. package/tools/cli/lib/xml-handler.js +177 -0
  563. package/tools/cli/lib/xml-to-markdown.js +82 -0
  564. package/tools/cli/lib/yaml-format.js +245 -0
  565. package/tools/cli/lib/yaml-xml-builder.js +587 -0
  566. package/tools/docs/BUNDLE_DISTRIBUTION_SETUP.md +95 -0
  567. package/tools/docs/index.md +2 -0
  568. package/tools/fix-doc-links.js +288 -0
  569. package/tools/flattener/aggregate.js +76 -0
  570. package/tools/flattener/binary.js +80 -0
  571. package/tools/flattener/discovery.js +71 -0
  572. package/tools/flattener/files.js +35 -0
  573. package/tools/flattener/ignoreRules.js +172 -0
  574. package/tools/flattener/main.js +483 -0
  575. package/tools/flattener/projectRoot.js +201 -0
  576. package/tools/flattener/prompts.js +44 -0
  577. package/tools/flattener/stats.helpers.js +368 -0
  578. package/tools/flattener/stats.js +75 -0
  579. package/tools/flattener/test-matrix.js +409 -0
  580. package/tools/flattener/xml.js +82 -0
  581. package/tools/format-workflow-md.js +263 -0
  582. package/tools/lib/xml-utils.js +13 -0
  583. package/tools/maintainer/review-pr-README.md +55 -0
  584. package/tools/maintainer/review-pr.md +242 -0
  585. package/tools/migrate-custom-module-paths.js +124 -0
  586. package/tools/platform-codes.yaml +157 -0
  587. package/tools/schema/agent.js +491 -0
  588. package/tools/validate-agent-schema.js +110 -0
  589. package/tools/validate-doc-links.js +363 -0
  590. package/tools/validate-svg-changes.sh +356 -0
  591. package/website/README.md +76 -0
  592. package/website/astro.config.mjs +228 -0
  593. package/website/public/favicon.ico +0 -0
  594. package/website/public/img/bmad-dark.png +0 -0
  595. package/website/public/img/bmad-light.png +0 -0
  596. package/website/public/img/logo.svg +4 -0
  597. package/website/public/robots.txt +37 -0
  598. package/website/src/components/Banner.astro +59 -0
  599. package/website/src/components/Header.astro +121 -0
  600. package/website/src/components/MobileMenuFooter.astro +53 -0
  601. package/website/src/content/config.ts +6 -0
  602. package/website/src/lib/site-url.js +25 -0
  603. package/website/src/rehype-markdown-links.js +102 -0
  604. package/website/src/styles/custom.css +485 -0
@@ -0,0 +1,2826 @@
1
+ const path = require('node:path');
2
+ const fs = require('fs-extra');
3
+ const chalk = require('chalk');
4
+ const ora = require('ora');
5
+ const { Detector } = require('./detector');
6
+ const { Manifest } = require('./manifest');
7
+ const { ModuleManager } = require('../modules/manager');
8
+ const { IdeManager } = require('../ide/manager');
9
+ const { FileOps } = require('../../../lib/file-ops');
10
+ const { Config } = require('../../../lib/config');
11
+ const { XmlHandler } = require('../../../lib/xml-handler');
12
+ const { DependencyResolver } = require('./dependency-resolver');
13
+ const { ConfigCollector } = require('./config-collector');
14
+ const { getProjectRoot, getSourcePath, getModulePath } = require('../../../lib/project-root');
15
+ const { CLIUtils } = require('../../../lib/cli-utils');
16
+ const { ManifestGenerator } = require('./manifest-generator');
17
+ const { IdeConfigManager } = require('./ide-config-manager');
18
+ const { CustomHandler } = require('../custom/handler');
19
+ const prompts = require('../../../lib/prompts');
20
+
21
+ // BMAD installation folder name - this is constant and should never change
22
+ const BMAD_FOLDER_NAME = '_bmad';
23
+
24
+ class Installer {
25
+ constructor() {
26
+ this.detector = new Detector();
27
+ this.manifest = new Manifest();
28
+ this.moduleManager = new ModuleManager();
29
+ this.ideManager = new IdeManager();
30
+ this.fileOps = new FileOps();
31
+ this.config = new Config();
32
+ this.xmlHandler = new XmlHandler();
33
+ this.dependencyResolver = new DependencyResolver();
34
+ this.configCollector = new ConfigCollector();
35
+ this.ideConfigManager = new IdeConfigManager();
36
+ this.installedFiles = new Set(); // Track all installed files
37
+ this.bmadFolderName = BMAD_FOLDER_NAME;
38
+ }
39
+
40
+ /**
41
+ * Find the bmad installation directory in a project
42
+ * Always uses the standard _bmad folder name
43
+ * Also checks for legacy _cfg folder for migration
44
+ * @param {string} projectDir - Project directory
45
+ * @returns {Promise<Object>} { bmadDir: string, hasLegacyCfg: boolean }
46
+ */
47
+ async findBmadDir(projectDir) {
48
+ const bmadDir = path.join(projectDir, BMAD_FOLDER_NAME);
49
+
50
+ // Check if project directory exists
51
+ if (!(await fs.pathExists(projectDir))) {
52
+ // Project doesn't exist yet, return default
53
+ return { bmadDir, hasLegacyCfg: false };
54
+ }
55
+
56
+ // Check for legacy _cfg folder if bmad directory exists
57
+ let hasLegacyCfg = false;
58
+ if (await fs.pathExists(bmadDir)) {
59
+ const legacyCfgPath = path.join(bmadDir, '_cfg');
60
+ if (await fs.pathExists(legacyCfgPath)) {
61
+ hasLegacyCfg = true;
62
+ }
63
+ }
64
+
65
+ return { bmadDir, hasLegacyCfg };
66
+ }
67
+
68
+ /**
69
+ * @function copyFileWithPlaceholderReplacement
70
+ * @intent Copy files from BMAD source to installation directory with dynamic content transformation
71
+ * @why Enables installation-time customization: _bmad replacement
72
+ * @param {string} sourcePath - Absolute path to source file in BMAD repository
73
+ * @param {string} targetPath - Absolute path to destination file in user's project
74
+ * @param {string} bmadFolderName - User's chosen bmad folder name (default: 'bmad')
75
+ * @returns {Promise<void>} Resolves when file copy and transformation complete
76
+ * @sideeffects Writes transformed file to targetPath, creates parent directories if needed
77
+ * @edgecases Binary files bypass transformation, falls back to raw copy if UTF-8 read fails
78
+ * @calledby installCore(), installModule(), IDE installers during file vendoring
79
+ * @calls fs.readFile(), fs.writeFile(), fs.copy()
80
+ *
81
+
82
+ *
83
+ * 3. Document marker in instructions.md (if applicable)
84
+ */
85
+ async copyFileWithPlaceholderReplacement(sourcePath, targetPath) {
86
+ // List of text file extensions that should have placeholder replacement
87
+ const textExtensions = ['.md', '.yaml', '.yml', '.txt', '.json', '.js', '.ts', '.html', '.css', '.sh', '.bat', '.csv', '.xml'];
88
+ const ext = path.extname(sourcePath).toLowerCase();
89
+
90
+ // Check if this is a text file that might contain placeholders
91
+ if (textExtensions.includes(ext)) {
92
+ try {
93
+ // Read the file content
94
+ let content = await fs.readFile(sourcePath, 'utf8');
95
+
96
+ // Write to target with replaced content
97
+ await fs.ensureDir(path.dirname(targetPath));
98
+ await fs.writeFile(targetPath, content, 'utf8');
99
+ } catch {
100
+ // If reading as text fails (might be binary despite extension), fall back to regular copy
101
+ await fs.copy(sourcePath, targetPath, { overwrite: true });
102
+ }
103
+ } else {
104
+ // Binary file or other file type - just copy directly
105
+ await fs.copy(sourcePath, targetPath, { overwrite: true });
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Collect Tool/IDE configurations after module configuration
111
+ * @param {string} projectDir - Project directory
112
+ * @param {Array} selectedModules - Selected modules from configuration
113
+ * @param {boolean} isFullReinstall - Whether this is a full reinstall
114
+ * @param {Array} previousIdes - Previously configured IDEs (for reinstalls)
115
+ * @param {Array} preSelectedIdes - Pre-selected IDEs from early prompt (optional)
116
+ * @returns {Object} Tool/IDE selection and configurations
117
+ */
118
+ async collectToolConfigurations(projectDir, selectedModules, isFullReinstall = false, previousIdes = [], preSelectedIdes = null) {
119
+ // Use pre-selected IDEs if provided, otherwise prompt
120
+ let toolConfig;
121
+ if (preSelectedIdes === null) {
122
+ // Fallback: prompt for tool selection (backwards compatibility)
123
+ const { UI } = require('../../../lib/ui');
124
+ const ui = new UI();
125
+ toolConfig = await ui.promptToolSelection(projectDir);
126
+ } else {
127
+ // IDEs were already selected during initial prompts
128
+ toolConfig = {
129
+ ides: preSelectedIdes,
130
+ skipIde: !preSelectedIdes || preSelectedIdes.length === 0,
131
+ };
132
+ }
133
+
134
+ // Check for already configured IDEs
135
+ const { Detector } = require('./detector');
136
+ const detector = new Detector();
137
+ const bmadDir = path.join(projectDir, BMAD_FOLDER_NAME);
138
+
139
+ // During full reinstall, use the saved previous IDEs since bmad dir was deleted
140
+ // Otherwise detect from existing installation
141
+ let previouslyConfiguredIdes;
142
+ if (isFullReinstall) {
143
+ // During reinstall, treat all IDEs as new (need configuration)
144
+ previouslyConfiguredIdes = [];
145
+ } else {
146
+ const existingInstall = await detector.detect(bmadDir);
147
+ previouslyConfiguredIdes = existingInstall.ides || [];
148
+ }
149
+
150
+ // Load saved IDE configurations for already-configured IDEs
151
+ const savedIdeConfigs = await this.ideConfigManager.loadAllIdeConfigs(bmadDir);
152
+
153
+ // Collect IDE-specific configurations if any were selected
154
+ const ideConfigurations = {};
155
+
156
+ // First, add saved configs for already-configured IDEs
157
+ for (const ide of toolConfig.ides || []) {
158
+ if (previouslyConfiguredIdes.includes(ide) && savedIdeConfigs[ide]) {
159
+ ideConfigurations[ide] = savedIdeConfigs[ide];
160
+ }
161
+ }
162
+
163
+ if (!toolConfig.skipIde && toolConfig.ides && toolConfig.ides.length > 0) {
164
+ // Determine which IDEs are newly selected (not previously configured)
165
+ const newlySelectedIdes = toolConfig.ides.filter((ide) => !previouslyConfiguredIdes.includes(ide));
166
+
167
+ if (newlySelectedIdes.length > 0) {
168
+ console.log('\n'); // Add spacing before IDE questions
169
+
170
+ for (const ide of newlySelectedIdes) {
171
+ // List of IDEs that have interactive prompts
172
+ //TODO: Why is this here, hardcoding this list here is bad, fix me!
173
+ const needsPrompts = ['claude-code', 'github-copilot', 'roo', 'cline', 'auggie', 'codex', 'qwen', 'gemini', 'rovo-dev'].includes(
174
+ ide,
175
+ );
176
+
177
+ if (needsPrompts) {
178
+ // Get IDE handler and collect configuration
179
+ try {
180
+ // Dynamically load the IDE setup module
181
+ const ideModule = require(`../ide/${ide}`);
182
+
183
+ // Get the setup class (handle different export formats)
184
+ let SetupClass;
185
+ const className =
186
+ ide
187
+ .split('-')
188
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
189
+ .join('') + 'Setup';
190
+
191
+ if (ideModule[className]) {
192
+ SetupClass = ideModule[className];
193
+ } else if (ideModule.default) {
194
+ SetupClass = ideModule.default;
195
+ } else {
196
+ continue;
197
+ }
198
+
199
+ const ideSetup = new SetupClass();
200
+
201
+ // Check if this IDE has a collectConfiguration method
202
+ if (typeof ideSetup.collectConfiguration === 'function') {
203
+ console.log(chalk.cyan(`\nConfiguring ${ide}...`));
204
+ ideConfigurations[ide] = await ideSetup.collectConfiguration({
205
+ selectedModules: selectedModules || [],
206
+ projectDir,
207
+ bmadDir,
208
+ });
209
+ }
210
+ } catch {
211
+ // IDE doesn't have a setup file or collectConfiguration method
212
+ console.warn(chalk.yellow(`Warning: Could not load configuration for ${ide}`));
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ // Log which IDEs are already configured and being kept
219
+ const keptIdes = toolConfig.ides.filter((ide) => previouslyConfiguredIdes.includes(ide));
220
+ if (keptIdes.length > 0) {
221
+ console.log(chalk.dim(`\nKeeping existing configuration for: ${keptIdes.join(', ')}`));
222
+ }
223
+ }
224
+
225
+ return {
226
+ ides: toolConfig.ides,
227
+ skipIde: toolConfig.skipIde,
228
+ configurations: ideConfigurations,
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Main installation method
234
+ * @param {Object} config - Installation configuration
235
+ * @param {string} config.directory - Target directory
236
+ * @param {boolean} config.installCore - Whether to install core
237
+ * @param {string[]} config.modules - Modules to install
238
+ * @param {string[]} config.ides - IDEs to configure
239
+ * @param {boolean} config.skipIde - Skip IDE configuration
240
+ */
241
+ async install(originalConfig) {
242
+ // Clone config to avoid mutating the caller's object
243
+ const config = { ...originalConfig };
244
+
245
+ // Check if core config was already collected in UI
246
+ const hasCoreConfig = config.coreConfig && Object.keys(config.coreConfig).length > 0;
247
+
248
+ // Only display logo if core config wasn't already collected (meaning we're not continuing from UI)
249
+ if (!hasCoreConfig) {
250
+ // Display BMAD logo
251
+ CLIUtils.displayLogo();
252
+
253
+ // Display welcome message
254
+ CLIUtils.displaySection('BMad™ Installation', 'Version ' + require(path.join(getProjectRoot(), 'package.json')).version);
255
+ }
256
+
257
+ // Note: Legacy V4 detection now happens earlier in UI.promptInstall()
258
+ // before any config collection, so we don't need to check again here
259
+
260
+ const projectDir = path.resolve(config.directory);
261
+
262
+ // If core config was pre-collected (from interactive mode), use it
263
+ if (config.coreConfig && Object.keys(config.coreConfig).length > 0) {
264
+ this.configCollector.collectedConfig.core = config.coreConfig;
265
+ // Also store in allAnswers for cross-referencing
266
+ this.configCollector.allAnswers = {};
267
+ for (const [key, value] of Object.entries(config.coreConfig)) {
268
+ this.configCollector.allAnswers[`core_${key}`] = value;
269
+ }
270
+ }
271
+
272
+ // Collect configurations for modules (skip if quick update already collected them)
273
+ let moduleConfigs;
274
+ let customModulePaths = new Map();
275
+
276
+ if (config._quickUpdate) {
277
+ // Quick update already collected all configs, use them directly
278
+ moduleConfigs = this.configCollector.collectedConfig;
279
+
280
+ // For quick update, populate customModulePaths from _customModuleSources
281
+ if (config._customModuleSources) {
282
+ for (const [moduleId, customInfo] of config._customModuleSources) {
283
+ customModulePaths.set(moduleId, customInfo.sourcePath);
284
+ }
285
+ }
286
+ } else {
287
+ // For regular updates (modify flow), check manifest for custom module sources
288
+ if (config._isUpdate && config._existingInstall && config._existingInstall.customModules) {
289
+ for (const customModule of config._existingInstall.customModules) {
290
+ // Ensure we have an absolute sourcePath
291
+ let absoluteSourcePath = customModule.sourcePath;
292
+
293
+ // Check if sourcePath is a cache-relative path (starts with _config)
294
+ if (absoluteSourcePath && absoluteSourcePath.startsWith('_config')) {
295
+ // Convert cache-relative path to absolute path
296
+ absoluteSourcePath = path.join(bmadDir, absoluteSourcePath);
297
+ }
298
+ // If no sourcePath but we have relativePath, convert it
299
+ else if (!absoluteSourcePath && customModule.relativePath) {
300
+ // relativePath is relative to the project root (parent of bmad dir)
301
+ absoluteSourcePath = path.resolve(projectDir, customModule.relativePath);
302
+ }
303
+ // Ensure sourcePath is absolute for anything else
304
+ else if (absoluteSourcePath && !path.isAbsolute(absoluteSourcePath)) {
305
+ absoluteSourcePath = path.resolve(absoluteSourcePath);
306
+ }
307
+
308
+ if (absoluteSourcePath) {
309
+ customModulePaths.set(customModule.id, absoluteSourcePath);
310
+ }
311
+ }
312
+ }
313
+
314
+ // Build custom module paths map from customContent
315
+
316
+ // Handle selectedFiles (from existing install path or manual directory input)
317
+ if (config.customContent && config.customContent.selected && config.customContent.selectedFiles) {
318
+ const customHandler = new CustomHandler();
319
+ for (const customFile of config.customContent.selectedFiles) {
320
+ const customInfo = await customHandler.getCustomInfo(customFile, path.resolve(config.directory));
321
+ if (customInfo && customInfo.id) {
322
+ customModulePaths.set(customInfo.id, customInfo.path);
323
+ }
324
+ }
325
+ }
326
+
327
+ // Handle new custom content sources from UI
328
+ if (config.customContent && config.customContent.sources) {
329
+ for (const source of config.customContent.sources) {
330
+ customModulePaths.set(source.id, source.path);
331
+ }
332
+ }
333
+
334
+ // Handle cachedModules (from new install path where modules are cached)
335
+ // Only include modules that were actually selected for installation
336
+ if (config.customContent && config.customContent.cachedModules) {
337
+ // Get selected cached module IDs (if available)
338
+ const selectedCachedIds = config.customContent.selectedCachedModules || [];
339
+ // If no selection info, include all cached modules (for backward compatibility)
340
+ const shouldIncludeAll = selectedCachedIds.length === 0 && config.customContent.selected;
341
+
342
+ for (const cachedModule of config.customContent.cachedModules) {
343
+ // For cached modules, the path is the cachePath which contains the module.yaml
344
+ if (
345
+ cachedModule.id &&
346
+ cachedModule.cachePath && // Include if selected or if we should include all
347
+ (shouldIncludeAll || selectedCachedIds.includes(cachedModule.id))
348
+ ) {
349
+ customModulePaths.set(cachedModule.id, cachedModule.cachePath);
350
+ }
351
+ }
352
+ }
353
+
354
+ // Get list of all modules including custom modules
355
+ // Order: core first, then official modules, then custom modules
356
+ const allModulesForConfig = ['core'];
357
+
358
+ // Add official modules (excluding core and any custom modules)
359
+ const officialModules = (config.modules || []).filter((m) => m !== 'core' && !customModulePaths.has(m));
360
+ allModulesForConfig.push(...officialModules);
361
+
362
+ // Add custom modules at the end
363
+ for (const [moduleId] of customModulePaths) {
364
+ if (!allModulesForConfig.includes(moduleId)) {
365
+ allModulesForConfig.push(moduleId);
366
+ }
367
+ }
368
+
369
+ // Check if core was already collected in UI
370
+ if (config.coreConfig && Object.keys(config.coreConfig).length > 0) {
371
+ // Core already collected, skip it in config collection
372
+ const modulesWithoutCore = allModulesForConfig.filter((m) => m !== 'core');
373
+ moduleConfigs = await this.configCollector.collectAllConfigurations(modulesWithoutCore, path.resolve(config.directory), {
374
+ customModulePaths,
375
+ });
376
+ } else {
377
+ // Core not collected yet, include it
378
+ moduleConfigs = await this.configCollector.collectAllConfigurations(allModulesForConfig, path.resolve(config.directory), {
379
+ customModulePaths,
380
+ });
381
+ }
382
+ }
383
+
384
+ // Set bmad folder name on module manager and IDE manager for placeholder replacement
385
+ this.moduleManager.setBmadFolderName(BMAD_FOLDER_NAME);
386
+ this.moduleManager.setCoreConfig(moduleConfigs.core || {});
387
+ this.moduleManager.setCustomModulePaths(customModulePaths);
388
+ this.ideManager.setBmadFolderName(BMAD_FOLDER_NAME);
389
+
390
+ // Tool selection will be collected after we determine if it's a reinstall/update/new install
391
+
392
+ const spinner = ora('Preparing installation...').start();
393
+
394
+ try {
395
+ // Resolve target directory (path.resolve handles platform differences)
396
+ const projectDir = path.resolve(config.directory);
397
+
398
+ // Always use the standard _bmad folder name
399
+ const bmadDir = path.join(projectDir, BMAD_FOLDER_NAME);
400
+
401
+ // Create a project directory if it doesn't exist (user already confirmed)
402
+ if (!(await fs.pathExists(projectDir))) {
403
+ spinner.text = 'Creating installation directory...';
404
+ try {
405
+ // fs.ensureDir handles platform-specific directory creation
406
+ // It will recursively create all necessary parent directories
407
+ await fs.ensureDir(projectDir);
408
+ } catch (error) {
409
+ spinner.fail('Failed to create installation directory');
410
+ console.error(chalk.red(`Error: ${error.message}`));
411
+ // More detailed error for common issues
412
+ if (error.code === 'EACCES') {
413
+ console.error(chalk.red('Permission denied. Check parent directory permissions.'));
414
+ } else if (error.code === 'ENOSPC') {
415
+ console.error(chalk.red('No space left on device.'));
416
+ }
417
+ throw new Error(`Cannot create directory: ${projectDir}`);
418
+ }
419
+ }
420
+
421
+ // Check existing installation
422
+ spinner.text = 'Checking for existing installation...';
423
+ const existingInstall = await this.detector.detect(bmadDir);
424
+
425
+ if (existingInstall.installed && !config.force && !config._quickUpdate) {
426
+ spinner.stop();
427
+
428
+ // Check if user already decided what to do (from early menu in ui.js)
429
+ let action = null;
430
+ if (config.actionType === 'update') {
431
+ action = 'update';
432
+ } else {
433
+ // Fallback: Ask the user (backwards compatibility for other code paths)
434
+ console.log(chalk.yellow('\n⚠️ Existing BMAD installation detected'));
435
+ console.log(chalk.dim(` Location: ${bmadDir}`));
436
+ console.log(chalk.dim(` Version: ${existingInstall.version}`));
437
+
438
+ const promptResult = await this.promptUpdateAction();
439
+ action = promptResult.action;
440
+ }
441
+
442
+ if (action === 'update') {
443
+ // Store that we're updating for later processing
444
+ config._isUpdate = true;
445
+ config._existingInstall = existingInstall;
446
+
447
+ // Detect modules that were previously installed but are NOT in the new selection (to be removed)
448
+ const previouslyInstalledModules = new Set(existingInstall.modules.map((m) => m.id));
449
+ const newlySelectedModules = new Set(config.modules || []);
450
+
451
+ // Find modules to remove (installed but not in new selection)
452
+ // Exclude 'core' from being removable
453
+ const modulesToRemove = [...previouslyInstalledModules].filter((m) => !newlySelectedModules.has(m) && m !== 'core');
454
+
455
+ // If there are modules to remove, ask for confirmation
456
+ if (modulesToRemove.length > 0) {
457
+ const prompts = require('../../../lib/prompts');
458
+ spinner.stop();
459
+
460
+ console.log('');
461
+ console.log(chalk.yellow.bold('⚠️ Modules to be removed:'));
462
+ for (const moduleId of modulesToRemove) {
463
+ const moduleInfo = existingInstall.modules.find((m) => m.id === moduleId);
464
+ const displayName = moduleInfo?.name || moduleId;
465
+ const modulePath = path.join(bmadDir, moduleId);
466
+ console.log(chalk.red(` - ${displayName} (${modulePath})`));
467
+ }
468
+ console.log('');
469
+
470
+ const confirmRemoval = await prompts.confirm({
471
+ message: `Remove ${modulesToRemove.length} module(s) from BMAD installation?`,
472
+ default: false,
473
+ });
474
+
475
+ if (confirmRemoval) {
476
+ // Remove module folders
477
+ for (const moduleId of modulesToRemove) {
478
+ const modulePath = path.join(bmadDir, moduleId);
479
+ try {
480
+ if (await fs.pathExists(modulePath)) {
481
+ await fs.remove(modulePath);
482
+ console.log(chalk.dim(` ✓ Removed: ${moduleId}`));
483
+ }
484
+ } catch (error) {
485
+ console.warn(chalk.yellow(` Warning: Failed to remove ${moduleId}: ${error.message}`));
486
+ }
487
+ }
488
+ console.log(chalk.green(` ✓ Removed ${modulesToRemove.length} module(s)`));
489
+ } else {
490
+ console.log(chalk.dim(' → Module removal cancelled'));
491
+ // Add the modules back to the selection since user cancelled removal
492
+ for (const moduleId of modulesToRemove) {
493
+ if (!config.modules) config.modules = [];
494
+ config.modules.push(moduleId);
495
+ }
496
+ }
497
+
498
+ spinner.start('Preparing update...');
499
+ }
500
+
501
+ // Detect custom and modified files BEFORE updating (compare current files vs files-manifest.csv)
502
+ const existingFilesManifest = await this.readFilesManifest(bmadDir);
503
+ const { customFiles, modifiedFiles } = await this.detectCustomFiles(bmadDir, existingFilesManifest);
504
+
505
+ config._customFiles = customFiles;
506
+ config._modifiedFiles = modifiedFiles;
507
+
508
+ // Preserve existing core configuration during updates
509
+ // Read the current core config.yaml to maintain user's settings
510
+ const coreConfigPath = path.join(bmadDir, 'core', 'config.yaml');
511
+ if ((await fs.pathExists(coreConfigPath)) && (!config.coreConfig || Object.keys(config.coreConfig).length === 0)) {
512
+ try {
513
+ const yaml = require('yaml');
514
+ const coreConfigContent = await fs.readFile(coreConfigPath, 'utf8');
515
+ const existingCoreConfig = yaml.parse(coreConfigContent);
516
+
517
+ // Store in config.coreConfig so it's preserved through the installation
518
+ config.coreConfig = existingCoreConfig;
519
+
520
+ // Also store in configCollector for use during config collection
521
+ this.configCollector.collectedConfig.core = existingCoreConfig;
522
+ } catch (error) {
523
+ console.warn(chalk.yellow(`Warning: Could not read existing core config: ${error.message}`));
524
+ }
525
+ }
526
+
527
+ // Also check cache directory for custom modules (like quick update does)
528
+ const cacheDir = path.join(bmadDir, '_config', 'custom');
529
+ if (await fs.pathExists(cacheDir)) {
530
+ const cachedModules = await fs.readdir(cacheDir, { withFileTypes: true });
531
+
532
+ for (const cachedModule of cachedModules) {
533
+ if (cachedModule.isDirectory()) {
534
+ const moduleId = cachedModule.name;
535
+
536
+ // Skip if we already have this module from manifest
537
+ if (customModulePaths.has(moduleId)) {
538
+ continue;
539
+ }
540
+
541
+ // Check if this is an external official module - skip cache for those
542
+ const isExternal = await this.moduleManager.isExternalModule(moduleId);
543
+ if (isExternal) {
544
+ // External modules are handled via cloneExternalModule, not from cache
545
+ continue;
546
+ }
547
+
548
+ const cachedPath = path.join(cacheDir, moduleId);
549
+
550
+ // Check if this is actually a custom module (has module.yaml)
551
+ const moduleYamlPath = path.join(cachedPath, 'module.yaml');
552
+ if (await fs.pathExists(moduleYamlPath)) {
553
+ customModulePaths.set(moduleId, cachedPath);
554
+ }
555
+ }
556
+ }
557
+
558
+ // Update module manager with the new custom module paths from cache
559
+ this.moduleManager.setCustomModulePaths(customModulePaths);
560
+ }
561
+
562
+ // If there are custom files, back them up temporarily
563
+ if (customFiles.length > 0) {
564
+ const tempBackupDir = path.join(projectDir, '_bmad-custom-backup-temp');
565
+ await fs.ensureDir(tempBackupDir);
566
+
567
+ spinner.start(`Backing up ${customFiles.length} custom files...`);
568
+ for (const customFile of customFiles) {
569
+ const relativePath = path.relative(bmadDir, customFile);
570
+ const backupPath = path.join(tempBackupDir, relativePath);
571
+ await fs.ensureDir(path.dirname(backupPath));
572
+ await fs.copy(customFile, backupPath);
573
+ }
574
+ spinner.succeed(`Backed up ${customFiles.length} custom files`);
575
+
576
+ config._tempBackupDir = tempBackupDir;
577
+ }
578
+
579
+ // For modified files, back them up to temp directory (will be restored as .bak files after install)
580
+ if (modifiedFiles.length > 0) {
581
+ const tempModifiedBackupDir = path.join(projectDir, '_bmad-modified-backup-temp');
582
+ await fs.ensureDir(tempModifiedBackupDir);
583
+
584
+ spinner.start(`Backing up ${modifiedFiles.length} modified files...`);
585
+ for (const modifiedFile of modifiedFiles) {
586
+ const relativePath = path.relative(bmadDir, modifiedFile.path);
587
+ const tempBackupPath = path.join(tempModifiedBackupDir, relativePath);
588
+ await fs.ensureDir(path.dirname(tempBackupPath));
589
+ await fs.copy(modifiedFile.path, tempBackupPath, { overwrite: true });
590
+ }
591
+ spinner.succeed(`Backed up ${modifiedFiles.length} modified files`);
592
+
593
+ config._tempModifiedBackupDir = tempModifiedBackupDir;
594
+ }
595
+ }
596
+ } else if (existingInstall.installed && config._quickUpdate) {
597
+ // Quick update mode - automatically treat as update without prompting
598
+ spinner.text = 'Preparing quick update...';
599
+ config._isUpdate = true;
600
+ config._existingInstall = existingInstall;
601
+
602
+ // Detect custom and modified files BEFORE updating
603
+ const existingFilesManifest = await this.readFilesManifest(bmadDir);
604
+ const { customFiles, modifiedFiles } = await this.detectCustomFiles(bmadDir, existingFilesManifest);
605
+
606
+ config._customFiles = customFiles;
607
+ config._modifiedFiles = modifiedFiles;
608
+
609
+ // Also check cache directory for custom modules (like quick update does)
610
+ const cacheDir = path.join(bmadDir, '_config', 'custom');
611
+ if (await fs.pathExists(cacheDir)) {
612
+ const cachedModules = await fs.readdir(cacheDir, { withFileTypes: true });
613
+
614
+ for (const cachedModule of cachedModules) {
615
+ if (cachedModule.isDirectory()) {
616
+ const moduleId = cachedModule.name;
617
+
618
+ // Skip if we already have this module from manifest
619
+ if (customModulePaths.has(moduleId)) {
620
+ continue;
621
+ }
622
+
623
+ // Check if this is an external official module - skip cache for those
624
+ const isExternal = await this.moduleManager.isExternalModule(moduleId);
625
+ if (isExternal) {
626
+ // External modules are handled via cloneExternalModule, not from cache
627
+ continue;
628
+ }
629
+
630
+ const cachedPath = path.join(cacheDir, moduleId);
631
+
632
+ // Check if this is actually a custom module (has module.yaml)
633
+ const moduleYamlPath = path.join(cachedPath, 'module.yaml');
634
+ if (await fs.pathExists(moduleYamlPath)) {
635
+ customModulePaths.set(moduleId, cachedPath);
636
+ }
637
+ }
638
+ }
639
+
640
+ // Update module manager with the new custom module paths from cache
641
+ this.moduleManager.setCustomModulePaths(customModulePaths);
642
+ }
643
+
644
+ // Back up custom files
645
+ if (customFiles.length > 0) {
646
+ const tempBackupDir = path.join(projectDir, '_bmad-custom-backup-temp');
647
+ await fs.ensureDir(tempBackupDir);
648
+
649
+ spinner.start(`Backing up ${customFiles.length} custom files...`);
650
+ for (const customFile of customFiles) {
651
+ const relativePath = path.relative(bmadDir, customFile);
652
+ const backupPath = path.join(tempBackupDir, relativePath);
653
+ await fs.ensureDir(path.dirname(backupPath));
654
+ await fs.copy(customFile, backupPath);
655
+ }
656
+ spinner.succeed(`Backed up ${customFiles.length} custom files`);
657
+ config._tempBackupDir = tempBackupDir;
658
+ }
659
+
660
+ // Back up modified files
661
+ if (modifiedFiles.length > 0) {
662
+ const tempModifiedBackupDir = path.join(projectDir, '_bmad-modified-backup-temp');
663
+ await fs.ensureDir(tempModifiedBackupDir);
664
+
665
+ spinner.start(`Backing up ${modifiedFiles.length} modified files...`);
666
+ for (const modifiedFile of modifiedFiles) {
667
+ const relativePath = path.relative(bmadDir, modifiedFile.path);
668
+ const tempBackupPath = path.join(tempModifiedBackupDir, relativePath);
669
+ await fs.ensureDir(path.dirname(tempBackupPath));
670
+ await fs.copy(modifiedFile.path, tempBackupPath, { overwrite: true });
671
+ }
672
+ spinner.succeed(`Backed up ${modifiedFiles.length} modified files`);
673
+ config._tempModifiedBackupDir = tempModifiedBackupDir;
674
+ }
675
+ }
676
+
677
+ // Now collect tool configurations after we know if it's a reinstall
678
+ // Skip for quick update since we already have the IDE list
679
+ spinner.stop();
680
+ let toolSelection;
681
+ if (config._quickUpdate) {
682
+ // Quick update already has IDEs configured, use saved configurations
683
+ const preConfiguredIdes = {};
684
+ const savedIdeConfigs = config._savedIdeConfigs || {};
685
+
686
+ for (const ide of config.ides || []) {
687
+ // Use saved config if available, otherwise mark as already configured (legacy)
688
+ if (savedIdeConfigs[ide]) {
689
+ preConfiguredIdes[ide] = savedIdeConfigs[ide];
690
+ } else {
691
+ preConfiguredIdes[ide] = { _alreadyConfigured: true };
692
+ }
693
+ }
694
+ toolSelection = {
695
+ ides: config.ides || [],
696
+ skipIde: !config.ides || config.ides.length === 0,
697
+ configurations: preConfiguredIdes,
698
+ };
699
+ } else {
700
+ // Pass pre-selected IDEs from early prompt (if available)
701
+ // This allows IDE selection to happen before file copying, improving UX
702
+ const preSelectedIdes = config.ides && config.ides.length > 0 ? config.ides : null;
703
+ toolSelection = await this.collectToolConfigurations(
704
+ path.resolve(config.directory),
705
+ config.modules,
706
+ config._isFullReinstall || false,
707
+ config._previouslyConfiguredIdes || [],
708
+ preSelectedIdes,
709
+ );
710
+ }
711
+
712
+ // Merge tool selection into config (for both quick update and regular flow)
713
+ config.ides = toolSelection.ides;
714
+ config.skipIde = toolSelection.skipIde;
715
+ const ideConfigurations = toolSelection.configurations;
716
+
717
+ // Add spacing after prompts before installation progress
718
+ console.log('');
719
+
720
+ if (spinner.isSpinning) {
721
+ spinner.text = 'Continuing installation...';
722
+ } else {
723
+ spinner.start('Continuing installation...');
724
+ }
725
+
726
+ // Create bmad directory structure
727
+ spinner.text = 'Creating directory structure...';
728
+ await this.createDirectoryStructure(bmadDir);
729
+
730
+ // Cache custom modules if any
731
+ if (customModulePaths && customModulePaths.size > 0) {
732
+ spinner.text = 'Caching custom modules...';
733
+ const { CustomModuleCache } = require('./custom-module-cache');
734
+ const customCache = new CustomModuleCache(bmadDir);
735
+
736
+ for (const [moduleId, sourcePath] of customModulePaths) {
737
+ const cachedInfo = await customCache.cacheModule(moduleId, sourcePath, {
738
+ sourcePath: sourcePath, // Store original path for updates
739
+ });
740
+
741
+ // Update the customModulePaths to use the cached location
742
+ customModulePaths.set(moduleId, cachedInfo.cachePath);
743
+ }
744
+
745
+ // Update module manager with the cached paths
746
+ this.moduleManager.setCustomModulePaths(customModulePaths);
747
+ spinner.succeed('Custom modules cached');
748
+ }
749
+
750
+ const projectRoot = getProjectRoot();
751
+
752
+ // Step 1: Install core module first (if requested)
753
+ if (config.installCore) {
754
+ spinner.start('Installing BMAD core...');
755
+ await this.installCoreWithDependencies(bmadDir, { core: {} });
756
+ spinner.succeed('Core installed');
757
+
758
+ // Generate core config file
759
+ await this.generateModuleConfigs(bmadDir, { core: config.coreConfig || {} });
760
+ }
761
+
762
+ // Custom content is already handled in UI before module selection
763
+ let finalCustomContent = config.customContent;
764
+
765
+ // Step 3: Prepare modules list including cached custom modules
766
+ let allModules = [...(config.modules || [])];
767
+
768
+ // During quick update, we might have custom module sources from the manifest
769
+ if (config._customModuleSources) {
770
+ // Add custom modules from stored sources
771
+ for (const [moduleId, customInfo] of config._customModuleSources) {
772
+ if (!allModules.includes(moduleId) && (await fs.pathExists(customInfo.sourcePath))) {
773
+ allModules.push(moduleId);
774
+ }
775
+ }
776
+ }
777
+
778
+ // Add cached custom modules
779
+ if (finalCustomContent && finalCustomContent.cachedModules) {
780
+ for (const cachedModule of finalCustomContent.cachedModules) {
781
+ if (!allModules.includes(cachedModule.id)) {
782
+ allModules.push(cachedModule.id);
783
+ }
784
+ }
785
+ }
786
+
787
+ // Regular custom content from user input (non-cached)
788
+ if (finalCustomContent && finalCustomContent.selected && finalCustomContent.selectedFiles) {
789
+ // Add custom modules to the installation list
790
+ const customHandler = new CustomHandler();
791
+ for (const customFile of finalCustomContent.selectedFiles) {
792
+ const customInfo = await customHandler.getCustomInfo(customFile, projectDir);
793
+ if (customInfo && customInfo.id) {
794
+ allModules.push(customInfo.id);
795
+ }
796
+ }
797
+ }
798
+
799
+ // Don't include core again if already installed
800
+ if (config.installCore) {
801
+ allModules = allModules.filter((m) => m !== 'core');
802
+ }
803
+
804
+ const modulesToInstall = allModules;
805
+
806
+ // For dependency resolution, we only need regular modules (not custom modules)
807
+ // Custom modules are already installed in _bmad and don't need dependency resolution from source
808
+ const regularModulesForResolution = allModules.filter((module) => {
809
+ // Check if this is a custom module
810
+ const isCustom =
811
+ customModulePaths.has(module) ||
812
+ (finalCustomContent && finalCustomContent.cachedModules && finalCustomContent.cachedModules.some((cm) => cm.id === module)) ||
813
+ (finalCustomContent &&
814
+ finalCustomContent.selected &&
815
+ finalCustomContent.selectedFiles &&
816
+ finalCustomContent.selectedFiles.some((f) => f.includes(module)));
817
+ return !isCustom;
818
+ });
819
+
820
+ // For dependency resolution, we need to pass the project root
821
+ // Create a temporary module manager that knows about custom content locations
822
+ const tempModuleManager = new ModuleManager({
823
+ bmadDir: bmadDir, // Pass bmadDir so we can check cache
824
+ });
825
+
826
+ const resolution = await this.dependencyResolver.resolve(projectRoot, regularModulesForResolution, {
827
+ verbose: config.verbose,
828
+ moduleManager: tempModuleManager,
829
+ });
830
+
831
+ spinner.succeed('Dependencies resolved');
832
+
833
+ // Install modules with their dependencies
834
+ if (allModules && allModules.length > 0) {
835
+ const installedModuleNames = new Set();
836
+
837
+ for (const moduleName of allModules) {
838
+ // Skip if already installed
839
+ if (installedModuleNames.has(moduleName)) {
840
+ continue;
841
+ }
842
+ installedModuleNames.add(moduleName);
843
+
844
+ // Show appropriate message based on whether this is a quick update
845
+ const isQuickUpdate = config._quickUpdate || false;
846
+ spinner.start(`${isQuickUpdate ? 'Updating' : 'Installing'} module: ${moduleName}...`);
847
+
848
+ // Check if this is a custom module
849
+ let isCustomModule = false;
850
+ let customInfo = null;
851
+ let useCache = false;
852
+
853
+ // First check if we have a cached version
854
+ if (finalCustomContent && finalCustomContent.cachedModules) {
855
+ const cachedModule = finalCustomContent.cachedModules.find((m) => m.id === moduleName);
856
+ if (cachedModule) {
857
+ isCustomModule = true;
858
+ customInfo = {
859
+ id: moduleName,
860
+ path: cachedModule.cachePath,
861
+ config: {},
862
+ };
863
+ useCache = true;
864
+ }
865
+ }
866
+
867
+ // Then check if we have custom module sources from the manifest (for quick update)
868
+ if (!isCustomModule && config._customModuleSources && config._customModuleSources.has(moduleName)) {
869
+ customInfo = config._customModuleSources.get(moduleName);
870
+ isCustomModule = true;
871
+
872
+ // Check if this is a cached module (source path starts with _config)
873
+ if (
874
+ customInfo.sourcePath &&
875
+ (customInfo.sourcePath.startsWith('_config') || customInfo.sourcePath.includes('_config/custom'))
876
+ ) {
877
+ useCache = true;
878
+ // Make sure we have the right path structure
879
+ if (!customInfo.path) {
880
+ customInfo.path = customInfo.sourcePath;
881
+ }
882
+ }
883
+ }
884
+
885
+ // Finally check regular custom content
886
+ if (!isCustomModule && finalCustomContent && finalCustomContent.selected && finalCustomContent.selectedFiles) {
887
+ const customHandler = new CustomHandler();
888
+ for (const customFile of finalCustomContent.selectedFiles) {
889
+ const info = await customHandler.getCustomInfo(customFile, projectDir);
890
+ if (info && info.id === moduleName) {
891
+ isCustomModule = true;
892
+ customInfo = info;
893
+ break;
894
+ }
895
+ }
896
+ }
897
+
898
+ if (isCustomModule && customInfo) {
899
+ // Custom modules are now installed via ModuleManager just like standard modules
900
+ // The custom module path should already be in customModulePaths from earlier setup
901
+ if (!customModulePaths.has(moduleName) && customInfo.path) {
902
+ customModulePaths.set(moduleName, customInfo.path);
903
+ this.moduleManager.setCustomModulePaths(customModulePaths);
904
+ }
905
+
906
+ const collectedModuleConfig = moduleConfigs[moduleName] || {};
907
+
908
+ // Use ModuleManager to install the custom module
909
+ await this.moduleManager.install(
910
+ moduleName,
911
+ bmadDir,
912
+ (filePath) => {
913
+ this.installedFiles.add(filePath);
914
+ },
915
+ {
916
+ isCustom: true,
917
+ moduleConfig: collectedModuleConfig,
918
+ isQuickUpdate: config._quickUpdate || false,
919
+ installer: this,
920
+ },
921
+ );
922
+
923
+ // Create module config (include collected config from module.yaml prompts)
924
+ await this.generateModuleConfigs(bmadDir, {
925
+ [moduleName]: { ...config.coreConfig, ...customInfo.config, ...collectedModuleConfig },
926
+ });
927
+ } else {
928
+ // Regular module installation
929
+ // Special case for core module
930
+ if (moduleName === 'core') {
931
+ await this.installCoreWithDependencies(bmadDir, resolution.byModule[moduleName]);
932
+ } else {
933
+ await this.installModuleWithDependencies(moduleName, bmadDir, resolution.byModule[moduleName]);
934
+ }
935
+ }
936
+
937
+ spinner.succeed(`Module ${isQuickUpdate ? 'updated' : 'installed'}: ${moduleName}`);
938
+ }
939
+
940
+ // Install partial modules (only dependencies)
941
+ for (const [module, files] of Object.entries(resolution.byModule)) {
942
+ if (!allModules.includes(module) && module !== 'core') {
943
+ const totalFiles =
944
+ files.agents.length +
945
+ files.tasks.length +
946
+ files.tools.length +
947
+ files.templates.length +
948
+ files.data.length +
949
+ files.other.length;
950
+ if (totalFiles > 0) {
951
+ spinner.start(`Installing ${module} dependencies...`);
952
+ await this.installPartialModule(module, bmadDir, files);
953
+ spinner.succeed(`${module} dependencies installed`);
954
+ }
955
+ }
956
+ }
957
+ }
958
+
959
+ // All content is now installed as modules - no separate custom content handling needed
960
+
961
+ // Generate clean config.yaml files for each installed module
962
+ spinner.start('Generating module configurations...');
963
+ await this.generateModuleConfigs(bmadDir, moduleConfigs);
964
+ spinner.succeed('Module configurations generated');
965
+
966
+ // Create agent configuration files
967
+ // Note: Legacy createAgentConfigs removed - using YAML customize system instead
968
+ // Customize templates are now created in processAgentFiles when building YAML agents
969
+
970
+ // Pre-register manifest files that will be created (except files-manifest.csv to avoid recursion)
971
+ const cfgDir = path.join(bmadDir, '_config');
972
+ this.installedFiles.add(path.join(cfgDir, 'manifest.yaml'));
973
+ this.installedFiles.add(path.join(cfgDir, 'workflow-manifest.csv'));
974
+ this.installedFiles.add(path.join(cfgDir, 'agent-manifest.csv'));
975
+ this.installedFiles.add(path.join(cfgDir, 'task-manifest.csv'));
976
+
977
+ // Generate CSV manifests for workflows, agents, tasks AND ALL FILES with hashes BEFORE IDE setup
978
+ // This must happen BEFORE mergeModuleHelpCatalogs because it depends on agent-manifest.csv
979
+ spinner.start('Generating workflow and agent manifests...');
980
+ const manifestGen = new ManifestGenerator();
981
+
982
+ // For quick update, we need ALL installed modules in the manifest
983
+ // Not just the ones being updated
984
+ const allModulesForManifest = config._quickUpdate
985
+ ? config._existingModules || allModules || []
986
+ : config._preserveModules
987
+ ? [...allModules, ...config._preserveModules]
988
+ : allModules || [];
989
+
990
+ // For regular installs (including when called from quick update), use what we have
991
+ let modulesForCsvPreserve;
992
+ if (config._quickUpdate) {
993
+ // Quick update - use existing modules or fall back to modules being updated
994
+ modulesForCsvPreserve = config._existingModules || allModules || [];
995
+ } else {
996
+ // Regular install - use the modules we're installing plus any preserved ones
997
+ modulesForCsvPreserve = config._preserveModules ? [...allModules, ...config._preserveModules] : allModules;
998
+ }
999
+
1000
+ const manifestStats = await manifestGen.generateManifests(bmadDir, allModulesForManifest, [...this.installedFiles], {
1001
+ ides: config.ides || [],
1002
+ preservedModules: modulesForCsvPreserve, // Scan these from installed bmad/ dir
1003
+ });
1004
+
1005
+ // Custom modules are now included in the main modules list - no separate tracking needed
1006
+
1007
+ spinner.succeed(
1008
+ `Manifests generated: ${manifestStats.workflows} workflows, ${manifestStats.agents} agents, ${manifestStats.tasks} tasks, ${manifestStats.tools} tools, ${manifestStats.files} files`,
1009
+ );
1010
+
1011
+ // Merge all module-help.csv files into bmad-help.csv
1012
+ // This must happen AFTER generateManifests because it depends on agent-manifest.csv
1013
+ spinner.start('Generating workflow help catalog...');
1014
+ await this.mergeModuleHelpCatalogs(bmadDir);
1015
+ spinner.succeed('Workflow help catalog generated');
1016
+
1017
+ // Configure IDEs and copy documentation
1018
+ if (!config.skipIde && config.ides && config.ides.length > 0) {
1019
+ // Filter out any undefined/null values from the IDE list
1020
+ const validIdes = config.ides.filter((ide) => ide && typeof ide === 'string');
1021
+
1022
+ if (validIdes.length === 0) {
1023
+ console.log(chalk.yellow('⚠️ No valid IDEs selected. Skipping IDE configuration.'));
1024
+ } else {
1025
+ // Check if any IDE might need prompting (no pre-collected config)
1026
+ const needsPrompting = validIdes.some((ide) => !ideConfigurations[ide]);
1027
+
1028
+ if (!needsPrompting) {
1029
+ spinner.start('Configuring IDEs...');
1030
+ }
1031
+
1032
+ // Temporarily suppress console output if not verbose
1033
+ const originalLog = console.log;
1034
+ if (!config.verbose) {
1035
+ console.log = () => {};
1036
+ }
1037
+
1038
+ for (const ide of validIdes) {
1039
+ // Only show spinner if we have pre-collected config (no prompts expected)
1040
+ if (ideConfigurations[ide] && !needsPrompting) {
1041
+ spinner.text = `Configuring ${ide}...`;
1042
+ } else if (!ideConfigurations[ide]) {
1043
+ // Stop spinner before prompting
1044
+ if (spinner.isSpinning) {
1045
+ spinner.stop();
1046
+ }
1047
+ console.log(chalk.cyan(`\nConfiguring ${ide}...`));
1048
+ }
1049
+
1050
+ // Pass pre-collected configuration to avoid re-prompting
1051
+ await this.ideManager.setup(ide, projectDir, bmadDir, {
1052
+ selectedModules: allModules || [],
1053
+ preCollectedConfig: ideConfigurations[ide] || null,
1054
+ verbose: config.verbose,
1055
+ });
1056
+
1057
+ // Save IDE configuration for future updates
1058
+ if (ideConfigurations[ide] && !ideConfigurations[ide]._alreadyConfigured) {
1059
+ await this.ideConfigManager.saveIdeConfig(bmadDir, ide, ideConfigurations[ide]);
1060
+ }
1061
+
1062
+ // Restart spinner if we stopped it
1063
+ if (!ideConfigurations[ide] && !spinner.isSpinning) {
1064
+ spinner.start('Configuring IDEs...');
1065
+ }
1066
+ }
1067
+
1068
+ // Restore console.log
1069
+ console.log = originalLog;
1070
+
1071
+ if (spinner.isSpinning) {
1072
+ spinner.succeed(`Configured: ${validIdes.join(', ')}`);
1073
+ } else {
1074
+ console.log(chalk.green(`✓ Configured: ${validIdes.join(', ')}`));
1075
+ }
1076
+ }
1077
+ }
1078
+
1079
+ // Run module-specific installers after IDE setup
1080
+ spinner.start('Running module-specific installers...');
1081
+
1082
+ // Create a conditional logger based on verbose mode
1083
+ const verboseMode = process.env.BMAD_VERBOSE_INSTALL === 'true' || config.verbose;
1084
+ const moduleLogger = {
1085
+ log: (msg) => (verboseMode ? console.log(msg) : {}), // Only log in verbose mode
1086
+ error: (msg) => console.error(msg), // Always show errors
1087
+ warn: (msg) => console.warn(msg), // Always show warnings
1088
+ };
1089
+
1090
+ // Run core module installer if core was installed
1091
+ if (config.installCore || resolution.byModule.core) {
1092
+ spinner.text = 'Running core module installer...';
1093
+
1094
+ await this.moduleManager.runModuleInstaller('core', bmadDir, {
1095
+ installedIDEs: config.ides || [],
1096
+ moduleConfig: moduleConfigs.core || {},
1097
+ coreConfig: moduleConfigs.core || {},
1098
+ logger: moduleLogger,
1099
+ });
1100
+ }
1101
+
1102
+ // Run installers for user-selected modules
1103
+ if (config.modules && config.modules.length > 0) {
1104
+ for (const moduleName of config.modules) {
1105
+ spinner.text = `Running ${moduleName} module installer...`;
1106
+
1107
+ // Pass installed IDEs and module config to module installer
1108
+ await this.moduleManager.runModuleInstaller(moduleName, bmadDir, {
1109
+ installedIDEs: config.ides || [],
1110
+ moduleConfig: moduleConfigs[moduleName] || {},
1111
+ coreConfig: moduleConfigs.core || {},
1112
+ logger: moduleLogger,
1113
+ });
1114
+ }
1115
+ }
1116
+
1117
+ spinner.succeed('Module-specific installers completed');
1118
+
1119
+ // Note: Manifest files are already created by ManifestGenerator above
1120
+ // No need to create legacy manifest.csv anymore
1121
+
1122
+ // If this was an update, restore custom files
1123
+ let customFiles = [];
1124
+ let modifiedFiles = [];
1125
+ if (config._isUpdate) {
1126
+ if (config._customFiles && config._customFiles.length > 0) {
1127
+ spinner.start(`Restoring ${config._customFiles.length} custom files...`);
1128
+
1129
+ for (const originalPath of config._customFiles) {
1130
+ const relativePath = path.relative(bmadDir, originalPath);
1131
+ const backupPath = path.join(config._tempBackupDir, relativePath);
1132
+
1133
+ if (await fs.pathExists(backupPath)) {
1134
+ await fs.ensureDir(path.dirname(originalPath));
1135
+ await fs.copy(backupPath, originalPath, { overwrite: true });
1136
+ }
1137
+ }
1138
+
1139
+ // Clean up temp backup
1140
+ if (config._tempBackupDir && (await fs.pathExists(config._tempBackupDir))) {
1141
+ await fs.remove(config._tempBackupDir);
1142
+ }
1143
+
1144
+ spinner.succeed(`Restored ${config._customFiles.length} custom files`);
1145
+ customFiles = config._customFiles;
1146
+ }
1147
+
1148
+ if (config._modifiedFiles && config._modifiedFiles.length > 0) {
1149
+ modifiedFiles = config._modifiedFiles;
1150
+
1151
+ // Restore modified files as .bak files
1152
+ if (config._tempModifiedBackupDir && (await fs.pathExists(config._tempModifiedBackupDir))) {
1153
+ spinner.start(`Restoring ${modifiedFiles.length} modified files as .bak...`);
1154
+
1155
+ for (const modifiedFile of modifiedFiles) {
1156
+ const relativePath = path.relative(bmadDir, modifiedFile.path);
1157
+ const tempBackupPath = path.join(config._tempModifiedBackupDir, relativePath);
1158
+ const bakPath = modifiedFile.path + '.bak';
1159
+
1160
+ if (await fs.pathExists(tempBackupPath)) {
1161
+ await fs.ensureDir(path.dirname(bakPath));
1162
+ await fs.copy(tempBackupPath, bakPath, { overwrite: true });
1163
+ }
1164
+ }
1165
+
1166
+ // Clean up temp backup
1167
+ await fs.remove(config._tempModifiedBackupDir);
1168
+
1169
+ spinner.succeed(`Restored ${modifiedFiles.length} modified files as .bak`);
1170
+ }
1171
+ }
1172
+ }
1173
+
1174
+ spinner.stop();
1175
+
1176
+ // Report custom and modified files if any were found
1177
+ if (customFiles.length > 0) {
1178
+ console.log(chalk.cyan(`\n📁 Custom files preserved: ${customFiles.length}`));
1179
+ }
1180
+
1181
+ if (modifiedFiles.length > 0) {
1182
+ console.log(chalk.yellow(`\n⚠️ User modified files detected: ${modifiedFiles.length}`));
1183
+ console.log(
1184
+ chalk.dim(
1185
+ '\nThese user modified files have been updated with the new version, search the project for .bak files that had your customizations.',
1186
+ ),
1187
+ );
1188
+ console.log(chalk.dim('Remove these .bak files it no longer needed\n'));
1189
+ }
1190
+
1191
+ // Display completion message
1192
+ const { UI } = require('../../../lib/ui');
1193
+ const ui = new UI();
1194
+ ui.showInstallSummary({
1195
+ path: bmadDir,
1196
+ modules: config.modules,
1197
+ ides: config.ides,
1198
+ customFiles: customFiles.length > 0 ? customFiles : undefined,
1199
+ });
1200
+
1201
+ return {
1202
+ success: true,
1203
+ path: bmadDir,
1204
+ modules: config.modules,
1205
+ ides: config.ides,
1206
+ projectDir: projectDir,
1207
+ };
1208
+ } catch (error) {
1209
+ spinner.fail('Installation failed');
1210
+ throw error;
1211
+ }
1212
+ }
1213
+
1214
+ /**
1215
+ * Update existing installation
1216
+ */
1217
+ async update(config) {
1218
+ const spinner = ora('Checking installation...').start();
1219
+
1220
+ try {
1221
+ const projectDir = path.resolve(config.directory);
1222
+ const { bmadDir } = await this.findBmadDir(projectDir);
1223
+ const existingInstall = await this.detector.detect(bmadDir);
1224
+
1225
+ if (!existingInstall.installed) {
1226
+ spinner.fail('No BMAD installation found');
1227
+ throw new Error(`No BMAD installation found at ${bmadDir}`);
1228
+ }
1229
+
1230
+ spinner.text = 'Analyzing update requirements...';
1231
+
1232
+ // Compare versions and determine what needs updating
1233
+ const currentVersion = existingInstall.version;
1234
+ const newVersion = require(path.join(getProjectRoot(), 'package.json')).version;
1235
+
1236
+ // Check for custom modules with missing sources before update
1237
+ const customModuleSources = new Map();
1238
+
1239
+ // Check manifest for backward compatibility
1240
+ if (existingInstall.customModules) {
1241
+ for (const customModule of existingInstall.customModules) {
1242
+ customModuleSources.set(customModule.id, customModule);
1243
+ }
1244
+ }
1245
+
1246
+ // Also check cache directory
1247
+ const cacheDir = path.join(bmadDir, '_config', 'custom');
1248
+ if (await fs.pathExists(cacheDir)) {
1249
+ const cachedModules = await fs.readdir(cacheDir, { withFileTypes: true });
1250
+
1251
+ for (const cachedModule of cachedModules) {
1252
+ if (cachedModule.isDirectory()) {
1253
+ const moduleId = cachedModule.name;
1254
+
1255
+ // Skip if we already have this module
1256
+ if (customModuleSources.has(moduleId)) {
1257
+ continue;
1258
+ }
1259
+
1260
+ // Check if this is an external official module - skip cache for those
1261
+ const isExternal = await this.moduleManager.isExternalModule(moduleId);
1262
+ if (isExternal) {
1263
+ // External modules are handled via cloneExternalModule, not from cache
1264
+ continue;
1265
+ }
1266
+
1267
+ const cachedPath = path.join(cacheDir, moduleId);
1268
+
1269
+ // Check if this is actually a custom module (has module.yaml)
1270
+ const moduleYamlPath = path.join(cachedPath, 'module.yaml');
1271
+ if (await fs.pathExists(moduleYamlPath)) {
1272
+ customModuleSources.set(moduleId, {
1273
+ id: moduleId,
1274
+ name: moduleId,
1275
+ sourcePath: path.join('_config', 'custom', moduleId), // Relative path
1276
+ cached: true,
1277
+ });
1278
+ }
1279
+ }
1280
+ }
1281
+ }
1282
+
1283
+ if (customModuleSources.size > 0) {
1284
+ spinner.stop();
1285
+ console.log(chalk.yellow('\nChecking custom module sources before update...'));
1286
+
1287
+ const projectRoot = getProjectRoot();
1288
+ await this.handleMissingCustomSources(
1289
+ customModuleSources,
1290
+ bmadDir,
1291
+ projectRoot,
1292
+ 'update',
1293
+ existingInstall.modules.map((m) => m.id),
1294
+ );
1295
+
1296
+ spinner.start('Preparing update...');
1297
+ }
1298
+
1299
+ if (config.dryRun) {
1300
+ spinner.stop();
1301
+ console.log(chalk.cyan('\n🔍 Update Preview (Dry Run)\n'));
1302
+ console.log(chalk.bold('Current version:'), currentVersion);
1303
+ console.log(chalk.bold('New version:'), newVersion);
1304
+ console.log(chalk.bold('Core:'), existingInstall.hasCore ? 'Will be updated' : 'Not installed');
1305
+
1306
+ if (existingInstall.modules.length > 0) {
1307
+ console.log(chalk.bold('\nModules to update:'));
1308
+ for (const mod of existingInstall.modules) {
1309
+ console.log(` - ${mod.id}`);
1310
+ }
1311
+ }
1312
+ return;
1313
+ }
1314
+
1315
+ // Perform actual update
1316
+ if (existingInstall.hasCore) {
1317
+ spinner.text = 'Updating core...';
1318
+ await this.updateCore(bmadDir, config.force);
1319
+ }
1320
+
1321
+ for (const module of existingInstall.modules) {
1322
+ spinner.text = `Updating module: ${module.id}...`;
1323
+ await this.moduleManager.update(module.id, bmadDir, config.force);
1324
+ }
1325
+
1326
+ // Update manifest
1327
+ spinner.text = 'Updating manifest...';
1328
+ await this.manifest.update(bmadDir, {
1329
+ version: newVersion,
1330
+ updateDate: new Date().toISOString(),
1331
+ });
1332
+
1333
+ spinner.succeed('Update complete');
1334
+ return { success: true };
1335
+ } catch (error) {
1336
+ spinner.fail('Update failed');
1337
+ throw error;
1338
+ }
1339
+ }
1340
+
1341
+ /**
1342
+ * Get installation status
1343
+ */
1344
+ async getStatus(directory) {
1345
+ const projectDir = path.resolve(directory);
1346
+ const { bmadDir } = await this.findBmadDir(projectDir);
1347
+ return await this.detector.detect(bmadDir);
1348
+ }
1349
+
1350
+ /**
1351
+ * Get available modules
1352
+ */
1353
+ async getAvailableModules() {
1354
+ return await this.moduleManager.listAvailable();
1355
+ }
1356
+
1357
+ /**
1358
+ * Uninstall BMAD
1359
+ */
1360
+ async uninstall(directory) {
1361
+ const projectDir = path.resolve(directory);
1362
+ const { bmadDir } = await this.findBmadDir(projectDir);
1363
+
1364
+ if (await fs.pathExists(bmadDir)) {
1365
+ await fs.remove(bmadDir);
1366
+ }
1367
+
1368
+ // Clean up IDE configurations
1369
+ await this.ideManager.cleanup(projectDir);
1370
+
1371
+ return { success: true };
1372
+ }
1373
+
1374
+ /**
1375
+ * Private: Create directory structure
1376
+ */
1377
+ /**
1378
+ * Merge all module-help.csv files into a single bmad-help.csv
1379
+ * Scans all installed modules for module-help.csv and merges them
1380
+ * Enriches agent info from agent-manifest.csv
1381
+ * Output is written to _bmad/_config/bmad-help.csv
1382
+ * @param {string} bmadDir - BMAD installation directory
1383
+ */
1384
+ async mergeModuleHelpCatalogs(bmadDir) {
1385
+ const allRows = [];
1386
+ const headerRow =
1387
+ 'module,phase,name,code,sequence,workflow-file,command,required,agent-name,agent-command,agent-display-name,agent-title,options,description,output-location,outputs';
1388
+
1389
+ // Load agent manifest for agent info lookup
1390
+ const agentManifestPath = path.join(bmadDir, '_config', 'agent-manifest.csv');
1391
+ const agentInfo = new Map(); // agent-name -> {command, displayName, title+icon}
1392
+
1393
+ if (await fs.pathExists(agentManifestPath)) {
1394
+ const manifestContent = await fs.readFile(agentManifestPath, 'utf8');
1395
+ const lines = manifestContent.split('\n').filter((line) => line.trim());
1396
+
1397
+ for (const line of lines) {
1398
+ if (line.startsWith('name,')) continue; // Skip header
1399
+
1400
+ const cols = line.split(',');
1401
+ if (cols.length >= 4) {
1402
+ const agentName = cols[0].replaceAll('"', '').trim();
1403
+ const displayName = cols[1].replaceAll('"', '').trim();
1404
+ const title = cols[2].replaceAll('"', '').trim();
1405
+ const icon = cols[3].replaceAll('"', '').trim();
1406
+ const module = cols[10] ? cols[10].replaceAll('"', '').trim() : '';
1407
+
1408
+ // Build agent command: bmad:module:agent:name
1409
+ const agentCommand = module ? `bmad:${module}:agent:${agentName}` : `bmad:agent:${agentName}`;
1410
+
1411
+ agentInfo.set(agentName, {
1412
+ command: agentCommand,
1413
+ displayName: displayName || agentName,
1414
+ title: icon && title ? `${icon} ${title}` : title || agentName,
1415
+ });
1416
+ }
1417
+ }
1418
+ }
1419
+
1420
+ // Get all installed module directories
1421
+ const entries = await fs.readdir(bmadDir, { withFileTypes: true });
1422
+ const installedModules = entries
1423
+ .filter((entry) => entry.isDirectory() && entry.name !== '_config' && entry.name !== 'docs' && entry.name !== '_memory')
1424
+ .map((entry) => entry.name);
1425
+
1426
+ // Add core module to scan (it's installed at root level as _config, but we check src/core)
1427
+ const coreModulePath = getSourcePath('core');
1428
+ const modulePaths = new Map();
1429
+
1430
+ // Map all module source paths
1431
+ if (await fs.pathExists(coreModulePath)) {
1432
+ modulePaths.set('core', coreModulePath);
1433
+ }
1434
+
1435
+ // Map installed module paths
1436
+ for (const moduleName of installedModules) {
1437
+ const modulePath = path.join(bmadDir, moduleName);
1438
+ modulePaths.set(moduleName, modulePath);
1439
+ }
1440
+
1441
+ // Scan each module for module-help.csv
1442
+ for (const [moduleName, modulePath] of modulePaths) {
1443
+ const helpFilePath = path.join(modulePath, 'module-help.csv');
1444
+
1445
+ if (await fs.pathExists(helpFilePath)) {
1446
+ try {
1447
+ const content = await fs.readFile(helpFilePath, 'utf8');
1448
+ const lines = content.split('\n').filter((line) => line.trim() && !line.startsWith('#'));
1449
+
1450
+ for (const line of lines) {
1451
+ // Skip header row
1452
+ if (line.startsWith('module,')) {
1453
+ continue;
1454
+ }
1455
+
1456
+ // Parse the line - handle quoted fields with commas
1457
+ const columns = this.parseCSVLine(line);
1458
+ if (columns.length >= 12) {
1459
+ // Map old schema to new schema
1460
+ // Old: module,phase,name,code,sequence,workflow-file,command,required,agent,options,description,output-location,outputs
1461
+ // New: module,phase,name,code,sequence,workflow-file,command,required,agent-name,agent-command,agent-display-name,agent-title,options,description,output-location,outputs
1462
+
1463
+ const [
1464
+ module,
1465
+ phase,
1466
+ name,
1467
+ code,
1468
+ sequence,
1469
+ workflowFile,
1470
+ command,
1471
+ required,
1472
+ agentName,
1473
+ options,
1474
+ description,
1475
+ outputLocation,
1476
+ outputs,
1477
+ ] = columns;
1478
+
1479
+ // If module column is empty, set it to this module's name (except for core which stays empty for universal tools)
1480
+ const finalModule = (!module || module.trim() === '') && moduleName !== 'core' ? moduleName : module || '';
1481
+
1482
+ // Lookup agent info
1483
+ const cleanAgentName = agentName ? agentName.trim() : '';
1484
+ const agentData = agentInfo.get(cleanAgentName) || { command: '', displayName: '', title: '' };
1485
+
1486
+ // Build new row with agent info
1487
+ const newRow = [
1488
+ finalModule,
1489
+ phase || '',
1490
+ name || '',
1491
+ code || '',
1492
+ sequence || '',
1493
+ workflowFile || '',
1494
+ command || '',
1495
+ required || 'false',
1496
+ cleanAgentName,
1497
+ agentData.command,
1498
+ agentData.displayName,
1499
+ agentData.title,
1500
+ options || '',
1501
+ description || '',
1502
+ outputLocation || '',
1503
+ outputs || '',
1504
+ ];
1505
+
1506
+ allRows.push(newRow.map((c) => this.escapeCSVField(c)).join(','));
1507
+ }
1508
+ }
1509
+
1510
+ if (process.env.BMAD_VERBOSE_INSTALL === 'true') {
1511
+ console.log(chalk.dim(` Merged module-help from: ${moduleName}`));
1512
+ }
1513
+ } catch (error) {
1514
+ console.warn(chalk.yellow(` Warning: Failed to read module-help.csv from ${moduleName}:`, error.message));
1515
+ }
1516
+ }
1517
+ }
1518
+
1519
+ // Sort by module, then phase, then sequence
1520
+ allRows.sort((a, b) => {
1521
+ const colsA = this.parseCSVLine(a);
1522
+ const colsB = this.parseCSVLine(b);
1523
+
1524
+ // Module comparison (empty module/universal tools come first)
1525
+ const moduleA = (colsA[0] || '').toLowerCase();
1526
+ const moduleB = (colsB[0] || '').toLowerCase();
1527
+ if (moduleA !== moduleB) {
1528
+ return moduleA.localeCompare(moduleB);
1529
+ }
1530
+
1531
+ // Phase comparison
1532
+ const phaseA = colsA[1] || '';
1533
+ const phaseB = colsB[1] || '';
1534
+ if (phaseA !== phaseB) {
1535
+ return phaseA.localeCompare(phaseB);
1536
+ }
1537
+
1538
+ // Sequence comparison
1539
+ const seqA = parseInt(colsA[4] || '0', 10);
1540
+ const seqB = parseInt(colsB[4] || '0', 10);
1541
+ return seqA - seqB;
1542
+ });
1543
+
1544
+ // Write merged catalog
1545
+ const outputDir = path.join(bmadDir, '_config');
1546
+ await fs.ensureDir(outputDir);
1547
+ const outputPath = path.join(outputDir, 'bmad-help.csv');
1548
+
1549
+ const mergedContent = [headerRow, ...allRows].join('\n');
1550
+ await fs.writeFile(outputPath, mergedContent, 'utf8');
1551
+
1552
+ // Track the installed file
1553
+ this.installedFiles.add(outputPath);
1554
+
1555
+ if (process.env.BMAD_VERBOSE_INSTALL === 'true') {
1556
+ console.log(chalk.dim(` Generated bmad-help.csv: ${allRows.length} workflows`));
1557
+ }
1558
+ }
1559
+
1560
+ /**
1561
+ * Parse a CSV line, handling quoted fields
1562
+ * @param {string} line - CSV line to parse
1563
+ * @returns {Array} Array of field values
1564
+ */
1565
+ parseCSVLine(line) {
1566
+ const result = [];
1567
+ let current = '';
1568
+ let inQuotes = false;
1569
+
1570
+ for (let i = 0; i < line.length; i++) {
1571
+ const char = line[i];
1572
+ const nextChar = line[i + 1];
1573
+
1574
+ if (char === '"') {
1575
+ if (inQuotes && nextChar === '"') {
1576
+ // Escaped quote
1577
+ current += '"';
1578
+ i++; // Skip next quote
1579
+ } else {
1580
+ // Toggle quote mode
1581
+ inQuotes = !inQuotes;
1582
+ }
1583
+ } else if (char === ',' && !inQuotes) {
1584
+ result.push(current);
1585
+ current = '';
1586
+ } else {
1587
+ current += char;
1588
+ }
1589
+ }
1590
+ result.push(current);
1591
+ return result;
1592
+ }
1593
+
1594
+ /**
1595
+ * Escape a CSV field if it contains special characters
1596
+ * @param {string} field - Field value to escape
1597
+ * @returns {string} Escaped field
1598
+ */
1599
+ escapeCSVField(field) {
1600
+ if (field === null || field === undefined) {
1601
+ return '';
1602
+ }
1603
+ const str = String(field);
1604
+ // If field contains comma, quote, or newline, wrap in quotes and escape inner quotes
1605
+ if (str.includes(',') || str.includes('"') || str.includes('\n')) {
1606
+ return `"${str.replaceAll('"', '""')}"`;
1607
+ }
1608
+ return str;
1609
+ }
1610
+
1611
+ async createDirectoryStructure(bmadDir) {
1612
+ await fs.ensureDir(bmadDir);
1613
+ await fs.ensureDir(path.join(bmadDir, '_config'));
1614
+ await fs.ensureDir(path.join(bmadDir, '_config', 'agents'));
1615
+ await fs.ensureDir(path.join(bmadDir, '_config', 'custom'));
1616
+ }
1617
+
1618
+ /**
1619
+ * Generate clean config.yaml files for each installed module
1620
+ * @param {string} bmadDir - BMAD installation directory
1621
+ * @param {Object} moduleConfigs - Collected configuration values
1622
+ */
1623
+ async generateModuleConfigs(bmadDir, moduleConfigs) {
1624
+ const yaml = require('yaml');
1625
+
1626
+ // Extract core config values to share with other modules
1627
+ const coreConfig = moduleConfigs.core || {};
1628
+
1629
+ // Get all installed module directories
1630
+ const entries = await fs.readdir(bmadDir, { withFileTypes: true });
1631
+ const installedModules = entries
1632
+ .filter((entry) => entry.isDirectory() && entry.name !== '_config' && entry.name !== 'docs')
1633
+ .map((entry) => entry.name);
1634
+
1635
+ // Generate config.yaml for each installed module
1636
+ for (const moduleName of installedModules) {
1637
+ const modulePath = path.join(bmadDir, moduleName);
1638
+
1639
+ // Get module-specific config or use empty object if none
1640
+ const config = moduleConfigs[moduleName] || {};
1641
+
1642
+ if (await fs.pathExists(modulePath)) {
1643
+ const configPath = path.join(modulePath, 'config.yaml');
1644
+
1645
+ // Create header
1646
+ const packageJson = require(path.join(getProjectRoot(), 'package.json'));
1647
+ const header = `# ${moduleName.toUpperCase()} Module Configuration
1648
+ # Generated by BMAD installer
1649
+ # Version: ${packageJson.version}
1650
+ # Date: ${new Date().toISOString()}
1651
+
1652
+ `;
1653
+
1654
+ // For non-core modules, add core config values directly
1655
+ let finalConfig = { ...config };
1656
+ let coreSection = '';
1657
+
1658
+ if (moduleName !== 'core' && coreConfig && Object.keys(coreConfig).length > 0) {
1659
+ // Add core values directly to the module config
1660
+ // These will be available for reference in the module
1661
+ finalConfig = {
1662
+ ...config,
1663
+ ...coreConfig, // Spread core config values directly into the module config
1664
+ };
1665
+
1666
+ // Create a comment section to identify core values
1667
+ coreSection = '\n# Core Configuration Values\n';
1668
+ }
1669
+
1670
+ // Clean the config to remove any non-serializable values (like functions)
1671
+ const cleanConfig = structuredClone(finalConfig);
1672
+
1673
+ // Convert config to YAML
1674
+ let yamlContent = yaml.stringify(cleanConfig, {
1675
+ indent: 2,
1676
+ lineWidth: 0,
1677
+ minContentWidth: 0,
1678
+ });
1679
+
1680
+ // If we have core values, reorganize the YAML to group them with their comment
1681
+ if (coreSection && moduleName !== 'core') {
1682
+ // Split the YAML into lines
1683
+ const lines = yamlContent.split('\n');
1684
+ const moduleConfigLines = [];
1685
+ const coreConfigLines = [];
1686
+
1687
+ // Separate module-specific and core config lines
1688
+ for (const line of lines) {
1689
+ const key = line.split(':')[0].trim();
1690
+ if (Object.prototype.hasOwnProperty.call(coreConfig, key)) {
1691
+ coreConfigLines.push(line);
1692
+ } else {
1693
+ moduleConfigLines.push(line);
1694
+ }
1695
+ }
1696
+
1697
+ // Rebuild YAML with module config first, then core config with comment
1698
+ yamlContent = moduleConfigLines.join('\n');
1699
+ if (coreConfigLines.length > 0) {
1700
+ yamlContent += coreSection + coreConfigLines.join('\n');
1701
+ }
1702
+ }
1703
+
1704
+ // Write the clean config file with POSIX-compliant final newline
1705
+ const content = header + yamlContent;
1706
+ await fs.writeFile(configPath, content.endsWith('\n') ? content : content + '\n', 'utf8');
1707
+
1708
+ // Track the config file in installedFiles
1709
+ this.installedFiles.add(configPath);
1710
+ }
1711
+ }
1712
+ }
1713
+
1714
+ /**
1715
+ * Install core with resolved dependencies
1716
+ * @param {string} bmadDir - BMAD installation directory
1717
+ * @param {Object} coreFiles - Core files to install
1718
+ */
1719
+ async installCoreWithDependencies(bmadDir, coreFiles) {
1720
+ const sourcePath = getModulePath('core');
1721
+ const targetPath = path.join(bmadDir, 'core');
1722
+ await this.installCore(bmadDir);
1723
+ }
1724
+
1725
+ /**
1726
+ * Install module with resolved dependencies
1727
+ * @param {string} moduleName - Module name
1728
+ * @param {string} bmadDir - BMAD installation directory
1729
+ * @param {Object} moduleFiles - Module files to install
1730
+ */
1731
+ async installModuleWithDependencies(moduleName, bmadDir, moduleFiles) {
1732
+ // Get module configuration for conditional installation
1733
+ const moduleConfig = this.configCollector.collectedConfig[moduleName] || {};
1734
+
1735
+ // Use existing module manager for full installation with file tracking
1736
+ // Note: Module-specific installers are called separately after IDE setup
1737
+ await this.moduleManager.install(
1738
+ moduleName,
1739
+ bmadDir,
1740
+ (filePath) => {
1741
+ this.installedFiles.add(filePath);
1742
+ },
1743
+ {
1744
+ skipModuleInstaller: true, // We'll run it later after IDE setup
1745
+ moduleConfig: moduleConfig, // Pass module config for conditional filtering
1746
+ installer: this,
1747
+ },
1748
+ );
1749
+
1750
+ // Process agent files to build YAML agents and create customize templates
1751
+ const modulePath = path.join(bmadDir, moduleName);
1752
+ await this.processAgentFiles(modulePath, moduleName);
1753
+
1754
+ // Dependencies are already included in full module install
1755
+ }
1756
+
1757
+ /**
1758
+ * Install partial module (only dependencies needed by other modules)
1759
+ */
1760
+ async installPartialModule(moduleName, bmadDir, files) {
1761
+ const sourceBase = getModulePath(moduleName);
1762
+ const targetBase = path.join(bmadDir, moduleName);
1763
+
1764
+ // Create module directory
1765
+ await fs.ensureDir(targetBase);
1766
+
1767
+ // Copy only the required dependency files
1768
+ if (files.agents && files.agents.length > 0) {
1769
+ const agentsDir = path.join(targetBase, 'agents');
1770
+ await fs.ensureDir(agentsDir);
1771
+
1772
+ for (const agentPath of files.agents) {
1773
+ const fileName = path.basename(agentPath);
1774
+ const sourcePath = path.join(sourceBase, 'agents', fileName);
1775
+ const targetPath = path.join(agentsDir, fileName);
1776
+
1777
+ if (await fs.pathExists(sourcePath)) {
1778
+ await this.copyFileWithPlaceholderReplacement(sourcePath, targetPath);
1779
+ this.installedFiles.add(targetPath);
1780
+ }
1781
+ }
1782
+ }
1783
+
1784
+ if (files.tasks && files.tasks.length > 0) {
1785
+ const tasksDir = path.join(targetBase, 'tasks');
1786
+ await fs.ensureDir(tasksDir);
1787
+
1788
+ for (const taskPath of files.tasks) {
1789
+ const fileName = path.basename(taskPath);
1790
+ const sourcePath = path.join(sourceBase, 'tasks', fileName);
1791
+ const targetPath = path.join(tasksDir, fileName);
1792
+
1793
+ if (await fs.pathExists(sourcePath)) {
1794
+ await this.copyFileWithPlaceholderReplacement(sourcePath, targetPath);
1795
+ this.installedFiles.add(targetPath);
1796
+ }
1797
+ }
1798
+ }
1799
+
1800
+ if (files.tools && files.tools.length > 0) {
1801
+ const toolsDir = path.join(targetBase, 'tools');
1802
+ await fs.ensureDir(toolsDir);
1803
+
1804
+ for (const toolPath of files.tools) {
1805
+ const fileName = path.basename(toolPath);
1806
+ const sourcePath = path.join(sourceBase, 'tools', fileName);
1807
+ const targetPath = path.join(toolsDir, fileName);
1808
+
1809
+ if (await fs.pathExists(sourcePath)) {
1810
+ await this.copyFileWithPlaceholderReplacement(sourcePath, targetPath);
1811
+ this.installedFiles.add(targetPath);
1812
+ }
1813
+ }
1814
+ }
1815
+
1816
+ if (files.templates && files.templates.length > 0) {
1817
+ const templatesDir = path.join(targetBase, 'templates');
1818
+ await fs.ensureDir(templatesDir);
1819
+
1820
+ for (const templatePath of files.templates) {
1821
+ const fileName = path.basename(templatePath);
1822
+ const sourcePath = path.join(sourceBase, 'templates', fileName);
1823
+ const targetPath = path.join(templatesDir, fileName);
1824
+
1825
+ if (await fs.pathExists(sourcePath)) {
1826
+ await this.copyFileWithPlaceholderReplacement(sourcePath, targetPath);
1827
+ this.installedFiles.add(targetPath);
1828
+ }
1829
+ }
1830
+ }
1831
+
1832
+ if (files.data && files.data.length > 0) {
1833
+ for (const dataPath of files.data) {
1834
+ // Preserve directory structure for data files
1835
+ const relative = path.relative(sourceBase, dataPath);
1836
+ const targetPath = path.join(targetBase, relative);
1837
+
1838
+ await fs.ensureDir(path.dirname(targetPath));
1839
+
1840
+ if (await fs.pathExists(dataPath)) {
1841
+ await this.copyFileWithPlaceholderReplacement(dataPath, targetPath);
1842
+ this.installedFiles.add(targetPath);
1843
+ }
1844
+ }
1845
+ }
1846
+
1847
+ // Create a marker file to indicate this is a partial installation
1848
+ const markerPath = path.join(targetBase, '.partial');
1849
+ await fs.writeFile(
1850
+ markerPath,
1851
+ `This module contains only dependencies required by other modules.\nInstalled: ${new Date().toISOString()}\n`,
1852
+ );
1853
+ }
1854
+
1855
+ /**
1856
+ * Private: Install core
1857
+ * @param {string} bmadDir - BMAD installation directory
1858
+ */
1859
+ async installCore(bmadDir) {
1860
+ const sourcePath = getModulePath('core');
1861
+ const targetPath = path.join(bmadDir, 'core');
1862
+
1863
+ // Copy core files (skip .agent.yaml files like modules do)
1864
+ await this.copyCoreFiles(sourcePath, targetPath);
1865
+
1866
+ // Compile agents using the same compiler as modules
1867
+ const { ModuleManager } = require('../modules/manager');
1868
+ const moduleManager = new ModuleManager();
1869
+ await moduleManager.compileModuleAgents(sourcePath, targetPath, 'core', bmadDir, this);
1870
+
1871
+ // Process agent files to inject activation block
1872
+ await this.processAgentFiles(targetPath, 'core');
1873
+ }
1874
+
1875
+ /**
1876
+ * Copy core files (similar to copyModuleWithFiltering but for core)
1877
+ * @param {string} sourcePath - Source path
1878
+ * @param {string} targetPath - Target path
1879
+ */
1880
+ async copyCoreFiles(sourcePath, targetPath) {
1881
+ // Get all files in source
1882
+ const files = await this.getFileList(sourcePath);
1883
+
1884
+ for (const file of files) {
1885
+ // Skip sub-modules directory - these are IDE-specific and handled separately
1886
+ if (file.startsWith('sub-modules/')) {
1887
+ continue;
1888
+ }
1889
+
1890
+ // Skip sidecar directories - they are handled separately during agent compilation
1891
+ if (
1892
+ path
1893
+ .dirname(file)
1894
+ .split('/')
1895
+ .some((dir) => dir.toLowerCase().includes('sidecar'))
1896
+ ) {
1897
+ continue;
1898
+ }
1899
+
1900
+ // Skip _module-installer directory - it's only needed at install time
1901
+ if (file.startsWith('_module-installer/') || file === 'module.yaml') {
1902
+ continue;
1903
+ }
1904
+
1905
+ // Skip config.yaml templates - we'll generate clean ones with actual values
1906
+ if (file === 'config.yaml' || file.endsWith('/config.yaml') || file === 'custom.yaml' || file.endsWith('/custom.yaml')) {
1907
+ continue;
1908
+ }
1909
+
1910
+ // Skip .agent.yaml files - they will be compiled separately
1911
+ if (file.endsWith('.agent.yaml')) {
1912
+ continue;
1913
+ }
1914
+
1915
+ const sourceFile = path.join(sourcePath, file);
1916
+ const targetFile = path.join(targetPath, file);
1917
+
1918
+ // Check if this is an agent file
1919
+ if (file.startsWith('agents/') && file.endsWith('.md')) {
1920
+ // Read the file to check for localskip
1921
+ const content = await fs.readFile(sourceFile, 'utf8');
1922
+
1923
+ // Check for localskip="true" in the agent tag
1924
+ const agentMatch = content.match(/<agent[^>]*\slocalskip="true"[^>]*>/);
1925
+ if (agentMatch) {
1926
+ console.log(chalk.dim(` Skipping web-only agent: ${path.basename(file)}`));
1927
+ continue; // Skip this agent
1928
+ }
1929
+ }
1930
+
1931
+ // Copy the file with placeholder replacement
1932
+ await fs.ensureDir(path.dirname(targetFile));
1933
+ await this.copyFileWithPlaceholderReplacement(sourceFile, targetFile);
1934
+
1935
+ // Track the installed file
1936
+ this.installedFiles.add(targetFile);
1937
+ }
1938
+ }
1939
+
1940
+ /**
1941
+ * Get list of all files in a directory recursively
1942
+ * @param {string} dir - Directory path
1943
+ * @param {string} baseDir - Base directory for relative paths
1944
+ * @returns {Array} List of relative file paths
1945
+ */
1946
+ async getFileList(dir, baseDir = dir) {
1947
+ const files = [];
1948
+ const entries = await fs.readdir(dir, { withFileTypes: true });
1949
+
1950
+ for (const entry of entries) {
1951
+ const fullPath = path.join(dir, entry.name);
1952
+
1953
+ if (entry.isDirectory()) {
1954
+ // Skip _module-installer directories
1955
+ if (entry.name === '_module-installer') {
1956
+ continue;
1957
+ }
1958
+ const subFiles = await this.getFileList(fullPath, baseDir);
1959
+ files.push(...subFiles);
1960
+ } else {
1961
+ files.push(path.relative(baseDir, fullPath));
1962
+ }
1963
+ }
1964
+
1965
+ return files;
1966
+ }
1967
+
1968
+ /**
1969
+ * Process agent files to build YAML agents and inject activation blocks
1970
+ * @param {string} modulePath - Path to module in bmad/ installation
1971
+ * @param {string} moduleName - Module name
1972
+ */
1973
+ async processAgentFiles(modulePath, moduleName) {
1974
+ const agentsPath = path.join(modulePath, 'agents');
1975
+
1976
+ // Check if agents directory exists
1977
+ if (!(await fs.pathExists(agentsPath))) {
1978
+ return; // No agents to process
1979
+ }
1980
+
1981
+ // Determine project directory (parent of bmad/ directory)
1982
+ const bmadDir = path.dirname(modulePath);
1983
+ const cfgAgentsDir = path.join(bmadDir, '_config', 'agents');
1984
+
1985
+ // Ensure _config/agents directory exists
1986
+ await fs.ensureDir(cfgAgentsDir);
1987
+
1988
+ // Get all agent files
1989
+ const agentFiles = await fs.readdir(agentsPath);
1990
+
1991
+ for (const agentFile of agentFiles) {
1992
+ // Skip .agent.yaml files - they should already be compiled by compileModuleAgents
1993
+ if (agentFile.endsWith('.agent.yaml')) {
1994
+ continue;
1995
+ }
1996
+
1997
+ // Only process .md files (already compiled from YAML)
1998
+ if (!agentFile.endsWith('.md')) {
1999
+ continue;
2000
+ }
2001
+
2002
+ const agentName = agentFile.replace('.md', '');
2003
+ const mdPath = path.join(agentsPath, agentFile);
2004
+ const customizePath = path.join(cfgAgentsDir, `${moduleName}-${agentName}.customize.yaml`);
2005
+
2006
+ // For .md files that are already compiled, we don't need to do much
2007
+ // Just ensure the customize template exists
2008
+ if (!(await fs.pathExists(customizePath))) {
2009
+ const genericTemplatePath = getSourcePath('utility', 'agent-components', 'agent.customize.template.yaml');
2010
+ if (await fs.pathExists(genericTemplatePath)) {
2011
+ await this.copyFileWithPlaceholderReplacement(genericTemplatePath, customizePath);
2012
+ if (process.env.BMAD_VERBOSE_INSTALL === 'true') {
2013
+ console.log(chalk.dim(` Created customize: ${moduleName}-${agentName}.customize.yaml`));
2014
+ }
2015
+ }
2016
+ }
2017
+ }
2018
+ }
2019
+
2020
+ /**
2021
+ * Private: Update core
2022
+ */
2023
+ async updateCore(bmadDir, force = false) {
2024
+ const sourcePath = getModulePath('core');
2025
+ const targetPath = path.join(bmadDir, 'core');
2026
+
2027
+ if (force) {
2028
+ await fs.remove(targetPath);
2029
+ await this.installCore(bmadDir);
2030
+ } else {
2031
+ // Selective update - preserve user modifications
2032
+ await this.fileOps.syncDirectory(sourcePath, targetPath);
2033
+
2034
+ // Recompile agents (#1133)
2035
+ const { ModuleManager } = require('../modules/manager');
2036
+ const moduleManager = new ModuleManager();
2037
+ await moduleManager.compileModuleAgents(sourcePath, targetPath, 'core', bmadDir, this);
2038
+ await this.processAgentFiles(targetPath, 'core');
2039
+ }
2040
+ }
2041
+
2042
+ /**
2043
+ * Quick update method - preserves all settings and only prompts for new config fields
2044
+ * @param {Object} config - Configuration with directory
2045
+ * @returns {Object} Update result
2046
+ */
2047
+ async quickUpdate(config) {
2048
+ const ora = require('ora');
2049
+ const spinner = ora('Starting quick update...').start();
2050
+
2051
+ try {
2052
+ const projectDir = path.resolve(config.directory);
2053
+ const { bmadDir } = await this.findBmadDir(projectDir);
2054
+
2055
+ // Check if bmad directory exists
2056
+ if (!(await fs.pathExists(bmadDir))) {
2057
+ spinner.fail('No BMAD installation found');
2058
+ throw new Error(`BMAD not installed at ${bmadDir}. Use regular install for first-time setup.`);
2059
+ }
2060
+
2061
+ spinner.text = 'Detecting installed modules and configuration...';
2062
+
2063
+ // Detect existing installation
2064
+ const existingInstall = await this.detector.detect(bmadDir);
2065
+ const installedModules = existingInstall.modules.map((m) => m.id);
2066
+ const configuredIdes = existingInstall.ides || [];
2067
+ const projectRoot = path.dirname(bmadDir);
2068
+
2069
+ // Get custom module sources from cache
2070
+ const customModuleSources = new Map();
2071
+ const cacheDir = path.join(bmadDir, '_config', 'custom');
2072
+ if (await fs.pathExists(cacheDir)) {
2073
+ const cachedModules = await fs.readdir(cacheDir, { withFileTypes: true });
2074
+
2075
+ for (const cachedModule of cachedModules) {
2076
+ if (cachedModule.isDirectory()) {
2077
+ const moduleId = cachedModule.name;
2078
+
2079
+ // Skip if we already have this module from manifest
2080
+ if (customModuleSources.has(moduleId)) {
2081
+ continue;
2082
+ }
2083
+
2084
+ // Check if this is an external official module - skip cache for those
2085
+ const isExternal = await this.moduleManager.isExternalModule(moduleId);
2086
+ if (isExternal) {
2087
+ // External modules are handled via cloneExternalModule, not from cache
2088
+ continue;
2089
+ }
2090
+
2091
+ const cachedPath = path.join(cacheDir, moduleId);
2092
+
2093
+ // Check if this is actually a custom module (has module.yaml)
2094
+ const moduleYamlPath = path.join(cachedPath, 'module.yaml');
2095
+ if (await fs.pathExists(moduleYamlPath)) {
2096
+ // For quick update, we always rebuild from cache
2097
+ customModuleSources.set(moduleId, {
2098
+ id: moduleId,
2099
+ name: moduleId, // We'll read the actual name if needed
2100
+ sourcePath: cachedPath,
2101
+ cached: true, // Flag to indicate this is from cache
2102
+ });
2103
+ }
2104
+ }
2105
+ }
2106
+ }
2107
+
2108
+ // Load saved IDE configurations
2109
+ const savedIdeConfigs = await this.ideConfigManager.loadAllIdeConfigs(bmadDir);
2110
+
2111
+ // Get available modules (what we have source for)
2112
+ const availableModulesData = await this.moduleManager.listAvailable();
2113
+ const availableModules = [...availableModulesData.modules, ...availableModulesData.customModules];
2114
+
2115
+ // Add external official modules to available modules
2116
+ // These can always be obtained by cloning from their remote URLs
2117
+ const { ExternalModuleManager } = require('../modules/external-manager');
2118
+ const externalManager = new ExternalModuleManager();
2119
+ const externalModules = await externalManager.listAvailable();
2120
+ for (const externalModule of externalModules) {
2121
+ // Only add if not already in the list and is installed
2122
+ if (installedModules.includes(externalModule.code) && !availableModules.some((m) => m.id === externalModule.code)) {
2123
+ availableModules.push({
2124
+ id: externalModule.code,
2125
+ name: externalModule.name,
2126
+ isExternal: true,
2127
+ fromExternal: true,
2128
+ });
2129
+ }
2130
+ }
2131
+
2132
+ // Add custom modules from manifest if their sources exist
2133
+ for (const [moduleId, customModule] of customModuleSources) {
2134
+ // Use the absolute sourcePath
2135
+ const sourcePath = customModule.sourcePath;
2136
+
2137
+ // Check if source exists at the recorded path
2138
+ if (
2139
+ sourcePath &&
2140
+ (await fs.pathExists(sourcePath)) && // Add to available modules if not already there
2141
+ !availableModules.some((m) => m.id === moduleId)
2142
+ ) {
2143
+ availableModules.push({
2144
+ id: moduleId,
2145
+ name: customModule.name || moduleId,
2146
+ path: sourcePath,
2147
+ isCustom: true,
2148
+ fromManifest: true,
2149
+ });
2150
+ }
2151
+ }
2152
+
2153
+ // Handle missing custom module sources using shared method
2154
+ const customModuleResult = await this.handleMissingCustomSources(
2155
+ customModuleSources,
2156
+ bmadDir,
2157
+ projectRoot,
2158
+ 'update',
2159
+ installedModules,
2160
+ );
2161
+
2162
+ const { validCustomModules, keptModulesWithoutSources } = customModuleResult;
2163
+
2164
+ const customModulesFromManifest = validCustomModules.map((m) => ({
2165
+ ...m,
2166
+ isCustom: true,
2167
+ hasUpdate: true,
2168
+ }));
2169
+
2170
+ const allAvailableModules = [...availableModules, ...customModulesFromManifest];
2171
+ const availableModuleIds = new Set(allAvailableModules.map((m) => m.id));
2172
+
2173
+ // Core module is special - never include it in update flow
2174
+ const nonCoreInstalledModules = installedModules.filter((id) => id !== 'core');
2175
+
2176
+ // Only update modules that are BOTH installed AND available (we have source for)
2177
+ const modulesToUpdate = nonCoreInstalledModules.filter((id) => availableModuleIds.has(id));
2178
+ const skippedModules = nonCoreInstalledModules.filter((id) => !availableModuleIds.has(id));
2179
+
2180
+ // Add custom modules that were kept without sources to the skipped modules
2181
+ // This ensures their agents are preserved in the manifest
2182
+ for (const keptModule of keptModulesWithoutSources) {
2183
+ if (!skippedModules.includes(keptModule)) {
2184
+ skippedModules.push(keptModule);
2185
+ }
2186
+ }
2187
+
2188
+ spinner.succeed(`Found ${modulesToUpdate.length} module(s) to update and ${configuredIdes.length} configured tool(s)`);
2189
+
2190
+ if (skippedModules.length > 0) {
2191
+ console.log(chalk.yellow(`⚠️ Skipping ${skippedModules.length} module(s) - no source available: ${skippedModules.join(', ')}`));
2192
+ }
2193
+
2194
+ // Load existing configs and collect new fields (if any)
2195
+ console.log(chalk.cyan('\n📋 Checking for new configuration options...'));
2196
+ await this.configCollector.loadExistingConfig(projectDir);
2197
+
2198
+ let promptedForNewFields = false;
2199
+
2200
+ // Check core config for new fields
2201
+ const corePrompted = await this.configCollector.collectModuleConfigQuick('core', projectDir, true);
2202
+ if (corePrompted) {
2203
+ promptedForNewFields = true;
2204
+ }
2205
+
2206
+ // Check each module we're updating for new fields (NOT skipped modules)
2207
+ for (const moduleName of modulesToUpdate) {
2208
+ const modulePrompted = await this.configCollector.collectModuleConfigQuick(moduleName, projectDir, true);
2209
+ if (modulePrompted) {
2210
+ promptedForNewFields = true;
2211
+ }
2212
+ }
2213
+
2214
+ if (!promptedForNewFields) {
2215
+ console.log(chalk.green('✓ All configuration is up to date, no new options to configure'));
2216
+ }
2217
+
2218
+ // Add metadata
2219
+ this.configCollector.collectedConfig._meta = {
2220
+ version: require(path.join(getProjectRoot(), 'package.json')).version,
2221
+ installDate: new Date().toISOString(),
2222
+ lastModified: new Date().toISOString(),
2223
+ };
2224
+
2225
+ // Build the config object for the installer
2226
+ const installConfig = {
2227
+ directory: projectDir,
2228
+ installCore: true,
2229
+ modules: modulesToUpdate, // Only update modules we have source for
2230
+ ides: configuredIdes,
2231
+ skipIde: configuredIdes.length === 0,
2232
+ coreConfig: this.configCollector.collectedConfig.core,
2233
+ actionType: 'install', // Use regular install flow
2234
+ _quickUpdate: true, // Flag to skip certain prompts
2235
+ _preserveModules: skippedModules, // Preserve these in manifest even though we didn't update them
2236
+ _savedIdeConfigs: savedIdeConfigs, // Pass saved IDE configs to installer
2237
+ _customModuleSources: customModuleSources, // Pass custom module sources for updates
2238
+ _existingModules: installedModules, // Pass all installed modules for manifest generation
2239
+ };
2240
+
2241
+ // Call the standard install method
2242
+ const result = await this.install(installConfig);
2243
+
2244
+ // Only succeed the spinner if it's still spinning
2245
+ // (install method might have stopped it if folder name changed)
2246
+ if (spinner.isSpinning) {
2247
+ spinner.succeed('Quick update complete!');
2248
+ }
2249
+
2250
+ return {
2251
+ success: true,
2252
+ moduleCount: modulesToUpdate.length + 1, // +1 for core
2253
+ hadNewFields: promptedForNewFields,
2254
+ modules: ['core', ...modulesToUpdate],
2255
+ skippedModules: skippedModules,
2256
+ ides: configuredIdes,
2257
+ };
2258
+ } catch (error) {
2259
+ spinner.fail('Quick update failed');
2260
+ throw error;
2261
+ }
2262
+ }
2263
+
2264
+ /**
2265
+ * Compile agents with customizations only
2266
+ * @param {Object} config - Configuration with directory
2267
+ * @returns {Object} Compilation result
2268
+ */
2269
+ async compileAgents(config) {
2270
+ const ora = require('ora');
2271
+ const chalk = require('chalk');
2272
+ const { ModuleManager } = require('../modules/manager');
2273
+ const { getSourcePath } = require('../../../lib/project-root');
2274
+
2275
+ const spinner = ora('Recompiling agents with customizations...').start();
2276
+
2277
+ try {
2278
+ const projectDir = path.resolve(config.directory);
2279
+ const { bmadDir } = await this.findBmadDir(projectDir);
2280
+
2281
+ // Check if bmad directory exists
2282
+ if (!(await fs.pathExists(bmadDir))) {
2283
+ spinner.fail('No BMAD installation found');
2284
+ throw new Error(`BMAD not installed at ${bmadDir}. Use regular install for first-time setup.`);
2285
+ }
2286
+
2287
+ // Detect existing installation
2288
+ const existingInstall = await this.detector.detect(bmadDir);
2289
+ const installedModules = existingInstall.modules.map((m) => m.id);
2290
+
2291
+ // Initialize module manager
2292
+ const moduleManager = new ModuleManager();
2293
+ moduleManager.setBmadFolderName(path.basename(bmadDir));
2294
+
2295
+ let totalAgentCount = 0;
2296
+
2297
+ // Get custom module sources from cache
2298
+ const customModuleSources = new Map();
2299
+ const cacheDir = path.join(bmadDir, '_config', 'custom');
2300
+ if (await fs.pathExists(cacheDir)) {
2301
+ const cachedModules = await fs.readdir(cacheDir, { withFileTypes: true });
2302
+
2303
+ for (const cachedModule of cachedModules) {
2304
+ if (cachedModule.isDirectory()) {
2305
+ const moduleId = cachedModule.name;
2306
+ const cachedPath = path.join(cacheDir, moduleId);
2307
+ const moduleYamlPath = path.join(cachedPath, 'module.yaml');
2308
+
2309
+ // Check if this is actually a custom module
2310
+ if (await fs.pathExists(moduleYamlPath)) {
2311
+ // Check if this is an external official module - skip cache for those
2312
+ const isExternal = await this.moduleManager.isExternalModule(moduleId);
2313
+ if (isExternal) {
2314
+ // External modules are handled via cloneExternalModule, not from cache
2315
+ continue;
2316
+ }
2317
+ customModuleSources.set(moduleId, cachedPath);
2318
+ }
2319
+ }
2320
+ }
2321
+ }
2322
+
2323
+ // Process each installed module
2324
+ for (const moduleId of installedModules) {
2325
+ spinner.text = `Recompiling agents in ${moduleId}...`;
2326
+
2327
+ // Get source path
2328
+ let sourcePath;
2329
+ if (moduleId === 'core') {
2330
+ sourcePath = getSourcePath('core');
2331
+ } else {
2332
+ // First check if it's in the custom cache
2333
+ if (customModuleSources.has(moduleId)) {
2334
+ sourcePath = customModuleSources.get(moduleId);
2335
+ } else {
2336
+ sourcePath = await moduleManager.findModuleSource(moduleId);
2337
+ }
2338
+ }
2339
+
2340
+ if (!sourcePath) {
2341
+ console.log(chalk.yellow(` Warning: Source not found for module ${moduleId}, skipping...`));
2342
+ continue;
2343
+ }
2344
+
2345
+ const targetPath = path.join(bmadDir, moduleId);
2346
+
2347
+ // Compile agents for this module
2348
+ await moduleManager.compileModuleAgents(sourcePath, targetPath, moduleId, bmadDir, this);
2349
+
2350
+ // Count agents (rough estimate based on files)
2351
+ const agentsPath = path.join(targetPath, 'agents');
2352
+ if (await fs.pathExists(agentsPath)) {
2353
+ const agentFiles = await fs.readdir(agentsPath);
2354
+ const agentCount = agentFiles.filter((f) => f.endsWith('.md')).length;
2355
+ totalAgentCount += agentCount;
2356
+ }
2357
+ }
2358
+
2359
+ spinner.succeed('Agent recompilation complete!');
2360
+
2361
+ return {
2362
+ success: true,
2363
+ agentCount: totalAgentCount,
2364
+ modules: installedModules,
2365
+ };
2366
+ } catch (error) {
2367
+ spinner.fail('Agent recompilation failed');
2368
+ throw error;
2369
+ }
2370
+ }
2371
+
2372
+ /**
2373
+ * Private: Prompt for update action
2374
+ */
2375
+ async promptUpdateAction() {
2376
+ const action = await prompts.select({
2377
+ message: 'What would you like to do?',
2378
+ choices: [{ name: 'Update existing installation', value: 'update' }],
2379
+ });
2380
+ return { action };
2381
+ }
2382
+
2383
+ /**
2384
+ * Handle legacy BMAD v4 detection with simple warning
2385
+ * @param {string} _projectDir - Project directory (unused in simplified version)
2386
+ * @param {Object} _legacyV4 - Legacy V4 detection result (unused in simplified version)
2387
+ */
2388
+ async handleLegacyV4Migration(_projectDir, _legacyV4) {
2389
+ console.log('');
2390
+ console.log(chalk.yellow.bold('⚠️ Legacy BMAD v4 detected'));
2391
+ console.log(chalk.yellow('─'.repeat(80)));
2392
+ console.log(chalk.yellow('Found .bmad-method folder from BMAD v4 installation.'));
2393
+ console.log('');
2394
+
2395
+ console.log(chalk.dim('Before continuing with installation, we recommend:'));
2396
+ console.log(chalk.dim(' 1. Remove the .bmad-method folder, OR'));
2397
+ console.log(chalk.dim(' 2. Back it up by renaming it to another name (e.g., bmad-method-backup)'));
2398
+ console.log('');
2399
+
2400
+ console.log(chalk.dim('If your v4 installation set up rules or commands, you should remove those as well.'));
2401
+ console.log('');
2402
+
2403
+ const proceed = await prompts.select({
2404
+ message: 'What would you like to do?',
2405
+ choices: [
2406
+ {
2407
+ name: 'Exit and clean up manually (recommended)',
2408
+ value: 'exit',
2409
+ hint: 'Exit installation',
2410
+ },
2411
+ {
2412
+ name: 'Continue with installation anyway',
2413
+ value: 'continue',
2414
+ hint: 'Continue',
2415
+ },
2416
+ ],
2417
+ default: 'exit',
2418
+ });
2419
+
2420
+ if (proceed === 'exit') {
2421
+ console.log('');
2422
+ console.log(chalk.cyan('Please remove the .bmad-method folder and any v4 rules/commands,'));
2423
+ console.log(chalk.cyan('then run the installer again.'));
2424
+ console.log('');
2425
+ process.exit(0);
2426
+ }
2427
+
2428
+ console.log('');
2429
+ console.log(chalk.yellow('⚠️ Proceeding with installation despite legacy v4 folder'));
2430
+ console.log('');
2431
+ }
2432
+
2433
+ /**
2434
+ * Read files-manifest.csv
2435
+ * @param {string} bmadDir - BMAD installation directory
2436
+ * @returns {Array} Array of file entries from files-manifest.csv
2437
+ */
2438
+ async readFilesManifest(bmadDir) {
2439
+ const filesManifestPath = path.join(bmadDir, '_config', 'files-manifest.csv');
2440
+ if (!(await fs.pathExists(filesManifestPath))) {
2441
+ return [];
2442
+ }
2443
+
2444
+ try {
2445
+ const content = await fs.readFile(filesManifestPath, 'utf8');
2446
+ const lines = content.split('\n');
2447
+ const files = [];
2448
+
2449
+ for (let i = 1; i < lines.length; i++) {
2450
+ // Skip header
2451
+ const line = lines[i].trim();
2452
+ if (!line) continue;
2453
+
2454
+ // Parse CSV line properly handling quoted values
2455
+ const parts = [];
2456
+ let current = '';
2457
+ let inQuotes = false;
2458
+
2459
+ for (const char of line) {
2460
+ if (char === '"') {
2461
+ inQuotes = !inQuotes;
2462
+ } else if (char === ',' && !inQuotes) {
2463
+ parts.push(current);
2464
+ current = '';
2465
+ } else {
2466
+ current += char;
2467
+ }
2468
+ }
2469
+ parts.push(current); // Add last part
2470
+
2471
+ if (parts.length >= 4) {
2472
+ files.push({
2473
+ type: parts[0],
2474
+ name: parts[1],
2475
+ module: parts[2],
2476
+ path: parts[3],
2477
+ hash: parts[4] || null, // Hash may not exist in old manifests
2478
+ });
2479
+ }
2480
+ }
2481
+
2482
+ return files;
2483
+ } catch (error) {
2484
+ console.warn('Warning: Could not read files-manifest.csv:', error.message);
2485
+ return [];
2486
+ }
2487
+ }
2488
+
2489
+ /**
2490
+ * Detect custom and modified files
2491
+ * @param {string} bmadDir - BMAD installation directory
2492
+ * @param {Array} existingFilesManifest - Previous files from files-manifest.csv
2493
+ * @returns {Object} Object with customFiles and modifiedFiles arrays
2494
+ */
2495
+ async detectCustomFiles(bmadDir, existingFilesManifest) {
2496
+ const customFiles = [];
2497
+ const modifiedFiles = [];
2498
+
2499
+ // Memory is always in _bmad/_memory
2500
+ const bmadMemoryPath = '_memory';
2501
+
2502
+ // Check if the manifest has hashes - if not, we can't detect modifications
2503
+ let manifestHasHashes = false;
2504
+ if (existingFilesManifest && existingFilesManifest.length > 0) {
2505
+ manifestHasHashes = existingFilesManifest.some((f) => f.hash);
2506
+ }
2507
+
2508
+ // Build map of previously installed files from files-manifest.csv with their hashes
2509
+ const installedFilesMap = new Map();
2510
+ for (const fileEntry of existingFilesManifest) {
2511
+ if (fileEntry.path) {
2512
+ const absolutePath = path.join(bmadDir, fileEntry.path);
2513
+ installedFilesMap.set(path.normalize(absolutePath), {
2514
+ hash: fileEntry.hash,
2515
+ relativePath: fileEntry.path,
2516
+ });
2517
+ }
2518
+ }
2519
+
2520
+ // Recursively scan bmadDir for all files
2521
+ const scanDirectory = async (dir) => {
2522
+ try {
2523
+ const entries = await fs.readdir(dir, { withFileTypes: true });
2524
+ for (const entry of entries) {
2525
+ const fullPath = path.join(dir, entry.name);
2526
+
2527
+ if (entry.isDirectory()) {
2528
+ // Skip certain directories
2529
+ if (entry.name === 'node_modules' || entry.name === '.git') {
2530
+ continue;
2531
+ }
2532
+ await scanDirectory(fullPath);
2533
+ } else if (entry.isFile()) {
2534
+ const normalizedPath = path.normalize(fullPath);
2535
+ const fileInfo = installedFilesMap.get(normalizedPath);
2536
+
2537
+ // Skip certain system files that are auto-generated
2538
+ const relativePath = path.relative(bmadDir, fullPath);
2539
+ const fileName = path.basename(fullPath);
2540
+
2541
+ // Skip _config directory EXCEPT for modified agent customizations
2542
+ if (relativePath.startsWith('_config/') || relativePath.startsWith('_config\\')) {
2543
+ // Special handling for .customize.yaml files - only preserve if modified
2544
+ if (relativePath.includes('/agents/') && fileName.endsWith('.customize.yaml')) {
2545
+ // Check if the customization file has been modified from manifest
2546
+ const manifestPath = path.join(bmadDir, '_config', 'manifest.yaml');
2547
+ if (await fs.pathExists(manifestPath)) {
2548
+ const crypto = require('node:crypto');
2549
+ const currentContent = await fs.readFile(fullPath, 'utf8');
2550
+ const currentHash = crypto.createHash('sha256').update(currentContent).digest('hex');
2551
+
2552
+ const yaml = require('yaml');
2553
+ const manifestContent = await fs.readFile(manifestPath, 'utf8');
2554
+ const manifestData = yaml.parse(manifestContent);
2555
+ const originalHash = manifestData.agentCustomizations?.[relativePath];
2556
+
2557
+ // Only add to customFiles if hash differs (user modified)
2558
+ if (originalHash && currentHash !== originalHash) {
2559
+ customFiles.push(fullPath);
2560
+ }
2561
+ }
2562
+ }
2563
+ continue;
2564
+ }
2565
+
2566
+ if (relativePath.startsWith(bmadMemoryPath + '/') && path.dirname(relativePath).includes('-sidecar')) {
2567
+ continue;
2568
+ }
2569
+
2570
+ // Skip config.yaml files - these are regenerated on each install/update
2571
+ if (fileName === 'config.yaml') {
2572
+ continue;
2573
+ }
2574
+
2575
+ if (!fileInfo) {
2576
+ // File not in manifest = custom file
2577
+ // EXCEPT: Agent .md files in module folders are generated files, not custom
2578
+ // Only treat .md files under _config/agents/ as custom
2579
+ if (!(fileName.endsWith('.md') && relativePath.includes('/agents/') && !relativePath.startsWith('_config/'))) {
2580
+ customFiles.push(fullPath);
2581
+ }
2582
+ } else if (manifestHasHashes && fileInfo.hash) {
2583
+ // File in manifest with hash - check if it was modified
2584
+ const currentHash = await this.manifest.calculateFileHash(fullPath);
2585
+ if (currentHash && currentHash !== fileInfo.hash) {
2586
+ // Hash changed = file was modified
2587
+ modifiedFiles.push({
2588
+ path: fullPath,
2589
+ relativePath: fileInfo.relativePath,
2590
+ });
2591
+ }
2592
+ }
2593
+ }
2594
+ }
2595
+ } catch {
2596
+ // Ignore errors scanning directories
2597
+ }
2598
+ };
2599
+
2600
+ await scanDirectory(bmadDir);
2601
+ return { customFiles, modifiedFiles };
2602
+ }
2603
+
2604
+ /**
2605
+ * Handle missing custom module sources interactively
2606
+ * @param {Map} customModuleSources - Map of custom module ID to info
2607
+ * @param {string} bmadDir - BMAD directory
2608
+ * @param {string} projectRoot - Project root directory
2609
+ * @param {string} operation - Current operation ('update', 'compile', etc.)
2610
+ * @param {Array} installedModules - Array of installed module IDs (will be modified)
2611
+ * @returns {Object} Object with validCustomModules array and keptModulesWithoutSources array
2612
+ */
2613
+ async handleMissingCustomSources(customModuleSources, bmadDir, projectRoot, operation, installedModules) {
2614
+ const validCustomModules = [];
2615
+ const keptModulesWithoutSources = []; // Track modules kept without sources
2616
+ const customModulesWithMissingSources = [];
2617
+
2618
+ // Check which sources exist
2619
+ for (const [moduleId, customInfo] of customModuleSources) {
2620
+ if (await fs.pathExists(customInfo.sourcePath)) {
2621
+ validCustomModules.push({
2622
+ id: moduleId,
2623
+ name: customInfo.name,
2624
+ path: customInfo.sourcePath,
2625
+ info: customInfo,
2626
+ });
2627
+ } else {
2628
+ // For cached modules that are missing, we just skip them without prompting
2629
+ if (customInfo.cached) {
2630
+ // Skip cached modules without prompting
2631
+ keptModulesWithoutSources.push({
2632
+ id: moduleId,
2633
+ name: customInfo.name,
2634
+ cached: true,
2635
+ });
2636
+ } else {
2637
+ customModulesWithMissingSources.push({
2638
+ id: moduleId,
2639
+ name: customInfo.name,
2640
+ sourcePath: customInfo.sourcePath,
2641
+ relativePath: customInfo.relativePath,
2642
+ info: customInfo,
2643
+ });
2644
+ }
2645
+ }
2646
+ }
2647
+
2648
+ // If no missing sources, return immediately
2649
+ if (customModulesWithMissingSources.length === 0) {
2650
+ return {
2651
+ validCustomModules,
2652
+ keptModulesWithoutSources: [],
2653
+ };
2654
+ }
2655
+
2656
+ // Stop any spinner for interactive prompts
2657
+ const currentSpinner = ora();
2658
+ if (currentSpinner.isSpinning) {
2659
+ currentSpinner.stop();
2660
+ }
2661
+
2662
+ console.log(chalk.yellow(`\n⚠️ Found ${customModulesWithMissingSources.length} custom module(s) with missing sources:`));
2663
+
2664
+ let keptCount = 0;
2665
+ let updatedCount = 0;
2666
+ let removedCount = 0;
2667
+
2668
+ for (const missing of customModulesWithMissingSources) {
2669
+ console.log(chalk.dim(` • ${missing.name} (${missing.id})`));
2670
+ console.log(chalk.dim(` Original source: ${missing.relativePath}`));
2671
+ console.log(chalk.dim(` Full path: ${missing.sourcePath}`));
2672
+
2673
+ const choices = [
2674
+ {
2675
+ name: 'Keep installed (will not be processed)',
2676
+ value: 'keep',
2677
+ hint: 'Keep',
2678
+ },
2679
+ {
2680
+ name: 'Specify new source location',
2681
+ value: 'update',
2682
+ hint: 'Update',
2683
+ },
2684
+ ];
2685
+
2686
+ // Only add remove option if not just compiling agents
2687
+ if (operation !== 'compile-agents') {
2688
+ choices.push({
2689
+ name: '⚠️ REMOVE module completely (destructive!)',
2690
+ value: 'remove',
2691
+ hint: 'Remove',
2692
+ });
2693
+ }
2694
+
2695
+ const action = await prompts.select({
2696
+ message: `How would you like to handle "${missing.name}"?`,
2697
+ choices,
2698
+ });
2699
+
2700
+ switch (action) {
2701
+ case 'update': {
2702
+ // Use sync validation because @clack/prompts doesn't support async validate
2703
+ const newSourcePath = await prompts.text({
2704
+ message: 'Enter the new path to the custom module:',
2705
+ default: missing.sourcePath,
2706
+ validate: (input) => {
2707
+ if (!input || input.trim() === '') {
2708
+ return 'Please enter a path';
2709
+ }
2710
+ const expandedPath = path.resolve(input.trim());
2711
+ if (!fs.pathExistsSync(expandedPath)) {
2712
+ return 'Path does not exist';
2713
+ }
2714
+ // Check if it looks like a valid module
2715
+ const moduleYamlPath = path.join(expandedPath, 'module.yaml');
2716
+ const agentsPath = path.join(expandedPath, 'agents');
2717
+ const workflowsPath = path.join(expandedPath, 'workflows');
2718
+
2719
+ if (!fs.pathExistsSync(moduleYamlPath) && !fs.pathExistsSync(agentsPath) && !fs.pathExistsSync(workflowsPath)) {
2720
+ return 'Path does not appear to contain a valid custom module';
2721
+ }
2722
+ return; // clack expects undefined for valid input
2723
+ },
2724
+ });
2725
+
2726
+ // Update the source in manifest
2727
+ const resolvedPath = path.resolve(newSourcePath.trim());
2728
+ missing.info.sourcePath = resolvedPath;
2729
+ // Remove relativePath - we only store absolute sourcePath now
2730
+ delete missing.info.relativePath;
2731
+ await this.manifest.addCustomModule(bmadDir, missing.info);
2732
+
2733
+ validCustomModules.push({
2734
+ id: missing.id,
2735
+ name: missing.name,
2736
+ path: resolvedPath,
2737
+ info: missing.info,
2738
+ });
2739
+
2740
+ updatedCount++;
2741
+ console.log(chalk.green(`✓ Updated source location`));
2742
+
2743
+ break;
2744
+ }
2745
+ case 'remove': {
2746
+ // Extra confirmation for destructive remove
2747
+ console.log(chalk.red.bold(`\n⚠️ WARNING: This will PERMANENTLY DELETE "${missing.name}" and all its files!`));
2748
+ console.log(chalk.red(` Module location: ${path.join(bmadDir, missing.id)}`));
2749
+
2750
+ const confirmDelete = await prompts.confirm({
2751
+ message: chalk.red.bold('Are you absolutely sure you want to delete this module?'),
2752
+ default: false,
2753
+ });
2754
+
2755
+ if (confirmDelete) {
2756
+ const typedConfirm = await prompts.text({
2757
+ message: chalk.red.bold('Type "DELETE" to confirm permanent deletion:'),
2758
+ validate: (input) => {
2759
+ if (input !== 'DELETE') {
2760
+ return chalk.red('You must type "DELETE" exactly to proceed');
2761
+ }
2762
+ return; // clack expects undefined for valid input
2763
+ },
2764
+ });
2765
+
2766
+ if (typedConfirm === 'DELETE') {
2767
+ // Remove the module from filesystem and manifest
2768
+ const modulePath = path.join(bmadDir, missing.id);
2769
+ if (await fs.pathExists(modulePath)) {
2770
+ const fsExtra = require('fs-extra');
2771
+ await fsExtra.remove(modulePath);
2772
+ console.log(chalk.yellow(` ✓ Deleted module directory: ${path.relative(projectRoot, modulePath)}`));
2773
+ }
2774
+
2775
+ await this.manifest.removeModule(bmadDir, missing.id);
2776
+ await this.manifest.removeCustomModule(bmadDir, missing.id);
2777
+ console.log(chalk.yellow(` ✓ Removed from manifest`));
2778
+
2779
+ // Also remove from installedModules list
2780
+ if (installedModules && installedModules.includes(missing.id)) {
2781
+ const index = installedModules.indexOf(missing.id);
2782
+ if (index !== -1) {
2783
+ installedModules.splice(index, 1);
2784
+ }
2785
+ }
2786
+
2787
+ removedCount++;
2788
+ console.log(chalk.red.bold(`✓ "${missing.name}" has been permanently removed`));
2789
+ } else {
2790
+ console.log(chalk.dim(' Removal cancelled - module will be kept'));
2791
+ keptCount++;
2792
+ }
2793
+ } else {
2794
+ console.log(chalk.dim(' Removal cancelled - module will be kept'));
2795
+ keptCount++;
2796
+ }
2797
+
2798
+ break;
2799
+ }
2800
+ case 'keep': {
2801
+ keptCount++;
2802
+ keptModulesWithoutSources.push(missing.id);
2803
+ console.log(chalk.dim(` Module will be kept as-is`));
2804
+
2805
+ break;
2806
+ }
2807
+ // No default
2808
+ }
2809
+ }
2810
+
2811
+ // Show summary
2812
+ if (keptCount > 0 || updatedCount > 0 || removedCount > 0) {
2813
+ console.log(chalk.dim(`\nSummary for custom modules with missing sources:`));
2814
+ if (keptCount > 0) console.log(chalk.dim(` • ${keptCount} module(s) kept as-is`));
2815
+ if (updatedCount > 0) console.log(chalk.dim(` • ${updatedCount} module(s) updated with new sources`));
2816
+ if (removedCount > 0) console.log(chalk.red(` • ${removedCount} module(s) permanently deleted`));
2817
+ }
2818
+
2819
+ return {
2820
+ validCustomModules,
2821
+ keptModulesWithoutSources,
2822
+ };
2823
+ }
2824
+ }
2825
+
2826
+ module.exports = { Installer };