codewhale_command_contract/
outcome.rs1use 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#[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 OpenContextInspector,
67 SendMessage(String),
68 SyncSession(SessionSyncPayload),
69 ConversationUndo {
72 sync: SessionSyncPayload,
73 retry_input: Option<String>,
74 },
75}
76
77pub type DebugCommandResult = CommandResult<DebugAction>;
78
79pub type StructcopyCommandResult = CommandResult<std::convert::Infallible>;
81
82#[derive(Debug, Clone, PartialEq)]
84pub enum SessionAction {
85 CompactContext { focus: Option<String> },
86 PurgeContext,
87 LoadSession(std::path::PathBuf),
88 SyncSession(SessionSyncPayload),
89 SendMessage(String),
90 RemoteControl(SessionRemoteControlAction),
91 OpenExternalUrl { url: String, label: String },
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq)]
95pub enum SessionRemoteControlAction {
96 Start,
97 Stop,
98}
99
100pub type SessionCommandResult = CommandResult<SessionAction>;
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub enum ConfigPolicyAction {
105 PermissionRulesChanged,
106}
107pub type ConfigPolicyCommandResult = CommandResult<ConfigPolicyAction>;
108pub type ConfigStatusCommandResult = CommandResult<std::convert::Infallible>;