#!/usr/bin/env python3 """Build the auditable v5.1 Prompt/Certified-FMFS overlay. This module deliberately leaves :mod:`eval.v5_sidecar` and all v5.0 artifacts frozen. A v5.1 row is built offline from one dataset row and its already-audited v5.0 sidecar row. It adds two contracts: ``fmfs.prompt`` Item-level, input-observable supervision. Physical and annotation masks are aligned exactly with ``dimensions.items``. Unknown or ambiguous items are omitted, never converted into model failures. ``fmfs.certified`` A strict endpoint. Automatic certification is intentionally restricted to three simple, complete prompt templates. Unsupported feature graphs remain ``unknown`` rather than being over-claimed as manufacturable. The overlay is evaluator metadata, not a model target or an intermediate DSL. It never executes generated code and never rewrites the prompt or GT. """ from __future__ import annotations import argparse import copy import hashlib import json import math import os import re import tempfile from collections import Counter, defaultdict, deque from pathlib import Path from typing import Any, Mapping, Sequence try: from . import v5_sidecar as V5 except ImportError: # direct script / external plugin import import v5_sidecar as V5 SCHEMA_VERSION = "edp-evaluator-sidecar-v5.1" FMFS_VERSION = "fmfs-v5.1" CERTIFICATE_SCOPE = "native_gt_dimension_manifest" NUMBER_TOKEN = r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)" MM_UNIT_TOKEN = r"(?:mm|millimet(?:er|re)s?)" PAIR_MEASUREMENT_RE = re.compile( rf"(?{NUMBER_TOKEN})\s*[x\u00d7]\s*" rf"(?P{NUMBER_TOKEN})\s*(?P{MM_UNIT_TOKEN})\b", re.IGNORECASE, ) # A dedicated, typed list recognizer is safer than a generic numeric-list # regex: it cannot absorb counts such as "5 edges" or "2 holes". SHARED_UNIT_LIST_RE = re.compile( rf"(?P