MingaEditor.AgentLifecycle (Minga v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Caches semantic transcript metadata for an explicit message list.

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.

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

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

Rebuilds the active agent presentation from its authoritative session snapshot.

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

Re-computes cached styled messages for the semantic transcript.

Types

state()

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

Functions

cache_messages(state, messages)

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

Caches semantic transcript metadata for an explicit message list.

maybe_set_auto_context(state, file_path, buffer_pid)

@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(state)

@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(state)

@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(state, tab)

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

Rebuilds the active agent presentation from its authoritative session snapshot.

sync_transcript(state)

@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(state)

@spec update_styled_cache(state()) :: state()

Re-computes cached styled messages for the semantic transcript.