Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
baxen committed Jan 17, 2025
1 parent fd80c3b commit 43e74e7
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 59 deletions.
128 changes: 92 additions & 36 deletions crates/goose-cli/src/commands/configure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cliclack::spinner;
use console::style;
use goose::agents::{SystemConfig, system::Envs};
use goose::agents::{system::Envs, SystemConfig};
use goose::key_manager::{get_keyring_secret, save_to_keyring, KeyRetrievalStrategy};
use goose::message::Message;
use goose::providers::anthropic::ANTHROPIC_DEFAULT_MODEL;
Expand All @@ -25,31 +25,56 @@ pub async fn handle_configure(
if !config_exists {
// First time setup flow
println!("");
println!("{}", style("Welcome to goose! Let's get you set up with a provider.").dim());
println!("{}", style(" you can rerun this command later to update your configuration").dim());
println!(
"{}",
style("Welcome to goose! Let's get you set up with a provider.").dim()
);
println!(
"{}",
style(" you can rerun this command later to update your configuration").dim()
);
println!("");
cliclack::intro(style(" goose-configure ").on_cyan().black())?;
configure_provider_dialog(provided_provider, provided_model).await?;
println!("\n {}: Run '{}' again to adjust your config or add systems", style("Tip").green().italic(), style("goose configure").cyan());
println!(
"\n {}: Run '{}' again to adjust your config or add systems",
style("Tip").green().italic(),
style("goose configure").cyan()
);
Ok(())
} else {
println!("");
println!("{}", style("This will update your existing config file").dim());
println!("{} {}", style(" if you prefer, you can edit it directly at").dim(), Config::config_path()?.display());
println!(
"{}",
style("This will update your existing config file").dim()
);
println!(
"{} {}",
style(" if you prefer, you can edit it directly at").dim(),
Config::config_path()?.display()
);
println!("");

cliclack::intro(style(" goose-configure ").on_cyan().black())?;
let action = cliclack::select("What would you like to configure?")
.item("providers", "Configure Providers", "Change provider or update credentials")
.item("toggle", "Toggle Systems", "Enable or disable connected systems")
.item(
"providers",
"Configure Providers",
"Change provider or update credentials",
)
.item(
"toggle",
"Toggle Systems",
"Enable or disable connected systems",
)
.item("add", "Add System", "Connect to a new system")
.interact()?;

match action {
"toggle" => toggle_systems_dialog(),
"add" => configure_systems_dialog(),
"providers" => configure_provider_dialog(provided_provider, provided_model).await,
_ => unreachable!()
_ => unreachable!(),
}
}
}
Expand Down Expand Up @@ -157,7 +182,7 @@ pub async fn configure_provider_dialog(
Ok(()) => {
let msg = format!("Configuration saved to: {:?}", Config::config_path()?);
cliclack::outro(msg)
},
}
Err(e) => cliclack::outro(format!("Failed to save configuration: {}", e)),
};
}
Expand Down Expand Up @@ -200,9 +225,11 @@ pub fn get_required_keys(provider_name: &str) -> Vec<&'static str> {
pub fn toggle_systems_dialog() -> Result<(), Box<dyn Error>> {
// Load existing config
let mut config = Config::load().unwrap_or_default();

if config.systems.is_empty() {
let _ = cliclack::outro("No systems configured yet. Run configure and add some systems first.")?;
let _ = cliclack::outro(
"No systems configured yet. Run configure and add some systems first.",
)?;
return Ok(());
}

Expand All @@ -211,18 +238,25 @@ pub fn toggle_systems_dialog() -> Result<(), Box<dyn Error>> {
for (name, entry) in config.systems.iter() {
system_status.push((name.clone(), entry.enabled));
}

// Get currently enabled systems for the selection
let enabled_systems: Vec<&String> = system_status.iter()
let enabled_systems: Vec<&String> = system_status
.iter()
.filter(|(_, enabled)| *enabled)
.map(|(name, _)| name)
.collect();

// Let user toggle systems
let selected = cliclack::multiselect("enable systems: (use \"space\" to toggle and \"enter\" to submit)")
.items(&system_status.iter().map(|(name, _)| (name, name.as_str(), "")).collect::<Vec<_>>())
.initial_values(enabled_systems)
.interact()?;
let selected =
cliclack::multiselect("enable systems: (use \"space\" to toggle and \"enter\" to submit)")
.items(
&system_status
.iter()
.map(|(name, _)| (name, name.as_str(), ""))
.collect::<Vec<_>>(),
)
.initial_values(enabled_systems)
.interact()?;

// Update the config with new enabled/disabled status
for (name, _) in system_status.iter() {
Expand All @@ -238,8 +272,14 @@ pub fn toggle_systems_dialog() -> Result<(), Box<dyn Error>> {

pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
println!("");
println!("{}", style("Configure will help you add systems that goose can use").dim());
println!("{}", style(" systems provide tools and capabilities to the AI agent").dim());
println!(
"{}",
style("Configure will help you add systems that goose can use").dim()
);
println!(
"{}",
style(" systems provide tools and capabilities to the AI agent").dim()
);
println!("");

cliclack::intro(style(" goose-configure-systems ").on_cyan().black())?;
Expand All @@ -248,27 +288,43 @@ pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
let mut config = Config::load().unwrap_or_default();

let system_type = cliclack::select("What type of system would you like to add?")
.item("built-in", "Built-in System", "Use a system that comes with Goose")
.item("stdio", "Command-line System", "Run a local command or script")
.item(
"built-in",
"Built-in System",
"Use a system that comes with Goose",
)
.item(
"stdio",
"Command-line System",
"Run a local command or script",
)
.item("sse", "Remote System", "Connect to a remote system via SSE")
.interact()?;

match system_type {
"built-in" => {
let system = cliclack::select("Which built-in system would you like to enable?")
.item("developer2", "Developer Tools", "Code editing and shell access")
.item("nondeveloper", "Non Developer", "AI driven scripting for non developers")
.item(
"developer2",
"Developer Tools",
"Code editing and shell access",
)
.item(
"nondeveloper",
"Non Developer",
"AI driven scripting for non developers",
)
.item("jetbrains", "JetBrains", "Connect to jetbrains IDEs")
.interact()?;

config.systems.insert(
system.to_string(),
SystemEntry {
enabled: true,
config: SystemConfig::Builtin {
name: system.to_string(),
}
}
},
},
);

let _ = cliclack::outro(format!("Enabled {} system", style(system).green()))?;
Expand Down Expand Up @@ -304,8 +360,8 @@ pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
let cmd = parts.next().unwrap_or("").to_string();
let args: Vec<String> = parts.map(String::from).collect();

let add_env = cliclack::confirm("Would you like to add environment variables?")
.interact()?;
let add_env =
cliclack::confirm("Would you like to add environment variables?").interact()?;

let mut envs = HashMap::new();
while add_env {
Expand All @@ -332,8 +388,8 @@ pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
cmd,
args,
envs: Envs::new(envs),
}
}
},
},
);

