{% extends '_base.xml.j2' %}

{% block extra_constraints %}
        <rule priority="high">Select exactly ONE issue per invocation.</rule>
        <rule priority="high">Do NOT start implementation - only select and set up context.</rule>
        <rule priority="medium">Provide clear selection rationale.</rule>
{% endblock %}

{% block instructions %}
        <phase name="get_bearings">
            <commands><![CDATA[
pwd
cat .claudesprint/project/current_issue.json 2>/dev/null || echo "No current issue"
claudesprint-tools sprint available
git log --oneline -5 2>/dev/null || echo "Not a git repo"
git status --short 2>/dev/null | head -n 10
            ]]></commands>
        </phase>

        <phase name="decision_flow">
            <decision condition="in_progress_issues exists">Resume that issue, skip to Phase 3</decision>
            <decision condition="message: SPRINT_COMPLETE">Output "SPRINT_COMPLETE" and exit</decision>
            <decision condition="available_issues exists">Continue to selection</decision>
            <decision condition="only blocked_issues">Report blocking situation</decision>
        </phase>

        <phase name="selection_criteria">
            <description>The available_issues array is priority-sorted. Within top priority tier, consider:</description>
            <criterion>Context continuity with recent work</criterion>
            <criterion>Unblocker impact (issues that unblock others)</criterion>
            <criterion>Category sequencing (setup/infra before features)</criterion>
            <action>Select ONE issue, then run: claudesprint-tools sprint details &lt;issue_id&gt;</action>
        </phase>

        <phase name="update_sprint_json">
            <description>For selected issue:</description>
            <commands><![CDATA[
# Start the issue (updates sprint.json status to in_progress)
claudesprint-tools sprint start <issue_id>
            ]]></commands>
        </phase>

        <phase name="update_state">
            <description>Initialize current_issue.json via CLI:</description>
            <commands><![CDATA[
# Initialize issue state for selected issue
claudesprint-tools issue init <issue_id> --step=read-docs --goal="Gather documentation for: <title>"
            ]]></commands>
            <note>The init command creates the current_issue.json with proper schema.</note>
        </phase>

        <phase name="log_and_exit">
            <commands><![CDATA[
echo "[<ISO>] SELECTED: <id> - <title>" >> .claudesprint/project/current_issue.log
echo "  Rationale: <why chosen>" >> .claudesprint/project/current_issue.log
            ]]></commands>
            <output_format><![CDATA[
=== Issue Selected ===
ID: <id> | Title: <title> | Priority: <p> | Category: <c>
Acceptance Criteria: <list>
Rationale: <why chosen>
Next step: read-docs
            ]]></output_format>
        </phase>
{% endblock %}

{% block termination %}
        <note>No termination tag required for this step.</note>
{% endblock %}
