@@ -14,6 +14,7 @@ import (
14 "github.com/charmbracelet/crush/internal/csync"
14 "github.com/charmbracelet/crush/internal/csync"
15 "github.com/charmbracelet/crush/internal/diff"
15 "github.com/charmbracelet/crush/internal/diff"
16 "github.com/charmbracelet/crush/internal/filepathext"
16 "github.com/charmbracelet/crush/internal/filepathext"
17+ "github.com/charmbracelet/crush/internal/filetracker"
17 "github.com/charmbracelet/crush/internal/fsext"
18 "github.com/charmbracelet/crush/internal/fsext"
18 "github.com/charmbracelet/crush/internal/history"
19 "github.com/charmbracelet/crush/internal/history"
@@ -159,8 +160,8 @@ func createNewFile(edit editContext, filePath, content string, call fantasy.Tool
159 slog.Error("Error creating file history version", "error", err)
160 slog.Error("Error creating file history version", "error", err)
162− recordFileWrite(filePath)
163+ filetracker.RecordWrite(filePath)
163− recordFileRead(filePath)
164+ filetracker.RecordRead(filePath)
165 return fantasy.WithResponseMetadata(
166 return fantasy.WithResponseMetadata(
166 fantasy.NewTextResponse("File created: "+filePath),
167 fantasy.NewTextResponse("File created: "+filePath),
@@ -186,12 +187,12 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
186 return fantasy.NewTextErrorResponse(fmt.Sprintf("path is a directory, not a file: %s", filePath)), nil
187 return fantasy.NewTextErrorResponse(fmt.Sprintf("path is a directory, not a file: %s", filePath)), nil
189− if getLastReadTime(filePath).IsZero() {
190+ if filetracker.LastReadTime(filePath).IsZero() {
190 return fantasy.NewTextErrorResponse("you must read the file before editing it. Use the View tool first"), nil
191 return fantasy.NewTextErrorResponse("you must read the file before editing it. Use the View tool first"), nil
193 modTime := fileInfo.ModTime()
194 modTime := fileInfo.ModTime()
194− lastRead := getLastReadTime(filePath)
195+ lastRead := filetracker.LastReadTime(filePath)
195 if modTime.After(lastRead) {
196 if modTime.After(lastRead) {
196 return fantasy.NewTextErrorResponse(
197 return fantasy.NewTextErrorResponse(
197 fmt.Sprintf("file %s has been modified since it was last read (mod time: %s, last read: %s)",
198 fmt.Sprintf("file %s has been modified since it was last read (mod time: %s, last read: %s)",
@@ -292,8 +293,8 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
292 slog.Error("Error creating file history version", "error", err)
293 slog.Error("Error creating file history version", "error", err)
295− recordFileWrite(filePath)
296+ filetracker.RecordWrite(filePath)
296− recordFileRead(filePath)
297+ filetracker.RecordRead(filePath)
298 return fantasy.WithResponseMetadata(
299 return fantasy.WithResponseMetadata(
299 fantasy.NewTextResponse("Content deleted from file: "+filePath),
300 fantasy.NewTextResponse("Content deleted from file: "+filePath),
@@ -319,12 +320,12 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
319 return fantasy.NewTextErrorResponse(fmt.Sprintf("path is a directory, not a file: %s", filePath)), nil
320 return fantasy.NewTextErrorResponse(fmt.Sprintf("path is a directory, not a file: %s", filePath)), nil
322− if getLastReadTime(filePath).IsZero() {
323+ if filetracker.LastReadTime(filePath).IsZero() {
323 return fantasy.NewTextErrorResponse("you must read the file before editing it. Use the View tool first"), nil
324 return fantasy.NewTextErrorResponse("you must read the file before editing it. Use the View tool first"), nil
326 modTime := fileInfo.ModTime()
327 modTime := fileInfo.ModTime()
327− lastRead := getLastReadTime(filePath)
328+ lastRead := filetracker.LastReadTime(filePath)
328 if modTime.After(lastRead) {
329 if modTime.After(lastRead) {
329 return fantasy.NewTextErrorResponse(
330 return fantasy.NewTextErrorResponse(
330 fmt.Sprintf("file %s has been modified since it was last read (mod time: %s, last read: %s)",
331 fmt.Sprintf("file %s has been modified since it was last read (mod time: %s, last read: %s)",
@@ -427,8 +428,8 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
427 slog.Error("Error creating file history version", "error", err)
428 slog.Error("Error creating file history version", "error", err)
430− recordFileWrite(filePath)
431+ filetracker.RecordWrite(filePath)
431− recordFileRead(filePath)
432+ filetracker.RecordRead(filePath)
433 return fantasy.WithResponseMetadata(
434 return fantasy.WithResponseMetadata(
434 fantasy.NewTextResponse("Content replaced in file: "+filePath),
435 fantasy.NewTextResponse("Content replaced in file: "+filePath),