let _ = cliclack::outro(format!("Added {} system", style(name).green()))?;
Expand Down Expand Up @@ -366,8 +422,8 @@ pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
})
.interact()?;

let add_env = cliclack::confirm("Would you like to add environment variables?")
.interact()?;
let add_env =
cliclack::confirm("Would you like to add environment variables?").interact()?;

let mut envs = HashMap::new();
while add_env {
Expand All @@ -393,13 +449,13 @@ pub fn configure_systems_dialog() -> Result<(), Box<dyn Error>> {
config: SystemConfig::Sse {
uri,
envs: Envs::new(envs),
}
}
},
},
);

let _ = cliclack::outro(format!("Added {} system", style(name).green()))?;
}
_ => unreachable!()
_ => unreachable!(),
};

config.save()?;
Expand Down
7 changes: 1 addition & 6 deletions crates/goose-cli/src/commands/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ pub async fn build_session<'a>(
Err(_) => Box::new(RustylinePrompt::new()),
};

display_session_info(
resume,
provider_name,
model_name,
session_file.as_path(),
);
display_session_info(resume, provider_name, model_name, session_file.as_path());
Box::new(Session::new(agent, prompt, session_file))
}

Expand Down
14 changes: 8 additions & 6 deletions crates/goose-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,18 @@ impl Default for Config {
default_provider: "".to_string(),
default_model: "".to_string(),
systems: HashMap::from([(
DEFAULT_SYSTEM.to_string(),
DEFAULT_SYSTEM.to_string(),
SystemEntry {
enabled: true,
config: SystemConfig::Builtin {
name: DEFAULT_SYSTEM.to_string(),
},
}
},
)]),
}
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -141,11 +140,11 @@ systems:
envs: {}
"#;
let config: Config = serde_yaml::from_str(yaml).unwrap();

