from pathlib import Path import json,hashlib,zipfile,csv root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent historical=root/'outputs/investmoz-fintech-correspondencia-20261015/INVENTARIO-ACERVO-ACESSIVEL-LOCAL.json' previous=json.loads(historical.read_text('utf-8')) attachments=Path('C:/Users/macbook/.codex/attachments'); files=[] for p in sorted(attachments.rglob('*')): if p.is_file():files.append({'path':str(p),'bytes':p.stat().st_size,'suffix':p.suffix.lower()}) history=[];csv.field_size_limit(10000000) for n,delimiter in [('docs/investmoz/v2/auditoria-portal/inventario-fontes.csv',','),('docs/investmoz/document-corpus-inventory-2026-10-06.csv',';')]: p=root/n with p.open(encoding='utf-8-sig',newline='') as f:rows=list(csv.DictReader(f,delimiter=delimiter)) history.append({'path':n,'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'records':len(rows)}) sources=json.loads((out/'FONTES-EXTRAIDAS.json').read_text('utf-8')); embedded=[] for item in sources['selection']: p=Path(item['path']) if p.suffix.lower()!='.docx' or 'error' in item:continue with zipfile.ZipFile(p) as z: for i in z.infolist(): if not i.is_dir() and (i.filename.startswith('word/media/') or i.filename.startswith('word/embeddings/')): embedded.append({'container':str(p),'entry':i.filename,'bytes':i.file_size,'CRC32':format(i.CRC,'08x')}) result={'date':'2026-10-16','scope':'All originals retained through existing complete inventory before source selection; current instruction attachments listed regardless of consumer relevance', 'corpus_inventory_reused':{'path':str(historical.relative_to(root)),'sha256':hashlib.sha256(historical.read_bytes()).hexdigest(),'at':previous['at'],'root':previous['root'],'files':len(previous['files']),'fresh_full_rescan_claimed':False}, 'corpus_files':previous['files'],'current_instruction_attachments':files,'historical_inventories_including_embedded_resources':history,'selected_DOCX_embedded':embedded, 'sources_selected':len(sources['selection']),'source_originals_changed':False,'active_changes':0,'publications':0, 'note':'A fresh full DOCX container rescan was stopped as redundant. Full existing inventories are reused; hashes and cells/paragraphs of the selected 12 exemplars were read this turn. No new provenance approval is required.'} assert not (out/'INVENTARIO-ACERVO.json').exists() (out/'INVENTARIO-ACERVO.json').write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n','utf-8') print(json.dumps({'corpus_files_reused':len(previous['files']),'current_attachments':len(files),'selected_DOCX_embedded':len(embedded),'historical':history}))