From e1b9fa0a3637ba96def2e65e07fa6da0455d6acd Mon Sep 17 00:00:00 2001 From: Finessse Date: Wed, 17 Dec 2025 21:01:05 +0700 Subject: [PATCH] memory: add session todo file --- internal/memory/file_store.go | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/internal/memory/file_store.go b/internal/memory/file_store.go index 3cf07797..9e8cd509 100644 --- a/internal/memory/file_store.go +++ b/internal/memory/file_store.go @@ -361,6 +361,51 @@ func (s *FileStore) readSmallTextFile(path string, maxBytes int64) string { return string(b) } +func (s *FileStore) ReadTodo(session string, maxChars int) string { + if s == nil || s.BaseDir == "" { + return "" + } + if session == "" { + return "" + } + if maxChars <= 0 { + maxChars = 4000 + } + dir := s.sessionDir(session) + txt := strings.TrimSpace(s.readSmallTextFile(filepath.Join(dir, "todo.md"), int64(maxChars*2))) + if txt == "" { + return "" + } + if len(txt) > maxChars { + txt = txt[:maxChars] + "\n...[truncated]..." + } + return txt +} + +func (s *FileStore) WriteTodo(session string, todo string, maxChars int) error { + if s == nil || s.BaseDir == "" { + return errors.New("memory store not configured") + } + if session == "" { + return nil + } + if maxChars <= 0 { + maxChars = 8000 + } + todo = strings.TrimSpace(RedactText(todo)) + if todo == "" { + return nil + } + if len(todo) > maxChars { + todo = todo[:maxChars] + "\n...[truncated]..." + } + dir := s.sessionDir(session) + if err := os.MkdirAll(dir, 0o755); err != nil { + return err + } + return os.WriteFile(filepath.Join(dir, "todo.md"), []byte(todo), 0o644) +} + func readTailBytes(path string, max int64) ([]byte, error) { f, err := os.Open(path) if err != nil {