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}
21
22impl CommandMode {
23    /// Parse a `/mode` argument, mirroring the config layer's `AppMode::parse`.
24    #[must_use]
25    pub fn parse(value: &str) -> Option<Self> {
26        match value.trim().to_ascii_lowercase().as_str() {
27            "agent" | "act" | "work" | "auto" | "1" => Some(Self::Agent),
28            "plan" | "2" => Some(Self::Plan),
29            other if Self::is_retired_operate_alias(other) => Some(Self::Agent),
30            other if Self::is_legacy_bypass_alias(other) => Some(Self::Agent),
31            _ => None,
32        }
33    }
34
35    #[must_use]
36    pub fn is_retired_operate_alias(value: &str) -> bool {
37        matches!(
38            value.trim().to_ascii_lowercase().as_str(),
39            "operate" | "operation" | "ops" | "3"
40        )
41    }
42
43    /// Legacy bypass spellings (`yolo`, `4`, `bypass`, …) that carry full access.
44    #[must_use]
45    pub fn is_legacy_bypass_alias(value: &str) -> bool {
46        matches!(
47            value.trim().to_ascii_lowercase().as_str(),
48            "yolo" | "4" | "bypass" | "bypass-permissions" | "bypasspermissions"
49        )
50    }
51
52    /// Short English UI label for the mode.
53    #[must_use]
54    pub fn display_name(self) -> &'static str {
55        match self {
56            Self::Agent => "Work",
57            Self::Plan => "Plan",
58        }
59    }
60}
61
62/// Tool-approval posture visible to commands.
63#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
64pub enum CommandApprovalMode {
65    Auto,
66    Bypass,
67    #[default]
68    Suggest,
69    AcceptEdits,
70    Never,
71}
72
73/// Cost currency used by command-facing accounting operations.
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
75pub enum CommandCurrency {
76    Usd,
77    Cny,
78}
79
80/// Terminal screen mode visible to `/fullscreen` and `/inline` (FEAT-028 D5).
81/// Mirrors the TUI `ScreenMode`; the host adapter owns the actual viewport swap.
82#[derive(Debug, Clone, Copy, PartialEq, Eq)]
83pub enum CommandScreenMode {
84    /// Alternate screen buffer.
85    Fullscreen,
86    /// Full-height inline viewport with no alternate screen.
87    Inline,
88}
89
90/// Workbar placement, mirroring the TUI `WorkSurfacePlacement`.
91#[derive(Debug, Clone, Copy, PartialEq, Eq)]
92pub enum CommandWorkSurfacePlacement {
93    Bottom,
94    Top,
95    Left,
96    Right,
97    Off,
98}
99
100impl CommandWorkSurfacePlacement {
101    /// Config-token spelling used by the `/workbar` status line and persistence.
102    #[must_use]
103    pub const fn as_setting(self) -> &'static str {
104        match self {
105            Self::Bottom => "bottom",
106            Self::Top => "top",
107            Self::Left => "left",
108            Self::Right => "right",
109            Self::Off => "off",
110        }
111    }
112}
113
114/// Workbar panel, mirroring the TUI `RailPanel`.
115#[derive(Debug, Clone, Copy, PartialEq, Eq)]
116pub enum CommandRailPanel {
117    Agents,
118    Tasks,
119    Background,
120    Terminal,
121    Files,
122    Notepad,
123    Context,
124    Git,
125    Price,
126}