import json
from pathlib import Path

STATE_FILE = Path("/data/state.json")

def load_state():
    if not STATE_FILE.exists():
        return set(), False
    data = json.loads(STATE_FILE.read_text())
    return set(data.get("known_ids", [])), True

def save_state(ids):
    STATE_FILE.write_text(json.dumps({
        "known_ids": sorted(ids)
    }, indent=2))
