-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (26 loc) · 1.02 KB
/
Copy pathmain.py
File metadata and controls
30 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import typer
from rich.console import Console
from agent import run_agent
def main(
file: str = typer.Option(..., help="The path to the python file to refactor"),
instruction: str = typer.Option(..., help="What you want the agent to improve")
):
"""
Autonomous Agent that refactors code based on your instructions.
"""
console = Console()
console.print(f"[bold green]Starting Refactor Agent on {file}...[/bold green]")
prompt = (
f"Read the file at '{file}'. "
f"Refactor the code following this instruction: '{instruction}'. "
"Ensure the new code is syntactically correct using the validate_syntax tool. "
f"If valid, overwrite the file at '{file}' with the improved code."
)
try:
response = run_agent(prompt)
console.print("\n[bold blue]Agent Finished:[/bold blue]")
console.print(response)
except Exception as e:
console.print(f"[bold red]An error occurred:[/bold red] {e}")
if __name__ == "__main__":
typer.run(main)