Skip to main content

codewhale_command_contract/
outcome.rs

1//! Shared command result data. Hosts consume actions after command dispatch;
2//! constructing an outcome never executes an action.
3
4use crate::facets::SessionSyncPayload;
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct CommandResult<A> {
8    pub message: Option<String>,
9    pub action: Option<A>,
10    pub is_error: bool,
11}
12
13impl<A> CommandResult<A> {
14    pub fn ok() -> Self {
15        Self {
16            message: None,
17            action: None,
18            is_error: false,
19        }
20    }
21    pub fn message(msg: impl Into<String>) -> Self {
22        Self {
23            message: Some(msg.into()),
24            action: None,
25            is_error: false,
26        }
27    }
28    pub fn action(action: A) -> Self {
29        Self {
30            message: None,
31            action: Some(action),
32            is_error: false,
33        }
34    }
35    pub fn with_message_and_action(msg: impl Into<String>, action: A) -> Self {
36        Self {
37            message: Some(msg.into()),
38            action: Some(action),
39            is_error: false,
40        }
41    }
42    pub fn error(msg: impl Into<String>) -> Self {
43        Self {
44            message: Some(format!("Error: {}", msg.into())),
45            action: None,
46            is_error: true,
47        }
48    }
49}
50
51/// Complete debug-group action vocabulary. This replaces its TUI AppAction
52/// references; other command groups' action ownership remains staged.
53#[derive(Debug, Clone, PartialEq)]
54pub enum DebugAction {
55    FetchBalance,
56    CacheWarmup,
57    PreviewOutboundRequest {
58        json: bool,
59        base_prompt_only: bool,
60        hypothetical_prompt: Option<String>,
61    },
62    OpenTextPager {
63        title: String,
64        content: String,
65    },
66    /// Show a unified diff in a pager, rendered as the transcript renders an
67    /// edit, without copying it into transcript history.
68    OpenDiffPager {
69        title: String,
70        diff: String,
71    },
72    OpenContextInspector,
73    SendMessage(String),
74    SyncSession(SessionSyncPayload),
75    /// Install and persist a conversation rollback; `/retry` resends its
76    /// input only after both succeed, replacing the removed exchange (#6788).
77    ConversationUndo {
78        sync: SessionSyncPayload,
79        retry_input: Option<String>,
80    },
81}
82
83pub type DebugCommandResult = CommandResult<DebugAction>;
84
85/// Structural copy cannot request a host action.
86pub type StructcopyCommandResult = CommandResult<std::convert::Infallible>;
87
88/// Complete session-group vocabulary. Hosts execute these requests after dispatch.
89#[derive(Debug, Clone, PartialEq)]
90pub enum SessionAction {
91    CompactContext { focus: Option<String> },
92    PurgeContext,
93    LoadSession(std::path::PathBuf),
94    SyncSession(SessionSyncPayload),
95    SendMessage(String),
96    RemoteControl(SessionRemoteControlAction),
97    OpenExternalUrl { url: String, label: String },
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq)]
101pub enum SessionRemoteControlAction {
102    Start,
103    Stop,
104}
105
106pub type SessionCommandResult = CommandResult<SessionAction>;
107
108/// Complete config-group action vocabulary (FEAT-028 D5). Unifies the FEAT-027
109/// policy action with the auth, picker, view, screen-mode, trust and
110/// host-effect actions of the main config slice. Constructing one never
111/// executes it; the TUI host adapter converts it to a concrete `AppAction`
112/// outside the movable closure.
113#[derive(Debug, Clone, PartialEq, Eq)]
114pub enum ConfigAction {
115    /// A permission rule was safely removed; the host reloads active rules.
116    PermissionRulesChanged,
117    // Auth flows (no host observation needed).
118    StartXaiDeviceLogin,
119    StartClaudeLogin,
120    StartClaudeRevoke,
121    StartChatgptPkceLogin,
122    StartChatgptRevoke,
123    StartOrcarouterPkceLogin,
124    StartOrcarouterRevoke,
125    // Views and pickers.
126    OpenConfigView,
127    OpenModePicker,
128    OpenThemePicker,
129    OpenStatusPicker,
130    OpenProviderPicker,
131    StartPluginLogin {
132        provider: String,
133    },
134    StartPluginLogout {
135        provider: String,
136    },
137    SetScreenMode(crate::types::CommandScreenMode),
138    SetWorkspaceTrust {
139        trusted: bool,
140        save: bool,
141    },
142    // Engine/route effects carrying the exact host payload.
143    ModeChanged(crate::types::CommandMode),
144    ApprovalPolicyChanged {
145        policy: Option<String>,
146    },
147    SwitchProvider {
148        provider: crate::types::CommandProviderId,
149        model: Option<String>,
150    },
151    CompactionChanged(crate::config::CommandCompactionConfig),
152    StreamChunkTimeoutChanged(u64),
153    SubagentRuntimeChanged(crate::config::CommandSubagentRuntimeConfig),
154    SearchProviderChanged(crate::config::CommandSearchProvider),
155    PromptSuggestionChanged {
156        enabled: bool,
157    },
158    NotificationChanged(crate::config::CommandNotificationUpdate),
159}
160pub type ConfigCommandResult = CommandResult<ConfigAction>;
161/// FEAT-027 compatibility alias; the whole group now standardizes on `ConfigAction`.
162pub type ConfigPolicyAction = ConfigAction;
163pub type ConfigPolicyCommandResult = ConfigCommandResult;
164pub type ConfigStatusCommandResult = CommandResult<std::convert::Infallible>;
165
166#[derive(Debug, Clone, PartialEq, Eq)]
167pub enum CoreNavigationAction {
168    OpenHotbarSetup,
169    DisableHotbar,
170    RestoreHotbarDefaults,
171    OpenLiveTranscript,
172    OpenTurnInspector,
173    OpenWorktreeManager,
174    SwitchWorkspace { workspace: std::path::PathBuf },
175    VoiceCapture,
176}
177
178pub type CoreNavigationCommandResult = CommandResult<CoreNavigationAction>;