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
impl GovernanceEngine
Sourcepub fn new(risk_threshold: f64, human_approval_required: bool) -> Self
pub fn new(risk_threshold: f64, human_approval_required: bool) -> Self
Create a governance engine with the given risk threshold.
Sourcepub fn open() -> Self
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.
Sourcepub fn with_eval_rate_limit(self, config: RateLimitConfig) -> Self
pub fn with_eval_rate_limit(self, config: RateLimitConfig) -> Self
Configure the per-principal evaluation rate limit (WEFT-148).
RateLimitConfig::unlimited() disables enforcement (tests).
Sourcepub fn set_eval_rate_limit(&self, config: RateLimitConfig)
pub fn set_eval_rate_limit(&self, config: RateLimitConfig)
Replace the evaluation rate-limit configuration in place.
Sourcepub fn eval_rate_limit(&self) -> RateLimitConfig
pub fn eval_rate_limit(&self) -> RateLimitConfig
Current evaluation rate-limit configuration.
Sourcepub fn eval_principal_key(request: &GovernanceRequest) -> &str
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.
Sourcepub fn with_scorer(self, scorer: GovernanceScorerModel) -> Self
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.
Sourcepub fn scorer(&self) -> Option<&GovernanceScorerModel>
pub fn scorer(&self) -> Option<&GovernanceScorerModel>
Returns a reference to the installed governance scorer model, if any.
Sourcepub fn add_rule(&mut self, rule: GovernanceRule)
pub fn add_rule(&mut self, rule: GovernanceRule)
Add a governance rule.
Sourcepub fn rules(&self) -> &[GovernanceRule]
pub fn rules(&self) -> &[GovernanceRule]
Every rule, active or not, in insertion order.
Sourcepub fn human_approval_required(&self) -> bool
pub fn human_approval_required(&self) -> bool
Whether blocking verdicts escalate to a human instead of denying.
Sourcepub fn active_rules(&self) -> Vec<&GovernanceRule>
pub fn active_rules(&self) -> Vec<&GovernanceRule>
Get all active rules.
Sourcepub fn rules_by_branch(&self, branch: &GovernanceBranch) -> Vec<&GovernanceRule>
pub fn rules_by_branch(&self, branch: &GovernanceBranch) -> Vec<&GovernanceRule>
Get rules by branch.
Sourcepub fn evaluate(&self, request: &GovernanceRequest) -> GovernanceResult
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.
- If any active
GovernanceRuleType::BrowserPolicyrule denies the action (platform-aware; independent of effect magnitude), deny. - If any active
GovernanceRuleType::BindingThreadrule denies the action (WEFT-342; independent of magnitude), deny withbinding-thread mismatch. - Action/tool selectors (WEFT-634): General rules whose selectors
do not match the request are skipped (still listed in
evaluated_rulesonly when they match — non-matching rules are not counted as evaluated for the verdict). - If any blocking/critical rule applies and (magnitude exceeds
threshold or
force_on_match), deny (or escalate when human approval is required). - If any warning rule applies and magnitude exceeds threshold, permit with warning.
- 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.
Sourcepub fn browser_policy_rules(&self) -> Vec<&GovernanceRule>
pub fn browser_policy_rules(&self) -> Vec<&GovernanceRule>
Active browser_policy rules only.
Sourcepub fn binding_thread_rules(&self) -> Vec<&GovernanceRule>
pub fn binding_thread_rules(&self) -> Vec<&GovernanceRule>
Active binding-thread integrity rules only (WEFT-342).
Sourcepub fn risk_threshold(&self) -> f64
pub fn risk_threshold(&self) -> f64
Get the configured risk threshold.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Get total rule count.
Sourcepub fn evaluate_in_environment(
&self,
request: &GovernanceRequest,
env: &Environment,
) -> GovernanceResult
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_thresholddirectly.
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.
Sourcepub fn evaluate_logged(
&self,
request: &GovernanceRequest,
chain: Option<&ChainManager>,
) -> GovernanceResult
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.
Sourcepub fn evaluate_in_environment_logged(
&self,
request: &GovernanceRequest,
env: &Environment,
chain: Option<&ChainManager>,
) -> GovernanceResult
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.
Sourcepub fn chain_log_result(
cm: &ChainManager,
request: &GovernanceRequest,
result: &GovernanceResult,
)
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
impl GovernanceEngine
Sourcepub fn to_rvf_mode(&self) -> GovernanceMode
pub fn to_rvf_mode(&self) -> GovernanceMode
Derive the equivalent RVF GovernanceMode from this engine’s config.
risk_threshold >= 1.0(open) →Autonomoushuman_approval_required→Approved- otherwise →
Restricted
Sourcepub fn to_rvf_policy(&self) -> GovernancePolicy
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§
impl !Freeze for GovernanceEngine
impl RefUnwindSafe for GovernanceEngine
impl Send for GovernanceEngine
impl Sync for GovernanceEngine
impl Unpin for GovernanceEngine
impl UnsafeUnpin for GovernanceEngine
impl UnwindSafe for GovernanceEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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