par-term 0.32.1

Cross-platform GPU-accelerated terminal emulator with inline graphics support (Sixel, iTerm2, Kitty)
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
//! AI Inspector side panel UI.
//!
//! Provides an egui-based side panel for viewing terminal state snapshots,
//! command history, and environment info. Supports multiple view modes
//! (Cards, Timeline, Tree, ListDetail) and interactive controls.
//!
//! Sub-modules:
//! - `types`         — `ViewMode`, `InspectorAction`, constants
//! - `snapshot_view` — controls row, environment strip, Cards/Timeline/Tree/ListDetail renderers
//! - `chat_view`     — agent bar, action bar, chat messages, rich text, chat input

mod chat_view;
mod message_render;
mod panel_body;
mod snapshot_view;
pub mod types;

pub use types::{InspectorAction, ViewMode};

use egui::{Color32, Context, CursorIcon, Id, Key, Order, Pos2, Stroke};

use crate::ai_inspector::chat::ChatState;
use crate::ai_inspector::snapshot::{SnapshotData, SnapshotScope};
use crate::config::Config;
use crate::ui_constants::{AI_PANEL_MAX_WIDTH_RATIO, AI_PANEL_MIN_WIDTH};
use par_term_acp::{AgentConfig, AgentStatus};
use par_term_config::AssistantInputHistoryMode;
use std::path::Path;

use types::RESIZE_HANDLE_WIDTH;

type AssistantPromptState = (Vec<par_term_config::AssistantPrompt>, Option<String>);
type AssistantPromptLoader = fn() -> AssistantPromptState;

/// AI Inspector side panel.
pub struct AIInspectorPanel {
    /// Whether the panel is open.
    pub open: bool,
    /// Current panel width in pixels (configured/drag-resized).
    pub width: f32,
    /// Minimum panel width.
    min_width: f32,
    /// Maximum width as ratio of viewport width.
    max_width_ratio: f32,
    /// Whether the user is currently resizing via drag.
    resizing: bool,
    /// Current snapshot scope.
    pub scope: SnapshotScope,
    /// Current view mode.
    pub view_mode: ViewMode,
    /// Whether to auto-refresh on terminal changes.
    pub live_update: bool,
    /// Whether to show zone boundaries.
    pub show_zones: bool,
    /// Current snapshot data (populated by the app layer).
    pub snapshot: Option<SnapshotData>,
    /// Whether the panel needs a data refresh.
    pub needs_refresh: bool,
    /// Last known command count (for detecting changes).
    pub last_command_count: usize,
    /// Current agent connection status.
    pub agent_status: AgentStatus,
    /// Chat state for the agent conversation.
    pub chat: ChatState,
    /// Saved Assistant prompt-library entries loaded from config.
    pub assistant_prompts: Vec<par_term_config::AssistantPrompt>,
    /// Last prompt-library load error, if loading failed.
    pub assistant_prompts_error: Option<String>,
    /// Loader used to refresh the Assistant prompt library when the panel opens.
    prompt_library_loader: AssistantPromptLoader,
    /// Whether the agent is allowed to write to the terminal.
    pub agent_terminal_access: bool,
    /// Whether to auto-approve all agent permission requests (YOLO mode).
    pub auto_approve: bool,
    /// Actual rendered width from the last egui frame (may exceed `width` if content overflows).
    rendered_width: f32,
    /// Whether the pointer is hovering over the resize handle (persists between frames
    /// so `is_egui_using_pointer` can block the initial mouse press from reaching the terminal).
    hover_resize_handle: bool,
    /// Maximum allowed width in pixels (computed from viewport * max_width_ratio).
    max_width: f32,
    /// Selected agent index for the multi-agent dropdown.
    selected_agent_index: usize,
    /// Display name of the most recently requested/connected agent.
    pub connected_agent_name: Option<String>,
    /// Identity of the most recently requested/connected agent.
    pub connected_agent_identity: Option<String>,
    /// Project root resolved for the active agent session.
    pub connected_agent_project_root: Option<String>,
    /// Working directory sent to the active agent session.
    pub connected_agent_cwd: Option<String>,
    /// Font size for chat message body text (points).
    pub chat_font_size: f32,
    /// Id of the chat input text field, used to check focus for Escape key handling.
    chat_input_id: Option<Id>,
}

impl AIInspectorPanel {
    /// Create a new inspector panel initialized from config.
    pub fn new(config: &Config) -> Self {
        let (assistant_prompts, assistant_prompts_error) = Self::load_assistant_prompts();
        Self::new_with_prompt_library_state(
            config,
            assistant_prompts,
            assistant_prompts_error,
            Self::load_assistant_prompts,
        )
    }

