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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//! Inner panel body rendering for [`AIInspectorPanel`].
//!
//! Contains `render_panel_body`, which is called from `show()` inside the
//! egui `Area` closure. Extracted here to keep `mod.rs` under 500 lines.
use egui::{Color32, Frame, RichText, Stroke};
use par_term_acp::{AgentConfig, AgentStatus};
use crate::ui_constants::{
AI_PANEL_CMD_SCROLL_MAX_HEIGHT, AI_PANEL_CMD_SCROLL_MIN_HEIGHT, AI_PANEL_INNER_INSET,
AI_PANEL_INNER_MARGIN,
};
use super::AIInspectorPanel;
use super::types::{InspectorAction, PANEL_BG};
impl AIInspectorPanel {
/// Render the full panel interior (frame + all sections) for a single egui frame.
///
/// Returns the [`InspectorAction`] produced by user interactions inside the panel.
pub(super) fn render_panel_body(
&mut self,
ui: &mut egui::Ui,
available_agents: &[AgentConfig],
) -> (InspectorAction, bool) {
let mut close_requested = false;
let mut action = InspectorAction::None;
let inner_width = self.width - AI_PANEL_INNER_INSET;
let panel_frame = Frame::new()
.fill(PANEL_BG)
.stroke(Stroke::new(1.0, Color32::from_gray(50)))
.inner_margin(AI_PANEL_INNER_MARGIN);
let viewport = ui.ctx().input(|i| i.viewport_rect());
panel_frame.show(ui, |ui| {
let panel_inner_height =
(viewport.height() - crate::ui_constants::AI_PANEL_HEIGHT_INSET).max(0.0);
ui.set_min_width(inner_width);
ui.set_max_width(inner_width);
ui.set_min_height(panel_inner_height);
ui.set_max_height(panel_inner_height);
// === Title bar ===
ui.horizontal(|ui| {
ui.heading(
RichText::new("Assistant")
.strong()
.color(Color32::from_gray(220)),
);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui
.button(RichText::new("X").size(14.0))
.on_hover_text("Close (Escape)")
.clicked()
{
close_requested = true;
}
});
});
ui.add_space(4.0);
ui.separator();
ui.add_space(4.0);
// === Agent connection bar (above terminal capture) ===
let agent_action = self.render_agent_bar(ui, available_agents);
if !matches!(agent_action, InspectorAction::None) {
action = agent_action;
}
ui.add_space(4.0);
ui.separator();
ui.add_space(4.0);
// === Collapsible terminal capture section ===
egui::CollapsingHeader::new(
RichText::new("Terminal Capture")
.color(Color32::from_gray(180))
.strong(),
)
.id_salt("terminal_capture_section")
.default_open(false)
.show(ui, |ui| {
// --- Controls row ---
self.render_controls(ui);
ui.add_space(4.0);
ui.separator();
ui.add_space(4.0);
// --- Environment strip ---
if let Some(ref snapshot) = self.snapshot {
self.render_environment(ui, snapshot);
ui.add_space(4.0);
ui.separator();
ui.add_space(4.0);
}
// --- Commands content ---
let cmd_height = (ui.available_height() * 0.5).clamp(
AI_PANEL_CMD_SCROLL_MIN_HEIGHT,
AI_PANEL_CMD_SCROLL_MAX_HEIGHT,
);
egui::ScrollArea::vertical()
.id_salt("capture_commands_scroll")
.max_height(cmd_height)
.auto_shrink([false, false])
.show(ui, |ui| {
if let Some(ref snapshot) = self.snapshot {
if snapshot.commands.is_empty() {
ui.vertical_centered(|ui| {
ui.add_space(20.0);
ui.label(
RichText::new("No commands captured yet")
.color(Color32::from_gray(100))
.italics(),
);
ui.add_space(4.0);
ui.label(
RichText::new(
"Run some commands in the terminal\nto see them here.",
)
.color(Color32::from_gray(80))
.small(),
);
});
} else {
match self.view_mode {
super::types::ViewMode::Cards => {
Self::render_cards(ui, &snapshot.commands);
}
super::types::ViewMode::Timeline => {
Self::render_timeline(ui, &snapshot.commands);
}
super::types::ViewMode::Tree => {
Self::render_tree(ui, &snapshot.commands);
}
super::types::ViewMode::ListDetail => {
Self::render_list_detail(ui, &snapshot.commands);
}
}
}
} else {
ui.vertical_centered(|ui| {
ui.add_space(20.0);
ui.label(
RichText::new("No snapshot available")
.color(Color32::from_gray(100))
.italics(),
);
ui.add_space(4.0);
ui.label(
RichText::new("Click Refresh to capture terminal state.")
.color(Color32::from_gray(80))
.small(),
);
});
}
});
});
ui.add_space(4.0);
ui.separator();
ui.add_space(4.0);
// Reserve space for pinned bottom elements
let input_lines = if self.agent_status == AgentStatus::Connected {
self.chat.input.lines().count().clamp(1, 6) as f32
} else {
0.0
};
let bottom_reserve = if self.agent_status == AgentStatus::Connected {
90.0 + (input_lines - 1.0).max(0.0) * 14.0
} else {
36.0
};
let available_height = (ui.available_height() - bottom_reserve).max(50.0);
// === Scrollable content: chat messages ===
egui::ScrollArea::vertical()
.id_salt("inspector_scroll")
.max_height(available_height)
.auto_shrink([false, false])
.stick_to_bottom(true)
.show(ui, |ui| {
if !self.chat.messages.is_empty() || self.chat.streaming {
ui.add_space(4.0);
ui.label(
RichText::new("Chat")
.color(Color32::from_gray(160))
.small()
.strong(),
);
ui.add_space(4.0);
let chat_action = Self::render_chat_messages(
ui,
&self.chat,
self.chat_font_size,
self.agent_terminal_access,
);
if !matches!(chat_action, InspectorAction::None) {
action = chat_action;
}
}
});
// === Pinned bottom: Chat input + checkbox + action bar ===
if self.agent_status == AgentStatus::Connected {
ui.add_space(4.0);
ui.separator();
ui.add_space(2.0);
let input_action = self.render_chat_input(ui);
if !matches!(input_action, InspectorAction::None) {
action = input_action;
}
ui.add_space(2.0);
ui.horizontal(|ui| {
if ui
.checkbox(
&mut self.agent_terminal_access,
RichText::new("Terminal access")
.small()
.color(Color32::from_gray(160)),
)
.on_hover_text(
"When enabled, shell commands the agent writes in fenced code \
blocks (```bash / ```sh) are automatically sent to your active \
terminal and executed. The agent is notified of the exit code \
after each command completes.",
)
.changed()
{
action = InspectorAction::SetTerminalAccess(self.agent_terminal_access);
}
let yolo_color = if self.auto_approve {
Color32::from_rgb(255, 193, 7)
} else {
Color32::from_gray(160)
};
if ui
.checkbox(
&mut self.auto_approve,
RichText::new("YOLO").small().color(yolo_color),
)
.on_hover_text("Auto-approve all agent permission requests")
.changed()
{
let mode = if self.auto_approve {
"bypassPermissions"
} else {
"default"
};
action = InspectorAction::SetAgentMode(mode.to_string());
}
});
}
ui.add_space(4.0);
ui.separator();
ui.add_space(2.0);
let bar_action = self.render_action_bar(ui);
if !matches!(bar_action, InspectorAction::None) {
action = bar_action;
}
});
(action, close_requested)
}
}