#!/usr/bin/env python3
import json,pathlib,re,zipfile
p=pathlib.Path(__file__).resolve().parent
with zipfile.ZipFile(p/"synthetic-fixtures.zip","w",zipfile.ZIP_DEFLATED) as z:
    for side in ["before","after"]:
        configfile=p/(side+"-fixture.json")
        config=json.loads(configfile.read_text())
        z.write(configfile,configfile.name)
        manifest=pathlib.Path(config["run"])/"manifest.json"
        z.write(manifest,manifest.relative_to(p))
        for row in config["manifest"]:
            transcript=pathlib.Path(row["transcript"])
            z.write(transcript,transcript.relative_to(p))
with zipfile.ZipFile(p/"diagnostic-archive.zip","w",zipfile.ZIP_DEFLATED) as z:
    for f in p.glob("*.log"):
        text=f.read_text(errors="replace").replace("\x00","")
        text=re.sub(r"token=[A-Za-z0-9_-]+","token=[REDACTED]",text)
        z.writestr(f.name,text)
    for name in ["after-import-raw.mp4","after-threads-raw.mp4","after-import-attempt2.mp4","after-import-attempt3.mp4","after-A-initial.png","import-video-contact.png"]:
        z.write(p/name,"rejected-rehearsals/"+name)
    z.writestr("README.txt","Diagnostic logs have one-time pairing tokens redacted. Rehearsal captures are rejected attempts, not accepted comparison evidence. The accepted clip is after-import-flow.mp4, uploaded separately.\n")
print("Archived diagnostic logs and rejected rehearsals; no T3 database included.")
