Skip to main content

Module read

Module read 

Source
Expand description

read_file tool — read file contents, optionally limited to a line range.

Why: AI agents need to inspect existing files before editing them. A structured ToolExecutor with explicit size and line-range parameters is safer than passing raw cat arguments to a shell tool. What: ReadFileTool reads up to MAX_FILE_BYTES (1 MiB) from the path, optionally slicing to [start_line, end_line] (1-based, inclusive). All paths are scoped to the provided working directory; traversal attempts are rejected. Test: See #[cfg(test)] below — covers round-trip, line range, size cap, missing file, and path traversal.

Structs§

ReadFileTool
ToolExecutor that reads the contents of a file.

Constants§

MAX_FILE_BYTES
Maximum file size allowed by ReadFileTool (1 MiB).