Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/agent/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ func (ms *MemoryStore) AppendToday(content string) error {
return os.WriteFile(todayFile, []byte(newContent), 0o644)
}

// EnsureTodayFile creates today's daily note file (and month directory) if missing,
// so paths advertised in the system prompt (memory/YYYYMM/YYYYMMDD.md) exist when the LLM reads them.
func (ms *MemoryStore) EnsureTodayFile() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different from AppendToday?

todayFile := ms.getTodayFile()
monthDir := filepath.Dir(todayFile)
if err := os.MkdirAll(monthDir, 0o755); err != nil {
return
}
if _, err := os.Stat(todayFile); err == nil {
return // already exists
}
header := fmt.Sprintf("# %s\n\n", time.Now().Format("2006-01-02"))
_ = os.WriteFile(todayFile, []byte(header), 0o644)
}

// GetRecentDailyNotes returns daily notes from the last N days.
// Contents are joined with "---" separator.
func (ms *MemoryStore) GetRecentDailyNotes(days int) string {
Expand Down Expand Up @@ -125,6 +140,7 @@ func (ms *MemoryStore) GetRecentDailyNotes(days int) string {
// GetMemoryContext returns formatted memory context for the agent prompt.
// Includes long-term memory and recent daily notes.
func (ms *MemoryStore) GetMemoryContext() string {
ms.EnsureTodayFile() // so memory/YYYYMM/YYYYMMDD.md exists when LLM uses read_file
longTerm := ms.ReadLongTerm()
recentNotes := ms.GetRecentDailyNotes(3)

Expand Down