memory

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRoot = "."
	DefaultFile = "memory.md"
)
View Source
const (
	StagedActionAdd     = "add"
	StagedActionReplace = "replace"
	StagedActionRemove  = "remove"
)

Staged action kinds for pending.json (empty Action = legacy encoded Content).

View Source
const DefaultMemoryCharLimit = 2200

DefaultMemoryCharLimit is the default memory.md body size budget (runes).

View Source
const MemoryToolDescription = `` /* 1171-byte string literal not displayed */

MemoryToolDescription is the main-agent memory tool prompt (aligned with Hermes WHEN/HOW/SKIP, adapted for memory.md + per-turn prompt freeze).

Variables

This section is empty.

Functions

func EntryContents

func EntryContents(entries []MemoryEntry) []string

EntryContents returns trimmed entry bodies for tool errors.

func FormatMemoryPolicyStatus

func FormatMemoryPolicyStatus(memoryWrite string, fromFile bool) string

FormatMemoryPolicyStatus renders /memory policy output.

func FormatMemoryPromptBody

func FormatMemoryPromptBody(entries []MemoryEntry) string

FormatMemoryPromptBody renders deduped entries for prompt injection (blank lines between facts).

func FormatMemoryUsage

func FormatMemoryUsage(used, limit int) string

FormatMemoryUsage returns a compact usage string such as "1474/2200".

func JoinUnderRoot

func JoinUnderRoot(root string, parts ...string) string

JoinUnderRoot joins segments under memoryRoot (".", "global:.", "local:memory", …).

func LedgerRel

func LedgerRel(root string) string

func LegacyStagedContentSummary

func LegacyStagedContentSummary(content string) string

LegacyStagedContentSummary decodes pre-structured pending payloads.

func LegacyStagedKind

func LegacyStagedKind(content string) (action, oldText, newContent string)

LegacyStagedKind classifies a legacy Content-only staged row.

func LooksLikeSecret

func LooksLikeSecret(s string) bool

LooksLikeSecret rejects content that may contain credentials.

func MemoryFileRel

func MemoryFileRel(root, file string) string

func MemoryPolicyRel

func MemoryPolicyRel(root string) string

func NormalizeMemoryToolAction

func NormalizeMemoryToolAction(action string) string

func RenderMemory

func RenderMemory(entries []MemoryEntry) string

RenderMemory serializes entries into a memory.md file body.

func RenderMemoryDocument

func RenderMemoryDocument(entries []MemoryEntry, docName string) string

RenderMemoryDocument serializes §-delimited entries with a file title header.

func SkillsPolicyRel

func SkillsPolicyRel(root string) string

func StagedDirRel

func StagedDirRel(root string) string

func StagedPendingSummary

func StagedPendingSummary(e StagedMemory) string

StagedPendingSummary is a human-readable line for /memory pending.

Types

type MemoryAddResult

type MemoryAddResult struct {
	Outcome capmemory.AddOutcome
}

MemoryAddResult is the outcome of MemoryStore.Add.

type MemoryAtCapacityError

type MemoryAtCapacityError struct {
	Used    int
	Limit   int
	Adding  int
	Entries []MemoryEntry
}

MemoryAtCapacityError is returned when a write would exceed the char limit.

func (*MemoryAtCapacityError) Error

func (e *MemoryAtCapacityError) Error() string

type MemoryEntry

type MemoryEntry = capmemory.MemoryEntry

MemoryEntry is one §-delimited block in memory.md (same shape as cap/memory).

func DedupeMemoryEntries

func DedupeMemoryEntries(entries []MemoryEntry) []MemoryEntry

DedupeMemoryEntries merges a list in order (later entries can replace earlier subsets).

func MergeMemoryAdd

func MergeMemoryAdd(entries []MemoryEntry, content string) ([]MemoryEntry, capmemory.AddOutcome)

MergeMemoryAdd integrates one fact into existing entries (exact + substring rules).

func ParseMemory

func ParseMemory(raw string) []MemoryEntry

ParseMemory splits a memory.md body into entries.

type MemoryLedger

