Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Culla is a Windows desktop app (Tauri 2 + Rust + React/TS) that culls Nikon JPEG+NEF photos with a swipe UI, then applies keep/reject as safe, journaled file operations. Start at `docs/SPEC.md`: it records the author's decisions and maps each topic to its owning doc (PRD, nfr, architecture, ADRs, file-engine design, threat model, testing, roadmap). `docs/research/` is historical input: where it disagrees with the spec or an ADR, the spec and ADRs win.

## Status
M0 (repo and tooling) is done; M1 (core engine headless) is in progress: NEF preview reader, scan and grouping, EXIF, volume identity, the preview decode and the preview pipeline (threads, prefetch, in-memory cache) are in, with the headless `culla scan` and `culla preview` and the `culla-bench` harness for the M1 campaign. M2 (file engine) has started: the pure decision log, `plan()`, preflight, the journal executor and the apply log's rendering are in, with the dry-run `culla plan`. M3 has started on the UI, demo backend only: start screen (folder and recent folders only, ADR 0029), swipe screen, TS decision reducer (`src/decisions`). M4 has started on the same demo backend: review screen with move or copy and the destination, and confirm dialog (`src/review`, the demo's plan and preflight in `backend/demo-plan.ts`, scenarios by `?scenario=` in `backend/demo-scenarios.ts`), apply screen and report (`src/apply`, the simulated run in `backend/demo-apply.ts`, its log in `backend/demo-log.ts`), zoom to 100 % and the EXIF overlay on the swipe screen (`swipe/zoom.ts`, `ZoomLayer.tsx`, `ExifOverlay.tsx`), resume and start over (sessions kept between visits in `backend/demo-sessions.ts`). Author decisions recorded 27 to 29 Nov; what is still open is in SPEC §10 and file-engine §13.
M0 (repo and tooling) is done; M1 (core engine headless) is in progress: NEF preview reader, scan and grouping, EXIF, volume identity, the preview decode and the preview pipeline (threads, prefetch, in-memory cache) are in, with the headless `culla scan` and `culla preview` and the `culla-bench` harness for the M1 campaign. M2 (file engine) has started: the pure decision log, `plan()`, preflight, the journal executor and the apply log's rendering are in, with the dry-run `culla plan`, and the SQLite session store (`culla_adapters::store`; reconcile on open and the Windows file steps are next). M3 has started on the UI, demo backend only: start screen (folder and recent folders only, ADR 0029), swipe screen, TS decision reducer (`src/decisions`). M4 has started on the same demo backend: review screen with move or copy and the destination, and confirm dialog (`src/review`, the demo's plan and preflight in `backend/demo-plan.ts`, scenarios by `?scenario=` in `backend/demo-scenarios.ts`), apply screen and report (`src/apply`, the simulated run in `backend/demo-apply.ts`, its log in `backend/demo-log.ts`), zoom to 100 % and the EXIF overlay on the swipe screen (`swipe/zoom.ts`, `ZoomLayer.tsx`, `ExifOverlay.tsx`), resume and start over (sessions kept between visits in `backend/demo-sessions.ts`). Author decisions recorded 27 to 29 Nov; what is still open is in SPEC §10 and file-engine §13.

## Commands
Work now:
Expand All @@ -19,7 +19,7 @@ Work now:

