workyard_core/model/amendment.rs
1use crate::{CreationOptions, Operation, Problem, RepositoryInput, Task};
2use std::path::PathBuf;
3
4/// Requested changes to an existing task's membership.
5#[derive(Clone, Debug)]
6pub struct AmendRequest {
7 /// Task selected for this operation.
8 pub task: String,
9 /// Backing repositories selected for membership.
10 pub repositories: Vec<RepositoryInput>,
11 /// Participant names selected for unlinking.
12 pub remove: Vec<String>,
13 /// Consent and direction supplied for unlinking worktrees.
14 pub removal_options: crate::RemovalOptions,
15 /// Branch reuse and network policy for new participants.
16 pub options: CreationOptions,
17 /// Remote selected for branch resolution or fetch.
18 pub remote: Option<String>,
19 /// Starting revision for a newly created branch.
20 pub from: Option<String>,
21}
22
23/// A selector is bound before any worktree can be renamed or replaced.
24#[derive(Clone, Debug, PartialEq, Eq)]
25pub struct RemovalTarget {
26 /// Name used to identify this entry.
27 pub name: String,
28 /// Identity used to distinguish backing repositories across path changes.
29 pub backing_identity: String,
30 /// Identity used to verify the linked worktree before applying changes.
31 pub worktree_identity: String,
32}
33
34impl RemovalTarget {
35 /// Verify the bound name and both identities against the current participant.
36 pub fn matches(&self, participant: &crate::Participant) -> bool {
37 self.name == participant.name
38 && self.backing_identity == participant.backing_identity
39 && participant.worktree_identity.as_ref() == Some(&self.worktree_identity)
40 }
41}
42
43/// A participant and the effect that amendment had on it.
44#[derive(Clone, Debug)]
45pub struct AmendmentChange {
46 /// Participant to which this observation or change applies.
47 pub participant: String,
48 /// Classification used to interpret this record.
49 pub kind: AmendmentChangeKind,
50}
51
52/// Membership and publication facts available after amendment.
53pub struct AmendResult {
54 /// Newly established project roots eligible for catalog registration.
55 pub admitted_roots: Vec<PathBuf>,
56 /// Whether the invocation entered the mutation phase.
57 pub mutation_started: bool,
58 /// Task selected for this operation.
59 pub task: Task,
60 /// Location of the task record when available.
61 pub record: PathBuf,
62 /// Invocation history tracked separately from task lifecycle.
63 pub operation: Operation,
64 /// Changes reported for individual participants.
65 pub changes: Vec<AmendmentChange>,
66 /// Diagnostic describing a failure or an unresolved condition.
67 pub problem: Option<Problem>,
68}
69
70/// How an amendment affected a participant.
71#[derive(Clone, Copy, Debug, PartialEq, Eq)]
72pub enum AmendmentChangeKind {
73 /// The participant joined the task.
74 Added,
75 /// The worktree was unlinked and membership removed.
76 Removed,
77 /// The participant received a new task-local name.
78 Renamed,
79 /// Git registration was reconciled with the worktree.
80 Repaired,
81 /// Recorded participant details changed.
82 Updated,
83 /// Membership and placement required no update.
84 Unchanged,
85}
86
87impl AmendmentChangeKind {
88 /// Return the stable spelling used in records or output.
89 pub fn as_str(self) -> &'static str {
90 match self {
91 Self::Added => "added",
92 Self::Removed => "removed",
93 Self::Renamed => "renamed",
94 Self::Repaired => "repaired",
95 Self::Updated => "updated",
96 Self::Unchanged => "unchanged",
97 }
98 }
99}