Files
zeekay ea3116aac9 Fix all test issues and achieve 100% test pass rate
- Remove all unconditional pytest.skip() calls
- Fix file content tests to handle both strict/non-strict modes
- Fix missing device_capabilities module in hanzo-network
- Fix HanzoNetProvider imports and exports
- Fix local_llm.py import errors
- Create test helper classes for pagination tests
- Fix FastMCP paginator test constructor args
- Configure all API keys from ~/.zsh/after.zsh
- All tests now pass or skip conditionally based on actual requirements
2025-08-12 16:19:34 -05:00

48 lines
1.3 KiB
Python

from dataclasses import asdict, dataclass, fields
from .config import MAX_RESPONSE_LEN_CHAR
from .prompts import CONTENT_TRUNCATED_NOTICE
@dataclass
class ToolResult:
"""Represents the result of a tool execution."""
output: str | None = None
error: str | None = None
def __bool__(self):
return any(getattr(self, field.name) for field in fields(self))
def to_dict(self, extra_field: dict | None = None) -> dict:
result = asdict(self)
# Add extra fields if provided
if extra_field:
result.update(extra_field)
return result
@dataclass
class CLIResult(ToolResult):
"""A ToolResult that can be rendered as a CLI output."""
# Optional fields for file editing commands
path: str | None = None
prev_exist: bool = True
old_content: str | None = None
new_content: str | None = None
def maybe_truncate(
content: str,
truncate_after: int | None = MAX_RESPONSE_LEN_CHAR,
truncate_notice: str = CONTENT_TRUNCATED_NOTICE,
) -> str:
"""Truncate content and append a notice if content exceeds the specified length."""
return (
content
if not truncate_after or len(content) <= truncate_after
else content[:truncate_after] + truncate_notice
)