Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

bash tool: Rename `working_directory` to `cd` and improve command wrap (#26702)

Agus Zubiaga2edadd9352e1
diff --git a/crates/assistant_tools/src/bash_tool.rs b/crates/assistant_tools/src/bash_tool.rs
index 781a5138f23..147c5ecc239 100644
--- a/crates/assistant_tools/src/bash_tool.rs
+++ b/crates/assistant_tools/src/bash_tool.rs
@@ -11,12 +11,9 @@ use util::command::new_smol_command;
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct BashToolInput {
/// The bash command to execute as a one-liner.
- ///
- /// WARNING: you must not `cd` into the working directory, as that's already
- /// taken care of automatically. Doing so will cause the command to fail!
command: String,
/// Working directory for the command. This must be one of the root directories of the project.
- working_directory: String,
+ cd: String,
}
pub struct BashTool;
@@ -47,17 +44,14 @@ impl Tool for BashTool {
Err(err) => return Task::ready(Err(anyhow!(err))),
};
- let Some(worktree) = project
- .read(cx)
- .worktree_for_root_name(&input.working_directory, cx)
- else {
+ let Some(worktree) = project.read(cx).worktree_for_root_name(&input.cd, cx) else {
return Task::ready(Err(anyhow!("Working directory not found in the project")));
};
let working_directory = worktree.read(cx).abs_path();
cx.spawn(|_| async move {
// Add 2>&1 to merge stderr into stdout for proper interleaving.
- let command = format!("{} 2>&1", input.command);
+ let command = format!("({}) 2>&1", input.command);
let output = new_smol_command("bash")
.arg("-c")
diff --git a/crates/assistant_tools/src/bash_tool/description.md b/crates/assistant_tools/src/bash_tool/description.md
index 9cb703fe385..5a9aa00d899 100644
--- a/crates/assistant_tools/src/bash_tool/description.md
+++ b/crates/assistant_tools/src/bash_tool/description.md
@@ -1,7 +1,7 @@
Executes a bash one-liner and returns the combined output.
-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.
+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.
-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.
+Make sure you use the `cd` parameter to navigate to one of the root directories of the project. NEVER do it as part of the `command` itself, otherwise it will error.
Remember that each invocation of this tool will spawn a new bash process, so you can't rely on any state from previous invocations.