Skip to main content

capsule_core/
culling.rs

1//! The client-side **culling** workflow engine (SSoT: [Organization — Culling]).
2//!
3//! Culling is the review pass a photographer makes after a shoot: keep, undecided, toss.
4//! Capsule models it as a trinary [`CullFlag`] per asset
5//! stored in the sidecar's `cull` LWW register. This module owns the *derived* pieces the
6//! schema deliberately does **not** store, so there is no second source of truth to diverge:
7//!
8//! - [`GroupCullState`] — a stack/burst has no stored flag of its own; its cull state is
9//!   **derived** from its members (all-rejected, any-pick, else mixed).
10//!
11//! The stateful surface (writing flags as signed `metadata-update`s, the cull-filtered views,
12//! flagging a whole stack, and the reject-sweep) lives on
13//! `Workspace`, which ties these predicates to the on-disk
14//! signed data plane. Flagging never touches bytes and is fully reversible; the reject-sweep's
15//! batch-move to trash is the *only* destructive step, and it is soft-per-retention like any
16//! delete.
17//!
18//! [Organization — Culling]: https://docs/design/organization/#culling
19
20use crate::sidecar::sidecar_v1::CullFlag;
21
22/// The **derived** cull state of a stack/burst (owner: [Organization — Culling]). A group
23/// never stores a flag of its own — this is computed from its members every time it is read,
24/// so grouping cannot diverge from the per-asset flags.
25///
26/// The precedence is exactly the doc's: `all-rejected → any-pick → else mixed`.
27///
28/// [Organization — Culling]: https://docs/design/organization/#culling
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum GroupCullState {
31    /// Every member is [`CullFlag::Reject`] — the whole group is a sweep candidate.
32    AllRejected,
33    /// At least one member is [`CullFlag::Pick`] (and not every member is rejected).
34    AnyPick,
35    /// Neither all-rejected nor any-pick (e.g. some rejects mixed with neutrals, or an
36    /// entirely undecided group).
37    Mixed,
38}
39
40impl GroupCullState {
41    /// Derive a group's state from its members' flags, per the doc precedence
42    /// (`all-rejected → any-pick → else mixed`). Returns `None` for an empty group — there
43    /// are no members to derive a state from, and a vacuous "all rejected" would be wrong.
44    pub fn derive(flags: impl IntoIterator<Item = CullFlag>) -> Option<Self> {
45        let mut count = 0usize;
46        let mut all_reject = true;
47        let mut any_pick = false;
48        for flag in flags {
49            count += 1;
50            match flag {
51                CullFlag::Reject => {}
52                CullFlag::Pick => {
53                    any_pick = true;
54                    all_reject = false;
55                }
56                CullFlag::Neutral => all_reject = false,
57            }
58        }
59        if count == 0 {
60            return None;
61        }
62        Some(if all_reject {
63            Self::AllRejected
64        } else if any_pick {
65            Self::AnyPick
66        } else {
67            Self::Mixed
68        })
69    }
70}
71
72#[cfg(test)]
73mod tests;