Files
Jellymove/CLAUDE.md
T
IxianPixel 25a743b350
CI / test (push) Successful in 1m12s
Show folder sizes for movies, shows and seasons. Closes #5
The library lists now show how much space each movie and show takes on disk, counting everything a move copies, with a per-season breakdown for shows, a running total and a "Largest first" sort.

- sizes.rs: a single background worker measures one folder at a time. Listing returns cached sizes straight away and queues folders; the UI
  polls until every size has arrived.
- Cached in a new folder_sizes table (store migration v2). A size is kept while the folder's signature (mtimes of the folder and its direct
  subfolders) is unchanged, checked at most hourly and re-measured after 7 days.
- Each agent measures its own folders, so peer listings carry the peer's sizes.
- Tests for measuring, signatures, natural season order, the migration, and an e2e test covering both sides and a moved item.
2026-11-06 16:43:52 +00:00

91 lines
4.7 KiB
Markdown

# CLAUDE.md
Guidance for Claude Code (and humans) working in this repo.
## What this is
jellymove moves movies and TV series between two separate Jellyfin servers
(e.g. a fast-but-small cloud box and a slow-but-big home NAS, federated by
Jellyswarrm). One agent runs next to each Jellyfin. The **destination pulls**
from the source over HTTP range requests, verifies with BLAKE3, renames into
its library, waits for Jellyfin to index it, re-applies every user's watch
state, then tells the source to move its copy to a hidden trash folder.
Design background and prior-art research: `docs/ARCHITECTURE.md`.
## Commands
```sh
cargo test --workspace # all tests (~15 s; e2e spins up 2 agents + 2 fake Jellyfins)
cargo clippy --workspace --all-targets # must be warning-free
npm --prefix ui ci && npm --prefix ui run build # UI → ui/dist (embedded by rust-embed)
npm --prefix ui run check # svelte-check
cargo run -p jm-server --example demo # two agents on :8097 (cloud) and :8098 (home) with fake media
npm --prefix ui run dev # Vite dev server proxying /api to 127.0.0.1:8097
cargo run -p jellymove -- --config jellymove.toml # real daemon
```
Build the UI before `cargo build --release`, or the binary serves a "UI not
built" page. Debug builds read `ui/dist` from disk, so rebuilding the UI is
enough while developing.
## Layout
| Crate | Role |
|---|---|
| `jm-core` | Pure domain: `Job`/`Stage`/`JobStatus`, `ExportInfo`/`Manifest`, `PathMap`, folder safety rules, user-data types. No I/O. |
| `jm-transfer` | Manifest building + BLAKE3, `range_response` (serve), `Puller` (resume/retry/throttle/verify), `promote` (atomic rename). |
| `jm-jellyfin` | Thin typed client for the ~10 Jellyfin endpoints used. |
| `jm-store` | SQLite (rusqlite, WAL). Jobs, exports and cached folder sizes as JSON blobs. Migrations are the `MIGRATIONS` array; append only. |
| `jm-server` | axum app: `/api/*` (UI), `/peer/v1/*` (agent↔agent), `export.rs` (source side), `runner.rs` (destination side), embedded UI. |
| `jellymove` | Binary: clap + figment config loading, tracing setup. |
| `ui/` | Svelte 5 (runes) + Vite + TS SPA. No SvelteKit. |
## Invariants — don't break these
- **Nothing is deleted from the source until the destination has indexed every
file** (`Stage::TargetScanned`) and user data is applied. Source "deletion" is
a rename into `<library>/.jellymove-trash/<entry>/`, never `remove_dir_all`.
The only code that deletes is `trash::empty`, which resolves opaque entry
IDs by scanning the trash folders and only removes real folders directly
inside them.
- **Every runner step is idempotent.** `Job.stage` is the last *completed*
milestone; the runner re-executes from there after a crash. If you add a
stage, make re-running it safe.
- **Peers can only read exported files by index** (`/exports/{id}/files/{idx}`),
never by path. Relative paths from a peer always go through
`jm_core::paths::join_relative`, which rejects `..`, absolute paths and `\`.
- **Never overwrite** at the destination: `plan` refuses if the target folder
exists; `promote` refuses on any clash before renaming anything.
- Partial/trash folders start with `.jellymove-` (Jellyfin skips dot-folders)
and get a `.ignore` file.
- Two path namespaces: what Jellyfin reports vs. what the agent sees.
Convert with `cfg.path_map.to_local()` / `to_jellyfin()`; Jellyfin API calls
always take Jellyfin-namespace paths.
## Jellyfin facts that shape the design
- Item IDs derive from file paths, so a moved item is a *new* item with no
watch history; hence user-data capture on the source and re-apply on the
destination. We find the new item by **path** (we know exactly where we put
it), then episodes by (season, episode).
- `POST /Library/Media/Updated` returns 204 even for paths outside every
library and only scans after `LibraryMonitorDelay` (60 s default). Always poll.
- User-data routes are the 10.9+ ones (`/UserItems/{id}/UserData`). Verify
against a real server's `/api-docs/openapi.json` before trusting.
## Testing approach
`crates/jm-server/tests/fake_jellyfin/` is a filesystem-backed fake Jellyfin
(path-derived IDs, delayed scans, user data). E2E tests in
`crates/jm-server/tests/e2e.rs` run two real agents against two fakes. Add an
e2e test for any behaviour change in the move flow. The fake is *not* proof
of real-Jellyfin compatibility; see "Not yet verified" in README.
## Style
- Errors: `thiserror` in library crates, `anyhow` with `.context()` in
`jm-server`. Job failure messages are shown to users; make them actionable.
- UI copy: plain, short, UK English. Svelte 5 runes only; run the Svelte
autofixer / `npm run check` after editing components.