use super::Deriver;
use crate::git_tree::{AgentState, GitTree};
use crate::watch::Mark;
use std::path::{Path, PathBuf};
pub(crate) fn needs_liveness_reprobe(tree: &GitTree) -> bool {
tree.agents
.iter()
.any(|a| matches!(a.state, AgentState::Live | AgentState::InFlight))
}
impl Deriver {
pub(super) fn reprobe_live(&mut self) {
let mut live: Vec<(PathBuf, Vec<String>)> = Vec::new();
for (path, tree) in &self.trees {
if needs_liveness_reprobe(tree) {
let ids = tree.agents.iter().map(|a| a.agent_id.clone()).collect();
live.push((path.clone(), ids));
}
}
for (path, ids) in live {
self.probes.invalidate_liveness(&path, &ids);
self.schedule.mark([(path, Mark::Poll)]);
}
}
pub(super) fn refresh_liveness(&self, root: &Path) {
let Some(tree) = self.trees.get(root) else {
return;
};
let resting: Vec<String> = tree
.agents
.iter()
.filter(|a| !matches!(a.state, AgentState::Live | AgentState::InFlight))
.map(|a| a.agent_id.clone())
.collect();
self.probes.invalidate_liveness(root, &resting);
}
}
#[cfg(test)]
mod tests;