diff --git a/openhands_cli/acp_impl/confirmation.py b/openhands_cli/acp_impl/confirmation.py index c315737f..caf7199d 100644 --- a/openhands_cli/acp_impl/confirmation.py +++ b/openhands_cli/acp_impl/confirmation.py @@ -2,7 +2,6 @@ import logging from collections.abc import Callable -from typing import Literal from acp import Client from acp.schema import ( @@ -15,40 +14,16 @@ from openhands.sdk.event import ActionEvent from openhands.sdk.security.confirmation_policy import ConfirmRisky, NeverConfirm from openhands.sdk.security.risk import SecurityRisk +from openhands_cli.shared.confirmation_modes import ( + CONFIRMATION_MODES as CONFIRMATION_MODES, + ConfirmationMode as ConfirmationMode, +) from openhands_cli.user_actions.types import ConfirmationResult, UserConfirmation logger = logging.getLogger(__name__) -# Type alias for confirmation modes -ConfirmationMode = Literal["always-ask", "always-approve", "llm-approve"] - - -# Confirmation mode descriptions -CONFIRMATION_MODES: dict[ConfirmationMode, dict[str, str]] = { - "always-ask": { - "short": "Ask for permission before every action", - "long": "Agent will ask for permission before executing every action.", - }, - "always-approve": { - "short": "Automatically approve all actions", - "long": ( - "Agent will automatically approve all actions without asking. " - "⚠️ Use with caution!" - ), - }, - "llm-approve": { - "short": "Use LLM security analyzer to auto-approve safe actions", - "long": ( - "Agent will use LLM security analyzer to automatically " - "approve safe actions. You will only be asked for permission " - "on potentially risky actions." - ), - }, -} - - # Permission options for confirmation requests PERMISSION_OPTIONS = [ PermissionOption( diff --git a/openhands_cli/acp_impl/slash_commands.py b/openhands_cli/acp_impl/slash_commands.py index 3572f053..cf9e3310 100644 --- a/openhands_cli/acp_impl/slash_commands.py +++ b/openhands_cli/acp_impl/slash_commands.py @@ -11,7 +11,11 @@ NeverConfirm, ) from openhands.sdk.security.llm_analyzer import LLMSecurityAnalyzer -from openhands_cli.acp_impl.confirmation import CONFIRMATION_MODES, ConfirmationMode +from openhands_cli.shared.confirmation_modes import ( + CONFIRMATION_MODES, + VALID_CONFIRMATION_MODES, + ConfirmationMode, +) from openhands_cli.shared.slash_commands import ( parse_slash_command as parse_slash_command, ) @@ -19,11 +23,8 @@ logger = logging.getLogger(__name__) -VALID_CONFIRMATION_MODE: list[ConfirmationMode] = [ - "always-ask", - "always-approve", - "llm-approve", -] +# Backward compatibility alias (deprecated, use VALID_CONFIRMATION_MODES) +VALID_CONFIRMATION_MODE = VALID_CONFIRMATION_MODES def get_available_slash_commands() -> list[AvailableCommand]: @@ -131,7 +132,7 @@ def validate_confirmation_mode(mode_str: str) -> ConfirmationMode | None: ConfirmationMode if valid, None otherwise """ normalized = mode_str.lower().strip() - return normalized if normalized in VALID_CONFIRMATION_MODE else None + return normalized if normalized in VALID_CONFIRMATION_MODES else None def apply_confirmation_mode_to_conversation( diff --git a/openhands_cli/shared/__init__.py b/openhands_cli/shared/__init__.py index 0b691a69..4fa6581b 100644 --- a/openhands_cli/shared/__init__.py +++ b/openhands_cli/shared/__init__.py @@ -1,8 +1,22 @@ # Shared utilities for openhands_cli +from openhands_cli.shared.confirmation_modes import ( + CONFIRMATION_MODES, + VALID_CONFIRMATION_MODES, + ConfirmationMode, + ModeInfo, +) from openhands_cli.shared.conversation_summary import extract_conversation_summary from openhands_cli.shared.rich_utils import escape_rich_markup from openhands_cli.shared.slash_commands import parse_slash_command -__all__ = ["escape_rich_markup", "extract_conversation_summary", "parse_slash_command"] +__all__ = [ + "CONFIRMATION_MODES", + "ConfirmationMode", + "ModeInfo", + "VALID_CONFIRMATION_MODES", + "escape_rich_markup", + "extract_conversation_summary", + "parse_slash_command", +] diff --git a/openhands_cli/shared/confirmation_modes.py b/openhands_cli/shared/confirmation_modes.py new file mode 100644 index 00000000..6d5585d3 --- /dev/null +++ b/openhands_cli/shared/confirmation_modes.py @@ -0,0 +1,45 @@ +"""Shared confirmation mode definitions. + +This module provides a single source of truth for confirmation mode types and +descriptions used by both ACP and TUI interfaces. +""" + +from typing import Literal, TypedDict + + +# Type alias for confirmation modes +ConfirmationMode = Literal["always-ask", "always-approve", "llm-approve"] + + +class ModeInfo(TypedDict): + """TypedDict for confirmation mode information.""" + + short: str + long: str + + +# Confirmation mode descriptions +CONFIRMATION_MODES: dict[ConfirmationMode, ModeInfo] = { + "always-ask": { + "short": "Ask for permission before every action", + "long": "Agent will ask for permission before executing every action.", + }, + "always-approve": { + "short": "Automatically approve all actions", + "long": ( + "Agent will automatically approve all actions without asking. " + "⚠️ Use with caution!" + ), + }, + "llm-approve": { + "short": "Use LLM security analyzer to auto-approve safe actions", + "long": ( + "Agent will use LLM security analyzer to automatically " + "approve safe actions. You will only be asked for permission " + "on potentially risky actions." + ), + }, +} + +# List of valid confirmation modes for validation +VALID_CONFIRMATION_MODES: list[ConfirmationMode] = list(CONFIRMATION_MODES.keys())