Files
Jellymove/CLAUDE.md
T
IxianPixel 4c6217bd40
CI / test (push) Successful in 1m18s
Add a Trash view to see and empty .jellymove-trash (#3)
Moved folders sat in each library's .jellymove-trash until removed by hand on the server. The new Trash tab lists them on either server with
size, file count, when and where they went, and empties one item, a library or everything after a confirmation.
- trash.rs: list and empty entries. Entries are referred to by an opaque ID and resolved by scanning; only real folders directly inside a trash folder can be deleted.
- Each move now gets its own trash entry folder, with a small metadata file. Fixes moves failing when the same item had been trashed before.
- Peer API: GET /trash, POST /trash/empty, and /exports/{id}/complete now records the job and destination.
- e2e tests for listing, emptying from either side, refusing paths as IDs, and moving the same item away twice.

Closes #3
2026-11-06 16:30:54 +00:00

4.7 KiB

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

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 and exports 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.