Skip to content

shell

code_context_agent.tools.shell

Standardized tool-response helper.

Provides :class:ToolResult, the JSON-serialization pattern shared by the git/discovery tools. Bounded shell execution (run_command / CommandResult) and the path validators now live in :mod:strands_teams.security; this module keeps only the domain response helper.

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"}'

to_json

to_json()

Serialize to JSON string, omitting None values.

Source code in packages/code-context-agent/src/code_context_agent/tools/shell.py
def to_json(self) -> str:
    """Serialize to JSON string, omitting None values."""
    d: dict[str, Any] = {"status": self.status}
    if self.data:
        d.update(self.data)
    if self.error_message:
        d["error"] = self.error_message
    return json.dumps(d)

success classmethod

success(**data)

Create a success result with data.

Source code in packages/code-context-agent/src/code_context_agent/tools/shell.py
@classmethod
def success(cls, **data: Any) -> ToolResult:
    """Create a success result with data."""
    return cls(status="success", data=data or None)

error classmethod

error(message, **extra)

Create an error result.

Source code in packages/code-context-agent/src/code_context_agent/tools/shell.py
@classmethod
def error(cls, message: str, **extra: Any) -> ToolResult:
    """Create an error result."""
    return cls(status="error", error_message=message, data=extra or None)