Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(cli): persist accepted history for resumed agent runs
thinhlpg5005527101cc
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rsindex 3aef91d28..209191360 100644--- a/src-tauri/src/core/cli/mod.rs+++ b/src-tauri/src/core/cli/mod.rs@@ -1834,8 +1834,16 @@ async fn run_agent_loop(// reads, so the JSON envelope can never disagree with the text output.let printer = tokio::spawn(async move {let mut report = RunReport::default();+ let mut updated_history = None;while let Some(ev) = rx.recv().await {report.observe(&ev);+ if format.is_stream_json() {+ print_json_line(&ev);+ }+ if let StreamEvent::MessagesUpdated { messages } = ev {+ updated_history = Some(messages);+ continue;+ }// Asked per event, not once per run: the client owns the decision// only while it is still reading. Once stdin has closed, the CLI// takes its own path back, which on a pipe is an auto-deny.@@ -1846,7 +1854,6 @@ async fn run_agent_loop(resolve_permission_silently(ev, &permission_requests, duplex).await;}OutputFormat::StreamJson => {- print_json_line(&ev);if let Some((request_id, decision)) =resolve_permission_silently(ev, &permission_requests, duplex).await{@@ -1855,7 +1862,7 @@ async fn run_agent_loop(}}}- report+ (report, updated_history)});// `None` when the client aborted: the run produced no completion, but a@@ -1871,7 +1878,7 @@ async fn run_agent_loop(let aborted = outcome.is_none();let result = outcome.unwrap_or_else(|| Err(ABORTED_BY_CLIENT.to_string()));drop(tx);- let report = printer.await.unwrap_or_default();+ let (report, updated_history) = printer.await.unwrap_or_default();if let Some(input) = input.as_ref() {report_dropped_follow_ups(input, format);}@@ -1884,6 +1891,9 @@ async fn run_agent_loop(mut history,workspace,} = persist;+ if let Some(messages) = updated_history {+ history = messages;+ }let mut session_id = thread_id.clone();let mut final_text = None;if let Ok(completion) = result.as_ref() {@@ -2336,11 +2346,9 @@ async fn print_event(ev: StreamEvent, registry: &PermissionRegistry, duplex: boo}// Headless never renders an ask prompt, so there is nothing to dismiss.StreamEvent::AskResolved { .. } => {}- // The non-interactive CLI doesn't persist session state; a todo update- // is silently dropped here (mirrors MessagesUpdated below).+ // Headless runs do not persist the interactive todo registry.StreamEvent::TodoUpdate { .. } => {}- // The non-interactive CLI doesn't persist session state, so- // MessagesUpdated is a no-op here.+ // The event collector adopts this history before it reaches the printer.StreamEvent::MessagesUpdated { .. } => {}StreamEvent::PermissionRequest {request_id,