MingaEditor.State.Workspace (Minga v0.1.0)

Copy Markdown View Source

Domain model for an editor workspace.

A workspace owns a task context. The manual workspace represents project-owned file work, while agent workspaces attach one optional agent session and later become the home for workspace files, agent UI, ProjectView, and review state.

Summary

Types

Agent status for workspace display.

Remote connection status for workspace-owned remote sessions.

Workspace icon identifier.

Workspace kind.

t()

A workspace domain object.

Functions

Adds a file membership to the workspace, preserving existing membership order.

Auto-names an agent workspace from an agent prompt unless the user renamed it.

Clears queued remote catch-up events after they have been replayed.

Clears durable remote metadata. Use only when the workspace no longer represents a remote session.

Clears the live agent session pid and returns the workspace to idle lifecycle status. Durable remote identity is preserved.

Restores a workspace from persisted JSON data, ignoring unknown fields and using defaults for missing fields.

Returns true when the workspace already contains the file membership.

Returns true when the workspace represents the remote server/session pair.

Creates a new agent workspace with a unique id.

Creates the manual project workspace.

Refreshes the workspace session pid after a managed restart.

Returns true when the workspace has durable remote metadata.

Returns true when the workspace belongs to the named remote server.

Removes a file membership from the workspace.

Renames the workspace and protects it from future auto-naming.

Retargets a file membership for a tab.

Retires every workspace-owned reference to a dead buffer process.

Returns true when drafts or conflicts require user action before close.

Sets the agent status on the workspace.

Sets the workspace-owned agent UI projection.

Sets the workspace icon.

Sets queued remote catch-up events waiting for the workspace to become active.

Sets the ProjectView owned by the workspace.

Updates durable remote connection status when the workspace has remote metadata.

Sets durable remote metadata on the workspace.

Sets review state through the owning workspace module.

Sets the session owned by the workspace.

Serializes the persisted workspace fields to a JSON-ready map.

Moves review state through a legal transition.

Returns a copy scoped to a project root for persistence.

Types

agent_status()

@type agent_status() ::
  :idle
  | :plan
  | :thinking
  | :tool_executing
  | :error
  | :stopped
  | :needs_review
  | :done
  | nil

Agent status for workspace display.

connection_status()

Remote connection status for workspace-owned remote sessions.

icon()

@type icon() :: String.t()

Workspace icon identifier.

kind()

@type kind() :: :manual | :agent

Workspace kind.

t()

@type t() :: %MingaEditor.State.Workspace{
  agent_status: agent_status(),
  agent_ui: MingaEditor.Agent.UIState.t() | nil,
  color: non_neg_integer(),
  custom_name: String.t() | nil,
  files: [Minga.Project.FileRef.t()],
  icon: icon(),
  id: non_neg_integer(),
  kind: kind(),
  label: String.t(),
  pending_catchup_events: [MingaAgent.EventLog.EventRecord.t()],
  project_root: String.t() | nil,
  project_view: MingaAgent.ProjectView.t() | nil,
  remote_session: MingaEditor.State.Workspace.RemoteSession.t() | nil,
  review: MingaEditor.State.WorkspaceReview.t(),
  session: pid() | nil
}

A workspace domain object.

Functions

add_file(workspace, file_ref)

@spec add_file(t(), Minga.Project.FileRef.t()) :: t()

Adds a file membership to the workspace, preserving existing membership order.

auto_name(workspace, prompt)

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

Auto-names an agent workspace from an agent prompt unless the user renamed it.

clear_pending_catchup_events(workspace)

@spec clear_pending_catchup_events(t()) :: t()

Clears queued remote catch-up events after they have been replayed.

clear_remote_session(workspace)

@spec clear_remote_session(t()) :: t()

Clears durable remote metadata. Use only when the workspace no longer represents a remote session.

clear_session(workspace)

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

Clears the live agent session pid and returns the workspace to idle lifecycle status. Durable remote identity is preserved.

from_persisted_map(data, project_root)

