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