<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';$public=json_decode(file_get_contents(__DIR__.'/evidence-'.$lane.'.json'),true);$check(count($public['cases'])===16&&$public['business_DML']===0&&$public['original_rows_unchanged'],'Complete exported audit before cleanup');$cache->clear();$files=0;if(is_dir($runtime.'/cache'))foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($runtime.'/cache',FilesystemIterator::SKIP_DOTS)) as $f)if($f->isFile())$files++;$check($files===0,'Auth/business cache empty');$removed=0;foreach(['private-cli-report','private-cli-red-report','private-v2-cli-report'] as $name){$dir=$runtime.'/'.$name;if(!is_dir($dir))continue;foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,FilesystemIterator::SKIP_DOTS),RecursiveIteratorIterator::CHILD_FIRST) as $f){$path=$f->getPathname();$check(!is_link($path)&&strpos(realpath($path),realpath($runtime).'/')===0,'Exact private CLI report cleanup');if($f->isDir())rmdir($path);else{unlink($path);$removed++;}}rmdir($dir);}
foreach(['private-collection.json','private-v2-collection.json','private-cli.log','private-errors.log'] as $name)if(is_file($runtime.'/'.$name)){unlink($runtime.'/'.$name);$removed++;}foreach(['private-report.json','private-green-report.json','private-v2-report.json'] as $name){$r=json_decode(file_get_contents($runtime.'/'.$name),true);unset($r['collections'],$r['collection']);file_put_contents($runtime.'/'.$name,json_encode($r,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION));chmod($runtime.'/'.$name,0600);}foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($runtime,FilesystemIterator::SKIP_DOTS)) as $f)if($f->isFile())chmod($f->getPathname(),0600);
$out=['lane'=>$lane,'business_DML'=>0,'business_fixtures_created'=>0,'natural_original_rows_unchanged'=>true,'tokens_cache_reclaimed'=>true,'business_cache_files'=>0,'raw_CLI_secret_artifacts_removed'=>$removed,'private_natural_rows_and_raw_response_evidence_retained_0600'=>true,'worker'=>'retained under task-level exclusive ownership for approved next GET meal.Meal/infos','SSH_master'=>'retained per root instruction for next frozen module','no_external_file_OSS_device_queue_calls'=>true];file_put_contents(__DIR__.'/resource-cleanup-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));echo json_encode(['lane'=>$lane,'secret_artifacts_reclaimed'=>$removed,'cache_files'=>$files,'business_DML'=>0,'worker_next_module_reuse'=>true]),"\n";