## Layout
- `crates/core` (package `culla-core`) — domain, ports, pure logic (TIFF/IFD walker behind a `ReadAt` port; `grouping` and scan exclusions over plain `ScanEntry` data; `exif` parsing and capture order over plain `RawExif` data; `names`; `volume`: serial + folded relative path keys, run binding; `preview`: sizes, scale, pixel cap, orientation, working bytes; `prefetch`: window, scheduler, LRU, memory budgets; `decisions`: event log, `fold`, undo/redo, reconcile clears, text form; `plan`: decided groups to operations over a snapshot of the target roots; `preflight`: P1–P17 over a plan and a snapshot of facts; `journal`: op states, recovery table, one executor for apply and resume over `Disk`/`Store` ports; `applylog`: renders the plain-text apply log from the journal; `text`: the shared escape set for untrusted names, used by the CLI and the apply log). Property tests: seeded plain loops instead of proptest (proposed, SPEC §10), `CULLA_PROP_CASES`. No I/O, no Tauri, `#![forbid(unsafe_code)]`.
- `crates/adapters` (package `culla-adapters`) — Windows file ops, the read-only folder walk (`scan`, `read_dir` only, re-checks each folder before listing it, swap window until M2, never a partial folder; moves into `winfs` in M2), file reads for NEF previews, EXIF, `preview` decode (turbojpeg builds libjpeg-turbo: needs CMake, and NASM on `PATH` for SIMD, else it silently builds slow plain C), `pipeline` (reader thread, decode workers, in-memory cache; std threads only), `facts` (read-only lookups for the dry-run plan and preflight: path facts, target snapshot, the decision log file), SQLite; `winfs` (Win32 `unsafe` only in `winfs/win32.rs`, read-only volume and time-zone lookups so far, a stub off Windows). No Tauri.
- `crates/adapters` (package `culla-adapters`) — Windows file ops, the read-only folder walk (`scan`, `read_dir` only, re-checks each folder before listing it, swap window until M2, never a partial folder; moves into `winfs` in M2), file reads for NEF previews, EXIF, `preview` decode (turbojpeg builds libjpeg-turbo: needs CMake, and NASM on `PATH` for SIMD, else it silently builds slow plain C), `pipeline` (reader thread, decode workers, in-memory cache; std threads only), `facts` (read-only lookups for the dry-run plan and preflight: path facts, target snapshot, the decision log file), `store` (the SQLite session store, rusqlite with bundled SQLite: one database per source under an injected sessions folder, WAL and `synchronous=FULL` asserted on open, schema v1 with migrations, a read-only check before any write, fails closed on a damaged, foreign, newer or altered file, journal writes only while a plan runs, the `<key>.lock` source lock, the core's `Store` port as `PlanStore`); `winfs` (Win32 `unsafe` only in `winfs/win32.rs`, read-only volume and time-zone lookups so far, a stub off Windows). No Tauri.
- `crates/cli` (package `culla-cli`, binary `culla`) — headless scan (in; exit codes, JSON fields and off-Windows behaviour provisional, SPEC §10), preview (in; decodes, times and reports), plan (in; dry run, exit codes 0 to 5 provisional), apply, resume. Wiring only; writes nothing but stdout and stderr.
- `crates/bench` (package `culla-bench`) — benchmark harness (ADR 0020): scan, preview, swipe through the pipeline, io-baseline, report; read-only, writes nothing but stdout, std only, `--json` unstable. Campaign: docs/benchmarks.md §7.
- `src-tauri` (package `culla-app`) — wiring only: commands, `culla://` image scheme, capabilities. New command: `build.rs` `AppManifest::commands` + `allow-<command>` in `capabilities/main.json`.
Expand Down
88 changes: 88 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/adapters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ kamadak-exif = "0.6.1"
turbojpeg = { version = "1", default-features = false, features = ["cmake"] }
# Preview resize (ADR 0012). MIT OR Apache-2.0. Pure Rust, SIMD picked at run time.
fast_image_resize = { version = "5", default-features = false }
# Session store (ADR 0009, `store`). MIT, with libsqlite3-sys (MIT) building the bundled SQLite
# (public domain) with `cc`: no system SQLite, the same version on every PC. 0.41 at least:
# its SQLite 3.54 fixes RUSTSEC-2026-0459 (a -wal with another page size). Added with
# Margaux's OK in chat (29 Nov 2026).
rusqlite = { version = "0.41", features = ["bundled"] }

[target.'cfg(windows)'.dependencies]
# Read-only Win32 lookups in `winfs` (volume identity, time zone). MIT OR Apache-2.0. Already in
Expand Down
4 changes: 3 additions & 1 deletion crates/adapters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
//! into screen previews in memory (`preview`), runs them on reader threads and decode workers
//! with prefetch and an in-memory cache (`pipeline`) and makes read-only Win32 lookups
//! (`winfs`: a folder's volume identity, the PC's UTC offset), and makes the read-only lookups
//! of a dry-run plan and preflight (`facts`).
//! of a dry-run plan and preflight (`facts`). The session store (`store`, SQLite) writes only
//! its own databases and lock files, in the injected sessions folder on the internal disk.

pub mod facts;
pub mod metadata;
pub mod pipeline;
pub mod preview;
pub mod scan;
pub mod store;
pub mod winfs;

pub use culla_core::VERSION;
28 changes: 28 additions & 0 deletions crates/adapters/src/store/key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! The file name of a source's session database and lock.

use culla_core::volume::SourceKey;

/// The `<key>` of `<key>.sqlite` and `<key>.lock`: 32 lowercase hex digits from the serial and
/// the folded path (ADR 0008). Never the drive letter, so a card under another letter finds its
/// session (US-09).
///
/// Provisional (proposed, SPEC §10): file-engine §2.2 names the first 16 bytes of
/// `blake3(serial ‖ rel_key)`; BLAKE3 is not a dependency yet (it comes with the hashing of the
/// copy steps), so this is FNV-1a 128 over a version tag, the serial (little endian) and the
/// folded path, which has the same length. A collision cannot mix two sources: the database
/// stores its source and [`super::SessionDb::open_at`] refuses another one
/// ([`super::DbError::OtherSource`]). To switch to BLAKE3 before the first release, when no
/// database exists yet.
pub fn file_key(key: &SourceKey) -> String {
const OFFSET: u128 = 0x6c62_272e_07bb_0142_62b8_2175_6295_c58d;
const PRIME: u128 = 0x0000_0000_0100_0000_0000_0000_0000_013b;
let mut bytes = b"culla-session-v1\0".to_vec();
bytes.extend_from_slice(&key.serial.to_le_bytes());
bytes.extend_from_slice(key.rel_key.as_bytes());
let mut h = OFFSET;
for b in bytes {
h ^= u128::from(b);
h = h.wrapping_mul(PRIME);
}
format!("{h:032x}")
}
104 changes: 104 additions & 0 deletions crates/adapters/src/store/lock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//! The source lock file `<key>.lock` next to each session database (design/file-engine.md
//! §2.2): recovery and apply hold it for their whole duration, so no second process recovers or
//! applies the same source.

use std::fmt;
use std::fs::{File, OpenOptions, TryLockError};
use std::io;
use std::path::{Path, PathBuf};

use culla_core::volume::SourceKey;

/// A held source lock. Dropping it releases the lock; the file itself stays (Culla never
/// removes it, and an unheld file means nothing).
#[derive(Debug)]
pub struct SourceLock {
// Held for its lock: released when the handle closes.
_file: File,
key: SourceKey,
path: PathBuf,
}

/// Why the lock was not taken.
#[derive(Debug)]
pub enum LockError {
/// Another holder has it (another instance applying or recovering this source): change
/// nothing in its database and show the source as busy.
Busy,
/// The lock file could not be opened or created.
Io(io::Error),
}

impl fmt::Display for LockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Busy => f.write_str("the source is being applied or recovered elsewhere"),
Self::Io(e) => write!(f, "the source lock could not be opened: {e}"),
}
}
}

