1use std::fmt;
2use std::str::FromStr;
3
4#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Hash)]
6pub enum PermissionMode {
7 #[default]
9 AutoEdit,
10 AutoEditAddressComments,
13 ReadOnly,
16}
17
18impl PermissionMode {
19 pub const ALL: [PermissionMode; 3] = [
21 PermissionMode::AutoEdit,
22 PermissionMode::AutoEditAddressComments,
23 PermissionMode::ReadOnly,
24 ];
25
26 pub fn description(self) -> &'static str {
28 match self {
29 Self::AutoEdit => "Allow the agent to edit files automatically.",
30 Self::AutoEditAddressComments => {
31 "Auto Edit, then address focused-review suggestions up to 3 times."
32 }
33 Self::ReadOnly => "Inspect the repository without changing files.",
34 }
35 }
36
37 pub fn label(self) -> &'static str {
39 match self {
40 Self::AutoEdit => "auto_edit",
41 Self::AutoEditAddressComments => "auto_edit_address_comments",
42 Self::ReadOnly => "read_only",
43 }
44 }
45
46 pub fn display_label(self) -> &'static str {
48 match self {
49 Self::AutoEdit => "Auto Edit",
50 Self::AutoEditAddressComments => "Auto Edit + Auto Address Comments",
51 Self::ReadOnly => "Read Only",
52 }
53 }
54
55 pub fn is_read_only(self) -> bool {
57 self == Self::ReadOnly
58 }
59}
60
61impl fmt::Display for PermissionMode {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "{}", self.label())
64 }
65}
66
67impl FromStr for PermissionMode {
68 type Err = String;
69
70 fn from_str(s: &str) -> Result<Self, Self::Err> {
71 match s {
72 "auto_edit" => Ok(PermissionMode::AutoEdit),
73 "auto_edit_address_comments" => Ok(PermissionMode::AutoEditAddressComments),
74 "read_only" => Ok(PermissionMode::ReadOnly),
75 _ => Err(format!("Unknown permission mode: {s}")),
76 }
77 }
78}
79
80#[cfg(test)]
81#[path = "permission_test.rs"]
82mod tests;