MCPcopy Index your code
hub / github.com/dagger/dagger / ReadFile

Method ReadFile

modules/doug/main.go:111–157  ·  view source on GitHub ↗

* Reads a file from the project directory. HOW TO USE THIS TOOL: - Always use relative paths from the workspace root - Reads the first 2000 lines by default - Each line is prefixed with a line number followed by an arrow (→). Everything that follows the arrow is the literal content of the

(
	ctx context.Context,
	// Relative path within the workspace
	filePath string,
	// Line offset to start reading from
	offset *int,
	// Limit the number of lines read
	limit *int,
)

Source from the content-addressed store, hash-verified

109 - If multiple files are interesting, you can read them all at once using multiple tool calls.
110*/
111func (d *Doug) ReadFile(
112 ctx context.Context,
113 // Relative path within the workspace
114 filePath string,
115 // Line offset to start reading from
116 offset *int,
117 // Limit the number of lines read
118 limit *int,
119) (string, error) {
120 filePath = d.normalizePath(filePath)
121
122 if limit == nil {
123 defaultLimit := 2000
124 limit = &defaultLimit
125 }
126
127 opts := dagger.FileContentsOpts{
128 LimitLines: *limit,
129 }
130 if offset != nil {
131 opts.OffsetLines = *offset
132 }
133
134 contents, err := d.Source.File(filePath).Contents(ctx, opts)
135 if err != nil {
136 return "", err
137 }
138
139 if contents == "" {
140 return "WARNING: File contents are empty.", nil
141 }
142
143 lines := strings.Split(contents, "\n")
144 var numberedLines []string
145
146 startLine := 1
147 if offset != nil {
148 startLine = *offset + 1
149 }
150
151 for i, line := range lines {
152 lineNo := startLine + i
153 numberedLines = append(numberedLines, fmt.Sprintf("%6d→%s", lineNo, line))
154 }
155
156 return strings.Join(numberedLines, "\n"), nil
157}
158
159/*
160Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the BasicShell tool with the 'mv' command instead. For larger file edits, use the Write tool to overwrite files.

Callers

nothing calls this directly

Calls 3

normalizePathMethod · 0.95
FileMethod · 0.65
ContentsMethod · 0.45

Tested by

no test coverage detected