Skip to content

CLI-33: Implement prompt queue feature - #629

Open
szmania wants to merge 8 commits into
cecli-dev:mainfrom
szmania:cli-33-queue-prompts
Open

CLI-33: Implement prompt queue feature#629
szmania wants to merge 8 commits into
cecli-dev:mainfrom
szmania:cli-33-queue-prompts

Conversation

@szmania

@szmania szmania commented Aug 2, 2026

Copy link
Copy Markdown

CLI-33: Implement Prompt Queue Feature

Purpose

This PR implements the prompt queue feature requested in CLI-33. It enables users to queue prompts for processing after current tasks complete, providing better control over workflow execution in the CLI.

Design Considerations

Architecture

  • In-Memory FIFO Queue: The prompt queue is stored as an in-memory list on the Commands class instance, ensuring it persists across command executions within a single session but is cleared on session restart
  • Thread Safety: Uses asyncio.Lock for atomic queue operations to prevent race conditions in the async event loop
  • Management Command Guard: Queue processing is explicitly excluded for /queue, /list-queue, and /remove-queue commands to prevent infinite recursion and ensure management commands can be executed during active prompt processing

Queue Processing

  • Integrated into Commands.execute() finally block, after cmd_running_event is set
  • Sequential FIFO processing ensures queued prompts execute in order after current command completes
  • Self-triggering guard via _processing_queue flag prevents infinite loops from queued prompts that queue additional items
  • Exception resilience: Generic exceptions during queued prompt execution are logged but don't halt subsequent queue processing
  • Signal propagation: SwitchCoderSignal and ReloadProgramSignal are re-raised to maintain proper control flow

Constraints

  • Maximum queue size: 100 items (prevents memory exhaustion)
  • Maximum prompt length: 10,000 characters per queued item
  • Session-specific: Queue state is lost on CLI restart (by design)

What Changed

New Files

  1. cecli/commands/queue.py - QueueCommand class implementing /queue <prompt> to add prompts to the queue
  2. cecli/commands/list_queue.py - ListQueueCommand class implementing /list-queue to display queued items
  3. cecli/commands/remove_queue.py - RemoveQueueCommand class implementing /remove-queue [index|*] for interactive or direct removal
  4. cecli/tests/test_queue_commands.py - Comprehensive test suite with unit, integration, and E2E tests

Modified Files

  1. cecli/commands/core.py:

    • Added prompt_queue, _queue_counter, _queue_lock, _processing_queue, _MANAGEMENT_COMMANDS state
    • Implemented queue management methods: _enqueue_prompt(), _dequeue_prompt(), _get_queue_length(), _remove_from_queue(), _clear_queue(), _process_queued_prompts()
    • Modified execute() to trigger queue processing after management command check
    • Fixed run() to handle all / prefixed commands properly
    • Modified execute() to skip clearing cmd_running_event for management commands
  2. cecli/commands/__init__.py:

    • Registered QueueCommand, ListQueueCommand, and RemoveQueueCommand in CommandRegistry
    • Added all three command classes to __all__ list
  3. README.md:

    • Added "Prompt Queue Management" section documenting all three new commands
    • Included usage syntax, examples, and constraints
    • Explained queue processing lifecycle and limits

Testing

All tests pass successfully:

  • Unit tests for queue data structure operations (enqueue, dequeue, remove, clear, etc.)
  • Integration tests for command registration and execution
  • E2E tests for full queue lifecycle and management during active commands
  • Regression tests confirming existing commands remain functional
  • Edge cases: empty queue, invalid indices, max size, long prompts

Related Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant