MCPcopy Create free account
hub / github.com/diillson/chatcli / loadMemoryIntoContext

Method loadMemoryIntoContext

cli/memory_command.go:164–215  ·  view source on GitHub ↗
(dateStr string)

Source from the content-addressed store, hash-verified

162}
163
164func (cli *ChatCLI) loadMemoryIntoContext(dateStr string) {
165 date, err := parseFlexibleDate(dateStr)
166 if err != nil {
167 fmt.Printf(" %s %s\n", colorize(i18n.T("memory.error.invalid_date"), ColorYellow), i18n.T("memory.error.date_format_hint"))
168 return
169 }
170
171 // Check if this date was already loaded (prevent duplicates)
172 marker := fmt.Sprintf("[MEMORY CONTEXT — loaded from %s]", date.Format("2006-01-02"))
173 for _, msg := range cli.history {
174 if strings.Contains(msg.Content, marker) {
175 fmt.Printf(" %s %s\n",
176 colorize("!", ColorYellow),
177 i18n.T("memory.already_loaded", date.Format("2006-01-02")))
178 return
179 }
180 }
181
182 notes := cli.memoryStore.GetRecentDailyNotes(30) // search last 30 days
183 var found string
184 for _, note := range notes {
185 if note.Date.Format("2006-01-02") == date.Format("2006-01-02") {
186 found = note.Content
187 break
188 }
189 }
190
191 if found == "" {
192 fmt.Printf(" %s %s\n", colorize(i18n.T("mem.cmd.no_notes_found_for"), ColorGray), colorize(date.Format("2006-01-02"), ColorCyan))
193 return
194 }
195
196 // Also include long-term memory
197 longTerm := cli.memoryStore.ReadLongTerm()
198
199 contextContent := marker + "\n\n"
200 if longTerm != "" {
201 contextContent += "## Long-term Memory\n\n" + longTerm + "\n\n"
202 }
203 contextContent += "## Notes from " + date.Format("2006-01-02") + "\n\n" + found
204
205 // Inject once as a user message so the AI has the context
206 cli.history = append(cli.history, models.Message{
207 Role: "user",
208 Content: contextContent,
209 })
210
211 fmt.Printf(" %s %s\n",
212 colorize("OK", ColorGreen),
213 i18n.T("memory.loaded_into_context", date.Format("2006-01-02"), len(contextContent)),
214 )
215}
216
217// --- New commands ---
218

Callers 1

handleMemoryCommandMethod · 0.95

Calls 5

TFunction · 0.92
parseFlexibleDateFunction · 0.85
colorizeFunction · 0.85
GetRecentDailyNotesMethod · 0.45
ReadLongTermMethod · 0.45

Tested by

no test coverage detected