Skip to main content

vtcode_core/tools/registry/
shell_policy_facade.rs

1//! Shell policy and agent identity accessors for ToolRegistry.
2
3use anyhow::Result;
4
5use super::ToolRegistry;
6
7impl ToolRegistry {
8    pub fn set_agent_type(&self, agent_type: impl Into<String>) {
9        if let Ok(mut guard) = self.agent_type.write() {
10            *guard = agent_type.into();
11        }
12    }
13
14    pub fn check_shell_policy(
15        &self,
16        command: &str,
17        deny_regex_patterns: &[String],
18        deny_glob_patterns: &[String],
19    ) -> Result<()> {
20        let agent_type = self.agent_type.read().unwrap_or_else(|e| e.into_inner());
21        let mut checker = self
22            .shell_policy
23            .write()
24            .map_err(|e| anyhow::anyhow!("Shell policy lock poisoned: {e}"))?;
25        checker.check_command(
26            command,
27            agent_type.as_str(),
28            deny_regex_patterns,
29            deny_glob_patterns,
30        )
31    }
32}