Skip to main content

ai_agent/utils/permissions/
permission_rule.rs

1// Source: ~/claudecode/openclaudecode/src/utils/permissions/PermissionRule.ts
2#![allow(dead_code)]
3
4//! Permission rule types and schema definitions.
5
6use serde::{Deserialize, Serialize};
7
8// Re-exports for backwards compatibility
9pub use crate::types::permissions::{
10    PermissionBehavior, PermissionRule, PermissionRuleSource, PermissionRuleValue,
11};
12
13/// ToolPermissionBehavior is the behavior associated with a permission rule.
14/// 'allow' means the rule allows the tool to run.
15/// 'deny' means the rule denies the tool from running.
16/// 'ask' means the rule forces a prompt to be shown to the user.
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
18#[serde(rename_all = "lowercase")]
19pub enum PermissionBehaviorSchema {
20    Allow,
21    Deny,
22    Ask,
23}
24
25impl From<PermissionBehavior> for PermissionBehaviorSchema {
26    fn from(behavior: PermissionBehavior) -> Self {
27        match behavior {
28            PermissionBehavior::Allow => PermissionBehaviorSchema::Allow,
29            PermissionBehavior::Deny => PermissionBehaviorSchema::Deny,
30            PermissionBehavior::Ask => PermissionBehaviorSchema::Ask,
31        }
32    }
33}
34
35impl From<PermissionBehaviorSchema> for PermissionBehavior {
36    fn from(schema: PermissionBehaviorSchema) -> Self {
37        match schema {
38            PermissionBehaviorSchema::Allow => PermissionBehavior::Allow,
39            PermissionBehaviorSchema::Deny => PermissionBehavior::Deny,
40            PermissionBehaviorSchema::Ask => PermissionBehavior::Ask,
41        }
42    }
43}