@spec from_persisted_map(map(), String.t()) :: {:ok, t()} | {:error, term()}

Restores a workspace from persisted JSON data, ignoring unknown fields and using defaults for missing fields.

has_file?(workspace, file_ref)

@spec has_file?(t(), Minga.Project.FileRef.t()) :: boolean()

Returns true when the workspace already contains the file membership.

matches_remote_session?(workspace, server_name, session_id)

@spec matches_remote_session?(t(), String.t(), String.t()) :: boolean()

Returns true when the workspace represents the remote server/session pair.

new_agent(id, label, session \\ nil, project_root \\ nil)

@spec new_agent(pos_integer(), String.t(), pid() | nil, String.t() | nil) :: t()

Creates a new agent workspace with a unique id.

new_manual(project_root)

@spec new_manual(String.t() | nil) :: t()

Creates the manual project workspace.

put_remote_session(workspace, server_name, session_id, status \\ :connected, last_seen_event_id \\ 0)

@spec put_remote_session(
  t(),
  String.t(),
  String.t(),
  connection_status(),
  non_neg_integer()
) :: t()

Sets durable remote metadata from its fields.

refresh_session_pid(workspace, old_pid, new_pid)

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

Refreshes the workspace session pid after a managed restart.

remote?(workspace)

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

Returns true when the workspace has durable remote metadata.

remote_server?(workspace, server_name)

@spec remote_server?(t(), String.t()) :: boolean()

Returns true when the workspace belongs to the named remote server.

remove_file(workspace, file_ref)

@spec remove_file(t(), Minga.Project.FileRef.t()) :: t()

Removes a file membership from the workspace.

rename(workspace, name)

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

Renames the workspace and protects it from future auto-naming.

retarget_file(workspace, old_file_ref, new_file_ref)

@spec retarget_file(t(), Minga.Project.FileRef.t() | nil, Minga.Project.FileRef.t()) ::
  t()

Retargets a file membership for a tab.

retire_buffer(workspace, buffer_pid)

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

Retires every workspace-owned reference to a dead buffer process.

review_pending?(workspace)

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

Returns true when drafts or conflicts require user action before close.

set_agent_status(workspace, status)

@spec set_agent_status(t(), agent_status()) :: t()

Sets the agent status on the workspace.

set_agent_ui(workspace, agent_ui)

@spec set_agent_ui(t(), MingaEditor.Agent.UIState.t() | nil) :: t()

Sets the workspace-owned agent UI projection.

set_icon(workspace, icon)

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

Sets the workspace icon.

set_pending_catchup_events(workspace, events)

@spec set_pending_catchup_events(t(), [MingaAgent.EventLog.EventRecord.t()]) :: t()

Sets queued remote catch-up events waiting for the workspace to become active.

set_project_view(workspace, project_view)

@spec set_project_view(t(), MingaAgent.ProjectView.t() | nil) :: t()

Sets the ProjectView owned by the workspace.

set_remote_connection_status(workspace, status)

@spec set_remote_connection_status(t(), connection_status()) :: t()

Updates durable remote connection status when the workspace has remote metadata.

set_remote_session(workspace, remote_session)

@spec set_remote_session(t(), MingaEditor.State.Workspace.RemoteSession.t() | nil) ::
  t()

Sets durable remote metadata on the workspace.

set_review(workspace, review)

@spec set_review(t(), MingaEditor.State.WorkspaceReview.t()) :: t()

Sets review state through the owning workspace module.

set_session(workspace, session)

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

Sets the session owned by the workspace.

to_persisted_map(workspace)

@spec to_persisted_map(t()) :: map()

Serializes the persisted workspace fields to a JSON-ready map.

transition_review(workspace, event, payload \\ nil)

@spec transition_review(t(), atom(), [Minga.Project.FileRef.t()] | nil | term()) ::
  {:ok, t()} | {:error, term()}

Moves review state through a legal transition.

with_project_root(workspace, project_root)

@spec with_project_root(t(), String.t() | nil) :: t()

Returns a copy scoped to a project root for persistence.