1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct ResourceBody {
9 pub mind: MindCapacity,
10 pub energy: ProcessingEnergy,
11 pub reach: NetworkReach,
12 pub storage: StorageCapacity,
13 pub visual: Option<GpuCapacity>,
14 pub vitals: BodyVitals,
15 pub sensations: Vec<ResourceSensation>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct MindCapacity {
21 pub total_bytes: u64,
22 pub used_bytes: u64,
23 pub available_bytes: u64,
24 pub feeling: MindFeeling,
25 pub pressure: MemoryPressure,
26 pub largest_free_bytes: u64,
27 pub fragmentation: f64,
28 pub swap: Option<SwapUsage>,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
32pub enum MindFeeling {
33 Clear,
34 Active,
35 Crowded,
36 Strained,
37 Overwhelmed,
38 Drowning,
39}
40
41impl std::fmt::Display for MindFeeling {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 match self {
44 Self::Clear => write!(f, "clear"),
45 Self::Active => write!(f, "active"),
46 Self::Crowded => write!(f, "crowded"),
47 Self::Strained => write!(f, "strained"),
48 Self::Overwhelmed => write!(f, "overwhelmed"),
49 Self::Drowning => write!(f, "drowning"),
50 }
51 }
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
55pub enum MemoryPressure {
56 None,
57 Low,
58 Medium,
59 High,
60 Critical,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct SwapUsage {
65 pub total_bytes: u64,
66 pub used_bytes: u64,
67 pub active: bool,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct ProcessingEnergy {
73 pub cores: u32,
74 pub utilization: f64,
75 pub feeling: EnergyFeeling,
76 pub load_average: [f64; 3],
77 pub burst_available: bool,
78 pub throttled: bool,
79 pub credits: Option<CpuCredits>,
80 pub temperature: Option<f64>,
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
84pub enum EnergyFeeling {
85 Vigorous,
86 Steady,
87 Busy,
88 Strained,
89 Depleted,
90 Constrained,
91}
92
93impl std::fmt::Display for EnergyFeeling {
94 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 match self {
96 Self::Vigorous => write!(f, "vigorous"),
97 Self::Steady => write!(f, "steady"),
98 Self::Busy => write!(f, "busy"),
99 Self::Strained => write!(f, "strained"),
100 Self::Depleted => write!(f, "depleted"),
101 Self::Constrained => write!(f, "constrained"),
102 }
103 }
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct CpuCredits {
108 pub remaining: f64,
109 pub earning_rate: f64,
110 pub depleted: bool,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct NetworkReach {
116 pub bandwidth_mbps: u64,
117 pub utilization: f64,
118 pub latencies: HashMap<String, LatencyStats>,
119 pub feeling: ReachFeeling,
120 pub connections: ConnectionStats,
121 pub stability: f64,
122 pub packet_loss: f64,
123 pub egress_remaining: Option<u64>,
124}
125
126#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
127pub enum ReachFeeling {
128 Connected,
129 Normal,
130 Sluggish,
131 Constrained,
132 Isolated,
133 Partitioned,
134}
135
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct LatencyStats {
138 pub p50_ms: f64,
139 pub p95_ms: f64,
140 pub p99_ms: f64,
141 pub max_ms: f64,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct ConnectionStats {
146 pub active: u32,
147 pub idle: u32,
148 pub max: u32,
149 pub errored: u32,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct StorageCapacity {
155 pub total_bytes: u64,
156 pub used_bytes: u64,
157 pub available_bytes: u64,
158 pub iops: Option<u64>,
159 pub throughput_mbps: Option<u64>,
160 pub latency_ms: Option<f64>,
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct GpuCapacity {
166 pub count: u32,
167 pub gpu_type: String,
168 pub memory_total_bytes: u64,
169 pub memory_used_bytes: u64,
170 pub utilization: f64,
171 pub temperature: Option<f64>,
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize)]
176pub struct BodyVitals {
177 pub overall_health: f64,
178 pub heartbeat_ms: u64,
179 pub last_check: i64,
180 pub anomalies: Vec<String>,
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185pub struct ResourceSensation {
186 pub resource: ResourceType,
187 pub sensation: SensationType,
188 pub intensity: f64,
189 pub started: i64,
190 pub trend: SensationTrend,
191}
192
193#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
194pub enum ResourceType {
195 Memory,
196 Cpu,
197 Network,
198 Storage,
199 Gpu,
200}
201
202impl std::fmt::Display for ResourceType {
203 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
204 match self {
205 Self::Memory => write!(f, "memory"),
206 Self::Cpu => write!(f, "cpu"),
207 Self::Network => write!(f, "network"),
208 Self::Storage => write!(f, "storage"),
209 Self::Gpu => write!(f, "gpu"),
210 }
211 }
212}
213
214#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
215pub enum SensationType {
216 Comfort,
217 Pressure,
218 Pain,
219 Relief,
220 Alarm,
221 Numbness,
222}
223
224#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
225pub enum SensationTrend {
226 Improving,
227 Stable,
228 Worsening,
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize)]
233pub struct ResourcePressureGradient {
234 pub bottleneck: Option<ResourceType>,
235 pub pressures: HashMap<ResourceType, Pressure>,
236 pub flow: PressureFlow,
237 pub building: Vec<ResourceType>,
238 pub releasing: Vec<ResourceType>,
239 pub predicted_bottleneck: Option<PredictedBottleneck>,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
243pub struct Pressure {
244 pub level: f64,
245 pub trend: PressureTrend,
246 pub source: String,
247}
248
249#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
250pub enum PressureTrend {
251 Rising,
252 Stable,
253 Falling,
254}
255
256#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
257pub enum PressureFlow {
258 Balanced,
259 Shifting,
260 Cascading,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize)]
264pub struct PredictedBottleneck {
265 pub resource: ResourceType,
266 pub estimated_secs: u64,
267 pub confidence: f64,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
272pub struct CostConsciousness {
273 pub burn_rate: Cost,
274 pub session_cost: Cost,
275 pub budget: Option<BudgetConstraints>,
276 pub breakdown: HashMap<String, Cost>,
277 pub feeling: CostFeeling,
278 pub projections: Vec<CostProjection>,
279}
280
281#[derive(Debug, Clone, Serialize, Deserialize)]
282pub struct Cost {
283 pub monetary: f64,
284 pub carbon: Option<f64>,
285 pub opportunity: Option<f64>,
286 pub reputation: Option<f64>,
287 pub currency: String,
288}
289
290#[derive(Debug, Clone, Serialize, Deserialize)]
291pub struct BudgetConstraints {
292 pub total: f64,
293 pub remaining: f64,
294 pub period: String,
295 pub hard_limit: bool,
296}
297
298#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
299pub enum CostFeeling {
300 Comfortable,
301 Mindful,
302 Concerned,
303 Anxious,
304 Panicked,
305}
306
307#[derive(Debug, Clone, Serialize, Deserialize)]
308pub struct CostProjection {
309 pub period: String,
310 pub projected_cost: f64,
311 pub confidence: f64,
312}
313
314#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct CapabilityMap {
317 pub capabilities: Vec<Capability>,
318 pub discovered_at: i64,
319 pub stale_after_secs: u64,
320}
321
322#[derive(Debug, Clone, Serialize, Deserialize)]
323pub struct Capability {
324 pub name: String,
325 pub category: CapabilityCategory,
326 pub available: bool,
327 pub constraints: Vec<CapabilityConstraint>,
328 pub confidence: f64,
329}
330
331#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
332pub enum CapabilityCategory {
333 Compute,
334 Storage,
335 Network,
336 ExternalApi,
337 SisterBridge,
338 Security,
339 MachineLearning,
340 Tool,
341}
342
343#[derive(Debug, Clone, Serialize, Deserialize)]
344pub struct CapabilityConstraint {
345 pub constraint_type: ConstraintType,
346 pub description: String,
347 pub value: String,
348}
349
350#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
351pub enum ConstraintType {
352 RateLimit,
353 Quota,
354 TimeWindow,
355 CostLimit,
356 Permission,
357 Dependency,
358}
359
360#[derive(Debug, Clone, Serialize, Deserialize)]
362pub struct CapacityIntuition {
363 pub adequacy: CapacityAdequacy,
364 pub intuitions: Vec<ResourceIntuition>,
365 pub patterns: Vec<CapacityPattern>,
366}
367
368#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
369pub enum CapacityAdequacy {
370 Abundant,
371 Sufficient,
372 Tight,
373 Insufficient,
374 Critical,
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize)]
378pub struct ResourceIntuition {
379 pub resource: ResourceType,
380 pub current_adequacy: CapacityAdequacy,
381 pub predicted_adequacy: CapacityAdequacy,
382 pub horizon_secs: u64,
383 pub confidence: f64,
384}
385
386#[derive(Debug, Clone, Serialize, Deserialize)]
387pub struct CapacityPattern {
388 pub pattern_type: PatternType,
389 pub resource: ResourceType,
390 pub description: String,
391 pub confidence: f64,
392}
393
394#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
395pub enum PatternType {
396 DailySpike,
397 WeeklyPattern,
398 GrowthTrend,
399 DecayTrend,
400 BurstPattern,
401 SeasonalPattern,
402 Anomaly,
403}