Skip to content

Commit

Permalink
feat: simplify CLI sessions (#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
baxen authored Feb 12, 2025
1 parent 6220ef0 commit 7a8552e
Show file tree
Hide file tree
Showing 17 changed files with 1,248 additions and 1,282 deletions.
1 change: 0 additions & 1 deletion crates/goose-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod agent_version;
pub mod configure;
pub mod mcp;
pub mod session;
192 changes: 0 additions & 192 deletions crates/goose-cli/src/commands/session.rs

This file was deleted.

15 changes: 15 additions & 0 deletions crates/goose-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use etcetera::AppStrategyArgs;
use once_cell::sync::Lazy;
pub mod commands;
pub mod log_usage;
pub mod logging;
pub mod session;

// Re-export commonly used types
pub use session::Session;

pub static APP_STRATEGY: Lazy<AppStrategyArgs> = Lazy::new(|| AppStrategyArgs {
top_level_domain: "Block".to_string(),
author: "Block".to_string(),
app_name: "goose".to_string(),
});
15 changes: 10 additions & 5 deletions crates/goose-cli/src/log_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@ mod tests {
use etcetera::{choose_app_strategy, AppStrategy};
use goose::providers::base::{ProviderUsage, Usage};

use crate::{
log_usage::{log_usage, SessionLog},
test_helpers::run_with_tmp_dir,
};
use crate::log_usage::{log_usage, SessionLog};

pub fn run_with_tmp_dir<F: FnOnce() -> T, T>(func: F) -> T {
use tempfile::tempdir;

let temp_dir = tempdir().unwrap();
let temp_dir_path = temp_dir.path().to_path_buf();

temp_env::with_vars([("HOME", Some(temp_dir_path.as_os_str()))], func)
}

#[test]
fn test_session_logging() {
run_with_tmp_dir(|| {
let home_dir = choose_app_strategy(crate::APP_STRATEGY.clone()).unwrap();

let log_file = home_dir
.in_state_dir("logs")
.unwrap_or_else(|| home_dir.in_data_dir("logs"))
Expand Down
30 changes: 6 additions & 24 deletions crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand};
use etcetera::AppStrategyArgs;
use once_cell::sync::Lazy;

pub static APP_STRATEGY: Lazy<AppStrategyArgs> = Lazy::new(|| AppStrategyArgs {
top_level_domain: "Block".to_string(),
author: "Block".to_string(),
app_name: "goose".to_string(),
});

mod cli_prompt;
mod commands;
mod log_usage;
mod logging;
mod prompt;
mod session;

use commands::agent_version::AgentCommand;
use commands::configure::handle_configure;
use commands::mcp::run_server;
use commands::session::build_session;

use console::style;
use goose::config::Config;
use logging::setup_logging;
use goose_cli::commands::agent_version::AgentCommand;
use goose_cli::commands::configure::handle_configure;
use goose_cli::commands::mcp::run_server;
use goose_cli::logging::setup_logging;
use goose_cli::session::build_session;
use std::io::{self, Read};

#[cfg(test)]
mod test_helpers;

#[derive(Parser)]
#[command(author, version, display_name = "", about, long_about = None)]
struct Cli {
Expand Down
39 changes: 0 additions & 39 deletions crates/goose-cli/src/prompt.rs

This file was deleted.

Loading

0 comments on commit 7a8552e

Please sign in to comment.