MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / readFile

Function readFile

src/tools/executors/files.ts:14–39  ·  view source on GitHub ↗
(args: Record<string, unknown>, context: ToolContext)

Source from the content-addressed store, hash-verified

12}
13
14export 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
41export async function fileWrite(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult> {
42 const filePath = resolveWorkspacePath(context.cwd, String(args.file_path ?? ""))

Callers

nothing calls this directly

Calls 2

resolveWorkspacePathFunction · 0.85
withLineNumbersFunction · 0.85

Tested by

no test coverage detected