1#![expect(
2 clippy::cast_possible_truncation,
3 reason = "Progress percentages are clamped to the documented byte-sized display range."
4)]
5
6use std::str::FromStr as _;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub enum InlineMessageKind {
14 Agent,
15 Error,
16 Info,
17 Policy,
18 Pty,
19 Tool,
20 User,
21 Warning,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct SlashCommandItem {
27 pub name: String,
28 pub description: String,
29}
30
31impl SlashCommandItem {
32 pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
33 Self { name: name.into(), description: description.into() }
34 }
35}
36
37#[derive(Clone, Debug, Default)]
39pub struct InlineListSearchConfig {
40 pub label: String,
41 pub placeholder: Option<String>,
42 pub fuzzy: bool,
47}
48
49#[derive(Clone, Debug)]
51pub struct SecurePromptConfig {
52 pub label: String,
53 pub placeholder: Option<String>,
55 pub mask_input: bool,
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
61pub enum SessionSurface {
62 Auto,
63 Alternate,
64 #[default]
65 Inline,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct KeyboardProtocolSettings {
71 pub enabled: bool,
72 pub mode: String,
73 pub disambiguate_escape_codes: bool,
74 pub report_event_types: bool,
75 pub report_alternate_keys: bool,
76 pub report_all_keys: bool,
77}
78
79impl Default for KeyboardProtocolSettings {
80 fn default() -> Self {
81 Self {
82 enabled: true,
83 mode: "default".to_owned(),
84 disambiguate_escape_codes: true,
85 report_event_types: true,
86 report_alternate_keys: true,
87 report_all_keys: false,
88 }
89 }
90}
91
92#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
94#[serde(rename_all = "snake_case")]
95pub enum UiMode {
96 #[default]
97 Full,
98 Minimal,
99 Focused,
100}
101
102#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
104#[serde(rename_all = "snake_case")]
105pub enum LayoutModeOverride {
106 #[default]
107 Auto,
108 Compact,
109 Standard,
110 Wide,
111}
112
113#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
115#[serde(rename_all = "snake_case")]
116pub enum ReasoningDisplayMode {
117 Always,
118 #[default]
119 Toggle,
120 Hidden,
121}
122
123#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
125#[serde(rename_all = "snake_case")]
126#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
127pub enum BusyEnterBehavior {
128 #[default]
130 Queue,
131 Steer,
133}
134
135#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
137#[serde(rename_all = "snake_case")]
138#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
139pub enum ThinkingBlockState {
140 #[default]
142 Collapsed,
143 Extended,
145}
146
147#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
151#[serde(rename_all = "snake_case")]
152#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
153pub enum CommunicationStyle {
154 #[default]
157 Balanced,
158 Quiet,
161 Verbose,
163 #[serde(other)]
165 Unknown,
166}
167
168impl CommunicationStyle {
169 #[must_use]
173 pub fn parse(value: &str) -> Self {
174 match value.trim().to_ascii_lowercase().as_str() {
175 "balanced" => Self::Balanced,
176 "quiet" => Self::Quiet,
177 "verbose" => Self::Verbose,
178 _ => Self::Unknown,
179 }
180 }
181
182 #[must_use]
186 pub fn resolve(self) -> Self {
187 match self {
188 Self::Unknown => Self::Balanced,
189 resolved => resolved,
190 }
191 }
192
193 #[must_use]
197 pub fn as_str(self) -> &'static str {
198 match self {
199 Self::Balanced => "balanced",
200 Self::Quiet => "quiet",
201 Self::Verbose => "verbose",
202 Self::Unknown => "unknown",
203 }
204 }
205}
206
207#[derive(Clone, Copy, Debug, PartialEq, Eq)]
209pub enum WizardModalMode {
210 MultiStep,
212 TabbedList,
214}
215
216#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
218#[serde(rename_all = "kebab-case")]
219#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
220pub enum DiffPreviewMode {
221 #[default]
223 Inline,
224 SideBySide,
226}
227
228#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
236#[serde(rename_all = "kebab-case")]
237#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
238pub enum AmbiguousWidthMode {
239 #[default]
241 Narrow,
242 Wide,
245}
246
247#[derive(Clone, Copy, Debug, PartialEq, Eq)]
256pub enum TaskItemStatus {
257 Pending,
258 InProgress,
259 Completed,
260 Blocked,
261}
262
263impl TaskItemStatus {
264 const fn as_tracker(self) -> vtcode_exec_events::tracker::TrackerItemStatus {
266 match self {
267 Self::Pending => vtcode_exec_events::tracker::TrackerItemStatus::Pending,
268 Self::InProgress => vtcode_exec_events::tracker::TrackerItemStatus::InProgress,
269 Self::Completed => vtcode_exec_events::tracker::TrackerItemStatus::Completed,
270 Self::Blocked => vtcode_exec_events::tracker::TrackerItemStatus::Blocked,
271 }
272 }
273
274 #[must_use]
276 pub fn as_str(self) -> &'static str {
277 self.as_tracker().as_str()
278 }
279}
280
281impl std::str::FromStr for TaskItemStatus {
282 type Err = ();
283
284 fn from_str(raw: &str) -> Result<Self, Self::Err> {
286 use vtcode_exec_events::tracker::TrackerItemStatus as Canonical;
287 match Canonical::from_str(raw)? {
288 Canonical::Pending => Ok(Self::Pending),
289 Canonical::InProgress => Ok(Self::InProgress),
290 Canonical::Completed => Ok(Self::Completed),
291 Canonical::Blocked => Ok(Self::Blocked),
292 Canonical::Unknown => Err(()),
293 }
294 }
295}
296
297#[derive(Clone, Debug)]
303pub struct PlanStep {
304 pub number: usize,
305 pub description: String,
306 pub details: Option<String>,
307 pub files: Vec<String>,
308 pub completed: bool,
309}
310
311#[derive(Clone, Debug)]
313pub struct PlanPhase {
314 pub name: String,
315 pub steps: Vec<PlanStep>,
316 pub completed: bool,
317}
318
319#[derive(Clone, Debug)]
321pub struct PlanContent {
322 pub title: String,
323 pub summary: String,
324 pub file_path: Option<String>,
325 pub phases: Vec<PlanPhase>,
326 pub open_questions: Vec<String>,
327 pub raw_content: String,
328 pub total_steps: usize,
329 pub completed_steps: usize,
330}
331
332impl PlanContent {
333 pub fn from_markdown(title: String, content: &str, file_path: Option<String>) -> Self {
335 let mut phases = Vec::new();
336 let mut open_questions = Vec::new();
337 let mut current_phase: Option<PlanPhase> = None;
338 let mut total_steps = 0;
339 let mut completed_steps = 0;
340 let mut summary = String::new();
341 let mut reading_summary = false;
342
343 for line in content.lines() {
344 let trimmed = line.trim();
345
346 if trimmed.eq_ignore_ascii_case("summary") || trimmed.eq_ignore_ascii_case("## summary") {
351 reading_summary = true;
352 continue;
353 }
354
355 if reading_summary {
356 if !trimmed.is_empty() {
357 if summary.is_empty() {
358 summary = trimmed.to_string();
359 }
360 reading_summary = false;
361 }
362 continue;
363 }
364
365 if summary.is_empty() && !trimmed.is_empty() && !trimmed.starts_with('#') {
367 summary = trimmed.to_string();
368 continue;
369 }
370
371 if let Some(phase_name) = trimmed.strip_prefix("## ") {
373 if let Some(phase) = current_phase.take() {
374 phases.push(phase);
375 }
376 current_phase = Some(PlanPhase {
377 name: phase_name.to_string(),
378 steps: Vec::new(),
379 completed: false,
380 });
381 continue;
382 }
383
384 if trimmed == "## Open Questions" {
386 if let Some(phase) = current_phase.take() {
387 phases.push(phase);
388 }
389 continue;
390 }
391
392 if let Some(rest) = trimmed.strip_prefix("[ ] ") {
394 total_steps += 1;
395 if let Some(ref mut phase) = current_phase {
396 phase.steps.push(PlanStep {
397 number: phase.steps.len() + 1,
398 description: rest.to_string(),
399 details: None,
400 files: Vec::new(),
401 completed: false,
402 });
403 }
404 continue;
405 }
406
407 if let Some(rest) = trimmed.strip_prefix("[x] ").or_else(|| trimmed.strip_prefix("[X] ")) {
408 total_steps += 1;
409 completed_steps += 1;
410 if let Some(ref mut phase) = current_phase {
411 phase.steps.push(PlanStep {
412 number: phase.steps.len() + 1,
413 description: rest.to_string(),
414 details: None,
415 files: Vec::new(),
416 completed: true,
417 });
418 }
419 continue;
420 }
421
422 if trimmed.starts_with(|c: char| c.is_ascii_digit()) && trimmed.contains('.') {
424 total_steps += 1;
425 if let Some(ref mut phase) = current_phase {
426 let desc = trimmed.split_once('.').map(|x| x.1).unwrap_or("").trim();
427 phase.steps.push(PlanStep {
428 number: phase.steps.len() + 1,
429 description: desc.to_string(),
430 details: None,
431 files: Vec::new(),
432 completed: false,
433 });
434 }
435 continue;
436 }
437
438 if trimmed.starts_with("- (") || trimmed.starts_with("- ?") {
440 open_questions.push(trimmed.trim_start_matches("- ").to_string());
441 }
442 }
443
444 if let Some(mut phase) = current_phase.take() {
446 phase.completed = phase.steps.iter().all(|s| s.completed);
447 phases.push(phase);
448 }
449
450 for phase in &mut phases {
452 phase.completed = !phase.steps.is_empty() && phase.steps.iter().all(|s| s.completed);
453 }
454
455 Self {
456 title,
457 summary,
458 file_path,
459 phases,
460 open_questions,
461 raw_content: content.to_string(),
462 total_steps,
463 completed_steps,
464 }
465 }
466
467 #[allow(
469 clippy::cast_sign_loss,
470 reason = "Intentional compatibility, platform, or test-only suppression."
471 )]
472 pub fn progress_percent(&self) -> u8 {
473 if self.total_steps == 0 {
474 0
475 } else {
476 ((self.completed_steps as f32 / self.total_steps as f32) * 100.0) as u8
477 }
478 }
479}
480
481#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
492#[serde(rename_all = "snake_case")]
493#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
494pub enum AppIconPreference {
495 #[default]
497 Dynamic,
498 Light,
500 Dark,
502 Clear,
504 Tinted,
506 #[serde(other)]
508 Unknown,
509}
510
511impl AppIconPreference {
512 pub const ALL: [Self; 5] = [Self::Dynamic, Self::Light, Self::Dark, Self::Clear, Self::Tinted];
514
515 #[must_use]
517 pub const fn id(self) -> &'static str {
518 match self {
519 Self::Dynamic | Self::Unknown => "dynamic",
520 Self::Light => "light",
521 Self::Dark => "dark",
522 Self::Clear => "clear",
523 Self::Tinted => "tinted",
524 }
525 }
526
527 #[must_use]
529 pub fn from_id(id: Option<&str>) -> Self {
530 match id.map(str::trim).map(str::to_ascii_lowercase).as_deref() {
531 Some("light") => Self::Light,
532 Some("dark") => Self::Dark,
533 Some("clear") => Self::Clear,
534 Some("tinted") => Self::Tinted,
535 _ => Self::Dynamic,
536 }
537 }
538
539 #[must_use]
542 pub const fn resolve(self, dark_mode: bool) -> Self {
543 match self {
544 Self::Dynamic | Self::Unknown => {
545 if dark_mode {
546 Self::Dark
547 } else {
548 Self::Light
549 }
550 }
551 pinned => pinned,
552 }
553 }
554
555 #[must_use]
561 pub const fn is_dark(self, dark_mode: bool) -> bool {
562 matches!(self.resolve(dark_mode), Self::Dark)
563 }
564}
565
566#[cfg(test)]
567mod tests {
568 use super::PlanContent;
569 use crate::ui_protocol::AppIconPreference;
570
571 #[test]
572 fn parses_sparse_summary_section_without_displaying_section_label() {
573 let plan = PlanContent::from_markdown(
574 "Implementation Plan".to_string(),
575 "Summary\nFocus on startup latency.\n\n1. Measure startup -> src/startup.rs\n2. Defer refresh -> src/update.rs\n\nValidation\n- cargo check --locked",
576 None,
577 );
578
579 assert_eq!(plan.summary, "Focus on startup latency.");
580 assert_eq!(plan.total_steps, 2);
581 assert_eq!(plan.raw_content.lines().next(), Some("Summary"));
582 }
583
584 #[test]
585 fn app_icon_default_is_dynamic() {
586 assert_eq!(AppIconPreference::default(), AppIconPreference::Dynamic);
587 }
588
589 #[test]
590 fn app_icon_ids_round_trip_through_from_id() {
591 for variant in AppIconPreference::ALL {
592 assert_eq!(AppIconPreference::from_id(Some(variant.id())), variant, "{}", variant.id());
593 }
594 assert_eq!(AppIconPreference::from_id(None), AppIconPreference::Dynamic);
595 }
596
597 #[test]
598 fn app_icon_from_id_is_forgiving_about_case_and_whitespace() {
599 assert_eq!(AppIconPreference::from_id(Some(" Light ")), AppIconPreference::Light);
600 assert_eq!(AppIconPreference::from_id(Some("DARK")), AppIconPreference::Dark);
601 assert_eq!(AppIconPreference::from_id(Some("DYNAMIC")), AppIconPreference::Dynamic);
602 assert_eq!(AppIconPreference::from_id(Some(" Clear ")), AppIconPreference::Clear);
603 assert_eq!(AppIconPreference::from_id(Some("TINTED")), AppIconPreference::Tinted);
604 }
605
606 #[test]
607 fn app_icon_from_id_falls_back_to_dynamic_for_unknown_or_empty() {
608 for raw in ["", " ", "twilight", "bright", "dynamic-v2"] {
609 assert_eq!(AppIconPreference::from_id(Some(raw)), AppIconPreference::Dynamic, "{raw:?}");
610 }
611 }
612
613 #[test]
614 fn app_icon_is_dark_pins_light_and_dark_but_follows_mode_for_dynamic() {
615 for dark_mode in [false, true] {
616 assert!(!AppIconPreference::Light.is_dark(dark_mode), "light pins light art");
617 assert!(AppIconPreference::Dark.is_dark(dark_mode), "dark pins dark art");
618 assert_eq!(AppIconPreference::Dynamic.is_dark(dark_mode), dark_mode, "dynamic follows mode");
619 assert_eq!(AppIconPreference::Unknown.is_dark(dark_mode), dark_mode, "unknown follows mode");
620 assert!(
621 !AppIconPreference::Clear.is_dark(dark_mode),
622 "clear pins its own glass art, never the dark flat tile"
623 );
624 assert!(
625 !AppIconPreference::Tinted.is_dark(dark_mode),
626 "tinted pins its own slate art, never the dark flat tile"
627 );
628 }
629 }
630
631 #[test]
632 fn app_icon_resolve_pins_explicit_variants_and_follows_mode_for_dynamic() {
633 for dark_mode in [false, true] {
634 for pinned in [
635 AppIconPreference::Light,
636 AppIconPreference::Dark,
637 AppIconPreference::Clear,
638 AppIconPreference::Tinted,
639 ] {
640 assert_eq!(pinned.resolve(dark_mode), pinned, "{pinned:?}");
641 }
642 let expected = if dark_mode {
643 AppIconPreference::Dark
644 } else {
645 AppIconPreference::Light
646 };
647 assert_eq!(AppIconPreference::Dynamic.resolve(dark_mode), expected);
648 assert_eq!(AppIconPreference::Unknown.resolve(dark_mode), expected);
649 }
650 }
651
652 #[test]
653 fn app_icon_serde_uses_ids_and_catches_unknown_variants() {
654 assert_eq!(serde_json::from_str::<AppIconPreference>("\"light\"").unwrap(), AppIconPreference::Light);
655 assert_eq!(serde_json::from_str::<AppIconPreference>("\"clear\"").unwrap(), AppIconPreference::Clear);
656 assert_eq!(serde_json::from_str::<AppIconPreference>("\"tinted\"").unwrap(), AppIconPreference::Tinted);
657 assert_eq!(
658 serde_json::from_str::<AppIconPreference>("\"future-variant\"").unwrap(),
659 AppIconPreference::Unknown
660 );
661 assert_eq!(serde_json::to_string(&AppIconPreference::Dynamic).unwrap(), "\"dynamic\"");
662 assert_eq!(serde_json::to_string(&AppIconPreference::Clear).unwrap(), "\"clear\"");
663 assert_eq!(serde_json::to_string(&AppIconPreference::Tinted).unwrap(), "\"tinted\"");
664 assert_eq!(AppIconPreference::Unknown.id(), "dynamic");
665 }
666}