use clap::Parser;
use sacp_tokio::AcpAgent;
use std::str::FromStr;
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
#[derive(Parser, Debug)]
#[command(author, version, about = "YOPO - You Only Prompt Once", long_about = None)]
struct Args {
prompt: String,
agent_config: String,
#[arg(short, long)]
log: Option<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
let env_filter = if let Some(level) = args.log {
EnvFilter::new(format!("yopo={}", level))
} else {
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("yopo=info"))
};
tracing_subscriber::registry()
.with(env_filter)
.with(
tracing_subscriber::fmt::layer()
.with_target(true)
.with_writer(std::io::stderr),
)
.init();
let prompt = &args.prompt;
let agent_config = &args.agent_config;
let agent = AcpAgent::from_str(agent_config)?;
eprintln!("🚀 Spawning agent and running prompt...");
yopo::prompt_with_callback(agent, prompt.as_str(), |block| async move {
print!("{}", yopo::content_block_to_string(&block));
})
.await?;
println!(); eprintln!("✅ Agent completed!");
Ok(())
}