pub struct WriteFileTool { /* private fields */ }Expand description
ToolExecutor that creates or overwrites a file.
Why: Provides agents with a safe, sandboxed way to write files inside the
working directory. Parent directories are created automatically so agents do
not need a separate mkdir step.
What: Implements ToolExecutor with name = "write_file". Scopes all writes
to working_dir; rejects traversal attempts.
Test: cargo test -p trusty-code -- tools::fs::write.
Implementations§
Source§impl WriteFileTool
impl WriteFileTool
Sourcepub fn new(working_dir: impl Into<PathBuf>) -> Self
pub fn new(working_dir: impl Into<PathBuf>) -> Self
Construct a new WriteFileTool scoped to working_dir.
Why: The working directory is the security boundary; it must be set at
construction time and cannot be overridden per-call by the LLM.
What: Stores working_dir.
Test: write_creates_new_file, et al.
Trait Implementations§
Source§impl ToolExecutor for WriteFileTool
impl ToolExecutor for WriteFileTool
Source§fn schema(&self) -> Value
fn schema(&self) -> Value
OpenAI function-call schema for write_file.
Why: The LLM uses this schema to construct its tool call.
What: JSON object with path and content (both required).
Test: schema_has_required_fields.
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute a write_file tool call.
Why: Writes content to a file within the working directory.
What: Parses {path, content} from args, calls write_inner, and
converts the result into a ToolResult.
Test: write_creates_new_file, write_creates_parent_dirs, etc.
Source§fn restricted_tiers(&self) -> &[ServiceTier]
fn restricted_tiers(&self) -> &[ServiceTier]
Auto Trait Implementations§
impl Freeze for WriteFileTool
impl RefUnwindSafe for WriteFileTool
impl Send for WriteFileTool
impl Sync for WriteFileTool
impl Unpin for WriteFileTool
impl UnsafeUnpin for WriteFileTool
impl UnwindSafe for WriteFileTool
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