<task id="{bmad_folder}/core/tasks/validate-workflow.xml" name="Validate Workflow Output">
  <objective>Run a checklist against a document with thorough analysis and produce a validation report</objective>

  <inputs>
    <input name="workflow" desc="Workflow path containing checklist.md" />
    <input name="checklist" desc="Checklist to validate against (defaults to workflow's checklist.md)" />
    <input name="document" desc="Document to validate (ask user if not specified)" />
  </inputs>

  <flow>
    <step n="1" title="Setup">
      <action>If checklist not provided, load checklist.md from workflow location</action>
      <action>Try to fuzzy match for files similar to the input document name or if user did not provide the document. If document not
        provided or unsure, ask user: "Which document should I validate?"</action>
      <action>Load both the checklist and document</action>
    </step>

    <step n="2" title="Validate" critical="true">
      <mandate>For EVERY checklist item, WITHOUT SKIPPING ANY:</mandate>

      <for-each-item>
        <action>Read requirement carefully</action>
        <action>Search document for evidence along with any ancillary loaded documents or artifacts (quotes with line numbers)</action>
        <action>Analyze deeply - look for explicit AND implied coverage</action>

        <mark-as>
          ✓ PASS - Requirement fully met (provide evidence)
          ⚠ PARTIAL - Some coverage but incomplete (explain gaps)
          ✗ FAIL - Not met or severely deficient (explain why)
          ➖ N/A - Not applicable (explain reason)
        </mark-as>
      </for-each-item>

      <critical>DO NOT SKIP ANY SECTIONS OR ITEMS</critical>
    </step>

    <step n="3" title="Generate Report">
      <action>Create validation-report-{timestamp}.md in document's folder</action>

      <report-format>
        # Validation Report

        **Document:** {document-path}
        **Checklist:** {checklist-path}
        **Date:** {timestamp}

        ## Summary
        - Overall: X/Y passed (Z%)
        - Critical Issues: {count}

        ## Section Results

        ### {Section Name}
        Pass Rate: X/Y (Z%)

        {For each item:}
        [MARK] {Item description}
        Evidence: {Quote with line# or explanation}
        {If FAIL/PARTIAL: Impact: {why this matters}}

        ## Failed Items
        {All ✗ items with recommendations}

        ## Partial Items
        {All ⚠ items with what's missing}

        ## Recommendations
        1. Must Fix: {critical failures}
        2. Should Improve: {important gaps}
        3. Consider: {minor improvements}
      </report-format>
    </step>

    <step n="4" title="Summary for User">
      <action>Present section-by-section summary</action>
      <action>Highlight all critical issues</action>
      <action>Provide path to saved report</action>
      <action>HALT - do not continue unless user asks</action>
    </step>
  </flow>

  <critical-rules>
    <rule>NEVER skip sections - validate EVERYTHING</rule>
    <rule>ALWAYS provide evidence (quotes + line numbers) for marks</rule>
    <rule>Think deeply about each requirement - don't rush</rule>
    <rule>Save report to document's folder automatically</rule>
    <rule>HALT after presenting summary - wait for user</rule>
  </critical-rules>
</task>