Server-owned session metadata index (<data_dir>/catalog/sessions.json)
backed by a :protected ETS table for lock-free concurrent reads.
H.Catalog never opens <data_dir>/sessions/<session_id>/ directly and
never wakes unloaded sessions on read.
Summary
Functions
Annotates a list of directory entry maps in a single pass over ETS for env_id.
Broadcasts a fresh :catalog upsert for session_id reflecting live computed
fields (loaded, cwd_exists) without rewriting sessions.json.
Returns a specification to start this module under a supervisor.
Deletes a session entry from ETS and disk atomically.
Looks up a single session entry directly from ETS.
Creates an identity without overwriting a concurrently created session.
Lists all catalog entries directly from ETS, sorted by updated_at descending.
Lists catalog entries directly from ETS scoped to {env_id, cwd}.
Inserts or merges server-owned session metadata after validating session_id
and absolute cwd. Persists to ETS and disk atomically.
Marks a session as quarantined (status: "quarantined", active: false).
Applies worker-owned runtime updates (title, active, next_wake_at,
updated_at, applied_edit_rev) without overwriting server-owned fields
like cwd or status.
Returns true when the catalog entry represents a root session (parent == nil).
Sanitizes an optional activity label to at most 120 printable characters without control characters.
Archives or unarchives a session in the catalog without waking it.
Updates catalog triage metadata (needs_attention and/or tags) without
waking the session. Setting needs_attention: true clears the archive flag.
Returns an atomic catalog snapshot (%{seq: pos_integer(), sessions: [map()]})
from the catalog GenServer without waking any sessions.
Starts the catalog process.
Formats a catalog entry into the wire-level SessionSummary map shared by
H.Daemon and catalog SSE broadcasts.
Functions
Annotates a list of directory entry maps in a single pass over ETS for env_id.
Each directory map is enriched with direct_session_count, subtree_session_count,
active_session_count, and latest_session (matching atom vs. string key style of
each input directory map). Subsessions (parent != nil) are excluded by default.
Options:
:table- ETS table name (default:h_catalog):parent_path- optional base path used when a directory map only provides:name/"name":include_subsessions- include subsessions in directory counts/recency (defaultfalse)
@spec broadcast_live_state(GenServer.server(), String.t()) :: :ok
Broadcasts a fresh :catalog upsert for session_id reflecting live computed
fields (loaded, cwd_exists) without rewriting sessions.json.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec delete_session(GenServer.server(), String.t()) :: :ok
Deletes a session entry from ETS and disk atomically.
Looks up a single session entry directly from ETS.
Creates an identity without overwriting a concurrently created session.
Lists all catalog entries directly from ETS, sorted by updated_at descending.
Lists catalog entries directly from ETS scoped to {env_id, cwd}.
Options:
:table- ETS table name (default:h_catalog):subtree- include sessions in descendant subdirectories (defaultfalse):include_subsessions- include sessions with a non-nilparent(defaulttrue)
@spec put_session(GenServer.server(), map()) :: {:ok, map()} | {:error, String.t()}
Inserts or merges server-owned session metadata after validating session_id
and absolute cwd. Persists to ETS and disk atomically.
@spec quarantine(GenServer.server(), String.t(), term()) :: {:ok, map()} | {:error, :not_found}
Marks a session as quarantined (status: "quarantined", active: false).
@spec report_runtime(GenServer.server(), String.t(), map()) :: {:ok, map()} | {:error, :not_found}
Applies worker-owned runtime updates (title, active, next_wake_at,
updated_at, applied_edit_rev) without overwriting server-owned fields
like cwd or status.
Returns true when the catalog entry represents a root session (parent == nil).
Sanitizes an optional activity label to at most 120 printable characters without control characters.
@spec set_archived(GenServer.server(), String.t(), boolean(), keyword()) :: {:ok, map()} | {:error, :not_found}
Archives or unarchives a session in the catalog without waking it.
@spec set_triage(GenServer.server(), String.t(), map()) :: {:ok, map()} | {:error, :not_found | String.t()}
Updates catalog triage metadata (needs_attention and/or tags) without
waking the session. Setting needs_attention: true clears the archive flag.
@spec snapshot(GenServer.server()) :: %{seq: pos_integer(), sessions: [map()]}
Returns an atomic catalog snapshot (%{seq: pos_integer(), sessions: [map()]})
from the catalog GenServer without waking any sessions.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the catalog process.
Options:
:data_dir(required) - root storage directory:name- GenServer registration name (defaultH.Catalog, passnilfor unnamed):table- ETS table name (default:h_catalog):pubsub-Registryname for:catalogtopic broadcasts (defaultH.PubSub, passnilto disable):registry-Registryname for live session lookup (defaultH.Registry, passnilto disable)
Formats a catalog entry into the wire-level SessionSummary map shared by
H.Daemon and catalog SSE broadcasts.