from research import *
p=ROOT/'prep/final_copyedit_suggestions.json'
changes=json.loads(p.read_text())
s=begin(1118,'Apply the bounded reader copyedit','Can presentation be improved without changing any calculated value?',{'suggestions_sha256':hashlib.sha256(p.read_bytes()).hexdigest()},['C1110','C1115','prep/final_copyedit_review.md'])
import re
paths={'Integrated_Draft_v2.md':'deliverables/review/Integrated_Draft_v2.md','Technical_Companion_Draft.md':'prep/Technical_Companion_Draft.md'}
contents={k:(ROOT/v).read_text() for k,v in paths.items()}
checks={};applied=[]
for c in changes:
 key=Path(c['file']).name
 assert contents[key].count(c['old'])==c['occurrences'],c['id']
 if c['category']=='spacing':assert re.findall(r'\d+',c['old'])==re.findall(r'\d+',c['new']),c['id']
 contents[key]=contents[key].replace(c['old'],c['new'])
 applied.append(c['id'])
a=artifact('deliverables/review/Integrated_Draft_v3.md',contents['Integrated_Draft_v2.md'])
b=artifact('deliverables/490d_Chronological_Families_Technical_Companion_C1131_Final.md',contents['Technical_Companion_Draft.md'])
c=artifact('model/final_copyedit_adoption.json',json.dumps({'applied':applied,'changes':'spacing, formula rendering and plain-language definitions; no calculation changed','preserved_previous_versions':True},indent=2)+'\n')
finish(s,{'reader_draft':a,'technical_companion':b,'adoption':c,'changes':len(applied)},'The reader copy now names the Isaac-to-Levi147 condition, defines rank, expands BJ, renders the core formulas, and separates joined prose and numbers. Original drafts and research records remain intact.','Finish the main reading document with the reviewed map, short navigation and source trail.',{'all_88_applied':len(applied)==88,'undefined_A1_removed':'third A1' not in contents['Integrated_Draft_v2.md'],'allocation_subscript':'A_{gf}(k)' in contents['Technical_Companion_Draft.md'],'all_sources_preserved':all(x in contents['Integrated_Draft_v2.md'] for x in ['## Source and verification notes','Supplement A','File52c'])})
