-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd0bef3
commit 8e843a8
Showing
16 changed files
with
453 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
|
6 changes: 3 additions & 3 deletions
6
healing_agent/json_fixer.py → healing_agent/agent_tools/tool_json_fixer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.