From 3173f87dc3f49c104e64c6ab5e152ecc77ce104e Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Mon, 12 May 2025 17:11:40 +0200 Subject: [PATCH] agent: Restore find path tool card after restart (#30580) Release Notes: - N/A --- crates/assistant_tools/src/find_path_tool.rs | 39 +++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/assistant_tools/src/find_path_tool.rs b/crates/assistant_tools/src/find_path_tool.rs index c52d290d2b..2004508a47 100644 --- a/crates/assistant_tools/src/find_path_tool.rs +++ b/crates/assistant_tools/src/find_path_tool.rs @@ -1,6 +1,6 @@ use crate::{schema::json_schema_for, ui::ToolCallCardHeader}; use anyhow::{Result, anyhow}; -use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolUseStatus}; +use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolResultOutput, ToolUseStatus}; use editor::Editor; use futures::channel::oneshot::{self, Receiver}; use gpui::{ @@ -38,6 +38,12 @@ pub struct FindPathToolInput { pub offset: usize, } +#[derive(Debug, Serialize, Deserialize)] +struct FindPathToolOutput { + glob: String, + paths: Vec, +} + const RESULTS_PER_PAGE: usize = 50; pub struct FindPathTool; @@ -111,10 +117,18 @@ impl Tool for FindPathTool { ) .unwrap(); } + let output = FindPathToolOutput { + glob, + paths: matches.clone(), + }; + for mat in matches.into_iter().skip(offset).take(RESULTS_PER_PAGE) { write!(&mut message, "\n{}", mat.display()).unwrap(); } - Ok(message.into()) + Ok(ToolResultOutput { + content: message, + output: Some(serde_json::to_value(output)?), + }) } }); @@ -123,6 +137,18 @@ impl Tool for FindPathTool { card: Some(card.into()), } } + + fn deserialize_card( + self: Arc, + output: serde_json::Value, + _project: Entity, + _window: &mut Window, + cx: &mut App, + ) -> Option { + let output = serde_json::from_value::(output).ok()?; + let card = cx.new(|_| FindPathToolCard::from_output(output)); + Some(card.into()) + } } fn search_paths(glob: &str, project: Entity, cx: &mut App) -> Task>> { @@ -180,6 +206,15 @@ impl FindPathToolCard { _receiver_task: Some(_receiver_task), } } + + fn from_output(output: FindPathToolOutput) -> Self { + Self { + glob: output.glob, + paths: output.paths, + expanded: false, + _receiver_task: None, + } + } } impl ToolCard for FindPathToolCard {