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    OpenUndoSelector,
74    UndoLatestRequest {
75        force: bool,
76    },
77    SendMessage(String),
78    SyncSession(SessionSyncPayload),
79    /// Install and persist a conversation rollback; `/retry` resends its
80    /// input only after both succeed, replacing the removed exchange (#6788).
81    ConversationUndo {
82        sync: SessionSyncPayload,
83        restored_files: usize,
84        retry_input: Option<String>,
85    },
86}
87
88pub type DebugCommandResult = CommandResult<DebugAction>;
89
90/// Structural copy cannot request a host action.
91pub type StructcopyCommandResult = CommandResult<std::convert::Infallible>;
92
93/// Complete session-group vocabulary. Hosts execute these requests after dispatch.
94#[derive(Debug, Clone, PartialEq)]
95pub enum SessionAction {
96    CompactContext {
97        focus: Option<String>,
98    },
99    PurgeContext,
100    LoadSession(std::path::PathBuf),
101    SyncSession(SessionSyncPayload),
102    NewSession {
103        sync: SessionSyncPayload,
104        force: bool,
105        draft: Option<String>,
106    },
107    SendMessage(String),
108    RemoteControl(SessionRemoteControlAction),
109    OpenExternalUrl {
110        url: String,
111        label: String,
112    },
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116pub enum SessionRemoteControlAction {
117    Start,
118    Stop,
119}
120
121pub type SessionCommandResult = CommandResult<SessionAction>;
122
123/// Complete config-group action vocabulary (FEAT-028 D5). Unifies the FEAT-027
124/// policy action with the auth, picker, view, screen-mode, trust and
125/// host-effect actions of the main config slice. Constructing one never
126/// executes it; the TUI host adapter converts it to a concrete `AppAction`
127/// outside the movable closure.
128#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum ConfigAction {
130    /// A permission rule was safely removed; the host reloads active rules.
131    PermissionRulesChanged,
132    ApproveAutoReviewRetry {
133        target: String,
134    },
135    // Auth flows (no host observation needed).
136    OpenModelConnectionSetup,
137    StartAccountConnect,
138    StartAccountLogin,
139    StartAccountLogout,
140    StartXaiDeviceLogin,
141    StartChatgptPkceLogin,
142    StartChatgptRevoke,
143    StartOrcarouterPkceLogin,
144    StartOrcarouterRevoke,
145    // Views and pickers.
146    OpenConfigView,
147    OpenModePicker,
148    SetConversationMode {
149        id: String,
150    },
151    OpenThemePicker,
152    OpenStatusPicker,
153    OpenProviderPicker,
154    StartPluginLogin {
155        provider: String,
156    },
157    StartPluginLogout {
158        provider: String,
159    },
160    SetScreenMode(crate::types::CommandScreenMode),
161    SetWorkspaceTrust {
162        trusted: bool,
163        save: bool,
164    },
165    // Engine/route effects carrying the exact host payload.
166    ModeChanged(crate::types::CommandMode),
167    ApprovalPolicyChanged {
168        policy: Option<String>,
169    },
170    SwitchProvider {
171        provider: crate::types::CommandProviderId,
172        model: Option<String>,
173    },
174    CompactionChanged(crate::config::CommandCompactionConfig),
175    StreamChunkTimeoutChanged(u64),
176    SubagentRuntimeChanged(crate::config::CommandSubagentRuntimeConfig),
177    SearchProviderChanged(crate::config::CommandSearchProvider),
178    PromptSuggestionChanged {
179        enabled: bool,
180    },
181    AutoReviewReviewerModelChanged {
182        reviewer_model: Option<String>,
183    },
184    NotificationChanged(crate::config::CommandNotificationUpdate),
185}
186pub type ConfigCommandResult = CommandResult<ConfigAction>;
187/// FEAT-027 compatibility alias; the whole group now standardizes on `ConfigAction`.
188pub type ConfigPolicyAction = ConfigAction;
189pub type ConfigPolicyCommandResult = ConfigCommandResult;
190pub type ConfigStatusCommandResult = CommandResult<std::convert::Infallible>;
191
192#[derive(Debug, Clone, PartialEq, Eq)]
193pub enum CoreNavigationAction {
194    OpenHotbarSetup,
195    DisableHotbar,
196    RestoreHotbarDefaults,
197    OpenLiveTranscript,
198    OpenTurnInspector,
199    OpenWorktreeManager,
200    SwitchWorkspace { workspace: std::path::PathBuf },
201    VoiceCapture,
202}
203
204pub type CoreNavigationCommandResult = CommandResult<CoreNavigationAction>;