memory

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextCategory = "_context"
)

Variables

This section is empty.

Functions

func BuildMemoryPrompt

func BuildMemoryPrompt(store *Store) string

BuildMemoryPrompt generates the prompt section content from memory store.

func BuildReinjectMessage added in v0.23.0

func BuildReinjectMessage(items []CriticalContext) string

BuildReinjectMessage formats critical context items into a user message to be appended after the compaction summary.

func Register

func Register(e *sdk.Extension)

Register registers the memory extension's tools, commands, and event handlers onto e, and schedules OnInit work via OnInitAppend.

Types

type CriticalContext added in v0.23.0

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

CriticalContext holds a re-injectable context item after compaction.

func GatherCriticalContext added in v0.23.0

func GatherCriticalContext(s *Store) []CriticalContext

GatherCriticalContext reads the memory store for context that should survive compaction. It collects plan content, recent edits, and other high-value facts.

type Extractor

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

Extractor writes structured facts from each turn to the memory store.

func NewExtractor

func NewExtractor(store *Store) *Extractor

NewExtractor creates an extractor backed by the given store.

func (*Extractor) Extract

func (e *Extractor) Extract(eventData json.RawMessage) error

Extract parses turn data and writes facts to the store. It's designed to be called from an EventTurnEnd handler.

type Fact

type Fact struct {
	Key        string    `json:"key"`
	Value      string    `json:"value"`
	Category   string    `json:"category,omitzero"`
	Relations  []string  `json:"relations,omitzero"`
	Importance int       `json:"importance,omitzero"` // 0 = default; higher = more important
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

Fact is a single key/value memory entry with optional category and relations.

func Related(s *Store, startKey string, maxDepth int) []Fact

Related returns all facts reachable from startKey via relation edges, up to maxDepth hops. Returns empty slice if startKey doesn't exist. maxDepth <= 0 means unlimited (capped at maxGraphDepth to prevent runaway). The startKey itself is excluded from results. Results are sorted by key for deterministic output.

type Store

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

Store holds facts in memory backed by a JSONL file.

func NewStore

func NewStore(cwd string) (*Store, error)

NewStore creates a Store whose file path is derived from the sha256 of cwd. Existing facts are loaded if the file is present.

func (*Store) Clear

func (s *Store) Clear() error

Clear removes all facts and deletes the backing file.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a fact by key, cleans up its relations, and rewrites the file.

func (*Store) Get

func (s *Store) Get(key string) (Fact, bool)

Get retrieves a fact by key.

func (*Store) List

func (s *Store) List(category string) []Fact

List returns all facts, optionally filtered by category. Results are sorted by key for deterministic output.

func (*Store) Path

func (s *Store) Path() string

Path returns the backing file path.

func (*Store) Relate

func (s *Store) Relate(keyA, keyB string) error

Relate creates a bidirectional link between two facts. Both keys must exist. Idempotent — duplicate relations are ignored.

func (*Store) Set

func (s *Store) Set(key, value, category string) error

Set upserts a fact. CreatedAt is preserved on update.

func (*Store) SetImportance added in v0.23.0

func (s *Store) SetImportance(key string, importance int) error

SetImportance updates the Importance field of an existing fact. No-op if the key does not exist. Use importance values > 0 to signal higher priority; 0 is the default (unset).

func (*Store) Unrelate

func (s *Store) Unrelate(keyA, keyB string) error

Unrelate removes a bidirectional link between two facts.

type TurnData

type TurnData struct {
	Assistant   json.RawMessage   `json:"Assistant"`
	ToolResults []json.RawMessage `json:"ToolResults"`
}

TurnData represents the relevant data from an EventTurnEnd, parsed from JSON.

type WireMsg added in v0.23.0

type WireMsg = compact.WireMsg

WireMsg is an alias for compact.WireMsg — re-exported for backward compatibility with any callers within the memory package that use the name directly.

type WireToolResult added in v0.23.0

type WireToolResult = compact.WireToolResult

WireToolResult is an alias for compact.WireToolResult — re-exported for backward compatibility with any callers within the memory package.

Directories

Path Synopsis
Memory extension binary.
Memory extension binary.

Jump to

Keyboard shortcuts

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