agent: ensure today's daily note file exists before LLM read_file
- Add EnsureTodayFile() to create memory/YYYYMM/YYYYMMDD.md with date header if missing - Call it from GetMemoryContext() so path advertised in system prompt always exists - Avoids read_file tool failure when agent (or cron) tries to read today's note Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ec6da7a530
commit
f3daad6da1
1 changed files with 16 additions and 0 deletions
|
|
@ -98,6 +98,21 @@ func (ms *MemoryStore) AppendToday(content string) error {
|
||||||
return os.WriteFile(todayFile, []byte(newContent), 0o644)
|
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() {
|
||||||
|
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.
|
// GetRecentDailyNotes returns daily notes from the last N days.
|
||||||
// Contents are joined with "---" separator.
|
// Contents are joined with "---" separator.
|
||||||
func (ms *MemoryStore) GetRecentDailyNotes(days int) string {
|
func (ms *MemoryStore) GetRecentDailyNotes(days int) string {
|
||||||
|
|
@ -125,6 +140,7 @@ func (ms *MemoryStore) GetRecentDailyNotes(days int) string {
|
||||||
// GetMemoryContext returns formatted memory context for the agent prompt.
|
// GetMemoryContext returns formatted memory context for the agent prompt.
|
||||||
// Includes long-term memory and recent daily notes.
|
// Includes long-term memory and recent daily notes.
|
||||||
func (ms *MemoryStore) GetMemoryContext() string {
|
func (ms *MemoryStore) GetMemoryContext() string {
|
||||||
|
ms.EnsureTodayFile() // so memory/YYYYMM/YYYYMMDD.md exists when LLM uses read_file
|
||||||
longTerm := ms.ReadLongTerm()
|
longTerm := ms.ReadLongTerm()
|
||||||
recentNotes := ms.GetRecentDailyNotes(3)
|
recentNotes := ms.GetRecentDailyNotes(3)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue