<?xml version="1.0" encoding="UTF-8"?>
<mxfile host="drawio" version="26.0.0">
  <diagram id="solpi-lifecycle" name="Page-1">
    <mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1360" pageHeight="760" background="#FFFFFF" math="0" shadow="0">
      <root>
        <mxCell id="0" />
        <mxCell id="1" parent="0" />

        <!-- Title Banner -->
        <mxCell id="2" value="SoL-Pi 在 Pi Agent Loop 中的生命周期挂载与四机制协同链路（零侵入扩展架构）" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#1E293B;strokeColor=#0F172A;fontColor=#FFFFFF;fontSize=18;fontStyle=1;arcSize=12;" vertex="1" parent="1">
          <mxGeometry x="40" y="25" width="1280" height="50" as="geometry" />
        </mxCell>

        <!-- Container 1: Startup & Tool Registration -->
        <mxCell id="3" value="阶段一：会话启动与工具注册 (session_start)" style="swimlane;startSize=36;rounded=1;fillColor=#F8FAFC;strokeColor=#64748B;fontColor=#0F172A;fontSize=15;fontStyle=1;swimlaneFillColor=#F8FAFC;arcSize=8;pointerEvents=0;" vertex="1" parent="1">
          <mxGeometry x="40" y="100" width="360" height="590" as="geometry" />
        </mxCell>

        <mxCell id="4" value="加载唯一配置 loadSolPiConfig&#xa;1. .pi/sol-pi.json (需 isProjectTrusted)&#xa;2. ~/.pi/agent/sol-pi.json&#xa;3. DEFAULT_CONFIG (全默认关闭)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#E2E8F0;strokeColor=#475569;fontColor=#0F172A;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="3">
          <mxGeometry x="25" y="60" width="310" height="105" as="geometry" />
        </mxCell>

        <mxCell id="5" value="Action Fusion 工具覆写&#xa;覆写 edit / write 工具 schema&#xa;新增可选参数 then_run {command, timeout}&#xa;继承 SettingsManager 的 shellPath" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DCFCE7;strokeColor=#16A34A;fontColor=#14532D;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="3">
          <mxGeometry x="25" y="205" width="310" height="105" as="geometry" />
        </mxCell>

        <mxCell id="6" value="注册状态与召回工具&#xa;• obs_recall(id, offset)：分页按字节召回&#xa;• update_plan(steps, progress)：&#xa;  设置 exposure=&quot;model-only&quot; 维护计划" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DBEAFE;strokeColor=#2563EB;fontColor=#1E3A8A;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="3">
          <mxGeometry x="25" y="350" width="310" height="105" as="geometry" />
        </mxCell>

        <mxCell id="7" value="初始化会话级存储 runtimeRoot&#xa;{sessionDir}/sol-pi/{sessionId}/&#xa;无会话模式自动降级至 os.tmpdir()" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=10;fillColor=#FEF3C7;strokeColor=#D97706;fontColor=#78350F;fontSize=13;arcSize=10;" vertex="1" parent="3">
          <mxGeometry x="25" y="485" width="310" height="80" as="geometry" />
        </mxCell>

        <!-- Container 2: Tool Execution & Context Projection -->
        <mxCell id="8" value="阶段二：工具执行与上下文投影 (Tool &amp; Context 层)" style="swimlane;startSize=36;rounded=1;fillColor=#F8FAFC;strokeColor=#16A34A;fontColor=#14532D;fontSize=15;fontStyle=1;swimlaneFillColor=#F8FAFC;arcSize=8;pointerEvents=0;" vertex="1" parent="1">
          <mxGeometry x="440" y="100" width="425" height="590" as="geometry" />
        </mxCell>

        <mxCell id="9" value="① Action Fusion (edit / write 执行期)&#xa;• withFusedFileQueue 单文件串行化锁&#xa;• 先执行文件写入，再校验前后 SHA-256 一致&#xa;• 同一轮内执行 bash 附加 [then_run:succeeded]" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DCFCE7;strokeColor=#16A34A;fontColor=#14532D;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="8">
          <mxGeometry x="22" y="60" width="380" height="115" as="geometry" />
        </mxCell>

        <mxCell id="10" value="② Evidence-Preserving Reducer (tool_result 钩子)&#xa;• 拦截 ≥ 4 KiB 的构建/测试命令输出并归档原件&#xa;• 委派轻量模型 (默认 gpt-5.6-luna) 抽取关键行&#xa;• validateReceipt 逐字节校验子串、哈希与退出状态&#xa;• 签发 sol_pi_evidence_receipt_v1 凭据" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FEF9C3;strokeColor=#CA8A04;fontColor=#713F12;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="8">
          <mxGeometry x="22" y="220" width="380" height="130" as="geometry" />
        </mxCell>

        <mxCell id="11" value="③ ObservationPack (context 钩子 · 先于 OCC 注册)&#xa;• 识别并跳过含 sol_pi_evidence_receipt_v1 的结果&#xa;• &gt; 10 KiB 纯文本前 2 次全量发送 (FULL_SENDS=2)&#xa;• 第 3 次起原地修改 message.content 为 obs_ 句柄&#xa;  + 1 KiB 首尾完整行摘要（不破坏 Prompt Cache 前缀）" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DBEAFE;strokeColor=#2563EB;fontColor=#1E3A8A;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="8">
          <mxGeometry x="22" y="400" width="380" height="150" as="geometry" />
        </mxCell>

        <!-- Container 3: Online Context Compact -->
        <mxCell id="12" value="阶段三：子任务边界压缩与续跑 (Online Context Compact)" style="swimlane;startSize=36;rounded=1;fillColor=#F8FAFC;strokeColor=#7C3AED;fontColor=#4C1D95;fontSize=14;fontStyle=1;swimlaneFillColor=#F8FAFC;arcSize=8;pointerEvents=0;" vertex="1" parent="1">
          <mxGeometry x="905" y="100" width="415" height="590" as="geometry" />
        </mxCell>

        <mxCell id="13" value="④a 真实请求与窗口增长计量&#xa;• context → before_provider_request → message_end&#xa;• 过滤中止请求与 Pi 1.0 cache-warming 重放&#xa;• 累计 requestCount、正增量均值与缓存负债摊销" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#F3E8FF;strokeColor=#7C3AED;fontColor=#4C1D95;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="12">
          <mxGeometry x="25" y="60" width="365" height="115" as="geometry" />
        </mxCell>

        <mxCell id="14" value="④b 子任务完成边界门禁 (turn_end)&#xa;• update_plan 将已登记步骤标为 completed&#xa;• 结合投影体积估算可移除 archiveTokens&#xa;• decideCompaction 核算缓存重写成本与剩余请求数&#xa;• 门禁通过则调用 context.abort() 暂停当前运行" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#F3E8FF;strokeColor=#7C3AED;fontColor=#4C1D95;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="12">
          <mxGeometry x="25" y="220" width="365" height="130" as="geometry" />
        </mxCell>

        <mxCell id="15" value="④c 原生压缩与自动续跑 (agent_settled)&#xa;• 拦截间歇期 threshold 自动压缩避免抢占&#xa;• 调用 context.compact() 生成摘要并记入缓存负债&#xa;• 调用 pi.sendMessage(..., { triggerTurn: true })&#xa;  注入隐藏提醒，在压缩后上下文无缝继续任务" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#EDE9FE;strokeColor=#6D28D9;fontColor=#3B0764;fontSize=14;align=left;spacingLeft=14;arcSize=10;" vertex="1" parent="12">
          <mxGeometry x="25" y="400" width="365" height="150" as="geometry" />
        </mxCell>

        <!-- Edges inside Container 1 -->
        <mxCell id="20" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#475569;" edge="1" parent="3" source="4" target="5">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="21" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#475569;" edge="1" parent="3" source="5" target="6">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>

        <!-- Edges inside Container 2 -->
        <mxCell id="22" value="工具输出进入 tool_result" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#16A34A;fontSize=12;labelBackgroundColor=#FFFFFF;" edge="1" parent="8" source="9" target="10">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="23" value="组装请求前触发 context" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#CA8A04;fontSize=12;labelBackgroundColor=#FFFFFF;" edge="1" parent="8" source="10" target="11">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>

        <!-- Edges inside Container 3 -->
        <mxCell id="24" value="每轮结束检查边界" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#7C3AED;fontSize=12;labelBackgroundColor=#FFFFFF;" edge="1" parent="12" source="13" target="14">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>
        <mxCell id="25" value="abort 后进入 settled" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#7C3AED;fontSize=12;labelBackgroundColor=#FFFFFF;" edge="1" parent="12" source="14" target="15">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>

        <!-- Cross-Container Edges -->
        <mxCell id="26" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#16A34A;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="9">
          <mxGeometry relative="1" as="geometry" />
        </mxCell>

        <mxCell id="27" value="投影后消息流" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#2563EB;fontSize=12;labelBackgroundColor=#FFFFFF;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="13">
          <mxGeometry relative="1" as="geometry">
            <Array as="points">
              <mxPoint x="885" y="575" />
              <mxPoint x="885" y="218" />
            </Array>
          </mxGeometry>
        </mxCell>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>
