Skip to main content

agentic_reality/types/
stakes.rs

1//! Stakes perception types — "What are the consequences?"
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Consequence awareness — understanding impacts of actions.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ConsequenceAwareness {
9    pub stakes: StakesLevel,
10    pub consequence_map: Vec<Consequence>,
11    pub irreversible: Vec<IrreversibleAction>,
12    pub safety_margins: SafetyMargins,
13    pub history: Vec<ConsequenceRecord>,
14}
15
16/// Level of stakes for the current context.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub enum StakesLevel {
19    Minimal {
20        can_experiment: bool,
21    },
22    Low {
23        rollback_available: bool,
24    },
25    Medium {
26        review_recommended: bool,
27    },
28    High {
29        caution_required: bool,
30        approval_needed: bool,
31    },
32    Critical {
33        multiple_approvals: bool,
34        audit_required: bool,
35        no_risk_tolerance: bool,
36    },
37}
38
39impl std::fmt::Display for StakesLevel {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        match self {
42            Self::Minimal { .. } => write!(f, "minimal"),
43            Self::Low { .. } => write!(f, "low"),
44            Self::Medium { .. } => write!(f, "medium"),
45            Self::High { .. } => write!(f, "high"),
46            Self::Critical { .. } => write!(f, "critical"),
47        }
48    }
49}
50
51/// A potential consequence of an action.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct Consequence {
54    pub effect: String,
55    pub probability: f64,
56    pub severity: Severity,
57    pub reversibility: Reversibility,
58    pub affected: Vec<String>,
59    pub latency_secs: Option<u64>,
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
63pub enum Severity {
64    Negligible,
65    Minor,
66    Moderate,
67    Major,
68    Catastrophic,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
72pub enum Reversibility {
73    Easy,
74    WithEffort,
75    Partial,
76    Irreversible,
77}
78
79/// An action that cannot be undone.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct IrreversibleAction {
82    pub action: String,
83    pub consequences: Vec<String>,
84    pub safeguards: Vec<String>,
85    pub requires_approval: bool,
86}
87
88/// Safety margins for operations.
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct SafetyMargins {
91    pub overall: f64,
92    pub by_domain: HashMap<String, f64>,
93    pub guardrails: Vec<Guardrail>,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct Guardrail {
98    pub name: String,
99    pub description: String,
100    pub active: bool,
101    pub triggered_count: u32,
102}
103
104/// Record of a consequence that occurred.
105#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct ConsequenceRecord {
107    pub action: String,
108    pub consequence: String,
109    pub severity: Severity,
110    pub timestamp: i64,
111    pub expected: bool,
112}
113
114/// Risk field perception — risk as a continuous field.
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct RiskFieldPerception {
117    pub overall_risk: f64,
118    pub risk_map: HashMap<RiskCategory, RiskLevel>,
119    pub hotspots: Vec<RiskHotspot>,
120    pub safe_zones: Vec<String>,
121    pub gradients: Vec<RiskGradient>,
122    pub forecast: Vec<RiskForecast>,
123}
124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
126pub enum RiskCategory {
127    DataRisk,
128    SecurityRisk,
129    AvailabilityRisk,
130    PerformanceRisk,
131    FinancialRisk,
132    ComplianceRisk,
133    ReputationRisk,
134    UserHarmRisk,
135}
136
137impl std::fmt::Display for RiskCategory {
138    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139        match self {
140            Self::DataRisk => write!(f, "data"),
141            Self::SecurityRisk => write!(f, "security"),
142            Self::AvailabilityRisk => write!(f, "availability"),
143            Self::PerformanceRisk => write!(f, "performance"),
144            Self::FinancialRisk => write!(f, "financial"),
145            Self::ComplianceRisk => write!(f, "compliance"),
146            Self::ReputationRisk => write!(f, "reputation"),
147            Self::UserHarmRisk => write!(f, "user_harm"),
148        }
149    }
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct RiskLevel {
154    pub score: f64,
155    pub trend: RiskTrend,
156    pub mitigations: Vec<String>,
157}
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
160pub enum RiskTrend {
161    Increasing,
162    Stable,
163    Decreasing,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize)]
167pub struct RiskHotspot {
168    pub area: String,
169    pub risk_score: f64,
170    pub categories: Vec<RiskCategory>,
171    pub description: String,
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize)]
175pub struct RiskGradient {
176    pub from: String,
177    pub to: String,
178    pub gradient: f64,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct RiskForecast {
183    pub category: RiskCategory,
184    pub horizon_secs: u64,
185    pub predicted_level: f64,
186    pub confidence: f64,
187}
188
189/// Blast radius awareness.
190#[derive(Debug, Clone, Serialize, Deserialize)]
191pub struct BlastRadiusAwareness {
192    pub my_blast_radius: BlastRadius,
193    pub dependency_blast: Vec<DependencyBlast>,
194    pub cascade: CascadeAnalysis,
195    pub isolation: IsolationAssessment,
196    pub containment: Vec<ContainmentStrategy>,
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize)]
200pub struct BlastRadius {
201    pub affected_services: Vec<String>,
202    pub affected_users: EstimatedImpact,
203    pub affected_data: Vec<String>,
204    pub geographic_scope: Vec<String>,
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize)]
208pub struct EstimatedImpact {
209    pub count: u64,
210    pub percentage: f64,
211    pub confidence: f64,
212}
213
214#[derive(Debug, Clone, Serialize, Deserialize)]
215pub struct DependencyBlast {
216    pub dependency: String,
217    pub blast_radius: BlastRadius,
218    pub probability: f64,
219}
220
221#[derive(Debug, Clone, Serialize, Deserialize)]
222pub struct CascadeAnalysis {
223    pub max_depth: u32,
224    pub affected_count: u32,
225    pub critical_path: Vec<String>,
226    pub containment_possible: bool,
227}
228
229#[derive(Debug, Clone, Serialize, Deserialize)]
230pub struct IsolationAssessment {
231    pub isolation_score: f64,
232    pub blast_walls: Vec<String>,
233    pub leaks: Vec<String>,
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct ContainmentStrategy {
238    pub name: String,
239    pub description: String,
240    pub effectiveness: f64,
241    pub cost: String,
242}