Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions agent/tools/codemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_code_definitions(file_path: str) -> str:
return "\n".join(output_lines)

@tool(parse_docstring=True)
def get_function_implementation(file_path: str, function_name: str) -> Optional[str]:
def get_function_implementation(file_path: str, function_name: str) -> str:
"""
Extract the implementation of a specific function or method from a file.

Expand All @@ -119,7 +119,7 @@ def get_function_implementation(file_path: str, function_name: str) -> Optional[
}
lang = lang_map.get(suffix)
if not lang:
return None
return f"Unsupported file type: {suffix}"

# Initialize parser
language = get_language(lang)
Expand Down Expand Up @@ -178,7 +178,7 @@ def get_function_implementation(file_path: str, function_name: str) -> Optional[

return "\n".join(output_lines)

return None
return f"Function '{function_name}' not found in {file_path}"

@tool(parse_docstring=True)
def get_code_definitions_multi(file_paths: list[str]) -> str:
Expand All @@ -202,12 +202,17 @@ def get_code_definitions_multi(file_paths: list[str]) -> str:
def get_raw_file_content(file_path: str) -> str:
"""
Get the raw content of the file. good for a non-code files

Args:
file_path: file path to read
"""
with open(file_path, "rb") as f:
return f.read().decode('utf-8')
try:
with open(file_path, "rb") as f:
return f.read().decode('utf-8')
except FileNotFoundError:
return f"Error: File '{file_path}' not found"
except Exception as e:
return f"Error reading file '{file_path}': {str(e)}"

# List of available tools
codemap_tools = [get_code_definitions, get_function_implementation, get_code_definitions_multi, get_raw_file_content]
Expand Down
10 changes: 7 additions & 3 deletions agent/tools/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ def create_file(path: str, content: str) -> str:
str: A success message with the file path, or an error message if creation failed
"""
try:
# Check if file already exists
# Ensure the directory exists
os.makedirs(os.path.dirname(path), exist_ok=True)
if os.path.exists(path):
return f"Error: File {path} already exists. Use write_to_file to overwrite it."

# Ensure the directory exists (only if there is a directory component)
dir_name = os.path.dirname(path)
if dir_name:
os.makedirs(dir_name, exist_ok=True)

with open(path, "w", encoding="utf-8") as f:
f.write(content)
Expand Down