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

{% block extra_constraints %}
        <rule priority="critical">Do NOT push to remote.</rule>
        <rule priority="critical">Do NOT amend previous commits.</rule>
        <rule priority="high">Use clear, descriptive commit messages.</rule>
{% endblock %}

{% block instructions %}
        <phase name="prerequisites">
            <commands><![CDATA[
git status 2>/dev/null || echo "Not a git repo"
git diff --staged --stat 2>/dev/null || echo "Nothing staged"
            ]]></commands>
            <fallback>If NOT a git repo or nothing staged:
                - Output: &lt;routing_signal&gt;pass&lt;/routing_signal&gt;
                - Log: "Skipped commit: &lt;reason&gt;"
                - Exit (engine handles completion)</fallback>
        </phase>

        <phase name="get_bearings">
            <commands><![CDATA[
pwd
cat .claudesprint/project/current_issue.json
            ]]></commands>
            <extract>issue_id, issue_title, changes</extract>
        </phase>

        <phase name="verify_and_commit">
            <steps>
                <step>Review git diff --staged --stat</step>
                <step>Ensure correct files staged</step>
            </steps>
            <commit_format><![CDATA[
git commit -m "<type>: <description>

- <detail 1>
- <detail 2>

Issue: <issue_id>"
            ]]></commit_format>
            <types>feat, fix, refactor, test, docs, chore</types>
            <verify><![CDATA[
git log --oneline -3
            ]]></verify>
        </phase>

        <phase name="update_sprint_json">
            <description>Mark issue as completed:</description>
            <update field="status">Change to "completed"</update>
            <update field="history">Add: {"timestamp": "&lt;ISO&gt;", "action": "completed", "session_id": "&lt;id&gt;"}</update>
            <update field="metadata">Update counts</update>
        </phase>

        <phase name="update_current_issue_json">
            <note>Do NOT change the step field - engine routing handles transitions</note>
            <update field="repo_state.git_head">New SHA</update>
            <update field="repo_state.dirty">false</update>
            <update field="changes">Clear (now in git)</update>
            <update field="commands_run">Add: commit command</update>
        </phase>

        <phase name="log_and_exit">
            <commands><![CDATA[
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] STEP: commit-changes DONE" >> .claudesprint/project/current_issue.log
echo "  Commit: <short SHA>" >> .claudesprint/project/current_issue.log
echo "  Issue: <issue_id> - <issue_title>" >> .claudesprint/project/current_issue.log
            ]]></commands>
            <output><![CDATA[<routing_signal>pass</routing_signal>]]></output>
        </phase>
{% endblock %}

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