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
38 changes: 26 additions & 12 deletions crates/goose-cli/src/commands/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,11 @@ pub fn build_session<'a>(
Err(_) => Box::new(RustylinePrompt::new()),
};

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(),
display_session_info(
resume,
loaded_profile.provider,
loaded_profile.model,
session_file.as_path(),
);
Box::new(Session::new(agent, prompt, session_file))
}
Expand Down Expand Up @@ -147,6 +140,27 @@ fn load_profile(profile_name: Option<String>) -> Box<Profile> {
loaded_profile
}

fn display_session_info(resume: bool, provider: String, model: String, session_file: &Path) {
let start_session_msg = if resume {
"resuming session |"
} else {
"starting session |"
};
println!(
"{} {} {} {} {}",
style(start_session_msg).dim(),
style("provider:").dim(),
style(provider).cyan().dim(),
style("model:").dim(),
style(model).cyan().dim(),
);
println!(
" {} {}",
style("logging to").dim(),
style(session_file.display()).dim().cyan(),
);
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 3 additions & 0 deletions crates/goose-cli/src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub trait Prompt {
fn show_busy(&mut self);
fn hide_busy(&self);
fn close(&self);
/// Load the user's message history into the prompt for command history navigation. First message is the oldest message.
/// When history is supported by the prompt.
fn load_user_message_history(&mut self, _messages: Vec<Message>) {}
fn goose_ready(&self) {
println!("\n");
println!("Goose is running! Enter your instructions, or try asking what goose can do.");
Expand Down
13 changes: 13 additions & 0 deletions crates/goose-cli/src/prompt/rustyline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::{
use anyhow::Result;
use cliclack::spinner;
use goose::message::Message;
use mcp_core::Role;
use rustyline::{DefaultEditor, EventHandler, KeyCode, KeyEvent, Modifiers};

const PROMPT: &str = "\x1b[1m\x1b[38;5;30m( O)> \x1b[0m";
Expand Down Expand Up @@ -136,6 +137,18 @@ impl Prompt for RustylinePrompt {
}
}

fn load_user_message_history(&mut self, messages: Vec<Message>) {
for message in messages.into_iter().filter(|m| m.role == Role::User) {
for content in message.content {
if let Some(text) = content.as_text() {
if let Err(e) = self.editor.add_history_entry(text) {
eprintln!("Failed to add to history: {}", e);
}
}
}
}
}

fn close(&self) {
// No cleanup required
}
Expand Down
8 changes: 7 additions & 1 deletion crates/goose-cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ pub struct Session<'a> {
}

impl<'a> Session<'a> {
pub fn new(agent: Box<dyn Agent>, prompt: Box<dyn Prompt + 'a>, session_file: PathBuf) -> Self {
pub fn new(
agent: Box<dyn Agent>,
mut prompt: Box<dyn Prompt + 'a>,
session_file: PathBuf,
) -> Self {
let messages = match readable_session_file(&session_file) {
Ok(file) => deserialize_messages(file).unwrap_or_else(|e| {
eprintln!(
Expand All @@ -117,6 +121,8 @@ impl<'a> Session<'a> {
}
};

prompt.load_user_message_history(messages.clone());

Session {
agent,
prompt,
Expand Down
Loading