pub struct PermissionHandler { /* private fields */ }Expand description
Permission handler for tool execution
Combines mode-based checking with settings rules.
The permission checker is shared with the pre_tool_use_hook to ensure that runtime rule changes (e.g., “Always Allow”) are reflected in both places.
Implementations§
Source§impl PermissionHandler
impl PermissionHandler
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new permission handler
Uses Default mode (standard behavior with permission prompts).
Sourcepub fn with_mode(mode: PermissionMode) -> Self
pub fn with_mode(mode: PermissionMode) -> Self
Create with a specific mode
Sourcepub fn with_checker(checker: Arc<RwLock<PermissionChecker>>) -> Self
pub fn with_checker(checker: Arc<RwLock<PermissionChecker>>) -> Self
Create with settings-based checker
Uses Default mode (standard behavior with permission prompts).
Sourcepub fn with_checker_owned(checker: PermissionChecker) -> Self
pub fn with_checker_owned(checker: PermissionChecker) -> Self
Create with settings-based checker (non-async, for convenience)
Uses Default mode (standard behavior with permission prompts).
Sourcepub fn mode(&self) -> PermissionMode
pub fn mode(&self) -> PermissionMode
Get current permission mode
Sourcepub fn set_mode(&mut self, mode: PermissionMode)
pub fn set_mode(&mut self, mode: PermissionMode)
Set permission mode
Sourcepub fn set_checker(&mut self, checker: Arc<RwLock<PermissionChecker>>)
pub fn set_checker(&mut self, checker: Arc<RwLock<PermissionChecker>>)
Set the permission checker
Sourcepub async fn checker_mut(
&mut self,
) -> Option<RwLockWriteGuard<'_, PermissionChecker>>
pub async fn checker_mut( &mut self, ) -> Option<RwLockWriteGuard<'_, PermissionChecker>>
Get mutable reference to checker (for adding runtime rules)
Sourcepub fn should_auto_approve(&self, tool_name: &str, _input: &Value) -> bool
pub fn should_auto_approve(&self, tool_name: &str, _input: &Value) -> bool
Check if a tool operation should be auto-approved
Returns true if the operation should proceed without user prompt.
Note: AcceptEdits mode auto-approves ALL tools (same as BypassPermissions) to maintain compatibility with root user environments while providing full automation capabilities.
Sourcepub fn is_tool_blocked(&self, tool_name: &str) -> bool
pub fn is_tool_blocked(&self, tool_name: &str) -> bool
Check if a tool is blocked in current mode
Sourcepub async fn check_permission(
&self,
tool_name: &str,
tool_input: &Value,
) -> ToolPermissionResult
pub async fn check_permission( &self, tool_name: &str, tool_input: &Value, ) -> ToolPermissionResult
Check permission for a tool with full context
Combines mode-based checking with settings rules. Returns the permission result.
Note: Both BypassPermissions and AcceptEdits modes bypass all permission checks (BypassPermissions for compatibility with non-root environments, AcceptEdits for root user compatibility).
Sourcepub async fn add_allow_rule(&self, tool_name: &str)
pub async fn add_allow_rule(&self, tool_name: &str)
Add a runtime allow rule (e.g., from user’s “Always Allow” choice)
Sourcepub fn add_allow_rule_for_tool_call(&self, tool_name: &str, tool_input: &Value)
pub fn add_allow_rule_for_tool_call(&self, tool_name: &str, tool_input: &Value)
Add a fine-grained allow rule based on tool call details This is used for “Always Allow” with specific parameters
Trait Implementations§
Source§impl Debug for PermissionHandler
impl Debug for PermissionHandler
Auto Trait Implementations§
impl Freeze for PermissionHandler
impl !RefUnwindSafe for PermissionHandler
impl Send for PermissionHandler
impl Sync for PermissionHandler
impl Unpin for PermissionHandler
impl !UnwindSafe for PermissionHandler
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
fn into_maybe_undefined(self) -> MaybeUndefined<T>
Source§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
fn into_option(self) -> Option<T>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request