Syncs agent conversation messages into a *Agent* Buffer.
Converts the session's message list into markdown text and writes it into the buffer. The buffer provides a vim-navigable view of the conversation, with tree-sitter markdown highlighting.
Summary
Types
Line type for buffer-line-to-message mapping.
Functions
Builds a per-buffer-line index mapping buffer lines to message indices and types.
Returns the buffer line number where the given message index starts.
Starts the *Agent* buffer.
Syncs messages into the agent buffer as markdown text.
Types
Functions
@spec line_message_index([term()]) :: [{non_neg_integer(), line_type()}]
Builds a per-buffer-line index mapping buffer lines to message indices and types.
Returns a list where each element corresponds to a buffer line and contains
{message_index, line_type}. The list is indexed by buffer line number.
Prefer reading the cached index from UIState.cached_line_index when
available (populated by sync/3). This function is the fallback for when
the cache is empty (e.g., before the first sync).
@spec message_start_line([term()], non_neg_integer()) :: non_neg_integer() | nil
Returns the buffer line number where the given message index starts.
Returns nil if the message index is not found in the current layout.
@spec start_buffer() :: pid() | nil
Starts the *Agent* buffer.
Returns the buffer pid. The buffer is nofile (no save), read-only (no user edits), unlisted (hidden from buffer picker), and persistent (survives buffer kill).
@spec sync(pid(), [term()], keyword()) :: [{non_neg_integer(), line_type()}]
Syncs messages into the agent buffer as markdown text.
Each message is rendered as a markdown section with a header. The buffer cursor is moved to the end (auto-scroll).
Returns the line-to-message index computed from the synced content, so the caller can cache it in state for later lookups without recomputing.