#!/usr/bin/env python3 """Snapshot/verify reference sources without writing to the reference workspace.""" import argparse,hashlib,json,sys from pathlib import Path p=argparse.ArgumentParser(description=__doc__) p.add_argument('mode',choices=['snapshot','verify']) p.add_argument('reference',type=Path) p.add_argument('manifest',type=Path) a=p.parse_args();ref=a.reference.resolve();manifest=a.manifest.resolve() if manifest.is_relative_to(ref):p.error('Manifest must be outside the read-only reference') suffixes={'.c','.et','.ent','.layer','.conf','.gproj','.meta','.layout','.emat','.md','.py'} current={str(f.relative_to(ref)):hashlib.sha256(f.read_bytes()).hexdigest() for f in sorted(ref.rglob('*')) if f.is_file() and f.suffix in suffixes and not any(part in {'.git','.agents','.codex','__pycache__'} for part in f.relative_to(ref).parts)} if a.mode=='snapshot': if manifest.exists():p.error('Refusing to overwrite an existing baseline') manifest.write_text(json.dumps(current,indent=2)+'\n');print(f'Recorded {len(current)} reference source hashes') else: before=json.loads(manifest.read_text()) changed=sorted(k for k in before.keys()|current.keys() if before.get(k)!=current.get(k)) if changed: print('Reference changes detected; no files were reverted:');print('\n'.join(changed));sys.exit(1) print(f'PASS: {len(current)} reference sources unchanged')