huskies: merge 533_story_crdt_based_done_archived_sweep_to_replace_filesystem_based_watcher_sweep

This commit is contained in:
dave
2026-04-10 16:54:14 +00:00
parent 8f34c521fb
commit 4c8fe910a7
2 changed files with 43 additions and 185 deletions
+24 -10
View File
@@ -328,26 +328,40 @@ async fn main() -> Result<(), std::io::Error> {
let watchdog_root: Option<PathBuf> = app_state.project_root.lock().unwrap().clone();
AgentPool::spawn_watchdog(Arc::clone(&agents), watchdog_root);
// Filesystem watcher: only watches config files (project.toml, agents.toml) and
// handles the sweep of done→archived. Work-item pipeline events are now driven
// by CRDT state transitions via crdt_state::subscribe().
// Filesystem watcher: watches config files (project.toml, agents.toml) for
// hot-reload and runs the CRDT-based done→archived sweep. Work-item pipeline
// events are driven by CRDT state transitions via crdt_state::subscribe().
if let Some(ref root) = *app_state.project_root.lock().unwrap() {
let work_dir = root.join(".huskies").join("work");
if work_dir.is_dir() {
let watcher_config = config::ProjectConfig::load(root)
.map(|c| c.watcher)
.unwrap_or_default();
io::watcher::start_watcher(work_dir, root.clone(), watcher_tx.clone(), watcher_config);
}
let watcher_config = config::ProjectConfig::load(root)
.map(|c| c.watcher)
.unwrap_or_default();
io::watcher::start_watcher(root.clone(), watcher_tx.clone(), watcher_config);
}
// Bridge CRDT state-transition events to the watcher broadcast channel.
// This replaces the filesystem watcher as the source of WorkItem events.
// Also prunes worktrees when stories transition to 6_archived.
{
let crdt_watcher_tx = watcher_tx.clone();
let crdt_prune_root: Option<PathBuf> = app_state.project_root.lock().unwrap().clone();
if let Some(mut crdt_rx) = crdt_state::subscribe() {
tokio::spawn(async move {
while let Ok(evt) = crdt_rx.recv().await {
// Prune the worktree when a story is archived.
if evt.to_stage == "6_archived"
&& let Some(root) = crdt_prune_root.as_ref().cloned()
{
let story_id = evt.story_id.clone();
tokio::task::spawn_blocking(move || {
if let Err(e) =
crate::worktree::prune_worktree_sync(&root, &story_id)
{
crate::slog!(
"[crdt] worktree prune failed for {story_id}: {e}"
);
}
});
}
let (action, commit_msg) =
io::watcher::stage_metadata(&evt.to_stage, &evt.story_id)
.unwrap_or(("update", format!("huskies: update {}", evt.story_id)));