pub mod audit;
pub mod cli;
pub mod config;
pub mod decision;
pub mod engine;
pub mod facts;
pub mod hook_input;
pub mod hook_output;
pub mod init;
pub mod io_runner;
pub mod plugin;
pub mod reason;
pub mod rules;
pub mod self_paths;
pub(crate) mod update;
#[cfg(any(test, feature = "testing"))]
#[doc(hidden)]
pub mod testing;
pub use decision::{Decision, aggregate};
pub use engine::{Engine, EngineError, Outcome};
pub use facts::Facts;
pub use hook_input::HookInput;
pub fn decide(input: &HookInput) -> Decision {
let engine = match Engine::for_cwd() {
Ok(engine) => engine,
Err(_) => match Engine::builder().agent("embed-fallback").build() {
Ok(engine) => engine,
Err(_) => Engine::with_components(config::Config::default(), plugin::PluginSet::new()),
},
};
engine.decide(input).decision
}
pub fn try_decide(input: &HookInput) -> Result<Decision, EngineError> {
let engine = Engine::for_cwd()?;
Ok(engine.decide(input).decision)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::hook_input::sample;
#[test]
fn decide_returns_allow_by_default() {
assert_eq!(decide(&sample("Bash")), Decision::Allow);
assert_eq!(decide(&sample("Read")), Decision::Allow);
}
#[test]
fn try_decide_returns_ok_for_clean_cwd() {
let outcome = try_decide(&sample("Bash"));
assert!(matches!(outcome, Ok(Decision::Allow)));
}
}