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
44 changes: 17 additions & 27 deletions crates/goose-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ async fn get_or_create_session_id(
}

let Some(id) = identifier else {
if resume {
return if resume {
let sessions = SessionManager::list_sessions().await?;
let session_id = sessions
.first()
.map(|s| s.id.clone())
.ok_or_else(|| anyhow::anyhow!("No session found to resume"))?;
return Ok(Some(session_id));
Ok(Some(session_id))
} else {
let session =
SessionManager::create_session(std::env::current_dir()?, "CLI Session".to_string())
.await?;
return Ok(Some(session.id));
}
Ok(Some(session.id))
};
};

if let Some(session_id) = id.session_id {
Expand Down Expand Up @@ -817,7 +817,7 @@ pub struct RecipeInfo {
pub retry_config: Option<goose::agents::types::RetryConfig>,
}

pub async fn cli() -> Result<()> {
pub async fn cli() -> anyhow::Result<()> {
let cli = Cli::parse();

// Track the current directory in projects.json
Expand Down Expand Up @@ -850,20 +850,17 @@ pub async fn cli() -> Result<()> {

match cli.command {
Some(Command::Configure {}) => {
let _ = handle_configure().await;
return Ok(());
handle_configure().await?;
}
Some(Command::Info { verbose }) => {
handle_info(verbose)?;
return Ok(());
}
Some(Command::Mcp { name }) => {
crate::logging::setup_logging(Some(&format!("mcp-{name}")), None)?;
let _ = goose_mcp::mcp_server_runner::run_mcp_server(&name).await;
goose_mcp::mcp_server_runner::run_mcp_server(&name).await?;
}
Some(Command::Acp {}) => {
let _ = run_acp_agent().await;
return Ok(());
run_acp_agent().await?;
}
Some(Command::Session {
command,
Expand All @@ -884,13 +881,9 @@ pub async fn cli() -> Result<()> {
ascending,
working_dir,
limit,
}) => {
handle_session_list(format, ascending, working_dir, limit).await?;
Ok(())
}
}) => Ok(handle_session_list(format, ascending, working_dir, limit).await?),
Some(SessionCommand::Remove { id, regex }) => {
handle_session_remove(id, regex).await?;
return Ok(());
Ok(handle_session_remove(id, regex).await?)
}
Some(SessionCommand::Export {
identifier,
Expand Down Expand Up @@ -1183,7 +1176,7 @@ pub async fn cli() -> Result<()> {
.await;

if interactive {
let _ = session.interactive(input_config.contents).await;
session.interactive(input_config.contents).await?;
} else if let Some(contents) = input_config.contents {
let session_start = std::time::Instant::now();
let session_type = if recipe_info.is_some() {
Expand Down Expand Up @@ -1237,8 +1230,9 @@ pub async fn cli() -> Result<()> {

result?;
} else {
eprintln!("Error: no text provided for prompt in headless mode");
std::process::exit(1);
return Err(anyhow::anyhow!(
"no text provided for prompt in headless mode"
));
}

return Ok(());
Expand Down Expand Up @@ -1290,8 +1284,7 @@ pub async fn cli() -> Result<()> {
BenchCommand::Selectors { config } => BenchRunner::list_selectors(config)?,
BenchCommand::InitConfig { name } => {
let mut config = BenchRunConfig::default();
let cwd =
std::env::current_dir().expect("Failed to get current working directory");
let cwd = std::env::current_dir()?;
config.output_dir = Some(cwd);
config.save(name);
}
Expand Down Expand Up @@ -1334,7 +1327,7 @@ pub async fn cli() -> Result<()> {
}
None => {
return if !Config::global().exists() {
let _ = handle_configure().await;
handle_configure().await?;
Ok(())
} else {
// Run session command by default
Expand Down Expand Up @@ -1364,10 +1357,7 @@ pub async fn cli() -> Result<()> {
retry_config: None,
})
.await;
if let Err(e) = session.interactive(None).await {
eprintln!("Session ended with error: {}", e);
std::process::exit(1);
}
session.interactive(None).await?;
Ok(())
};
}
Expand Down
Loading
Loading