
        const proofConfig = JSON.parse(NodeFS.readFileSync(new URL("./remote-proof-config.json", import.meta.url), "utf8"));
        const promptText = JSON.stringify(params.prompt ?? []);
        const statePath = session.cwd + "/.remote-proof-state.json";
        const proofState = NodeFS.existsSync(statePath) ? JSON.parse(NodeFS.readFileSync(statePath, "utf8")) : {};
        const text = (text) => send({method:"session/update",params:{sessionId,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text}}}});
        const call = async (name, args) => {
          const endpoint = process.env.T3_ACP_MCP_ENDPOINT;
          const auth = process.env.T3_ACP_MCP_AUTHORIZATION;
          if (!endpoint || !auth) throw new Error("Replay agent has no MCP endpoint");
          let sid;
          let seq = 0;
          async function request(method, params, notification = false) {
            const id = ++seq;
            const response = await fetch(endpoint, {method:"POST",headers:{"content-type":"application/json",accept:"application/json, text/event-stream",authorization:auth,...(sid?{"mcp-session-id":sid}:{})},body:JSON.stringify({jsonrpc:"2.0",...(notification?{}:{id}),method,params})});
            sid = response.headers.get("mcp-session-id") ?? sid;
            const body = await response.text();
            if (!response.ok) throw new Error("MCP HTTP " + response.status + " " + body);
            if (!body) return;
            const frames = body.startsWith("{") ? [JSON.parse(body)] : body.split("\n").filter(l=>l.startsWith("data: ")).map(l=>JSON.parse(l.slice(6)));
            const frame = frames.find(f=>f.id===id);
            if (frame?.error) throw new Error(JSON.stringify(frame.error));
            return frame?.result;
          }
          await request("initialize",{protocolVersion:"2025-06-18",capabilities:{},clientInfo:{name:"remote-proof-replay",version:"1"}});
          await request("notifications/initialized",{},true);
          const result = await request("tools/call",{name,arguments:args});
          if(result?.isError) throw new Error(JSON.stringify(result));
          const data = result?.structuredContent ?? JSON.parse(result.content.find(c=>c.type==="text").text);
          return data;
        };
        if (promptText.includes("PROOF_FIRST_CHILD")) {
          await new Promise(r=>setTimeout(r,2000));
          text("FIRST_RESULT: first remote task completed on environment B.");
        } else if (promptText.includes("PROOF_SECOND_CHILD")) {
          await new Promise(r=>setTimeout(r,2000));
          text("SECOND_RESULT: follow-up completed on environment B.");
          NodeFS.writeFileSync(proofConfig.secondDone, "completed");
        } else if (promptText.includes("PROOF_DELEGATE")) {
          await call("orchestrator_capabilities",{});
          const result = await call("delegate_task",{task:"PROOF_FIRST_CHILD: return FIRST_RESULT and finish.",title:"Remote bounded task",target:{environmentId:proofConfig.environmentId,projectId:proofConfig.projectId,providerInstanceId:"devReplay",model:"multi-turn"},mode:"async",isolation:"shared",clientRequestId:NodeCrypto.randomUUID()});
          proofState.childThreadId = result.remoteChild.threadId;
          proofState.firstTaskId = result.taskId;
          NodeFS.writeFileSync(statePath,JSON.stringify(proofState));
          text("First remote task started. Ending this turn; waiting for its automatic completion wake.");
        } else if (promptText.includes("PROOF_FOLLOWUP")) {
          const result = await call("t3_thread_send",{environmentId:proofConfig.environmentId,threadId:proofState.childThreadId,message:"PROOF_SECOND_CHILD: return SECOND_RESULT and finish.",mode:"auto",clientRequestId:NodeCrypto.randomUUID()});
          proofState.secondTaskId = result.taskId ?? null;
          proofState.followupRunId = result.runId;
          NodeFS.writeFileSync(statePath,JSON.stringify(proofState));
          text("Follow-up send returned a runId and " + (result.taskId ? "a fresh taskId (different from first: " + (result.taskId !== proofState.firstTaskId) + ")." : "NO taskId.") + " Ending this turn.");
        } else if (promptText.includes("SECOND_RESULT")) {
          text("Automatic parent wake received SECOND_RESULT from environment B.");
        } else if (promptText.includes("FIRST_RESULT")) {
          text("Automatic parent wake received FIRST_RESULT from environment B.");
        } else {
          text("Ready for the linked-environment proof.");
        }
        return {stopReason:"end_turn"};
