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    /// Openly shareable.
49    #[default]
50    Public = 0,
51    /// Limited audience — rights-filtered.
52    Restricted = 1,
53    /// Highest confidentiality (sanctuary-grade).
54    Classified = 2,
55}
56
57impl SensitivityClass {
58    /// Parse a class label; `"restricted"` → Restricted,
59    /// `"classified"`/`"sanctuary"`/`"secret"` → Classified, anything else
60    /// → Public.
61    pub fn parse(s: &str) -> Self {
62        match s.trim().to_ascii_lowercase().as_str() {
63            "restricted" => Self::Restricted,
64            "classified" | "sanctuary" | "secret" => Self::Classified,
65            _ => Self::Public,
66        }
67    }
68
69    /// True for `Restricted` or `Classified` — content that requires
70    /// rights-filtered presentation.
71    pub fn is_high(self) -> bool {
72        matches!(self, Self::Restricted | Self::Classified)
73    }
74}
75
76/// Fixed affordance bits for path open/share/enter/edit (presentation + deontic).
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
78pub struct AffordanceBits {
79    /// Observer may open/read the entity.
80    pub can_open: bool,
81    /// Observer may share/forward it.
82    pub can_share: bool,
83    /// Observer may enter its spatial/scene context.
84    pub can_enter: bool,
85    /// Observer may modify it.
86    pub can_edit: bool,
87}
88
89impl AffordanceBits {
90    pub const NONE: Self = Self {
91        can_open: false,
92        can_share: false,
93        can_enter: false,
94        can_edit: false,
95    };
96
97    pub const FULL: Self = Self {
98        can_open: true,
99        can_share: true,
100        can_enter: true,
101        can_edit: true,
102    };
103
104    /// Pack the four flags into a nibble (bit0=open, 1=share, 2=enter,
105    /// 3=edit) for wire/storage.
106    pub fn pack(self) -> u8 {
107        let mut b = 0u8;
108        if self.can_open {
109            b |= 1;
110        }
111        if self.can_share {
112            b |= 2;
113        }
114        if self.can_enter {
115            b |= 4;
116        }
117        if self.can_edit {
118            b |= 8;
119        }
120        b
121    }
122
123    /// Inverse of [`Self::pack`]; bits above bit3 are ignored.
124    pub fn unpack(b: u8) -> Self {
125        Self {
126            can_open: b & 1 != 0,
127            can_share: b & 2 != 0,
128            can_enter: b & 4 != 0,
129            can_edit: b & 8 != 0,
130        }
131    }
132}
133
134/// Minimal entity descriptor for pure rights filtering (no heap bodies).
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
136pub struct EntityViewMeta {
137    /// Stable entity identifier being viewed.
138    pub entity_id: super::entity_id::EntityId,
139    /// Coarse projection kind.
140    pub kind: super::entity_id::EntityKind,
141    /// Sensitivity of the underlying content.
142    pub sensitivity: SensitivityClass,
143    /// Entity lives in secret / sanctuary lane.
144    pub is_secret: bool,
145    /// Commons / offered visibility intended by owner.
146    pub commons_visible: bool,
147    /// Offered to peers (metadata wing).
148    pub peer_offered: bool,
149}
150
151impl Default for EntityViewMeta {
152    fn default() -> Self {
153        Self {
154            entity_id: super::entity_id::EntityId::default(),
155            kind: super::entity_id::EntityKind::Unknown,
156            sensitivity: SensitivityClass::Public,
157            is_secret: false,
158            commons_visible: false,
159            peer_offered: false,
160        }
161    }
162}