type MemoryLedger struct {
	Path string
}

MemoryLedger appends JSON lines under memory/ledger.jsonl (not injected into prompts).

func (*MemoryLedger) Append

func (l *MemoryLedger) Append(ev MemoryLedgerEvent) error

func (*MemoryLedger) Rewrite

func (l *MemoryLedger) Rewrite(events []MemoryLedgerEvent) error

Rewrite truncates and rewrites the ledger (tests).

type MemoryLedgerEvent

type MemoryLedgerEvent struct {
	Action  string    `json:"action"`
	Content string    `json:"content,omitempty"`
	Match   string    `json:"match,omitempty"`
	Source  string    `json:"source,omitempty"`
	At      time.Time `json:"at"`
}

MemoryLedgerEvent is one append-only audit row for memory.md changes.

type MemoryPolicyStore

type MemoryPolicyStore struct {
	Path string
}

MemoryPolicyStore persists memory/policy.json under memoryRoot.

func (*MemoryPolicyStore) Load

func (*MemoryPolicyStore) Save

type MemoryStore

type MemoryStore struct {
	Path      string
	CharLimit int
	// DocName is the file title in the on-disk header (default memory.md).
	DocName string
}

MemoryStore reads and writes a §-delimited memory.md file with capacity limits.

func NewMemoryStore

func NewMemoryStore(path string, charLimit int) *MemoryStore

NewMemoryStore opens a store at path with the given char limit.

func (*MemoryStore) Add

func (s *MemoryStore) Add(content string) (MemoryAddResult, error)

Add merges one fact into memory.md on disk.

func (*MemoryStore) Load

func (s *MemoryStore) Load() ([]MemoryEntry, error)

Load reads all entries from disk.

func (*MemoryStore) Remove

func (s *MemoryStore) Remove(oldText string) (string, error)

Remove deletes the entry whose body contains oldText.

func (*MemoryStore) Replace

func (s *MemoryStore) Replace(oldText, content string) (MemoryAddResult, error)

Replace updates the entry whose body contains oldText.

func (*MemoryStore) Save

func (s *MemoryStore) Save(entries []MemoryEntry) error

Save writes entries atomically.

func (*MemoryStore) TotalChars

func (s *MemoryStore) TotalChars(entries []MemoryEntry) int

TotalChars counts runes across entry bodies.

type MemoryToolInput

type MemoryToolInput = capmemory.MemoryToolInput

type MemoryToolOutput

type MemoryToolOutput = capmemory.MemoryToolOutput

type MemoryWritePolicy

type MemoryWritePolicy struct {
	MemoryWrite string `json:"memoryWrite,omitempty"` // approve | auto
}

MemoryWritePolicy is tenant-local background-review memory write mode.

func (MemoryWritePolicy) Normalized

func (p MemoryWritePolicy) Normalized() MemoryWritePolicy

type StagedMemory

type StagedMemory struct {
	ID        string    `json:"id"`
	Action    string    `json:"action,omitempty"`  // add | replace | remove; empty = legacy Content encoding
	OldText   string    `json:"oldText,omitempty"` // replace/remove match substring
	Content   string    `json:"content"`           // add body or replace new text
	Source    string    `json:"source"`
	CreatedAt time.Time `json:"createdAt"`
}

StagedMemory is a pending memory write awaiting approval.

func NormalizeStagedEntry

func NormalizeStagedEntry(e StagedMemory) StagedMemory

NormalizeStagedEntry fills Action/OldText/Content from legacy Content encoding when needed.

type StagedStore

type StagedStore struct {
	Dir string
}

StagedStore persists pending memory entries under workspace local root.

func (*StagedStore) Add

func (s *StagedStore) Add(entry StagedMemory) error

func (*StagedStore) Clear

func (s *StagedStore) Clear() error

Clear removes all staged entries.

func (*StagedStore) List

func (s *StagedStore) List() ([]StagedMemory, error)

func (*StagedStore) Remove

func (s *StagedStore) Remove(id string) (StagedMemory, error)

Jump to

Keyboard shortcuts

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