impl std::error::Error for LockError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Busy => None,
Self::Io(e) => Some(e),
}
}
}

impl SourceLock {
/// The source this lock is for.
pub fn key(&self) -> &SourceKey {
&self.key
}

/// The lock file.
pub fn path(&self) -> &Path {
&self.path
}

/// Takes the lock at `path` for `key` without waiting: the file is created if missing
/// (never truncated), opened with share mode 0 on Windows, and locked exclusively
/// (`File::try_lock`) on every platform.
pub(crate) fn acquire(path: PathBuf, key: SourceKey) -> Result<Self, LockError> {
let file = match open(&path, true) {
Ok(f) => f,
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => {
open(&path, false).map_err(busy_or_io)?
}
Err(e) => return Err(busy_or_io(e)),
};
match file.try_lock() {
Ok(()) => Ok(Self {
_file: file,
key,
path,
}),
Err(TryLockError::WouldBlock) => Err(LockError::Busy),
Err(TryLockError::Error(e)) => Err(busy_or_io(e)),
}
}
}

/// Opens the lock file for reading and writing, creating it only when `create_new` (so an
/// existing file is never truncated or replaced).
fn open(path: &Path, create_new: bool) -> io::Result<File> {
let mut o = OpenOptions::new();
o.read(true).write(true).create_new(create_new);
#[cfg(windows)]
{
use std::os::windows::fs::OpenOptionsExt;
o.share_mode(0);
}
o.open(path)
}

/// `ERROR_SHARING_VIOLATION` (32) and `ERROR_LOCK_VIOLATION` (33) mean another holder.
fn busy_or_io(e: io::Error) -> LockError {
if cfg!(windows) && matches!(e.raw_os_error(), Some(32 | 33)) {
LockError::Busy
} else {
LockError::Io(e)
}
}
Loading
Loading