pub struct PolicyEngine { /* private fields */ }Expand description
The policy engine evaluates actions against both the constitution and the policy rule set.
Implementations§
Source§impl PolicyEngine
impl PolicyEngine
Sourcepub fn new(
constitution: Constitution,
rules_dir: &Path,
patterns_dir: &Path,
) -> Self
pub fn new( constitution: Constitution, rules_dir: &Path, patterns_dir: &Path, ) -> Self
Create a new policy engine from a constitution and a rules directory.
Sourcepub fn with_rules(
constitution: Constitution,
rules: PolicyRuleSet,
patterns_dir: &Path,
) -> Self
pub fn with_rules( constitution: Constitution, rules: PolicyRuleSet, patterns_dir: &Path, ) -> Self
Create a policy engine with an explicit rule set (for testing).
Sourcepub fn evaluate(&self, action: &Action) -> ActionDecision
pub fn evaluate(&self, action: &Action) -> ActionDecision
Evaluate an action against the constitution and policy rules.
Decision priority:
- Constitution forbidden → Blocked (always wins)
- Policy rules can downgrade (block or require approval) but cannot
upgrade a constitution
NeedsApprovaltoAllowed. - Constitution requires_approval / auto_allowed
- Default: NeedsApproval
Sourcepub fn evaluate_with_context(
&self,
action: &Action,
workflow_id: Option<&str>,
estimated_cost: Option<f64>,
) -> ActionDecision
pub fn evaluate_with_context( &self, action: &Action, workflow_id: Option<&str>, estimated_cost: Option<f64>, ) -> ActionDecision
Evaluate an action with workflow context.
Sourcepub fn get_pattern_context(
&self,
action_type: &str,
action_command: &str,
) -> Result<Option<String>>
pub fn get_pattern_context( &self, action_type: &str, action_command: &str, ) -> Result<Option<String>>
Get pattern context for an action (for AI model injection).
Sourcepub fn rules(&self) -> &PolicyRuleSet
pub fn rules(&self) -> &PolicyRuleSet
Get a reference to the current rule set.
Sourcepub fn rules_mut(&mut self) -> &mut PolicyRuleSet
pub fn rules_mut(&mut self) -> &mut PolicyRuleSet
Get a mutable reference to the current rule set.
Sourcepub fn save_rules(&self) -> Result<()>
pub fn save_rules(&self) -> Result<()>
Save the current rules back to the rules directory.
Sourcepub fn reload_rules(&mut self)
pub fn reload_rules(&mut self)
Reload rules from the rules directory.
Sourcepub fn constitution(&self) -> &Constitution
pub fn constitution(&self) -> &Constitution
Get a reference to the constitution.
Sourcepub fn pattern_store(&self) -> &PatternStore
pub fn pattern_store(&self) -> &PatternStore
Get a reference to the pattern store.
Auto Trait Implementations§
impl !Freeze for PolicyEngine
impl RefUnwindSafe for PolicyEngine
impl Send for PolicyEngine
impl Sync for PolicyEngine
impl Unpin for PolicyEngine
impl UnsafeUnpin for PolicyEngine
impl UnwindSafe for PolicyEngine
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
Mutably borrows from an owned value. Read more