    #[cfg(test)]
    pub(super) fn new_for_tests(config: &Config) -> Self {
        Self::new_for_tests_with_prompt_library(config, Vec::new(), None)
    }

    #[cfg(test)]
    pub(super) fn new_for_tests_with_prompt_library(
        config: &Config,
        assistant_prompts: Vec<par_term_config::AssistantPrompt>,
        assistant_prompts_error: Option<String>,
    ) -> Self {
        Self::new_for_tests_with_prompt_refresh(
            config,
            assistant_prompts,
            assistant_prompts_error,
            Self::empty_assistant_prompts,
        )
    }

    #[cfg(test)]
    pub(super) fn new_for_tests_with_prompt_refresh(
        config: &Config,
        assistant_prompts: Vec<par_term_config::AssistantPrompt>,
        assistant_prompts_error: Option<String>,
        prompt_library_loader: AssistantPromptLoader,
    ) -> Self {
        Self::new_with_prompt_library_state(
            config,
            assistant_prompts,
            assistant_prompts_error,
            prompt_library_loader,
        )
    }

    fn new_with_prompt_library_state(
        config: &Config,
        assistant_prompts: Vec<par_term_config::AssistantPrompt>,
        assistant_prompts_error: Option<String>,
        prompt_library_loader: AssistantPromptLoader,
    ) -> Self {
        let chat = ChatState::new();

        let mut panel = Self {
            open: config.ai_inspector.ai_inspector_open_on_startup,
            width: config.ai_inspector.ai_inspector_width,
            min_width: AI_PANEL_MIN_WIDTH,
            max_width_ratio: AI_PANEL_MAX_WIDTH_RATIO,
            resizing: false,
            scope: SnapshotScope::from_config_str(&config.ai_inspector.ai_inspector_default_scope),
            view_mode: ViewMode::from_config_str(&config.ai_inspector.ai_inspector_view_mode),
            live_update: config.ai_inspector.ai_inspector_live_update,
            show_zones: config.ai_inspector.ai_inspector_show_zones,
            snapshot: None,
            needs_refresh: true,
            last_command_count: 0,
            agent_status: AgentStatus::Disconnected,
            chat,
            assistant_prompts,
            assistant_prompts_error,
            prompt_library_loader,
            agent_terminal_access: config.ai_inspector.ai_inspector_agent_terminal_access,
            auto_approve: config.ai_inspector.ai_inspector_auto_approve,
            rendered_width: 0.0,
            hover_resize_handle: false,
            max_width: 0.0,
            selected_agent_index: 0,
            connected_agent_name: None,
            connected_agent_identity: None,
            connected_agent_project_root: None,
            connected_agent_cwd: None,
            chat_font_size: config.ai_inspector.ai_inspector_chat_font_size,
            chat_input_id: None,
        };

        if config.ai_inspector.ai_inspector_input_history_mode == AssistantInputHistoryMode::Persist
        {
            panel.merge_persisted_input_history();
        }

        panel
    }

    pub(crate) fn merge_persisted_input_history(&mut self) {
        match par_term_config::load_assistant_input_history() {
            Ok(persisted_entries) => {
                let merged_entries = par_term_config::merge_assistant_input_history(
                    self.chat.input_history_entries(),
                    &persisted_entries,
                );
                self.chat.set_input_history(merged_entries);
            }
            Err(error) => log::warn!("Assistant input history: failed to load: {error}"),
        }
    }

    fn load_assistant_prompts() -> AssistantPromptState {
        match par_term_config::list_prompts() {
            Ok(prompts) => (prompts, None),
            Err(error) => (Vec::new(), Some(error)),
        }
    }

    #[cfg(test)]
    fn empty_assistant_prompts() -> AssistantPromptState {
        (Vec::new(), None)
    }

    pub(crate) fn refresh_assistant_prompts(&mut self) {
        let (assistant_prompts, assistant_prompts_error) = (self.prompt_library_loader)();
        self.assistant_prompts = assistant_prompts;
        self.assistant_prompts_error = assistant_prompts_error;
    }

    /// Toggle the panel open/closed.
    ///
    /// Returns `true` if the panel was just opened (useful for auto-launch).
    pub fn toggle(&mut self) -> bool {
        self.open = !self.open;
        if self.open {
            self.needs_refresh = true;
            self.refresh_assistant_prompts();
        }
        self.open
    }

