instructions.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <workflow>
  2. <critical>The workflow execution engine is governed by: {project-root}/_bmad/core/tasks/workflow.xml</critical>
  3. <critical>You MUST have already loaded and processed: {installed_path}/workflow.yaml</critical>
  4. <critical>Communicate all responses in {communication_language} and generate all documents in {document_output_language}</critical>
  5. <critical>🔥 CRITICAL MISSION: You are creating the ULTIMATE story context engine that prevents LLM developer mistakes, omissions or
  6. disasters! 🔥</critical>
  7. <critical>Your purpose is NOT to copy from epics - it's to create a comprehensive, optimized story file that gives the DEV agent
  8. EVERYTHING needed for flawless implementation</critical>
  9. <critical>COMMON LLM MISTAKES TO PREVENT: reinventing wheels, wrong libraries, wrong file locations, breaking regressions, ignoring UX,
  10. vague implementations, lying about completion, not learning from past work</critical>
  11. <critical>🚨 EXHAUSTIVE ANALYSIS REQUIRED: You must thoroughly analyze ALL artifacts to extract critical context - do NOT be lazy or skim!
  12. This is the most important function in the entire development process!</critical>
  13. <critical>🔬 UTILIZE SUBPROCESSES AND SUBAGENTS: Use research subagents, subprocesses or parallel processing if available to thoroughly
  14. analyze different artifacts simultaneously and thoroughly</critical>
  15. <critical>❓ SAVE QUESTIONS: If you think of questions or clarifications during analysis, save them for the end after the complete story is
  16. written</critical>
  17. <critical>🎯 ZERO USER INTERVENTION: Process should be fully automated except for initial epic/story selection or missing documents</critical>
  18. <step n="1" goal="Determine target story">
  19. <check if="{{story_path}} is provided by user or user provided the epic and story number such as 2-4 or 1.6 or epic 1 story 5">
  20. <action>Parse user-provided story path: extract epic_num, story_num, story_title from format like "1-2-user-auth"</action>
  21. <action>Set {{epic_num}}, {{story_num}}, {{story_key}} from user input</action>
  22. <action>GOTO step 2a</action>
  23. </check>
  24. <action>Check if {{sprint_status}} file exists for auto discover</action>
  25. <check if="sprint status file does NOT exist">
  26. <output>🚫 No sprint status file found and no story specified</output>
  27. <output>
  28. **Required Options:**
  29. 1. Run `sprint-planning` to initialize sprint tracking (recommended)
  30. 2. Provide specific epic-story number to create (e.g., "1-2-user-auth")
  31. 3. Provide path to story documents if sprint status doesn't exist yet
  32. </output>
  33. <ask>Choose option [1], provide epic-story number, path to story docs, or [q] to quit:</ask>
  34. <check if="user chooses 'q'">
  35. <action>HALT - No work needed</action>
  36. </check>
  37. <check if="user chooses '1'">
  38. <output>Run sprint-planning workflow first to create sprint-status.yaml</output>
  39. <action>HALT - User needs to run sprint-planning</action>
  40. </check>
  41. <check if="user provides epic-story number">
  42. <action>Parse user input: extract epic_num, story_num, story_title</action>
  43. <action>Set {{epic_num}}, {{story_num}}, {{story_key}} from user input</action>
  44. <action>GOTO step 2a</action>
  45. </check>
  46. <check if="user provides story docs path">
  47. <action>Use user-provided path for story documents</action>
  48. <action>GOTO step 2a</action>
  49. </check>
  50. </check>
  51. <!-- Auto-discover from sprint status only if no user input -->
  52. <check if="no user input provided">
  53. <critical>MUST read COMPLETE {sprint_status} file from start to end to preserve order</critical>
  54. <action>Load the FULL file: {{sprint_status}}</action>
  55. <action>Read ALL lines from beginning to end - do not skip any content</action>
  56. <action>Parse the development_status section completely</action>
  57. <action>Find the FIRST story (by reading in order from top to bottom) where:
  58. - Key matches pattern: number-number-name (e.g., "1-2-user-auth")
  59. - NOT an epic key (epic-X) or retrospective (epic-X-retrospective)
  60. - Status value equals "backlog"
  61. </action>
  62. <check if="no backlog story found">
  63. <output>📋 No backlog stories found in sprint-status.yaml
  64. All stories are either already created, in progress, or done.
  65. **Options:**
  66. 1. Run sprint-planning to refresh story tracking
  67. 2. Load PM agent and run correct-course to add more stories
  68. 3. Check if current sprint is complete and run retrospective
  69. </output>
  70. <action>HALT</action>
  71. </check>
  72. <action>Extract from found story key (e.g., "1-2-user-authentication"):
  73. - epic_num: first number before dash (e.g., "1")
  74. - story_num: second number after first dash (e.g., "2")
  75. - story_title: remainder after second dash (e.g., "user-authentication")
  76. </action>
  77. <action>Set {{story_id}} = "{{epic_num}}.{{story_num}}"</action>
  78. <action>Store story_key for later use (e.g., "1-2-user-authentication")</action>
  79. <!-- Mark epic as in-progress if this is first story -->
  80. <action>Check if this is the first story in epic {{epic_num}} by looking for {{epic_num}}-1-* pattern</action>
  81. <check if="this is first story in epic {{epic_num}}">
  82. <action>Load {{sprint_status}} and check epic-{{epic_num}} status</action>
  83. <action>If epic status is "backlog" → update to "in-progress"</action>
  84. <action>If epic status is "contexted" (legacy status) → update to "in-progress" (backward compatibility)</action>
  85. <action>If epic status is "in-progress" → no change needed</action>
  86. <check if="epic status is 'done'">
  87. <output>🚫 ERROR: Cannot create story in completed epic</output>
  88. <output>Epic {{epic_num}} is marked as 'done'. All stories are complete.</output>
  89. <output>If you need to add more work, either:</output>
  90. <output>1. Manually change epic status back to 'in-progress' in sprint-status.yaml</output>
  91. <output>2. Create a new epic for additional work</output>
  92. <action>HALT - Cannot proceed</action>
  93. </check>
  94. <check if="epic status is not one of: backlog, contexted, in-progress, done">
  95. <output>🚫 ERROR: Invalid epic status '{{epic_status}}'</output>
  96. <output>Epic {{epic_num}} has invalid status. Expected: backlog, in-progress, or done</output>
  97. <output>Please fix sprint-status.yaml manually or run sprint-planning to regenerate</output>
  98. <action>HALT - Cannot proceed</action>
  99. </check>
  100. <output>📊 Epic {{epic_num}} status updated to in-progress</output>
  101. </check>
  102. <action>GOTO step 2a</action>
  103. </check>
  104. <action>Load the FULL file: {{sprint_status}}</action>
  105. <action>Read ALL lines from beginning to end - do not skip any content</action>
  106. <action>Parse the development_status section completely</action>
  107. <action>Find the FIRST story (by reading in order from top to bottom) where:
  108. - Key matches pattern: number-number-name (e.g., "1-2-user-auth")
  109. - NOT an epic key (epic-X) or retrospective (epic-X-retrospective)
  110. - Status value equals "backlog"
  111. </action>
  112. <check if="no backlog story found">
  113. <output>📋 No backlog stories found in sprint-status.yaml
  114. All stories are either already created, in progress, or done.
  115. **Options:**
  116. 1. Run sprint-planning to refresh story tracking
  117. 2. Load PM agent and run correct-course to add more stories
  118. 3. Check if current sprint is complete and run retrospective
  119. </output>
  120. <action>HALT</action>
  121. </check>
  122. <action>Extract from found story key (e.g., "1-2-user-authentication"):
  123. - epic_num: first number before dash (e.g., "1")
  124. - story_num: second number after first dash (e.g., "2")
  125. - story_title: remainder after second dash (e.g., "user-authentication")
  126. </action>
  127. <action>Set {{story_id}} = "{{epic_num}}.{{story_num}}"</action>
  128. <action>Store story_key for later use (e.g., "1-2-user-authentication")</action>
  129. <!-- Mark epic as in-progress if this is first story -->
  130. <action>Check if this is the first story in epic {{epic_num}} by looking for {{epic_num}}-1-* pattern</action>
  131. <check if="this is first story in epic {{epic_num}}">
  132. <action>Load {{sprint_status}} and check epic-{{epic_num}} status</action>
  133. <action>If epic status is "backlog" → update to "in-progress"</action>
  134. <action>If epic status is "contexted" (legacy status) → update to "in-progress" (backward compatibility)</action>
  135. <action>If epic status is "in-progress" → no change needed</action>
  136. <check if="epic status is 'done'">
  137. <output>🚫 ERROR: Cannot create story in completed epic</output>
  138. <output>Epic {{epic_num}} is marked as 'done'. All stories are complete.</output>
  139. <output>If you need to add more work, either:</output>
  140. <output>1. Manually change epic status back to 'in-progress' in sprint-status.yaml</output>
  141. <output>2. Create a new epic for additional work</output>
  142. <action>HALT - Cannot proceed</action>
  143. </check>
  144. <check if="epic status is not one of: backlog, contexted, in-progress, done">
  145. <output>🚫 ERROR: Invalid epic status '{{epic_status}}'</output>
  146. <output>Epic {{epic_num}} has invalid status. Expected: backlog, in-progress, or done</output>
  147. <output>Please fix sprint-status.yaml manually or run sprint-planning to regenerate</output>
  148. <action>HALT - Cannot proceed</action>
  149. </check>
  150. <output>📊 Epic {{epic_num}} status updated to in-progress</output>
  151. </check>
  152. <action>GOTO step 2a</action>
  153. </step>
  154. <step n="2" goal="Load and analyze core artifacts">
  155. <critical>🔬 EXHAUSTIVE ARTIFACT ANALYSIS - This is where you prevent future developer fuckups!</critical>
  156. <!-- Load all available content through discovery protocol -->
  157. <invoke-protocol
  158. name="discover_inputs" />
  159. <note>Available content: {epics_content}, {prd_content}, {architecture_content}, {ux_content},
  160. {project_context}</note>
  161. <!-- Analyze epics file for story foundation -->
  162. <action>From {epics_content}, extract Epic {{epic_num}} complete context:</action> **EPIC ANALYSIS:** - Epic
  163. objectives and business value - ALL stories in this epic for cross-story context - Our specific story's requirements, user story
  164. statement, acceptance criteria - Technical requirements and constraints - Dependencies on other stories/epics - Source hints pointing to
  165. original documents <!-- Extract specific story requirements -->
  166. <action>Extract our story ({{epic_num}}-{{story_num}}) details:</action> **STORY FOUNDATION:** - User story statement
  167. (As a, I want, so that) - Detailed acceptance criteria (already BDD formatted) - Technical requirements specific to this story -
  168. Business context and value - Success criteria <!-- Previous story analysis for context continuity -->
  169. <check if="story_num > 1">
  170. <action>Load previous story file: {{story_dir}}/{{epic_num}}-{{previous_story_num}}-*.md</action> **PREVIOUS STORY INTELLIGENCE:** -
  171. Dev notes and learnings from previous story - Review feedback and corrections needed - Files that were created/modified and their
  172. patterns - Testing approaches that worked/didn't work - Problems encountered and solutions found - Code patterns established <action>Extract
  173. all learnings that could impact current story implementation</action>
  174. </check>
  175. <!-- Git intelligence for previous work patterns -->
  176. <check
  177. if="previous story exists AND git repository detected">
  178. <action>Get last 5 commit titles to understand recent work patterns</action>
  179. <action>Analyze 1-5 most recent commits for relevance to current story:
  180. - Files created/modified
  181. - Code patterns and conventions used
  182. - Library dependencies added/changed
  183. - Architecture decisions implemented
  184. - Testing approaches used
  185. </action>
  186. <action>Extract actionable insights for current story implementation</action>
  187. </check>
  188. </step>
  189. <step n="3" goal="Architecture analysis for developer guardrails">
  190. <critical>🏗️ ARCHITECTURE INTELLIGENCE - Extract everything the developer MUST follow!</critical> **ARCHITECTURE DOCUMENT ANALYSIS:** <action>Systematically
  191. analyze architecture content for story-relevant requirements:</action>
  192. <!-- Load architecture - single file or sharded -->
  193. <check if="architecture file is single file">
  194. <action>Load complete {architecture_content}</action>
  195. </check>
  196. <check if="architecture is sharded to folder">
  197. <action>Load architecture index and scan all architecture files</action>
  198. </check> **CRITICAL ARCHITECTURE EXTRACTION:** <action>For
  199. each architecture section, determine if relevant to this story:</action> - **Technical Stack:** Languages, frameworks, libraries with
  200. versions - **Code Structure:** Folder organization, naming conventions, file patterns - **API Patterns:** Service structure, endpoint
  201. patterns, data contracts - **Database Schemas:** Tables, relationships, constraints relevant to story - **Security Requirements:**
  202. Authentication patterns, authorization rules - **Performance Requirements:** Caching strategies, optimization patterns - **Testing
  203. Standards:** Testing frameworks, coverage expectations, test patterns - **Deployment Patterns:** Environment configurations, build
  204. processes - **Integration Patterns:** External service integrations, data flows <action>Extract any story-specific requirements that the
  205. developer MUST follow</action>
  206. <action>Identify any architectural decisions that override previous patterns</action>
  207. </step>
  208. <step n="4" goal="Web research for latest technical specifics">
  209. <critical>🌐 ENSURE LATEST TECH KNOWLEDGE - Prevent outdated implementations!</critical> **WEB INTELLIGENCE:** <action>Identify specific
  210. technical areas that require latest version knowledge:</action>
  211. <!-- Check for libraries/frameworks mentioned in architecture -->
  212. <action>From architecture analysis, identify specific libraries, APIs, or
  213. frameworks</action>
  214. <action>For each critical technology, research latest stable version and key changes:
  215. - Latest API documentation and breaking changes
  216. - Security vulnerabilities or updates
  217. - Performance improvements or deprecations
  218. - Best practices for current version
  219. </action>
  220. **EXTERNAL CONTEXT INCLUSION:** <action>Include in story any critical latest information the developer needs:
  221. - Specific library versions and why chosen
  222. - API endpoints with parameters and authentication
  223. - Recent security patches or considerations
  224. - Performance optimization techniques
  225. - Migration considerations if upgrading
  226. </action>
  227. </step>
  228. <step n="5" goal="Create comprehensive story file">
  229. <critical>📝 CREATE ULTIMATE STORY FILE - The developer's master implementation guide!</critical>
  230. <action>Initialize from template.md:
  231. {default_output_file}</action>
  232. <template-output file="{default_output_file}">story_header</template-output>
  233. <!-- Story foundation from epics analysis -->
  234. <template-output
  235. file="{default_output_file}">story_requirements</template-output>
  236. <!-- Developer context section - MOST IMPORTANT PART -->
  237. <template-output file="{default_output_file}">
  238. developer_context_section</template-output> **DEV AGENT GUARDRAILS:** <template-output file="{default_output_file}">
  239. technical_requirements</template-output>
  240. <template-output file="{default_output_file}">architecture_compliance</template-output>
  241. <template-output
  242. file="{default_output_file}">library_framework_requirements</template-output>
  243. <template-output file="{default_output_file}">
  244. file_structure_requirements</template-output>
  245. <template-output file="{default_output_file}">testing_requirements</template-output>
  246. <!-- Previous story intelligence -->
  247. <check
  248. if="previous story learnings available">
  249. <template-output file="{default_output_file}">previous_story_intelligence</template-output>
  250. </check>
  251. <!-- Git intelligence -->
  252. <check
  253. if="git analysis completed">
  254. <template-output file="{default_output_file}">git_intelligence_summary</template-output>
  255. </check>
  256. <!-- Latest technical specifics -->
  257. <check if="web research completed">
  258. <template-output file="{default_output_file}">latest_tech_information</template-output>
  259. </check>
  260. <!-- Project context reference -->
  261. <template-output
  262. file="{default_output_file}">project_context_reference</template-output>
  263. <!-- Final status update -->
  264. <template-output file="{default_output_file}">
  265. story_completion_status</template-output>
  266. <!-- CRITICAL: Set status to ready-for-dev -->
  267. <action>Set story Status to: "ready-for-dev"</action>
  268. <action>Add completion note: "Ultimate
  269. context engine analysis completed - comprehensive developer guide created"</action>
  270. </step>
  271. <step n="6" goal="Update sprint status and finalize">
  272. <invoke-task>Validate against checklist at {installed_path}/checklist.md using _bmad/core/tasks/validate-workflow.xml</invoke-task>
  273. <action>Save story document unconditionally</action>
  274. <!-- Update sprint status -->
  275. <check if="sprint status file exists">
  276. <action>Update {{sprint_status}}</action>
  277. <action>Load the FULL file and read all development_status entries</action>
  278. <action>Find development_status key matching {{story_key}}</action>
  279. <action>Verify current status is "backlog" (expected previous state)</action>
  280. <action>Update development_status[{{story_key}}] = "ready-for-dev"</action>
  281. <action>Save file, preserving ALL comments and structure including STATUS DEFINITIONS</action>
  282. </check>
  283. <action>Report completion</action>
  284. <output>**🎯 ULTIMATE BMad Method STORY CONTEXT CREATED, {user_name}!**
  285. **Story Details:**
  286. - Story ID: {{story_id}}
  287. - Story Key: {{story_key}}
  288. - File: {{story_file}}
  289. - Status: ready-for-dev
  290. **Next Steps:**
  291. 1. Review the comprehensive story in {{story_file}}
  292. 2. Run dev agents `dev-story` for optimized implementation
  293. 3. Run `code-review` when complete (auto-marks done)
  294. 4. Optional: Run TEA `*automate` after `dev-story` to generate guardrail tests
  295. **The developer now has everything needed for flawless implementation!**
  296. </output>
  297. </step>
  298. </workflow>