{# ============================================================================ #}
{# Template: planning_xsd_retry.txt                                             #}
{# Version: 4.0 - Mandatory XSD reading with file-based context                 #}
{# ============================================================================ #}
{#                                                                             #}
{# PURPOSE:                                                                    #}
{#   Retry prompt when XML validation fails during planning phase.              #}
{#   XSD schema and last output are written to files to keep prompt small.      #}
{#                                                                             #}
{# VARIABLES:                                                                  #}
{#   {{XSD_ERROR}} - XSD validation error message (required)                    #}
{#                                                                             #}
{# FILES TO READ:                                                               #}
{#   .agent/tmp/plan.xsd       - The XSD schema your output must conform to     #}
{#   .agent/tmp/last_output.xml - Your previous invalid output                  #}
{#                                                                             #}
{# OUTPUT FORMAT:                                                               #}
{#   Valid <ralph-plan> XML conforming to the XSD schema                       #}
{# ============================================================================ #}

{{> shared/_unattended_mode}}

Your XML at `{{PLAN_XML_PATH}}` failed validation.

ERROR: {{XSD_ERROR}}

Fix `{{PLAN_XML_PATH}}` based on `{{PLAN_XSD_PATH}}`.

IMPORTANT: Use file editing tools to modify the XML file directly. Do NOT output the corrected XML in your response.

═══════════════════════════════════════════════════════════════════════════════
COMMON MISTAKES TO AVOID
═══════════════════════════════════════════════════════════════════════════════

1. Start IMMEDIATELY with <ralph-plan> - NO text before it
2. End with </ralph-plan> - NO text after it
3. NO markdown code fences (```) around the XML
4. ALL 5 sections are REQUIRED: ralph-summary, ralph-implementation-steps,
   ralph-critical-files, ralph-risks-mitigations, ralph-verification-strategy
5. <ralph-summary> MUST have <context> (non-empty) AND <scope-items> (minimum 3 items)
6. Each <step> MUST have number attribute, <title>, and <content>
7. file-change steps MUST have <target-files> with at least one <file path="..." action="..."/>
8. <content> MUST have at least one element (<paragraph>, <code-block>, <list>, etc.)
9. <primary-files> MUST have at least one <file path="..." action="..."/>
10. Each <risk-pair> MUST have both <risk> and <mitigation>
11. Each <verification> MUST have both <method> and <expected-outcome>
12. For inline code: <code>a &lt; b</code>
13. For code blocks, ALWAYS use CDATA:
    <code-block language="rust"><![CDATA[if a < b { ... }]]></code-block>
    CDATA preserves content exactly - no escaping needed inside.

After reading the XSD schema, fix the validation error and resend your plan.
