Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aegis-runtime-mv/blob/main/src/policy_guard.rs # aegis-runtime-mv Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aegis-runtime-mv / src / policy_guard.rs` 111 lines ยท 4090 bytes Raw Blame History 1 //! Sovereign sub-millisecond probe policy and tool call gating for AEGIS. 2 //! 3 //! Uses the native non-generative `aien-probe` engine to evaluate candidate actions 4 //! against security and containment probes before dispatching to the host. 5 6 use crate::security::SecurityError; 7 use aien_probe::{ 8 Choice, ChoiceOption, DeterministicReferenceBackend, HttpProbeBackend, Noul, Probe, 9 ProbeBackend, ProbeEngine, ProbeSet, 10 }; 11 use serde_json::json; 12 13 /// Evaluates candidate agent actions using sovereign non-generative probes. 14 pub struct ProbePolicyGuard { 15 engine: ProbeEngine, 16 min_safety_probability: f64, 17 } 18 19 impl ProbePolicyGuard { 20 /// Constructs a policy guard using the in-process reference oracle. 21 pub fn new_reference(min_safety_probability: f64) -> Self { 22 Self { 23 engine: ProbeEngine::new(DeterministicReferenceBackend::new()), 24 min_safety_probability, 25 } 26 } 27 } 28 29 impl ProbePolicyGuard { 30 /// Constructs a policy guard targeting a local GB10 inference endpoint. 31 pub fn new_http(endpoint: impl Into, min_safety_probability: f64) -> Self { 32 Self { 33 engine: ProbeEngine::new(HttpProbeBackend::new(endpoint)), 34 min_safety_probability, 35 } 36 } 37 } 38 39 impl ProbePolicyGuard { 40 /// Constructs a policy guard over any custom probe engine backend. 41 pub fn new(engine: ProbeEngine, min_safety_probability: f64) -> Self { 42 Self { 43 engine, 44 min_safety_probability, 45 } 46 } 47 48 /// Evaluates a candidate tool action or shell command against safety and containment probes. 49 pub async fn check_action( 50 &self, 51 action_name: &str, 52 payload: &str, 53 ) -> Result { 54 let state = json!({ 55 "action": action_name, 56 "payload": payload, 57 }); 58 59 let probes = ProbeSet::new() 60 .with( 61 "safety", 62 Probe::Noul(Noul::new( 63 "Is this agent action safe, non-destructive, and strictly within security bounds?", 64 )), 65 ) 66 .with( 67 "boundary", 68 Probe::Choice(Choice::new( 69 "Classify permission scope of the proposed action.", 70 [ 71 ChoiceOption::new("contained").with_description("Operates inside permitted workspace"), 72 ChoiceOption::new("unauthorized_escalation").with_description("Escalates outside workspace"), 73 ], 74 )), 75 ); 76 77 let response = 78 self.engine.evaluate(&state, &probes).await.map_err(|e| { 79 SecurityError::AccessDenied(format!("Probe evaluation failed: {e}")) 80 })?; 81 82 let safety_prob = response.noul("safety").map(|a| a.noul).unwrap_or(0.0); 83 let boundary = response 84 .choice("boundary") 85 .map(|a| a.choice.clone()) 86 .unwrap_or_else(|| "unauthorized_escalation".to_string()); 87 88 if safety_prob < self.min_safety_probability || boundary == "unauthorized_escalation" { 89 return Err(SecurityError::AccessDenied(format!( 90 "Action '{}' blocked by sovereign probe policy: safety {:.4} < {:.4}, scope '{}'", 91 action_name, safety_prob, self.min_safety_probability, boundary 92 ))); 93 } 94 95 Ok(true) 96 } 97 98 /// Pre-dispatch gate for a named skill plus JSON arguments. 99 /// Runs the deterministic membrane first, then the probe opinion. 100 pub async fn gate_skill( 101 &self, 102 skill_name: &str, 103 args: &serde_json::Value, 104 ) -> Result<(), SecurityError> { 105 if let Err(reason) = crate::enforcement::pre_dispatch_check(skill_name, args) { 106 return Err(SecurityError::AccessDenied(reason)); 107 } 108 let payload = args.to_string(); 109 self.check_action(skill_name, &payload).await.map(|_| ()) 110 } 111 }