Skip to content

Edit queued messages before LLM processing in TUI #503

@bug-ops

Description

@bug-ops

Problem

When a message is queued (visible via [+N queued] badge), there is no way to edit it before the agent picks it up. The only option is /clear-queue (Ctrl+K) which discards all queued messages entirely.

Common scenario: user submits a message, realizes a typo or wrong intent, wants to fix it before the LLM processes it.

Current state

  • Messages queued in VecDeque<QueuedMessage> in agent (zeph-core/src/agent/mod.rs:127)
  • TUI shows [+N queued] badge (zeph-tui/src/widgets/input.rs:23)
  • Ctrl+K sends /clear-queue — clears entire queue, no selective editing
  • Up arrow in Insert mode navigates input history, not the queue
  • Queue is agent-side; TUI only knows the count via AgentEvent::QueueCount

Proposed approach

1. New channel command: /edit-last-queued

Add a channel command that pops the last queued message and returns it to the TUI input buffer for editing. The agent removes it from message_queue and sends the text back via a new AgentEvent::EditQueued(String).

2. TUI keybinding: Up arrow when queue is non-empty

In Insert mode, when queued_count > 0 and input buffer is empty:

  • Up arrow → send /edit-last-queued command
  • Agent pops last message from queue, sends text back via AgentEvent::EditQueued
  • TUI populates input buffer with the returned text, cursor at end
  • Queue count decrements (badge updates)
  • User edits and presses Enter to re-queue

When input buffer is non-empty or queue is empty, Up arrow keeps existing behavior (input history).

3. Agent-side changes (zeph-core)

// In agent run loop, handle the command:
if trimmed == "/edit-last-queued" {
    if let Some(msg) = self.message_queue.pop_back() {
        self.channel.send_edit_queued(&msg.text).await?;
    }
    continue;
}

4. Channel trait addition

async fn send_edit_queued(&mut self, text: &str) -> Result<(), ChannelError>;

Default no-op impl for CLI/Telegram. TUI sends AgentEvent::EditQueued(String).

5. Visual feedback

  • When editing a recalled message, show [editing queued] indicator in input area
  • On Enter, message goes back to queue as normal

Scope

  • zeph-core: /edit-last-queued command handling, send_edit_queued in Channel trait
  • zeph-tui/app.rs: Up arrow logic, EditQueued event handling
  • zeph-tui/channel.rs: send_edit_queued implementation
  • zeph-tui/widgets/input.rs: [editing queued] indicator

Acceptance criteria

  • Up arrow with empty input and non-empty queue recalls last queued message into input buffer
  • Queue count decrements when message is recalled
  • Enter re-submits edited message to queue
  • Up arrow with non-empty input or empty queue uses input history (existing behavior)
  • Visual indicator shown when editing a recalled message

Metadata

Metadata

Assignees

No one assigned

    Labels

    llmLLM provider related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions