diff --git a/crates/assistant_tools/src/bash_tool.rs b/crates/assistant_tools/src/bash_tool.rs index 781a5138f231d7270c801de17927e371476435d3..147c5ecc239118bec43805dcd799b99588e5a349 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 9cb703fe3858ed19745aa4aac842d601f5e57e55..5a9aa00d899ec1aa13bd9dd288dee2450d1c1fd9 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.