# `MingaEditor.State.AgentAccess`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/state/agent_access.ex#L1)

Direct accessors for agent state on EditorState.

Agent-related state is split across three locations:

- `state.shell_state.agent` (`MingaEditor.State.Agent`) — rendering
  cache for the user's current view. Holds `runtime` (status), `error`,
  `pending_approval`, `spinner_timer`, and `buffer`. Repopulated on
  every tab/card switch from the active session's
  `MingaAgent.Session.editor_snapshot/1`. **Not the source of truth
  for the session pid.**
- The active session pid lives on `Tab.session` (Traditional shell)
  or `Card.session` (Board shell). `session/1` reads it through
  `Shell.active_session/1`.
- `state.workspace.agent_ui` (`Agent.UIState`) — full UI state
  wrapping Panel and View. Per-tab.
  - `state.workspace.agent_ui.panel` (`UIState.Panel`) — prompt
    editing and chat display.
  - `state.workspace.agent_ui.view` (`UIState.View`) — layout,
    search, preview, toasts.

This module provides read/write functions so callers don't need to
know the field layout.

# `agent`

```elixir
@spec agent(MingaEditor.State.t() | map()) :: MingaEditor.State.Agent.t()
```

Returns the agent session lifecycle state.

# `agent_ui`

```elixir
@spec agent_ui(MingaEditor.State.t() | map()) :: MingaEditor.Agent.UIState.t()
```

Returns the full agent UI state (wrapping Panel and View).

# `focus`

```elixir
@spec focus(MingaEditor.State.t() | map()) :: atom()
```

Returns the agent UI focus.

# `input_focused?`

```elixir
@spec input_focused?(MingaEditor.State.t() | map()) :: boolean()
```

Returns true if the agent panel input is focused.

# `panel`

```elixir
@spec panel(MingaEditor.State.t() | map()) :: MingaEditor.Agent.UIState.Panel.t()
```

Returns the agent panel state (prompt editing and chat display).

# `session`

```elixir
@spec session(MingaEditor.State.t() | map()) :: pid() | nil
```

Returns the agent session pid for the user's current view, or `nil`.

Reads through the shell behaviour: Traditional returns the active tab's
session, Board returns the zoomed card's session. The session pid is
owned by the tab/card; `state.shell_state.agent` only caches the
rendering fields (status, error, pending_approval) for that session.

# `update_agent`

```elixir
@spec update_agent(MingaEditor.State.t() | map(), (MingaEditor.State.Agent.t() -&gt;
                                               MingaEditor.State.Agent.t())) ::
  MingaEditor.State.t() | map()
```

Updates agent session lifecycle state via a transform function.

# `update_agent_ui`

> This function is deprecated. Use update_panel/2 or update_view/2 for targeted sub-struct updates.

```elixir
@spec update_agent_ui(MingaEditor.State.t() | map(), (MingaEditor.Agent.UIState.t() -&gt;
                                                  MingaEditor.Agent.UIState.t())) ::
  MingaEditor.State.t() | map()
```

Updates the full agent UI state. Prefer update_panel/2 or update_view/2.

# `update_panel`

```elixir
@spec update_panel(
  MingaEditor.State.t() | map(),
  (MingaEditor.Agent.UIState.Panel.t() -&gt;
     MingaEditor.Agent.UIState.Panel.t())
) ::
  MingaEditor.State.t() | map()
```

Updates just the panel sub-struct via a transform function.

# `update_view`

```elixir
@spec update_view(
  MingaEditor.State.t() | map(),
  (MingaEditor.Agent.UIState.View.t() -&gt;
     MingaEditor.Agent.UIState.View.t())
) ::
  MingaEditor.State.t() | map()
```

Updates just the view sub-struct via a transform function.

# `view`

```elixir
@spec view(MingaEditor.State.t() | map()) :: MingaEditor.Agent.UIState.View.t()
```

Returns the agent view state (layout, search, preview, toasts).

---

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