Skip to main content

rhema_agent_tools/
approval.rs

1//! The approval seam: a per-turn hook that gates the side-effecting tools.
2//!
3//! The hook travels as an `Arc` because the resolver that consults it is
4//! owned by the engine's `Agent` and must stay `'static` — a plain `&dyn`
5//! borrow cannot be installed into it. It is installed before a turn and
6//! cleared after; tool resolution is synchronous within a turn, so the
7//! per-turn swap is race-free.
8
9use rhema_core::ToolCall;
10
11/// Decides whether a gated tool call (`bash`) may run.
12/// Called once per gated call, before execution.
13pub trait Approval: Send + Sync {
14    /// Return `true` to let the tool run.
15    fn approve(&self, call: &ToolCall) -> bool;
16}
17
18/// Approves everything; used by non-interactive drivers and tests.
19#[derive(Debug, Clone, Copy, Default)]
20pub struct AllowAll;
21
22impl Approval for AllowAll {
23    fn approve(&self, _call: &ToolCall) -> bool {
24        true
25    }
26}
27
28/// Rejects every gated call: the headless default, where nobody is
29/// present to approve. Pair with an explicit opt-in to run tools
30/// unattended.
31#[derive(Debug, Clone, Copy, Default)]
32pub struct DenyAll;
33
34impl Approval for DenyAll {
35    fn approve(&self, _call: &ToolCall) -> bool {
36        false
37    }
38}