#!/usr/bin/env python3
import json,hashlib,sys
from pathlib import Path
PROJECT='gacmai_20260718_075153'
CONCEPT_SHA='0ac2600ec1e964494a688426ed3f59e1bd0d46d4f34982756cfb539a29bed7a0'
CAST=['Võ Thanh Hà','Nguyễn Hữu Duy','Trần Mộc Lan','Lê Quang Vinh','Phạm Ngọc Thư','Đỗ Minh Khang']
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def main():
 if len(sys.argv)!=3:raise SystemExit('usage: build_outline_audit_bundle.py OUTLINE OUT')
 src,out=map(Path,sys.argv[1:]);d=json.loads(src.read_text())
 assert d['project_id']==PROJECT and d['source_concept_sha256']==CONCEPT_SHA
 parts=d['parts'];assert len(parts)==12 and all(len(x['beats'])==12 for x in parts)
 bundle={
  'schema_version':1,'audit_type':'independent_full_read_outline_release','project_id':PROJECT,
  'source':{'path':str(src),'sha256':sha(src),'concept_sha256':CONCEPT_SHA},
  'contract':{
   'required_verdicts':['pass','fail'],'pass_with_minor_edits_allowed':False,
   'structure':'12 parts x 12 unique beats; planned 14000-15000 Vietnamese words',
   'pov':'close-third limited only to Võ Thanh Hà','exact_named_cast':CAST,
   'authority_chain':['Đỗ Minh Khang certifies completeness, reopens consultation, submits procedurally valid recommendation','Nguyễn Hữu Duy signs technically viable alignment revision','Trần Mộc Lan validates resident-controlled revocable consent without exposing sealed coordinates','District Review Council is an unnamed institution and decides only after prerequisites'],
   'blocking_gates':['dramatic escalation rather than checklist/scaffold prose','scene-specific evidence source/custody/authority/limits','consent/privacy causally handled without boilerplate','continuity and causal linkage across all 144 beats','no extra named person','no POV leakage','no prohibited domains','ending causally earned and preserves shared access, sealed coordinates, revocable consent']
  },
  'outline':d
 }
 out.write_text(json.dumps(bundle,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'status':'passed','path':str(out),'sha256':sha(out),'source_sha256':sha(src)},ensure_ascii=False))
if __name__=='__main__':main()
