@@ -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")
@@ -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.