pub struct BashTool {
pub working_dir: Option<PathBuf>,
pub default_timeout: Duration,
}Expand description
Executes arbitrary shell commands on behalf of the coder agent loop.
Why: Lets the LLM run test suites (pytest, cargo test, etc.), build steps,
and diagnostic commands without a separate MCP bridge. Capturing output
as a ToolResult (not a fatal error) on non-zero exit means the model
can read failing test output and iterate.
What: Wraps tokio::process::Command launched via sh -c; enforces a
configurable per-call timeout; kills the child process group (POSIX) on
expiry; truncates large outputs.
Test: bash::tests::fast_command_exit_zero, nonzero_exit_is_recoverable,
timeout_kills_child, cwd_is_honored, stdout_truncation,
registry_registration_and_dispatch.
Fields§
§working_dir: Option<PathBuf>Working directory for the spawned process. None means inherit the
tcode process’s current directory.
default_timeout: DurationDefault timeout applied when the caller does not supply timeout_secs.
Implementations§
Source§impl BashTool
impl BashTool
Sourcepub fn new(working_dir: Option<PathBuf>, default_timeout: Duration) -> Self
pub fn new(working_dir: Option<PathBuf>, default_timeout: Duration) -> Self
Construct with an optional working directory and default timeout.
Why: Callers providing a RunContext can inject working_dir so the
shell respects the project root without mutating global process state.
What: Stores working_dir and default_timeout.
Test: Constructed in all BashTool tests.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Construct with default settings (no cwd override, 120 s timeout).
Why: Convenience constructor for callers that accept process defaults.
What: Delegates to new(None, DEFAULT_TIMEOUT_SECS seconds).
Test: bash::tests::fast_command_exit_zero.
Trait Implementations§
Source§impl ToolExecutor for BashTool
impl ToolExecutor for BashTool
Source§fn schema(&self) -> Value
fn schema(&self) -> Value
OpenAI-function schema for the bash tool.
Why: The LLM function-calling loop requires a JSON schema to generate
valid calls. Declaring command as required and timeout_secs as
optional keeps the schema minimal while supporting per-call overrides.
What: Returns a { type: "function", function: { … } } Value.
Test: Checked via bash::tests::registry_registration_and_dispatch.
Source§fn restricted_tiers(&self) -> &[ServiceTier]
fn restricted_tiers(&self) -> &[ServiceTier]
Mark as RESTRICTED so ReadOnly/Analytics callers cannot invoke it.
Why: Shell execution is a privileged capability. Untrusted or
analytics-only callers must not be able to run arbitrary commands.
What: Returns [ReadOnly, Analytics] — callers in either tier are
blocked at the registry’s dispatch_for_user boundary.
Test: Covered by crate::tools::registry tier-gating tests; also
checked via bash::tests::restricted_tiers_includes_readonly_and_analytics.
Auto Trait Implementations§
impl Freeze for BashTool
impl RefUnwindSafe for BashTool
impl Send for BashTool
impl Sync for BashTool
impl Unpin for BashTool
impl UnsafeUnpin for BashTool
impl UnwindSafe for BashTool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more