"""Evidence-gated origin resolution; CST digits are never an origin source.""" def resolve_origin(product_id: str, aggregate: dict, kb_facts: dict) -> dict: if aggregate.get("conflict_count", 0): status = "ORIGIN_CONFLICT" elif aggregate.get("strong_evidence") and aggregate.get("value") in {str(i) for i in range(9)}: status = "ORIGIN_CONFIRMED" else: status = "ORIGIN_NEEDS_EVIDENCE" return { "product_id": product_id, "status": status, "value": aggregate.get("value") if status == "ORIGIN_CONFIRMED" else None, "provenance": aggregate.get("provenance", []), "reason": "explicit supplier observations only; CST digit ignored", }