pub struct ToolGateExecutor { /* private fields */ }Expand description
Tool-call gate: allow-list + deny-list, optional audit, optional real http_get.
Denied tools never touch the network. When enable_http_get is true and the
tool name is http_get on the allow-list, a GET is performed (response truncated).
Implementations§
Source§impl ToolGateExecutor
impl ToolGateExecutor
Sourcepub fn new(allowed: impl IntoIterator<Item = String>) -> Self
pub fn new(allowed: impl IntoIterator<Item = String>) -> Self
Examples found in repository?
examples/tool_gate.rs (line 45)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-gate-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json"); // audit lives beside this path
35 let audit = AuditLog::beside_state(&state_marker);
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Omega tool-gate — block high-risk tool calls ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit.path.display());
41 println!();
42
43 // Safe tools an agent may call; dangerous names explicitly denied.
44 let mut gate =
45 ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
46 .deny([
47 "delete_database".into(),
48 "shell_exec".into(),
49 "send_wire_transfer".into(),
50 ])
51 .with_audit(AuditLog {
52 path: audit.path.clone(),
53 })
54 .echo(true)
55 .fail_closed(false); // continue batch after deny so demo shows mixed outcomes
56
57 // Simulated model proposals (not from DecisionMaker — host/agent layer).
58 let proposals = [
59 tool("search_docs"),
60 tool("http_get"),
61 tool("delete_database"), // should DENY
62 tool("summarize"),
63 tool("shell_exec"), // should DENY
64 tool("unknown_tool"), // not on allow-list → DENY
65 ];
66
67 println!("── model proposed tools ──");
68 let results = gate.execute(&proposals)?;
69 for r in &results {
70 println!(" → {r}");
71 }
72
73 let sum: AuditSummary = AuditLog {
74 path: audit.path.clone(),
75 }
76 .summarize()?;
77 println!("\n── audit summary ──");
78 println!(
79 "events={} tools_allowed={} tools_denied={}",
80 sum.total_events, sum.tools_allowed, sum.tools_denied
81 );
82 for (name, n) in &sum.action_counts {
83 println!(" {name:<24} {n}");
84 }
85
86 println!("\n── takeaway ──");
87 println!("1. Proposals come from outside (fake LLM / agent).");
88 println!("2. ToolGateExecutor allow + deny is the enforcement point.");
89 println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
90 println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
91
92 let _ = std::fs::remove_dir_all(&root);
93 Ok(())
94}More examples
examples/tool_gate_http.rs (line 43)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Sourcepub fn deny(self, names: impl IntoIterator<Item = String>) -> Self
pub fn deny(self, names: impl IntoIterator<Item = String>) -> Self
Examples found in repository?
examples/tool_gate.rs (lines 46-50)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-gate-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json"); // audit lives beside this path
35 let audit = AuditLog::beside_state(&state_marker);
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Omega tool-gate — block high-risk tool calls ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit.path.display());
41 println!();
42
43 // Safe tools an agent may call; dangerous names explicitly denied.
44 let mut gate =
45 ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
46 .deny([
47 "delete_database".into(),
48 "shell_exec".into(),
49 "send_wire_transfer".into(),
50 ])
51 .with_audit(AuditLog {
52 path: audit.path.clone(),
53 })
54 .echo(true)
55 .fail_closed(false); // continue batch after deny so demo shows mixed outcomes
56
57 // Simulated model proposals (not from DecisionMaker — host/agent layer).
58 let proposals = [
59 tool("search_docs"),
60 tool("http_get"),
61 tool("delete_database"), // should DENY
62 tool("summarize"),
63 tool("shell_exec"), // should DENY
64 tool("unknown_tool"), // not on allow-list → DENY
65 ];
66
67 println!("── model proposed tools ──");
68 let results = gate.execute(&proposals)?;
69 for r in &results {
70 println!(" → {r}");
71 }
72
73 let sum: AuditSummary = AuditLog {
74 path: audit.path.clone(),
75 }
76 .summarize()?;
77 println!("\n── audit summary ──");
78 println!(
79 "events={} tools_allowed={} tools_denied={}",
80 sum.total_events, sum.tools_allowed, sum.tools_denied
81 );
82 for (name, n) in &sum.action_counts {
83 println!(" {name:<24} {n}");
84 }
85
86 println!("\n── takeaway ──");
87 println!("1. Proposals come from outside (fake LLM / agent).");
88 println!("2. ToolGateExecutor allow + deny is the enforcement point.");
89 println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
90 println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
91
92 let _ = std::fs::remove_dir_all(&root);
93 Ok(())
94}More examples
examples/tool_gate_http.rs (lines 44-48)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Sourcepub fn with_audit(self, log: AuditLog) -> Self
pub fn with_audit(self, log: AuditLog) -> Self
Examples found in repository?
examples/tool_gate.rs (lines 51-53)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-gate-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json"); // audit lives beside this path
35 let audit = AuditLog::beside_state(&state_marker);
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Omega tool-gate — block high-risk tool calls ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit.path.display());
41 println!();
42
43 // Safe tools an agent may call; dangerous names explicitly denied.
44 let mut gate =
45 ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
46 .deny([
47 "delete_database".into(),
48 "shell_exec".into(),
49 "send_wire_transfer".into(),
50 ])
51 .with_audit(AuditLog {
52 path: audit.path.clone(),
53 })
54 .echo(true)
55 .fail_closed(false); // continue batch after deny so demo shows mixed outcomes
56
57 // Simulated model proposals (not from DecisionMaker — host/agent layer).
58 let proposals = [
59 tool("search_docs"),
60 tool("http_get"),
61 tool("delete_database"), // should DENY
62 tool("summarize"),
63 tool("shell_exec"), // should DENY
64 tool("unknown_tool"), // not on allow-list → DENY
65 ];
66
67 println!("── model proposed tools ──");
68 let results = gate.execute(&proposals)?;
69 for r in &results {
70 println!(" → {r}");
71 }
72
73 let sum: AuditSummary = AuditLog {
74 path: audit.path.clone(),
75 }
76 .summarize()?;
77 println!("\n── audit summary ──");
78 println!(
79 "events={} tools_allowed={} tools_denied={}",
80 sum.total_events, sum.tools_allowed, sum.tools_denied
81 );
82 for (name, n) in &sum.action_counts {
83 println!(" {name:<24} {n}");
84 }
85
86 println!("\n── takeaway ──");
87 println!("1. Proposals come from outside (fake LLM / agent).");
88 println!("2. ToolGateExecutor allow + deny is the enforcement point.");
89 println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
90 println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
91
92 let _ = std::fs::remove_dir_all(&root);
93 Ok(())
94}More examples
examples/tool_gate_http.rs (lines 49-51)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Sourcepub fn echo(self, on: bool) -> Self
pub fn echo(self, on: bool) -> Self
Examples found in repository?
examples/tool_gate.rs (line 54)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-gate-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json"); // audit lives beside this path
35 let audit = AuditLog::beside_state(&state_marker);
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Omega tool-gate — block high-risk tool calls ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit.path.display());
41 println!();
42
43 // Safe tools an agent may call; dangerous names explicitly denied.
44 let mut gate =
45 ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
46 .deny([
47 "delete_database".into(),
48 "shell_exec".into(),
49 "send_wire_transfer".into(),
50 ])
51 .with_audit(AuditLog {
52 path: audit.path.clone(),
53 })
54 .echo(true)
55 .fail_closed(false); // continue batch after deny so demo shows mixed outcomes
56
57 // Simulated model proposals (not from DecisionMaker — host/agent layer).
58 let proposals = [
59 tool("search_docs"),
60 tool("http_get"),
61 tool("delete_database"), // should DENY
62 tool("summarize"),
63 tool("shell_exec"), // should DENY
64 tool("unknown_tool"), // not on allow-list → DENY
65 ];
66
67 println!("── model proposed tools ──");
68 let results = gate.execute(&proposals)?;
69 for r in &results {
70 println!(" → {r}");
71 }
72
73 let sum: AuditSummary = AuditLog {
74 path: audit.path.clone(),
75 }
76 .summarize()?;
77 println!("\n── audit summary ──");
78 println!(
79 "events={} tools_allowed={} tools_denied={}",
80 sum.total_events, sum.tools_allowed, sum.tools_denied
81 );
82 for (name, n) in &sum.action_counts {
83 println!(" {name:<24} {n}");
84 }
85
86 println!("\n── takeaway ──");
87 println!("1. Proposals come from outside (fake LLM / agent).");
88 println!("2. ToolGateExecutor allow + deny is the enforcement point.");
89 println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
90 println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
91
92 let _ = std::fs::remove_dir_all(&root);
93 Ok(())
94}More examples
examples/tool_gate_http.rs (line 54)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Sourcepub fn fail_closed(self, on: bool) -> Self
pub fn fail_closed(self, on: bool) -> Self
Examples found in repository?
examples/tool_gate.rs (line 55)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-gate-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json"); // audit lives beside this path
35 let audit = AuditLog::beside_state(&state_marker);
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Omega tool-gate — block high-risk tool calls ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit.path.display());
41 println!();
42
43 // Safe tools an agent may call; dangerous names explicitly denied.
44 let mut gate =
45 ToolGateExecutor::new(["search_docs".into(), "http_get".into(), "summarize".into()])
46 .deny([
47 "delete_database".into(),
48 "shell_exec".into(),
49 "send_wire_transfer".into(),
50 ])
51 .with_audit(AuditLog {
52 path: audit.path.clone(),
53 })
54 .echo(true)
55 .fail_closed(false); // continue batch after deny so demo shows mixed outcomes
56
57 // Simulated model proposals (not from DecisionMaker — host/agent layer).
58 let proposals = [
59 tool("search_docs"),
60 tool("http_get"),
61 tool("delete_database"), // should DENY
62 tool("summarize"),
63 tool("shell_exec"), // should DENY
64 tool("unknown_tool"), // not on allow-list → DENY
65 ];
66
67 println!("── model proposed tools ──");
68 let results = gate.execute(&proposals)?;
69 for r in &results {
70 println!(" → {r}");
71 }
72
73 let sum: AuditSummary = AuditLog {
74 path: audit.path.clone(),
75 }
76 .summarize()?;
77 println!("\n── audit summary ──");
78 println!(
79 "events={} tools_allowed={} tools_denied={}",
80 sum.total_events, sum.tools_allowed, sum.tools_denied
81 );
82 for (name, n) in &sum.action_counts {
83 println!(" {name:<24} {n}");
84 }
85
86 println!("\n── takeaway ──");
87 println!("1. Proposals come from outside (fake LLM / agent).");
88 println!("2. ToolGateExecutor allow + deny is the enforcement point.");
89 println!("3. Denies are auditable (ToolDenied) — no side effects executed.");
90 println!("4. Next engineering step: wire real HTTP tools only on ALLOW path.");
91
92 let _ = std::fs::remove_dir_all(&root);
93 Ok(())
94}More examples
examples/tool_gate_http.rs (line 53)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Sourcepub fn enable_http_get(self, on: bool) -> Self
pub fn enable_http_get(self, on: bool) -> Self
Enable real HTTP GET for tool name http_get after allow-list pass.
Examples found in repository?
examples/tool_gate_http.rs (line 52)
28fn main() -> Result<()> {
29 let root: PathBuf = temp_dir().join(format!(
30 "omega-tool-http-{}",
31 omega_cognitive_kernel::new_uuid()
32 ));
33 std::fs::create_dir_all(&root).ok();
34 let state_marker = root.join("state.json");
35 let audit_path = AuditLog::beside_state(&state_marker).path;
36
37 println!("╔══════════════════════════════════════════════════╗");
38 println!("║ Tool gate + real http_get (GET only) ║");
39 println!("╚══════════════════════════════════════════════════╝");
40 println!("audit: {}", audit_path.display());
41 println!();
42
43 let mut gate = ToolGateExecutor::new(["http_get".into(), "search_docs".into()])
44 .deny([
45 "delete_database".into(),
46 "shell_exec".into(),
47 "http_post".into(), // POST not implemented — deny by policy
48 ])
49 .with_audit(AuditLog {
50 path: audit_path.clone(),
51 })
52 .enable_http_get(true)
53 .fail_closed(false)
54 .echo(true);
55
56 // Public, stable endpoint (example.com).
57 let proposals = [
58 tool("http_get", Some("https://example.com")),
59 tool("delete_database", None), // DENY — no network
60 tool("search_docs", None), // ALLOW simulated
61 tool("http_get", Some("file:///etc/passwd")), // should fail scheme check if reached
62 ];
63
64 println!("── proposals ──");
65 // Run one-by-one so a scheme error on last doesn't hide earlier results.
66 for p in &proposals {
67 match gate.execute(std::slice::from_ref(p)) {
68 Ok(rows) => {
69 for r in rows {
70 let status = r.get("status").and_then(|v| v.as_str()).unwrap_or("?");
71 let action = r.get("action").and_then(|v| v.as_str()).unwrap_or("?");
72 if status == "ok" && r.get("http_status").is_some() {
73 println!(
74 " OK {action} http={} truncated={:?} preview_len={}",
75 r["http_status"],
76 r.get("truncated"),
77 r.get("body_preview")
78 .and_then(|v| v.as_str())
79 .map(|s| s.len())
80 .unwrap_or(0)
81 );
82 } else {
83 println!(" {status} {action} {r}");
84 }
85 }
86 }
87 Err(e) => println!(" ERR {e}"),
88 }
89 }
90
91 let sum = AuditLog {
92 path: audit_path.clone(),
93 }
94 .summarize()?;
95 println!("\n── audit ──");
96 println!(
97 "allowed={} denied={} events={}",
98 sum.tools_allowed, sum.tools_denied, sum.total_events
99 );
100
101 println!("\n── takeaway ──");
102 println!("1. DENY paths never open sockets.");
103 println!("2. ALLOW http_get can perform a real GET (truncated body).");
104 println!("3. Still not a full LLM proxy — one read-only tool behind the gate.");
105
106 let _ = std::fs::remove_dir_all(&root);
107 Ok(())
108}Trait Implementations§
Auto Trait Implementations§
impl Forget for ToolGateExecutor
impl Freeze for ToolGateExecutor
impl Move for ToolGateExecutor
impl RefUnwindSafe for ToolGateExecutor
impl Send for ToolGateExecutor
impl Sync for ToolGateExecutor
impl Unpin for ToolGateExecutor
impl UnsafeUnpin for ToolGateExecutor
impl UnwindSafe for ToolGateExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more