Make read_file always output status panel.

This commit is contained in:
AI Christianson 2024-12-27 19:55:15 -05:00
parent f1727c76d4
commit 5976727359
2 changed files with 6 additions and 15 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix web research prompt. - Fix web research prompt.
- Simplify planning stage by executing tasks directly. - Simplify planning stage by executing tasks directly.
- Make research notes available to more agents/tools. - Make research notes available to more agents/tools.
- Make read_file always output status panel.
## [0.10.2] - 2024-12-26 ## [0.10.2] - 2024-12-26

View File

@ -15,22 +15,13 @@ CHUNK_SIZE = 8192
@tool @tool
def read_file_tool( def read_file_tool(
filepath: str, filepath: str,
verbose: bool = True,
encoding: str = 'utf-8' encoding: str = 'utf-8'
) -> Dict[str, str]: ) -> Dict[str, str]:
"""Read and return the contents of a text file. """Read and return the contents of a text file.
Args: Args:
filepath: Path to the file to read filepath: Path to the file to read
verbose: Whether to display a Rich panel with read statistics (default: True)
encoding: File encoding to use (default: utf-8) encoding: File encoding to use (default: utf-8)
Returns:
Dict containing:
- content: The file contents as a string (truncated if needed)
Raises:
RuntimeError: If file cannot be read or does not exist
""" """
start_time = time.time() start_time = time.time()
try: try:
@ -60,12 +51,11 @@ def read_file_tool(
logging.debug(f"File read complete: {total_bytes} bytes in {elapsed:.2f}s") logging.debug(f"File read complete: {total_bytes} bytes in {elapsed:.2f}s")
logging.debug(f"Pre-truncation stats: {total_bytes} bytes, {line_count} lines") logging.debug(f"Pre-truncation stats: {total_bytes} bytes, {line_count} lines")
if verbose: console.print(Panel(
console.print(Panel( f"Read {line_count} lines ({total_bytes} bytes) from {filepath} in {elapsed:.2f}s",
f"Read {line_count} lines ({total_bytes} bytes) from {filepath} in {elapsed:.2f}s", title="📄 File Read",
title="📄 File Read", border_style="bright_blue"
border_style="bright_blue" ))
))
# Truncate if needed # Truncate if needed
truncated = truncate_output(full_content) if full_content else "" truncated = truncate_output(full_content) if full_content else ""