-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtui.py
More file actions
194 lines (160 loc) · 6.48 KB
/
tui.py
File metadata and controls
194 lines (160 loc) · 6.48 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import asyncio
from collections.abc import Generator
from datetime import datetime
import json
from typing import ClassVar
import httpx
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer, Header, Input, RichLog
import websockets
class ProximusNovaTUI(App):
"""A Textual app to manage the Proximus-Nova Orchestrator live."""
CSS = """
Screen {
background: #09090b;
color: #f1f5f9;
}
#log {
height: 1fr;
border: solid #27272a;
background: #09090b;
padding: 1;
}
#cmd_input {
dock: bottom;
margin: 1 0;
border: solid #10b981;
background: #09090b;
color: #f1f5f9;
}
Header {
background: #050505;
color: #34d399;
}
"""
BINDINGS: ClassVar[list[Binding]] = [
Binding("ctrl+c", "quit", "Quit", show=True),
Binding("ctrl+l", "clear_log", "Clear Log", show=True),
]
TITLE = "Proximus-Nova Orchestrator"
SUB_TITLE = "Live Control Plane"
def compose(self) -> Generator[ComposeResult, None, None]:
yield Header(show_clock=True)
yield RichLog(id="log", highlight=True, wrap=True, markup=True)
yield Input(
placeholder="➜ Type a goal (e.g. 'Build a Next.js landing page...')",
id="cmd_input",
)
yield Input(
placeholder="➜ Your Business Goal (e.g. 'Build a SaaS scaffold')",
id="cmd_input",
)
yield Footer()
def on_mount(self) -> None:
log = self.query_one(RichLog)
# Initial boot sequence logs
log.write("[bold cyan]Loading Proximus-Nova kernel...[/]")
log.write("[bold cyan]Initializing AI sub-systems: [/][bold green][OK][/]")
log.write(
"[bold cyan]Mounting Model Context Protocol (MCP): [/][bold green][OK][/]"
)
log.write(
"[bold cyan]Connecting to Amazon Bedrock Nova Foundation: [/][bold green][READY][/]"
)
log.write("\n[dim]Awaiting command... Type 'exit' to quit.[/]")
self.query_one(Input).focus()
def action_clear_log(self) -> None:
"""Action for clearing the log."""
self.query_one(RichLog).clear()
async def simulate_execution(self, command: str) -> None:
"""Simulate execution logic streaming into the log."""
log = self.query_one(RichLog)
await asyncio.sleep(0.5)
log.write(f"[dim]\\[Orchestrator] Parsing intent for: '{command}'[/]")
await asyncio.sleep(1.0)
log.write("[bold magenta]\\[Engineer Agent][/] ➜ Generating execution plan...")
await asyncio.sleep(1.5)
log.write(
"[bold yellow]\\[System][/] ➜ Executing terminal command mapping context."
)
await asyncio.sleep(2.0)
log.write(
"[bold green]\\[Success][/] Task simulated successfully. (Run full system to see actual agent workflows)."
)
log.write("[bold cyan]Proximus-Nova TUI v1.0[/]")
log.write("[dim]Searching for orchestrator at http://localhost:8080...[/]")
self.query_one(Input).focus()
async def stream_events(self, project_id: str):
log = self.query_one(RichLog)
uri = f"ws://localhost:8080/ws/{project_id}"
try:
async with websockets.connect(uri) as websocket:
log.write(f"[bold green]Connected to project {project_id}[/]")
while True:
message = await websocket.recv()
data = json.loads(message)
event_type = data.get("type", "unknown")
agent = data.get("agent", "System")
text = data.get("message", "")
# Formatting based on role
colors = {
"CEO": "blue",
"CTO": "magenta",
"Engineer_Backend": "green",
"Engineer_Frontend": "cyan",
"QA": "yellow",
"DevOps": "red",
"Orchestrator": "white",
}
color = colors.get(agent, "dim")
timestamp = datetime.now(timezone.utc).strftime("%H:%M:%S")
if event_type == "thinking":
log.write(
f"[dim]{timestamp}[/] [bold {color}]\\[{agent}][/] [italic dim]{text}[/]"
)
elif event_type == "task_start":
log.write(
f"[dim]{timestamp}[/] [bold {color}]\\[{agent}][/] ➜ Starting: [bold]{text}[/]"
)
elif event_type == "task_completed":
log.write(
f"[dim]{timestamp}[/] [bold {color}]\\[{agent}][/] ✅ [green]Completed[/]"
)
elif event_type == "phase_change":
log.write(f"\n[bold white]-- PHASE CHANGE: {text} --[/]\n")
else:
log.write(
f"[dim]{timestamp}[/] [bold {color}]\\[{agent}][/] {text}"
)
except Exception as e:
log.write(f"[bold red]Connection lost: {e!s}[/]")
async def on_input_submitted(self, event: Input.Submitted) -> None:
idea = event.value.strip()
if not idea:
return
input_widget = self.query_one(Input)
log = self.query_one(RichLog)
input_widget.value = ""
if idea.lower() in ("exit", "quit"):
self.exit()
return
log.write(f"\n[bold white]➜ {idea}[/]")
self.run_worker(self.simulate_execution(idea), exclusive=True)
log.write(f"\n[bold white]🚀 Launching Goal:[/] {idea}")
try:
async with httpx.AsyncClient() as client:
resp = await client.post(
"http://localhost:8080/v1/projects",
json={"idea": idea, "name": idea[:30]},
timeout=10.0,
)
resp.raise_for_status()
project = resp.json()
project_id = project["id"]
# Start listener background task
self.run_worker(self.stream_events(project_id))
except Exception as e:
log.write(f"[bold red]Failed to launch project: {e!s}[/]")
if __name__ == "__main__":
ProximusNovaTUI().run()