"""Reconcile supplied attempt IDs; does not generate or judge AI answers."""
import json,sys
from collections import Counter
def score(data):
 expected=data['expected_attempts'];observed=data['observed']; ids=[r['attempt_id'] for r in observed]
 if any(not isinstance(x,str) or not x for x in expected+ids):raise ValueError('invalid ID')
 if len(expected)!=len(set(expected)) or len(ids)!=len(set(ids)):raise ValueError('duplicate ID')
 if any(r['label'] not in {'supported','contradicted','unresolved'} or r['delivery'] not in {'internal','final','unknown'} for r in observed):raise ValueError('invalid label or delivery')
 matched=[r for r in observed if r['attempt_id'] in set(expected)];counts=Counter(r['label'] for r in matched)
 return dict(expected_attempts=len(expected),observed_records=len(observed),matched_attempts=len(matched),missing_attempt_ids=sorted(set(expected)-set(ids)),unmatched_log_ids=sorted(set(ids)-set(expected)),matched_claim_labels={k:counts[k] for k in ['supported','contradicted','unresolved']},supported_fraction=counts['supported']/len(matched) if matched else None,matched_final_answers=sum(r['delivery']=='final' for r in matched),scope='One supplied claim label per matched attempt; missing and unmatched evidence require review. No action or source truth verified.')
if __name__=='__main__':
 with open(sys.argv[1]) as f:print(json.dumps(score(json.load(f)),indent=2,sort_keys=True))