    /// Returns the width consumed by the panel (0 if closed).
    ///
    /// Uses the actual rendered width (which may exceed the configured `self.width`
    /// if content overflows) to ensure the terminal insets correctly.
    /// Clamps to the maximum allowed width to prevent the panel from taking
    /// over the entire window.
    pub fn consumed_width(&self) -> f32 {
        if self.open {
            let raw_width = self.rendered_width.max(self.width);
            if self.max_width > 0.0 {
                raw_width.min(self.max_width)
            } else {
                raw_width
            }
        } else {
            0.0
        }
    }

    pub(super) fn agent_project_label(&self) -> Option<String> {
        let root = self.connected_agent_project_root.as_deref()?;
        let name = Path::new(root)
            .file_name()
            .and_then(|name| name.to_str())
            .filter(|name| !name.is_empty())
            .unwrap_or(root);
        Some(format!("Project: {name}"))
    }

    /// Whether the user is currently drag-resizing the panel.
    pub fn is_resizing(&self) -> bool {
        self.resizing
    }

    /// Whether the pointer is interacting with the resize handle (hovering or dragging).
    /// Used by `is_egui_using_pointer()` to block mouse events from reaching the terminal.
    pub fn wants_pointer(&self) -> bool {
        self.resizing || self.hover_resize_handle
    }

