From 512bec273667096c5f2cf65e259dcdf957ae7e3f Mon Sep 17 00:00:00 2001 From: jayhack Date: Wed, 12 Feb 2025 16:55:16 -0800 Subject: [PATCH] fixed tools on unknown files --- src/codegen/extensions/tools/file_operations.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/codegen/extensions/tools/file_operations.py b/src/codegen/extensions/tools/file_operations.py index 27900d4d5..d21d8ffac 100644 --- a/src/codegen/extensions/tools/file_operations.py +++ b/src/codegen/extensions/tools/file_operations.py @@ -25,13 +25,7 @@ def view_file(codebase: Codebase, filepath: str) -> dict[str, Any]: pass if not file: - for f in codebase.files: - if f.file_path.endswith(filepath): - file = f - break - - if not file: - return {"error": f"File not found: {filepath}"} + return {"error": f"File not found: {filepath}. Please use full filepath relative to workspace root."} return { "filepath": file.filepath, @@ -106,6 +100,8 @@ def edit_file(codebase: Codebase, filepath: str, content: str) -> dict[str, Any] file = codebase.get_file(filepath) except ValueError: return {"error": f"File not found: {filepath}"} + if file is None: + return {"error": f"File not found: {filepath}"} file.edit(content) codebase.commit() @@ -144,6 +140,8 @@ def delete_file(codebase: Codebase, filepath: str) -> dict[str, Any]: file = codebase.get_file(filepath) except ValueError: return {"error": f"File not found: {filepath}"} + if file is None: + return {"error": f"File not found: {filepath}"} file.remove() codebase.commit() @@ -165,6 +163,8 @@ def rename_file(codebase: Codebase, filepath: str, new_filepath: str) -> dict[st file = codebase.get_file(filepath) except ValueError: return {"error": f"File not found: {filepath}"} + if file is None: + return {"error": f"File not found: {filepath}"} if codebase.has_file(new_filepath): return {"error": f"Destination file already exists: {new_filepath}"} @@ -204,6 +204,8 @@ def move_symbol( source = codebase.get_file(source_file) except ValueError: return {"error": f"Source file not found: {source_file}"} + if source is None: + return {"error": f"Source file not found: {source_file}"} try: target = codebase.get_file(target_file)