# PlexReaper v2 — design brief *Written 2026-10-09. Supersedes the v0.1 README's architecture notes and the "do NOT" list in AGENTS.md where they conflict (see "Reversed decisions").* ## The problem, restated The shared Plex server is at 100% disk (700 GB free of 111 TB). The library is 8,558 movies and ~2,000 shows served to ~48 users across **two** Plex servers (`plexms`, `plexms-cf`) that mount the same files. Requests arrive through Ombi; acquisition is Radarr (plus a separate 3D Radarr), Sonarr, Prowlarr. Tautulli runs against each server. v0.1 answered "what has nobody ever watched?" with a single bit per title (Plex `view_count > 0`) from a single server. Measured against Tautulli on 2026-10-09 that bit is wrong in three ways: | Finding | Value | | --- | --- | | Admin movie sessions that stopped before 15% (quality sampling) | 42% (other users: 20%) | | Movies whose only sessions ever were under 15% complete ("ghost watched") | 311 | | Shows in the same state | 74 | | Titles completed on `plexms-cf` with no completion on `plexms` | 2,060 | | Movie sessions abandoned between 15% and 85%, all users | ~38% | So: the sampling taint is real but *separable* (Tautulli has `view_offset` and runtime per session), partial watches carry information the old tool discarded, and a single-server view would propose deleting things people finished on the other server. ## Goal Find what to get rid of, with evidence, and make the review fast enough that it actually happens. Every candidate shows *why*. Nothing is deleted without a human decision, and every decision is remembered. ## Non-goals - Replacing Maintainerr / Janitorr. They are rule engines with web UIs. This is a personal, evidence-first tool with a terminal UI. Overlap is fine. - Pruning watched content on a schedule. The target is content nobody wanted. - Multi-tenant anything. One operator. ## Core idea: the reap score Each movie or show gets a **reap score** from 0 to 100. Higher means a stronger candidate for removal. The score is a sum of signal contributions, each carrying a reason code and a short human sentence. The TUI shows the full breakdown for every row. There is no black box; an optional LLM verdict (phase 3) is displayed, never scored. ### Session classification (the fix for sampling) Every Tautulli session is classified from `view_offset / duration`: | Class | Rule | Meaning | | --- | --- | --- | | `full` | ≥ 85% complete | a genuine watch | | `abandoned` | 15% ≤ p < 85% | tried it and bailed | | `touch` | < 15% | started, didn't watch | | `qc` | `touch` **and** admin account **and** within 7 days of `added_at` | quality sampling; ignored entirely | `full` sessions from any server, by any user, count as watches. `abandoned` sessions by non-admin users count *against* the title. `touch` sessions are not watches; a title with only `touch` sessions is treated as never played. ### Evidence union across servers Plex rating keys differ per server, so evidence is keyed by **Plex GUID** (`plex://movie/…`, `plex://episode/…`). Episode GUIDs are mapped to their show through the main server's episode list (`/library/sections/{id}/all?type=4`), one call per page rather than one per show. Pre-Tautulli history (before 2022-07) exists only as Plex view counts. `/status/sessions/history/all` on the main server is read as a weaker prior: a view there counts as a watch with no completion information. ### Signals and weights (phase 1) | Code | Signal | Contribution | Source | | --- | --- | --- | --- | | `NEVER` | no `full` session on any server and no Plex history | +30 | Tautulli, Plex | | `GHOST` | only `touch` sessions ever | +5 (on top of `NEVER`) | Tautulli | | `ABANDON` | each non-admin `abandoned` session, cap 3 | +8 each | Tautulli | | `AGE` | days since added, 365 → +0, 1460+ → +15, linear | +0…15 | Plex | | `SIZE` | log-scaled on bytes, 1 GB → +0, 100 GB → +15 | +0…15 | Plex | | `BLOAT` | GB per hour of runtime > 8 | +5, flags *downgrade* | Plex | | `LOWRATE` | audience (else critic) rating ≤ 5.0 | +5; ≤ 3.0 → +10 | Plex | | `WATCHED` | ≥ 1 `full` session | −40; each extra distinct user −10, cap −70 | Tautulli | | `RECENT` | last `full` session within 365 days | −20 | Tautulli | | `PRIOR` | Plex history view with no Tautulli evidence | −25 | Plex | | `SIBLING` | same Plex collection as a watched title | −15 | Plex | | `STALLED` | show: furthest episode reached is in season 1 and show has > 1 season | +10, flags *trim seasons* | Tautulli, Plex | | `PROTECTED` | genre / title regex / library rule | score forced to 0, not selectable | config | Score is clamped to 0…100. Weights live in config and are expected to be tuned; the ablation rule applies (keep a signal only if it changes decisions). ### Phase 2 signals | Code | Signal | Source | | --- | --- | --- | | `REQUESTER` | requested by a user who is now inactive and never watched it | Ombi API + Tautulli `users` | | `RARE` | no indexer results for the title: protect | Prowlarr search, shortlist only | | `STREAMING` | available on a subscribed provider in region | TMDB watch providers | | `OBSCURE` | TMDB vote count < 100 | TMDB | | `ENDED` / `CONTINUING` | show status, missing episodes | Sonarr | Slow signals are fetched **on the fly** by TUI background workers for the visible rows and the row under the cursor, and cached in local SQLite with a TTL. The initial table never waits on them. ## Actions | Action | What happens | Phase | | --- | --- | --- | | `keep` | recorded in the ledger; suppressed from future lists until the title changes | 1 | | `reap` | marked for removal; executed via Radarr/Sonarr file delete, entry preserved | mark: 1, execute: 2 | | `downgrade` | profile swap per `[arr.downgrade]` map, files above the target resolution deleted, search posted | 2 | | `retarget` | bulk profile swap, no files touched (policy change for future grabs) | 2 | | `mark-4k` | measure bytes above 1080p per title, mark `downgrade` over a floor | 2 | | `trim` | show: unmonitor + delete seasons after the furthest watched | 3 | | `protect` | adds a persistent protection rule | 1 | | leaving-soon | marked titles join a Plex collection for N days before execution | 3 | ## The ledger A local SQLite file (`--state`, default `~/.local/state/plex-reaper/ledger.db`) records every decision (`keep`, `reap`, `downgrade`, `protect`) with the title's GUID, size, score, breakdown and timestamp, and every executed action with the Radarr/Sonarr identifiers and file paths needed to re-monitor. The v0.1 text selection list goes away; `scan --json` is the scriptable export. ## The TUI Textual. One screen: ``` ┌ candidates ──────────────────────────────┐┌ evidence ───────────────────┐ │ score size age title why ││ Gods of Egypt (2016) │ │ 92 58.1G 3.2y Gods of Egypt NEVER││ Movies · Action · 58.1 GB │ │ 88 41.0G 4.1y Some Procedural ABAN ││ │ │ … ││ +30 NEVER no full watch │ │ ││ +16 ABANDON 2 users bailed │ │ ││ +15 SIZE 58 GB │ │ ││ +12 AGE 3.2 years │ │ ││ +5 BLOAT 31 GB/h → downgr │ │ ││ −0 │ │ ││ sessions: 3 (2 abandoned, │ │ ││ 1 qc ignored) │ └──────────────────────────────────────────┘└─────────────────────────────┘ space reap · k keep · d downgrade · p protect · / filter · s sort · x review 12 marked · 611 GB to free · disk 700 GB free of 111 TB ``` Decisions persist immediately. `x` opens the review screen listing marked items and (phase 1) writes them to the ledger and a JSON export; execution arrives in phase 2 behind the same screen. ## Architecture - Python ≥ 3.12, `uv`-compatible `pyproject.toml`, PEP 621. - `httpx` async clients, `pydantic` models, `textual` TUI, `typer` CLI. - Config: `plex-reaper.toml` (`tomllib`) with secrets from env / `.env`. - Sources: `PlexSource` (HTTP API, main server), `TautulliSource` (direct read-only SQLite, one per server; API variant later), `PlexHistoryPrior`. - `evidence.py`: session classification and per-title aggregation. Pure. - `scoring.py`: signals → `Breakdown`. Pure. - `ledger.py`: SQLite decisions. - `tui/`: Textual app. `cli.py`: `scan`, `tui`, `libraries`, `check`, `decisions`. - Tests offline: fixture Tautulli databases built in-test, Plex JSON via `respx`, pure scoring tests, Textual pilot tests. Layout mapping for this server (config, not code): Movies → Radarr; Movies - 3D → Radarr 3D; TV Shows / Kids / Anime / Daily → Sonarr. ## Phases 1. **Evidence + TUI, read-only.** Plex inventory, both Tautullis, scoring, ledger, TUI with keep/reap/protect marks, `scan --json`. No network writes. *Done 2026-10-09.* 2. **Execution + first enrichment.** Radarr/Sonarr `reap` and `downgrade` with dry run, confirmation, and an executions record; Radarr/Sonarr and TMDB facts in the evidence panel. *Done 2026-10-09.* The `downgrade` mechanism is profile swap → delete files → search, because neither Radarr nor Sonarr will replace a file with a lower quality while it exists. *2026-10-11:* first real execution (3/3). Measured TV: 946 shows on the 2160p profile hold 48.6 TB of files, 24.5 TB of it actual 4K across 333 shows, half of that in 67 shows. Added `retarget`, `mark-4k`, resolution- aware downgrade (keeps files at or below target) and `execute --limit`. 3. **Social and rarity signals.** Ombi requester provenance, Prowlarr rarity (protect what cannot be re-acquired), season `trim`, leaving-soon Plex collection with a cooling period (the first and only Plex write; it would be a separate, explicitly scoped writer class). 4. **Optional LLM verdicts** through the local LiteLLM gateway, displayed only; ablate and drop if it never changes a decision. ## Reversed decisions AGENTS.md (v0.1) said: no TUI, no persistent state, Python 3.9, zero dependencies. All four are reversed deliberately. The old rules fit a weekend script; a tool that has to make 8,000 decisions reviewable needs a UI and a memory. The things that stay: read-only Plex, deletion only through the `*arr` APIs with the entry preserved, dry-run on every destructive path, human decision on every item.