validation
code_context_agent.tools.validation ¶
Input validation utilities for tool functions.
This module provides validation functions to prevent path traversal, command injection, and other security issues in user-provided inputs.
ValidationError ¶
Bases: ValueError
Raised when input validation fails.
validate_repo_path ¶
Validate repository path is safe to use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | User-provided path string. | required |
Returns:
| Type | Description |
|---|---|
Path | Resolved Path object. |
Raises:
| Type | Description |
|---|---|
ValidationError | If path is dangerous or invalid. |
Example
validate_repo_path("/home/user/project") PosixPath('/home/user/project')
Source code in src/code_context_agent/tools/validation.py
validate_file_path ¶
Validate file path is safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | User-provided file path. | required |
must_exist | bool | If True, file must exist. | True |
Returns:
| Type | Description |
|---|---|
Path | Resolved Path object. |
Raises:
| Type | Description |
|---|---|
ValidationError | If path is dangerous or invalid. |
Source code in src/code_context_agent/tools/validation.py
validate_glob_pattern ¶
Validate glob pattern is safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern | str | User-provided glob pattern. | required |
Returns:
| Type | Description |
|---|---|
str | Validated pattern string. |
Raises:
| Type | Description |
|---|---|
ValidationError | If pattern contains dangerous characters. |
Source code in src/code_context_agent/tools/validation.py
validate_path_within_repo ¶
Validate that a path is contained within the repository root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to validate. | required |
repo_root | str | Repository root path. | required |
Returns:
| Type | Description |
|---|---|
Path | Resolved Path object. |
Raises:
| Type | Description |
|---|---|
ValidationError | If path escapes the repository root. |
Source code in src/code_context_agent/tools/validation.py
validate_search_pattern ¶
Validate search pattern (regex) is safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern | str | User-provided search pattern. | required |
max_length | int | Maximum allowed pattern length. | 1000 |
Returns:
| Type | Description |
|---|---|
str | Validated pattern string. |
Raises:
| Type | Description |
|---|---|
ValidationError | If pattern is invalid or too long. |