UAT: ShellSafetyService dead code in TUI — app.py uses simple env-var gate instead of structured danger-level detection for shell warning overlay #6361

Open
opened 2026-04-09 20:17:10 +00:00 by HAL9000 · 0 comments
Owner

Bug Report

Feature Area: TUI Implementation
Spec Reference: §TUI — Shell Mode / Shell Danger Detection
Milestone: v3.7.0

Summary

The spec requires that dangerous shell commands be highlighted with $error styling and a warning indicator shown below the prompt. The ShellSafetyService + DangerousPatternDetector infrastructure (with 4 danger levels: LOW/MEDIUM/HIGH/CRITICAL) is fully implemented but never used in app.py. Instead, app.py's shell_confirm callback only checks an environment variable, bypassing the entire pattern-based danger detection system.

Spec Requirements

Per §TUI — Shell Mode / Shell Danger Detection:

  • When shell mode is active (!/$ prefix), the prompt performs heuristic analysis to detect potentially destructive operations
  • Dangerous commands are highlighted with $error styling and a warning indicator appears below the prompt
  • Warning text: ⚠ Potentially destructive command detected
  • Danger detection is controlled by shell.warn_dangerous setting (default: true)
  • Detection is advisory only — it never prevents command execution

The spec's danger level table maps patterns to risk levels:

  • rm -rf / rm -r → High
  • chmod 777 → Medium
  • > /dev/sda / dd if= → High
  • Fork bomb → High
  • mkfs / fdisk → High
  • kill -9 / killall → Medium
  • sudo / su → Low (warning only)

What Was Found

Code location: /app/src/cleveragents/tui/app.py (lines ~176–183)

mode_router = InputModeRouter(
    command_handler=lambda raw: self._command_router.handle(
        raw, session_id=self._session.session_id
    ),
    shell_confirm=lambda _cmd: (
        os.environ.get("CLEVERAGENTS_ALLOW_DANGEROUS_SHELL", "").strip()
        in {"1", "true"}
    ),
)

The shell_confirm callback ignores the _cmd argument entirely — it only checks the CLEVERAGENTS_ALLOW_DANGEROUS_SHELL environment variable. This means:

  1. No ShellSafetyService or DangerousPatternDetector is instantiated or used
  2. The 4-level danger classification (LOW/MEDIUM/HIGH/CRITICAL) from shell_safety/ is dead code in the TUI context
  3. No visual warning overlay, $error styling, or indicator is ever shown — the command silently blocks or executes based only on an env var
  4. shell_exec.py's simple looks_dangerous() function is used instead (only checks 5 hardcoded patterns, no severity levels)

The full ShellSafetyService infrastructure at src/cleveragents/tui/shell_safety/ (6 files: danger_level.py, dangerous_pattern.py, pattern_detector.py, pattern_registry.py, safety_service.py, warning.py) is completely disconnected from the TUI application.

Code location: /app/src/cleveragents/tui/app.py — No shell warning widget exists in compose(). The cleveragents.tcss has no $error color variable or shell-warning CSS rule.

Expected Behaviour

  • When user types a shell command (e.g. !rm -rf /tmp), ShellSafetyService.check_command() is called
  • If a dangerous pattern is detected:
    • The command text in the prompt is highlighted with $error styling
    • A warning indicator widget appears below the prompt: ⚠ Potentially destructive command detected
    • The danger level (LOW/MEDIUM/HIGH/CRITICAL) determines the warning severity
    • Execution proceeds (advisory only, never blocked unless shell.warn_dangerous is false)
  • ShellSafetyService with warn_callback is wired to the TUI's warning display mechanism

Actual Behaviour

  • ShellSafetyService, DangerousPatternDetector, and DangerousPattern are never instantiated in the TUI
  • shell_confirm only checks env var, ignores command content entirely
  • No warning, no $error styling, no danger level display
  • For commands blocked by looks_dangerous(), the user sees no visual feedback — just stderr: "blocked dangerous shell command" in the conversation area

Impact

The spec-required shell danger UX is broken on two levels:

  1. The rich pattern-based detection infrastructure (ShellSafetyService) is dead code in the TUI
  2. No visual warning/highlighting is shown for any dangerous command

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

