From 904061c243f70696bfe781e97bf4e392e6954d07 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Tue, 25 Mar 2025 13:04:36 +0100 Subject: additional tools --- internal/llm/tools/file.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/llm/tools/file.go (limited to 'internal/llm/tools/file.go') diff --git a/internal/llm/tools/file.go b/internal/llm/tools/file.go new file mode 100644 index 000000000..7f34fdc1f --- /dev/null +++ b/internal/llm/tools/file.go @@ -0,0 +1,53 @@ +package tools + +import ( + "sync" + "time" +) + +// File record to track when files were read/written +type fileRecord struct { + path string + readTime time.Time + writeTime time.Time +} + +var ( + fileRecords = make(map[string]fileRecord) + fileRecordMutex sync.RWMutex +) + +func recordFileRead(path string) { + fileRecordMutex.Lock() + defer fileRecordMutex.Unlock() + + record, exists := fileRecords[path] + if !exists { + record = fileRecord{path: path} + } + record.readTime = time.Now() + fileRecords[path] = record +} + +func getLastReadTime(path string) time.Time { + fileRecordMutex.RLock() + defer fileRecordMutex.RUnlock() + + record, exists := fileRecords[path] + if !exists { + return time.Time{} + } + return record.readTime +} + +func recordFileWrite(path string) { + fileRecordMutex.Lock() + defer fileRecordMutex.Unlock() + + record, exists := fileRecords[path] + if !exists { + record = fileRecord{path: path} + } + record.writeTime = time.Now() + fileRecords[path] = record +} -- cgit v1.2.3