Files
ARCADIA-Studio/harness/experiments/palette-readability-20260913/archive.py
T

57 lines
2.8 KiB
Python

"""Preserve the bounded palette decisions and reviews, without rerunning them."""
from pathlib import Path
import hashlib
import json
import subprocess
import sys
root = next(parent for parent in Path(__file__).resolve().parents
if (parent / 'Cargo.toml').is_file() and (parent / '.git').exists())
out = root / 'harness/experiments/palette-readability-20260913'
names = [
'palette-readability-audit-20260912.md',
'palette-contrast-20260912.py', 'palette-contrast-20260912.json',
'palette-readability-independent-critique-20260912.md',
'palette-readability-independent-calculation-20260912.json',
'palette-selection-remedy-20260912.md',
'palette-selection-remedy-20260912.py', 'palette-selection-remedy-20260912.json',
'palette-foundation-source-handoff-20260912.md',
'palette-foundation-independent-review-20260913.md',
'palette-canvas-handoff-20260913.md',
'palette-readonly-correction-source-handoff-20260913.md',
'palette-correction-independent-review-20260913.md',
'routing-warning-selector-scope-20260913.md',
'palette-integration-decision-20260913.md',
]
mode = sys.argv[1]
if mode == 'create':
assert not out.exists(), 'Never overwrite archived evidence'
sources = {name: root / '.local' / name for name in names}
sources['archive.py'] = Path(__file__)
assert all(path.is_file() for path in sources.values())
out.mkdir(parents=True)
rows = []
for name, path in sources.items():
raw = path.read_bytes()
with (out / name).open('xb') as stream:
stream.write(raw)
rows.append({'path': name, 'source': path.relative_to(root).as_posix(),
'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest()})
record = {'scope': 'Historical candidate decisions, arithmetic and source review; native acceptance is separate.',
'limitations': 'Original local source/command references retain their historical checkout layout. Do not run copied calculators as portable build gates. These files do not establish monitor acceptance.',
'files': rows}
with (out / 'manifest.json').open('x', encoding='utf-8', newline='\n') as stream:
json.dump(record, stream, indent=2)
stream.write('\n')
else:
assert mode in ['verify', 'verify-index']
rows = json.loads((out / 'manifest.json').read_bytes())['files']
for row in rows:
raw = (out / row['path']).read_bytes()
assert len(raw) == row['bytes']
assert hashlib.sha256(raw).hexdigest() == row['sha256']
if mode == 'verify-index':
rel = (out / row['path']).relative_to(root).as_posix()
assert raw == subprocess.check_output(['git', 'show', ':' + rel], cwd=root)
print(json.dumps({'mode': mode, 'verified_payloads': len(rows), 'payload_bytes': sum(row['bytes'] for row in rows)}))