(args: Record<string, unknown>, context: ToolContext)
| 12 | } |
| 13 | |
| 14 | export async function readFile(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult> { |
| 15 | const filePath = resolveWorkspacePath(context.cwd, String(args.file_path ?? "")) |
| 16 | const offset = Math.max(1, Number(args.offset ?? 1) || 1) |
| 17 | const limitArg = args.limit === null || args.limit === undefined ? MAX_READ_LINES : Number(args.limit) |
| 18 | const limit = Math.min(Math.max(1, limitArg || MAX_READ_LINES), MAX_READ_LINES) |
| 19 | |
| 20 | let content: string |
| 21 | try { |
| 22 | content = fs.readFileSync(filePath, "utf8") |
| 23 | } catch (error) { |
| 24 | return { text: `Error reading file ${filePath}: ${(error as Error).message}`, isError: true } |
| 25 | } |
| 26 | |
| 27 | const allLines = content.split("\n") |
| 28 | const slice = allLines.slice(offset - 1, offset - 1 + limit) |
| 29 | if (slice.length === 0) { |
| 30 | return { text: `File ${filePath} has ${allLines.length} lines; offset ${offset} is beyond the end.`, isError: true } |
| 31 | } |
| 32 | |
| 33 | let result = withLineNumbers(slice, offset) |
| 34 | const lastLineShown = offset - 1 + slice.length |
| 35 | if (lastLineShown < allLines.length) { |
| 36 | result += `\n\n(Showing lines ${offset}-${lastLineShown} of ${allLines.length}. Use offset/limit to read more.)` |
| 37 | } |
| 38 | return { text: result } |
| 39 | } |
| 40 | |
| 41 | export async function fileWrite(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult> { |
| 42 | const filePath = resolveWorkspacePath(context.cwd, String(args.file_path ?? "")) |
nothing calls this directly
no test coverage detected