zwischenstand
This commit is contained in:
54
internal/brain/core_memory.go
Normal file
54
internal/brain/core_memory.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// core_memory.go – Persistente Kernfakten über den Nutzer (core_memory.md)
|
||||
package brain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"my-brain-importer/internal/config"
|
||||
)
|
||||
|
||||
// CoreMemoryPath gibt den Pfad zur core_memory.md-Datei zurück.
|
||||
func CoreMemoryPath() string {
|
||||
return filepath.Join(config.Cfg.BrainRoot, "core_memory.md")
|
||||
}
|
||||
|
||||
// LoadCoreMemory liest den Inhalt der core_memory.md-Datei.
|
||||
// Gibt leeren String zurück wenn die Datei nicht existiert.
|
||||
func LoadCoreMemory() string {
|
||||
data, err := os.ReadFile(CoreMemoryPath())
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
// AppendCoreMemory fügt einen Fakt zur core_memory.md-Datei hinzu.
|
||||
func AppendCoreMemory(text string) error {
|
||||
path := CoreMemoryPath()
|
||||
// Datei erstellen falls nicht vorhanden, sonst anhängen
|
||||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("core_memory.md öffnen: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Führenden Bindestrich ergänzen wenn nicht vorhanden
|
||||
line := strings.TrimSpace(text)
|
||||
if !strings.HasPrefix(line, "-") {
|
||||
line = "- " + line
|
||||
}
|
||||
_, err = fmt.Fprintf(f, "%s\n", line)
|
||||
return err
|
||||
}
|
||||
|
||||
// ShowCoreMemory gibt den Inhalt der core_memory.md als formatierte Nachricht zurück.
|
||||
func ShowCoreMemory() string {
|
||||
content := LoadCoreMemory()
|
||||
if content == "" {
|
||||
return "📭 Keine Kernfakten gespeichert. Nutze `/memory profile <text>` um Fakten hinzuzufügen."
|
||||
}
|
||||
return fmt.Sprintf("🧠 **Kerngedächtnis:**\n```\n%s\n```", content)
|
||||
}
|
||||
Reference in New Issue
Block a user