    /// Render the inspector panel and return any action to perform.
    pub fn show(&mut self, ctx: &Context, available_agents: &[AgentConfig]) -> InspectorAction {
        if !self.open {
            return InspectorAction::None;
        }

        // Handle Escape key to close — but only when the chat input is NOT focused
        let chat_input_focused = self
            .chat_input_id
            .is_some_and(|id| ctx.memory(|m| m.has_focus(id)));
        if ctx.input(|i| i.key_pressed(Key::Escape)) && !chat_input_focused {
            self.open = false;
            return InspectorAction::Close;
        }

        let viewport = ctx.input(|i| i.viewport_rect());
        let max_width = viewport.width() * self.max_width_ratio;
        self.max_width = max_width;
        self.width = self.width.clamp(self.min_width, max_width);

        // --- Resize handle input (BEFORE panel rendering so width updates this frame) ---
        // Use previous frame's consumed_width for hover detection (imperceptible 1-frame lag).
        let prev_panel_x = viewport.max.x - self.consumed_width();
        let handle_left = prev_panel_x - RESIZE_HANDLE_WIDTH / 2.0;
        let handle_right = prev_panel_x + RESIZE_HANDLE_WIDTH / 2.0;
        let pointer_pos = ctx.input(|i| i.pointer.hover_pos());
        let hover = pointer_pos.is_some_and(|pos| {
            pos.x >= handle_left
                && pos.x <= handle_right
                && pos.y >= viewport.min.y
                && pos.y <= viewport.max.y
        });

        let primary_pressed = ctx.input(|i| i.pointer.primary_pressed());
        let primary_down = ctx.input(|i| i.pointer.primary_down());
        let delta = ctx.input(|i| i.pointer.delta());

        if hover && primary_pressed {
            self.resizing = true;
        }
        if self.resizing {
            if primary_down {
                let old_width = self.width;
                self.width = (self.width - delta.x).clamp(self.min_width, max_width);
                // Apply the same clamped delta to rendered_width so consumed_width()
                // moves in lockstep with the drag. This avoids a jump at drag start
                // (when rendered_width > self.width due to content overflow) and also
                // prevents movement when clamped at min/max (clamped_delta == 0).
                let clamped_delta = self.width - old_width;
                self.rendered_width = (self.rendered_width + clamped_delta).max(self.width);
            } else {
                self.resizing = false;
            }
        }
        // Persist hover state so is_egui_using_pointer() can block mouse events
        // from reaching the terminal on the initial click (before resizing is set).
        self.hover_resize_handle = hover;
        if hover || self.resizing {
            ctx.set_cursor_icon(CursorIcon::ResizeHorizontal);
        }

        // Recompute panel_x with potentially drag-updated width (eliminates 1-frame lag).
        let panel_x = viewport.max.x - self.consumed_width();

        // --- Main panel area ---
        // Use Order::Middle so modal dialogs (Order::Foreground) render above.
        let area_response = egui::Area::new(Id::new("ai_inspector_panel"))
            .fixed_pos(Pos2::new(panel_x, viewport.min.y))
            .order(Order::Middle)
            .interactable(true)
            .show(ctx, |ui| {
                let (action, close_requested) = self.render_panel_body(ui, available_agents);
                if close_requested {
                    InspectorAction::Close
                } else {
                    action
                }
            });

        // Track the actual rendered width (used by consumed_width() next frame).
        // Skip during active drag to prevent oscillation: the drag handler sets
        // rendered_width = self.width, but the area may render wider than self.width
        // (content overflow). Updating here would cause consumed_width() to bounce
        // between the two values on alternating frames, making the scrollbar jitter.
        if !self.resizing {
            self.rendered_width = area_response.response.rect.width();
        }

        // --- Paint resize handle line (Order::Background so modal dialogs render above) ---
        let line_color = if hover || self.resizing {
            Color32::from_gray(120)
        } else {
            Color32::from_gray(60)
        };
        let painter = ctx.layer_painter(egui::LayerId::new(
            Order::Background,
            Id::new("ai_inspector_resize_line"),
        ));
        painter.line_segment(
            [
                Pos2::new(panel_x, viewport.min.y),
                Pos2::new(panel_x, viewport.max.y),
            ],
            Stroke::new(2.0, line_color),
        );

        let action = area_response.inner;

        // Handle close action
        if matches!(action, InspectorAction::Close) {
            self.open = false;
        }

        action
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::ai_inspector::panel_helpers::{format_duration, truncate_chars, truncate_output};
    use crate::ai_inspector::snapshot::SnapshotScope;

    #[test]
    fn test_view_mode_label() {
        assert_eq!(ViewMode::Cards.label(), "Cards");
        assert_eq!(ViewMode::Timeline.label(), "Timeline");
        assert_eq!(ViewMode::Tree.label(), "Tree");
        assert_eq!(ViewMode::ListDetail.label(), "List Detail");
    }

    #[test]
    fn test_view_mode_all() {
        let all = ViewMode::all();
        assert_eq!(all.len(), 4);
    }

    #[test]
    fn test_view_mode_from_config_str() {
        assert_eq!(ViewMode::from_config_str("cards"), ViewMode::Cards);
        assert_eq!(ViewMode::from_config_str("timeline"), ViewMode::Timeline);
        assert_eq!(ViewMode::from_config_str("tree"), ViewMode::Tree);
        assert_eq!(
            ViewMode::from_config_str("list_detail"),
            ViewMode::ListDetail
        );
        assert_eq!(ViewMode::from_config_str("unknown"), ViewMode::Cards);
    }

    #[test]
    fn test_format_duration() {
        assert_eq!(format_duration(0), "0ms");
        assert_eq!(format_duration(500), "500ms");
        assert_eq!(format_duration(1000), "1.0s");
        assert_eq!(format_duration(1500), "1.5s");
        assert_eq!(format_duration(60000), "1m 0s");
        assert_eq!(format_duration(90000), "1m 30s");
    }

    #[test]
    fn test_truncate_output() {
        let short = "line1\nline2\nline3";
        assert_eq!(truncate_output(short, 5), short);

        let long = (0..30)
            .map(|i| format!("line {i}"))
            .collect::<Vec<_>>()
            .join("\n");
        let truncated = truncate_output(&long, 5);
        assert!(truncated.ends_with("... (truncated)"));
        // 5 lines + the truncation notice
        assert_eq!(truncated.lines().count(), 6);
    }

    #[test]
    fn test_truncate_chars_ascii() {
        assert_eq!(truncate_chars("hello", 10), "hello");
        assert_eq!(truncate_chars("hello world", 5), "hello");
        assert_eq!(truncate_chars("", 5), "");
    }

    #[test]
    fn test_truncate_chars_multibyte() {
        // Each emoji is 4 bytes; function now correctly uses character count
        let emoji = "🚀🎉🌍";
        let result = truncate_chars(emoji, 1); // first character (1 emoji)
        assert_eq!(result, "🚀");
        // Multiple emoji characters
        let result = truncate_chars(emoji, 2);
        assert_eq!(result, "🚀🎉");
        // All emoji
        let result = truncate_chars(emoji, 3);
        assert_eq!(result, "🚀🎉🌍");
        // More than string length returns full string
        let result = truncate_chars(emoji, 10);
        assert_eq!(result, "🚀🎉🌍");
    }

    #[test]
    fn test_truncate_chars_cjk() {
        // CJK characters are 3 bytes each; function now correctly uses character count
        let cjk = "你好世界";
        let result = truncate_chars(cjk, 1);
        assert_eq!(result, "");
        let result = truncate_chars(cjk, 2);
        assert_eq!(result, "你好");
        let result = truncate_chars(cjk, 4);
        assert_eq!(result, "你好世界");
        // More than string length returns full string
        let result = truncate_chars(cjk, 10);
        assert_eq!(result, "你好世界");
    }

    #[test]
    fn test_inspector_panel_toggle() {
        let config = Config::default();
        let mut panel = AIInspectorPanel::new_for_tests(&config);
        assert!(!panel.open);
        assert_eq!(panel.consumed_width(), 0.0);

        let opened = panel.toggle();
        assert!(opened);
        assert!(panel.open);
        assert!(panel.needs_refresh);
        assert!(panel.consumed_width() > 0.0);

        let opened = panel.toggle();
        assert!(!opened);
        assert!(!panel.open);
        assert_eq!(panel.consumed_width(), 0.0);
    }

    #[test]
    fn test_inspector_panel_new_from_config() {
        let config = Config::default();
        let panel = AIInspectorPanel::new_for_tests(&config);
        assert!(!panel.open);
        assert_eq!(panel.width, 300.0);
        assert_eq!(panel.scope, SnapshotScope::Visible);
        assert_eq!(panel.view_mode, ViewMode::Tree);
        assert!(!panel.live_update);
        assert!(panel.show_zones);
        assert_eq!(panel.connected_agent_project_root, None);
        assert_eq!(panel.connected_agent_cwd, None);
    }

    #[test]
    fn inspector_panel_prompt_library_state_can_be_injected() {
        let config = Config::default();
        let prompt = par_term_config::AssistantPrompt {
            path: std::path::PathBuf::from("debug.md"),
            title: "Debug build".to_string(),
            auto_submit: false,
            prompt: "Fix the build.".to_string(),
        };

        let panel = AIInspectorPanel::new_for_tests_with_prompt_library(
            &config,
            vec![prompt.clone()],
            Some("load failed".to_string()),
        );

        assert_eq!(panel.assistant_prompts, vec![prompt]);
        assert_eq!(
            panel.assistant_prompts_error.as_deref(),
            Some("load failed")
        );
    }

    #[test]
    fn inspector_panel_toggle_uses_injected_prompt_refresh_for_tests() {
        fn refreshed_prompts() -> AssistantPromptState {
            (
                vec![par_term_config::AssistantPrompt {
                    path: std::path::PathBuf::from("refreshed.md"),
                    title: "Refreshed".to_string(),
                    auto_submit: false,
                    prompt: "Use refreshed prompt.".to_string(),
                }],
                None,
            )
        }

        let config = Config::default();
        let mut panel = AIInspectorPanel::new_for_tests_with_prompt_refresh(
            &config,
            Vec::new(),
            Some("initial error".to_string()),
            refreshed_prompts,
        );

        let opened = panel.toggle();

        assert!(opened);
        assert_eq!(panel.assistant_prompts, refreshed_prompts().0);
        assert_eq!(panel.assistant_prompts_error, None);
    }

    #[test]
    fn load_prompt_action_carries_prompt_body() {
        let action = InspectorAction::LoadPrompt("hello".to_string());
        assert!(matches!(action, InspectorAction::LoadPrompt(text) if text == "hello"));
    }

    #[test]
    fn prompt_selection_loads_non_auto_submit_prompt() {
        let prompt = par_term_config::AssistantPrompt {
            path: std::path::PathBuf::from("load.md"),
            title: "Load only".to_string(),
            auto_submit: false,
            prompt: "Review this first.".to_string(),
        };

        let action = AIInspectorPanel::action_for_assistant_prompt(&prompt);

        assert!(
            matches!(action, InspectorAction::LoadPrompt(text) if text == "Review this first.")
        );
    }

    #[test]
    fn prompt_selection_sends_auto_submit_prompt() {
        let prompt = par_term_config::AssistantPrompt {
            path: std::path::PathBuf::from("send.md"),
            title: "Send now".to_string(),
            auto_submit: true,
            prompt: "Run diagnostics.".to_string(),
        };

        let action = AIInspectorPanel::action_for_assistant_prompt(&prompt);

        assert!(matches!(action, InspectorAction::SendPrompt(text) if text == "Run diagnostics."));
    }

    #[test]
    fn test_agent_project_label_uses_project_directory_name() {
        let config = Config::default();
        let mut panel = AIInspectorPanel::new_for_tests(&config);
        panel.connected_agent_project_root = Some("/Users/example/Repos/par-term".to_string());

        assert_eq!(
            panel.agent_project_label(),
            Some("Project: par-term".to_string())
        );
    }

    #[test]
    fn test_agent_project_label_falls_back_to_full_path_for_root() {
        let config = Config::default();
        let mut panel = AIInspectorPanel::new_for_tests(&config);
        panel.connected_agent_project_root = Some("/".to_string());

        assert_eq!(panel.agent_project_label(), Some("Project: /".to_string()));
    }
}