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

Function ReadFileSchema

internal/tools/read.go:35–53  ·  view source on GitHub ↗

ReadFileSchema is the OpenAI tool definition for read_file. The description nudges the model toward read_file over `cat` so it stops piping source through the shell just to look at it.

()

Source from the content-addressed store, hash-verified

33 if path == "" {
34 return "(empty path)"
35 }
36 // Refuse non-regular files up front: open(2) on a FIFO blocks forever
37 // waiting for a writer (leaking the tool goroutine past Ctrl+C, which
38 // cancels the turn but can't unblock the read), and an endless device file
39 // (/dev/zero) grows ReadFile's buffer without bound. Stat never blocks.
40 // The same Stat size-gates the whole-file read below (see maxFileBytes).
41 if info, err := os.Stat(path); err == nil {
42 if !info.Mode().IsRegular() && !info.IsDir() {
43 return fmt.Sprintf("(read error: %s is not a regular file)", path)
44 }
45 if info.Mode().IsRegular() && info.Size() > maxFileBytes {
46 return fmt.Sprintf("(too large: %s is %d bytes, over read_file's %dMB cap - read slices with bash instead: grep -n pattern, or sed -n '1,200p')", path, info.Size(), maxFileBytes>>20)
47 }
48 }
49 raw, err := os.ReadFile(path)
50 if err != nil {
51 return fmt.Sprintf("(read error: %v)", err)
52 }
53 lines := strings.Split(string(raw), "\n")
54 // A trailing newline splits into a final empty element that is not a line;
55 // counting it would report one line too many in every continuation note.
56 // Remember it so a window reaching the end restores it: read_file's

Callers 2

buildToolsMethod · 0.92
TestReadFileSchemaShapeFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestReadFileSchemaShapeFunction · 0.68