Skip to content

Commit

Permalink
0.2.4 preparation for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
matebenyovszky committed Nov 10, 2024
1 parent fd0bef3 commit 8e843a8
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config.py
ideas.md
.tokens
.ideas
.initialprompt
.initial_prompt

tests/_healing_agent_exceptions
tests/_healing_agent_backups
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.4] - 2024-11-10
### Added
- New test

### Changed
- Improved error context capture (preparation for v0.3.0)
- Source code verification removed (seems unnecessary)

## [0.2.3] - 2024-11-05
### Added
- Saving global and local variables to context
Expand Down
37 changes: 37 additions & 0 deletions examples/tests/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import requests
import healing_agent
import socket

@healing_agent
def test_api_call():
"""Test function that makes a buggy DNS lookup that will fail and need healing"""
print("♣ Attempting DNS lookup...")

# Intentionally incorrect DNS query setup
# Using wrong port and protocol for DNS lookup
dns_server = "8.8.8.8" # Google's DNS
dns_port = 80 # Wrong port (should be 53)

# Creating TCP socket instead of UDP
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)

# Trying to send malformed DNS query
query = b"VALID_DNS_QUERY"
sock.connect((dns_server, dns_port))
sock.send(query)

# Trying to parse response without proper DNS protocol handling
response = sock.recv(512)
domain_name = response.decode('utf-8')

return domain_name

if __name__ == "__main__":
try:
result = test_api_call()
print(f"♣ DNS Response: {result}")
except Exception as e:
print(f"♣ Test completed with expected error: {str(e)}")


19 changes: 19 additions & 0 deletions healing_agent/agent_tools/tool_check_env_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Experimental and not used.

import os

def get_environment_variables() -> dict:
"""
Get all environment variables and return them as a dictionary.
Returns:
dict: Dictionary containing all environment variables as key-value pairs
"""
env_vars = {}
for key, value in os.environ.items():
env_vars[key] = value
return env_vars

if __name__ == "__main__":
print(get_environment_variables())

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Experimental and not used.

import json
from typing import Any, Dict
from .ai_code_fixer import get_ai_response

## Experimental and not used. Probably a better approach would be the JSON with AI / linter and give feedback accordingly.
from ..ai_code_fixer import get_ai_response

def fix_json_ai(context: Dict[str, Any], config: Dict[str, Any]) -> Any:
"""
Expand Down
116 changes: 116 additions & 0 deletions healing_agent/agent_tools/tool_list_files_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Experimental and not used.

import os
import ast
import json
from typing import Dict, List, Optional, Union

def get_function_details(file_path: str) -> List[Dict[str, str]]:
"""
Extract function names and docstrings from a Python file.
Args:
file_path: Path to the Python file
Returns:
List of dictionaries containing function names and their docstrings
"""
functions = []
try:
with open(file_path, 'r', encoding='utf-8') as f:
tree = ast.parse(f.read())

for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
docstring = ast.get_docstring(node)
functions.append({
"name": node.name,
"docstring": docstring if docstring else "No description available"
})
except Exception as e:
print(f"Error parsing {file_path}: {str(e)}")
return []

return functions

def list_directory_contents(
directory: str,
recursive: bool = False,
include_functions: bool = False
) -> Dict[str, Union[List[str], Dict[str, List[Dict[str, str]]]]]:
"""
List all files in a directory with optional recursive search and Python function details.
Args:
directory: Path to the directory to scan
recursive: Whether to scan subdirectories recursively
include_functions: Whether to extract function details from Python files
Returns:
Dictionary containing:
- files: List of all files
- python_files: Dictionary of Python files and their function details (if include_functions=True)
"""

if not os.path.exists(directory):
raise ValueError(f"Directory {directory} does not exist")

result = {
"files": [],
"python_files": {}
}

def scan_directory(path: str):
for entry in os.scandir(path):
if entry.is_file():
file_path = os.path.relpath(entry.path, directory)
result["files"].append(file_path)

if include_functions and file_path.endswith('.py'):
functions = get_function_details(entry.path)
if functions:
result["python_files"][file_path] = functions

elif entry.is_dir() and recursive:
scan_directory(entry.path)

scan_directory(directory)

# Sort files for consistent output
result["files"].sort()

return result

def get_directory_info(
directory: str = ".",
recursive: bool = False,
include_functions: bool = False,
pretty_print: bool = False
) -> str:
"""
Get directory information in JSON format.
Args:
directory: Path to the directory to scan (defaults to current directory)
recursive: Whether to scan subdirectories recursively
include_functions: Whether to extract function details from Python files
pretty_print: Whether to format the JSON output with indentation
Returns:
JSON string containing directory information
"""
try:
contents = list_directory_contents(
directory,
recursive=recursive,
include_functions=include_functions
)

return json.dumps(contents, indent=2 if pretty_print else None)

except Exception as e:
error_response = {
"error": str(e),
"directory": directory
}
return json.dumps(error_response, indent=2 if pretty_print else None)
Loading

0 comments on commit 8e843a8

Please sign in to comment.