crisol_core/agent/
permissions.rs1use std::collections::HashSet;
4
5#[derive(Clone, Debug)]
7#[non_exhaustive]
8pub struct Permissions {
14 pub read_only: bool,
16 pub allowed_commands: Option<HashSet<String>>,
18 pub sensitive_commands: HashSet<String>,
20 pub confirmation_token: Option<String>,
22}
23
24impl Default for Permissions {
25 fn default() -> Self {
26 Self {
27 read_only: true,
28 allowed_commands: None,
29 sensitive_commands: HashSet::new(),
30 confirmation_token: None,
31 }
32 }
33}
34
35impl Permissions {
36 pub fn read_write() -> Self {
38 Self {
39 read_only: false,
40 ..Self::default()
41 }
42 }
43
44 pub fn allow_commands<I, S>(mut self, commands: I) -> Self
46 where
47 I: IntoIterator<Item = S>,
48 S: Into<String>,
49 {
50 self.allowed_commands = Some(commands.into_iter().map(Into::into).collect());
51 self
52 }
53
54 pub fn confirm<I, S>(mut self, commands: I, token: impl Into<String>) -> Self
56 where
57 I: IntoIterator<Item = S>,
58 S: Into<String>,
59 {
60 self.sensitive_commands = commands.into_iter().map(Into::into).collect();
61 self.confirmation_token = Some(token.into());
62 self
63 }
64
65 pub fn require_confirmation<I, S>(mut self, commands: I) -> Self
70 where
71 I: IntoIterator<Item = S>,
72 S: Into<String>,
73 {
74 self.sensitive_commands = commands.into_iter().map(Into::into).collect();
75 self.confirmation_token = None;
76 self
77 }
78}