Services.Memories (fnord v0.8.82)

View Source

GenServer maintaining the in-memory graph of all loaded memories.

Tracks current project context and provides client API for CRUD operations. State includes both global and project-scoped memories when a project is selected.

Summary

Functions

Returns a specification to start this module under a supervisor.

Creates a new memory. Validates parent scope matches if parent_id provided. Persists to disk and updates in-memory state.

Deletes a memory. Removes from disk and in-memory state.

Gets all loaded memories (global + project if project selected).

Gets a memory by ID.

Gets a memory by slug.

Gets children of a specific memory by ID.

Gets only root memories (parent_id: nil).

Reloads all memories from disk.

Sets the current project context and reloads memories.

Updates an existing memory. Persists to disk and updates in-memory state.

Types

t()

@type t() :: %Services.Memories{
  by_id: %{required(String.t()) => AI.Memory.t()},
  by_slug: %{required(String.t()) => AI.Memory.t()},
  memories: [AI.Memory.t()],
  project_name: String.t() | nil,
  roots: [AI.Memory.t()]
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create(memory)

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

Creates a new memory. Validates parent scope matches if parent_id provided. Persists to disk and updates in-memory state.

delete(memory_id)

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

Deletes a memory. Removes from disk and in-memory state.

get_all()

@spec get_all() :: [AI.Memory.t()]

Gets all loaded memories (global + project if project selected).

get_by_id(id)

@spec get_by_id(String.t()) :: AI.Memory.t() | nil

Gets a memory by ID.

get_by_slug(slug)

@spec get_by_slug(String.t()) :: AI.Memory.t() | nil

Gets a memory by slug.

get_children(parent_id)

@spec get_children(String.t()) :: [AI.Memory.t()]

Gets children of a specific memory by ID.

get_roots()

@spec get_roots() :: [AI.Memory.t()]

Gets only root memories (parent_id: nil).

reload()

@spec reload() :: :ok

Reloads all memories from disk.

set_project(project_name)

@spec set_project(String.t() | nil) :: :ok

Sets the current project context and reloads memories.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

update(memory)

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

Updates an existing memory. Persists to disk and updates in-memory state.