<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="drawio" version="26.0.0">
  <diagram name="Headroom compression sequence">
    <mxGraphModel dx="1600" dy="1200" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
      <root>
        <mxCell id="0" />
        <mxCell id="1" parent="0" />
        <mxCell id="2" value="Git hook" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontStyle=1;" vertex="1" parent="1"><mxGeometry x="40" y="40" width="120" height="50" as="geometry" /></mxCell>
        <mxCell id="3" value="llm.py&#xa;get_commit_msg()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontStyle=1;" vertex="1" parent="1"><mxGeometry x="250" y="40" width="150" height="50" as="geometry" /></mxCell>
        <mxCell id="4" value="Headroom&#xa;compress()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontStyle=1;" vertex="1" parent="1"><mxGeometry x="510" y="40" width="150" height="50" as="geometry" /></mxCell>
        <mxCell id="5" value="Router +&#xa;content transforms" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;" vertex="1" parent="1"><mxGeometry x="770" y="40" width="170" height="50" as="geometry" /></mxCell>
        <mxCell id="6" value="LiteLLM&#xa;token counter" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontStyle=1;" vertex="1" parent="1"><mxGeometry x="1050" y="40" width="150" height="50" as="geometry" /></mxCell>
        <mxCell id="7" value="Model provider" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontStyle=1;" vertex="1" parent="1"><mxGeometry x="1310" y="40" width="150" height="50" as="geometry" /></mxCell>
        <mxCell id="8" value="load prompt messages; append staged diff as final user message" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="2" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="205" y="130" /></Array></mxGeometry></mxCell>
        <mxCell id="9" value="messages, model, LiteLLM-derived token limit, compress_user_messages=True, protect_recent=0" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="3" target="4"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="455" y="190" /></Array></mxGeometry></mxCell>
        <mxCell id="10" value="inspect message content and select safe transform" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="4" target="5"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="715" y="250" /></Array></mxGeometry></mxCell>
        <mxCell id="11" value="apply diff-aware compression when eligible" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="5" target="4"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="715" y="310" /></Array></mxGeometry></mxCell>
        <mxCell id="12" value="compressed messages + tokens_before/tokens_after" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;dashed=1;endArrow=open;" edge="1" parent="1" source="4" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="455" y="370" /></Array></mxGeometry></mxCell>
        <mxCell id="13" value="token_counter(model, messages)" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="3" target="6"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="925" y="430" /></Array></mxGeometry></mxCell>
        <mxCell id="14" value="prompt estimate" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;dashed=1;endArrow=open;" edge="1" parent="1" source="6" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="925" y="490" /></Array></mxGeometry></mxCell>
        <mxCell id="15" value="if still oversized: summarize diff, compress again, re-estimate" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeColor=#d79b00;" edge="1" parent="1" source="3" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="440" y="560" /><mxPoint x="440" y="620" /><mxPoint x="250" y="620" /></Array></mxGeometry></mxCell>
        <mxCell id="16" value="completion(messages)" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;" edge="1" parent="1" source="3" target="7"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1260" y="700" /></Array></mxGeometry></mxCell>
        <mxCell id="17" value="commit message response" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;dashed=1;endArrow=open;" edge="1" parent="1" source="7" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="1260" y="760" /></Array></mxGeometry></mxCell>
        <mxCell id="18" value="Fail open: unavailable, import/runtime error, no positive baseline, or unsafe/no-op transform keeps original messages" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1"><mxGeometry x="510" y="820" width="690" height="60" as="geometry" /></mxCell>
        <mxCell id="19" value="compression fallback" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;dashed=1;endArrow=open;strokeColor=#b85450;" edge="1" parent="1" source="18" target="3"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="455" y="850" /></Array></mxGeometry></mxCell>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>