Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions openhands_cli/acp_impl/confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
from collections.abc import Callable
from typing import Literal

from acp import Client
from acp.schema import (
Expand All @@ -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(
Expand Down
15 changes: 8 additions & 7 deletions openhands_cli/acp_impl/slash_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
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,
)


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]:
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion openhands_cli/shared/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
45 changes: 45 additions & 0 deletions openhands_cli/shared/confirmation_modes.py
Original file line number Diff line number Diff line change
@@ -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())