UAT: InputModeRouter.detect_mode() uses lstrip() instead of checking position 0 — violates ADR-046 constraint #5926

Open
opened 2026-04-09 11:52:47 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: TUI Reference and Command Input System — Input Mode Detection
Component: src/cleveragents/tui/input/modes.py
ADR Reference: ADR-046 §Constraints


What Was Tested

Code-level analysis of InputModeRouter.detect_mode() in src/cleveragents/tui/input/modes.py (lines 49–56) against ADR-046 constraints.


Expected Behavior (from ADR-046 §Constraints)

The / character triggers command mode only at position 0 of an empty or beginning-of-line prompt — / in the middle of text is literal.
The ! character triggers shell mode only at position 0! in the middle of text is literal.

The Input Mode Summary table in ADR-046 also states:

* (any other) → Normal mode


Actual Behavior (from code)

In src/cleveragents/tui/input/modes.py, lines 49–56:

@staticmethod
def detect_mode(text: str) -> InputMode:
    stripped = text.lstrip()
    if stripped.startswith("/"):
        return InputMode.COMMAND
    if stripped.startswith("!"):
        return InputMode.SHELL
    return InputMode.NORMAL

The implementation calls text.lstrip() before checking for / and !. This means leading whitespace is stripped before the position-0 check. A user typing /help (with leading spaces) would incorrectly be routed to command mode, and !ls would incorrectly be routed to shell mode.

ADR-046 is explicit: these prefixes trigger their modes only at position 0. The correct check should be text.startswith("/") and text.startswith("!") (no lstrip).


Steps to Reproduce

from cleveragents.tui.input.modes import InputModeRouter

# These should be NORMAL mode (leading spaces, not position 0)
assert InputModeRouter.detect_mode("  /help") == "normal"   # FAILS — returns "command"
assert InputModeRouter.detect_mode("  !ls") == "normal"     # FAILS — returns "shell"

# These should be COMMAND/SHELL mode (position 0)
assert InputModeRouter.detect_mode("/help") == "command"    # passes
assert InputModeRouter.detect_mode("!ls") == "shell"        # passes

Code Location

  • src/cleveragents/tui/input/modes.py, lines 49–56 (detect_mode static method)

Fix

Replace text.lstrip() with text in the mode detection:

@staticmethod
def detect_mode(text: str) -> InputMode:
    if text.startswith("/"):
        return InputMode.COMMAND
    if text.startswith("!"):
        return InputMode.SHELL
    return InputMode.NORMAL

Severity Assessment

Non-critical — this only affects edge cases where users type leading whitespace before / or !. Normal usage (typing / or ! at the start) works correctly. However, it is a clear spec violation.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area:** TUI Reference and Command Input System — Input Mode Detection **Component:** `src/cleveragents/tui/input/modes.py` **ADR Reference:** ADR-046 §Constraints --- ## What Was Tested Code-level analysis of `InputModeRouter.detect_mode()` in `src/cleveragents/tui/input/modes.py` (lines 49–56) against ADR-046 constraints. --- ## Expected Behavior (from ADR-046 §Constraints) > The `/` character triggers command mode **only at position 0** of an empty or beginning-of-line prompt — `/` in the middle of text is literal. > The `!` character triggers shell mode **only at position 0** — `!` in the middle of text is literal. The Input Mode Summary table in ADR-046 also states: > `*` (any other) → Normal mode --- ## Actual Behavior (from code) In `src/cleveragents/tui/input/modes.py`, lines 49–56: ```python @staticmethod def detect_mode(text: str) -> InputMode: stripped = text.lstrip() if stripped.startswith("/"): return InputMode.COMMAND if stripped.startswith("!"): return InputMode.SHELL return InputMode.NORMAL ``` The implementation calls `text.lstrip()` before checking for `/` and `!`. This means **leading whitespace is stripped** before the position-0 check. A user typing ` /help` (with leading spaces) would incorrectly be routed to command mode, and ` !ls` would incorrectly be routed to shell mode. ADR-046 is explicit: these prefixes trigger their modes **only at position 0**. The correct check should be `text.startswith("/")` and `text.startswith("!")` (no lstrip). --- ## Steps to Reproduce ```python from cleveragents.tui.input.modes import InputModeRouter # These should be NORMAL mode (leading spaces, not position 0) assert InputModeRouter.detect_mode(" /help") == "normal" # FAILS — returns "command" assert InputModeRouter.detect_mode(" !ls") == "normal" # FAILS — returns "shell" # These should be COMMAND/SHELL mode (position 0) assert InputModeRouter.detect_mode("/help") == "command" # passes assert InputModeRouter.detect_mode("!ls") == "shell" # passes ``` --- ## Code Location - `src/cleveragents/tui/input/modes.py`, lines 49–56 (`detect_mode` static method) --- ## Fix Replace `text.lstrip()` with `text` in the mode detection: ```python @staticmethod def detect_mode(text: str) -> InputMode: if text.startswith("/"): return InputMode.COMMAND if text.startswith("!"): return InputMode.SHELL return InputMode.NORMAL ``` --- ## Severity Assessment Non-critical — this only affects edge cases where users type leading whitespace before `/` or `!`. Normal usage (typing `/` or `!` at the start) works correctly. However, it is a clear spec violation. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.2.0 milestone 2026-04-09 12:16:38 +00:00
Author
Owner

Label compliance fix applied:

  • Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

Label compliance fix applied: - Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5926
No description provided.