#[cfg(feature = "ureq")]
use omega_cognitive_kernel::types::Action;
#[cfg(feature = "ureq")]
use omega_cognitive_kernel::{AuditLog, AuditSummary, Executor, Result, ToolGateExecutor};
#[cfg(feature = "ureq")]
use std::collections::BTreeMap;
#[cfg(feature = "ureq")]
use std::env::temp_dir;
#[cfg(feature = "ureq")]
use std::path::PathBuf;
#[cfg(feature = "ureq")]
fn tool(name: &str) -> Action {
Action {
name: name.into(),
params: BTreeMap::new(),
constraints_checked: true,
}
}
#[cfg(feature = "ureq")]
fn main() -> Result<()> {
let root: PathBuf = temp_dir().join(format!(
"omega-tool-gate-{}",
omega_cognitive_kernel::new_uuid()
));
std::fs::create_dir_all(&root).ok();
let state_marker = root.join("state.json"); let audit = AuditLog::beside_state(&state_marker);
println!("╔══════════════════════════════════════════════════╗");
println!("║ Omega tool-gate — block high-risk tool calls ║");
println!("╚══════════════════════════════════════════════════╝");
println!("audit: {}", audit.path.display());
println!();
let mut gate =
ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
.deny([
"delete_database".into(),
"shell_exec".into(),
"send_wire_transfer".into(),
])
.with_audit(AuditLog {
path: audit.path.clone(),
})
.echo(true)
.fail_closed(false);
let proposals = [
tool("search_docs"),
tool("http_get"),
tool("delete_database"), tool("summarize"),
tool("shell_exec"), tool("unknown_tool"), ];
println!("── model proposed tools ──");
let results = gate.execute(&proposals)?;
for r in &results {
println!(" → {r}");
}
let sum: AuditSummary = AuditLog {
path: audit.path.clone(),
}
.summarize()?;
println!("\n── audit summary ──");
println!(
"events={} tools_allowed={} tools_denied={}",
sum.total_events, sum.tools_allowed, sum.tools_denied
);
for (name, n) in &sum.action_counts {
println!(" {name:<24} {n}");
}
println!("\n── takeaway ──");
println!("1. Proposals come from outside (fake LLM / agent).");
println!("2. ToolGateExecutor allow + deny is the enforcement point.");
println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
let _ = std::fs::remove_dir_all(&root);
Ok(())
}
#[cfg(not(feature = "ureq"))]
fn main() {
eprintln!("This example requires the 'ureq' feature. Run with:");
eprintln!(" cargo run --example tool_gate --features ureq");
std::process::exit(1);
}