Skip to main content

GovernanceEngine

Struct GovernanceEngine 

Source
pub struct GovernanceEngine { /* private fields */ }
Expand description

Governance engine.

Evaluates actions against governance rules and the environment’s risk threshold. Without the governance feature gate, all evaluations return Permit.

Evaluation requests are rate-limited per principal (WEFT-148) to stop flood/DoS against the governance path. Defaults are generous enough for normal agent tool loops; configure via GovernanceEngine::with_eval_rate_limit.

Implementations§

Source§

impl GovernanceEngine

Source

pub fn new(risk_threshold: f64, human_approval_required: bool) -> Self

Create a governance engine with the given risk threshold.

Source

pub fn open() -> Self

Create an open governance engine that permits everything.

Still rate-limits evaluations per principal by default so an open policy cannot be used as a free DoS amplifier.

Source

pub fn with_eval_rate_limit(self, config: RateLimitConfig) -> Self

Configure the per-principal evaluation rate limit (WEFT-148).

RateLimitConfig::unlimited() disables enforcement (tests).

Source

pub fn set_eval_rate_limit(&self, config: RateLimitConfig)

Replace the evaluation rate-limit configuration in place.

Source

pub fn eval_rate_limit(&self) -> RateLimitConfig

Current evaluation rate-limit configuration.

Source

pub fn eval_principal_key(request: &GovernanceRequest) -> &str

Resolve the principal key used for evaluation rate limiting.

Prefers non-empty agent_id; then explicit principal’s agent/user; falls back to node_id.

Source

pub fn with_scorer(self, scorer: GovernanceScorerModel) -> Self

Install a learned GovernanceScorerModel.

With a scorer installed, evaluate uses EffectVector::score which delegates to the model when trained and falls back to the L2 magnitude otherwise. The fallback path is bit-for-bit identical to the pre-EML behaviour.

Source

pub fn scorer(&self) -> Option<&GovernanceScorerModel>

Returns a reference to the installed governance scorer model, if any.

Source

pub fn add_rule(&mut self, rule: GovernanceRule)

Add a governance rule.

Source

pub fn rules(&self) -> &[GovernanceRule]

Every rule, active or not, in insertion order.

Source

pub fn human_approval_required(&self) -> bool

Whether blocking verdicts escalate to a human instead of denying.

Source

pub fn active_rules(&self) -> Vec<&GovernanceRule>

Get all active rules.

Source

pub fn rules_by_branch(&self, branch: &GovernanceBranch) -> Vec<&GovernanceRule>

Get rules by branch.

Source

pub fn evaluate(&self, request: &GovernanceRequest) -> GovernanceResult

Evaluate a governance request.

Decision logic: 0. Rate limit (WEFT-148): if the principal has exceeded the configured evaluation quota, return Deny("rate limited: …") without scoring rules.

  1. If any active GovernanceRuleType::BrowserPolicy rule denies the action (platform-aware; independent of effect magnitude), deny.
  2. If any active GovernanceRuleType::BindingThread rule denies the action (WEFT-342; independent of magnitude), deny with binding-thread mismatch.
  3. Action/tool selectors (WEFT-634): General rules whose selectors do not match the request are skipped (still listed in evaluated_rules only when they match — non-matching rules are not counted as evaluated for the verdict).
  4. If any blocking/critical rule applies and (magnitude exceeds threshold or force_on_match), deny (or escalate when human approval is required).
  5. If any warning rule applies and magnitude exceeds threshold, permit with warning.
  6. Otherwise permit.

NOTE(eml-swap): wired — Finding #5 (GovernanceScorerModel). The scalar fed into the threshold check is produced by EffectVector::score, which consults the engine’s optional scorer and falls back to the L2 magnitude when no model is installed or the model is untrained.

Source

pub fn browser_policy_rules(&self) -> Vec<&GovernanceRule>

Active browser_policy rules only.

Source

pub fn binding_thread_rules(&self) -> Vec<&GovernanceRule>

Active binding-thread integrity rules only (WEFT-342).

Source

pub fn risk_threshold(&self) -> f64

Get the configured risk threshold.

Source

pub fn rule_count(&self) -> usize

Get total rule count.

Source

pub fn evaluate_in_environment( &self, request: &GovernanceRequest, env: &Environment, ) -> GovernanceResult

Evaluate a governance request in the context of a specific environment.

Different environment classes apply different risk thresholds:

  • Development: uses the environment’s own risk_threshold (lenient, typically 0.9).
  • Staging: uses the environment’s own risk_threshold (moderate, typically 0.6).
  • Production: uses half the environment’s risk_threshold (strict, typically 0.15).
  • Custom: uses the custom class’s risk_threshold directly.

After normal rule evaluation, an additional effect-magnitude check is performed against the environment-adjusted threshold. If the magnitude exceeds it, the decision is overridden to Deny.

Source

pub fn evaluate_logged( &self, request: &GovernanceRequest, chain: Option<&ChainManager>, ) -> GovernanceResult

Evaluate a governance request and log the decision to the chain.

This is the recommended entry point when a ChainManager is available. It calls evaluate and records an ipc.dead_letter-style audit event via [ChainLoggable].

If no chain manager is provided, behaves identically to evaluate.

Source

pub fn evaluate_in_environment_logged( &self, request: &GovernanceRequest, env: &Environment, chain: Option<&ChainManager>, ) -> GovernanceResult

Evaluate in an environment and log the decision to the chain.

Source

pub fn chain_log_result( cm: &ChainManager, request: &GovernanceRequest, result: &GovernanceResult, )

Log a governance result to the ExoChain.

Can be called after any evaluate / evaluate_in_environment call to record the decision in the audit trail.

Source§

impl GovernanceEngine

Source

pub fn to_rvf_mode(&self) -> GovernanceMode

Derive the equivalent RVF GovernanceMode from this engine’s config.

  • risk_threshold >= 1.0 (open) → Autonomous
  • human_approval_required → Approved
  • otherwise → Restricted
Source

pub fn to_rvf_policy(&self) -> GovernancePolicy

Build an RVF GovernancePolicy from this engine’s configuration.

Uses the default tool lists and cost budgets for each mode. Callers can customize the returned policy further if needed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more