From b19eb52511b7f4b8e7fe9319f686ec920b256e39 Mon Sep 17 00:00:00 2001 From: Hare Date: Sun, 12 Apr 2026 03:44:45 +0900 Subject: [PATCH] =?UTF-8?q?history=E5=8F=96=E5=BE=97=EF=BC=9ATUI=E5=81=B4?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/tui/src/app.rs | 57 +++++++++++++++++++++++++++++++++++++++++- crates/tui/src/main.rs | 3 ++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/crates/tui/src/app.rs b/crates/tui/src/app.rs index 9e4f5264..3e7825bf 100644 --- a/crates/tui/src/app.rs +++ b/crates/tui/src/app.rs @@ -135,7 +135,9 @@ impl App { self.push_status(format!("[run end] {result:?}")); } Event::ToolCallArgsDelta { .. } => {} - Event::History { .. } => {} + Event::History { items } => { + self.restore_history(&items); + } } } @@ -216,6 +218,59 @@ impl App { lines } + fn restore_history(&mut self, items: &[serde_json::Value]) { + self.messages.clear(); + for item in items { + let item_type = item["type"].as_str().unwrap_or(""); + match item_type { + "message" => { + let role = item["role"].as_str().unwrap_or(""); + let kind = match role { + "user" => MessageKind::User, + "assistant" => MessageKind::Assistant, + _ => continue, + }; + let text = item["content"] + .as_array() + .and_then(|parts| { + parts + .iter() + .filter_map(|p| p["text"].as_str()) + .next() + }) + .unwrap_or(""); + if !text.is_empty() { + self.messages.push(Message { + kind, + content: text.to_owned(), + }); + } + } + "tool_call" => { + let name = item["name"].as_str().unwrap_or("?"); + self.messages.push(Message { + kind: MessageKind::Tool, + content: format!("[tool] {name}"), + }); + } + "tool_result" => { + let output = item["output"].as_str().unwrap_or(""); + let display = if output.len() > 200 { + format!("{}...", &output[..200]) + } else { + output.to_owned() + }; + self.messages.push(Message { + kind: MessageKind::Tool, + content: format!("[tool result] {display}"), + }); + } + _ => {} + } + } + self.scroll_to_bottom(); + } + fn push_status(&mut self, content: String) { self.messages.push(Message { kind: MessageKind::Status, diff --git a/crates/tui/src/main.rs b/crates/tui/src/main.rs index 47a57309..31313930 100644 --- a/crates/tui/src/main.rs +++ b/crates/tui/src/main.rs @@ -73,8 +73,9 @@ async fn main() -> Result<(), Box> { // Connect to pod match PodClient::connect(&socket_path).await { - Ok(client) => { + Ok(mut client) => { app.connected = true; + let _ = client.send(&Method::GetHistory).await; run_loop(&mut terminal, &mut app, client).await?; } Err(e) => {