Documentation
¶
Overview ¶
Package files is the built-in memory backend: per scope one MEMORY.md index plus one Markdown file per entry. It needs nothing but the standard library, so memory works out of the box.
Two layouts are supported:
- DirLayout{Dir}: index <Dir>/MEMORY.md, entries <Dir>/<id>.md; used for user memory under <SUGA_HOME>/memory/user and for project memory without a repository MEMORY.md, under <SUGA_HOME>/projects/<key>/memory.
- RepoLayout{Root}: index <Root>/MEMORY.md, entries <Root>/.suga/memory/<id>.md (project memory kept in the repository).
Index lines have the form "- [Title](relative/path.md) — kind". Lines that do not match (headings, prose, other lists) are hand-written and preserved verbatim at their position; they are read-only for the backend. New entries are appended at the end of MEMORY.md.
All file access goes through os.Root, so ids and symlinks cannot reach outside the layout root. Directories are created 0700, files 0600, and every file is replaced atomically (temp file + rename). A Store serializes its own writes; concurrent writers in other processes are not coordinated (last index write wins).
Index ¶
- Constants
- type DirLayout
- type Layout
- type Option
- type RepoLayout
- type Store
- func (s *Store) BackendName() string
- func (s *Store) Entries(_ context.Context, sc memory.Scope) ([]memory.Entry, error)
- func (s *Store) Get(_ context.Context, sc memory.Scope, id string) (memory.Entry, error)
- func (s *Store) Index(_ context.Context, sc memory.Scope) (memory.Index, error)
- func (s *Store) Search(ctx context.Context, sc memory.Scope, q string, limit int) ([]memory.Hit, error)
- func (s *Store) SetSummary(_ context.Context, sc memory.Scope, id, summary string) error
- func (s *Store) Write(_ context.Context, sc memory.Scope, op memory.Op) (memory.Entry, error)
Constants ¶
const Name = "files"
Name is the backend name reported by BackendName.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DirLayout ¶
type DirLayout struct{ Dir string }
DirLayout keeps MEMORY.md and <id>.md files side by side in Dir. Dir is created on the first write.
type Layout ¶
type Layout interface {
// contains filtered or unexported methods
}
Layout places a scope's index and entry files. It is implemented by DirLayout and RepoLayout only.
type RepoLayout ¶
type RepoLayout struct{ Root string }
RepoLayout keeps MEMORY.md at the repository root and entries under .suga/memory/. Root must already exist; it is never created.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements memory.Store over files.
func New ¶
New builds a Store with one layout per scope (exact Scope match, e.g. memory.UserScope() and memory.ProjectScope("<key>")). Layout roots must be absolute paths.
func (*Store) BackendName ¶
BackendName implements memory.Named.
func (*Store) Entries ¶
Entries enumerates readable entry files using the same id and root safety rules as Search. Missing layouts are empty; unreadable or escaping entries are skipped so one bad file cannot hide the rest of the scope.
func (*Store) Get ¶
Get implements memory.Store. Missing title or kind in the entry file fall back to the index line.
func (*Store) Index ¶
Index implements memory.Store. A missing layout root or MEMORY.md is an empty index.
func (*Store) Search ¶
func (s *Store) Search(ctx context.Context, sc memory.Scope, q string, limit int) ([]memory.Hit, error)
Search implements memory.Store: every entry file is scanned and matched case-insensitively against all whitespace-separated terms of q (AND) in its title and body. Hits are ordered by Updated (newest first), then id.
func (*Store) SetSummary ¶
SetSummary implements memory.Summarizer: only the MEMORY.md line changes, the entry file keeps its body untouched. An empty summary removes the summary from the line (back to the old format).