NewSessionFiles opens (or creates) the memory directory at root and loads the index. Missing sessions referenced in the index get pruned silently — drift between disk and index is fixed in place instead of surfacing as errors at recall time.
(root string)
| 43 | // silently — drift between disk and index is fixed in place instead of |
| 44 | // surfacing as errors at recall time. |
| 45 | func NewSessionFiles(root string) (*SessionFiles, error) { |
| 46 | if err := os.MkdirAll(filepath.Join(root, "sessions"), 0o755); err != nil { |
| 47 | return nil, fmt.Errorf("memory: create %s: %w", root, err) |
| 48 | } |
| 49 | s := &SessionFiles{root: root, sessionStart: time.Now()} |
| 50 | if err := s.loadIndex(); err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | s.pruneMissing() |
| 54 | return s, nil |
| 55 | } |
| 56 | |
| 57 | func (s *SessionFiles) loadIndex() error { |
| 58 | data, err := os.ReadFile(filepath.Join(s.root, "index.json")) |