docs(memory): add comprehensive English godoc documentation
Add field-level comments to NoteMeta struct, enhance type and function documentation across vault.go and memory tools with usage context and behavioral details.
This commit is contained in:
parent
ac5b384f16
commit
f53e8dbe99
2 changed files with 35 additions and 9 deletions
|
|
@ -1,3 +1,18 @@
|
||||||
|
// Package memory implements an Obsidian-inspired markdown vault for persistent
|
||||||
|
// agent memory. Notes are plain markdown files with YAML frontmatter for
|
||||||
|
// metadata (title, tags, aliases, dates). The vault is folder-agnostic:
|
||||||
|
// organization comes from tags and [[wikilinks]], not directory structure.
|
||||||
|
//
|
||||||
|
// The vault generates an auto-maintained _index.md file containing a compact
|
||||||
|
// overview of all notes, tags, and aliases. This index is injected into the
|
||||||
|
// agent's system prompt so the LLM can efficiently query memory without
|
||||||
|
// reading every note.
|
||||||
|
//
|
||||||
|
// Key design constraints:
|
||||||
|
// - No external dependencies (hand-rolled frontmatter parser, pure stdlib)
|
||||||
|
// - No in-memory caches (reads from disk on demand, <10ms for <100 notes)
|
||||||
|
// - No mutexes (tools are called sequentially by the agent loop)
|
||||||
|
// - Backward compatible with the legacy MEMORY.md format
|
||||||
package memory
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -11,18 +26,20 @@ import (
|
||||||
|
|
||||||
// NoteMeta represents parsed frontmatter metadata from a single markdown note.
|
// NoteMeta represents parsed frontmatter metadata from a single markdown note.
|
||||||
type NoteMeta struct {
|
type NoteMeta struct {
|
||||||
Title string
|
Title string // Note title from frontmatter, or inferred from filename.
|
||||||
Created string
|
Created string // Creation date in YYYY-MM-DD format.
|
||||||
Updated string
|
Updated string // Last modification date in YYYY-MM-DD format.
|
||||||
Tags []string
|
Tags []string // Classification tags for search and filtering.
|
||||||
Aliases []string
|
Aliases []string // Alternate names for wikilink resolution.
|
||||||
RelPath string
|
RelPath string // Slash-separated path relative to the vault root.
|
||||||
Links []string
|
Links []string // Wikilink targets ([[target]]) extracted from the note body.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vault manages the memory vault: scanning, indexing, and searching notes.
|
// Vault manages the memory vault: scanning, indexing, and searching notes.
|
||||||
|
// All operations read from disk on demand with no in-memory caching, keeping
|
||||||
|
// the implementation stateless and safe for sequential tool calls.
|
||||||
type Vault struct {
|
type Vault struct {
|
||||||
memoryDir string
|
memoryDir string // Absolute path to the vault root directory.
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVault creates a new Vault rooted at the given memory directory.
|
// NewVault creates a new Vault rooted at the given memory directory.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// MemorySaveTool saves a structured note to the memory vault with frontmatter.
|
// MemorySaveTool saves a structured note to the memory vault with frontmatter.
|
||||||
|
// It auto-generates YAML frontmatter (title, created, updated, tags, aliases),
|
||||||
|
// preserves the original created date when updating an existing note, and
|
||||||
|
// rebuilds the vault index after every write.
|
||||||
type MemorySaveTool struct {
|
type MemorySaveTool struct {
|
||||||
vault *memory.Vault
|
vault *memory.Vault
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +105,10 @@ func (t *MemorySaveTool) Execute(ctx context.Context, args map[string]any) *Tool
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemorySearchTool searches the memory vault by tags, title, or text content.
|
// MemorySearchTool searches the memory vault by tags, title, or text content.
|
||||||
|
// Tags use AND logic (a note must match all specified tags). The text query
|
||||||
|
// matches case-insensitively against title, tags, and aliases. Results are
|
||||||
|
// capped at 20 entries and include metadata only — use MemoryRecallTool to
|
||||||
|
// read full note content.
|
||||||
type MemorySearchTool struct {
|
type MemorySearchTool struct {
|
||||||
vault *memory.Vault
|
vault *memory.Vault
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +186,9 @@ func (t *MemorySearchTool) Execute(ctx context.Context, args map[string]any) *To
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryRecallTool recalls specific notes from the memory vault by path or topic.
|
// MemoryRecallTool recalls specific notes from the memory vault by path or topic.
|
||||||
// Unlike memory_search which returns metadata, memory_recall returns full note content.
|
// Unlike MemorySearchTool which returns metadata only, MemoryRecallTool returns
|
||||||
|
// the full note body with frontmatter stripped. When using topic-based recall,
|
||||||
|
// it searches for matching notes and reads the top N (default 3).
|
||||||
type MemoryRecallTool struct {
|
type MemoryRecallTool struct {
|
||||||
vault *memory.Vault
|
vault *memory.Vault
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue