Skip to main content

secureops_core/
runtime.rs

1//! Runtime value types shared by monitors, hardening and the daemon.
2//!
3//! Port of the monitor / cost / hardening / skill-scan interfaces in
4//! `src/types.ts`. Behavior (the actual tokio monitors, AlertBus, hardening
5//! modules) lives in `secureops-monitors` / future hardening crates; these are
6//! the data shapes that cross the JSON / IPC boundary.
7
8use crate::types::Severity;
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11
12/// A monitor alert emitted onto the AlertBus and persisted to SQLite.
13#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
14#[serde(rename_all = "camelCase")]
15pub struct MonitorAlert {
16    pub timestamp: String,
17    pub severity: Severity,
18    pub monitor: String,
19    pub message: String,
20    #[serde(skip_serializing_if = "Option::is_none", default)]
21    pub details: Option<String>,
22}
23
24/// Snapshot of a monitor's state.
25#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
26#[serde(rename_all = "camelCase")]
27pub struct MonitorStatus {
28    pub running: bool,
29    #[serde(skip_serializing_if = "Option::is_none", default)]
30    pub last_check: Option<String>,
31    pub alerts: Vec<MonitorAlert>,
32}
33
34/// One cost-tracking entry.
35#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
36#[serde(rename_all = "camelCase")]
37pub struct CostEntry {
38    pub timestamp: String,
39    pub model: String,
40    pub input_tokens: u64,
41    pub output_tokens: u64,
42    pub estimated_cost_usd: f64,
43}
44
45/// Rolling cost report + circuit-breaker state.
46#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
47#[serde(rename_all = "camelCase")]
48pub struct CostReport {
49    pub hourly: f64,
50    pub daily: f64,
51    pub monthly: f64,
52    pub projection: CostProjection,
53    pub circuit_breaker_tripped: bool,
54    pub entries: Vec<CostEntry>,
55}
56
57#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
58#[serde(rename_all = "camelCase")]
59pub struct CostProjection {
60    pub daily: f64,
61    pub monthly: f64,
62}
63
64/// Result of scanning a single skill.
65#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
66#[serde(rename_all = "camelCase")]
67pub struct SkillScanResult {
68    pub safe: bool,
69    pub skill_name: String,
70    pub findings: Vec<String>,
71    pub dangerous_patterns: Vec<String>,
72    pub ioc_matches: Vec<String>,
73}
74
75/// Behavioral baseline entry (directive G3).
76#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
77#[serde(rename_all = "camelCase")]
78pub struct BehavioralBaseline {
79    pub tool_call_frequency: HashMap<String, u64>,
80    pub typical_tools: Vec<String>,
81    pub typical_data_paths: Vec<String>,
82    pub window_minutes: u64,
83    pub last_updated: String,
84}
85
86// ---- Hardening ----
87
88/// A single hardening action taken (before/after for rollback + audit).
89#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
90#[serde(rename_all = "camelCase")]
91pub struct HardeningAction {
92    pub id: String,
93    pub description: String,
94    pub before: String,
95    pub after: String,
96}
97
98/// Result of running one hardening module.
99#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
100#[serde(rename_all = "camelCase")]
101pub struct HardeningResult {
102    pub module: String,
103    pub applied: Vec<HardeningAction>,
104    pub skipped: Vec<HardeningAction>,
105    pub errors: Vec<String>,
106}