MingaEditor.Agent.View.Preview (Minga v0.1.0)

Copy Markdown View Source

Preview pane state machine for the agentic view.

The right pane of the agentic view reacts to agent tool activity. This module manages a discriminated union of content types:

  • :empty - no content yet (welcome state)
  • {:shell, command, output, status} - shell command output (streaming or done)
  • {:diff, DiffReview.t()} - unified diff from a file edit
  • {:file, path, content} - file content from a read_file tool

The preview updates in response to tool events: ToolStart sets a loading state, ToolUpdate streams partial output, ToolEnd finalizes, and ToolFileChanged triggers diff mode.

Scroll state is tracked here so each content type preserves its own scroll position. Auto-follow pauses when the user scrolls manually and resumes on the next tool event.

Summary

Types

The content currently displayed in the preview pane.

Shell command execution status.

t()

Preview pane state.

Functions

Clears the preview to empty state.

Returns true if the preview is showing a diff review.

Returns the DiffReview if the preview is in diff mode, nil otherwise.

Returns true if the preview is showing a directory listing.

Returns true if the preview is empty.

Marks the shell command as complete.

Creates a new empty preview state.

Sets the preview to show a diff review.

Sets the preview to show a directory listing.

Sets the preview to show file content.

Sets the preview to show shell command output (streaming).

Returns true if the preview is showing shell output.

Updates the diff review within the preview.

Updates the shell output with new partial content.

Types

content()

@type content() ::
  :empty
  | {:shell, command :: String.t(), output :: String.t(), shell_status()}
  | {:diff, MingaEditor.Agent.DiffReview.t()}
  | {:file, path :: String.t(), content :: String.t()}
  | {:directory, path :: String.t(), entries :: [String.t()]}

The content currently displayed in the preview pane.

shell_status()

@type shell_status() :: :running | :done | :error

Shell command execution status.

t()

@type t() :: %MingaEditor.Agent.View.Preview{
  content: content(),
  scroll: Minga.Editing.Scroll.t()
}

Preview pane state.

Functions

clear(preview)

@spec clear(t()) :: t()

Clears the preview to empty state.

diff?(preview)

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

Returns true if the preview is showing a diff review.

diff_review(preview)

@spec diff_review(t()) :: MingaEditor.Agent.DiffReview.t() | nil

Returns the DiffReview if the preview is in diff mode, nil otherwise.

directory?(preview)

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

Returns true if the preview is showing a directory listing.

empty?(preview)

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

Returns true if the preview is empty.

finish_shell(preview, final_output, status)

@spec finish_shell(t(), String.t(), shell_status()) :: t()

Marks the shell command as complete.

new()

@spec new() :: t()

Creates a new empty preview state.

scroll_down(preview, amount)

@spec scroll_down(t(), pos_integer()) :: t()

Scrolls down. Delegates to Minga.Editing.scroll_down/2.

scroll_to_bottom(preview)

@spec scroll_to_bottom(t()) :: t()

Pins to bottom. Delegates to Minga.Editing.pin_to_bottom/1.

scroll_to_top(preview)

@spec scroll_to_top(t()) :: t()

Scrolls to top. Delegates to Minga.Editing.scroll_to_top/1.

scroll_up(preview, amount)

@spec scroll_up(t(), pos_integer()) :: t()

Scrolls up. Delegates to Minga.Editing.scroll_up/2.

set_diff(preview, review)

@spec set_diff(t(), MingaEditor.Agent.DiffReview.t()) :: t()

Sets the preview to show a diff review.

set_directory(preview, path, entries)

@spec set_directory(t(), String.t(), [String.t()]) :: t()

Sets the preview to show a directory listing.

set_file(preview, path, content)

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

Sets the preview to show file content.

set_shell(preview, command)

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

Sets the preview to show shell command output (streaming).

shell?(preview)

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

Returns true if the preview is showing shell output.

update_diff(preview, fun)

Updates the diff review within the preview.

update_shell_output(preview, new_output)

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

Updates the shell output with new partial content.