<?php
require __DIR__.'/oracle.php';$baseline=json_decode(file_get_contents(__DIR__.'/private-baseline.json'),true);$current=$source();$wires=file(__DIR__.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);$report=['lane'=>$lane,'actual_http'=>count($wires),'historical_scope_rows'=>count($current),'source_unchanged'=>$baseline['source']===$current,'source_sha256'=>$hash($current),'actor_unchanged'=>$baseline['actor']===$actorNow(),'business_dml'=>0,'fixture_insert'=>0,'ddl'=>0];
if($lane==='C'){$own=json_decode(file_get_contents(__DIR__.'/private-fixture-insert.json'),true);$naturalBefore=json_decode(file_get_contents(__DIR__.'/private-natural-before.json'),true);$naturalAfter=$q('SELECT * FROM '.$p.'agent_conversation_log WHERE ID<>? ORDER BY ID',[$own['id']]);$ownAfter=$q('SELECT * FROM '.$p.'agent_conversation_log WHERE ID=?',[$own['id']]);$report['fixture_insert']=1;$report['retained_own_id']=$own['id'];$report['own_full_value_unchanged']=$ownAfter===[$own['row']];$report['natural_full_value_unchanged']=$naturalBefore===$naturalAfter;$report['natural_row_count']=count($naturalAfter);$report['natural_before_sha256']=$hash($naturalBefore);$report['natural_after_sha256']=$hash($naturalAfter);$rows=[];foreach($naturalBefore as $r)$rows[]=['id'=>$r['id'],'before_sha256'=>$hash($r),'after_sha256'=>$hash($naturalAfter[array_search($r['id'],array_column($naturalAfter,'id'),true)])];$report['natural_per_pk']=$rows;}
$check($report['source_unchanged']&&$report['actor_unchanged'],'Consumed source unchanged');if($lane==='C')$check($report['own_full_value_unchanged']&&$report['natural_full_value_unchanged'],'Full natural unchanged excluding own');$save('private-final-audit.json',$report);echo json_encode($report),"\n";
