Feature: REPL CLI Coverage Boost
  Additional scenarios that exercise previously uncovered code paths
  in the cleveragents.cli.commands.repl module.

  Background:
    Given the repl module is imported

  # --- _build_reference_catalog: file limit break (line 222) ---

  Scenario: Reference catalog stops collecting after MAX_REFERENCE_FILES
    Given a temporary directory with more files than the reference limit
    When I build the reference catalog from that directory
    Then the catalog file list should be capped at the maximum

  # --- _expand_references: category match but no fuzzy match (lines 331-332) ---

  Scenario: Expand references with known category but no matching value
    Given a reference catalog with an empty actor list
    When I expand the reference "@actor:nonexistent" using that catalog
    Then the token should remain unchanged as "@actor:nonexistent"

  # --- _reference_suggestions: empty raw token (line 360) ---

  Scenario: Reference suggestions skip bare at-sign tokens
    Given a reference catalog with some files
    When I request suggestions for a line containing only "@"
    Then no suggestions should be returned

  # --- _print_persona_list: empty list (lines 423-424) ---

  Scenario: Persona list prints warning when no personas exist
    Given a mock persona registry that returns no personas
    When I call print persona list
    Then the output should contain a no-personas warning

  # --- _parse_persona_create: unknown flags skipped (line 467) ---

  Scenario: Parse persona create skips unknown flags
    When I parse persona create with tokens "create mybot --actor ns/bot --unknown-flag val"
    Then the resulting persona should have name "mybot" and actor "ns/bot"

  # --- _parse_persona_create: missing --actor (line 469) ---

  Scenario: Parse persona create raises when actor is missing
    When I parse persona create with tokens "create mybot --description hello"
    Then a ValueError about missing actor should be raised

  # --- _parse_persona_create: too few tokens (line 434) ---

  Scenario: Parse persona create raises when too few tokens given
    When I parse persona create with only two tokens
    Then a ValueError about usage should be raised

  # --- _parse_persona_create: --cycle-order invalid (lines 463-464) ---

  Scenario: Parse persona create rejects non-integer cycle-order
    When I parse persona create with a non-integer cycle-order
    Then a ValueError about cycle-order should be raised

  # --- /persona set missing name (lines 506-507) ---

  Scenario: Slash command persona set without a name shows error
    Given a mock persona registry for slash commands
    When I handle slash command "persona set"
    Then the repl slash exit code should be 2

  # --- /persona pick with no personas (lines 529-530) ---

  Scenario: Slash command persona pick with no personas shows warning
    Given a mock persona registry that returns no personas for slash commands
    When I handle slash command "persona pick"
    Then the repl slash exit code should be 1

  # --- /persona delete without name (lines 558-559) ---

  Scenario: Slash command persona delete without a name shows error
    Given a mock persona registry for slash commands
    When I handle slash command "persona delete"
    Then the repl slash exit code should be 2

  # --- /persona delete not found (lines 566-567) ---

  Scenario: Slash command persona delete for nonexistent persona
    Given a mock persona registry that cannot delete for slash commands
    When I handle slash command "persona delete ghostbot"
    Then the repl slash exit code should be 1

  # --- /persona export without name (lines 579-580) ---

  Scenario: Slash command persona export without a name shows error
    Given a mock persona registry for slash commands
    When I handle slash command "persona export"
    Then the repl slash exit code should be 2

  # --- /persona export not found (lines 584-585) ---

  Scenario: Slash command persona export for nonexistent persona
    Given a mock persona registry that cannot find persona for slash commands
    When I handle slash command "persona export ghostbot"
    Then the repl slash exit code should be 1

  # --- _run_shell_command empty (line 386-387) ---

  Scenario: Shell command with empty text returns error code
    When I run a shell command with empty text
    Then the shell exit code should be 2

  # --- _run_shell_command disabled (lines 388-389) ---

  Scenario: Shell command when shell mode is disabled
    Given shell mode is disabled via environment
    When I run a shell command with text "echo hello"
    Then the shell exit code should be 2
    And the shell mode disabled message is shown

  # --- _run_shell_command timeout (lines 404-408) ---

  Scenario: Shell command that times out returns exit code 124
    When I run a shell command that will time out
    Then the shell exit code should be 124

  # --- _compose_prompt formats correctly ---

  Scenario: Compose prompt includes session and persona info
    When I compose a prompt with base "agents" and session "s1" and persona "coder"
    Then the prompt should contain session and persona markers

  # --- _get_prompt_context with project and plan ---

  Scenario: Prompt context includes project and plan
    Given rclcb CLEVERAGENTS_PROJECT is set to "myproj"
    And CLEVERAGENTS_PLAN is set to "myplan"
    When I get the prompt context
    Then the prompt context should contain "myproj/myplan"

  # --- _get_prompt_context with neither ---

  Scenario: Prompt context defaults when no env vars set
    Given CLEVERAGENTS_PROJECT is not set
    And CLEVERAGENTS_PLAN is not set
    When I get the prompt context
    Then the prompt context should be the default "agents> "

  # --- _find_reference_candidates with empty query ---

  Scenario: Find reference candidates with empty query returns first items
    Given a list of reference options
    When I find candidates with an empty query
    Then the first items from the list should be returned

  # --- _best_fuzzy_match substring branch ---

  Scenario: Best fuzzy match returns substring match when no prefix match
    Given a list of options including "my-long-name"
    When I fuzzy match with query "long"
    Then the match should be "my-long-name"

  # --- _best_fuzzy_match difflib fallback ---

  Scenario: Best fuzzy match falls back to difflib close matches
    Given a list of options including "controller"
    When I fuzzy match with query "contrlr"
    Then the match should be "controller"

  # --- _best_fuzzy_match no match ---

  Scenario: Best fuzzy match returns None when nothing matches
    Given a list of options including "alpha"
    When I fuzzy match with query "zzzzzzz"
    Then the match should be None

  # --- _reference_suggestions with category prefix ---

  Scenario: Reference suggestions with category-prefixed token
    Given a reference catalog with actors "ns/bot1" and "ns/bot2"
    When I request suggestions for a line containing "@actor:bot"
    Then suggestions should include actor-prefixed candidates

  # --- _expand_references with escaped at-sign ---

  Scenario: Expand references preserves escaped at-sign
    Given a reference catalog with some files
    When I expand a line containing a backslash-escaped at-sign token
    Then the escaped at-sign should be stripped to a bare at-sign

  # --- _parse_persona_create with all optional flags ---

  Scenario: Parse persona create with all optional flags
    When I parse persona create with all flags
    Then the persona should have description icon greeting and cycle-order set
