memory

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

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

Index manages the SQLite FTS5 index for memory search.

func NewIndex

func NewIndex(dbPath string) (*Index, error)

NewIndex opens (or creates) the SQLite database at dbPath, initializes the schema, and configures WAL mode with a busy timeout.

func (*Index) Close

func (idx *Index) Close() error

Close closes the underlying database connection.

func (*Index) List

func (idx *Index) List(scope string, topic string) ([]MemoryEntry, error)

List returns all memories, optionally filtered by scope and/or topic.

func (*Index) Rebuild

func (idx *Index) Rebuild(projectDir, globalDir string) error

Rebuild drops all rows and re-indexes markdown files from both directories.

func (*Index) Remove

func (idx *Index) Remove(name string) error

Remove deletes a memory from the index by name.

func (*Index) Search

func (idx *Index) Search(query string, scope string) ([]MemoryEntry, error)

Search performs a full-text search over the index, optionally filtered by scope. Returns up to 20 results ordered by FTS5 rank.

func (*Index) Upsert

func (idx *Index) Upsert(name, filePath, scope, content string) error

Upsert inserts or replaces a memory in the index. It extracts title, headings, and tags from the markdown content automatically.

type MemoryEntry

type MemoryEntry struct {
	Name     string
	FilePath string
	Scope    string // "project" or "global"
	Topic    string
	Title    string
	Summary  string
	Rank     float64 // FTS5 rank (populated for search results)
}

MemoryEntry represents a single memory record with its metadata.

type MemoryStore

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

MemoryStore provides CRUD operations for markdown-based memories with SQLite FTS5 indexing. It manages two directories: project-local and global.

func NewMemoryStore

func NewMemoryStore(projectDir, globalDir, indexDBPath string, logger *slog.Logger) (*MemoryStore, error)

NewMemoryStore creates a MemoryStore with the given directories and index DB path. Both projectDir and globalDir are created if they do not exist.

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close closes the underlying index.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(name string) error

Delete removes a memory file and its index entry.

func (*MemoryStore) Edit

func (s *MemoryStore) Edit(name string, editFn func(content string) string) error

Edit reads a memory, applies editFn to its content, and writes the result back.

func (*MemoryStore) Index

func (s *MemoryStore) Index() *Index

Index returns the underlying Index for direct access (e.g., by the watcher).

func (*MemoryStore) List

func (s *MemoryStore) List(scope string, topic string) ([]MemoryEntry, error)

List returns all memories, optionally filtered by scope and topic.

func (*MemoryStore) Read

func (s *MemoryStore) Read(name string) (string, error)

Read returns the content of a memory by name.

func (*MemoryStore) Rename

func (s *MemoryStore) Rename(oldName, newName string) error

Rename moves a memory from oldName to newName. This supports cross-scope moves.

func (*MemoryStore) Search

func (s *MemoryStore) Search(query string, scope string) ([]MemoryEntry, error)

Search performs a full-text search over all memories.

func (*MemoryStore) Write

func (s *MemoryStore) Write(name, content string) error

Write creates or overwrites a memory. The name determines scope and path:

  • "global/foo" -> globalDir/foo.md (scope=global)
  • "foo" -> projectDir/foo.md (scope=project)
  • "topic/sub/name" -> projectDir/topic/sub/name.md (scope=project)

type Scope

type Scope string

Scope represents the storage scope for a memory.

const (
	// ScopeProject stores memories in the project's .helix/memories/ directory.
	ScopeProject Scope = "project"
	// ScopeGlobal stores memories in ~/.helix/memories/.
	ScopeGlobal Scope = "global"
)

type Watcher

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

Watcher monitors memory directories for file changes and auto-updates the SQLite FTS5 index. It debounces events to avoid redundant rebuilds.

func NewWatcher

func NewWatcher(index *Index, projectDir, globalDir string, logger *slog.Logger) (*Watcher, error)

NewWatcher creates a Watcher that monitors projectDir and globalDir for markdown file changes. The default debounce window is 300ms.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the underlying fsnotify watcher.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

Run blocks and processes file events until the context is cancelled.

Jump to

Keyboard shortcuts

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