Memory.FileStore (fnord v0.9.29)

View Source

Shared file-backed storage for long-term memories.

This module underpins both global and project memory stores, preserving compatibility with existing file-backed memory layouts while centralizing shared lookup, allocation, listing, locking, and JSON marshalling behavior.

Summary

Functions

Returns whether a memory with the given title is present.

Resolves a title to a file path using the canonical slug location first and only scanning suffix collisions when the base path does not match.

Removes the memory file identified by title.

Ensures the configured storage path exists and removes the retired legacy directory when present.

Returns all memory titles by reading each stored file once.

Returns all decodable memories in a single filesystem pass.

Builds a store context from runtime paths.

Reads a memory by title using slug-based lookup with collision fallback.

Persists a memory, overwriting an existing file for the same title or allocating a new collision-safe path when needed.

Types

t()

@type t() :: %Memory.FileStore{
  debug_label: String.t(),
  old_storage_path: String.t(),
  storage_path: String.t()
}

Functions

exists?(store, title)

@spec exists?(t(), String.t()) :: boolean()

Returns whether a memory with the given title is present.

find_file_path_by_title(store, title)

@spec find_file_path_by_title(t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Resolves a title to a file path using the canonical slug location first and only scanning suffix collisions when the base path does not match.

forget(store, title)

@spec forget(t(), String.t()) :: :ok | {:error, term()}

Removes the memory file identified by title.

init(store)

@spec init(t()) :: :ok | {:error, term()}

Ensures the configured storage path exists and removes the retired legacy directory when present.

list(store)

@spec list(t()) :: {:ok, [String.t()]} | {:error, term()}

Returns all memory titles by reading each stored file once.

list_memories(store)

@spec list_memories(t()) :: {:ok, [Memory.t()]} | {:error, term()}

Returns all decodable memories in a single filesystem pass.

new(opts)

@spec new(keyword()) :: t()

Builds a store context from runtime paths.

read(store, title)

@spec read(t(), String.t()) :: {:ok, Memory.t()} | {:error, term()}

Reads a memory by title using slug-based lookup with collision fallback.

save(store, memory)

@spec save(t(), Memory.t()) :: :ok | {:error, term()}

Persists a memory, overwriting an existing file for the same title or allocating a new collision-safe path when needed.