Skip to main content

codetether_agent/cli/
run.rs

1//! Non-interactive run command
2
3use super::RunArgs;
4use crate::session::Session;
5use anyhow::Result;
6
7pub async fn execute(args: RunArgs) -> Result<()> {
8    let message = args.message.trim();
9    
10    if message.is_empty() {
11        anyhow::bail!("You must provide a message");
12    }
13
14    tracing::info!("Running with message: {}", message);
15
16    // Create or continue session
17    let mut session = if let Some(session_id) = args.session {
18        Session::load(&session_id).await?
19    } else if args.continue_session {
20        Session::last().await?
21    } else {
22        Session::new().await?
23    };
24
25    // Set model if specified
26    if let Some(model) = args.model {
27        tracing::info!("Using specified model: {}", model);
28        session.metadata.model = Some(model);
29    }
30
31    // Execute the prompt
32    let result = session.prompt(message).await?;
33
34    // Output based on format
35    match args.format.as_str() {
36        "json" => {
37            println!("{}", serde_json::to_string_pretty(&result)?);
38        }
39        _ => {
40            println!("{}", result.text);
41        }
42    }
43
44    Ok(())
45}