Documentation
¶
Index ¶
- Constants
- Variables
- func FormatFrontmatter(fm Frontmatter, body string) string
- func FormatTree(entries []TreeEntry) string
- func GitEnabledFromConfig(cfg *config.Config) bool
- type Chunk
- type ClaudeReranker
- type EmbeddingProvider
- type FileInfo
- type Frontmatter
- type GitBranchInfo
- type GitLogEntry
- type GitRepo
- func (g *GitRepo) AutoCommit(message string) error
- func (g *GitRepo) BranchInfo() (GitBranchInfo, error)
- func (g *GitRepo) Branches() ([]string, error)
- func (g *GitRepo) CreateBranch(name, fromRef string) error
- func (g *GitRepo) CurrentBranch() (string, error)
- func (g *GitRepo) DefaultBranch() (string, error)
- func (g *GitRepo) DeleteBranch(name string, force bool) error
- func (g *GitRepo) DiffRefs(baseRef, headRef, path string) (string, error)
- func (g *GitRepo) IsInitialized() bool
- func (g *GitRepo) ListMarkdownFilesAtRef(ref string) (map[string]string, error)
- func (g *GitRepo) Log(path string, count int) ([]GitLogEntry, error)
- func (g *GitRepo) LogWithBranch(path string, count int, branch string) ([]GitLogEntry, error)
- func (g *GitRepo) MergeBranch(source, target, strategy string) ([]string, error)
- func (g *GitRepo) ReadFileAtRef(ref, relPath string) (string, error)
- type Manager
- func (m *Manager) Append(relPath, content string) error
- func (m *Manager) AppendOnBranch(relPath, content, branch string) error
- func (m *Manager) Close()
- func (m *Manager) CreateBranch(name, fromRef string) error
- func (m *Manager) Delete(relPath string) error
- func (m *Manager) DeleteBranch(name string, force bool) error
- func (m *Manager) DeleteOnBranch(relPath, branch string) error
- func (m *Manager) DiffRefs(baseRef, headRef, relPath string) (string, error)
- func (m *Manager) Dir() string
- func (m *Manager) Get(relPath string, from, lines int) (string, error)
- func (m *Manager) GetAtRef(relPath string, from, lines int, ref string) (string, error)
- func (m *Manager) GitBranchInfo() (GitBranchInfo, error)
- func (m *Manager) GitBranches() (current string, branches []string, err error)
- func (m *Manager) GitEnabled() bool
- func (m *Manager) History(relPath string, count int) ([]GitLogEntry, error)
- func (m *Manager) HistoryWithBranch(relPath string, count int, branch string) ([]GitLogEntry, error)
- func (m *Manager) List() ([]FileInfo, error)
- func (m *Manager) ListAtRef(ref string) ([]FileInfo, error)
- func (m *Manager) MergeBranch(source, target, strategy string) error
- func (m *Manager) Move(from, to string) error
- func (m *Manager) MoveOnBranch(from, to, branch string) error
- func (m *Manager) Pin(relPath string) error
- func (m *Manager) PinOnBranch(relPath, branch string) error
- func (m *Manager) Read(relPath string) (string, error)
- func (m *Manager) ReadAtRef(relPath string, ref string) (string, error)
- func (m *Manager) ReadFileFrontmatter(relPath string) (Frontmatter, error)
- func (m *Manager) Search(query string, opts SearchOpts) ([]SearchResult, error)
- func (m *Manager) SetReranker(r Reranker)
- func (m *Manager) StartWatcher() (stop func(), err error)
- func (m *Manager) Sync(relPath string) error
- func (m *Manager) SystemFiles(maxChars int) (map[string]string, error)
- func (m *Manager) Tree() ([]TreeEntry, error)
- func (m *Manager) TreeAtRef(ref string) ([]TreeEntry, error)
- func (m *Manager) Unpin(relPath string) error
- func (m *Manager) UnpinOnBranch(relPath, branch string) error
- func (m *Manager) Write(content, file string) error
- func (m *Manager) WriteFile(relPath, content, commitMsg string) error
- func (m *Manager) WriteFileOnBranch(relPath, content, commitMsg, branch string) error
- func (m *Manager) WriteWithCommitMessage(content, file, commitMsg string) error
- func (m *Manager) WriteWithCommitMessageOnBranch(content, file, commitMsg, branch string) error
- type ManagerOptions
- type MemoryStore
- type OllamaProvider
- type OpenAIProvider
- type RepoStoreResolution
- type Reranker
- type SearchOpts
- type SearchResult
- type TreeEntry
Constants ¶
const DefaultRerankModel = "claude-haiku-4-5-20251001"
DefaultRerankModel is the default Claude model used for re-ranking.
Variables ¶
var ( ErrPathEscape = errors.New("path escapes memory directory") ErrReadOnly = errors.New("file is marked read-only") ErrFileNotFound = errors.New("memory file not found") ErrAlreadyPinned = errors.New("file is already in system/") ErrNotPinned = errors.New("file is not in system/") )
Sentinel errors for memory operations.
var ErrNoChanges = errors.New("no changes to commit")
ErrNoChanges is returned by AutoCommit when the working tree is clean.
var ErrRepoBusy = errors.New("memory repo busy")
ErrRepoBusy is returned when a memory repo lock cannot be acquired in time.
Functions ¶
func FormatFrontmatter ¶
func FormatFrontmatter(fm Frontmatter, body string) string
FormatFrontmatter prepends a YAML frontmatter block to body. If fm is zero-value, body is returned unchanged.
func FormatTree ¶
FormatTree renders entries as a compact ASCII tree suitable for CLAUDE.md injection.
func GitEnabledFromConfig ¶
GitEnabledFromConfig returns whether memory git versioning should be enabled. Defaults to true when unset.
Types ¶
type ClaudeReranker ¶
type ClaudeReranker struct {
// contains filtered or unexported fields
}
ClaudeReranker uses a local claude CLI process to re-rank FTS5 keyword results by semantic relevance. It works with any claude auth method — API key or Max subscription — because auth is handled by the claude binary.
func NewClaudeReranker ¶
func NewClaudeReranker(model string) (*ClaudeReranker, error)
NewClaudeReranker creates a ClaudeReranker. If model is empty, defaults to claude-haiku-4-5-20251001. Returns an error if the claude binary is not found in PATH.
func (*ClaudeReranker) Rerank ¶
func (r *ClaudeReranker) Rerank(query string, results []SearchResult) ([]SearchResult, error)
Rerank re-orders results by semantic relevance to the query. On any error (timeout, parse failure, claude unavailable), it returns the original results unchanged — search still works via FTS5 order.
type EmbeddingProvider ¶
type EmbeddingProvider interface {
Embed(texts []string) ([][]float32, error)
Dims() int
Name() string
}
EmbeddingProvider abstracts an embedding API.
type FileInfo ¶
type FileInfo struct {
Path string // relative to memory dir
SizeBytes int64
UpdatedAt int64 // Unix ms
ChunkCount int
}
FileInfo is metadata about one memory file, returned by List.
type Frontmatter ¶
type Frontmatter struct {
Description string `yaml:"description,omitempty"`
ReadOnly bool `yaml:"read-only,omitempty"`
Tags []string `yaml:"tags,omitempty"`
Source string `yaml:"source,omitempty"`
Limit int `yaml:"limit,omitempty"`
Metadata map[string]interface{} `yaml:"metadata,omitempty"`
Extra map[string]interface{} `yaml:"-"`
}
Frontmatter is optional YAML metadata at the top of a memory file.
func ParseFrontmatter ¶
func ParseFrontmatter(content string) (Frontmatter, string)
ParseFrontmatter extracts YAML frontmatter from content. If no frontmatter is present, it returns a zero-value Frontmatter and the full content unchanged. Frontmatter must be delimited by "---" on its own line.
type GitBranchInfo ¶
type GitBranchInfo struct {
Current string `json:"current"`
Default string `json:"default"`
All []string `json:"all"`
}
GitBranchInfo describes branch metadata for a memory repo.
type GitLogEntry ¶
type GitLogEntry struct {
SHA string `json:"sha"`
ParentSHA string `json:"parent_sha,omitempty"`
Message string `json:"message"`
Date string `json:"date"`
AuthorName string `json:"author_name,omitempty"`
AuthorEmail string `json:"author_email,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
Branch string `json:"branch,omitempty"`
Files []string `json:"files,omitempty"`
}
GitLogEntry represents a single commit in the memory git log.
type GitRepo ¶
type GitRepo struct {
// contains filtered or unexported fields
}
GitRepo manages a git repository for memory versioning.
func InitGitRepo ¶
InitGitRepo initialises a git repo in dir if one doesn't already exist. It creates a .gitignore that excludes the .index/ directory. This is idempotent — calling it on an already-initialised repo is safe.
func (*GitRepo) AutoCommit ¶
AutoCommit stages all changes and commits with the given message. Returns ErrNoChanges if the working tree is clean.
func (*GitRepo) BranchInfo ¶
func (g *GitRepo) BranchInfo() (GitBranchInfo, error)
BranchInfo returns current/default branch and the complete branch list.
func (*GitRepo) CreateBranch ¶
CreateBranch creates a new branch from fromRef (or default branch when empty).
func (*GitRepo) CurrentBranch ¶
CurrentBranch returns the currently checked-out branch name.
func (*GitRepo) DefaultBranch ¶
DefaultBranch returns the preferred default branch for this memory repo.
func (*GitRepo) DeleteBranch ¶
DeleteBranch deletes a branch. If force=true it uses -D.
func (*GitRepo) DiffRefs ¶
DiffRefs returns the git diff between two refs. Optional path limits the diff.
func (*GitRepo) IsInitialized ¶
IsInitialized returns true if the directory contains a .git directory.
func (*GitRepo) ListMarkdownFilesAtRef ¶
ListMarkdownFilesAtRef returns markdown files and raw content at a ref.
func (*GitRepo) Log ¶
func (g *GitRepo) Log(path string, count int) ([]GitLogEntry, error)
Log returns the most recent commits, optionally filtered by file path. If path is empty, all commits are returned.
func (*GitRepo) LogWithBranch ¶
LogWithBranch returns the most recent commits on a specific branch/ref. When branch is empty, history is read from HEAD.
func (*GitRepo) MergeBranch ¶
MergeBranch merges source into target (or default branch when target is empty). Supported strategies: "ff-only" (default), "no-ff".
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the primary interface for IDE-wide memory operations. It is safe for concurrent use from multiple goroutines (or processes via WAL).
func NewManager ¶
func NewManager(dir string, provider EmbeddingProvider) (*Manager, error)
NewManager opens (or creates) a MemoryManager rooted at dir. provider may be nil for keyword-only search.
func NewManagerFromConfig ¶
NewManagerFromConfig creates a MemoryManager from the application config. Returns (nil, nil) if memory is disabled or not configured.
func NewManagerWithOptions ¶
func NewManagerWithOptions(dir string, provider EmbeddingProvider, opts ManagerOptions) (*Manager, error)
NewManagerWithOptions opens (or creates) a MemoryManager rooted at dir with explicit options.
func (*Manager) Append ¶
Append adds content to an existing memory file, re-indexes, and auto-commits.
func (*Manager) AppendOnBranch ¶
AppendOnBranch adds content to an existing memory file and commits it to the selected branch.
func (*Manager) CreateBranch ¶
CreateBranch creates a memory git branch from an optional source ref.
func (*Manager) DeleteBranch ¶
DeleteBranch deletes a memory git branch.
func (*Manager) DeleteOnBranch ¶
DeleteOnBranch removes a memory file on the selected branch.
func (*Manager) GetAtRef ¶
GetAtRef reads lines from a memory file at a specific git ref. from=0 means start; lines=0 means all.
func (*Manager) GitBranchInfo ¶
func (m *Manager) GitBranchInfo() (GitBranchInfo, error)
GitBranchInfo returns current/default branch and all branches for this memory repo.
func (*Manager) GitBranches ¶
GitBranches returns the current branch and all branch names for this memory git repo. When git versioning is disabled it returns zero values.
func (*Manager) GitEnabled ¶
GitEnabled reports whether git versioning is active for this manager.
func (*Manager) History ¶
func (m *Manager) History(relPath string, count int) ([]GitLogEntry, error)
History returns git log entries for a file, or all files if relPath is empty. Returns nil if git is not available.
func (*Manager) HistoryWithBranch ¶
func (m *Manager) HistoryWithBranch(relPath string, count int, branch string) ([]GitLogEntry, error)
HistoryWithBranch returns git log entries for a file on a specific branch/ref.
func (*Manager) ListAtRef ¶
ListAtRef returns metadata for all markdown files at a specific git ref.
func (*Manager) MergeBranch ¶
MergeBranch merges source into target branch and re-syncs changed markdown files when the target is the default branch.
func (*Manager) MoveOnBranch ¶
MoveOnBranch renames/moves a memory file on the selected branch.
func (*Manager) PinOnBranch ¶
PinOnBranch moves a file into system/ on the selected branch.
func (*Manager) ReadAtRef ¶
ReadAtRef returns the body of a memory file with frontmatter stripped at a specific ref.
func (*Manager) ReadFileFrontmatter ¶
func (m *Manager) ReadFileFrontmatter(relPath string) (Frontmatter, error)
ReadFileFrontmatter reads a memory file's frontmatter without loading the full file. It reads up to maxBytes from the start of the file.
func (*Manager) Search ¶
func (m *Manager) Search(query string, opts SearchOpts) ([]SearchResult, error)
Search performs hybrid search: FTS5 BM25 + optional cosine similarity, followed by optional Claude-based re-ranking.
func (*Manager) SetReranker ¶
SetReranker configures an optional post-FTS5 reranker. Safe to call before the Manager is used for searches.
func (*Manager) StartWatcher ¶
StartWatcher watches the memory directory (recursively) for file changes and triggers re-indexing + auto-commit. Returns a stop function.
func (*Manager) SystemFiles ¶
SystemFiles reads all files from system/ up to maxChars total. Returns a map of relative path → body content (frontmatter stripped).
func (*Manager) Tree ¶
Tree returns all .md files in the memory directory with frontmatter descriptions.
func (*Manager) TreeAtRef ¶
TreeAtRef returns the markdown tree with descriptions at a specific git ref.
func (*Manager) UnpinOnBranch ¶
UnpinOnBranch moves a file out of system/ on the selected branch.
func (*Manager) Write ¶
Write appends content to a named memory file and triggers re-indexing. If file is empty, the default is today's date (YYYY-MM-DD.md).
func (*Manager) WriteFile ¶
WriteFile creates or overwrites a memory file, re-indexes, and auto-commits.
func (*Manager) WriteFileOnBranch ¶
WriteFileOnBranch creates or overwrites a memory file and commits it to the selected branch.
func (*Manager) WriteWithCommitMessage ¶
WriteWithCommitMessage appends content to a named memory file, re-indexes, and commits with the provided commit message when git is enabled. If commitMsg is empty, a default message is generated.
func (*Manager) WriteWithCommitMessageOnBranch ¶
WriteWithCommitMessageOnBranch appends content to a named memory file and commits to the selected branch when provided. When branch is empty, it writes to the repository default branch.
type ManagerOptions ¶
type ManagerOptions struct {
// GitEnabled controls whether the memory store is git-versioned.
// Defaults to true when NewManager is used.
GitEnabled bool
}
ManagerOptions configures optional manager behaviors.
type MemoryStore ¶
type MemoryStore interface {
Dir() string
GitEnabled() bool
Search(query string, opts SearchOpts) ([]SearchResult, error)
Read(relPath string) (string, error)
ReadAtRef(relPath, ref string) (string, error)
Get(relPath string, from, lines int) (string, error)
GetAtRef(relPath string, from, lines int, ref string) (string, error)
List() ([]FileInfo, error)
ListAtRef(ref string) ([]FileInfo, error)
Tree() ([]TreeEntry, error)
TreeAtRef(ref string) ([]TreeEntry, error)
History(relPath string, count int) ([]GitLogEntry, error)
HistoryWithBranch(relPath string, count int, branch string) ([]GitLogEntry, error)
WriteWithCommitMessage(content, file, commitMsg string) error
WriteWithCommitMessageOnBranch(content, file, commitMsg, branch string) error
WriteFile(relPath, content, commitMsg string) error
WriteFileOnBranch(relPath, content, commitMsg, branch string) error
Append(relPath, content string) error
AppendOnBranch(relPath, content, branch string) error
Move(from, to string) error
MoveOnBranch(from, to, branch string) error
Delete(relPath string) error
DeleteOnBranch(relPath, branch string) error
Pin(relPath string) error
PinOnBranch(relPath, branch string) error
Unpin(relPath string) error
UnpinOnBranch(relPath, branch string) error
GitBranches() (current string, branches []string, err error)
GitBranchInfo() (GitBranchInfo, error)
CreateBranch(name, fromRef string) error
DeleteBranch(name string, force bool) error
MergeBranch(source, target, strategy string) error
DiffRefs(baseRef, headRef, relPath string) (string, error)
}
MemoryStore defines the local memory operations surface used by higher layers. It intentionally maps to the current Manager API so future daemon/remote adapters can satisfy the same contract.
type OllamaProvider ¶
type OllamaProvider struct {
URL string // e.g. "http://localhost:11434"
Model string // e.g. "nomic-embed-text"
// contains filtered or unexported fields
}
OllamaProvider calls a local Ollama server for embeddings.
func NewOllamaProvider ¶
func NewOllamaProvider(url, model string) *OllamaProvider
func (*OllamaProvider) Dims ¶
func (p *OllamaProvider) Dims() int
func (*OllamaProvider) Name ¶
func (p *OllamaProvider) Name() string
type OpenAIProvider ¶
type OpenAIProvider struct {
APIKey string
Model string // default "text-embedding-3-small"
// contains filtered or unexported fields
}
OpenAIProvider calls the OpenAI embeddings API.
func NewOpenAIProvider ¶
func NewOpenAIProvider(apiKey, model string) *OpenAIProvider
func (*OpenAIProvider) Dims ¶
func (p *OpenAIProvider) Dims() int
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
type RepoStoreResolution ¶
type RepoStoreResolution struct {
CanonicalSlug string
CanonicalPath string
LegacySlug string
LegacyPath string
}
RepoStoreResolution describes canonical and legacy per-repo memory locations. LegacyPath is only set when both canonical and legacy dirs currently exist.
func ResolveRepoStorePaths ¶
func ResolveRepoStorePaths(baseDir, repoPath, worktreePath string) (RepoStoreResolution, error)
ResolveRepoStorePaths resolves canonical/legacy repo memory dirs and performs one-time migration from legacy (worktree-derived slug) to canonical (repo-derived slug) when canonical does not yet exist.
type Reranker ¶
type Reranker interface {
Rerank(query string, results []SearchResult) ([]SearchResult, error)
Name() string
}
Reranker re-orders search results by semantic relevance to a query. It is applied as a post-processing step after FTS5 keyword retrieval, without requiring any embedding storage.
type SearchOpts ¶
SearchOpts configures a Search call.