Skip to content

Commit 6b3de5c

Browse files
committed
persist command history
1 parent 2aba7f2 commit 6b3de5c

4 files changed

Lines changed: 108 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 84 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dirs = "5"
1616
dotenvy = "0.15"
1717
glob = "0.3"
1818
regex = "1"
19-
rustyline = "14"
19+
rustyline = { version = "17", features = ["with-file-history"] }
2020
serde = { version = "1", features = ["derive"] }
2121
serde_json = "1"
2222
serde_yaml = { package = "serde_yml", version = "0.0.12" }

src/agent.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ fn verbose(ctx: &Context, message: &str) {
4747
}
4848
}
4949

50-
pub fn run_turn(ctx: &Context, user_input: &str, messages: &mut Vec<Value>) -> Result<CommandStats> {
50+
pub fn run_turn(
51+
ctx: &Context,
52+
user_input: &str,
53+
messages: &mut Vec<Value>,
54+
) -> Result<CommandStats> {
5155
let mut stats = CommandStats::default();
5256
let _ = ctx.transcript.borrow_mut().user_message(user_input);
5357

src/cli.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ use std::cell::RefCell;
1818
use std::path::PathBuf;
1919
use std::time::{Duration, Instant};
2020

21+
/// Get the path to the history file
22+
fn history_path() -> PathBuf {
23+
dirs::home_dir()
24+
.unwrap_or_else(|| PathBuf::from("."))
25+
.join(".yo")
26+
.join("history")
27+
}
28+
2129
pub struct Context {
2230
pub args: Args,
2331
pub root: PathBuf,
@@ -62,6 +70,10 @@ pub fn run_repl(ctx: Context) -> Result<()> {
6270
let mut rl = DefaultEditor::new()?;
6371
let mut messages = Vec::new();
6472

73+
// Load command history
74+
let history_file = history_path();
75+
let _ = rl.load_history(&history_file);
76+
6577
println!("yo - type /help for commands, /exit to quit");
6678

6779
loop {
@@ -98,6 +110,12 @@ pub fn run_repl(ctx: Context) -> Result<()> {
98110
}
99111
}
100112

113+
// Save command history (create parent directory if needed)
114+
if let Some(parent) = history_file.parent() {
115+
let _ = std::fs::create_dir_all(parent);
116+
}
117+
let _ = rl.save_history(&history_file);
118+
101119
Ok(())
102120
}
103121

0 commit comments

Comments
 (0)