The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(tools): handle tool output artifacts for filesystem and shell tools
Steven Enamakel65eaf7c56e6a
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rsindex f4a4505acf..1e1ad2c44d 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs@@ -17,7 +17,7 @@ use serde_json::Value;use tinyagents_harness::artifacts::tool_results::{self, ArtifactRead, ToolResultArtifactStore};use crate::agent::harness::artifact_offload::{SanitizingRedactor, READ_TOOL};-use crate::tools::FileReadTool;+use tinytools_std::filesystem::FileReadTool;/// Namespace of the artifact index in the run's store registry.pub(crate) const TINYAGENTS_TOOL_RESULT_ARTIFACT_STORE: &str = "openhuman_tool_result_artifacts";diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rsindex e3019630e2..72dc0f3135 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs@@ -420,7 +420,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Too&& budget_bytes > 0&& self.artifact_store.is_some()&& content.len() > budget_bytes- && content.len() as u64 <= crate::tools::FileReadTool::MAX_FILE_SIZE_BYTES)+ && content.len() as u64 <= tinytools_std::filesystem::FileReadTool::MAX_FILE_SIZE_BYTES).then(|| content.clone());// 1+2. TinyJuice: the LLM summary stage (when this agent has adiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rsindex d79549a377..0a83525968 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tool_output_artifact_tests.rs@@ -111,7 +111,7 @@ async fn an_oversized_result_is_stored_as_the_tool_returned_it_not_as_rewritten(async fn a_raw_result_file_read_cannot_open_is_stored_as_the_processed_copy() {let tmp = tempfile::tempdir().unwrap();let summary = "s".repeat(3_000);- let raw_len = crate::tools::FileReadTool::MAX_FILE_SIZE_BYTES as usize + 1;+ let raw_len = tinytools_std::filesystem::FileReadTool::MAX_FILE_SIZE_BYTES as usize + 1;let mw = artifact_mw(Some(summarized(&summary)), tmp.path());let mut result = tool_result("echo", &"r".repeat(raw_len));diff --git a/crates/openhuman-core/src/tools/impl/filesystem/gate.rs b/crates/openhuman-core/src/tools/impl/filesystem/gate.rsnew file mode 100644index 0000000000..3ae735ce0e--- /dev/null+++ b/crates/openhuman-core/src/tools/impl/filesystem/gate.rs@@ -0,0 +1,89 @@+//! `SecurityPolicy` as the filesystem tools' [`FsGate`].+//!+//! A mechanical mapping: every method is one call the tools used to make on+//! the policy directly, with the same argument and the same answer. No policy+//! is decided here; the adapter only names the questions.++use std::path::{Path, PathBuf};+use std::sync::Arc;++use async_trait::async_trait;+use tinytools_std::filesystem::FsGate;++use crate::security::policy::{TrustedAccess, TrustedRoot};+use crate::security::{AutonomyLevel, CommandClass, GateDecision, SecurityPolicy};++/// Clone `security` and scope it to `root`, a run's workspace descriptor root.+///+/// The root becomes both the relative-path resolution root (`action_dir`)+/// **and** a `ReadWrite` trusted root. The grant is the load-bearing half:+/// `action_dir` only decides where a relative path lands, while the allow/deny+/// decision reads `workspace_dir` + `trusted_roots`+/// (`SecurityPolicy::is_resolved_path_allowed_for`). Without the grant a+/// descriptor rooted outside `workspace_dir` moved the cwd but refused every+/// read and write in it.+///+/// The grant is *additive and per-call*: it is pushed onto a clone, so nothing+/// process-global is mutated and concurrent turns cannot race each other. It+/// also cannot widen the hard invariants: `is_always_forbidden` (credential+/// stores, core OS dirs) and `is_workspace_internal_path` (core-managed state+/// under `workspace_dir`) are both evaluated *before* any trusted-root+/// shortcut, so a granted root can never expose them.+///+/// The root always originates from trusted in-process code (the session+/// builder, the sub-agent runner, or the `cwd` RPC parameter), never from+/// model-supplied text.+pub(super) fn security_scoped_to_root(security: &SecurityPolicy, root: &Path) -> SecurityPolicy {+ let mut scoped = security.clone();+ scoped.action_dir = root.to_path_buf();+ scoped.trusted_roots.push(TrustedRoot {+ path: root.to_string_lossy().to_string(),+ access: TrustedAccess::ReadWrite,+ });+ scoped+}++#[async_trait]+impl FsGate for SecurityPolicy {+ fn can_act(&self) -> bool {+ SecurityPolicy::can_act(self)+ }++ fn is_read_only(&self) -> bool {+ // Deliberately the raw tier, not `can_act()`: `git_operations` asks+ // this in addition to `can_act()` and always has.+ self.autonomy == AutonomyLevel::ReadOnly+ }++ fn is_rate_limited(&self) -> bool {+ SecurityPolicy::is_rate_limited(self)+ }++ fn record_action(&self) -> bool {+ SecurityPolicy::record_action(self)+ }++ fn write_needs_approval(&self) -> bool {+ self.gate_decision(CommandClass::Write) == GateDecision::Prompt+ }++ fn action_dir(&self) -> &Path {+ &self.action_dir+ }++ fn is_path_string_allowed(&self, path: &str) -> bool {+ SecurityPolicy::is_path_string_allowed(self, path)+ }++ async fn validate_path(&self, path: &str) -> Result<PathBuf, String> {+ SecurityPolicy::validate_path(self, path).await+ }++ async fn validate_parent_path(&self, path: &str) -> Result<PathBuf, String> {+ SecurityPolicy::validate_parent_path(self, path).await+ }++ fn scoped_to_workspace(&self, root: &Path) -> Arc<dyn FsGate> {+ Arc::new(security_scoped_to_root(self, root))+ }+}diff --git a/crates/openhuman-core/src/tools/impl/filesystem/mod.rs b/crates/openhuman-core/src/tools/impl/filesystem/mod.rsindex 9c06995916..4c6c3074e7 100644--- a/crates/openhuman-core/src/tools/impl/filesystem/mod.rs+++ b/crates/openhuman-core/src/tools/impl/filesystem/mod.rs@@ -1,93 +1,21 @@-//! Cross-cutting filesystem tools: read/write/edit/patch, grep/glob/list,-//! diffs, CSV export, git operations, linter/test runners. Every tool struct-//! and its registration gate is listed in `tools/impl/README.md`;-//! `security_for_tool_context` below resolves the `SecurityPolicy` for a tool-//! run and is mirrored by the `system` family.+//! Host adapter for the filesystem tools.+//!+//! The tools themselves (`file_read`, `file_write`, `edit_file`,+//! `apply_patch`, `grep`, `glob`, `list_files`, `csv_export`, `read_diff`,+//! `git_operations`, `run_linter`, `run_tests`, `update_memory_md`) live in+//! `tinytools_std::filesystem` and are registered by `tools/ops.rs`. What stays+//! here is the policy they consult: [`gate`] implements+//! `tinytools_std::filesystem::FsGate` for [`crate::security::SecurityPolicy`],+//! so the autonomy flag, the `is_always_forbidden` floor, `workspace_only`,+//! trusted roots and the approval gate remain host decisions. The tools only+//! ask.-mod apply_patch;-mod csv_export;-mod edit_file;-mod file_read;-mod file_write;-mod git_operations;-mod git_operations_config;-mod git_operations_render;-mod glob_search;-mod grep;-mod list_files;-mod read_diff;-mod run_linter;-mod run_tests;-mod update_memory_md;-mod write_sink;+mod gate;-use crate::security::policy::{TrustedAccess, TrustedRoot};-use crate::security::SecurityPolicy;-use tinytools::ToolRunContext;+#[cfg(test)]+#[path = "gate_tests.rs"]+mod gate_tests;#[cfg(test)]#[path = "mod_tests.rs"]mod tests;--/// The git config overrides a shell-spawned `git` is forced to run under.-///-/// Re-exported from the module that owns the whole policy so the `shell` tool-/// and `git_operations` cannot drift into two different answers about which-/// config keys are dangerous.-pub(crate) use git_operations_config::shell_git_env;--pub use apply_patch::ApplyPatchTool;-pub use csv_export::CsvExportTool;-pub use edit_file::EditFileTool;-pub use file_read::FileReadTool;-pub use file_write::FileWriteTool;-pub use git_operations::GitOperationsTool;-pub use glob_search::GlobTool;-pub use grep::GrepTool;-pub use list_files::ListFilesTool;-pub use read_diff::ReadDiffTool;-pub use run_linter::RunLinterTool;-pub use run_tests::RunTestsTool;-pub use update_memory_md::UpdateMemoryMdTool;--/// Clone `security` and scope it to the run's workspace descriptor, if any.-///-/// The descriptor's root becomes both the relative-path resolution root-/// (`action_dir`) **and** a `ReadWrite` trusted root. The grant is the-/// load-bearing half: `action_dir` only decides where a relative path lands,-/// while the allow/deny decision reads `workspace_dir` + `trusted_roots`-/// (`SecurityPolicy::is_resolved_path_allowed_for`). Without the grant a-/// descriptor rooted outside `workspace_dir` moved the cwd but refused every-/// read and write in it.-///-/// The grant is *additive and per-call*: it is pushed onto a clone, so nothing-/// process-global is mutated and concurrent turns cannot race each other. It-/// also cannot widen the hard invariants — `is_always_forbidden` (credential-/// stores, core OS dirs) and `is_workspace_internal_path` (core-managed state-/// under `workspace_dir`) are both evaluated *before* any trusted-root-/// shortcut, so a granted root can never expose them.-///-/// The root always originates from trusted in-process code (the session-/// builder, the sub-agent runner, or the `cwd` RPC parameter) — never from-/// model-supplied text.-pub(super) fn security_for_tool_context(- security: &SecurityPolicy,- context: Option<&dyn ToolRunContext>,- tool: &str,-) -> SecurityPolicy {- let mut scoped = security.clone();- if let Some(workspace) = context.and_then(|ctx| ctx.workspace()) {- tracing::debug!(- tool,- workspace_root = %workspace.root.display(),- policy_id = %workspace.policy_id,- "[tools:filesystem] granting TinyAgents workspace descriptor as action dir + trusted root"- );- scoped.action_dir = workspace.root.clone();- scoped.trusted_roots.push(TrustedRoot {- path: workspace.root.to_string_lossy().to_string(),- access: TrustedAccess::ReadWrite,- });- }- scoped-}diff --git a/crates/openhuman-core/src/tools/impl/filesystem/mod_tests.rs b/crates/openhuman-core/src/tools/impl/filesystem/mod_tests.rsindex 8fe8cdcd02..225efcdcc1 100644--- a/crates/openhuman-core/src/tools/impl/filesystem/mod_tests.rs+++ b/crates/openhuman-core/src/tools/impl/filesystem/mod_tests.rs@@ -1,13 +1,12 @@-//! Tests for [`super::security_for_tool_context`] — the per-tool-call policy-//! clone that carries a run's `WorkspaceDescriptor` into the filesystem tools.-//!-//! Split out of `mod.rs` to keep the module root export-focused. Declared via-//! `#[path = "mod_tests.rs"] mod tests;` so `super::*` resolves to the-//! `filesystem` module.--use super::*;+//! Tests for the per-tool-call policy scoping that carries a run's+//! `WorkspaceDescriptor` into the filesystem tools+//! ([`super::gate::security_scoped_to_root`]).++use super::gate::security_scoped_to_root;use crate::security::policy::TrustedAccess;+use crate::security::SecurityPolicy;use std::path::Path;+use tinytools::ToolRunContext;use tinyagents_harness::context::{RunConfig, RunContext};use tinyagents_harness::tool::ToolExecutionContext;use tinytools::WorkspaceDescriptor;@@ -20,6 +19,20 @@ fn tool_context_with_workspace(root: &Path) -> ToolExecutionContext {ToolExecutionContext::from_run_context(&ctx, tinyagents_harness::ids::CallId::new("test-call"))}+/// The policy the tools validate against for a call: scoped to the run's+/// workspace descriptor when there is one, otherwise untouched. This is what+/// `tinytools_std::filesystem` does through `FsGate::scoped_to_workspace`.+fn security_for_tool_context(+ security: &SecurityPolicy,+ context: Option<&dyn ToolRunContext>,+ _tool: &str,+) -> SecurityPolicy {+ match context.and_then(|ctx| ctx.workspace()) {+ Some(workspace) => security_scoped_to_root(security, &workspace.root),+ None => security.clone(),+ }+}+/// A policy whose `workspace_dir`/`action_dir` are the OpenHuman home — i.e. a/// directory that does NOT contain the descriptor root. `workspace_only` is on,/// matching the default tier, so an absolute path outside the workspace isdiff --git a/crates/openhuman-core/src/tools/impl/mod.rs b/crates/openhuman-core/src/tools/impl/mod.rsindex 2581d5b3e9..e5db89f4a5 100644--- a/crates/openhuman-core/src/tools/impl/mod.rs+++ b/crates/openhuman-core/src/tools/impl/mod.rs@@ -1,7 +1,7 @@pub mod browser;#[cfg(feature = "documents")]pub mod document;-pub mod filesystem;+mod filesystem;pub mod meta;pub mod network;#[cfg(feature = "documents")]@@ -11,7 +11,6 @@ pub mod system;pub use browser::*;#[cfg(feature = "documents")]pub use document::DocumentTool;-pub use filesystem::*;pub use network::*;#[cfg(feature = "documents")]pub use presentation::PresentationTool;diff --git a/crates/openhuman-core/src/tools/impl/system/mod.rs b/crates/openhuman-core/src/tools/impl/system/mod.rsindex b134892acd..e0b110ec0d 100644--- a/crates/openhuman-core/src/tools/impl/system/mod.rs+++ b/crates/openhuman-core/src/tools/impl/system/mod.rs@@ -43,7 +43,7 @@ pub use workspace_state::WorkspaceStateTool;/// Clone `security` and scope it to the run's workspace descriptor, if any.////// The process-tool counterpart of-/// [`super::filesystem::security_for_tool_context`], and it must stay in step+/// `tools/impl/filesystem/gate.rs` (`security_scoped_to_root`), and it must stay in step/// with it: the descriptor's root becomes both the relative-path resolution/// root (`action_dir`) **and** a `ReadWrite` trusted root. The grant is the/// load-bearing half — `action_dir` only decides where a relative path lands,diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex e816d97477..40a627f029 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -393,7 +393,7 @@ impl ShellTool {// Keep command-valued repository Git settings from executing host// programs when a shell command happens to invoke git.- for (key, value) in crate::tools::implementations::filesystem::shell_git_env() {+ for (key, value) in tinytools_std::filesystem::shell_git_env() {cmd.env(key, value);}@@ -522,7 +522,7 @@ impl ShellTool {}// Apply the same Git config hardening to local and sandboxed shells.- extra_env.extend(crate::tools::implementations::filesystem::shell_git_env());+ extra_env.extend(tinytools_std::filesystem::shell_git_env());// Sandbox backends require a finite deadline. Without an explicit// `timeout_secs`, substitute the generous effective-unbounded cap so a