...f read_text(path: Path) -> str:
    return path.read_text(encoding="utf-8", errors="replace")

def safe_json_loads(s: str):
    """
    Try strict JSON first. If that fails, try to extract the first {...} block.
    """
    s = (s or "").strip()
    if not s:
        raise ValueError("empty response")
    try:
        return json.loads(s)
    except Exception:
        # Try to extract first JSON obje...