Bug: InputModeRouter passes empty string to command handler for root command #8874

Open
opened 2026-04-14 03:11:56 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: fix(tui): guard against empty command string in InputModeRouter.process
  • Branch: fix/tui-input-mode-router-empty-command

Background and Context

In InputModeRouter.process in src/cleveragents/tui/input/modes.py, when the user submits input consisting solely of / (i.e., a slash with no command name), the cmd variable is derived as:

# src/cleveragents/tui/input/modes.py — InputModeRouter.process
cmd = text.lstrip()[1:]

If text is "/", then text.lstrip() is still "/", and [1:] produces an empty string "". This empty string is then passed directly to self._command_handler(cmd) without any validation.

This issue belongs to the Reference and Command Input System (Epic #8604), which is part of the v3.7.0 TUI Implementation milestone.

Per the project's Argument Validation guidelines, all public and protected class methods must validate arguments as the first guard, and empty strings must be rejected where non-empty strings are required. The InputModeRouter should enforce this boundary condition rather than delegating it to every downstream command handler.

Expected Behavior

When a user submits / with no command name, InputModeRouter.process should detect the empty command string and return a graceful error result — without invoking _command_handler at all. The returned ModeResult should carry a descriptive command_result error message such as "Error: command cannot be empty".

Acceptance Criteria

  • Submitting / (slash only) does not invoke _command_handler with an empty string.
  • InputModeRouter.process returns a ModeResult with command_result set to a non-empty error message (e.g., "Error: command cannot be empty") when cmd is empty.
  • Submitting /help or any other non-empty command continues to work correctly and routes to _command_handler as before.
  • Submitting / help (slash followed by whitespace then a command) is handled consistently — either stripped and routed, or rejected with a clear message.
  • BDD scenario(s) cover the empty-command boundary condition.
  • All existing tests continue to pass.
  • Test coverage remains ≥ 97%.

Subtasks

  • Add empty-string guard in InputModeRouter.process after cmd = text.lstrip()[1:]
  • Return a ModeResult with an appropriate command_result error message when cmd is empty (or blank after stripping)
  • Tests (Behave): Add scenario Given the user submits "/"Then the command handler is not called and And the result contains error message "Error: command cannot be empty"
  • Tests (Behave): Add scenario for /help to confirm normal routing is unaffected
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(tui): guard against empty command string in InputModeRouter.process), followed by a blank line, then additional lines providing relevant implementation details.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (fix/tui-input-mode-router-empty-command).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(tui): guard against empty command string in InputModeRouter.process` - **Branch**: `fix/tui-input-mode-router-empty-command` ## Background and Context In `InputModeRouter.process` in `src/cleveragents/tui/input/modes.py`, when the user submits input consisting solely of `/` (i.e., a slash with no command name), the `cmd` variable is derived as: ```python # src/cleveragents/tui/input/modes.py — InputModeRouter.process cmd = text.lstrip()[1:] ``` If `text` is `"/"`, then `text.lstrip()` is still `"/"`, and `[1:]` produces an empty string `""`. This empty string is then passed directly to `self._command_handler(cmd)` without any validation. This issue belongs to the Reference and Command Input System (Epic #8604), which is part of the v3.7.0 TUI Implementation milestone. Per the project's [Argument Validation guidelines](CONTRIBUTING.md), all public and protected class methods must validate arguments as the first guard, and empty strings must be rejected where non-empty strings are required. The `InputModeRouter` should enforce this boundary condition rather than delegating it to every downstream command handler. ## Expected Behavior When a user submits `/` with no command name, `InputModeRouter.process` should detect the empty command string and return a graceful error result — without invoking `_command_handler` at all. The returned `ModeResult` should carry a descriptive `command_result` error message such as `"Error: command cannot be empty"`. ## Acceptance Criteria - [ ] Submitting `/` (slash only) does **not** invoke `_command_handler` with an empty string. - [ ] `InputModeRouter.process` returns a `ModeResult` with `command_result` set to a non-empty error message (e.g., `"Error: command cannot be empty"`) when `cmd` is empty. - [ ] Submitting `/help` or any other non-empty command continues to work correctly and routes to `_command_handler` as before. - [ ] Submitting `/ help` (slash followed by whitespace then a command) is handled consistently — either stripped and routed, or rejected with a clear message. - [ ] BDD scenario(s) cover the empty-command boundary condition. - [ ] All existing tests continue to pass. - [ ] Test coverage remains ≥ 97%. ## Subtasks - [ ] Add empty-string guard in `InputModeRouter.process` after `cmd = text.lstrip()[1:]` - [ ] Return a `ModeResult` with an appropriate `command_result` error message when `cmd` is empty (or blank after stripping) - [ ] Tests (Behave): Add scenario `Given the user submits "/"` → `Then the command handler is not called` and `And the result contains error message "Error: command cannot be empty"` - [ ] Tests (Behave): Add scenario for `/help` to confirm normal routing is unaffected - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(tui): guard against empty command string in InputModeRouter.process`), followed by a blank line, then additional lines providing relevant implementation details. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`fix/tui-input-mode-router-empty-command`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.7.0 milestone 2026-04-14 03:18:35 +00:00
Author
Owner

Triage Decision: VERIFIED — MoSCoW/Must Have

Real TUI input validation bug: InputModeRouter.process passes an empty string to _command_handler when the user submits just /. This violates the argument validation guidelines and can cause unexpected behavior in command handlers.

Priority/High — Input validation is a core reliability requirement for the TUI.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Triage Decision: VERIFIED — MoSCoW/Must Have** Real TUI input validation bug: `InputModeRouter.process` passes an empty string to `_command_handler` when the user submits just `/`. This violates the argument validation guidelines and can cause unexpected behavior in command handlers. **Priority/High** — Input validation is a core reliability requirement for the TUI. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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.

Dependencies

No dependencies set.

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