MCPcopy Create free account
hub / github.com/codehamr/codehamr / ReadFile

Function ReadFile

internal/tools/read.go:14–30  ·  view source on GitHub ↗

ReadFile returns path's contents, truncated to the shared tool-output budget (Truncate). The model gets exact bytes, not a shell-mangled approximation. Per the bash/write/edit convention, filesystem errors come back in the output string, never as a Go error: the model reacts to them like a non-zero

(path string)

Source from the content-addressed store, hash-verified

12// re-fire on the window and drop its middle, silently reinstating the
13// unrecoverable dead end that offset/limit exists to remove.
14const readChunkBytes = 20000
15
16// maxFileBytes gates read_file and edit_file: both slurp the whole file with
17// os.ReadFile, so a multi-GB log would OOM-kill the TUI - the same hazard
18// bash's headTailBuffer capture cap exists to stop, unguarded in the file
19// tools. 5MB covers every real source file; anything bigger is a log or an
20// artifact, which grep/sed handle without loading it.
21const maxFileBytes = 5 << 20
22
23// ReadFile returns a window of path's contents: whole lines from offset
24// (1-indexed, 0 meaning the start) up to limit lines, bounded by
25// readChunkBytes. When the window stops short, the result names the exact
26// offset to continue from, so a big file is read by repeated calls instead of
27// guessed at from a truncated middle.
28//
29// Per the bash/write/edit convention, filesystem errors come back in the
30// output string, never as a Go error: the model reacts to them like a non-zero
31// exit.
32func ReadFile(path string, offset, limit int) string {
33 if path == "" {

Callers 6

TestReadFileHappyFunction · 0.85
TestReadFileEmptyPathFunction · 0.85
TestReadFileMissingFileFunction · 0.85
runRawFunction · 0.85

Calls

no outgoing calls

Tested by 5

TestReadFileHappyFunction · 0.68
TestReadFileEmptyPathFunction · 0.68
TestReadFileMissingFileFunction · 0.68