{# ============================================================================ #}
{# Template: planning_xsd_retry.txt                                             #}
{# Version: 5.0 - STRICT XML-only fix mode                                      #}
{# ============================================================================ #}
{#                                                                             #}
{# PURPOSE:                                                                    #}
{#   Retry prompt when XML validation fails during planning phase.              #}
{#   This is STRICTLY for fixing malformed XML - NO other actions allowed.     #}
{#                                                                             #}
{# 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}}

═══════════════════════════════════════════════════════════════════════════════
XSD VALIDATION FAILED - FIX XML ONLY
═══════════════════════════════════════════════════════════════════════════════

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

ERROR: {{XSD_ERROR}}

═══════════════════════════════════════════════════════════════════════════════
CRITICAL INSTRUCTIONS - READ CAREFULLY
═══════════════════════════════════════════════════════════════════════════════

You MUST:
1. Read the XSD schema at `{{PLAN_XSD_PATH}}`
2. Read your previous invalid output at `.agent/tmp/last_output.xml`
3. Fix ONLY the XML structure/format issues
4. Write the corrected XML to `{{PLAN_XML_PATH}}`

## AUTHORIZATION OVERRIDE (CRITICAL)

You are explicitly authorized to write EXACTLY ONE file:
- `{{PLAN_XML_PATH}}`

Writing the XML file is MANDATORY.
This OVERRIDES the safety mode restrictions only.
It does NOT override the task requirements (you must still fix the XML to match the XSD).

This is a READ-ONLY task EXCEPT FOR writing `{{PLAN_XML_PATH}}`.
You MUST NOT create, modify, or delete any other files.

Not writing the XML file is a FAILURE.
Writing XML that does not conform to the XSD schema is a FAILURE.

You MUST NOT:
- Read any code files
- Analyze the codebase
- Run any commands
- Do ANY planning work
- Change the content/meaning of your plan - ONLY fix the XML format

This is a PURE XML SYNTAX FIX. Your planning work is done. The only problem
is that your XML output doesn't conform to the schema. Fix the XML structure,
nothing else.

═══════════════════════════════════════════════════════════════════════════════
COMMON XML MISTAKES TO FIX
═══════════════════════════════════════════════════════════════════════════════

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 ONLY the XML validation error.
DO NOT do any other work.
