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
- Variables
- type Entry
- type ExtStore
- func (s *ExtStore) Can(capability string) bool
- func (s *ExtStore) Get(ctx context.Context, name string) (Note, error)
- func (s *ExtStore) List(ctx context.Context) ([]Entry, error)
- func (s *ExtStore) Name() string
- func (s *ExtStore) Put(ctx context.Context, name, text, ifVersion string) (Entry, error)
- func (s *ExtStore) Search(ctx context.Context, query string, limit int) ([]Hit, error)
- type FileStore
- func (s FileStore) Get(_ context.Context, name string) (Note, error)
- func (s FileStore) List(context.Context) ([]Entry, error)
- func (s FileStore) Put(_ context.Context, name, text, ifVersion string) (Entry, error)
- func (s FileStore) Search(ctx context.Context, query string, limit int) ([]Hit, error)
- type Hit
- type Layered
- func (l Layered) Get(ctx context.Context, name string) (Note, error)
- func (l Layered) List(ctx context.Context) ([]Entry, error)
- func (l Layered) Put(ctx context.Context, name, text, ifVersion string) (Entry, error)
- func (l Layered) Search(ctx context.Context, query string, limit int) ([]Hit, error)
- type Note
- type Store
Constants ¶
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 ¶
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 ¶
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 ¶
NewExtStore is the store of an adapter that has described itself.
func Register ¶
Register asks the adapter to describe itself and, when it speaks the memory protocol, makes a store of it.
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.
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 ¶
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.
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.