shard-doc.xml 5.6 KB

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