memory

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 11 Imported by: 0

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/projects/<hash>/memory/<slug>.md) — project, reference

where <hash> is SHA256(CanonicalizePath(workspaceRoot))[:16]. 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
	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.

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

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