Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (78 loc) · 2.57 KB
/
Copy pathmain.py
File metadata and controls
94 lines (78 loc) · 2.57 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import sys
from typing import Any, cast
# Use UTF-8 for console output (Windows-safe)
if hasattr(sys.stdout, "reconfigure"):
cast(Any, sys.stdout).reconfigure(encoding="utf-8")
if hasattr(sys.stderr, "reconfigure"):
cast(Any, sys.stderr).reconfigure(encoding="utf-8")
import typer
from rich.console import Console
from rich.panel import Panel
from rich.syntax import Syntax
from rich.markdown import Markdown
from rich.align import Align
from src.agent import CodePilotAgent, Deps
app = typer.Typer(
name="CodePilot",
help="CodePilot - An autonomous AI software engineer CLI.",
no_args_is_help=False,
)
console = Console()
@app.command()
def main(
prompt: str = typer.Argument(
None,
help="The programming task or problem to solve. If not provided, you will be prompted.",
),
):
# Print high-fidelity title banner
console.print(
Panel(
Align.center(
"[bold cyan]CODEPILOT[/bold cyan]\n"
"[dim]Autonomous AI Software Engineer (Pydantic AI + Groq)[/dim]"
),
border_style="cyan",
expand=True,
)
)
# Check/Prompt for task description
if not prompt:
prompt = typer.prompt("What task would you like me to solve?")
console.print()
agent = CodePilotAgent()
deps = Deps()
console.print(f"[bold blue]Task received:[/bold blue] {prompt}\n")
with console.status(
"[bold blue]Analyzing task and generating solutions...[/bold blue]"
):
try:
result = agent.run_sync(prompt, deps=deps)
except Exception as e:
console.print(f"\n[bold red][ERROR] Error executing agent:[/bold red] {e}")
raise typer.Exit(code=1)
# Print final success banner
console.print(
Panel(
Align.center("[bold green]SOLUTION SUCCESSFULLY GENERATED[/bold green]"),
border_style="green",
expand=True,
)
)
console.print()
# Print summary explanation
console.print("[bold cyan]Summary & Explanation:[/bold cyan]")
console.print(Markdown(result.output.summary))
console.print()
# Print final code
lang = result.output.language.lower() if hasattr(result.output, "language") else "python"
console.print(f"[bold cyan]Final Solution ({lang}):[/bold cyan]")
console.print(
Panel(
Syntax(result.output.code, lang, theme="monokai", line_numbers=True),
border_style="green",
title="[bold green]Final Solution[/bold green]",
)
)
if __name__ == "__main__":
app()