<?php
declare(strict_types=1);
foreach(glob(__DIR__.'/page-retained-readonly-*.apifox-cli.json') as $path){$c=json_decode(file_get_contents($path),true);foreach($c['item'][0]['item'] as &$i){$module=strpos($i['id'],'_STORE_')!==false?'store':'terminal';foreach($i['request']['header'] as &$h)if($h['key']==='Access-Token')$h['value']='{{'.$module.'_token}}';unset($h);}unset($i);file_put_contents($path,json_encode($c,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));}
require __DIR__.'/metadata_gate.php';$main='/workspace/zhct/zhctproject/ai_api';$sources=[];foreach(['B','C'] as $lane){assertPageMetadata(json_decode(file_get_contents(__DIR__.'/structure-'.$lane.'.json'),true),$lane==='C');$id=json_decode(file_get_contents(__DIR__.'/source-identity-'.$lane.'.json'),true);foreach($id['hashes'] as $f=>$sha){if(hash_file('sha256',$main.'/'.$f)!==$sha)throw new RuntimeException('Main/actual source drift '.$f);$sources[$f]=$sha;}$r=json_decode(file_get_contents(__DIR__.'/resource-cleanup-'.$lane.'.json'),true);if(!$r['port_closed']||$r['business_cache_files']!==0||!$r['tokens_removed']||!$r['raw_token_CLI_reports_removed'])throw new RuntimeException('Resource gate incomplete');}
$files=[];foreach(new DirectoryIterator(__DIR__) as $f)if($f->isFile()&&!in_array($f->getFilename(),['manifest.json','MANIFEST.sha256'],true)){$name=$f->getFilename();$files[$name]=hash_file('sha256',$f->getPathname());if(strpos($name,'.apifox-cli.json')!==false){$c=json_decode(file_get_contents($f->getPathname()),true);foreach($c['item'][0]['item'] as $item)foreach($item['request']['header'] as $h)if($h['key']==='Access-Token'&&!preg_match('/^\{\{[A-Za-z0-9_]+\}\}$/D',$h['value']))throw new RuntimeException('Credential leaked in local collection');}}ksort($files);$m=['task'=>'ZHCTPROMPT-20260928-SMART-CANTEEN-DUAL-DB-COMPAT-PLAN','module'=>'ai_api Page store/terminal','business_revision'=>'bb530e9b78894faa0f83d0d92416a152a468b1c2','actual_main_and_private_source_sha256'=>$sources,'business_patch'=>null,'files'=>$files,'runtime_private'=>['B'=>'Docker /tmp/cdx-ai-page-config-20261010.3AABI8','C'=>'/tmp/cdx-ai-page-config-20261010.6qWWNB'],'secrets_in_control'=>false,'status'=>'bounded scenario evidence; root final classification required'];file_put_contents(__DIR__.'/manifest.json',json_encode($m,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));$lines=[];foreach($files as $name=>$sha)$lines[]=$sha.'  '.$name;file_put_contents(__DIR__.'/MANIFEST.sha256',implode("\n",$lines)."\n");echo json_encode(['files'=>count($files),'actual_source_hashes'=>count($sources),'credential_free_collections'=>true]),"\n";
