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

Method runMemoryCompact

cli/memory_command.go:553–591  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

551}
552
553func (cli *ChatCLI) runMemoryCompact(ctx context.Context) {
554 mgr := cli.memoryStore.Manager()
555
556 fmt.Println(colorize(" "+i18n.T("mem.cmd.compact.running"), ColorCyan))
557
558 llmClient := cli.getClient()
559 var sendPrompt func(ctx context.Context, prompt string) (string, error)
560
561 if llmClient != nil {
562 sendPrompt = func(ctx context.Context, prompt string) (string, error) {
563 history := []models.Message{
564 {Role: "user", Content: prompt},
565 }
566 return llmClient.SendPrompt(ctx, prompt, history, 0)
567 }
568 }
569
570 ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
571 defer cancel()
572
573 factsBefore := mgr.Facts.Count()
574
575 if err := mgr.RunCompaction(ctx, sendPrompt); err != nil {
576 fmt.Printf(" %s %s %s\n", colorize("ERR", ColorRed), i18n.T("mem.cmd.compact.failed"), err.Error())
577 return
578 }
579
580 factsAfter := mgr.Facts.Count()
581
582 // Also cleanup daily notes
583 deleted, _ := mgr.CleanupDailyNotes()
584
585 fmt.Printf(" %s %s\n", colorize("OK", ColorGreen), i18n.T("mem.cmd.compact.complete"))
586 fmt.Printf(" %s\n", i18n.T("mem.cmd.compact.facts_change", factsBefore, factsAfter))
587 if deleted > 0 {
588 fmt.Printf(" %s\n", i18n.T("mem.cmd.compact.notes_removed", deleted))
589 }
590 fmt.Println()
591}
592
593func (cli *ChatCLI) listMemoryNotes() {
594 if cli.memoryStore == nil {

Callers 1

handleMemoryCommandMethod · 0.95

Calls 9

getClientMethod · 0.95
TFunction · 0.92
colorizeFunction · 0.85
ManagerMethod · 0.80
RunCompactionMethod · 0.80
SendPromptMethod · 0.65
CountMethod · 0.65
ErrorMethod · 0.65
CleanupDailyNotesMethod · 0.45

Tested by

no test coverage detected