from pathlib import Path import json,hashlib,shutil,datetime,subprocess r=Path(__file__).resolve().parents[3];w=r/'web';identity=json.loads((w/'out/build-identity.json').read_text());names=[] for folder in ['app','lib','fsd','scripts','data','public']: names.extend(str(p.relative_to(w)) for p in (w/folder).rglob('*') if p.is_file() and str(p.relative_to(w))!='public/build-identity.json') names+=['package.json','package-lock.json','next.config.mjs'];h=hashlib.sha256();inputs=[] for n in sorted(names):b=(w/n).read_bytes();h.update(n.encode());h.update(b);inputs.append({'path':n,'bytes':len(b),'sha256':hashlib.sha256(b).hexdigest()}) assert h.hexdigest()==identity['sourceHash'];source=h.hexdigest();files=[];h=hashlib.sha256() for p in sorted((w/'out').rglob('*')): if p.is_file():n=str(p.relative_to(w/'out'));b=p.read_bytes();h.update(n.encode());h.update(b);files.append({'path':n,'bytes':len(b),'sha256':hashlib.sha256(b).hexdigest()}) c=r/'docs/design-system/implementation-v3/candidates'/source[:12];c.mkdir(parents=True,exist_ok=True);target=Path('/private/tmp')/('progcode-v3-frozen-'+source[:12]);shutil.copytree(w/'out',target) m={'recordedAtUTC':datetime.datetime.now(datetime.timezone.utc).isoformat(),'stage':'Actual integrated V3 first freeze; personalroles/functional/SDK checks pending; NO acceptance or publication','sourceHash':source,'sourceFiles':len(inputs),'buildHash':h.hexdigest(),'buildFiles':len(files),'staticRoot':str(target),'sourceCommit':None,'production':'0458 unchanged'} (c/'manifest.json').write_text(json.dumps(m,ensure_ascii=False,indent=2)+'\n');(c/'source-inputs.json').write_text(json.dumps({'sourceHash':source,'files':inputs},ensure_ascii=False,indent=2)+'\n');(c/'build-output.json').write_text(json.dumps({'buildHash':h.hexdigest(),'files':files},ensure_ascii=False,indent=2)+'\n') f=open('/private/tmp/progcode-v3-'+source[:12]+'.log','ab');p=subprocess.Popen(['python3',str(r/'docs/design-system/implementation-v3/serve-candidate.py'),'--root',str(target),'--manifest',str(c/'manifest.json')],stdout=f,stderr=f,start_new_session=True);print(json.dumps({**m,'pid':p.pid},ensure_ascii=False,indent=2))