Skip to main content

ToolGateExecutor

Struct ToolGateExecutor 

Source
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

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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§

Source§

impl Executor for ToolGateExecutor

Available on crate feature std only.
Source§

fn execute(&mut self, actions: &[Action]) -> Result<Vec<Value>>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.