use crate::outcome::ConfigAction;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConfigMessage {
Keyed {
key: String,
params: Vec<(String, ConfigMessage)>,
},
Literal(String),
Concat(Vec<ConfigMessage>),
}
impl ConfigMessage {
pub fn keyed(key: impl Into<String>) -> Self {
Self::Keyed {
key: key.into(),
params: Vec::new(),
}
}
pub fn keyed_with(key: impl Into<String>, params: Vec<(String, ConfigMessage)>) -> Self {
Self::Keyed {
key: key.into(),
params,
}
}
pub fn literal(text: impl Into<String>) -> Self {
Self::Literal(text.into())
}
pub fn concat(parts: Vec<ConfigMessage>) -> Self {
Self::Concat(parts)
}
}
impl From<String> for ConfigMessage {
fn from(value: String) -> Self {
Self::Literal(value)
}
}
impl From<&str> for ConfigMessage {
fn from(value: &str) -> Self {
Self::Literal(value.to_string())
}
}
impl From<std::borrow::Cow<'_, str>> for ConfigMessage {
fn from(value: std::borrow::Cow<'_, str>) -> Self {
Self::Literal(value.into_owned())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConfigReply {
pub message: Option<ConfigMessage>,
pub action: Option<ConfigAction>,
pub is_error: bool,
}
impl ConfigReply {
pub fn ok() -> Self {
Self {
message: None,
action: None,
is_error: false,
}
}
pub fn message(msg: impl Into<ConfigMessage>) -> Self {
Self {
message: Some(msg.into()),
action: None,
is_error: false,
}
}
pub fn error(msg: impl Into<ConfigMessage>) -> Self {
let msg = match msg.into() {
ConfigMessage::Literal(text) => ConfigMessage::Literal(format!("Error: {text}")),
other => other,
};
Self {
message: Some(msg),
action: None,
is_error: true,
}
}
pub fn action(action: ConfigAction) -> Self {
Self {
message: None,
action: Some(action),
is_error: false,
}
}
pub fn with_message_and_action(msg: impl Into<ConfigMessage>, action: ConfigAction) -> Self {
Self {
message: Some(msg.into()),
action: Some(action),
is_error: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandSettingsRow {
pub label: String,
pub value: String,
pub label_width: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandSettingsReport {
pub rows: Vec<CommandSettingsRow>,
pub config_file: String,
pub from_settings: Vec<String>,
pub session_overrides: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandSubagentsReport {
pub disabled_reason: Option<String>,
pub config_path: String,
pub provider_key: String,
pub provider_label: String,
pub explicit_enabled: Option<bool>,
pub limits: Vec<CommandSubagentsLimit>,
pub provider_rows: Option<Vec<CommandSubagentsProviderRow>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandSubagentsLimit {
pub key: &'static str,
pub raw: String,
pub global: String,
pub provider: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandSubagentsProviderRow {
pub key: &'static str,
pub value: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandConfigAuditRow {
pub key: String,
pub current: String,
pub editability: String,
pub command: String,
pub note: ConfigMessage,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandConfigAuditReport {
pub config_path: String,
pub rows: Vec<CommandConfigAuditRow>,
}
pub const EFFECT_REPLY_TEMPLATES: &[(&str, &[&str])] = &[
("config_command_invalid_value", &["key", "value", "choices"]),
("config_notification_updated", &["key", "value", "scope"]),
("config_notifications_set_hint", &[]),
("config_prompt_suggestion_updated", &["value", "scope"]),
("config_scope_saved", &[]),
("config_scope_session", &[]),
("config_search_updated", &["value", "scope"]),
("contextual_tips_not_saved", &["error"]),
("help_usage_label", &[]),
("startup_default_not_saved", &["setting", "error"]),
];
pub trait CommandConfigContext {
fn config_path(&self) -> Option<PathBuf>;
fn translation_enabled(&self) -> bool;
fn set_translation_enabled(&mut self, enabled: bool);
fn audit(&mut self) -> Result<CommandConfigAuditReport, String>;
fn workflow_summary(&mut self) -> CommandWorkflowSummary;
fn subagents_status(&mut self) -> Result<CommandSubagentsReport, String>;
fn subagent(&mut self, key: &str) -> ConfigReply;
fn set_subagent(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
fn search_provider_status(&mut self) -> ConfigReply;
fn search_provider_names(&self) -> &'static str;
fn set_search_provider(&mut self, value: &str, persist: bool) -> ConfigReply;
fn notifications_status(&mut self) -> ConfigReply;
fn notification(&mut self, key: &str) -> ConfigReply;
fn set_notification(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
fn apply_preset(&mut self, name: &str, persist: bool) -> ConfigReply;
fn get_value(&mut self, key: &str) -> ConfigReply;
fn set_value(&mut self, key: &str, value: &str, persist: bool) -> ConfigReply;
fn show_settings(&mut self) -> Result<CommandSettingsReport, String>;
fn theme_schema(&self) -> String;
fn themes_dir(&self) -> Result<String, String>;
fn verbose_enabled(&self) -> bool;
fn set_verbose_enabled(&mut self, enabled: bool);
fn screen_mode(&self) -> crate::types::CommandScreenMode;
fn build_plan(&mut self) -> Option<CommandClaudePlan>;
fn write_artifacts(&mut self, report: &str, bundle: Option<&str>) -> CommandClaudeArtifacts;
fn apply_import(
&mut self,
plan: &CommandClaudePlan,
report_path: &Path,
wrote_report: bool,
) -> CommandClaudeApplyOutcome;
fn display_path(&self, path: &Path) -> String;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandPetControl {
Sound,
Browser,
Select,
FocusAgents,
Appearance {
body: CommandPetBodyStyle,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandPetBodyStyle {
Smooth,
Pixel,
}
impl CommandPetBodyStyle {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Smooth => "smooth",
Self::Pixel => "pixel",
}
}
#[must_use]
pub fn parse(value: &str) -> Option<Self> {
match value {
"smooth" => Some(Self::Smooth),
"pixel" => Some(Self::Pixel),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandPetLabel {
ModeOn,
ModeOff,
ModeOnLabel,
ModeOffLabel,
ViewOpen,
ViewClosed,
HabitatQueued,
ExportQueued,
ExportUnavailable,
SoundOn,
WatchUnavailable,
}
pub trait CommandPetContext {
fn enabled(&self) -> bool;
fn is_open(&self) -> bool;
fn status(&self) -> String;
fn avatar_choices(&self) -> String;
fn select_avatar(&mut self, key: &str) -> bool;
fn preview_avatar(&mut self, name: &str, view: bool) -> bool;
fn set_enabled(&mut self, enabled: bool, persist: bool);
fn set_sound(&mut self, enabled: bool);
fn sound_label(&self) -> String;
fn export(&mut self) -> bool;
fn open_habitat(&mut self);
fn queue(&mut self, control: CommandPetControl) -> bool;
fn label(&self, which: CommandPetLabel) -> String;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandAccountState {
SignedOut,
Authenticated,
OfflineCached,
Expired,
Revoked,
Unavailable(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandLoginStatus {
pub account: CommandAccountState,
pub api_base: String,
pub provider: String,
}
pub trait CommandLoginContext {
fn login_status(&self) -> CommandLoginStatus;
fn connect(&mut self, provider: Option<&str>) -> ConfigReply;
fn disconnect(&mut self, provider: &str) -> ConfigReply;
}
pub trait CommandWorkSurfaceContext {
fn placement(&self) -> crate::types::CommandWorkSurfacePlacement;
fn panel(&self) -> crate::types::CommandRailPanel;
fn effective_placement(&self) -> crate::types::CommandWorkSurfacePlacement;
fn area_present(&self) -> bool;
fn panel_title(&self, panel: crate::types::CommandRailPanel) -> String;
fn set_placement(
&mut self,
placement: crate::types::CommandWorkSurfacePlacement,
persist: bool,
) -> ConfigReply;
fn set_panel(&mut self, panel: crate::types::CommandRailPanel, persist: bool) -> ConfigReply;
fn mark_redraw(&mut self);
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TrustPathError {
NotFound(PathBuf),
UpdateFailed(String),
}
pub trait CommandTrustContext {
fn trust_mode(&self) -> bool;
fn trusted_paths(&self) -> Vec<PathBuf>;
fn add_trusted_path(&mut self, raw: &str) -> Result<PathBuf, TrustPathError>;
fn remove_trusted_path(&mut self, raw: &str) -> Result<(PathBuf, bool), TrustPathError>;
fn usage_label(&self) -> String;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandCapabilityState {
Supported,
Unsupported,
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandCompactionConfig {
pub enabled: bool,
pub token_threshold: usize,
pub model: String,
pub image_input: CommandCapabilityState,
pub effective_context_window: Option<u32>,
pub cache_summary: bool,
pub focus: Option<String>,
pub runtime_cost_owner: Option<String>,
pub workspace: Option<PathBuf>,
pub summary_instructions: Option<String>,
pub retained_user_message_tokens: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CommandSubagentRuntimeConfig {
pub enabled: bool,
pub max_subagents: usize,
pub launch_concurrency: usize,
pub max_spawn_depth: u32,
pub api_timeout_secs: u64,
pub heartbeat_timeout_secs: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandSearchProvider {
Bing,
DuckDuckGo,
Firecrawl,
Tavily,
Bocha,
Metaso,
Searxng,
Baidu,
Volcengine,
Sofya,
Serply,
DeepSeek,
SearchApi,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandNotificationMethod {
Auto,
Osc9,
Bel,
Kitty,
Ghostty,
Off,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandCompletionSound {
Off,
Beep,
Bell,
Whale,
File,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandNotificationCondition {
Always,
Unfocused,
Never,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandSubagentCompletion {
Always,
FinalOnly,
Off,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandNotificationEvent {
TurnComplete,
SubagentTerminal,
ApprovalNeeded,
InputNeeded,
ElevationNeeded,
ModelNotify,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandNotificationUpdate {
Method(CommandNotificationMethod),
ThresholdSecs(u64),
IncludeSummary(bool),
Quiet(bool),
Sound(Option<CommandCompletionSound>),
Condition(CommandNotificationCondition),
CompletionSound(CommandCompletionSound),
SubagentCompletion(CommandSubagentCompletion),
SoundFile(PathBuf),
Event(CommandNotificationEvent, bool),
EventSoundEnabled(bool),
EventSoundEvents(Vec<String>),
EventSoundMinIntervalMs(u64),
EventSoundQuiet(bool),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CommandWorkflowSummary {
pub automatic: bool,
pub auto_start_read_only: bool,
pub require_approval_for_writes: bool,
pub max_children: u32,
pub max_concurrent: u32,
pub max_depth: u32,
pub default_token_budget: u64,
pub goal_max_continuations: u32,
pub goal_enforce_token_budget: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandSourceStatus {
Found,
NotFound,
Oversize(u64),
InvalidJson,
Unreadable(String),
}
impl CommandSourceStatus {
#[must_use]
pub fn describe(&self, display_path: &str) -> String {
match self {
Self::Found => format!("found: {display_path}"),
Self::NotFound => format!("not found: {display_path}"),
Self::Oversize(bytes) => {
format!("skipped, too large ({bytes} bytes): {display_path}")
}
Self::InvalidJson => format!("invalid JSON: {display_path}"),
Self::Unreadable(error) => format!("unreadable: {display_path} ({error})"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandMcpCandidate {
pub name: String,
pub summary: String,
pub hard_blocked: bool,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CommandClaudePlan {
pub sources: Vec<(PathBuf, CommandSourceStatus)>,
pub mcp_candidates: Vec<CommandMcpCandidate>,
pub per_project_mcp: Vec<String>,
pub env_safe: Vec<(String, String)>,
pub env_skipped: Vec<String>,
pub permissions_default_mode: Option<String>,
pub permissions_allow: Vec<String>,
pub permissions_ask: Vec<String>,
pub permissions_deny: Vec<String>,
pub hook_events: Vec<String>,
pub has_claude_md: bool,
pub claude_projects: Vec<String>,
}
impl CommandClaudePlan {
#[must_use]
pub fn is_empty(&self) -> bool {
self.mcp_candidates.is_empty()
&& self.per_project_mcp.is_empty()
&& self.env_safe.is_empty()
&& self.env_skipped.is_empty()
&& self.permissions_default_mode.is_none()
&& self.permissions_allow.is_empty()
&& self.permissions_ask.is_empty()
&& self.permissions_deny.is_empty()
&& self.hook_events.is_empty()
&& !self.has_claude_md
&& self.claude_projects.is_empty()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandImportFollowUp {
InstructionsCopied { destination: String },
InstructionsKeptExisting { destination: String, source: String },
InstructionsCopyFailed { source: String, destination: String },
HomeUnresolved,
McpBlocked { name: String },
McpNeedsReview { name: String },
HookEvents { count: usize },
PermissionRules,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CommandClaudeArtifacts {
pub report_path: PathBuf,
pub bundle_path: PathBuf,
pub wrote_report: bool,
pub wrote_bundle: bool,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct CommandClaudeApplyOutcome {
pub done: Vec<CommandImportFollowUp>,
pub manual: Vec<CommandImportFollowUp>,
pub report_path: PathBuf,
pub wrote_report: bool,
}