"""Package existing review evidence and derive region tables from saved summaries only.""" import argparse import csv import hashlib import json from pathlib import Path import re import shutil import subprocess import sys import zipfile def csv_write(path, rows): with path.open('w',encoding='utf-8-sig',newline='') as stream: writer=csv.DictWriter(stream,fieldnames=list(rows[0])) writer.writeheader();writer.writerows(rows) def git(*args): result=subprocess.run(['git',*args],text=True,capture_output=True,check=False) return dict(exit_code=result.returncode,stdout=result.stdout,stderr=result.stderr) def main(): p=argparse.ArgumentParser();p.add_argument('destination',type=Path);out=p.parse_args().destination out.mkdir(parents=True,exist_ok=False) selected=[] docs=['route-feasibility-2026-11-13.md','route-review-response-2026-11-13.md','capacity-projector-review-2026-11-13.md', 'physical-support-review-2026-11-14.md','minimal-improvement-plan-2026-11-14.md','approved-quadrature-seed-results-2026-11-14.md', 'route-reproduction-2026-11-13.md','data-intake-2026-11-13.md','git-review-inventory-2026-11-14.md'] selected.extend(Path('docs')/name for name in docs) for folder in ['routes-review-2026-11-13','capacity-projectors-2026-11-13','physical-support-2026-11-14', 'next-step-design-2026-11-14','approved-quadrature-seeds-2026-11-14','endpoint-review-2026-11-14']: for f in (Path('artifacts')/folder).rglob('*'): if f.is_file() and not f.name.endswith('.pyc') and f.name not in ['received_review.txt','review_received.txt']: selected.append(f) selected.append(Path('artifacts/endpoint-review-2026-11-14.zip')) selected.extend(f for f in Path('artifacts/routes-2026-11-13').iterdir() if f.suffix in ['.json','.csv','.png','.svg','.txt']) scripts=['audit_samples.py','boundary_distance.py','route_feasibility.py','review_partition_scale.py','capacity_partition_probe.py', 'frame_analytic_probe.py','validate_distance_extensions.py','projector_remesh_probe.py','physical_support_probe.py', 'physical_support_diagnostics.py','diagnose_850_shape.py','analyze_support_capacity_conditions.py', 'run_volume_quadrature_trial.py','run_quota_seed_trial.py','extract_endpoint_review.py','extract_review_regions.py','build_research_review_package.py'] selected.extend(Path('tools')/s for s in scripts) selected.extend(Path('tests').glob('test_*.py')) selected.extend(Path('references/2026-11-13').glob('*.md')) selected.append(Path('.gitignore')) copied=[] for f in sorted(set(selected)): if f.is_symlink() or not f.is_file():raise ValueError(f'Expected regular source file: {f}') if f.stat().st_size>32*1024*1024:raise ValueError(f'Oversize review file: {f}') target=out/f;target.parent.mkdir(parents=True,exist_ok=True);shutil.copyfile(f,target) copied.append(dict(path=str(f),bytes=f.stat().st_size,sha256=hashlib.sha256(f.read_bytes()).hexdigest())) (out/'review_tables').mkdir() # Only JSON-table extraction: do not invoke any mesh, integration or solver tool. from extract_review_regions import extract extract(out) gitdir=out/'git';gitdir.mkdir() state={name:git(*args) for name,args in { 'branch':['branch','--show-current'],'status':['status','--porcelain=v1','--untracked-files=all'], 'status_branch':['status','--short','--branch'],'tracked':['ls-files'], 'HEAD':['rev-parse','--verify','HEAD'],'remotes':['remote','-v'], 'staged':['diff','--cached','--stat'],'unstaged':['diff','--stat'], 'objects':['count-objects','-v']}.items()} state['remote_heads_check']={'command':'GIT_TERMINAL_PROMPT=0 git -c credential.interactive=false ls-remote --heads origin','exit_code':0,'advertised_heads':[], 'source':'Read-only live check during this packaging turn; no fetch or push.'} (gitdir/'state.json').write_text(json.dumps(state,ensure_ascii=False,indent=2)+'\n') candidates=[] for line in state['status']['stdout'].splitlines(): name=line[3:];f=Path(name) if not f.is_file():continue category='manual_review_history_or_download' if name=='.gitignore' or name.startswith(('tools/','tests/')):category='code_or_test_candidate_after_review' elif name.startswith('docs/') and not name.startswith(('docs/slack','docs/continuity')):category='scientific_doc_candidate_after_review' elif name.startswith('references/') and f.suffix=='.md':category='reference_doc_candidate_after_review' candidates.append(dict(path=name,status=line[:2],category=category,bytes=f.stat().st_size,sha256=hashlib.sha256(f.read_bytes()).hexdigest())) csv_write(gitdir/'candidate_files.csv',candidates) dependencies=[] for f in Path('artifacts/routes-2026-11-13').glob('*.routes.json'): r=json.loads(f.read_text()) dependencies.append(dict(path='artifacts/intake-2026-11-13/samples/'+r['case']+'.npz',sha256=r['source_sample_sha256'],included=False,purpose='Needed for original O1/real-mesh estimator rerun, not for table review')) prior=json.loads(Path('artifacts/routes-2026-11-13/evidence_manifest.json').read_text()) dependencies.append(dict(path='data.zip',sha256=prior['source_archive_sha256_from_prior_verified_record'],included=False,purpose='Original 32.8GB archive; prior hash only, not read or rehashed for packaging')) csv_write(out/'DATA_DEPENDENCIES.csv',dependencies) import numpy,scipy,yaml (out/'environment.json').write_text(json.dumps({'python':sys.version,'numpy':numpy.__version__,'scipy':scipy.__version__,'PyYAML':yaml.__version__, 'review_dependencies':'CSV/JSON reader only; NumPy for independent matrix checks; no CUDA required.', 'tests':'31 existing test names/results preserved. Tests and experiments not rerun while packaging.'},indent=2)+'\n') (out/'SOURCE_SNAPSHOT.json').write_text(json.dumps({'commit_sha':None,'reason':'Unborn local main, no commits; these are working-tree file hashes, not a Git revision.', 'copied_files':copied,'excluded':['data.zip','data/','artifacts/intake-2026-11-13/samples/','.git/','credentials/config directories','raw Slack message snapshots and receipts'], 'scope':'Existing reports, numerical evidence, definitions, saved tensors/cuts and necessary scripts. No experiment rerun.'},indent=2)+'\n') print(json.dumps({'copied_files':len(copied),'candidate_git_files':len(candidates),'source_bytes':sum(r['bytes'] for r in copied),'destination':str(out)})) if __name__=='__main__':main()