Skip to main content

ApprovalRulesManager

Struct ApprovalRulesManager 

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

Manager for approval rules and command history.

Supports both session-only (ephemeral) and persistent rules. Persistent rules are loaded from disk on init and survive across sessions.

Implementations§

Source§

impl ApprovalRulesManager

Source

pub fn new(project_dir: Option<&Path>) -> Self

Create a new manager, loading default danger rules and persistent rules.

Source

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

Read-only access to the current rule set.

Source

pub fn history(&self) -> &[CommandHistory]

Read-only access to command history.

Source

pub fn evaluate_command(&self, command: &str) -> Option<&ApprovalRule>

Evaluate a command against all enabled rules (highest priority first).

Returns the first matching rule, or None if no rule applies.

Source

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

Add a session-only rule.

Source

pub fn update_rule<F>(&mut self, rule_id: &str, updater: F) -> bool
where F: FnOnce(&mut ApprovalRule),

Update fields on an existing rule by ID.

Returns true if a rule was found and updated.

Source

pub fn remove_rule(&mut self, rule_id: &str) -> bool

Remove a rule by ID. Returns true if something was removed.

Source

pub fn add_history( &mut self, command: &str, approved: bool, edited_command: Option<String>, rule_matched: Option<String>, )

Record a command evaluation in the session history.

Source

pub fn add_persistent_rule(&mut self, rule: ApprovalRule, scope: RuleScope)

Add a rule and persist it to disk.

Source

pub fn remove_persistent_rule(&mut self, rule_id: &str) -> bool

Remove a rule and update persistent storage.

Source

pub fn clear_persistent_rules(&mut self, scope: RuleScope) -> usize

Remove all persistent (non-default) rules. Returns count removed.

Source

pub fn list_persistent_rules(&self) -> Vec<Value>

List all non-default rules in a display-friendly format.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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