memory

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	// MaxFactSize is the hard per-fact limit (16KB).
	MaxFactSize = 16 * 1024
)

Variables

This section is empty.

Functions

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a valid kebab-case ASCII slug.

func ValidType

func ValidType(t Type) bool

ValidType reports whether t is one of the four known types.

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.

func (Memory) ID

func (m Memory) ID() string

ID is the canonical, scope-qualified identifier used in the index and by the read/delete actions (e.g. "project/uses-docker").

type Scope

type Scope int

Scope is where a fact lives.

const (
	ScopeProject Scope = iota // project-local (project, reference)
	ScopeGlobal               // cross-project (user, feedback)
)

func ScopeForType

func ScopeForType(t Type) Scope

ScopeForType routes a type to its scope (D2): user/feedback are global, everything else is project-local.

func (Scope) String

func (s Scope) String() string

type Store

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

Store manages the global and project memory directories for one workspace.

func New

func New(configDir, workspaceRoot string) *Store

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

func (s *Store) Delete(id string) error

Delete removes a single fact by canonical ID or bare name.

func (*Store) FormatIndex

func (s *Store) FormatIndex(mems []Memory) string

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

func (s *Store) GlobalDir() string

GlobalDir returns the global memory directory.

func (*Store) List

func (s *Store) List() []Memory

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

func (s *Store) Migrate() error

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

func (s *Store) MigrateV1IfNeeded() error

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

func (s *Store) ProjectDir() string

ProjectDir returns this workspace's project memory directory.

func (*Store) Read

func (s *Store) Read(id string) (Memory, bool, error)

Read returns the full fact for a canonical ID ("project/foo", "global/foo") or a bare name. A bare name that exists in both scopes is an error (D9).

func (*Store) Write

func (s *Store) Write(m Memory) error

Write creates or overwrites a single fact. Scope is derived from Type (D2); an invalid type or name is a hard error (D10).

type Type

type Type string

Type classifies a fact and (via scopeForType) decides its scope.

const (
	TypeUser      Type = "user"
	TypeFeedback  Type = "feedback"
	TypeProject   Type = "project"
	TypeReference Type = "reference"
)

Jump to

Keyboard shortcuts

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