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 Select,
292 FocusAgents,
293 Appearance {
295 body: CommandPetBodyStyle,
296 },
297}
298
299#[derive(Debug, Clone, Copy, PartialEq, Eq)]
301pub enum CommandPetBodyStyle {
302 Smooth,
303 Pixel,
304}
305
306impl CommandPetBodyStyle {
307 #[must_use]
309 pub fn as_str(self) -> &'static str {
310 match self {
311 Self::Smooth => "smooth",
312 Self::Pixel => "pixel",
313 }
314 }
315
316 #[must_use]
317 pub fn parse(value: &str) -> Option<Self> {
318 match value {
319 "smooth" => Some(Self::Smooth),
320 "pixel" => Some(Self::Pixel),
321 _ => None,
322 }
323 }
324}
325
326#[derive(Debug, Clone, Copy, PartialEq, Eq)]
328pub enum CommandPetLabel {
329 ModeOn,
330 ModeOff,
331 ModeOnLabel,
332 ModeOffLabel,
333 ViewOpen,
334 ViewClosed,
335 HabitatQueued,
336 ExportQueued,
337 ExportUnavailable,
338 SoundOn,
339 WatchUnavailable,
341}
342
343pub trait CommandPetContext {
344 fn enabled(&self) -> bool;
345 fn is_open(&self) -> bool;
346 fn status(&self) -> String;
347 fn avatar_choices(&self) -> String;
348 fn select_avatar(&mut self, key: &str) -> bool;
349 fn preview_avatar(&mut self, name: &str, view: bool) -> bool;
350 fn set_enabled(&mut self, enabled: bool, persist: bool);
351 fn set_sound(&mut self, enabled: bool);
352 fn sound_label(&self) -> String;
353 fn export(&mut self) -> bool;
354 fn open_habitat(&mut self);
355 fn queue(&mut self, control: CommandPetControl) -> bool;
357 fn label(&self, which: CommandPetLabel) -> String;
358}
359
360#[derive(Debug, Clone, PartialEq, Eq)]
362pub enum CommandAccountState {
363 SignedOut,
364 Authenticated,
365 OfflineCached,
366 Expired,
367 Revoked,
368 Unavailable(String),
369}
370
371#[derive(Debug, Clone, PartialEq, Eq)]
373pub struct CommandLoginStatus {
374 pub account: CommandAccountState,
375 pub api_base: String,
376 pub provider: String,
377}
378
379pub trait CommandLoginContext {
381 fn login_status(&self) -> CommandLoginStatus;
382 fn connect(&mut self, provider: Option<&str>) -> ConfigReply;
384 fn disconnect(&mut self, provider: &str) -> ConfigReply;
386}
387
388pub trait CommandWorkSurfaceContext {
390 fn placement(&self) -> crate::types::CommandWorkSurfacePlacement;
391 fn panel(&self) -> crate::types::CommandRailPanel;
392 fn effective_placement(&self) -> crate::types::CommandWorkSurfacePlacement;
393 fn area_present(&self) -> bool;
394 fn panel_title(&self, panel: crate::types::CommandRailPanel) -> String;
395 fn set_placement(
398 &mut self,
399 placement: crate::types::CommandWorkSurfacePlacement,
400 persist: bool,
401 ) -> ConfigReply;
402 fn set_panel(&mut self, panel: crate::types::CommandRailPanel, persist: bool) -> ConfigReply;
403 fn mark_redraw(&mut self);
404}
405
406#[derive(Debug, Clone, PartialEq, Eq)]
408pub enum TrustPathError {
409 NotFound(PathBuf),
411 UpdateFailed(String),
413}
414
415pub trait CommandTrustContext {
417 fn trust_mode(&self) -> bool;
418 fn trusted_paths(&self) -> Vec<PathBuf>;
419 fn add_trusted_path(&mut self, raw: &str) -> Result<PathBuf, TrustPathError>;
421 fn remove_trusted_path(&mut self, raw: &str) -> Result<(PathBuf, bool), TrustPathError>;
423 fn usage_label(&self) -> String;
425}
426
427#[derive(Debug, Clone, Copy, PartialEq, Eq)]
437pub enum CommandCapabilityState {
438 Supported,
439 Unsupported,
440 Unknown,
441}
442
443#[derive(Debug, Clone, PartialEq, Eq)]
445pub struct CommandCompactionConfig {
446 pub enabled: bool,
447 pub token_threshold: usize,
448 pub model: String,
449 pub image_input: CommandCapabilityState,
450 pub effective_context_window: Option<u32>,
451 pub cache_summary: bool,
452 pub focus: Option<String>,
453 pub runtime_cost_owner: Option<String>,
454 pub workspace: Option<PathBuf>,
455 pub summary_instructions: Option<String>,
456 pub retained_user_message_tokens: usize,
457}
458
459#[derive(Debug, Clone, Copy, PartialEq, Eq)]
461pub struct CommandSubagentRuntimeConfig {
462 pub enabled: bool,
463 pub max_subagents: usize,
464 pub launch_concurrency: usize,
465 pub max_spawn_depth: u32,
466 pub api_timeout_secs: u64,
467 pub heartbeat_timeout_secs: u64,
468}
469
470#[derive(Debug, Clone, Copy, PartialEq, Eq)]
472pub enum CommandSearchProvider {
473 Bing,
474 DuckDuckGo,
475 Firecrawl,
476 Tavily,
477 Bocha,
478 Metaso,
479 Searxng,
480 Baidu,
481 Volcengine,
482 Sofya,
483 Serply,
484 DeepSeek,
485 SearchApi,
486}
487
488#[derive(Debug, Clone, Copy, PartialEq, Eq)]
490pub enum CommandNotificationMethod {
491 Auto,
492 Osc9,
493 Bel,
494 Kitty,
495 Ghostty,
496 Off,
497}
498
499#[derive(Debug, Clone, Copy, PartialEq, Eq)]
501pub enum CommandCompletionSound {
502 Off,
503 Beep,
504 Bell,
505 Whale,
506 File,
507}
508
509#[derive(Debug, Clone, Copy, PartialEq, Eq)]
511pub enum CommandNotificationCondition {
512 Always,
513 Unfocused,
514 Never,
515}
516
517#[derive(Debug, Clone, Copy, PartialEq, Eq)]
519pub enum CommandSubagentCompletion {
520 Always,
521 FinalOnly,
522 Off,
523}
524
525#[derive(Debug, Clone, Copy, PartialEq, Eq)]
527pub enum CommandNotificationEvent {
528 TurnComplete,
529 SubagentTerminal,
530 ApprovalNeeded,
531 InputNeeded,
532 ElevationNeeded,
533 ModelNotify,
534}
535
536#[derive(Debug, Clone, PartialEq, Eq)]
538pub enum CommandNotificationUpdate {
539 Method(CommandNotificationMethod),
540 ThresholdSecs(u64),
541 IncludeSummary(bool),
542 Quiet(bool),
543 Sound(Option<CommandCompletionSound>),
544 Condition(CommandNotificationCondition),
545 CompletionSound(CommandCompletionSound),
546 SubagentCompletion(CommandSubagentCompletion),
547 SoundFile(PathBuf),
548 Event(CommandNotificationEvent, bool),
549 EventSoundEnabled(bool),
550 EventSoundEvents(Vec<String>),
551 EventSoundMinIntervalMs(u64),
552 EventSoundQuiet(bool),
553}
554
555#[derive(Debug, Clone, Copy, PartialEq, Eq)]
562pub struct CommandWorkflowSummary {
563 pub automatic: bool,
564 pub auto_start_read_only: bool,
565 pub require_approval_for_writes: bool,
566 pub max_children: u32,
567 pub max_concurrent: u32,
568 pub max_depth: u32,
569 pub default_token_budget: u64,
570 pub goal_max_continuations: u32,
571 pub goal_enforce_token_budget: bool,
572}
573
574#[derive(Debug, Clone, PartialEq, Eq)]
576pub enum CommandSourceStatus {
577 Found,
578 NotFound,
579 Oversize(u64),
580 InvalidJson,
581 Unreadable(String),
582}
583
584impl CommandSourceStatus {
585 #[must_use]
590 pub fn describe(&self, display_path: &str) -> String {
591 match self {
592 Self::Found => format!("found: {display_path}"),
593 Self::NotFound => format!("not found: {display_path}"),
594 Self::Oversize(bytes) => {
595 format!("skipped, too large ({bytes} bytes): {display_path}")
596 }
597 Self::InvalidJson => format!("invalid JSON: {display_path}"),
598 Self::Unreadable(error) => format!("unreadable: {display_path} ({error})"),
599 }
600 }
601}
602
603#[derive(Debug, Clone, PartialEq, Eq)]
605pub struct CommandMcpCandidate {
606 pub name: String,
607 pub summary: String,
608 pub hard_blocked: bool,
609}
610
611#[derive(Debug, Clone, Default, PartialEq, Eq)]
613pub struct CommandClaudePlan {
614 pub sources: Vec<(PathBuf, CommandSourceStatus)>,
615 pub mcp_candidates: Vec<CommandMcpCandidate>,
616 pub per_project_mcp: Vec<String>,
617 pub env_safe: Vec<(String, String)>,
619 pub env_skipped: Vec<String>,
620 pub permissions_default_mode: Option<String>,
621 pub permissions_allow: Vec<String>,
622 pub permissions_ask: Vec<String>,
623 pub permissions_deny: Vec<String>,
624 pub hook_events: Vec<String>,
625 pub has_claude_md: bool,
626 pub claude_projects: Vec<String>,
627}
628
629impl CommandClaudePlan {
630 #[must_use]
631 pub fn is_empty(&self) -> bool {
632 self.mcp_candidates.is_empty()
633 && self.per_project_mcp.is_empty()
634 && self.env_safe.is_empty()
635 && self.env_skipped.is_empty()
636 && self.permissions_default_mode.is_none()
637 && self.permissions_allow.is_empty()
638 && self.permissions_ask.is_empty()
639 && self.permissions_deny.is_empty()
640 && self.hook_events.is_empty()
641 && !self.has_claude_md
642 && self.claude_projects.is_empty()
643 }
644}
645
646#[derive(Debug, Clone, PartialEq, Eq)]
650pub enum CommandImportFollowUp {
651 InstructionsCopied { destination: String },
652 InstructionsKeptExisting { destination: String, source: String },
653 InstructionsCopyFailed { source: String, destination: String },
654 HomeUnresolved,
655 McpBlocked { name: String },
656 McpNeedsReview { name: String },
657 HookEvents { count: usize },
658 PermissionRules,
659}
660
661#[derive(Debug, Clone, PartialEq, Eq)]
663pub struct CommandClaudeArtifacts {
664 pub report_path: PathBuf,
665 pub bundle_path: PathBuf,
666 pub wrote_report: bool,
667 pub wrote_bundle: bool,
668}
669
670#[derive(Debug, Clone, Default, PartialEq, Eq)]
672pub struct CommandClaudeApplyOutcome {
673 pub done: Vec<CommandImportFollowUp>,
674 pub manual: Vec<CommandImportFollowUp>,
675 pub report_path: PathBuf,
676 pub wrote_report: bool,
677}