Skip to content
Merged
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
14 changes: 11 additions & 3 deletions crates/goose-cli/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,20 @@ impl CliSession {
let completer = GooseCompleter::new(self.completion_cache.clone());
editor.set_helper(Some(completer));

let history_file = Paths::config_dir().join("history.txt");
let history_file = Paths::state_dir().join("history.txt");
let old_history_file = Paths::config_dir().join("history.txt");

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above seems more complicated than it should be. we already check if the history file exists. if we also check whether the old history exists we can then just load from old if new doesn't exist and delete old when new does exist

if let Some(parent) = history_file.parent() {
if !parent.exists() {
std::fs::create_dir_all(parent)?;
}
}

if history_file.exists() {
if let Err(err) = editor.load_history(&history_file) {
let history_files = [&history_file, &old_history_file];
let load_from = history_files.iter().find(|f| f.exists());

if let Some(file) = load_from {
if let Err(err) = editor.load_history(file) {
eprintln!("Warning: Failed to load command history: {}", err);
}
}
Expand All @@ -415,6 +419,10 @@ impl CliSession {
|editor: &mut rustyline::Editor<GooseCompleter, rustyline::history::DefaultHistory>| {
if let Err(err) = editor.save_history(&history_file) {
eprintln!("Warning: Failed to save command history: {}", err);
} else if old_history_file.exists() {
if let Err(err) = std::fs::remove_file(&old_history_file) {
eprintln!("Warning: Failed to remove old history file: {}", err);
}
}
};

Expand Down
Loading