"""Read-only public Agnes model-file audit with no inference or checkpoint download
Run: python3 audit-agnes-repository.py > agnes-audit.json
Uses standard HTTPS certificate verification and a pinned public revision
"""

import fnmatch
import hashlib
import json
import urllib.request

MODEL = "Agnes-AI/Agnes-Video-2.0-MoE"
REVISION = "96782683494d011586f62873c87f90449f9a6c99"
BASE = "https://huggingface.co"


def read(url):
    with urllib.request.urlopen(url, timeout=45) as response:
        return response.read()


info = json.loads(read(f"{BASE}/api/models/{MODEL}/revision/{REVISION}"))
assert info["sha"] == REVISION, "Repository revision changed"
files = sorted(item["rfilename"] for item in info["siblings"])
paths = [
    "README.md",
    "inference_code/README.md",
    "inference_code/configs/config_template.json",
    "inference_code/infer.sh",
]
documents = {}
for path in paths:
    url = f"{BASE}/{MODEL}/raw/{REVISION}/{path}"
    documents[path] = {"url": url, "sha256": hashlib.sha256(read(url)).hexdigest()}
pattern = "checkpoint_parts/ckpt_best.pt.part-*"
print(
    json.dumps(
        {
            "kind": "Public file inventory audit, not inference or runtime verification",
            "model": MODEL,
            "revision": REVISION,
            "sourceDocuments": documents,
            "fileCount": len(files),
            "checkpointPaths": [p for p in files if p.startswith("checkpoint_parts/")],
            "readmeShardPattern": pattern,
            "matchingShardPaths": [p for p in files if fnmatch.fnmatch(p, pattern)],
            "filePaths": files,
            "notValidated": [
                "checkpoint tensor compatibility",
                "GPU memory",
                "inference runtime",
                "generated audio or video",
            ],
        },
        indent=2,
    )
)
