(filePath: string)
| 11 | * Read a file and return its contents |
| 12 | */ |
| 13 | export function readFile(filePath: string): ToolResult { |
| 14 | try { |
| 15 | if (!fs.existsSync(filePath)) { |
| 16 | return { |
| 17 | success: false, |
| 18 | output: `Error: File does not exist: ${filePath}`, |
| 19 | error: `File not found: ${filePath}`, |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | const content = fs.readFileSync(filePath, "utf-8"); |
| 24 | return { |
| 25 | success: true, |
| 26 | output: `File content:\n${content}`, |
| 27 | }; |
| 28 | } catch (error) { |
| 29 | return { |
| 30 | success: false, |
| 31 | output: `Error reading file: ${error instanceof Error ? error.message : String(error)}`, |
| 32 | error: error instanceof Error ? error.message : String(error), |
| 33 | }; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Write content to a file |
no outgoing calls
no test coverage detected