MingaEditor.State.Agent (Minga v0.1.0)

Copy Markdown View Source

Agent rendering cache: status, error, pending approval, spinner timer, and the agent buffer pid.

This struct is not the source of truth for the active agent session. The session pid lives on the active Tab (Traditional shell) or the zoomed Card (Board shell). MingaEditor.State.AgentAccess.session/1 reads it through the Shell.active_session/1 callback.

After a tab switch, MingaEditor.State.rebuild_agent_from_session/2 repopulates the cache fields below from the incoming tab's session process via MingaAgent.Session.editor_snapshot/1.

Domain-only state (status, model, provider, session ID) lives in the composed MingaAgent.RuntimeState struct at runtime. Lifecycle monitoring (Process.monitor) is handled exclusively by MingaAgent.SessionManager, which broadcasts :agent_session_stopped events via Minga.Events.

UI state (scroll, prompt, focus, search, toasts) lives in UIState on EditorState.workspace.agent_ui.

Summary

Types

Pending tool approval data.

Agent status (delegated from RuntimeState).

t()

Agent rendering cache.

Functions

Returns true if the agent is actively working.

Clears the pending tool approval.

Resets the rendering cache to idle defaults.

Sets the agent buffer pid.

Sets the agent into an error state with a message.

Sets a pending tool approval.

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.

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(),
  spinner_timer: {:ok, :timer.tref()} | nil
}

Agent rendering cache.

Functions

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.

reset_cache(agent)

@spec reset_cache(t()) :: t()

Resets the rendering cache to idle defaults.

Called when the active tab/card no longer has a session, or when its session has been torn down. The session pid itself lives on the tab or card, not on this struct, so callers must clear that separately via EditorState.set_tab_session/3 (Traditional) or by clearing the card's :session field (Board).

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_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.