Skip to main content

codewhale_command_contract/
types.rs

1//! Prototype boundary values used by the command capability shapes.
2//!
3//! These types deliberately do not replace the current TUI-owned production
4//! types in FEAT-014. During the in-place adoption stage, thin TUI adapters
5//! convert between existing application values and these boundary values.
6
7/// Stable provider identity at the command boundary.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct CommandProviderId(pub String);
10
11// Slice 4 removed `CommandReasoningEffort`: it was a verbatim 9-variant copy of
12// `codewhale_tui::reasoning_preference::ReasoningEffort` with no independent
13// behavior and no consumer, so it had no place on the command boundary.
14
15/// Application mode visible to commands.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum CommandMode {
18    Agent,
19    Plan,
20    Operate,
21}
22
23impl CommandMode {
24    /// Parse a `/mode` argument, mirroring the config layer's `AppMode::parse`.
25    #[must_use]
26    pub fn parse(value: &str) -> Option<Self> {
27        match value.trim().to_ascii_lowercase().as_str() {
28            "agent" | "act" | "work" | "auto" | "1" => Some(Self::Agent),
29            "plan" | "2" => Some(Self::Plan),
30            "operate" | "operation" | "ops" | "3" => Some(Self::Operate),
31            other if Self::is_legacy_bypass_alias(other) => Some(Self::Agent),
32            _ => None,
33        }
34    }
35
36    /// Legacy bypass spellings (`yolo`, `4`, `bypass`, …) that carry full access.
37    #[must_use]
38    pub fn is_legacy_bypass_alias(value: &str) -> bool {
39        matches!(
40            value.trim().to_ascii_lowercase().as_str(),
41            "yolo" | "4" | "bypass" | "bypass-permissions" | "bypasspermissions"
42        )
43    }
44
45    /// Short English UI label for the mode.
46    #[must_use]
47    pub fn display_name(self) -> &'static str {
48        match self {
49            Self::Agent => "Work",
50            Self::Plan => "Plan",
51            Self::Operate => "Operate",
52        }
53    }
54}
55
56/// Tool-approval posture visible to commands.
57#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
58pub enum CommandApprovalMode {
59    Auto,
60    Bypass,
61    #[default]
62    Suggest,
63    Never,
64}
65
66/// Cost currency used by command-facing accounting operations.
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68pub enum CommandCurrency {
69    Usd,
70    Cny,
71}
72
73/// Terminal screen mode visible to `/fullscreen` and `/inline` (FEAT-028 D5).
74/// Mirrors the TUI `ScreenMode`; the host adapter owns the actual viewport swap.
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub enum CommandScreenMode {
77    /// Alternate screen buffer.
78    Fullscreen,
79    /// Full-height inline viewport with no alternate screen.
80    Inline,
81}
82
83/// Workbar placement, mirroring the TUI `WorkSurfacePlacement`.
84#[derive(Debug, Clone, Copy, PartialEq, Eq)]
85pub enum CommandWorkSurfacePlacement {
86    Bottom,
87    Top,
88    Left,
89    Right,
90    Off,
91}
92
93impl CommandWorkSurfacePlacement {
94    /// Config-token spelling used by the `/workbar` status line and persistence.
95    #[must_use]
96    pub const fn as_setting(self) -> &'static str {
97        match self {
98            Self::Bottom => "bottom",
99            Self::Top => "top",
100            Self::Left => "left",
101            Self::Right => "right",
102            Self::Off => "off",
103        }
104    }
105}
106
107/// Workbar panel, mirroring the TUI `RailPanel`.
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109pub enum CommandRailPanel {
110    Agents,
111    Tasks,
112    Background,
113    Terminal,
114    Files,
115    Notepad,
116    Context,
117    Git,
118    Price,
119}