xonecas.io
62159
Sy

symb / files

symb / internal / mcptools / filetrack.go

936 bytes
1package mcptools
2
3import "sync"
4
5// FileReadTracker tracks which files have been read via Open.
6// Edit checks this before allowing modifications.
7type FileReadTracker struct {
8	mu   sync.RWMutex
9	read map[string]struct{} // absolute paths that have been opened
10}
11
12// NewFileReadTracker creates a new tracker.
13func NewFileReadTracker() *FileReadTracker {
14	return &FileReadTracker{read: make(map[string]struct{})}
15}
16
17// MarkRead records that a file was read via Open.
18func (t *FileReadTracker) MarkRead(absPath string) {
19	t.mu.Lock()
20	defer t.mu.Unlock()
21	t.read[absPath] = struct{}{}
22}
23
24// WasRead returns true if the file was previously opened.
25func (t *FileReadTracker) WasRead(absPath string) bool {
26	t.mu.RLock()
27	defer t.mu.RUnlock()
28	_, ok := t.read[absPath]
29	return ok
30}
31
32// Reset clears all read records (used on undo).
33func (t *FileReadTracker) Reset() {
34	t.mu.Lock()
35	defer t.mu.Unlock()
36	t.read = make(map[string]struct{})
37}