workyard_core/model/removal.rs
1/// Removal evidence belongs to one task incarnation. Restoration never toggles back.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum RemovalDirection {
4 /// Unlink participant worktrees.
5 Remove,
6 /// Recreate previously unlinked worktrees from retained branches.
7 Restore,
8}
9
10/// Progress of a participant through unlinking or restoration.
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum RemovalPhase {
13 /// The participant still has its original worktree.
14 Present,
15 /// The participant worktree has been unlinked.
16 Removed,
17 /// Restoration has begun.
18 Restoring,
19 /// Supervised add succeeded; identity/final publication may still need recovery.
20 Recreated,
21 /// Restoration of the worktree has settled.
22 Restored,
23}
24
25/// Facts retained for one participant across removal and undo.
26#[derive(Clone, Debug, PartialEq, Eq)]
27pub struct RemovalParticipant {
28 /// Local branch retained by removal; absent for a protected detached HEAD.
29 pub branch: Option<String>,
30 /// Whether local changes were present when removal began.
31 pub dirty_at_start: bool,
32 /// Step reached by this participant.
33 pub phase: RemovalPhase,
34}
35
36/// Evidence retained to continue or undo removal.
37#[derive(Clone, Debug, PartialEq, Eq)]
38pub struct Removal {
39 /// Direction persisted for subsequent recovery attempts.
40 pub direction: RemovalDirection,
41 /// Members associated with this task or operation.
42 pub participants: Vec<RemovalParticipant>,
43 /// Unix milliseconds, assigned only once every participant is removed.
44 pub retired_at: Option<u64>,
45}
46
47impl Removal {
48 /// Check whether every participant is present or restored in the restoration direction.
49 pub fn restoration_complete(&self) -> bool {
50 self.direction == RemovalDirection::Restore
51 && self
52 .participants
53 .iter()
54 .all(|p| matches!(p.phase, RemovalPhase::Present | RemovalPhase::Restored))
55 }
56}
57
58/// An invocation outcome does not replace task history when nothing was changed.
59pub struct RemovalResult {
60 /// Whether inspection found no outstanding work to resume.
61 pub nothing_to_recover: bool,
62 /// Task selected for this operation.
63 pub task: crate::Task,
64 /// Location of the task record when available.
65 pub record: std::path::PathBuf,
66 /// Invocation history tracked separately from task lifecycle.
67 pub operation: crate::Operation,
68 /// Diagnostic describing a failure or an unresolved condition.
69 pub problem: Option<crate::Problem>,
70 /// True after entering publication, even if its durability is uncertain.
71 pub mutation_started: bool,
72 /// Whether inspection produced removal facts.
73 pub inspected: bool,
74 /// Whether a task record was available for the result.
75 pub record_available: bool,
76 /// Existing damage/incomplete work, independent of this invocation outcome.
77 pub needs_attention: bool,
78}