From 4aeb52e41dd79f3057a485ee881720ac4ca20372 Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Wed, 26 Feb 2025 20:01:00 -0500 Subject: [PATCH] enable file editing tools --- ra_aid/prompts.py | 3 --- ra_aid/tool_configs.py | 10 +++++---- ra_aid/tools/agent.py | 2 -- ra_aid/tools/file_str_replace.py | 5 ----- ra_aid/tools/write_file.py | 38 ++++++++++---------------------- 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/ra_aid/prompts.py b/ra_aid/prompts.py index 8cfd984..50e9b81 100644 --- a/ra_aid/prompts.py +++ b/ra_aid/prompts.py @@ -487,7 +487,6 @@ Important Notes: - Do not add features not explicitly required. - Only create or modify files directly related to this task. - Use file_str_replace and put_complete_file_contents for simple file modifications. -- Delegate to run_programming_task for more complex programming tasks. This is a capable human programmer that can work on multiple files at once. Testing: @@ -527,8 +526,6 @@ FOLLOW TEST DRIVEN DEVELOPMENT (TDD) PRACTICES WHERE POSSIBE. E.G. COMPILE CODE IF YOU CAN SEE THE CODE WRITTEN/CHANGED BY THE PROGRAMMER, TRUST IT. YOU DO NOT NEED TO RE-READ EVERY FILE WITH EVERY SMALL EDIT. -YOU MUST CALL emit_related_files BEFORE CALLING run_programming_task WITH ALL RELEVANT FILES, UNLESS THEY ARE ALREADY RECORDED AS RELATED FILES. - NEVER ANNOUNCE WHAT YOU ARE DOING, JUST DO IT! """ diff --git a/ra_aid/tool_configs.py b/ra_aid/tool_configs.py index ebc8f08..2b66bc2 100644 --- a/ra_aid/tool_configs.py +++ b/ra_aid/tool_configs.py @@ -8,6 +8,8 @@ from ra_aid.tools import ( emit_key_snippet, emit_related_files, emit_research_notes, + file_str_replace, + put_complete_file_contents, fuzzy_find_project_files, list_directory_tree, read_file_tool, @@ -78,10 +80,10 @@ def get_all_tools() -> list[BaseTool]: # Define constant tool groups READ_ONLY_TOOLS = get_read_only_tools() -# MODIFICATION_TOOLS = [run_programming_task, put_complete_file_contents] -MODIFICATION_TOOLS = [ - run_programming_task -] # having put_complete_file_contents causes trouble :( +MODIFICATION_TOOLS = [file_str_replace, put_complete_file_contents] +# MODIFICATION_TOOLS = [ +# run_programming_task +# ] # having put_complete_file_contents causes trouble :( COMMON_TOOLS = get_read_only_tools() EXPERT_TOOLS = [emit_expert_context, ask_expert] RESEARCH_TOOLS = [ diff --git a/ra_aid/tools/agent.py b/ra_aid/tools/agent.py index 1e75da9..1f41282 100644 --- a/ra_aid/tools/agent.py +++ b/ra_aid/tools/agent.py @@ -311,7 +311,6 @@ def request_task_implementation(task_spec: str) -> Dict[str, Any]: } if work_log is not None: response_data["work_log"] = work_log - print("TASK HERE", response_data) return response_data @@ -378,5 +377,4 @@ def request_implementation(task_spec: str) -> Dict[str, Any]: if work_log is not None: response_data["work_log"] = work_log - print("HERE", response_data) return response_data diff --git a/ra_aid/tools/file_str_replace.py b/ra_aid/tools/file_str_replace.py index ba596e9..73bc217 100644 --- a/ra_aid/tools/file_str_replace.py +++ b/ra_aid/tools/file_str_replace.py @@ -47,11 +47,6 @@ def file_str_replace(filepath: str, old_str: str, new_str: str) -> Dict[str, any filepath: Path to the file to modify old_str: Exact string to replace new_str: String to replace with - - Returns: - Dict containing: - - success: Whether the operation succeeded - - message: Success confirmation or error details """ try: path = Path(filepath) diff --git a/ra_aid/tools/write_file.py b/ra_aid/tools/write_file.py index af935f2..922b755 100644 --- a/ra_aid/tools/write_file.py +++ b/ra_aid/tools/write_file.py @@ -15,7 +15,6 @@ def put_complete_file_contents( filepath: str, complete_file_contents: str = "", encoding: str = "utf-8", - verbose: bool = True, ) -> Dict[str, any]: """Write the complete contents of a file, creating it if it doesn't exist. This tool is specifically for writing the entire contents of a file at once, @@ -28,17 +27,6 @@ def put_complete_file_contents( complete_file_contents: Complete string content to write to the file. Defaults to an empty string, which will create an empty file. encoding: File encoding to use (default: utf-8) - verbose: Whether to display a Rich panel with write statistics (default: True) - - Returns: - Dict containing: - - success: Boolean indicating if write was successful - - bytes_written: Number of bytes written - - elapsed_time: Time taken in seconds - - error: Error message if any (None if successful) - - Raises: - RuntimeError: If file cannot be written """ start_time = time.time() result = { @@ -77,14 +65,13 @@ def put_complete_file_contents( f"File write complete: {bytes_written} bytes in {elapsed:.2f}s" ) - if verbose: - console.print( - Panel( - f"{'Initialized empty file' if not complete_file_contents else f'Wrote {bytes_written} bytes'} at {filepath} in {elapsed:.2f}s", - title="💾 File Write", - border_style="bright_green", - ) + console.print( + Panel( + f"{'Initialized empty file' if not complete_file_contents else f'Wrote {bytes_written} bytes'} at {filepath} in {elapsed:.2f}s", + title="💾 File Write", + border_style="bright_green", ) + ) except Exception as e: elapsed = time.time() - start_time @@ -97,13 +84,12 @@ def put_complete_file_contents( else: result["message"] = error_msg - if verbose: - console.print( - Panel( - f"Failed to write {filepath}\nError: {error_msg}", - title="❌ File Write Error", - border_style="red", - ) + console.print( + Panel( + f"Failed to write {filepath}\nError: {error_msg}", + title="❌ File Write Error", + border_style="red", ) + ) return result