Documentation
¶
Overview ¶
Package memory is ynf's memory port (ADR-008, ADR-012): ynm when it is installed, nothing when it is not. ynf writes what only it can see, outcomes and failures recurring across runs; it never decides anything with memory, and never puts memory into an agent's task: a harness that wants memory connects its agent to ynm itself.
Index ¶
Constants ¶
const ClaimTTL = 5 * time.Minute
ClaimTTL is how long a claim on a queued record holds. A worker that died mid-send leaves its claim behind; after this another may retake the record.
const QueueCap = 1000
QueueCap bounds the queue: past it the oldest records are dropped, so a ynm that never comes back cannot fill the store.
const QueuePrefix = "memory/queue/"
QueuePrefix is where queued writes live in ynf's store: one document per record, keyed by a ULID so the keys sort oldest first.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Memory ¶
Memory is the port.
func Detect ¶
Detect returns ynm when it is on PATH and a store is present, or nil and the reason it is not (ADR-012: detected, never required). It looks where ynm itself writes: a repository's own `.ynm/` (at the root of the git repository cwd is in, which for a linked worktree is the main repository's too; cwd is the directory ynm runs from, the working directory when empty), then the user's store, which is $YNM_HOME when that is set and only then ~/.ynm. Nothing is found by walking up past the repository root, so ~/.ynm is never taken for a project's store.
type Queue ¶
type Queue struct {
Memory Memory
Store store.Store
Owner string // this process, unique among the workers sharing the store
Now func() time.Time
NewID func() string // ULIDs
Log *slog.Logger
// Cap and ClaimTTL default to QueueCap and ClaimTTL.
Cap int
ClaimTTL time.Duration
// contains filtered or unexported fields
}
Queue sends records to Memory and keeps the ones it cannot in the store until it can (ADR-008): a ynm outage loses nothing and never stops a step. Records are sent oldest first, and a record is claimed with a conditional write before it is sent, so two workers sharing a store never send the same one.
func (*Queue) Flush ¶
Flush sends queued records oldest first, deleting each once sent, and stops at the first that fails: ynm is still down, so the rest stay queued. It returns how many are left, counting those another worker has claimed. With nothing queued it costs one Keys call.
func (*Queue) Pending ¶
Pending reports how many writes are queued and when the oldest was first queued; zero when none.
func (*Queue) Remember ¶
Remember sends the record, behind anything already queued: it first flushes, and only when nothing is left does it send directly, so records do not jump the queue. A record that cannot be sent is queued. It never fails because ynm does; an error means it could not even be queued.
type Queued ¶
type Queued struct {
Record Record `json:"record"`
Queued time.Time `json:"queued"` // when it was first queued
Attempts int `json:"attempts"` // sends tried, including one in flight
ClaimedBy string `json:"claimedBy,omitempty"`
ClaimedAt time.Time `json:"claimedAt,omitempty"`
}
Queued is the document for one record waiting to be sent.
type Record ¶
type Record struct {
Type string // episodic
Namespace string // factory/<host>/<owner>/<repo>
Level string // personal or distributed; empty is ynm's default, personal
Subject string // the item key, or a failure signature
Summary string // one line
Content string // markdown
Tags []string
DataSchema string // ynf.step.v1, ynf.failure.v1: ynf owns these schemas
Data map[string]any
Source string // the step that wrote it
}
Record is one memory ynf writes.
type Ynm ¶
type Ynm struct {
Bin string // default "ynm"
Cwd string // the directory ynm runs as if from; default the process's
}
Ynm talks to ynm through its CLI, which works against whatever store ynm is configured for.
type YnmHTTP ¶
type YnmHTTP struct {
Endpoint string
Token string
// Transport overrides the connection, for tests.
Transport func() mcp.Transport
// contains filtered or unexported fields
}
YnmHTTP talks to a hosted ynm over its MCP HTTP endpoint (ADR-008): the shared store for a pool of workers or CI, where many writers go through one server. It authenticates with a bearer token, such as a machine token from the identity provider's client-credentials grant, whose subject is the writer in ynm's audit log.