ReadFileForInline reads a text file and wraps it in an XML-like tag with the file path for context. Returns the formatted content and any error.
(filePath string)
| 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. |
| 263 | func ReadFileForInline(filePath string) (string, error) { |
| 264 | data, err := os.ReadFile(filePath) |
| 265 | if err != nil { |
| 266 | return "", fmt.Errorf("failed to read file: %w", err) |
| 267 | } |
| 268 | return fmt.Sprintf("<attached_file path=%q>\n%s\n</attached_file>", filePath, string(data)), nil |
| 269 | } |
| 270 | |
| 271 | // isTextExtension returns true for file extensions known to be text-based. |
| 272 | // This includes programming languages, config files, markup, and data formats. |