Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ureq = { version = "2", features = ["json"] }
# Database
rusqlite = { version = "0.31", features = ["bundled"] }

# Signal handling
ctrlc = "3"

# Terminal UI
colored = "2"
indicatif = "0.17"
Expand Down
22 changes: 21 additions & 1 deletion core/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use anyhow::Result;
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};

pub struct WatchConfig {
Expand Down Expand Up @@ -32,10 +34,19 @@ pub fn run_watch(
);
eprintln!(" Press Ctrl-C to stop.\n");

// Graceful shutdown via signal handler
let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
ctrlc::set_handler(move || {
r.store(false, Ordering::SeqCst);
}).ok();

let watch_start = Instant::now();
let mut handoff_count: u32 = 0;
let mut last_handoff: Option<Instant> = None;
let mut last_size: u64 = 0;

loop {
while running.load(Ordering::SeqCst) {
std::thread::sleep(watch_config.poll_interval);

// Find latest JSONL
Expand Down Expand Up @@ -106,6 +117,7 @@ pub fn run_watch(
let result = handoff_with_chain(config, &handoff_text, &project_dir.to_string_lossy());

if result.success {
handoff_count += 1;
eprintln!(" \u{2705} Auto-handed off to {}", result.agent);
if !handoff_path.as_os_str().is_empty() {
eprintln!(" \u{1f4c4} Saved: {}", handoff_path.display());
Expand All @@ -128,6 +140,14 @@ pub fn run_watch(
last_handoff = Some(Instant::now());
last_size = current_size;
}

// Graceful shutdown summary
let elapsed = watch_start.elapsed();
eprintln!("\n \u{1f6d1} Watch stopped.");
eprintln!(" Uptime: {}m {}s | Handoffs: {}",
elapsed.as_secs() / 60, elapsed.as_secs() % 60, handoff_count);

Ok(())
}

/// Handoff with chain — try each agent in priority order.
Expand Down
Loading