From 4fa9c2ad3d41092e5f56f31daefecebb0aeddcf0 Mon Sep 17 00:00:00 2001 From: Bradley Axen Date: Wed, 27 Nov 2024 15:52:26 -0800 Subject: [PATCH] feat: simplify initial session splash (#362) --- crates/goose-cli/src/agents/mock_agent.rs | 2 +- crates/goose-cli/src/commands/session.rs | 29 +++++++------ crates/goose-cli/src/prompt.rs | 19 ++------- crates/goose-cli/src/prompt/thinking.rs | 52 ----------------------- crates/goose-cli/src/session.rs | 7 +-- crates/goose-server/src/routes/reply.rs | 5 +-- crates/goose/src/memory.rs | 10 +++-- crates/goose/src/providers/oauth.rs | 2 +- 8 files changed, 30 insertions(+), 96 deletions(-) diff --git a/crates/goose-cli/src/agents/mock_agent.rs b/crates/goose-cli/src/agents/mock_agent.rs index 4ddcece289..bb7e1b0919 100644 --- a/crates/goose-cli/src/agents/mock_agent.rs +++ b/crates/goose-cli/src/agents/mock_agent.rs @@ -10,7 +10,7 @@ pub struct MockAgent; #[async_trait] impl Agent for MockAgent { fn add_system(&mut self, _system: Box) { - () + } async fn reply(&self, _messages: &[Message]) -> Result>> { diff --git a/crates/goose-cli/src/commands/session.rs b/crates/goose-cli/src/commands/session.rs index e89fb5ac1c..2f2ee2cb32 100644 --- a/crates/goose-cli/src/commands/session.rs +++ b/crates/goose-cli/src/commands/session.rs @@ -1,8 +1,8 @@ +use console::style; use rand::{distributions::Alphanumeric, Rng}; use std::path::{Path, PathBuf}; use goose::agent::Agent; -use goose::models::message::Message; use goose::providers::factory; use crate::commands::expected_config::get_recommended_models; @@ -11,7 +11,6 @@ use crate::profile::{ }; use crate::prompt::cliclack::CliclackPrompt; use crate::prompt::rustyline::RustylinePrompt; -use crate::prompt::thinking::get_random_goose_action; use crate::prompt::Prompt; use crate::session::{ensure_session_dir, Session}; @@ -48,7 +47,7 @@ pub fn build_session<'a>( // TODO: Odd to be prepping the provider rather than having that done in the agent? let provider = factory::get_provider(provider_config).unwrap(); let agent = Box::new(Agent::new(provider)); - let mut prompt = match std::env::var("GOOSE_INPUT") { + let prompt = match std::env::var("GOOSE_INPUT") { Ok(val) => match val.as_str() { "cliclack" => Box::new(CliclackPrompt::new()) as Box, "rustyline" => Box::new(RustylinePrompt::new()) as Box, @@ -57,17 +56,19 @@ pub fn build_session<'a>( Err(_) => Box::new(RustylinePrompt::new()), }; - prompt.render(Box::new(Message::assistant().with_text(format!( - r#"{}... - Provider: {} - Model: {} - Session file: {}"#, - get_random_goose_action(), - loaded_profile.provider, - loaded_profile.model, - session_file.display() - )))); - + println!( + "{} {} {} {} {}", + style("starting session |").dim(), + style("provider:").dim(), + style(loaded_profile.provider).cyan().dim(), + style("model:").dim(), + style(loaded_profile.model).cyan().dim(), + ); + println!( + " {} {}", + style("logging to").dim(), + style(session_file.display()).dim().cyan(), + ); Box::new(Session::new(agent, prompt, session_file)) } diff --git a/crates/goose-cli/src/prompt.rs b/crates/goose-cli/src/prompt.rs index 4ab52eb626..b564acc09c 100644 --- a/crates/goose-cli/src/prompt.rs +++ b/crates/goose-cli/src/prompt.rs @@ -12,22 +12,9 @@ pub trait Prompt { fn hide_busy(&self); fn close(&self); fn goose_ready(&self) { - self.draw_goose(); - } - - fn draw_goose(&self) { - println!( - r#" __ - - - - - ( 0)> < honk! > - || - - - - - || - __||_ - <=/ \=> - \_____/ - | | - ^ ^ - "# - ); + println!("\n"); + println!("Goose is running! Enter your instructions, or try asking what goose can do."); + println!("\n"); } } diff --git a/crates/goose-cli/src/prompt/thinking.rs b/crates/goose-cli/src/prompt/thinking.rs index 51d4154099..cc187522e6 100644 --- a/crates/goose-cli/src/prompt/thinking.rs +++ b/crates/goose-cli/src/prompt/thinking.rs @@ -1,50 +1,5 @@ use rand::seq::SliceRandom; -/// List of goose-specific actions for noting goose readiness. -pub const GOOSE_ACTIONS: &[&str] = &[ - "Spreading wings", - "Honking thoughtfully", - "Waddling to conclusions", - "Flapping wings excitedly", - "Preening code feathers", - "Gathering digital breadcrumbs", - "Paddling through data", - "Migrating thoughts", - "Nesting ideas", - "Squawking calculations", - "Ruffling algorithmic feathers", - "Pecking at problems", - "Stretching webbed feet", - "Foraging for solutions", - "Grooming syntax", - "Building digital nest", - "Patrolling the codebase", - "Gosling about", - "Strutting with purpose", - "Diving for answers", - "Herding bytes", - "Molting old code", - "Swimming through streams", - "Goose-stepping through logic", - "Synchronizing flock algorithms", - "Navigating code marshes", - "Incubating brilliant ideas", - "Arranging feathers recursively", - "Gliding through branches", - "Migrating to better solutions", - "Nesting functions carefully", - "Hatching clever solutions", - "Preening parse trees", - "Flying through functions", - "Gathering syntax seeds", - "Webbing connections", - "Flocking to optimizations", - "Paddling through protocols", - "Honking success signals", - "Waddling through workflows", - "Nesting in neural networks", -]; - /// Extended list of playful thinking messages including both goose and general AI actions pub const THINKING_MESSAGES: &[&str] = &[ "Thinking", @@ -268,10 +223,3 @@ pub fn get_random_thinking_message() -> &'static str { .choose(&mut rand::thread_rng()) .unwrap_or(&THINKING_MESSAGES[0]) } - -/// Returns a random goose-specific action -pub fn get_random_goose_action() -> &'static str { - GOOSE_ACTIONS - .choose(&mut rand::thread_rng()) - .unwrap_or(&GOOSE_ACTIONS[0]) -} diff --git a/crates/goose-cli/src/session.rs b/crates/goose-cli/src/session.rs index 29ba6f8ff6..6f0ec450e1 100644 --- a/crates/goose-cli/src/session.rs +++ b/crates/goose-cli/src/session.rs @@ -99,6 +99,7 @@ impl<'a> Session<'a> { pub async fn start(&mut self) -> Result<(), Box> { self.setup_session(); + self.prompt.goose_ready(); loop { let input = self.prompt.get_input().unwrap(); @@ -202,14 +203,8 @@ impl<'a> Session<'a> { fn setup_session(&mut self) { let system = Box::new(DeveloperSystem::new()); self.agent.add_system(system); - self.prompt - .render(raw_message("Connected developer system.")); let goosehints_system = Box::new(GooseHintsSystem::new()); self.agent.add_system(goosehints_system); - self.prompt - .render(raw_message("Connected .goosehints system.")); - - self.prompt.goose_ready(); } fn close_session(&mut self) { diff --git a/crates/goose-server/src/routes/reply.rs b/crates/goose-server/src/routes/reply.rs index 36f8f55dd9..d9b3aa3e68 100644 --- a/crates/goose-server/src/routes/reply.rs +++ b/crates/goose-server/src/routes/reply.rs @@ -139,7 +139,6 @@ fn convert_messages(incoming: Vec) -> Vec { struct ProtocolFormatter; impl ProtocolFormatter { - fn format_text(text: &str) -> String { let encoded_text = serde_json::to_string(text).unwrap_or_else(|_| String::new()); format!("0:{}\n", encoded_text) @@ -236,8 +235,8 @@ async fn stream_message( MessageContent::Text(text) => { for line in text.text.lines() { let modified_line = format!("{}\n", line); - tx.send(ProtocolFormatter::format_text(&modified_line)).await?; - + tx.send(ProtocolFormatter::format_text(&modified_line)) + .await?; } } MessageContent::Image(_) => { diff --git a/crates/goose/src/memory.rs b/crates/goose/src/memory.rs index 511c7c3ed8..e522809f4f 100644 --- a/crates/goose/src/memory.rs +++ b/crates/goose/src/memory.rs @@ -111,7 +111,6 @@ impl MemoryManager { if let Some(first_line) = lines.next() { if first_line.starts_with('#') { let tags = first_line[1..] - .trim() .split_whitespace() .map(String::from) .collect::>(); @@ -236,8 +235,7 @@ pub fn execute_tool_call(tool_call: ToolCall) -> Result { .map(|v| v.as_str().unwrap()) .collect(); let is_global = tool_call.arguments["is_global"].as_bool().unwrap(); - let _result = - MemoryManager::new()?.remember("context", category, data, &tags, is_global)?; + MemoryManager::new()?.remember("context", category, data, &tags, is_global)?; Ok(format!("Stored memory in category: {}", category)) } "retrieve_memories" => { @@ -274,6 +272,12 @@ pub struct MemorySystem { instructions: String, } +impl Default for MemorySystem { + fn default() -> Self { + Self::new() + } +} + impl MemorySystem { pub fn new() -> Self { let memory_manager = MemoryManager::new().expect("Failed to create MemoryManager"); diff --git a/crates/goose/src/providers/oauth.rs b/crates/goose/src/providers/oauth.rs index 6cedd6df23..0d6e5104cf 100644 --- a/crates/goose/src/providers/oauth.rs +++ b/crates/goose/src/providers/oauth.rs @@ -40,7 +40,7 @@ impl TokenCache { let hash = format!("{:x}", hasher.finalize()); fs::create_dir_all(get_base_path()).unwrap(); - let cache_path = PathBuf::from(get_base_path()).join(format!("{}.json", hash)); + let cache_path = get_base_path().join(format!("{}.json", hash)); Self { cache_path } }