memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package memory implements BroCode's cross-session project memory.

Every session starts cold; memory is the layer that lets a new session start warm. It persists durable facts about the project (architecture, build/test commands, decisions, gotchas) to .brocode/memory.md and makes them available three ways:

  1. Warm start — a capped excerpt of the memory file is injected into the system prompt at session start, so the agent already knows what past sessions learned without grep/glob.
  2. memory tool — the agent can recall (BM25 relevance), retain (add a fact), or list the memory during a turn.
  3. Auto-extract — on context compaction, the compaction summary's durable decisions are merged into memory automatically.

The file lives next to the project config (.brocode/memory.md) so it can be committed for the team or git-ignored for personal notes, matching the global/project layering used elsewhere in BroCode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes the project memory file.

func NewStore

func NewStore(workspaceDir string) *Store

NewStore opens (or creates on first write) the project memory file under workspaceDir/.brocode/memory.md. Returns nil if no workspace dir.

func (*Store) CaptureGotcha

func (s *Store) CaptureGotcha(contextHint, gotcha string) error

CaptureGotcha records a project-specific trap, gotcha, or failure pattern so the agent never repeats the same mistake in future sessions.

func (*Store) CaptureMinerFindings

func (s *Store) CaptureMinerFindings(answer string, files []string) error

CaptureMinerFindings persists what a MINER turn actually examined plus the model's own synthesized summary into project memory. It parses markdown headers (## Architecture, ## Build & Test, ## Decisions, ## Gotchas) and bullet points, storing structured facts into their respective sections in memory.md.

func (*Store) CaptureSession

func (s *Store) CaptureSession(sessionID string, events []store.Event) error

CaptureSession extracts durable facts from a finished session's events WITHOUT calling the LLM (deterministic, non-blocking — safe to run on quit):

  • the last real user prompt becomes a session goal note
  • files the agent wrote/edited are recorded under a session note

This complements auto-extract-on-compaction: short sessions that never hit the compaction threshold still leave a trace in project memory.

func (*Store) List

func (s *Store) List() string

List returns all memory facts formatted for the model (used by /memory).

func (*Store) MergeCompaction

func (s *Store) MergeCompaction(goal string, decisions []string, state string) error

MergeCompaction persists durable facts from a compaction summary into the Decisions/Gotchas sections automatically (auto-extract on context loss).

func (*Store) Path

func (s *Store) Path() string

Path returns the memory file location (empty if store is nil).

func (*Store) Recall

func (s *Store) Recall(query string, limit int) string

Recall searches memory facts by BM25 relevance to query, returning the top matches formatted for the model. Returns a friendly "no memory" note when empty.

func (*Store) Retain

func (s *Store) Retain(section, fact string) (bool, error)

Retain adds a fact to a section, deduplicating near-identical entries. It returns true when a new fact was added. Sections default to "Notes".

func (*Store) Save

func (s *Store) Save() error

Save writes the facts back to the file, pruning to the size cap.

func (*Store) WarmStart

func (s *Store) WarmStart() string

WarmStart returns a capped excerpt of memory for system-prompt injection. Returns "" when the store is empty or nil.

func (*Store) WarmStartRelevant

func (s *Store) WarmStartRelevant(query string) string

WarmStartRelevant returns a query-filtered dynamic slice of memory facts. When query is non-empty, it selects the top relevant facts matching the active task using BM25 relevance scoring, saving 70-90% of token overhead.

Jump to

Keyboard shortcuts

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