// Check core settings
assert_eq!(config.default_provider, "openai");
assert_eq!(config.default_model, "gpt-4");

// Check builtin enabled system
match &config.systems.get("developer").unwrap().config {
SystemConfig::Builtin { name } => assert_eq!(name, "developer"),
Expand All @@ -166,7 +165,10 @@ systems:
match &python.config {
SystemConfig::Stdio { cmd, args, envs } => {
assert_eq!(cmd, "python3");
assert_eq!(args, vec!["-m", "goose.systems.python"]);
assert_eq!(
args,
&vec!["-m".to_string(), "goose.systems.python".to_string()]
);
let env = envs.get_env();
assert_eq!(env.get("PYTHONPATH").unwrap(), "/path/to/python");
assert_eq!(env.get("DEBUG").unwrap(), "true");
Expand Down
15 changes: 8 additions & 7 deletions crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{Parser, Subcommand, CommandFactory};
use clap::{CommandFactory, Parser, Subcommand};
use goose::agents::AgentFactory;

mod commands;
Expand All @@ -14,9 +14,9 @@ use commands::configure::handle_configure;
use commands::mcp::run_server;
use commands::session::build_session;
use commands::version::print_version;
use logging::setup_logging;
use config::Config;
use console::style;
use logging::setup_logging;
use std::io::{self, Read};

#[cfg(test)]
Expand Down Expand Up @@ -202,10 +202,7 @@ async fn main() -> Result<()> {
}

match cli.command {
Some(Command::Configure {
provider,
model,
}) => {
Some(Command::Configure { provider, model }) => {
let _ = handle_configure(provider, model).await;
return Ok(());
}
Expand Down Expand Up @@ -288,7 +285,11 @@ async fn main() -> Result<()> {
Cli::command().print_help()?;
println!();
if Config::load().is_err() {
println!("\n {}: Run '{}' to setup goose for the first time", style("Tip").green().italic(), style("goose configure").cyan());
println!(
"\n {}: Run '{}' to setup goose for the first time",
style("Tip").green().italic(),
style("goose configure").cyan()
);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/goose/src/agents/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ impl Capabilities {
.to_str()
.expect("should resolve executable to string path")
.to_string();
let transport = StdioTransport::new(&cmd, vec!["mcp".to_string(), name.clone()], HashMap::new());
let transport = StdioTransport::new(
&cmd,
vec!["mcp".to_string(), name.clone()],
HashMap::new(),
);
let handle = transport.start().await?;
let service = McpService::with_timeout(handle, Duration::from_secs(100));
Box::new(McpClient::new(service))
Expand Down
4 changes: 1 addition & 3 deletions crates/goose/src/agents/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ pub enum SystemConfig {
},
/// Built-in system that is part of the goose binary
#[serde(rename = "builtin")]
Builtin {
name: String,
},
Builtin { name: String },
}

impl SystemConfig {
Expand Down

0 comments on commit 43e74e7

Please sign in to comment.