Feature: TUI Command Router and run_tui coverage
  Exercises previously uncovered code paths in
  cleveragents.tui.commands (lines 22-64).

  Background:
    Given the TUI commands module is imported

  # ---------- TuiCommandRouter.handle() ----------

  Scenario: handle returns empty command for whitespace-only input
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "   "
    Then the handle result should be "Empty command"

  Scenario: handle dispatches persona list command
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "persona list"
    Then the handle result should contain persona listing

  Scenario: handle dispatches persona set command
    Given a TuiCommandRouter with a mock registry and state that supports set
    When I call handle with raw input "persona set testpersona"
    Then the handle result should start with "Active persona:"

  Scenario: handle dispatches session show command
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "session show"
    Then the handle result should be "Current session: test-session"

  Scenario: handle returns help text listing all commands
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "help"
    Then the handle result should contain "Available slash commands:"
    And the handle result should contain "persona:list"
    And the handle result should contain "session:create"

  Scenario: handle returns unknown command for unrecognised input
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "foobar"
    Then the handle result should be "Unknown command: /foobar"

  # ---------- _persona_command() ----------

  Scenario: persona command with no subcommand lists personas
    Given a TuiCommandRouter with a mock registry containing two personas
    When I call handle with raw input "persona"
    Then the handle result should be "Alice, Bob"

  Scenario: persona list returns No personas when registry is empty
    Given a TuiCommandRouter with an empty mock registry
    When I call handle with raw input "persona list"
    Then the handle result should be "No personas"

  Scenario: persona set without a name returns usage
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "persona set"
    Then the handle result should be "Usage: /persona set <name>"

  Scenario: persona unknown subcommand returns error
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "persona delete all"
    Then the handle result should be "Unknown persona command: delete all"

  # ---------- _session_command() ----------

  Scenario: session command with no subcommand shows current session
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "session"
    Then the handle result should be "Current session: test-session"

  Scenario: session unknown subcommand returns error
    Given a TuiCommandRouter with a mock registry and state
    When I call handle with raw input "session reset abc"
    Then the handle result should be "Unknown session command: reset abc"

  # ---------- run_tui() ----------

  Scenario: run_tui headless mode prints JSON payload and returns zero
    When I call run_tui in headless mode with mocked dependencies
    Then the run_tui return code should be 0
    And the printed JSON should contain textual_available key
    And the printed JSON should contain help key

  Scenario: run_tui non-headless mode creates app and returns zero
    When I call run_tui in non-headless mode with mocked dependencies
    Then the run_tui return code should be 0
    And the mocked app run method should have been called
