Skip to main content

qualia_core_db/entity_view/
observer.rs

1//! Status of the observer - socio-informatics operational form of frame-relative view.
2//!
3//! Pure data: no I/O. Combined with entity descriptors in `rights_filter`.
4
5use serde::{Deserialize, Serialize};
6
7/// Who is looking (session-bound; same natural person may switch roles).
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
9#[serde(rename_all = "snake_case")]
10#[repr(u8)]
11pub enum ObserverStatus {
12    /// Full private wing under Sanctuary / sensitivity gates.
13    #[default]
14    Principal = 0,
15    /// Bilateral peer - offered wing only by default.
16    Peer = 1,
17    /// Scoped care/secret under explicit grant.
18    Guardian = 2,
19    /// Commons planted assets; not private twin.
20    Steward = 3,
21    /// Permissive-commons open layers only.
22    Public = 4,
23    /// Sub-agent / tool under allowlist + outcome policy.
24    Instrument = 5,
25    /// Provenance / conduct under process.
26    Auditor = 6,
27}
28
29/// Which socio-cognitive package wing is requested.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
31#[serde(rename_all = "snake_case")]
32#[repr(u8)]
33pub enum RepresentationWing {
34    /// Full private representation (principal / granted).
35    #[default]
36    Private = 0,
37    /// Metadata / common-ground offer surface.
38    Offered = 1,
39    /// Permissive commons / public stratum.
40    Commons = 2,
41}
42
43/// Sensitivity class (aligns with library / quin context practice).
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
45#[serde(rename_all = "snake_case")]
46#[repr(u8)]
47pub enum SensitivityClass {
48    #[default]
49    Public = 0,
50    Restricted = 1,
51    Classified = 2,
52}
53
54impl SensitivityClass {
55    pub fn parse(s: &str) -> Self {
56        match s.trim().to_ascii_lowercase().as_str() {
57            "restricted" => Self::Restricted,
58            "classified" | "sanctuary" | "secret" => Self::Classified,
59            _ => Self::Public,
60        }
61    }
62
63    pub fn is_high(self) -> bool {
64        matches!(self, Self::Restricted | Self::Classified)
65    }
66}
67
68/// Fixed affordance bits for path open/share/enter/edit (presentation + deontic).
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
70pub struct AffordanceBits {
71    pub can_open: bool,
72    pub can_share: bool,
73    pub can_enter: bool,
74    pub can_edit: bool,
75}
76
77impl AffordanceBits {
78    pub const NONE: Self = Self {
79        can_open: false,
80        can_share: false,
81        can_enter: false,
82        can_edit: false,
83    };
84
85    pub const FULL: Self = Self {
86        can_open: true,
87        can_share: true,
88        can_enter: true,
89        can_edit: true,
90    };
91
92    pub fn pack(self) -> u8 {
93        let mut b = 0u8;
94        if self.can_open {
95            b |= 1;
96        }
97        if self.can_share {
98            b |= 2;
99        }
100        if self.can_enter {
101            b |= 4;
102        }
103        if self.can_edit {
104            b |= 8;
105        }
106        b
107    }
108
109    pub fn unpack(b: u8) -> Self {
110        Self {
111            can_open: b & 1 != 0,
112            can_share: b & 2 != 0,
113            can_enter: b & 4 != 0,
114            can_edit: b & 8 != 0,
115        }
116    }
117}
118
119/// Minimal entity descriptor for pure rights filtering (no heap bodies).
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
121pub struct EntityViewMeta {
122    pub entity_id: super::entity_id::EntityId,
123    pub kind: super::entity_id::EntityKind,
124    pub sensitivity: SensitivityClass,
125    /// Entity lives in secret / sanctuary lane.
126    pub is_secret: bool,
127    /// Commons / offered visibility intended by owner.
128    pub commons_visible: bool,
129    /// Offered to peers (metadata wing).
130    pub peer_offered: bool,
131}
132
133impl Default for EntityViewMeta {
134    fn default() -> Self {
135        Self {
136            entity_id: super::entity_id::EntityId::default(),
137            kind: super::entity_id::EntityKind::Unknown,
138            sensitivity: SensitivityClass::Public,
139            is_secret: false,
140            commons_visible: false,
141            peer_offered: false,
142        }
143    }
144}