aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 91d54da..45ca8c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -195,6 +195,7 @@ fn run(args: Args) {
195 } 195 }
196 }; 196 };
197 197
198 let resuming = args.session.is_some() || args.continue_last;
198 let (mut session, mut history) = match open_session(&cfg, args.session, args.continue_last) { 199 let (mut session, mut history) = match open_session(&cfg, args.session, args.continue_last) {
199 Ok(pair) => pair, 200 Ok(pair) => pair,
200 Err(message) => { 201 Err(message) => {
@@ -205,6 +206,9 @@ fn run(args: Args) {
205 cfg.session = session.id.clone(); 206 cfg.session = session.id.clone();
206 207
207 warn_if_moved(&session); 208 warn_if_moved(&session);
209 if resuming {
210 print_last_reply(&session.id);
211 }
208 if !session.version.is_empty() && session.version != env!("CARGO_PKG_VERSION") { 212 if !session.version.is_empty() && session.version != env!("CARGO_PKG_VERSION") {
209 eprintln!( 213 eprintln!(
210 "agent686: this session was written by {}; the prompt and tool schemas may \ 214 "agent686: this session was written by {}; the prompt and tool schemas may \
@@ -647,3 +651,42 @@ fn render_message(message: &Value, color: bool) -> String {
647 other => format!("[{other}]\n"), 651 other => format!("[{other}]\n"),
648 } 652 }
649} 653}
654
655/// On resume, show where the conversation left off: the last answer, or the last
656/// reasoning when the model never produced content. Only on a terminal, so piped
657/// runs stay clean.
658fn print_last_reply(id: &str) {
659 if !std::io::stdout().is_terminal() {
660 return;
661 }
662 let Some(reply) = session::last_reply(id) else {
663 return;
664 };
665 let text = if reply.content.trim().is_empty() {
666 reply.reasoning.trim()
667 } else {
668 reply.content.trim()
669 };
670 if text.is_empty() {
671 return;
672 }
673
674 let lines: Vec<&str> = text.lines().collect();
675 let limit = 20;
676 println!();
677 println!("{}", style("2", "── where you left off ──", true));
678 for line in lines.iter().take(limit) {
679 println!("{line}");
680 }
681 if lines.len() > limit {
682 println!(
683 "{}",
684 style(
685 "2",
686 &format!("… {} more line(s); `agent686 --show` for the transcript", lines.len() - limit),
687 true
688 )
689 );
690 }
691 println!();
692}