workyard_core/observation.rs
1//! Read-only task observations keep saved progress distinct from current Git facts.
2use crate::{Control, Participant, Problem, Task};
3use std::{future::Future, path::PathBuf};
4
5/// Recorded task and evidence available during read-only inspection.
6pub struct TaskSnapshot {
7 /// Name used to identify this entry.
8 pub name: Option<String>,
9 /// Location of the task record when available.
10 pub record: PathBuf,
11 /// Decoded task when the published record is readable.
12 pub task: Option<Task>,
13 /// Independent evidence available for checking the task record.
14 pub evidence: Option<Task>,
15 /// Participant index associated with unresolved effect evidence.
16 pub pending: Option<usize>,
17 /// Whether another operation currently holds admission.
18 pub busy: bool,
19 /// Diagnostics collected while reading or inspecting the task.
20 pub problems: Vec<Problem>,
21}
22
23/// Current branch, worktree location and working-copy observations from Git.
24pub struct GitFacts {
25 /// Verified common Git storage, not the linked worktree administration.
26 pub common_dir: Option<PathBuf>,
27 /// Source location verified against the participant's Git backing identity.
28 pub repository_source: Option<PathBuf>,
29 /// An observed condition can be known (such as absence) and still need a remedy.
30 pub problem: Option<Problem>,
31 /// Worktree location reported by Git, when available.
32 pub path: Option<PathBuf>,
33 /// Branch associated with the worktree, when known.
34 pub branch: Option<String>,
35 /// Whether the worktree has local changes.
36 pub dirty: bool,
37 /// Whether Git reports unresolved conflicts.
38 pub conflicted: bool,
39 /// Whether an unfinished repository operation was observed.
40 pub operation_in_progress: bool,
41}
42
43/// Recorded participant paired with its current observation.
44pub struct ParticipantInspection {
45 /// Participant to which this observation or change applies.
46 pub participant: Participant,
47 /// Facts collected from the current filesystem or Git inspection.
48 pub current: Result<GitFacts, Problem>,
49}
50
51/// Snapshot and live participant observations for a task.
52pub struct TaskInspection {
53 /// Task and evidence as read before inspecting participants.
54 pub snapshot: TaskSnapshot,
55 /// Members associated with this task or operation.
56 pub participants: Vec<ParticipantInspection>,
57}
58
59/// Read-only Git inspection used by status and recovery decisions.
60pub trait ObservationGit: Sync {
61 /// Collect live repository facts for a recorded participant.
62 fn observe(
63 &self,
64 participant: &Participant,
65 control: &Control,
66 ) -> impl Future<Output = Result<GitFacts, Problem>> + Send;
67}
68
69/// Inspect the selected repository or task without applying changes.
70pub async fn inspect(
71 snapshot: TaskSnapshot,
72 git: &impl ObservationGit,
73 control: &Control,
74) -> Result<TaskInspection, Problem> {
75 let mut participants = Vec::new();
76 // Independent evidence can describe intended membership when publication failed.
77 // It remains separately identified in the result, never reconstructed as a record.
78 if let Some(task) = snapshot.task.as_ref().or(snapshot.evidence.as_ref()) {
79 for participant in &task.participants {
80 control.check()?;
81 let current = git.observe(participant, control).await;
82 control.check()?;
83 participants.push(ParticipantInspection {
84 participant: participant.clone(),
85 current,
86 });
87 }
88 }
89 Ok(TaskInspection {
90 snapshot,
91 participants,
92 })
93}