-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
228 lines (181 loc) · 6.36 KB
/
cli.py
File metadata and controls
228 lines (181 loc) · 6.36 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import sys
import os
import asyncio
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical
from textual.widgets import Header, Footer, TextArea, Input, Button, Static, Markdown, LoadingIndicator
from textual.reactive import reactive
# Import processing logic directly
from engine.dispatcher import process_submission
class ResultView(Static):
"""A widget to display the analysis results."""
results_text = reactive("")
def render(self) -> str:
return self.results_text
class AICodeJudgeApp(App):
"""A Textual TUI for ELS JUDGE."""
CSS = """
Screen {
background: $background;
}
Header {
background: #d6336c;
color: white;
text-style: bold;
}
Footer {
background: $surface;
color: #f06595;
}
#main_container {
padding: 0;
width: 100%;
height: 100%;
layout: horizontal;
}
#left_pane {
width: 40%;
height: 100%;
border-right: solid #d6336c;
padding-right: 1;
}
#right_pane {
width: 60%;
height: 100%;
padding-left: 1;
}
.label {
color: #f06595;
text-style: bold;
margin-bottom: 0;
margin-top: 1;
}
TextArea {
height: 100;
border: solid #d6336c;
background: $surface;
color: $text;
}
TextArea:focus {
border: double #f06595;
}
Input {
border: solid #d6336c;
background: $surface;
color: $text;
}
Input:focus {
border: double #f06595;
}
Button {
width: 100%;
margin-top: 1;
background: #d6336c;
color: white;
text-style: bold;
}
Button:hover {
background: #a61e4d;
}
#branding_footer {
color: #f06595;
text-style: italic;
text-align: center;
margin-top: 1;
}
#results_container {
height: 100%;
overflow-y: scroll;
border: solid #d6336c;
background: $surface;
padding: 1;
}
LoadingIndicator {
color: #f06595;
}
MarkdownH2 {
color: #d6336c;
text-style: bold;
}
MarkdownHr {
color: #f06595;
border-bottom: heavy #f06595;
margin: 2 0;
}
"""
BINDINGS = [
("q", "quit", "Quit"),
("ctrl+r", "analyze", "Analyze Code")
]
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header(show_clock=True)
with Container(id="main_container"):
# Left Pane: Inputs
with Vertical(id="left_pane"):
yield Static("Target Files (space separated):", classes="label")
yield Input(id="files_input", placeholder="e.g. core/config.py engine/reviewers.py")
yield Static("What should be improved?", classes="label")
yield Input(id="prompt_input", placeholder="e.g. Add type hints and error handling")
yield Button("Analyze with 2 AI Models", id="submit_btn", variant="primary")
yield Static("Built by codedbyelif", id="branding_footer")
# Right Pane: Results
with Vertical(id="right_pane"):
yield Static("Analysis Report:", classes="label")
with Container(id="results_container"):
yield Markdown("## Welcome to ELS JUDGE\n\n1. List target files on the left.\n2. Enter your instructions.\n3. Press **Analyze** to submit.", id="markdown_result")
yield LoadingIndicator(id="loading", classes="hidden")
yield Footer()
def on_mount(self) -> None:
self.title = "ELS JUDGE"
self.query_one("#loading").display = False
async def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "submit_btn":
await self.action_analyze()
async def action_analyze(self) -> None:
files_input = self.query_one("#files_input", Input).value
prompt_input = self.query_one("#prompt_input", Input).value
if not files_input.strip() or not prompt_input.strip():
self.query_one("#markdown_result", Markdown).update("### Error\nPlease provide both target files and a prompt.")
return
target_files = [f.strip() for f in files_input.split() if f.strip()]
# Show loading
btn = self.query_one("#submit_btn", Button)
btn.disabled = True
btn.label = "Analyzing..."
md_view = self.query_one("#markdown_result", Markdown)
loading = self.query_one("#loading", LoadingIndicator)
md_view.display = False
loading.display = True
# Call processing logic directly
self.run_worker(self.fetch_analysis(target_files, prompt_input), exclusive=True)
async def fetch_analysis(self, target_files: list[str], prompt: str) -> None:
try:
# Process submission directly through the dispatcher
result = await process_submission(target_files, prompt)
md_report = result.get("report", "No report generated.")
self.update_success(md_report)
except Exception as e:
self.update_error(str(e))
def update_success(self, markdown_text: str) -> None:
self.query_one("#loading").display = False
md_view = self.query_one("#markdown_result", Markdown)
md_view.update(markdown_text)
md_view.display = True
btn = self.query_one("#submit_btn", Button)
btn.disabled = False
btn.label = "Analyze with 2 AI Models"
def update_error(self, error_msg: str) -> None:
self.query_one("#loading").display = False
md_view = self.query_one("#markdown_result", Markdown)
md_view.update(f"### Engine Error\nAn error occurred during analysis.\n\nDetails: `{error_msg}`")
md_view.display = True
btn = self.query_one("#submit_btn", Button)
btn.disabled = False
btn.label = "Analyze with 2 AI Models"
if __name__ == "__main__":
app = AICodeJudgeApp()
app.run()
if __name__ == "__main__":
app = AICodeJudgeApp()
app.run()