-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmalaz_cli.py
More file actions
112 lines (90 loc) · 4.08 KB
/
malaz_cli.py
File metadata and controls
112 lines (90 loc) · 4.08 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os
import argparse
from rich.console import Console
from rich.syntax import Syntax
from core.agent import CodingAgent
from core.memory import SessionMemory
try:
from core import __version__
except ImportError:
__version__ = "1.0.0"
console = Console()
def main():
console.print("Malaz - AI Coding Agent", style="bold green")
parser = argparse.ArgumentParser(description='Malaz - AI Coding Agent')
parser.add_argument('--project', type=str, default=os.getcwd(), help='Project directory')
parser.add_argument('--version', action='version', version=f'Malaz {__version__}')
parser.add_argument('command', nargs='?', type=str, help='Direct command to execute')
args = parser.parse_args()
session_memory = SessionMemory()
agent = CodingAgent(project_path=args.project)
if args.command:
# Direct command execution
console.print(f"[bold cyan]Executing:[/] {args.command}")
response = agent.process_request(args.command, session_memory)
console.print(f"[bold green]\n{response}\n[/]")
return
# Interactive mode
console.print("[bold magenta]\n✨ Welcome to Malaz AI Agent![/]")
console.print("Type '/help' for commands, '!review <file>' for code review, '!commit' to save changes\n")
console.print("Type '/exit' to quit\n")
while True:
try:
user_input = console.input("[bold cyan]malaz> [/]")
if user_input.lower() == '/exit':
break
if user_input.startswith('/'):
handle_command(user_input, agent, session_memory)
continue
# Handle special commands
if user_input.startswith('!'):
response = agent.process_request(user_input, session_memory)
# Format code review output
if user_input.startswith('!review'):
console.print(Syntax(response, "text", theme="monokai", line_numbers=True))
else:
console.print(f"[bold green]\n{response}\n[/]")
continue
# Process natural language request
response = agent.process_request(user_input, session_memory)
console.print(f"[bold green]\n{response}\n[/]")
except KeyboardInterrupt:
console.print("\n[bold yellow]Session interrupted. Type /exit to quit[/]")
except Exception as e:
console.print(f"[bold red]Error: {str(e)}[/]")
def handle_command(command: str, agent: CodingAgent, memory: SessionMemory):
"""Handle custom commands"""
cmd_parts = command[1:].split()
if not cmd_parts:
return
cmd = cmd_parts[0].lower()
if cmd == "help":
console.print("[bold]Available Commands:[/]")
console.print("/help - Show this help")
console.print("/reset - Reset session memory")
console.print("/context - Show project context")
console.print("/history - Show conversation history")
console.print("/tools - List available tools")
console.print("/state - Show current project state")
console.print("/exit - Exit the program")
elif cmd == "reset":
memory.reset()
console.print("[green]Session memory has been reset[/]")
elif cmd == "context":
console.print(f"[bold]Project Context:[/]\n{agent.context}")
elif cmd == "history":
console.print("[bold]Conversation History:[/]")
for i, item in enumerate(memory.history, 1):
console.print(f"{i}. User: {item['user']}")
console.print(f" Agent: {item['agent']}")
elif cmd == "tools":
console.print("[bold]Available Tools:[/]")
for tool in agent.tool_manager.list_tools():
console.print(f"- {tool['name']}: {tool['description']}")
elif cmd == "state":
console.print(f"[bold]Project Path:[/] {agent.project_path}")
console.print(f"[bold]Context:[/]\n{agent.context}")
else:
console.print(f"[red]Unknown command: {cmd}[/]")
if __name__ == "__main__":
main()