Iterate on tools some more (#26663)

Antonio Scandurra created

Release Notes:

- N/A

Change summary

crates/assistant_tools/src/bash_tool/description.md |  4 ++
crates/assistant_tools/src/edit_files_tool.rs       | 20 ++++++++++++---
2 files changed, 19 insertions(+), 5 deletions(-)

Detailed changes

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.

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 =