import hashlib,json
from pathlib import Path
ROOT=Path(__file__).resolve().parent;main=ROOT.parents[3]/'zhctproject'/'ai_api';old=json.loads((ROOT/'source-frozen-sha.json').read_text())['files']
for n,s in old.items():assert hashlib.sha256((main/n).read_bytes()).hexdigest()==s,'Preflight source changed: '+n
files=list(old)+['app/common/database/Dm.php','app/common/database/DmBuilder.php','cores/ExceptionHandle.php','cores/exception/BaseException.php'];out={'scope':'immutable pre-HTTP actual business source identity','files':{n:hashlib.sha256((main/n).read_bytes()).hexdigest() for n in files}}
target=ROOT/'source-http-frozen-sha.json';assert not target.exists(),'No HTTP source freeze overwrite';target.write_text(json.dumps(out,indent=2)+'\n');print(json.dumps({'actual_source_files':len(files),'sha256':hashlib.sha256(target.read_bytes()).hexdigest()}))
