From e80df25386a3af2ee736d270c10ed10ee8e002bf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 13 Mar 2025 13:42:02 +0100 Subject: [PATCH] Iterate on tools some more (#26663) Release Notes: - N/A --- .../src/bash_tool/description.md | 4 +++- crates/assistant_tools/src/edit_files_tool.rs | 20 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/assistant_tools/src/bash_tool/description.md b/crates/assistant_tools/src/bash_tool/description.md index 666a7c28c0390d0401d05701b67236c65df74709..9cb703fe3858ed19745aa4aac842d601f5e57e55 100644 --- a/crates/assistant_tools/src/bash_tool/description.md +++ b/crates/assistant_tools/src/bash_tool/description.md @@ -1,5 +1,7 @@ Executes a bash one-liner and returns the combined output. -This tool spawns a bash process, combines stdout and stderr into one interleaved stream as they are produced (preserving the order of writes), and captures that stream into a string which is returned. +This tool spawns a bash process IN THE SPECIFIED WORKING DIRECTORY, combines stdout and stderr into one interleaved stream as they are produced (preserving the order of writes), and captures that stream into a string which is returned. + +WARNING: **NEVER** use 'cd' commands to navigate to the working directory - this is automatically handled by the 'working_directory' parameter. Only use 'cd' to navigate to subdirectories within the specified working directory. Remember that each invocation of this tool will spawn a new bash process, so you can't rely on any state from previous invocations. diff --git a/crates/assistant_tools/src/edit_files_tool.rs b/crates/assistant_tools/src/edit_files_tool.rs index ed222c00baa2816ccc5aaa076d3046613b482afd..2cb3f06f82f0559a9484200342910c188dd9efc0 100644 --- a/crates/assistant_tools/src/edit_files_tool.rs +++ b/crates/assistant_tools/src/edit_files_tool.rs @@ -204,15 +204,27 @@ impl EditFilesTool { let diff = buffer .read_with(&cx, |buffer, cx| { let new_text = match action { - EditAction::Replace { old, new, .. } => { + EditAction::Replace { + file_path, + old, + new, + } => { // TODO: Replace in background? - buffer.text().replace(&old, &new) + let text = buffer.text(); + if text.contains(&old) { + text.replace(&old, &new) + } else { + return Err(anyhow!( + "Could not find search text in {}", + file_path.display() + )); + } } EditAction::Write { content, .. } => content, }; - buffer.diff(new_text, cx) - })? + anyhow::Ok(buffer.diff(new_text, cx)) + })?? .await; let _clock =