<?php
$root=getenv('PM_ROOT');$path=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);if(!in_array($path,['/p/agentConversationLog/lists','/p/agentConversationLog/detail'],true)||$_SERVER['REQUEST_METHOD']!=='POST'){http_response_code(403);exit;}
foreach(json_decode(file_get_contents(__DIR__.'/private-source-lock.json'),true)as $file=>$sha)if(hash_file('sha256',__DIR__.'/source/application/'.$file)!==$sha){http_response_code(403);exit;}
require __DIR__.'/oracle.php';$post=$_POST;$case=$_SERVER['HTTP_X_CDX_CASE']??'';$spec=json_decode(file_get_contents(__DIR__.'/private-spec.json'),true);$matches=array_values(array_filter($spec,static function($s)use($case){return $s['label']===$case;}));if(count($matches)!==1||$path!=='/p/agentConversationLog/'.$matches[0]['method']){http_response_code(403);exit;}$expected=array_map('strval',$matches[0]['params']);ksort($expected);$actual=$post;ksort($actual);if($actual!==$expected){http_response_code(403);exit;}
if(in_array($case,['own_list','own_detail'],true)){$scope=json_decode(file_get_contents(__DIR__.'/private-fixture-scope.json'),true);require __DIR__.'/fixture-oracle.php';}
$before=$source();$beforeActor=$actorNow();$check($actor===$beforeActor,'Actual actor drift');ob_start();register_shutdown_function(static function()use($case,$path,$post,$before,$beforeActor,$source,$actorNow):void{try{$entry=['label'=>$case,'phase'=>$_SERVER['HTTP_X_CDX_PHASE']??'original','path'=>$path,'params'=>$post,'status'=>http_response_code(),'response'=>(string)ob_get_contents(),'source_before'=>$before,'source_after'=>$source(),'actor_before'=>$beforeActor,'actor_after'=>$actorNow()];if(strlen($entry['response'])>2097152)throw new RuntimeException('Response cap2MiB');file_put_contents(__DIR__.'/private-wire.jsonl',json_encode($entry,JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND);chmod(__DIR__.'/private-wire.jsonl',0600);}catch(Throwable $e){file_put_contents(__DIR__.'/private-audit-error',hash('sha256',$e->getMessage()));chmod(__DIR__.'/private-audit-error',0600);}});
$_SERVER['PATH_INFO']=$path;require __DIR__.'/init.php';\think\App::run()->send();
