# `MingaEditor.AgentLifecycle`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/agent_lifecycle.ex#L1)

Agent session lifecycle helpers for the Editor GenServer.

Handles agent session startup, auto-context loading, semantic transcript
caching, and tab label updates. These are called by the
Editor during init, file open, and surface effect processing.

All functions are pure state transformations (state -> state) that
the Editor calls at the appropriate lifecycle points.

# `state`

```elixir
@type state() :: MingaEditor.State.t()
```

# `cache_messages`

```elixir
@spec cache_messages(state(), [term()]) :: state()
```

Caches semantic transcript metadata for an explicit message list.

# `maybe_set_auto_context`

```elixir
@spec maybe_set_auto_context(state(), String.t(), pid()) :: state()
```

Sets a file's content as the agentic preview pane if the agent pane
is active and the preview is empty. Called when a file is opened while
the agent view is already active.

# `maybe_start_session`

```elixir
@spec maybe_start_session(state()) :: state()
```

Starts the agent session if the agent pane is visible during init.

Also loads auto-context if configured. Called once the port is ready.

# `maybe_update_tab_label`

```elixir
@spec maybe_update_tab_label(state()) :: state()
```

Updates the active agent tab's label to the first user prompt (truncated).

Only updates if the current label is the default "New Agent" or "minga".

# `rebuild_agent_from_session`

```elixir
@spec rebuild_agent_from_session(state(), MingaEditor.State.Tab.t()) :: state()
```

Rebuilds the active agent presentation from its authoritative session snapshot.

# `sync_transcript`

```elixir
@spec sync_transcript(state()) :: state()
```

Caches the semantic agent transcript metadata for the current session messages.

Called as a surface effect when the agent view receives new messages.

# `update_styled_cache`

```elixir
@spec update_styled_cache(state()) :: state()
```

Re-computes cached styled messages for the semantic transcript.

---

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