memory

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 10 Imported by: 0

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

func ExtractLearningsPrompt(goal string, sessionSummary string) string

ExtractLearningsPrompt builds a prompt asking the AI to extract key learnings from the just-completed session.

func FormatAge

func FormatAge(t time.Time) string

FormatAge returns a human-readable age string for a timestamp.

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

type Memory struct {
	Entries []*Entry `json:"entries"`
	NextID  int      `json:"next_id"`
}

Memory is the persistent knowledge base for a project.

func Load

func Load(workDir string) (*Memory, error)

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) Add

func (m *Memory) Add(content, source, goal string, tags []string) *Entry

Add appends a new entry to memory.

func (*Memory) Clear

func (m *Memory) Clear()

Clear removes all entries.

func (*Memory) Delete

func (m *Memory) Delete(id int) bool

Delete removes an entry by ID. Returns false if not found.

func (*Memory) FormatForPrompt

func (m *Memory) FormatForPrompt(limit int) string

FormatForPrompt returns a prompt-ready summary of stored memories. It returns at most limit entries (most recent first). 0 = all.

func (*Memory) Save

func (m *Memory) Save(workDir string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL