2
0

feat(headless): add wait command for monitoring background run completion

This commit is contained in:
2026-03-24 15:15:41 +09:00
parent 12faa891e7
commit 5f60a6c5f3
2 changed files with 32 additions and 0 deletions

View File

@@ -195,6 +195,10 @@ fn execute_once(configs: Vec<config::AgentConfig>) -> Result<(), String> {
let all: Vec<usize> = (0..agents.len()).collect();
let path = save_session(1, &agents, &decision, &all);
eprintln!(" saved: {path}");
// Write done marker for background monitoring
atomic_write(&format!("{STATE_DIR}/done"), b"1");
Ok(())
}
@@ -297,6 +301,7 @@ fn run_once(configs: &[config::AgentConfig]) -> Result<(), String> {
return run_with_configs(next);
}
atomic_write(&format!("{STATE_DIR}/done"), b"1");
Ok(())
}
@@ -804,6 +809,32 @@ pub fn remember() {
}
}
/// Wait for background run to complete, then show summary.
pub fn wait_done() {
let done_path = format!("{STATE_DIR}/done");
eprint!(" waiting...");
loop {
if std::path::Path::new(&done_path).exists() {
eprintln!(" done");
let _ = std::fs::remove_file(&done_path);
// Show compact summary
status(false);
if let Ok(content) = std::fs::read_to_string(format!("{STATE_DIR}/decision.json")) {
if let Ok(d) = serde_json::from_str::<serde_json::Value>(&content) {
let text = d["decision"].as_str().unwrap_or("");
let first: String = text.lines()
.filter(|l| !l.starts_with('#') && !l.is_empty())
.take(3).collect::<Vec<_>>().join("\n");
if !first.is_empty() { println!("\n{first}"); }
}
}
return;
}
std::thread::sleep(std::time::Duration::from_millis(500));
eprint!(".");
}
}
pub fn signal_next(save: Vec<usize>) {
let save_val = if save.is_empty() {
serde_json::json!(null)

View File

@@ -120,6 +120,7 @@ fn main() {
std::process::exit(1);
}
}
Some("wait") => aishell::headless::wait_done(),
Some("next") => {
let save: Vec<usize> = env::args().skip(2)
.filter_map(|s| s.parse().ok())