Documentation
¶
Overview ¶
Package memory implements persistent session learning for cloop. After each session the AI can extract key learnings (what worked, what failed, important project facts) which are stored in .cloop/memory.json and injected into future session prompts so the AI builds institutional knowledge over time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLearnings ¶
func ExtractLearnings(ctx context.Context, p provider.Provider, model string, goal string, sessionSummary string, mem *Memory) ([]string, error)
ExtractLearnings calls the AI to extract learnings from a session and stores them.
func ExtractLearningsPrompt ¶
ExtractLearningsPrompt builds a prompt asking the AI to extract key learnings from the just-completed session.
Types ¶
type Entry ¶
type Entry struct {
ID int `json:"id"`
Timestamp time.Time `json:"timestamp"`
Goal string `json:"goal,omitempty"` // project goal when memory was recorded
Content string `json:"content"` // the learning / fact
Source string `json:"source"` // "ai" or "user"
Tags []string `json:"tags,omitempty"`
}
Entry is a single learned fact stored across sessions.
type Memory ¶
Memory is the persistent knowledge base for a project.
func Load ¶
Load reads memory from disk. Returns empty memory if file doesn't exist.
On parse failure (zero-byte file, schema drift, manual edit gone wrong) the corrupt file is quarantined aside as memory.json.corrupt-<unix> and an empty Memory is returned. The alternative — propagating a parse error — would silently drop every accumulated learning across all sessions for the rest of the run, since most callers ignore the error and treat memory as empty anyway. Quarantining preserves the bad bytes for forensics and makes the loss explicit via a stderr warning.
func (*Memory) FormatForPrompt ¶
FormatForPrompt returns a prompt-ready summary of stored memories. It returns at most limit entries (most recent first). 0 = all.
func (*Memory) Save ¶
Save persists memory to disk atomically. A crash, ENOSPC, or concurrent reader during the write will never leave a half-written or empty memory.json — readers see either the previous valid file or the new valid file. This is critical because a corrupted memory.json fails Load() with a parse error, which silently drops every accumulated learning across all sessions.