## Bug Report **Feature Area**: TUI Implementation **Spec Reference**: §TUI — Shell Mode / Shell Danger Detection **Milestone**: v3.7.0 ### Summary The spec requires that dangerous shell commands be highlighted with `$error` styling and a warning indicator shown below the prompt. The `ShellSafetyService` + `DangerousPatternDetector` infrastructure (with 4 danger levels: LOW/MEDIUM/HIGH/CRITICAL) is fully implemented but **never used** in `app.py`. Instead, `app.py`'s `shell_confirm` callback only checks an environment variable, bypassing the entire pattern-based danger detection system. ### Spec Requirements Per §TUI — Shell Mode / Shell Danger Detection: - When shell mode is active (`!`/`$` prefix), the prompt performs heuristic analysis to detect potentially destructive operations - Dangerous commands are **highlighted with `$error` styling** and a **warning indicator appears below the prompt** - Warning text: `⚠ Potentially destructive command detected` - Danger detection is controlled by `shell.warn_dangerous` setting (default: `true`) - Detection is advisory only — it never prevents command execution The spec's danger level table maps patterns to risk levels: - `rm -rf` / `rm -r` → High - `chmod 777` → Medium - `> /dev/sda` / `dd if=` → High - Fork bomb → High - `mkfs` / `fdisk` → High - `kill -9` / `killall` → Medium - `sudo` / `su` → Low (warning only) ### What Was Found **Code location**: `/app/src/cleveragents/tui/app.py` (lines ~176–183) ```python mode_router = InputModeRouter( command_handler=lambda raw: self._command_router.handle( raw, session_id=self._session.session_id ), shell_confirm=lambda _cmd: ( os.environ.get("CLEVERAGENTS_ALLOW_DANGEROUS_SHELL", "").strip() in {"1", "true"} ), ) ``` The `shell_confirm` callback **ignores the `_cmd` argument entirely** — it only checks the `CLEVERAGENTS_ALLOW_DANGEROUS_SHELL` environment variable. This means: 1. No `ShellSafetyService` or `DangerousPatternDetector` is instantiated or used 2. The 4-level danger classification (LOW/MEDIUM/HIGH/CRITICAL) from `shell_safety/` is dead code in the TUI context 3. No visual warning overlay, `$error` styling, or `⚠` indicator is ever shown — the command silently blocks or executes based only on an env var 4. `shell_exec.py`'s simple `looks_dangerous()` function is used instead (only checks 5 hardcoded patterns, no severity levels) The full `ShellSafetyService` infrastructure at `src/cleveragents/tui/shell_safety/` (6 files: `danger_level.py`, `dangerous_pattern.py`, `pattern_detector.py`, `pattern_registry.py`, `safety_service.py`, `warning.py`) is completely disconnected from the TUI application. **Code location**: `/app/src/cleveragents/tui/app.py` — No shell warning widget exists in `compose()`. The `cleveragents.tcss` has no `$error` color variable or shell-warning CSS rule. ### Expected Behaviour - When user types a shell command (e.g. `!rm -rf /tmp`), `ShellSafetyService.check_command()` is called - If a dangerous pattern is detected: - The command text in the prompt is highlighted with `$error` styling - A warning indicator widget appears below the prompt: `⚠ Potentially destructive command detected` - The danger level (LOW/MEDIUM/HIGH/CRITICAL) determines the warning severity - Execution proceeds (advisory only, never blocked unless `shell.warn_dangerous` is false) - `ShellSafetyService` with `warn_callback` is wired to the TUI's warning display mechanism ### Actual Behaviour - `ShellSafetyService`, `DangerousPatternDetector`, and `DangerousPattern` are never instantiated in the TUI - `shell_confirm` only checks env var, ignores command content entirely - No `⚠` warning, no `$error` styling, no danger level display - For commands blocked by `looks_dangerous()`, the user sees no visual feedback — just `stderr: "blocked dangerous shell command"` in the conversation area ### Impact The spec-required shell danger UX is broken on two levels: 1. The rich pattern-based detection infrastructure (`ShellSafetyService`) is dead code in the TUI 2. No visual warning/highlighting is shown for any dangerous command --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.2.0 milestone 2026-04-09 21:09:28 +00:00
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#6361
No description provided.