pub mod allowlist;
pub mod approval;
pub mod ask;
pub mod checker;
pub mod engine;
pub mod path;
pub mod pattern;
pub fn apply_prompt_deny(perm: &Option<checker::PermCheck>, deny: &[String]) {
if let Some(p) = perm {
let mut guard = p.lock_ignore_poison();
guard.set_prompt_deny_tools(deny.to_vec());
}
#[cfg(feature = "experimental-ui-computer-use")]
{
if let Some(pm) = crate::plugin::hook::global() {
let mut mgr = pm.lock_ignore_poison();
mgr.set_deny_tools_for_computer_use(deny);
}
}
}
#[allow(unused_imports)]
use crate::sync_util::LockExt;
use serde::Deserialize;
#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Action {
Allow,
Ask,
Deny,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum OpSpec {
#[default]
#[serde(rename = "*", alias = "any")]
Any,
Read,
Edit,
Execute,
Network,
Mcp,
Memory,
Skill,
Agent,
Meta,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RuleConfig {
#[serde(default)]
pub op: OpSpec,
#[serde(rename = "match")]
pub pattern: String,
pub effect: Action,
#[serde(default)]
pub tool: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PermissionConfig {
#[serde(rename = "*", alias = "default")]
pub default: Option<Action>,
pub doom_loop: Option<Action>,
#[serde(default)]
pub rules: Vec<RuleConfig>,
#[serde(default)]
pub external_directory: Vec<RuleConfig>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SecurityMode {
Standard,
Restrictive,
Accept,
Yolo,
}
impl std::fmt::Display for SecurityMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SecurityMode::Standard => write!(f, "standard"),
SecurityMode::Restrictive => write!(f, "restrictive"),
SecurityMode::Accept => write!(f, "accept"),
SecurityMode::Yolo => write!(f, "yolo"),
}
}
}
pub fn default_bash_rules() -> Vec<(&'static str, Action)> {
vec![
("ls **", Action::Allow),
("cd **", Action::Allow),
("pwd", Action::Allow),
("echo **", Action::Allow),
("which **", Action::Allow),
("type **", Action::Allow),
("cat **", Action::Allow),
("head **", Action::Allow),
("tail **", Action::Allow),
("wc **", Action::Allow),
("sort **", Action::Allow),
("uniq **", Action::Allow),
("cut **", Action::Allow),
("diff **", Action::Allow),
("grep **", Action::Allow),
("rg **", Action::Allow),
("find **", Action::Allow),
("file **", Action::Allow),
("stat **", Action::Allow),
("env", Action::Allow),
("date **", Action::Allow),
("whoami", Action::Allow),
("hostname", Action::Allow),
("export *", Action::Allow),
("set *", Action::Allow),
("unset *", Action::Allow),
("pushd *", Action::Allow),
("popd *", Action::Allow),
(": *", Action::Allow),
("true *", Action::Allow),
("git status **", Action::Allow),
("git log **", Action::Allow),
("git diff **", Action::Allow),
("git show **", Action::Allow),
("git branch **", Action::Allow),
("git add **", Action::Allow),
("git commit **", Action::Allow),
("git pull **", Action::Allow),
("git fetch **", Action::Allow),
("git remote **", Action::Allow),
("git tag **", Action::Allow),
("git blame **", Action::Allow),
("git rev-parse **", Action::Allow),
("git rev-list **", Action::Allow),
("git ls-files **", Action::Allow),
("git config --get **", Action::Allow),
("cargo check **", Action::Allow),
("cargo build **", Action::Allow),
("cargo test **", Action::Allow),
("cargo fmt **", Action::Allow),
("cargo clippy **", Action::Allow),
("cargo run **", Action::Allow),
("cargo doc **", Action::Allow),
("cargo tree **", Action::Allow),
("cargo metadata **", Action::Allow),
("rustc --version", Action::Allow),
("mkdir **", Action::Allow),
("touch **", Action::Allow),
("mv **", Action::Allow),
("cp **", Action::Allow),
("ln **", Action::Allow),
("chmod **", Action::Allow),
("npm test **", Action::Allow),
("npm run **", Action::Allow),
("npm ls **", Action::Allow),
("yarn run **", Action::Allow),
("pnpm run **", Action::Allow),
("pytest **", Action::Allow),
("ruff **", Action::Allow),
("black **", Action::Allow),
("mypy **", Action::Allow),
("pip list **", Action::Allow),
("pip show **", Action::Allow),
("pip freeze", Action::Allow),
("go build **", Action::Allow),
("go test **", Action::Allow),
("go run **", Action::Allow),
("go fmt **", Action::Allow),
("go vet **", Action::Allow),
("go mod **", Action::Allow),
("make **", Action::Allow),
("just **", Action::Allow),
("rm -rf /**", Action::Deny),
("sudo rm -rf /**", Action::Deny),
("dd **", Action::Deny),
("mkfs **", Action::Deny),
("fdisk **", Action::Deny),
("mkswap **", Action::Deny),
]
}