pub struct ReadFileTool { /* private fields */ }Expand description
ToolExecutor that reads the contents of a file.
Why: Provides agents with a safe, sandboxed way to read files inside the
working directory. Construction requires an explicit working_dir so the
scoping contract is compile-time visible.
What: Implements ToolExecutor with name = "read_file". Reads the whole
file (up to MAX_FILE_BYTES) and optionally slices to a 1-based line range.
Test: cargo test -p trusty-code -- tools::fs::read.
Implementations§
Source§impl ReadFileTool
impl ReadFileTool
Sourcepub fn new(working_dir: impl Into<PathBuf>) -> Self
pub fn new(working_dir: impl Into<PathBuf>) -> Self
Construct a new ReadFileTool scoped to working_dir.
Why: The working directory is the security boundary; it must be set at
construction time so it cannot be changed per-call by the LLM.
What: Stores working_dir for use in every execute call.
Test: read_round_trips_file, et al.
Trait Implementations§
Source§impl ToolExecutor for ReadFileTool
impl ToolExecutor for ReadFileTool
Source§fn schema(&self) -> Value
fn schema(&self) -> Value
OpenAI function-call schema for read_file.
Why: The LLM uses this schema to construct its tool call. Parameters
mirror the execute argument contract exactly.
What: JSON object with path (required), start_line and end_line
(optional, 1-based integers).
Test: cargo test -p trusty-code -- tools::fs::read::tests::schema_has_required_path.
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 read_file tool call.
Why: Reads a file within the working directory, enforcing the size cap
and optional line range.
What: Parses {path, start_line?, end_line?} from args, calls
read_inner, and converts the result into a ToolResult.
Test: read_round_trips_file, read_honors_line_range, etc.
Source§fn restricted_tiers(&self) -> &[ServiceTier]
fn restricted_tiers(&self) -> &[ServiceTier]
Auto Trait Implementations§
impl Freeze for ReadFileTool
impl RefUnwindSafe for ReadFileTool
impl Send for ReadFileTool
impl Sync for ReadFileTool
impl Unpin for ReadFileTool
impl UnsafeUnpin for ReadFileTool
impl UnwindSafe for ReadFileTool
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