pub struct CompiledPolicy {
pub sandboxes: HashMap<String, SandboxPolicy>,
pub tree: Vec<Node>,
pub default_effect: Effect,
pub default_sandbox: Option<String>,
pub on_sandbox_violation: ViolationAction,
pub harness_defaults: Option<bool>,
}Expand description
A fully compiled match-tree policy, ready for evaluation.
Fields§
§sandboxes: HashMap<String, SandboxPolicy>Named sandbox definitions.
tree: Vec<Node>Root-level children of the tree.
default_effect: EffectDefault effect when no rule matches.
default_sandbox: Option<String>Name of the default sandbox (used by clash shell when no rule-specific sandbox matches).
on_sandbox_violation: ViolationActionWhat the model should do when a sandbox blocks an operation.
harness_defaults: Option<bool>When explicitly set to false, harness default rules are not injected.
None means enabled (default behavior).
Implementations§
Source§impl CompiledPolicy
impl CompiledPolicy
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Return the number of root-level rule branches.
Sourcepub fn format_rules(&self) -> Vec<String>
pub fn format_rules(&self) -> Vec<String>
Format rules as human-readable lines for display (flat, denormalized).
Sourcepub fn format_tree(&self) -> Vec<String>
pub fn format_tree(&self) -> Vec<String>
Format rules as a tree with box-drawing characters.
Sourcepub fn harness_node_count(&self) -> usize
pub fn harness_node_count(&self) -> usize
Count root-level nodes stamped with source “harness”.
Sourcepub fn tree_without_harness(&self) -> Vec<&Node>
pub fn tree_without_harness(&self) -> Vec<&Node>
Return a view of the tree with harness nodes filtered out.
Sourcepub fn format_tree_filtered(&self, include_harness: bool) -> Vec<String>
pub fn format_tree_filtered(&self, include_harness: bool) -> Vec<String>
Format rules as a tree, optionally excluding harness nodes.
Source§impl CompiledPolicy
impl CompiledPolicy
Sourcepub fn evaluate(&self, tool_name: &str, tool_input: &Value) -> PolicyDecision
pub fn evaluate(&self, tool_name: &str, tool_input: &Value) -> PolicyDecision
Evaluate this policy against a tool invocation.
Sourcepub fn evaluate_with_mode(
&self,
tool_name: &str,
tool_input: &Value,
mode: Option<&str>,
) -> PolicyDecision
pub fn evaluate_with_mode( &self, tool_name: &str, tool_input: &Value, mode: Option<&str>, ) -> PolicyDecision
Evaluate this policy with mode and agent context.
Sourcepub fn evaluate_with_context(
&self,
tool_name: &str,
tool_input: &Value,
mode: Option<&str>,
agent_name: Option<&str>,
) -> PolicyDecision
pub fn evaluate_with_context( &self, tool_name: &str, tool_input: &Value, mode: Option<&str>, agent_name: Option<&str>, ) -> PolicyDecision
Evaluate this policy with mode and agent context.
Sourcepub fn find_match_path(
&self,
tool_name: &str,
tool_input: &Value,
) -> Option<Vec<usize>>
pub fn find_match_path( &self, tool_name: &str, tool_input: &Value, ) -> Option<Vec<usize>>
Find the index path through the tree to the first matching decision.
Returns Some(vec![root_idx, child_idx, ...]) if a rule matched,
or None if no rule matched (default effect applies).
Sourcepub fn evaluate_ctx(&self, ctx: &QueryContext) -> PolicyDecision
pub fn evaluate_ctx(&self, ctx: &QueryContext) -> PolicyDecision
Evaluate this policy against a prepared query context.
Sourcepub fn platform_warnings(&self) -> Vec<String>
pub fn platform_warnings(&self) -> Vec<String>
Return platform-specific warnings for sandbox policies.
These are non-fatal: the policy is valid but some rules behave differently on certain platforms.
Trait Implementations§
Source§impl Clone for CompiledPolicy
impl Clone for CompiledPolicy
Source§fn clone(&self) -> CompiledPolicy
fn clone(&self) -> CompiledPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more