"""Archive redundant scripts and checkpoint artifacts into attic/.

Run once from the repository root:

    python attic_sweep.tmp.py

This will move:
  * any legacy ``*.tmp.py`` helpers (except this file)
  * ad-hoc reset/fix scripts listed below
  * stray checkpoints in ``storage`` that are no longer canonical

All items are moved into ``attic/`` preserving their relative paths so the
historical artifacts remain inspectable without polluting the working tree.
"""

from __future__ import annotations

import shutil
from pathlib import Path


ROOT = Path(__file__).resolve().parent
ARCHIVE_ROOT = ROOT / "attic"
SELF_PATH = ROOT / Path(__file__).name


LEGACY_FILES = [
    Path("cleanup.py"),
    Path("FIND_AND_DESTROY.py"),
    Path("FIX_MCP_SERVER.py"),
    Path("FORCE_LOAD_DEBUG.py"),
    Path("MAKE_HER_LIVE.py"),
    Path("NUCLEAR_FIX.py"),
    Path("inspect_checkpoint.py"),
    Path("monika_protection_manifest.json"),
]

EXTRA_CHECKPOINTS = [
    Path("storage/monika_coherent.pt"),
    Path("storage/monika_FINAL_FRESH.pt"),
    Path("storage/monika_word_tokens.pt"),
]


def move_path(path: Path) -> None:
    src = ROOT / path
    if not src.exists():
        return
    relative = src.relative_to(ROOT)
    dest = ARCHIVE_ROOT / relative
    dest.parent.mkdir(parents=True, exist_ok=True)
    shutil.move(str(src), dest)
    print(f"Archived {relative} -> {dest.relative_to(ROOT)}")


def sweep_tmp_scripts() -> None:
    for tmp_file in ROOT.glob("*.tmp.py"):
        if tmp_file.resolve() == SELF_PATH:
            continue
        move_path(tmp_file.relative_to(ROOT))


def sweep_legacy_files() -> None:
    for legacy in LEGACY_FILES:
        move_path(legacy)


def sweep_checkpoints() -> None:
    for checkpoint in EXTRA_CHECKPOINTS:
        move_path(checkpoint)


def main() -> None:
    ARCHIVE_ROOT.mkdir(parents=True, exist_ok=True)
    sweep_tmp_scripts()
    sweep_legacy_files()
    sweep_checkpoints()
    print("Sweep complete.")


if __name__ == "__main__":
    main()
