#!/usr/bin/env python3 """Refresh recoverable source hashes while preserving observed upstream provenance.""" from pathlib import Path import hashlib,json root=Path(__file__).resolve().parents[1]/'gateway' manifest=json.loads((root/'SOURCE_MANIFEST.json').read_text()) manifest['archive_baseline_commit']='19a7adccd9322986eb0646b165b9ce1cf2650cf2' manifest['workspace_release']='0.5.0' manifest['code_version']='0.7.1 (legacy health version; reply.emotion version 1 capability)' for path in sorted(root.rglob('*')): if not path.is_file():continue name=path.relative_to(root).as_posix() if name=='SOURCE_MANIFEST.json' or any(x in path.relative_to(root).parts for x in ('__pycache__','.runtime','models','logs')):continue raw=path.read_bytes();digest=hashlib.sha256(raw).hexdigest();old=manifest['files'].get(name) row={'source':old['source'] if old else 'workspace:gateway/'+name,'sha256':digest,'bytes':len(raw)} if old and old['sha256']!=digest: row['upstream_sha256']=old.get('upstream_sha256',old['sha256']);row['source']='workspace:gateway/'+name elif old and 'upstream_sha256' in old:row['upstream_sha256']=old['upstream_sha256'] manifest['files'][name]=row (root/'SOURCE_MANIFEST.json').write_text(json.dumps(manifest,indent=2,ensure_ascii=False)+'\n') print('Updated canonical gateway source manifest')