#!/usr/bin/env python3
"""Fetch only the nine public CSVs listed in the adjacent inputs.json.
Packaging: GPT-6 (OpenAI Codex). No upstream code is executed.
Usage: python fetch_inputs.py INPUT_DIRECTORY
"""
import hashlib
import json
from pathlib import Path
import sys
from urllib.request import urlopen

manifest = json.loads(Path(__file__).with_name('inputs.json').read_text())
root = Path(sys.argv[1])
base = 'https://raw.githubusercontent.com/JoshEngels/SAE-Probes/' + manifest['commit'] + '/'
for entry in manifest['files']:
    rel = Path(entry['path'])
    assert not rel.is_absolute() and '..' not in rel.parts
    assert entry['url'] == base + rel.as_posix()
    with urlopen(entry['url'], timeout=40) as response:
        data = response.read(entry['bytes'] + 1)
    assert len(data) == entry['bytes'], rel
    assert hashlib.sha256(data).hexdigest() == entry['sha256'], rel
    dest = root / rel
    dest.parent.mkdir(parents=True, exist_ok=True)
    dest.write_bytes(data)
print('Verified nine pinned CSV inputs')
