load all previous messages if --resume is passed (#2424)

This commit is contained in:
Raduan Al-Shedivat
2025-05-08 01:42:52 +02:00
committed by GitHub
parent 72f966e4fc
commit a8d4bd0415
2 changed files with 40 additions and 0 deletions

View File

@@ -203,6 +203,14 @@ enum Command {
)]
resume: bool,
/// Show message history when resuming
#[arg(
long,
help = "Show previous messages when resuming a session",
requires = "resume"
)]
history: bool,
/// Enable debug output mode
#[arg(
long,
@@ -413,6 +421,7 @@ pub async fn cli() -> Result<()> {
command,
identifier,
resume,
history,
debug,
extensions,
remote_extensions,
@@ -448,6 +457,12 @@ pub async fn cli() -> Result<()> {
session.session_file().file_stem().and_then(|s| s.to_str()),
None,
)?;
// Render previous messages if resuming a session and history flag is set
if resume && history {
session.render_message_history();
}
let _ = session.interactive(None).await;
Ok(())
}

View File

@@ -899,6 +899,31 @@ impl Session {
self.messages.clone()
}
/// Render all past messages from the session history
pub fn render_message_history(&self) {
if self.messages.is_empty() {
return;
}
// Print session restored message
println!(
"\n{} {} messages loaded into context.",
console::style("Session restored:").green().bold(),
console::style(self.messages.len()).green()
);
// Render each message
for message in &self.messages {
output::render_message(message, self.debug);
}
// Add a visual separator after restored messages
println!(
"\n{}\n",
console::style("──────── New Messages ────────").dim()
);
}
/// Get the session metadata
pub fn get_metadata(&self) -> Result<session::SessionMetadata> {
if !self.session_file.exists() {