MingaEditor.State.Agent (Minga v0.1.0)

Copy Markdown View Source

Agent session lifecycle state: session pid, status, approvals.

Domain-only state (status, model, provider, session ID) lives in the composed MingaAgent.RuntimeState struct at runtime. Presentation state (spinner timer, buffer pid, session history) stays on this struct.

Lifecycle monitoring (Process.monitor) is handled exclusively by MingaAgent.SessionManager, which broadcasts :agent_session_stopped events via Minga.Events. The Editor subscribes to those events instead of monitoring session PIDs directly.

UI state (scroll, prompt, focus, search, toasts) lives in UIState on EditorState.agent_ui. This module holds only process-aware, action-heavy fields that manage the agent session.

Summary

Types

Pending tool approval data.

Agent status (delegated from RuntimeState).

t()

Agent session state.

Functions

Returns all session pids (active + history), most recent first.

Returns true if the agent is actively working.

Clears the pending tool approval.

Clears the session reference and resets status to :idle. Lifecycle monitoring is handled by SessionManager.

Sets the agent buffer pid.

Sets the agent into an error state with a message.

Sets a pending tool approval.

Stores the session pid and sets status to :idle. Archives the previous session. Lifecycle monitoring is handled by SessionManager.

Sets the agent status (delegates to RuntimeState).

Starts the spinner timer if not already running.

Returns the agent lifecycle status from RuntimeState.

Stops the spinner timer if running.

Switches to a session from history, moving current to history. Lifecycle monitoring is handled by SessionManager.

Types

approval()

@type approval() :: MingaAgent.ToolApproval.t()

Pending tool approval data.

status()

@type status() :: MingaAgent.RuntimeState.status()

Agent status (delegated from RuntimeState).

t()

@type t() :: %MingaEditor.State.Agent{
  buffer: pid() | nil,
  error: String.t() | nil,
  pending_approval: approval() | nil,
  runtime: MingaAgent.RuntimeState.t(),
  session: pid() | nil,
  session_history: [pid()],
  spinner_timer: {:ok, :timer.tref()} | nil
}

Agent session state.

Functions

all_sessions(agent)

@spec all_sessions(t()) :: [pid()]

Returns all session pids (active + history), most recent first.

busy?(agent)

@spec busy?(t()) :: boolean()

Returns true if the agent is actively working.

clear_pending_approval(agent)

@spec clear_pending_approval(t()) :: t()

Clears the pending tool approval.

clear_session(agent)

@spec clear_session(t()) :: t()

Clears the session reference and resets status to :idle. Lifecycle monitoring is handled by SessionManager.

set_buffer(agent, pid)

@spec set_buffer(t(), pid()) :: t()

Sets the agent buffer pid.

set_error(agent, message)

@spec set_error(t(), String.t()) :: t()

Sets the agent into an error state with a message.

set_pending_approval(agent, approval)

@spec set_pending_approval(t(), approval()) :: t()

Sets a pending tool approval.

set_session(agent, pid)

@spec set_session(t(), pid()) :: t()

Stores the session pid and sets status to :idle. Archives the previous session. Lifecycle monitoring is handled by SessionManager.

set_status(agent, status)

@spec set_status(t(), status()) :: t()

Sets the agent status (delegates to RuntimeState).

start_spinner_timer(agent)

@spec start_spinner_timer(t()) :: t()

Starts the spinner timer if not already running.

status(agent)

@spec status(t()) :: status()

Returns the agent lifecycle status from RuntimeState.

stop_spinner_timer(agent)

@spec stop_spinner_timer(t()) :: t()

Stops the spinner timer if running.

switch_session(agent, pid)

@spec switch_session(t(), pid()) :: t()

Switches to a session from history, moving current to history. Lifecycle monitoring is handled by SessionManager.