diff --git a/poc-agent/src/cli.rs b/poc-agent/src/cli.rs index d95a572..6925561 100644 --- a/poc-agent/src/cli.rs +++ b/poc-agent/src/cli.rs @@ -62,6 +62,9 @@ pub enum SubCmd { /// Stream output continuously instead of exiting #[arg(short, long)] follow: bool, + /// Block until a complete response is received, then exit + #[arg(long)] + block: bool, }, /// Send a message to the running agent Write { diff --git a/poc-agent/src/main.rs b/poc-agent/src/main.rs index a8430b5..6468069 100644 --- a/poc-agent/src/main.rs +++ b/poc-agent/src/main.rs @@ -83,8 +83,8 @@ async fn main() { // Subcommands that don't launch the TUI match &cli.command { - Some(cli::SubCmd::Read { follow }) => { - if let Err(e) = observe::cmd_read(*follow, cli.debug).await { + Some(cli::SubCmd::Read { follow, block }) => { + if let Err(e) = observe::cmd_read_inner(*follow, *block, cli.debug).await { eprintln!("{:#}", e); std::process::exit(1); } diff --git a/poc-agent/src/observe.rs b/poc-agent/src/observe.rs index e6e651e..a5bd127 100644 --- a/poc-agent/src/observe.rs +++ b/poc-agent/src/observe.rs @@ -69,6 +69,11 @@ fn cursor_path() -> PathBuf { session_dir().join("read-cursor") } /// Print new output since last read. With -f, also stream live from socket. pub async fn cmd_read(follow: bool, debug: bool) -> anyhow::Result<()> { + cmd_read_inner(follow, false, debug).await +} + +/// Print new output since last read. With -f, stream live. With block, wait for one response. +pub async fn cmd_read_inner(follow: bool, block: bool, debug: bool) -> anyhow::Result<()> { use std::io::{Read, Seek, SeekFrom, Write}; let log = log_path(); @@ -91,20 +96,20 @@ pub async fn cmd_read(follow: bool, debug: bool) -> anyhow::Result<()> { f.read_to_string(&mut buf)?; print!("{}", buf); let _ = std::io::stdout().flush(); - } else if !follow { + } else if !follow && !block { println!("(nothing new)"); } let _ = std::fs::write(&cursor, len.to_string()); - } else if !follow { + } else if !follow && !block { println!("(no log yet — is poc-agent running?)"); return Ok(()); } - if !follow { + if !follow && !block { return Ok(()); } - // -f: connect to socket for live output + // -f or --block: connect to socket for live output let sock = socket_path(); let stream = UnixStream::connect(&sock).await .map_err(|e| anyhow::anyhow!( @@ -122,6 +127,11 @@ pub async fn cmd_read(follow: bool, debug: bool) -> anyhow::Result<()> { Ok(_) => { print!("{}", line); let _ = std::io::stdout().lock().flush(); + + // In blocking mode, stop when we see a new user input (line starting with ">") + if block && line.trim_start().starts_with('>') { + break; + } } Err(_) => break, }