"""Build only the authorized ledger, preserving complete JSON fields.""" 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(): keys, strings, pool = [], [], [] key_ids, string_ids, object_ids = {}, {}, {} def key_id(key): if key not in key_ids: key_ids[key] = len(keys) keys.append(key) return key_ids[key] def encode(value): if isinstance(value, str): if value not in string_ids: string_ids[value] = len(strings) strings.append(value) return ['s', string_ids[value]] if isinstance(value, (dict, list)): signature = json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(',', ':')) if signature in object_ids: return ['r', object_ids[signature]] if isinstance(value, dict): node = ['d'] for key, item in value.items(): node.extend([key_id(key), encode(item)]) else: node = ['l'] + [encode(item) for item in value] index = len(pool) pool.append(node) object_ids[signature] = index return ['r', index] return value pins = {} for path in [ROOT / CURRENT, *sorted((ROOT / EVIDENCE).iterdir())]: if path.is_file(): pins[str(path.relative_to(ROOT))] = hashlib.sha256(path.read_bytes()).hexdigest() ledger = { 'accepted_input': json.loads((ROOT / INPUT).read_text()), 'current': json.loads((ROOT / CURRENT).read_text()), 'evidence_pins': pins, 'original_conditions': { 'all_exact_uses_selected_and_usable': False, 'all_creator_and_rights_evidence_accepted': False, 'all_naming_resolution_layout_replacement_references_accepted': False, 'all_mandatory_unmade_and_disclosure_gaps_resolved': False, 'applicable_display_and_hearing_evidence': False, 'independent_opus_review': False, 'root_static_and_meaningful_negative_validation': False, 'integration_and_final_original_30_88_acceptance': False, }, 'selection_contract': { 'selected_assets': [], 'candidate_names': 'Exact candidate_pool path names; no rename or final assignment', 'replacement_chain': 'Accepted historical representation -> current candidate_ref (prior applicability retained) -> selected replacement UNKNOWN', 'format': 'candidate_pool observed_format for physical media; representation_kind and exact raw source for code. Final per-use format/layout UNKNOWN.', 'rights': 'candidate_pool rights_provenance and complete pinned publisher/license/manifest evidence; internal recipe is origin only, not final rights or hearing acceptance', 'quantity': 'D08/D09 UNKNOWN. 2 state groups are not images. Never infer final file/frame/variant counts from 614 identities.', }, } files = encode(ledger) packet = {'keys': keys, 'strings': strings, 'pool': pool, 'files': files, 'encoding': 'd=flat key-id/value; l=list; s=string index; r=complete object/list index'} raw = json.dumps(packet, ensure_ascii=False, separators=(',', ':')).encode() + b'\n' (HERE / 'asset-contracts.json').write_bytes(raw) print(json.dumps({'ledger_bytes': len(raw), 'formal_tests': 'not_run'})) if __name__ == '__main__': build()