# `MingaAgent.SessionManager`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/session_manager.ex#L1)

Owns agent session lifecycle independently of any UI.

Maps human-readable session IDs (e.g., `"session-1"`) to session PIDs.
Sessions are started via `MingaAgent.Supervisor` (DynamicSupervisor) and
monitored here. When a session dies, the manager broadcasts an
`:agent_session_stopped` event so the Editor (or any subscriber) can
react without monitoring PIDs directly.

# `session_entry`

```elixir
@type session_entry() :: %{pid: pid(), monitor_ref: reference()}
```

An entry in the sessions map.

# `state`

```elixir
@type state() :: %{
  sessions: %{required(String.t()) =&gt; session_entry()},
  next_id: pos_integer()
}
```

Internal state of the SessionManager.

# `abort`

```elixir
@spec abort(String.t()) :: :ok | {:error, :not_found}
```

Aborts the current operation on a session by ID.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_session`

```elixir
@spec get_session(String.t()) :: {:ok, pid()} | {:error, :not_found}
```

Looks up the PID for a session ID.

# `list_sessions`

```elixir
@spec list_sessions() :: [{String.t(), pid(), MingaAgent.SessionMetadata.t()}]
```

Lists all active sessions as `{id, pid, metadata}` tuples.

# `send_prompt`

```elixir
@spec send_prompt(String.t(), String.t()) :: :ok | {:error, term()}
```

Sends a user prompt to a session by ID.

# `session_id_for_pid`

```elixir
@spec session_id_for_pid(pid()) :: {:ok, String.t()} | {:error, :not_found}
```

Looks up the session ID for a PID.

# `start_link`

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

Starts the SessionManager.

# `start_session`

```elixir
@spec start_session(keyword()) :: {:ok, String.t(), pid()} | {:error, term()}
```

Starts a new agent session with a generated human-readable ID.

Returns `{:ok, session_id, pid}` on success.

# `stop_session`

```elixir
@spec stop_session(String.t()) :: :ok | {:error, :not_found}
```

Stops a session by its human-readable ID.

# `stop_session_by_pid`

```elixir
@spec stop_session_by_pid(pid()) :: :ok | {:error, :not_found}
```

Stops a session by its PID (looks up the ID internally).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
