pub struct PermissionHandler { /* private fields */ }Expand description
A user-supplied async callback invoked when the CLI requests permission to use a tool.
Construct with Self::new, passing an async fn or
async-block closure. Cheap to clone (Arc under the hood).
The handler runs inline on the duplex session’s task. The CLI is
blocked on the response while the handler runs, so awaiting an
async policy check (DB lookup, remote call) is fine. If the
decision needs human input on a different timescale, return
PermissionDecision::Defer and answer via
DuplexSession::respond_to_permission when ready.
Implementations§
Source§impl PermissionHandler
impl PermissionHandler
Sourcepub fn new<F, Fut>(f: F) -> Selfwhere
F: Fn(PermissionRequest) -> Fut + Send + Sync + 'static,
Fut: Future<Output = PermissionDecision> + Send + 'static,
pub fn new<F, Fut>(f: F) -> Selfwhere
F: Fn(PermissionRequest) -> Fut + Send + Sync + 'static,
Fut: Future<Output = PermissionDecision> + Send + 'static,
Wrap an async closure as a permission handler.
§Example
use claude_wrapper::duplex::{PermissionDecision, PermissionHandler};
let _handler = PermissionHandler::new(|req| async move {
if req.tool_name == "Bash" {
PermissionDecision::Deny { message: "no bash".into() }
} else {
PermissionDecision::Allow { updated_input: None }
}
});Trait Implementations§
Source§impl Clone for PermissionHandler
impl Clone for PermissionHandler
Source§fn clone(&self) -> PermissionHandler
fn clone(&self) -> PermissionHandler
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PermissionHandler
impl !RefUnwindSafe for PermissionHandler
impl Send for PermissionHandler
impl Sync for PermissionHandler
impl Unpin for PermissionHandler
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more