"""Initialize a compact ledger. Not invoked by read-only verification. All historic fields are retained by raw-SHA references. This initializer replaces selection work; never use it to refresh pins after a source change. """ import hashlib import json from pathlib import Path ROOT = Path(__file__).resolve().parents[5] HERE = Path(__file__).resolve().parent INPUT = 'docs/spec/inputs/P22-02-accepted-usage.json' CURRENT = 'docs/plans/original-completion-2026-10-02/checkpoints/p22-02-slot-contract-r02/all-slot-current-candidate-contracts.json' EVIDENCE = 'docs/plans/original-completion-2026-10-02/checkpoints/p22-02-current-contract-r01' def build(): paths = [INPUT, CURRENT] + [str(p.relative_to(ROOT)) for p in sorted((ROOT / EVIDENCE).iterdir()) if p.is_file()] pins = {p: hashlib.sha256((ROOT / p).read_bytes()).hexdigest() for p in paths} current = json.loads((ROOT / CURRENT).read_text()) ledger = { 'schema': 'p22-reference-contract-v2', 'references': pins, 'reconstruction': 'All accepted codec fields and snapshot fields retained by raw SHA; selections inherit entire snapshot contracts by identity, including every unmade condition.', 'selections': {c['id']: ('candidate' if c['candidate_refs'] else 'missing') for c in current['contracts']}, 'source_pins': {p: f['current_raw_sha256'] for p, f in current['candidate_pool'].items()}, 'unit_proofs': {}, } (HERE / 'asset-contracts.json').write_text(json.dumps(ledger, ensure_ascii=False, indent=2) + '\n') if __name__ == '__main__': build()