Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(mcp): route repl tool calls through the approval gate

Steven Enamakel1b0b00ed261c
diff --git a/crates/openhuman-core/src/inference/tokenjuice/repl_tools.rs b/crates/openhuman-core/src/inference/tokenjuice/repl_tools.rs
index e4bbfd3b23..a9c9096167 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/repl_tools.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/repl_tools.rs
@@ -32,8 +32,11 @@ const RELATIVE_ARTIFACT_PREFIX: &str = "artifacts/tool-results/";
pub(crate) trait QuerySource: Send + Sync {
/// `ctx` is the context the calling tool runs under; a source bound to a
/// config of its own ignores it.
- async fn query(&self, ctx: &DispatchCtx, request: QueryRequest)
- -> Result<QueryResponse, String>;
+ async fn query(
+ &self,
+ ctx: &DispatchCtx,
+ request: QueryRequest,
+ ) -> Result<QueryResponse, String>;
}
struct ModuleSource {
@@ -268,11 +271,11 @@ impl ModuleReplTool {
.query(
ctx,
QueryRequest {
- target,
- op,
- limits: self.limits,
- context_token: None,
- scope: None,
+ target,
+ op,
+ limits: self.limits,
+ context_token: None,
+ scope: None,
},
)
.await;
@@ -307,11 +310,10 @@ impl ModuleReplTool {
);
return Ok(ToolResult::error(not_a_handle_message()));
};
- let read = ctx.spawn_blocking(move || {
- read_tool_result_artifact(&dir, &path, MAX_ARTIFACT_BYTES)
- })
- .await
- .map_err(|e| anyhow::anyhow!("juice: artifact read task failed: {e}"))?;
+ let read = ctx
+ .spawn_blocking(move || read_tool_result_artifact(&dir, &path, MAX_ARTIFACT_BYTES))
+ .await
+ .map_err(|e| anyhow::anyhow!("juice: artifact read task failed: {e}"))?;
match read {
Ok(content) => {
log::debug!(
@@ -319,7 +321,8 @@ impl ModuleReplTool {
self.name,
content.len()
);
- self.run_query(QueryTarget::Content { content }, args).await
+ self.run_query(ctx, QueryTarget::Content { content }, args)
+ .await
}
Err(message) => {
log::debug!("[tokenjuice][repl] {} artifact refused", self.name);
@@ -354,14 +357,15 @@ impl Tool for ModuleReplTool {
_options: ToolCallOptions,
tool_context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
- let ctx =
- crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
let Some(raw) = args.get("handle").and_then(Value::as_str) else {
return Ok(ToolResult::error("missing required argument: handle"));
};
let handle = match handle::classify(raw) {
handle::HandleArg::Handle(handle) => handle,
- handle::HandleArg::Path(path) => return self.execute_on_artifact(&ctx, path, args).await,
+ handle::HandleArg::Path(path) => {
+ return self.execute_on_artifact(&ctx, path, args).await
+ }
handle::HandleArg::Invalid => {
log::debug!("[tokenjuice][repl] {} rejected a non-handle", self.name);
return Ok(ToolResult::error(not_a_handle_message()));
diff --git a/crates/openhuman-core/src/mcp/ui/tools.rs b/crates/openhuman-core/src/mcp/ui/tools.rs
index aedbd85a37..cc6ce81575 100644
--- a/crates/openhuman-core/src/mcp/ui/tools.rs
+++ b/crates/openhuman-core/src/mcp/ui/tools.rs
@@ -10,9 +10,7 @@ use std::path::{Component, Path, PathBuf};
use async_trait::async_trait;
use serde_json::{json, Value};
-use tinytools::{
- PermissionLevel, Tool, ToolCallOptions, ToolExposure, ToolResult, ToolRunContext,
-};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolExposure, ToolResult, ToolRunContext};
use super::cache::{self, InlineEntry};
use super::resolve::{MAX_RESOURCE_BYTES, MAX_STRUCTURED_BYTES};
diff --git a/crates/openhuman-core/src/mcp/ui/tools_tests.rs b/crates/openhuman-core/src/mcp/ui/tools_tests.rs
index 99d71f2573..c05d737664 100644
--- a/crates/openhuman-core/src/mcp/ui/tools_tests.rs
+++ b/crates/openhuman-core/src/mcp/ui/tools_tests.rs
@@ -47,15 +47,23 @@ async fn read_confined_refuses_a_file_swapped_for_an_outside_symlink() {
let roots = vec![root.path().to_path_buf()];
let (canonical_root, resolved) = confine_path_in(&roots, "view.html").unwrap();
assert_eq!(
- read_confined(&DispatchCtx::ambient(), canonical_root.clone(), resolved.clone())
- .await
- .unwrap(),
+ read_confined(
+ &DispatchCtx::ambient(),
+ canonical_root.clone(),
+ resolved.clone()
+ )
+ .await
+ .unwrap(),
"<p>inside</p>"
);
std::fs::remove_file(&target).unwrap();
std::os::unix::fs::symlink(outside.path().join("secret.html"), &target).unwrap();
- assert!(read_confined(&DispatchCtx::ambient(), canonical_root, resolved).await.is_err());
+ assert!(
+ read_confined(&DispatchCtx::ambient(), canonical_root, resolved)
+ .await
+ .is_err()
+ );
}
#[cfg(unix)]
@@ -71,7 +79,11 @@ async fn read_confined_refuses_a_directory_swapped_for_an_outside_symlink() {
std::fs::remove_dir_all(root.path().join("pages")).unwrap();
std::os::unix::fs::symlink(outside.path(), root.path().join("pages")).unwrap();
- assert!(read_confined(&DispatchCtx::ambient(), canonical_root, resolved).await.is_err());
+ assert!(
+ read_confined(&DispatchCtx::ambient(), canonical_root, resolved)
+ .await
+ .is_err()
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rs
index bb8ff9e956..176e47e677 100644
--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs
+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs
@@ -84,11 +84,9 @@ impl ApprovalGate {
}
// SaaS has no per-user approval surface: never park, allow only what
// the deployment's sandboxed tool groups open.
- if let Some(outcome) = saas_outcome_with(
- &crate::core::runtime::DispatchCtx::ambient(),
- crate::core::runtime::is_saas(),
- tool_name,
- ) {
+ if let Some(outcome) =
+ saas_outcome_with(&turn_ctx, crate::core::runtime::is_saas(), tool_name)
+ {
return (outcome, None);
}
if forced
@@ -205,8 +203,8 @@ impl ApprovalGate {
// `auto_approve_all_allows_a_remote_triage_dispatch_without_an_audit_row`
// below pins that outcome, so a change to this exclusion list has to
// confront the decision rather than discover it.
- let auto_all =
- self.is_auto_approve_all_enabled(&turn_ctx) && !matches!(&origin, AgentTurnOrigin::Unknown);
+ let auto_all = self.is_auto_approve_all_enabled(&turn_ctx)
+ && !matches!(&origin, AgentTurnOrigin::Unknown);
if auto_all && !forced {
// `origin_class` is the sanitized variant label (no thread/client
@@ -227,9 +225,7 @@ impl ApprovalGate {
return (GateOutcome::Allow, None);
}
- if !forced
- && !matches!(&origin, AgentTurnOrigin::Unknown)
- && turn_ctx.approvals_disabled()
+ if !forced && !matches!(&origin, AgentTurnOrigin::Unknown) && turn_ctx.approvals_disabled()
{
tracing::info!(
tool = tool_name,
@@ -247,7 +243,10 @@ impl ApprovalGate {
// live policy) takes effect on the very next tool call; fall back to the
// gate's boot-time config when no live policy is installed (e.g. a CLI
// invocation that never started a session runtime, or a unit test).
- if !forced && !bypass_auto_approve_shortcut && self.tool_is_auto_approved(&turn_ctx, tool_name) {
+ if !forced
+ && !bypass_auto_approve_shortcut
+ && self.tool_is_auto_approved(&turn_ctx, tool_name)
+ {
tracing::debug!(
tool = tool_name,
"[approval::gate] auto_approve allowlist hit, skipping prompt"