shell
code_context_agent.tools.shell ¶
Unified shell command executor.
This module provides a secure, bounded shell command execution utility shared across all tool modules.
CommandResult ¶
Bases: TypedDict
Result of a shell command execution.
ToolResult ¶
Bases: FrozenModel
Standardized result structure for tool responses.
Provides a consistent JSON serialization pattern for tool outputs.
Example
result = ToolResult(status="success", data={"count": 42}) return result.to_json() '{"status": "success", "data": {"count": 42}}'
result = ToolResult.error("File not found") return result.to_json() '{"status": "error", "error": "File not found"}'
run_command ¶
Run shell command with bounds.
Uses shell=False with shlex parsing for security. For commands requiring shell features (pipes, redirects), pass a list like ["sh", "-c", "cmd"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd | str | list[str] | Command string or list of arguments. | required |
cwd | str | None | Working directory. | None |
timeout | int | Maximum execution time in seconds. | 120 |
max_output | int | Maximum characters to capture. | 100000 |
input_data | str | None | Optional string to send to stdin. | None |
Returns:
| Type | Description |
|---|---|
CommandResult | Dict with status, stdout, stderr, return_code, and truncated flag. |