1use crate::outcome::ConfigAction;
10use std::path::{Path, PathBuf};
11
12#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum ConfigMessage {
21 Keyed {
23 key: String,
24 params: Vec<(String, ConfigMessage)>,
25 },
26 Literal(String),
28 Concat(Vec<ConfigMessage>),
30}
31
32impl ConfigMessage {
33 pub fn keyed(key: impl Into<String>) -> Self {
34 Self::Keyed {
35 key: key.into(),
36 params: Vec::new(),
37 }
38 }
39 pub fn keyed_with(key: impl Into<String>, params: Vec<(String, ConfigMessage)>) -> Self {
40 Self::Keyed {
41 key: key.into(),
42 params,
43 }
44 }
45 pub fn literal(text: impl Into<String>) -> Self {
46 Self::Literal(text.into())
47 }
48 pub fn concat(parts: Vec<ConfigMessage>) -> Self {
49 Self::Concat(parts)
50 }
51}
52
53impl From<String> for ConfigMessage {
54 fn from(value: String) -> Self {
55 Self::Literal(value)
56 }
57}
58
59impl From<&str> for ConfigMessage {
60 fn from(value: &str) -> Self {
61 Self::Literal(value.to_string())
62 }
63}
64
65impl From<std::borrow::Cow<'_, str>> for ConfigMessage {
66 fn from(value: std::borrow::Cow<'_, str>) -> Self {
67 Self::Literal(value.into_owned())
68 }
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct ConfigReply {
78 pub message: Option<ConfigMessage>,
79 pub action: Option<ConfigAction>,
80 pub is_error: bool,
81}
82
83impl ConfigReply {
84 pub fn ok() -> Self {
85 Self {
86 message: None,
87 action: None,
88 is_error: false,
89 }
90 }
91 pub fn message(msg: impl Into<ConfigMessage>) -> Self {
92 Self {
93 message: Some(msg.into()),
94 action: None,
95 is_error: false,
96 }
97 }
98 pub fn error(msg: impl Into<ConfigMessage>) -> Self {
99 let msg = match msg.into() {
100 ConfigMessage::Literal(text) => ConfigMessage::Literal(format!("Error: {text}")),
101 other => other,
102 };
103 Self {
104 message: Some(msg),
105 action: None,
106 is_error: true,
107 }
108 }
109 pub fn action(action: ConfigAction) -> Self {
110 Self {
111 message: None,
112 action: Some(action),
113 is_error: false,
114 }
115 }
116 pub fn with_message_and_action(msg: impl Into<ConfigMessage>, action: ConfigAction) -> Self {
117 Self {
118 message: Some(msg.into()),
119 action: Some(action),
120 is_error: false,
121 }
122 }
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct CommandSettingsRow {
128 pub label: String,
129 pub value: String,
130 pub label_width: usize,
131}
132
133#[derive(Debug, Clone, PartialEq, Eq)]
138pub struct CommandSettingsReport {
139 pub rows: Vec<CommandSettingsRow>,
140 pub config_file: String,
141 pub from_settings: Vec<String>,
142 pub session_overrides: Vec<String>,
143}
144
145#[derive(Debug, Clone, PartialEq, Eq)]
147pub struct CommandSubagentsReport {
148 pub disabled_reason: Option<String>,
149 pub config_path: String,
150 pub provider_key: String,
151 pub provider_label: String,
152 pub explicit_enabled: Option<bool>,
153 pub limits: Vec<CommandSubagentsLimit>,
154 pub provider_rows: Option<Vec<CommandSubagentsProviderRow>>,
156}
157
158#[derive(Debug, Clone, PartialEq, Eq)]
160pub struct CommandSubagentsLimit {
161 pub key: &'static str,
162 pub raw: String,
163 pub global: String,
164 pub provider: String,
165}
166
167#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct CommandSubagentsProviderRow {
170 pub key: &'static str,
171 pub value: String,
172}
173
174#[derive(Debug, Clone, PartialEq, Eq)]
178pub struct CommandConfigAuditRow {
179 pub key: String,
180 pub current: String,
181 pub editability: String,
182 pub command: String,
183 pub note: ConfigMessage,
185}
186
187#[derive(Debug, Clone, PartialEq, Eq)]
189pub struct CommandConfigAuditReport {
190 pub config_path: String,
191 pub rows: Vec<CommandConfigAuditRow>,
192}
193
194pub const EFFECT_REPLY_TEMPLATES: &[(&str, &[&str])] = &[
203 ("config_command_invalid_value", &["key", "value", "choices"]),
204 ("config_notification_updated", &["key", "value", "scope"]),
205 ("config_notifications_set_hint", &[]),
206 ("config_prompt_suggestion_updated", &["value", "scope"]),
207 ("config_scope_saved", &[]),
208 ("config_scope_session", &[]),
209 ("config_search_updated", &["value", "scope"]),
210 ("contextual_tips_not_saved", &["error"]),
211 ("help_usage_label", &[]),
212 ("startup_default_not_saved", &["setting", "error"]),
213];
214
215pub trait CommandConfigContext {
223 fn config_path(&self) -> Option<PathBuf>;
225 fn translation_enabled(&self) -> bool;
226 fn set_translation_enabled(&mut self, enabled: bool);
227
228 fn audit(&mut self) -> Result<CommandConfigAuditReport, String>;
230 fn workflow_summary(&mut self) -> CommandWorkflowSummary;
232 fn subagents_status(&mut self) -> Result<CommandSubagentsReport, String>;
234 fn subagent(&mut self, key: &str) -> ConfigReply;
236 fn set_subagent(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
238 fn search_provider_status(&mut self) -> ConfigReply;
240 fn search_provider_names(&self) -> &'static str;
242 fn set_search_provider(&mut self, value: &str, persist: bool) -> ConfigReply;
244 fn notifications_status(&mut self) -> ConfigReply;
246 fn notification(&mut self, key: &str) -> ConfigReply;
248 fn set_notification(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
250 fn apply_preset(&mut self, name: &str, persist: bool) -> ConfigReply;
252 fn get_value(&mut self, key: &str) -> ConfigReply;
254 fn set_value(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
256 fn show_settings(&mut self) -> Result<CommandSettingsReport, String>;
258 fn theme_schema(&self) -> String;
260 fn themes_dir(&self) -> Result<String, String>;
262 fn verbose_enabled(&self) -> bool;
264 fn set_verbose_enabled(&mut self, enabled: bool);
266 fn screen_mode(&self) -> crate::types::CommandScreenMode;
268 fn build_plan(&mut self) -> Option<CommandClaudePlan>;
270 fn write_artifacts(&mut self, report: &str, bundle: Option<&str>) -> CommandClaudeArtifacts;
272 fn apply_import(
274 &mut self,
275 plan: &CommandClaudePlan,
276 report_path: &Path,
277 wrote_report: bool,
278 ) -> CommandClaudeApplyOutcome;
279 fn display_path(&self, path: &Path) -> String;
281}
282
283#[derive(Debug, Clone, Copy, PartialEq, Eq)]
288pub enum CommandPetControl {
289 Sound,
290 Browser,
291 Window,
292 Select,
293 FocusAgents,
294 Appearance {
296 body: Option<CommandPetBodyStyle>,
297 language: Option<CommandPetTextLanguage>,
298 },
299}
300
301#[derive(Debug, Clone, Copy, PartialEq, Eq)]
303pub enum CommandPetBodyStyle {
304 Smooth,
305 Pixel,
306}
307
308impl CommandPetBodyStyle {
309 #[must_use]
311 pub fn as_str(self) -> &'static str {
312 match self {
313 Self::Smooth => "smooth",
314 Self::Pixel => "pixel",
315 }
316 }
317
318 #[must_use]
319 pub fn parse(value: &str) -> Option<Self> {
320 match value {
321 "smooth" => Some(Self::Smooth),
322 "pixel" => Some(Self::Pixel),
323 _ => None,
324 }
325 }
326}
327
328#[derive(Debug, Clone, Copy, PartialEq, Eq)]
330pub enum CommandPetTextLanguage {
331 Auto,
332 En,
333 ZhHans,
334 ZhHant,
335 Ja,
336}
337
338impl CommandPetTextLanguage {
339 #[must_use]
341 pub fn as_str(self) -> &'static str {
342 match self {
343 Self::Auto => "auto",
344 Self::En => "en",
345 Self::ZhHans => "zh-hans",
346 Self::ZhHant => "zh-hant",
347 Self::Ja => "ja",
348 }
349 }
350
351 #[must_use]
352 pub fn parse(value: &str) -> Option<Self> {
353 match value {
354 "auto" => Some(Self::Auto),
355 "en" => Some(Self::En),
356 "zh-hans" => Some(Self::ZhHans),
357 "zh-hant" => Some(Self::ZhHant),
358 "ja" => Some(Self::Ja),
359 _ => None,
360 }
361 }
362}
363
364#[derive(Debug, Clone, Copy, PartialEq, Eq)]
366pub enum CommandPetLabel {
367 ModeOn,
368 ModeOff,
369 ModeOnLabel,
370 ModeOffLabel,
371 ViewOpen,
372 ViewClosed,
373 HabitatQueued,
374 ExportQueued,
375 ExportUnavailable,
376 SoundOn,
377 WatchUnavailable,
379}
380
381pub trait CommandPetContext {
382 fn enabled(&self) -> bool;
383 fn is_open(&self) -> bool;
384 fn status(&self) -> String;
385 fn avatar_choices(&self) -> String;
386 fn select_avatar(&mut self, key: &str) -> bool;
387 fn preview_avatar(&mut self, name: &str, view: bool) -> bool;
388 fn set_enabled(&mut self, enabled: bool, persist: bool);
389 fn set_sound(&mut self, enabled: bool);
390 fn sound_label(&self) -> String;
391 fn export(&mut self) -> bool;
392 fn open_habitat(&mut self);
393 fn queue(&mut self, control: CommandPetControl) -> bool;
395 fn label(&self, which: CommandPetLabel) -> String;
396}
397
398#[derive(Debug, Clone, PartialEq, Eq)]
400pub enum CommandAccountState {
401 SignedOut,
402 Authenticated,
403 OfflineCached,
404 Expired,
405 Revoked,
406 Unavailable(String),
407}
408
409#[derive(Debug, Clone, PartialEq, Eq)]
411pub struct CommandLoginStatus {
412 pub account: CommandAccountState,
413 pub api_base: String,
414 pub provider: String,
415}
416
417#[derive(Debug, Clone, PartialEq, Eq)]
420pub struct CommandLogoutOutcome {
421 pub provider: String,
422 pub account: Result<bool, String>,
423 pub legacy_sandbox: Result<bool, String>,
424}
425
426#[derive(Debug, Clone, PartialEq, Eq)]
428pub struct LogoutFailure {
429 pub provider: String,
430 pub error: String,
431}
432
433pub trait CommandLoginContext {
435 fn login_status(&self) -> CommandLoginStatus;
436 fn logout(&mut self) -> Result<CommandLogoutOutcome, LogoutFailure>;
437 fn connect(&mut self, provider: Option<&str>) -> ConfigReply;
439 fn disconnect(&mut self, provider: &str) -> ConfigReply;
441}
442
443pub trait CommandWorkSurfaceContext {
445 fn placement(&self) -> crate::types::CommandWorkSurfacePlacement;
446 fn panel(&self) -> crate::types::CommandRailPanel;
447 fn effective_placement(&self) -> crate::types::CommandWorkSurfacePlacement;
448 fn area_present(&self) -> bool;
449 fn panel_title(&self, panel: crate::types::CommandRailPanel) -> String;
450 fn set_placement(
453 &mut self,
454 placement: crate::types::CommandWorkSurfacePlacement,
455 persist: bool,
456 ) -> ConfigReply;
457 fn set_panel(&mut self, panel: crate::types::CommandRailPanel, persist: bool) -> ConfigReply;
458 fn mark_redraw(&mut self);
459}
460
461#[derive(Debug, Clone, PartialEq, Eq)]
463pub enum TrustPathError {
464 NotFound(PathBuf),
466 UpdateFailed(String),
468}
469
470pub trait CommandTrustContext {
472 fn trust_mode(&self) -> bool;
473 fn trusted_paths(&self) -> Vec<PathBuf>;
474 fn add_trusted_path(&mut self, raw: &str) -> Result<PathBuf, TrustPathError>;
476 fn remove_trusted_path(&mut self, raw: &str) -> Result<(PathBuf, bool), TrustPathError>;
478 fn usage_label(&self) -> String;
480}
481
482#[derive(Debug, Clone, Copy, PartialEq, Eq)]
492pub enum CommandCapabilityState {
493 Supported,
494 Unsupported,
495 Unknown,
496}
497
498#[derive(Debug, Clone, PartialEq, Eq)]
500pub struct CommandCompactionConfig {
501 pub enabled: bool,
502 pub token_threshold: usize,
503 pub model: String,
504 pub image_input: CommandCapabilityState,
505 pub effective_context_window: Option<u32>,
506 pub cache_summary: bool,
507 pub focus: Option<String>,
508 pub runtime_cost_owner: Option<String>,
509 pub workspace: Option<PathBuf>,
510 pub summary_instructions: Option<String>,
511 pub retained_user_message_tokens: usize,
512}
513
514#[derive(Debug, Clone, Copy, PartialEq, Eq)]
516pub struct CommandSubagentRuntimeConfig {
517 pub enabled: bool,
518 pub max_subagents: usize,
519 pub launch_concurrency: usize,
520 pub max_spawn_depth: u32,
521 pub api_timeout_secs: u64,
522 pub heartbeat_timeout_secs: u64,
523}
524
525#[derive(Debug, Clone, Copy, PartialEq, Eq)]
527pub enum CommandSearchProvider {
528 Bing,
529 DuckDuckGo,
530 Firecrawl,
531 Tavily,
532 Bocha,
533 Metaso,
534 Searxng,
535 Baidu,
536 Volcengine,
537 Sofya,
538 Serply,
539 DeepSeek,
540}
541
542#[derive(Debug, Clone, Copy, PartialEq, Eq)]
544pub enum CommandNotificationMethod {
545 Auto,
546 Osc9,
547 Bel,
548 Kitty,
549 Ghostty,
550 Off,
551}
552
553#[derive(Debug, Clone, Copy, PartialEq, Eq)]
555pub enum CommandCompletionSound {
556 Off,
557 Beep,
558 Bell,
559 Whale,
560 File,
561}
562
563#[derive(Debug, Clone, Copy, PartialEq, Eq)]
565pub enum CommandNotificationCondition {
566 Always,
567 Unfocused,
568 Never,
569}
570
571#[derive(Debug, Clone, Copy, PartialEq, Eq)]
573pub enum CommandSubagentCompletion {
574 Always,
575 FinalOnly,
576 Off,
577}
578
579#[derive(Debug, Clone, Copy, PartialEq, Eq)]
581pub enum CommandNotificationEvent {
582 TurnComplete,
583 SubagentTerminal,
584 ApprovalNeeded,
585 InputNeeded,
586 ElevationNeeded,
587 ModelNotify,
588}
589
590#[derive(Debug, Clone, PartialEq, Eq)]
592pub enum CommandNotificationUpdate {
593 Method(CommandNotificationMethod),
594 ThresholdSecs(u64),
595 IncludeSummary(bool),
596 Quiet(bool),
597 Sound(Option<CommandCompletionSound>),
598 Condition(CommandNotificationCondition),
599 CompletionSound(CommandCompletionSound),
600 SubagentCompletion(CommandSubagentCompletion),
601 SoundFile(PathBuf),
602 Event(CommandNotificationEvent, bool),
603 EventSoundEnabled(bool),
604 EventSoundEvents(Vec<String>),
605 EventSoundMinIntervalMs(u64),
606 EventSoundQuiet(bool),
607}
608
609#[derive(Debug, Clone, Copy, PartialEq, Eq)]
616pub struct CommandWorkflowSummary {
617 pub automatic: bool,
618 pub auto_start_read_only: bool,
619 pub require_approval_for_writes: bool,
620 pub max_children: u32,
621 pub max_concurrent: u32,
622 pub max_depth: u32,
623 pub default_token_budget: u64,
624 pub goal_max_continuations: u32,
625 pub goal_enforce_token_budget: bool,
626}
627
628#[derive(Debug, Clone, PartialEq, Eq)]
630pub enum CommandSourceStatus {
631 Found,
632 NotFound,
633 Oversize(u64),
634 InvalidJson,
635 Unreadable(String),
636}
637
638impl CommandSourceStatus {
639 #[must_use]
644 pub fn describe(&self, display_path: &str) -> String {
645 match self {
646 Self::Found => format!("found: {display_path}"),
647 Self::NotFound => format!("not found: {display_path}"),
648 Self::Oversize(bytes) => {
649 format!("skipped, too large ({bytes} bytes): {display_path}")
650 }
651 Self::InvalidJson => format!("invalid JSON: {display_path}"),
652 Self::Unreadable(error) => format!("unreadable: {display_path} ({error})"),
653 }
654 }
655}
656
657#[derive(Debug, Clone, PartialEq, Eq)]
659pub struct CommandMcpCandidate {
660 pub name: String,
661 pub summary: String,
662 pub hard_blocked: bool,
663}
664
665#[derive(Debug, Clone, Default, PartialEq, Eq)]
667pub struct CommandClaudePlan {
668 pub sources: Vec<(PathBuf, CommandSourceStatus)>,
669 pub mcp_candidates: Vec<CommandMcpCandidate>,
670 pub per_project_mcp: Vec<String>,
671 pub env_safe: Vec<(String, String)>,
673 pub env_skipped: Vec<String>,
674 pub permissions_default_mode: Option<String>,
675 pub permissions_allow: Vec<String>,
676 pub permissions_ask: Vec<String>,
677 pub permissions_deny: Vec<String>,
678 pub hook_events: Vec<String>,
679 pub has_claude_md: bool,
680 pub claude_projects: Vec<String>,
681}
682
683impl CommandClaudePlan {
684 #[must_use]
685 pub fn is_empty(&self) -> bool {
686 self.mcp_candidates.is_empty()
687 && self.per_project_mcp.is_empty()
688 && self.env_safe.is_empty()
689 && self.env_skipped.is_empty()
690 && self.permissions_default_mode.is_none()
691 && self.permissions_allow.is_empty()
692 && self.permissions_ask.is_empty()
693 && self.permissions_deny.is_empty()
694 && self.hook_events.is_empty()
695 && !self.has_claude_md
696 && self.claude_projects.is_empty()
697 }
698}
699
700#[derive(Debug, Clone, PartialEq, Eq)]
704pub enum CommandImportFollowUp {
705 InstructionsCopied { destination: String },
706 InstructionsKeptExisting { destination: String, source: String },
707 InstructionsCopyFailed { source: String, destination: String },
708 HomeUnresolved,
709 McpBlocked { name: String },
710 McpNeedsReview { name: String },
711 HookEvents { count: usize },
712 PermissionRules,
713}
714
715#[derive(Debug, Clone, PartialEq, Eq)]
717pub struct CommandClaudeArtifacts {
718 pub report_path: PathBuf,
719 pub bundle_path: PathBuf,
720 pub wrote_report: bool,
721 pub wrote_bundle: bool,
722}
723
724#[derive(Debug, Clone, Default, PartialEq, Eq)]
726pub struct CommandClaudeApplyOutcome {
727 pub done: Vec<CommandImportFollowUp>,
728 pub manual: Vec<CommandImportFollowUp>,
729 pub report_path: PathBuf,
730 pub wrote_report: bool,
731}