"""6657 engineering-only local Git barriers; unchanged scientific proof verifier.""" import fcntl,hashlib,json,shutil,subprocess from pathlib import Path from phase2_h1_worker_v2 import sha,save BASE=Path('/home/frank14f/optane/MeltMind') STORE=Path('/tmp/meltmind-phase2-local-fixed-20261117') LOCK=Path('/tmp/meltmind-phase2-local-fixed-20261117.lock') BRANCH='codex/phase2-local-fixed-20261117' ENGINEERING=BASE/'artifacts/phase2-local-launch-2026-11-17/engineering-contract.json' def freeze(root,name,files): with LOCK.open('a') as lock: fcntl.flock(lock,fcntl.LOCK_EX) def git(*args):return subprocess.check_output(['git','-C',str(STORE),'-c','gc.auto=0',*args],text=True).strip() if not (STORE/'.git').exists(): STORE.mkdir(exist_ok=True) if list(STORE.iterdir()):raise RuntimeError('Unrecognized local evidence store') subprocess.run(['git','init','-q','-b',BRANCH,str(STORE)],check=True) if git('branch','--show-current')!=BRANCH or git('status','--porcelain'):raise RuntimeError('Local barrier writer not clean') hashes={} extra=[] if ENGINEERING.exists(): e=json.loads(ENGINEERING.read_text());extra=[ENGINEERING,*[BASE/p for p in e['engineering_sha256']]] for p,h in e['engineering_sha256'].items(): if sha(BASE/p)!=h:raise RuntimeError('Engineering source changed: '+p) for p in [*files,*extra]: p=Path(p);rel=str(p.resolve().relative_to(BASE));dest=STORE/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(p,dest);hashes[rel]=sha(p) subprocess.run(['git','-C',str(STORE),'add','--',*hashes],check=True) if git('diff','--cached','--name-only'): subprocess.run(['git','-C',str(STORE),'-c','user.name=MeltAstra','-c','user.email=meltrastra@local','commit','-q','-m','Phase2 local immutable '+root.name+' '+name],check=True) commit=git('rev-parse','HEAD') for rel,h in hashes.items(): if hashlib.sha256(subprocess.check_output(['git','-C',str(STORE),'show',commit+':'+rel])).hexdigest()!=h:raise ValueError('Local Git byte mismatch') save(root/(name+'-git-freeze.json'),dict(commit=commit,sha256=hashes,remote_published=False,local_repository=str(STORE),backend='6657_local_immutable_barrier',approval='1794906657.779289')) save(root/(name+'-authorization.json'),dict(proof_sha256=sha(root/(name+'-git-freeze.json')),contract_sha256=sha(root/'contract.json')))