文件 I/O 模块位于 internal/fileio/,提供安全的文件读取能力,支持大文件截断。
Read(path string, maxBytes int) (string, error)maxBytes <= 0 时使用 DefaultMaxBytes = 64 KiBmaxBytes 字节,并追加
\n\n[truncated: showing first N bytes]Write(path, content string) errorMkdirAll 父目录,文件权限 0644Runtime 在调用前触发 filehistory 备份Edit(path, oldStr, newStr string) (string, error)oldStr 必须存在,否则返回 old_string not found-old / +new 预览(各截断 8 行)search_replace / parallel_edit_files| 函数 | 行为 |
|---|---|
Exists(path) bool |
os.Stat 成功即存在 |
IsReadable(path) error |
必须存在、非目录且可 Open |
文件 I/O 本身不做路径沙箱:路径解析、工作区外审批与敏感路径拦截在
internal/pathutil + internal/permission 中完成;工具层只负责读写字节。
content, err := fileio.Read("./main.go", 32*1024)
if err != nil {
// 处理错误
}
// content 可能带 truncation 标记
read_file / write_file / edit_file 由 internal/tool 调用;大输出外存与分页由
internal/tool/artifact.go 处理,不在 fileio 中做头尾截断。