#!/usr/bin/env python3
"""Write deterministic checksums for the isolated completeness package."""

from __future__ import annotations

import hashlib
from pathlib import Path

HERE = Path(__file__).resolve().parent
ROOT = HERE.parents[1]
OUT = HERE / "artifact-checksums.sha256"
EXCLUDE = {OUT.name, "publication-gate-inputs.json", "VALIDATION_RESULTS.md"}

paths = sorted(
    p for p in HERE.rglob("*")
    if p.is_file()
    and p.name not in EXCLUDE
    and "__pycache__" not in p.parts
)
lines = [
    f"{hashlib.sha256(path.read_bytes()).hexdigest()}  {path.relative_to(ROOT).as_posix()}"
    for path in paths
]
OUT.write_text("\n".join(lines) + "\n")
print(f"wrote {OUT.relative_to(ROOT)} with {len(lines)} checksums")
