Skip to main content

steer_tools/tools/
read_file.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::{ToolExecutionError, WorkspaceOpError};
7use crate::result::FileContentResult;
8
9pub const READ_FILE_TOOL_NAME: &str = "read_file";
10
11pub struct ReadFileToolSpec;
12
13impl ToolSpec for ReadFileToolSpec {
14    type Params = ReadFileParams;
15    type Result = FileContentResult;
16    type Error = ReadFileError;
17
18    const NAME: &'static str = READ_FILE_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "Read File";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::ReadFile(error)
23    }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
27#[serde(tag = "code", content = "details", rename_all = "snake_case")]
28pub enum ReadFileError {
29    #[error("{0}")]
30    Workspace(WorkspaceOpError),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
34pub struct ReadFileParams {
35    /// The absolute path to the file to read
36    pub file_path: String,
37    /// The line number to start reading from (1-indexed)
38    pub offset: Option<u64>,
39    /// The maximum number of lines to read
40    pub limit: Option<u64>,
41    /// Return raw file bytes rendered as text without numbering/trimming/truncation
42    pub raw: Option<bool>,
43}