Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

3.9 KB
Raw Blame
<a id="camel.toolkits.terminal_toolkit.utils"></a>

<a id="camel.toolkits.terminal_toolkit.utils._normalize_command_name"></a>

## _normalize_command_name

```python
def _normalize_command_name(command: str):
```

Normalize command names for safer matching.

<a id="camel.toolkits.terminal_toolkit.utils._split_command_segments"></a>

## _split_command_segments

```python
def _split_command_segments(command: str):
```

Split command by shell separators while preserving quoted content.

<a id="camel.toolkits.terminal_toolkit.utils._extract_shell_c_payloads"></a>

## _extract_shell_c_payloads

```python
def _extract_shell_c_payloads(command: str):
```

Extract payloads from shell wrapper commands like `bash -c "<cmd>"`.

<a id="camel.toolkits.terminal_toolkit.utils.check_command_safety"></a>

## check_command_safety

```python
def check_command_safety(command: str, allowed_commands: Optional[Set[str]] = None):
```

Check if a command (potentially with chaining) is safe to execute.

**Parameters:**

- **command** (str): The command string to check
- **allowed_commands** (Optional[Set[str]]): Set of allowed commands (whitelist mode)

**Returns:**

  Tuple[bool, str]: (is_safe, reason)

<a id="camel.toolkits.terminal_toolkit.utils.sanitize_command"></a>

## sanitize_command

```python
def sanitize_command(
    command: str,
    use_docker_backend: bool = False,
    safe_mode: bool = True,
    working_dir: Optional[str] = None,
    allowed_commands: Optional[Set[str]] = None
):
```

A comprehensive command sanitizer for both local and Docker backends.

**Parameters:**

- **command** (str): The command to sanitize
- **use_docker_backend** (bool): Whether using Docker backend
- **safe_mode** (bool): Whether to apply security checks
- **working_dir** (Optional[str]): Working directory for path validation
- **allowed_commands** (Optional[Set[str]]): Set of allowed commands

**Returns:**

  Tuple[bool, str]: (is_safe, message_or_command)

<a id="camel.toolkits.terminal_toolkit.utils.is_uv_environment"></a>

## is_uv_environment

```python
def is_uv_environment():
```

Detect whether the current Python runtime is managed by uv.

<a id="camel.toolkits.terminal_toolkit.utils.ensure_uv_available"></a>

## ensure_uv_available

```python
def ensure_uv_available(update_callback = None):
```

Ensure uv is available, installing it if necessary.

**Parameters:**

- **update_callback**: Optional callback function to receive status updates

**Returns:**

  Tuple[bool, Optional[str]]: (success, uv_path)

<a id="camel.toolkits.terminal_toolkit.utils.setup_initial_env_with_uv"></a>

## setup_initial_env_with_uv

```python
def setup_initial_env_with_uv(
    env_path: str,
    uv_path: str,
    working_dir: str,
    update_callback = None
):
```

Set up initial environment using uv.

<a id="camel.toolkits.terminal_toolkit.utils.setup_initial_env_with_venv"></a>

## setup_initial_env_with_venv

```python
def setup_initial_env_with_venv(env_path: str, working_dir: str, update_callback = None):
```

Set up initial environment using standard venv.

<a id="camel.toolkits.terminal_toolkit.utils.clone_current_environment"></a>

## clone_current_environment

```python
def clone_current_environment(env_path: str, working_dir: str, update_callback = None):
```

Clone the current Python environment to a new virtual environment.

This function creates a new virtual environment with the same Python
version as the current environment and installs all packages from
the current environment.

**Parameters:**

- **env_path**: Path where the new environment will be created.
- **working_dir**: Working directory for subprocess commands.
- **update_callback**: Optional callback for status updates.

**Returns:**

  True if the environment was created successfully, False otherwise.

<a id="camel.toolkits.terminal_toolkit.utils.check_nodejs_availability"></a>

## check_nodejs_availability

```python
def check_nodejs_availability(update_callback = None):
```

Check if Node.js is available without modifying the system.