Skip to main content

Module conversation_mode

Module conversation_mode 

Source
Expand description

ai-conversation major mode (AU‑2).

The read-only *ai:opencode* buffer backing the agent conversation view. Mirrors lattice_agent::log::modes::AiLogMode: on_activate reads the ConversationStore service, seeds the buffer from the current snapshot, subscribes to ConversationUpdated, and spawns a drain task that re-projects on every change. The returned Subscription guard unsubscribes on drop.

render_conversation is pure and unit-testable. Projection is a line-granular suffix replace: unchanged leading lines are never rewritten, so streaming appends touch only the tail and a tool-call status change rewrites only from its line down (AU‑2 shows status inline as text; a decoration-based in-place update is a follow-up).

Structs§

AiConversationGuard
AU‑3+ activation guard: the ConversationUpdated subscription. Dropping it on deactivation unsubscribes, so a stopped mode contributes no further work.
AiConversationMode
ai-conversation-mode – major mode for the *ai:opencode* buffer.
LineSuffixReplace
Result of suffix_replace: replace lines first_diff_line..old_line_count (0-based, the split-on-\n line grid) with replacement.

Functions§

conversation_buffer_name
The synthetic buffer name for the (single, v1) opencode conversation.
project_conversation
TCF: project the conversation to (transcript_text, fold_spans) in a single pass, so a fold’s line range can never drift from the rendered layout. The text half is what the drain diffs into the buffer; the span half is what the ToolCallFoldSource and ReasoningFoldSource read.
register_ai_conversation_actions
AU‑3: register the ai-conversation action commands so the mode’s keymap cmd names resolve (the diff subsystem’s register_diff_actions pattern). The specs are pure shells returning Effect::None: the real bodies live in AiConversationMode::action_handlers, consulted before the CommandSpec.
render_conversation
Render the whole conversation to plain text. Pure; the projection diffs this against the buffer to compute a minimal edit. Thin wrapper over project_conversation — the text half.
suffix_replace
The minimal line-granular replacement turning old into new: the index of the first differing line, and the replacement text for everything from that line onward. None when the texts are already equal.