memstore

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 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 memstore is the contract of the agent's memory store: list the notes, read one, write one, search by text. The default implementation is the files Claude Code and harnessly already keep (FileStore), and nothing changes for a person without an adapter. A corporate store (a wiki, a database) connects as an adapter of the extension frame (internal/hub/ext), protocol harnessly.memory/v1 (docs/memory-adapters.md), and is layered over the files.

Index

Constants

View Source
const Protocol = "harnessly.memory/v1"

Protocol is what a memory adapter speaks. The adapter is an HTTP service of the extension frame (internal/hub/ext): GET /v1/describe, then POST calls with a JSON body, the same way as the connection adapters.

POST /v1/list   {}                           -> {notes: [Entry]}
POST /v1/get    {name}                       -> Note, or 404
POST /v1/put    {name, text, ifVersion}      -> Entry; 409 when ifVersion is not the current one
POST /v1/search {query, limit}               -> {hits: [Hit]}

The capabilities describe lists are `read` (list and get; required), `write` and `search`. A call of a capability that is not listed is not sent.

Variables

View Source
var (
	// ErrNotFound: there is no such note.
	ErrNotFound = errors.New("memstore: no such note")
	// ErrUnsupported: the store does not do this (a read-only store asked to write, an adapter without search).
	ErrUnsupported = errors.New("memstore: not supported")
	// ErrConflict: the note changed since the version the writer read.
	ErrConflict = errors.New("memstore: the note changed")
	// ErrBadName: the name is not a note name (letters, digits, dot, dash, underscore, ending in .md).
	ErrBadName = errors.New("memstore: bad note name")
	// ErrUnreachable: an external store did not answer.
	ErrUnreachable = errors.New("memstore: the store is unreachable")
)

Errors a store answers.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Description string `json:"description"`
	// ModifiedMs is when the note last changed, milliseconds since the epoch.
	ModifiedMs float64 `json:"modifiedMs"`
	// Version changes with every write; Put with IfVersion refuses to overwrite a newer one.
	Version string `json:"version"`
}

Entry is a note without its text.

type ExtStore

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

ExtStore is a Store backed by an adapter.

func Adapters

func Adapters() []*ExtStore

Adapters are the memory adapters the file RUNTIME_MEMORY_ADAPTERS_FILE declares, loaded once per process. Without the variable there are none and the memory is the files, as it always was. An adapter that does not answer is told on stderr; the files go on.

func LoadAdapters

func LoadAdapters(ctx context.Context, path string) ([]*ExtStore, []error)

LoadAdapters makes a store of every memory adapter the file declares (the file of ext.Spec, kind "memory"). Entries of other protocols are skipped; one that does not answer is an error and the rest go on.

func NewExtStore

func NewExtStore(c *ext.Client, d ext.Description) (*ExtStore, error)

NewExtStore is the store of an adapter that has described itself.

func Register

func Register(ctx context.Context, c *ext.Client) (*ExtStore, error)

Register asks the adapter to describe itself and, when it speaks the memory protocol, makes a store of it.

func (*ExtStore) Can

func (s *ExtStore) Can(capability string) bool

Can reports whether the adapter lists a capability.

func (*ExtStore) Get

func (s *ExtStore) Get(ctx context.Context, name string) (Note, error)

func (*ExtStore) List

func (s *ExtStore) List(ctx context.Context) ([]Entry, error)

func (*ExtStore) Name

func (s *ExtStore) Name() string

Name is the adapter's name.

func (*ExtStore) Put

func (s *ExtStore) Put(ctx context.Context, name, text, ifVersion string) (Entry, error)

func (*ExtStore) Search

func (s *ExtStore) Search(ctx context.Context, query string, limit int) ([]Hit, error)

Search uses the adapter's own search when it lists one, and reads the notes otherwise.

type FileStore

type FileStore struct {
	Parents []string
	// WriteDir is where Put writes; empty means the store is read-only.
	WriteDir string
}

FileStore is the memory as it is on disk: <parent>/<entry>/memory/<name>.md under Claude Code's projects and the folders of synced session copies; the freshest copy of a name wins. It reads as it always did. It writes only when WriteDir is set, so a person's memory is never changed by the runtime on its own.

func (FileStore) Get

func (s FileStore) Get(_ context.Context, name string) (Note, error)

func (FileStore) List

func (s FileStore) List(context.Context) ([]Entry, error)

func (FileStore) Put

func (s FileStore) Put(_ context.Context, name, text, ifVersion string) (Entry, error)

func (FileStore) Search

func (s FileStore) Search(ctx context.Context, query string, limit int) ([]Hit, error)

type Hit

type Hit struct {
	Entry
	// Snippet is a line of the note around the match.
	Snippet string `json:"snippet"`
}

Hit is a search result.

type Layered

type Layered struct {
	Top  Store
	Base Store
}

Layered puts an external store over the files: what the adapter has wins, what it does not have (or cannot say because it is unreachable) comes from the files, so the agent never loses the memory it had.

func (Layered) Get

func (l Layered) Get(ctx context.Context, name string) (Note, error)

func (Layered) List

func (l Layered) List(ctx context.Context) ([]Entry, error)

func (Layered) Put

func (l Layered) Put(ctx context.Context, name, text, ifVersion string) (Entry, error)

Put goes to the adapter; a store without write (or an unreachable one) falls to the files, which refuse when they have nowhere to write.

func (Layered) Search

func (l Layered) Search(ctx context.Context, query string, limit int) ([]Hit, error)

type Note

type Note struct {
	Entry
	Body string `json:"body"`
}

Note is an entry with its text, front matter taken off.

type Store

type Store interface {
	// List is every note, by name.
	List(ctx context.Context) ([]Entry, error)
	// Get reads one note; ErrNotFound when there is none.
	Get(ctx context.Context, name string) (Note, error)
	// Put writes a note. ifVersion, when not empty, is the version the writer read: a newer note is ErrConflict. It
	// answers the new entry.
	Put(ctx context.Context, name, text, ifVersion string) (Entry, error)
	// Search finds notes whose title or text holds the query (case-insensitive), at most limit of them (0: 20).
	Search(ctx context.Context, query string, limit int) ([]Hit, error)
}

Store is the memory contract.

func For

func For(files FileStore) Store

For is the store of a runtime: the files, with the first declared adapter over them when there is one.

Jump to

Keyboard shortcuts

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