Documentation
¶
Overview ¶
Package memory provides cross-session memory persistence as a set of typed, single-fact files with a lightweight frontmatter header.
Facts live in two scopes:
- global (~/.config/moa/global/memory/<slug>.md) — user, feedback
- project (~/.config/moa/codebases/<key>/memory/<slug>.md) — project, reference
where <key> is core.CodebaseKey(workspaceRoot): the identity of the repository the workspace belongs to, so every git worktree of one repo reads and writes the same facts and deleting a worktree no longer orphans what was learned in it. Only the index (one line per fact) is injected into the prompt; full bodies are read on demand. The index is derived from the files at load — moa never writes a MEMORY.md of its own.
Index ¶
- Constants
- func ValidName(name string) bool
- func ValidType(t Type) bool
- type Memory
- type Scope
- type Store
- func (s *Store) Delete(id string) error
- func (s *Store) FormatIndex(mems []Memory) string
- func (s *Store) GlobalDir() string
- func (s *Store) List() []Memory
- func (s *Store) Migrate() error
- func (s *Store) MigrateV1IfNeeded() error
- func (s *Store) ProjectDir() string
- func (s *Store) Read(id string) (Memory, bool, error)
- func (s *Store) Write(m Memory) error
- type Type
Constants ¶
const (
// MaxFactSize is the hard per-fact limit (16KB).
MaxFactSize = 16 * 1024
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Memory ¶
type Memory struct {
Name string
Description string
Type Type
InvalidateWhen string
Durable bool // write-time declaration; durable facts omit invalidate_when on disk
Body string
Scope Scope
Path string // absolute path to the file (set on read/list)
}
Memory is a single fact.
type Scope ¶
type Scope int
Scope is where a fact lives.
func ScopeForType ¶
ScopeForType routes a type to its scope (D2): user/feedback are global, everything else is project-local.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages the global and project memory directories for one workspace.
func New ¶
New builds a Store. configDir is the moa config root (~/.config/moa); workspaceRoot selects the project scope.
It does not migrate anything: call Migrate for that, once, at startup.
func (*Store) FormatIndex ¶
FormatIndex renders the index as one bullet per fact (no framing — the caller adds it). Empty if no facts. Bounded by maxIndexBytes with a truncation note.
func (*Store) List ¶
List scans both scopes and returns all facts, project scope first, then by name. Global and project facts with the same name coexist as distinct IDs.
func (*Store) Migrate ¶ added in v0.25.0
Migrate brings this store's project scope up to date. Call it once, at startup, before reading anything.
The order is load-bearing: the codebase migration reconciles the destination with every legacy store first, so that the v1 wrapping below writes into a directory whose names are already settled and cannot displace a fact the merge was about to place there.
func (*Store) MigrateV1IfNeeded ¶
MigrateV1IfNeeded wraps a flat v1 MEMORY.md into a single legacy fact, then retires the flat file. Idempotent even across partial failures: the flat file is only renamed after the fact is safely written, so an interrupted run simply retries next time (D6).
The flat file is looked for under the path-keyed project directory because that is the only place v1 ever wrote it; the fact it becomes is written to the current (codebase-keyed) directory like any other. It must therefore run after the codebase migration — see Migrate.
func (*Store) ProjectDir ¶
ProjectDir returns this workspace's project memory directory.