shard-doc.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <task id="_bmad/core/tasks/shard-doc" name="Shard Document"
  2. description="Splits large markdown documents into smaller, organized files based on level 2 (default) sections. Use if the user says perform shard document">
  3. <objective>Split large markdown documents into smaller, organized files based on level 2 sections using @kayvan/markdown-tree-parser tool</objective>
  4. <llm critical="true">
  5. <i>MANDATORY: Execute ALL steps in the flow section IN EXACT ORDER</i>
  6. <i>DO NOT skip steps or change the sequence</i>
  7. <i>HALT immediately when halt-conditions are met</i>
  8. <i>Each action xml tag within step xml tag is a REQUIRED action to complete that step</i>
  9. <i>Sections outside flow (validation, output, critical-context) provide essential context - review and apply throughout execution</i>
  10. </llm>
  11. <critical-context>
  12. <i>Uses `npx @kayvan/markdown-tree-parser` to automatically shard documents by level 2 headings and generate an index</i>
  13. </critical-context>
  14. <flow>
  15. <step n="1" title="Get Source Document">
  16. <action>Ask user for the source document path if not provided already</action>
  17. <action>Verify file exists and is accessible</action>
  18. <action>Verify file is markdown format (.md extension)</action>
  19. <action if="file not found or not markdown">HALT with error message</action>
  20. </step>
  21. <step n="2" title="Get Destination Folder">
  22. <action>Determine default destination: same location as source file, folder named after source file without .md extension</action>
  23. <action>Example: /path/to/architecture.md → /path/to/architecture/</action>
  24. <action>Ask user for the destination folder path ([y] to confirm use of default: [suggested-path], else enter a new path)</action>
  25. <action if="user accepts default">Use the suggested destination path</action>
  26. <action if="user provides custom path">Use the custom destination path</action>
  27. <action>Verify destination folder exists or can be created</action>
  28. <action>Check write permissions for destination</action>
  29. <action if="permission denied">HALT with error message</action>
  30. </step>
  31. <step n="3" title="Execute Sharding">
  32. <action>Inform user that sharding is beginning</action>
  33. <action>Execute command: `npx @kayvan/markdown-tree-parser explode [source-document] [destination-folder]`</action>
  34. <action>Capture command output and any errors</action>
  35. <action if="command fails">HALT and display error to user</action>
  36. </step>
  37. <step n="4" title="Verify Output">
  38. <action>Check that destination folder contains sharded files</action>
  39. <action>Verify index.md was created in destination folder</action>
  40. <action>Count the number of files created</action>
  41. <action if="no files created">HALT with error message</action>
  42. </step>
  43. <step n="5" title="Report Completion">
  44. <action>Display completion report to user including:</action>
  45. <i>- Source document path and name</i>
  46. <i>- Destination folder path</i>
  47. <i>- Number of section files created</i>
  48. <i>- Confirmation that index.md was created</i>
  49. <i>- Any tool output or warnings</i>
  50. <action>Inform user that sharding completed successfully</action>
  51. </step>
  52. <step n="6" title="Handle Original Document">
  53. <critical>Keeping both the original and sharded versions defeats the purpose of sharding and can cause confusion</critical>
  54. <action>Present user with options for the original document:</action>
  55. <ask>What would you like to do with the original document `[source-document-name]`?
  56. Options:
  57. [d] Delete - Remove the original (recommended - shards can always be recombined)
  58. [m] Move to archive - Move original to a backup/archive location
  59. [k] Keep - Leave original in place (NOT recommended - defeats sharding purpose)
  60. Your choice (d/m/k):</ask>
  61. <check if="user selects 'd' (delete)">
  62. <action>Delete the original source document file</action>
  63. <action>Confirm deletion to user: "✓ Original document deleted: [source-document-path]"</action>
  64. <note>The document can be reconstructed from shards by concatenating all section files in order</note>
  65. </check>
  66. <check if="user selects 'm' (move)">
  67. <action>Determine default archive location: same directory as source, in an "archive" subfolder</action>
  68. <action>Example: /path/to/architecture.md → /path/to/archive/architecture.md</action>
  69. <ask>Archive location ([y] to use default: [default-archive-path], or provide custom path):</ask>
  70. <action if="user accepts default">Use default archive path</action>
  71. <action if="user provides custom path">Use custom archive path</action>
  72. <action>Create archive directory if it doesn't exist</action>
  73. <action>Move original document to archive location</action>
  74. <action>Confirm move to user: "✓ Original document moved to: [archive-path]"</action>
  75. </check>
  76. <check if="user selects 'k' (keep)">
  77. <action>Display warning to user:</action>
  78. <output>⚠️ WARNING: Keeping both original and sharded versions is NOT recommended.
  79. This creates confusion because:
  80. - The discover_inputs protocol may load the wrong version
  81. - Updates to one won't reflect in the other
  82. - You'll have duplicate content taking up space
  83. Consider deleting or archiving the original document.</output>
  84. <action>Confirm user choice: "Original document kept at: [source-document-path]"</action>
  85. </check>
  86. </step>
  87. </flow>
  88. <halt-conditions critical="true">
  89. <i>HALT if npx command fails or produces no output files</i>
  90. </halt-conditions>
  91. </task>