Skip to main content

aidaemon_core/
audience.rs

1//! Who a conversation reaches and who is speaking: the shared vocabulary
2//! hosts, tools, channels and memory use to scope what an agent may see and
3//! remember.
4
5/// Visibility level of the channel the message originated from.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum ChannelVisibility {
8    /// Direct message (1-on-1). Full memory, no restrictions.
9    Private,
10    /// Small private group (e.g., Telegram group, Slack MPIM). Cautious with sensitive info.
11    PrivateGroup,
12    /// Public channel visible to many users. No personal memory injected.
13    Public,
14    /// Untrusted public platform (Twitter, public APIs). Hardened security, minimal memory.
15    PublicExternal,
16    /// Internal/system-initiated (scheduler, triggers, sub-agents default). Full memory.
17    Internal,
18}
19
20impl std::fmt::Display for ChannelVisibility {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            ChannelVisibility::Private => write!(f, "private"),
24            ChannelVisibility::PrivateGroup => write!(f, "private_group"),
25            ChannelVisibility::Public => write!(f, "public"),
26            ChannelVisibility::PublicExternal => write!(f, "public_external"),
27            ChannelVisibility::Internal => write!(f, "internal"),
28        }
29    }
30}
31
32impl ChannelVisibility {
33    /// Parse from a string (e.g., from tool args). Falls back to `Internal`.
34    pub fn from_str_lossy(s: &str) -> Self {
35        match s {
36            "private" => Self::Private,
37            "private_group" => Self::PrivateGroup,
38            "public" => Self::Public,
39            "public_external" => Self::PublicExternal,
40            "internal" => Self::Internal,
41            _ => Self::Internal,
42        }
43    }
44}
45
46/// Role assigned to a user based on config (owner_ids).
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum UserRole {
49    /// Full access — listed in `users.owner_ids`.
50    Owner,
51    /// Allowed by channel allowlist but not an owner.
52    Guest,
53    /// Non-whitelisted user — conversational access only, no tools.
54    Public,
55}
56
57impl std::fmt::Display for UserRole {
58    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59        match self {
60            UserRole::Owner => write!(f, "owner"),
61            UserRole::Guest => write!(f, "guest"),
62            UserRole::Public => write!(f, "public"),
63        }
64    }
65}
66
67impl UserRole {
68    /// Only explicit owner traffic is allowed to update durable owner memory.
69    /// The daemon's memory policy, not part of the stable API.
70    #[doc(hidden)]
71    pub fn can_persist_owner_memory(self) -> bool {
72        matches!(self, Self::Owner)
73    }
74}