MCPcopy Index your code
hub / github.com/docker/docker-agent / IsTextFile

Function IsTextFile

pkg/chat/chat.go:252–259  ·  view source on GitHub ↗

IsTextFile determines if a file at the given path is a text file that should be inlined into the message rather than uploaded via a provider's file API. It first checks the file extension against a broad allowlist of known text extensions. For unknown extensions, it falls back to reading the first 8

(filePath string)

Source from the content-addressed store, hash-verified

250// extensions. For unknown extensions, it falls back to reading the first 8KB
251// and checking if the content is valid UTF-8 with no null bytes.
252func IsTextFile(filePath string) bool {
253 ext := strings.ToLower(filepath.Ext(filePath))
254 if isTextExtension(ext) {
255 return true
256 }
257 // For unknown extensions, try byte-sniffing
258 return isTextByContent(filePath)
259}
260
261// ReadFileForInline reads a text file and wraps it in an XML-like tag with
262// the file path for context. Returns the formatted content and any error.

Calls 2

isTextExtensionFunction · 0.85
isTextByContentFunction · 0.85