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
impl ApprovalRulesManager
Sourcepub fn new(project_dir: Option<&Path>) -> Self
pub fn new(project_dir: Option<&Path>) -> Self
Create a new manager, loading default danger rules and persistent rules.
Sourcepub fn rules(&self) -> &[ApprovalRule]
pub fn rules(&self) -> &[ApprovalRule]
Read-only access to the current rule set.
Sourcepub fn history(&self) -> &[CommandHistory]
pub fn history(&self) -> &[CommandHistory]
Read-only access to command history.
Sourcepub fn evaluate_command(&self, command: &str) -> Option<&ApprovalRule>
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.
Sourcepub fn add_rule(&mut self, rule: ApprovalRule)
pub fn add_rule(&mut self, rule: ApprovalRule)
Add a session-only rule.
Sourcepub fn update_rule<F>(&mut self, rule_id: &str, updater: F) -> boolwhere
F: FnOnce(&mut ApprovalRule),
pub fn update_rule<F>(&mut self, rule_id: &str, updater: F) -> boolwhere
F: FnOnce(&mut ApprovalRule),
Update fields on an existing rule by ID.
Returns true if a rule was found and updated.
Sourcepub fn remove_rule(&mut self, rule_id: &str) -> bool
pub fn remove_rule(&mut self, rule_id: &str) -> bool
Remove a rule by ID. Returns true if something was removed.
Sourcepub fn add_history(
&mut self,
command: &str,
approved: bool,
edited_command: Option<String>,
rule_matched: Option<String>,
)
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.
Sourcepub fn add_persistent_rule(&mut self, rule: ApprovalRule, scope: RuleScope)
pub fn add_persistent_rule(&mut self, rule: ApprovalRule, scope: RuleScope)
Add a rule and persist it to disk.
Sourcepub fn remove_persistent_rule(&mut self, rule_id: &str) -> bool
pub fn remove_persistent_rule(&mut self, rule_id: &str) -> bool
Remove a rule and update persistent storage.
Sourcepub fn clear_persistent_rules(&mut self, scope: RuleScope) -> usize
pub fn clear_persistent_rules(&mut self, scope: RuleScope) -> usize
Remove all persistent (non-default) rules. Returns count removed.
Sourcepub fn list_persistent_rules(&self) -> Vec<Value>
pub fn list_persistent_rules(&self) -> Vec<Value>
List all non-default rules in a display-friendly format.