Help us shape the future of Go! Take the 2026 Go Developer Survey

memory

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 16 Imported by: 0

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

View Source
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.

View Source
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.

View Source
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

func Pending

func Pending(ctx context.Context, s store.Store) (n int, since time.Time, err error)

Pending is Queue.Pending for a store alone, which is all `ynf doctor` has.

func StoreAt

func StoreAt(cwd string) (path, why string)

StoreAt names the ynm store ynf finds and why it is the one, or "" when there is none: the repository's own `.ynm/`, else the user's store.

Types

type Memory

type Memory interface {
	Remember(ctx context.Context, r Record) error
}

Memory is the port.

func Detect

func Detect(cwd string) (Memory, string)

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

func (q *Queue) Flush(ctx context.Context) int

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

func (q *Queue) Pending(ctx context.Context) (n int, since time.Time, err error)

Pending reports how many writes are queued and when the oldest was first queued; zero when none.

func (*Queue) Remember

func (q *Queue) Remember(ctx context.Context, r Record) error

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.

func (Ynm) Remember

func (y Ynm) Remember(ctx context.Context, r Record) error

Remember implements Memory.

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.

func (*YnmHTTP) Close

func (y *YnmHTTP) Close()

Close ends the session.

func (*YnmHTTP) Remember

func (y *YnmHTTP) Remember(ctx context.Context, r Record) error

Remember implements Memory, through ynm's memory_remember tool.

Jump to

Keyboard shortcuts

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