<?php
declare(strict_types=1);
$specs=[
'B'=>['path'=>'/tmp/cdx-nfh-B-20261011.M6NODe','journal'=>'private-run-B.jsonl','sha'=>'ef1f7d1b0b3eacd4390209b14c977e169356ec7b10315ec4a85822454800c098','files'=>['gate.php','gate.check.php','runner.php','plan.json','private-run-B.jsonl','cleanup-runtime.php']],
'C'=>['path'=>'/tmp/cdx-nfh-C-20261011.JX9uUW','journal'=>'private-run-C.jsonl','sha'=>'d88c49742383de7b62546aaf5189ede4b1099d7c715a4c9224e76acba187a680','files'=>['gate.php','gate.check.php','runner.php','launch-C.php','plan.json','private-run-C.jsonl','cleanup-runtime.php']]
];
$l=$argv[1]??'';if(!isset($specs[$l]))exit(78);$s=$specs[$l];$d=$s['path'];
if(!is_dir($d)||is_link($d)||(fileperms($d)&0077)!==0)throw new RuntimeException('Exact private owned runtime');
$a=array_values(array_diff(scandir($d),['.','..']));sort($a);$w=$s['files'];sort($w);
if($a!==$w||hash_file('sha256',$d.'/plan.json')!=='169ada31e30e80ab5dea1059f8de512c47cff634df14ed5194f999a0cf7b78c3'||hash_file('sha256',$d.'/'.$s['journal'])!==$s['sha'])throw new RuntimeException('Original archived plan/journal/file list ownership gate');
foreach($w as $f)if(!is_file($d.'/'.$f)||is_link($d.'/'.$f))throw new RuntimeException('Regular own file only');
foreach($w as $f)if(!unlink($d.'/'.$f))throw new RuntimeException('Exact unlink failed');
if(!rmdir($d)||file_exists($d))throw new RuntimeException('Empty owned directory removal failed');
echo json_encode(['lane'=>$l,'status'=>'OWN_RUNTIME_REMOVED','path'=>$d,'archived_raw_sha256'=>$s['sha'],'removed_files'=>count($w),'directory_exists_after'=>false,'new_DB_operations'=>0],JSON_PRETTY_PRINT),"\n";
