MCPcopy Index your code
hub / github.com/coder/coder / executeReadFileTool

Function executeReadFileTool

coderd/x/chatd/chattool/readfile.go:41–74  ·  view source on GitHub ↗
(
	ctx context.Context,
	conn workspacesdk.AgentConn,
	args ReadFileArgs,
)

Source from the content-addressed store, hash-verified

39}
40
41func executeReadFileTool(
42 ctx context.Context,
43 conn workspacesdk.AgentConn,
44 args ReadFileArgs,
45) (fantasy.ToolResponse, error) {
46 if args.Path == "" {
47 return fantasy.NewTextErrorResponse("path is required"), nil
48 }
49
50 offset := int64(1) // 1-based line number default
51 limit := int64(0) // 0 means use server default (2000)
52 if args.Offset != nil {
53 offset = *args.Offset
54 }
55 if args.Limit != nil {
56 limit = *args.Limit
57 }
58
59 resp, err := conn.ReadFileLines(ctx, args.Path, offset, limit, workspacesdk.DefaultReadFileLinesLimits())
60 if err != nil {
61 return fantasy.NewTextErrorResponse(err.Error()), nil
62 }
63
64 if !resp.Success {
65 return fantasy.NewTextErrorResponse(resp.Error), nil
66 }
67
68 return toolResponse(map[string]any{
69 "content": resp.Content,
70 "file_size": resp.FileSize,
71 "total_lines": resp.TotalLines,
72 "lines_read": resp.LinesRead,
73 }), nil
74}

Callers 1

ReadFileFunction · 0.85

Calls 4

toolResponseFunction · 0.85
ReadFileLinesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected