# Agent instructions — PlexReaper For AI coding assistants working in this repository. Read `docs/design-brief.md` first; it is the source of truth for scope and the scoring model. ## What this is An evidence-first tool for deciding what to remove from a shared Plex library. It unions watch evidence from every Tautulli instance, scores each title with transparent reason codes, and lets the operator decide in a terminal UI. Decisions persist in a local SQLite ledger. Removal (phase 2) goes through Radarr/Sonarr with the `*arr` entry preserved. ## Layout ``` plexreaper/ models.py pydantic models: Title, Session, Evidence, Breakdown, Candidate, ScanResult config.py plex-reaper.toml + .env / env overlay sources/plex.py async Plex HTTP client (GET only): inventory + history prior sources/tautulli.py read-only, immutable SQLite reader evidence.py session classification and per-title aggregation (pure) scoring.py reap score with reason codes (pure) sources/arr.py Radarr/Sonarr v3 client: the ONLY module that performs network writes sources/tmdb.py TMDB enrichment (read-only) ledger.py decisions, executions, enrichment cache, append-only log pipeline.py fetch → cache → evidence → score → ScanResult execute.py marked titles → plan (resolve, files, profiles) → run; dry run by default cli.py typer: check, libraries, scan, tui, decisions, execute, executions, export tui/app.py Textual review UI docs/design-brief.md tests/ offline: fixture Tautulli DB, respx for Plex, Textual pilot ``` ## Commands ```bash python -m venv .venv && .venv/bin/pip install -e '.[dev]' .venv/bin/pytest -q .venv/bin/ruff check plexreaper tests .venv/bin/plex-reaper check ``` Python ≥ 3.12. Modern syntax is expected (`X | None`, `match`, `StrEnum`). ## Rules - `evidence.py` and `scoring.py` stay pure. Sources do I/O. The CLI is thin. - Every signal has a reason code and a one-line note; the TUI shows them all. A signal nobody can explain in a sentence does not go in. - Weights live in config, never hard-coded in `scoring.py`. - Tautulli databases are opened `mode=ro&immutable=1`. The Plex client only implements GET. Do not change either. - Never list Plex users by name in output, logs, exports or tests. - Network writes live only in `sources/arr.py` and are reached only through `execute.run_plan`, which defaults to dry run and records every action in the ledger. Deletion is by `moviefile` / `episodefile` id; never delete the movie or series entry itself. Plex is never written to. - Tests are offline. A feature without tests is incomplete. - Never commit `.env`, `plex-reaper.toml` with real paths you would not publish, ledger files, caches or Tautulli/Plex databases.