Owns agent session lifecycle independently of any UI.
Maps stable session IDs to session PIDs. Local scratch sessions still use
human-readable generated IDs (e.g., "session-1"), while remote attach sessions
pass a deterministic :session_id derived from their server-side working directory.
Sessions are started via MingaAgent.Supervisor (DynamicSupervisor) and
monitored here. When a session dies or restarts, the manager broadcasts
lifecycle events so the Editor (or any subscriber) can react without
monitoring PIDs directly.
Summary
Types
Restart bookkeeping for a managed session that is being recovered.
An entry in the sessions map.
Internal state of the SessionManager.
Functions
Aborts the current operation on a session by ID.
Aborts the current operation on a session by ID through the given manager.
Returns a specification to start this module under a supervisor.
Looks up the PID for a session ID.
Looks up the PID for a session ID through the given manager.
Lists background sub-agents for a parent session pid, or all background sub-agents when parent is nil.
Lists background sub-agents through the given manager.
Lists all active sessions as {id, pid, metadata} tuples.
Lists all active sessions through the given manager.
Sends a user prompt to a session by ID.
Sends a user prompt to a session by ID through the given manager.
Looks up the session ID for a PID.
Looks up the session ID for a PID through the given manager.
Returns the broker token for a live session. Used by the remote API bootstrap path.
Returns the broker token for a live session through the given manager.
Builds the deterministic session ID used for a server-side working directory.
Starts a background sub-agent, sends it the task asynchronously, and returns a stable handle.
Starts a background sub-agent through the given manager.
Starts the SessionManager.
Starts or returns the stable session with the given ID.
Starts or returns the stable session with the given ID through the given manager.
Starts a new agent session with a generated human-readable ID.
Starts a new agent session through the given manager.
Stops a session by its human-readable ID.
Stops a session by its human-readable ID through the given manager.
Stops a session by its PID (looks up the ID internally).
Stops a session by its PID through the given manager.
Types
@type restart_state() :: %{ attempts: pos_integer(), window_started_at_ms: integer(), timer_ref: reference() | nil, timer_token: reference() | nil, old_pid: pid(), reason: term() }
Restart bookkeeping for a managed session that is being recovered.
@type session_entry() :: %{ pid: pid(), monitor_ref: reference() | nil, token: String.t(), restart_opts: keyword(), restart_state: restart_state() | nil }
An entry in the sessions map.
@type state() :: %{ sessions: %{required(String.t()) => session_entry()}, background_subagents: %{ required(String.t()) => MingaAgent.Subagent.Handle.t() }, next_id: pos_integer() }
Internal state of the SessionManager.
Functions
@spec abort(String.t()) :: :ok | {:error, :not_found}
Aborts the current operation on a session by ID.
@spec abort(GenServer.server(), String.t()) :: :ok | {:error, :not_found}
Aborts the current operation on a session by ID through the given manager.
Returns a specification to start this module under a supervisor.
See Supervisor.
Looks up the PID for a session ID.
@spec get_session(GenServer.server(), String.t()) :: {:ok, pid()} | {:error, :not_found}
Looks up the PID for a session ID through the given manager.
@spec list_background_subagents(pid() | nil) :: [MingaAgent.Subagent.Handle.t()]
Lists background sub-agents for a parent session pid, or all background sub-agents when parent is nil.
@spec list_background_subagents(GenServer.server(), pid() | nil) :: [ MingaAgent.Subagent.Handle.t() ]
Lists background sub-agents through the given manager.
@spec list_sessions() :: [{String.t(), pid(), MingaAgent.SessionMetadata.t()}]
Lists all active sessions as {id, pid, metadata} tuples.
@spec list_sessions(GenServer.server()) :: [ {String.t(), pid(), MingaAgent.SessionMetadata.t()} ]
Lists all active sessions through the given manager.
Sends a user prompt to a session by ID.
@spec send_prompt(GenServer.server(), String.t(), String.t()) :: :ok | {:error, term()}
Sends a user prompt to a session by ID through the given manager.
Looks up the session ID for a PID.
@spec session_id_for_pid(GenServer.server(), pid()) :: {:ok, String.t()} | {:error, :not_found}
Looks up the session ID for a PID through the given manager.
Returns the broker token for a live session. Used by the remote API bootstrap path.
@spec session_token(GenServer.server(), String.t()) :: {:ok, String.t()} | {:error, :not_found}
Returns the broker token for a live session through the given manager.
Builds the deterministic session ID used for a server-side working directory.
@spec start_background_subagent(pid() | nil, String.t(), keyword()) :: {:ok, MingaAgent.Subagent.Handle.t()} | {:error, term()}
Starts a background sub-agent, sends it the task asynchronously, and returns a stable handle.
@spec start_background_subagent( GenServer.server(), pid() | nil, String.t(), keyword() ) :: {:ok, MingaAgent.Subagent.Handle.t()} | {:error, term()}
Starts a background sub-agent through the given manager.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the SessionManager.
Starts or returns the stable session with the given ID.
@spec start_or_get_session(GenServer.server(), String.t(), keyword()) :: {:ok, String.t(), pid()} | {:error, term()}
Starts or returns the stable session with the given ID through the given manager.
Starts a new agent session with a generated human-readable ID.
Returns {:ok, session_id, pid} on success.
@spec start_session( GenServer.server(), keyword() ) :: {:ok, String.t(), pid()} | {:error, term()}
Starts a new agent session through the given manager.
@spec stop_session(String.t()) :: :ok | {:error, :not_found}
Stops a session by its human-readable ID.
@spec stop_session(GenServer.server(), String.t()) :: :ok | {:error, :not_found}
Stops a session by its human-readable ID through the given manager.
@spec stop_session_by_pid(pid()) :: :ok | {:error, :not_found}
Stops a session by its PID (looks up the ID internally).
@spec stop_session_by_pid(GenServer.server(), pid()) :: :ok | {:error, :not_found}
Stops a session by its PID through the given manager.