from pathlib import Path
import tarfile, shutil, json, hashlib
H=Path(__file__).resolve().parent
R=Path('/tmp/cdx-ai-weight-owned-flow-20261011')
for p in (H/'tools').iterdir():
    if p.is_file(): shutil.copyfile(p,R/p.name)
for side in ('B','C'):
    archive=R/f'runtime-{side}-deployed.tar'
    with tarfile.open(archive,'w',format=tarfile.USTAR_FORMAT) as out:
        for p in sorted(R.rglob('*')):
            rel=p.relative_to(R)
            if rel.parts[0].startswith('seed-'):
                if rel.parts[0]!=f'seed-{side}': continue
                rel=Path('private',*rel.parts[1:])
            if not p.is_file(): continue
            assert not p.name.startswith('._')
            info=tarfile.TarInfo(str(Path(R.name)/rel));info.size=p.stat().st_size;info.mode=0o600
            with p.open('rb') as source: out.addfile(info,source)
    archive.chmod(0o600)
print(json.dumps({'source_files':6168,'tools':len(list((H/'tools').glob('*'))),'package':'byte-only USTAR'}))
