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
refactor(tinyagents): use tinytools_std helpers for read-only and fetch status checks
Steven Enamakel3ec8e1da5cba
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware.rs b/crates/openhuman-core/src/agent/tinyagents/middleware.rsindex 64694a4da5..561bd1d754 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware.rs@@ -43,7 +43,6 @@ mod stop_latch;mod tool_exposure;mod tool_outcome_capture;mod tool_output;-mod tool_output_file_read;mod tool_policy;mod turn_context;mod unmet_deliverable;diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rsindex ff1f1aed91..b5fd80e9bd 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/fetched_site.rs@@ -12,22 +12,6 @@/// The agent tool that fetches a public URL (`tinytools` `web_fetch`).pub(super) const WEB_FETCH_TOOL: &str = "web_fetch";-/// The HTTP status of a `web_fetch` error result. Anchored to the start of the-/// text, so a status quoted later (a response excerpt, another tool's output)-/// is not read, and to the whole shape, so a bare `HTTP 403` or `403 Forbidden`-/// from some other source is not either.-pub(super) fn fetched_site_status(text: &str) -> Option<u16> {- let rest = text.trim_start().strip_prefix("HTTP ")?;- let code = rest- .get(..3)- .filter(|c| c.bytes().all(|b| b.is_ascii_digit()))?;- let rest = rest[3..].strip_prefix(' ')?;- let status: u16 = code.parse().ok().filter(|s| (400..=599).contains(s))?;- let (_reason, after_from) = rest.lines().next()?.split_once(" from ")?;- let (host, _guidance) = after_from.split_once(';')?;- (!host.is_empty() && !host.contains(char::is_whitespace)).then_some(status)-}-/// Recovery policy for a `web_fetch` error carrying a fetched site's status:/// `None` when `tool`/`error` are not that shape (the caller classifies as/// usual), otherwise the policy to return, itself `None` for an ordinary@@ -45,7 +29,7 @@ pub(super) fn fetched_site_policy(if tool != WEB_FETCH_TOOL {return None;}- let status = fetched_site_status(error)?;+ let status = tinytools_std::network::web_fetch::status_of(error)?;tracing::debug!(status,"[tinyagents::mw] web_fetch site status — not a credential failure"diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rsindex bf05301d5c..fc0effd55c 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output.rs@@ -208,7 +208,7 @@ pub(crate) struct ToolOutputMiddleware {/// Calls that only print files the agent can read again (`cat`, `sed -n`,/// `file_read`, ...), keyed by call id; the same `before_tool` →/// `after_tool` seam. Their results skip the LLM summary. See- /// [`super::tool_output_file_read`].+ /// `tinytools_std::filesystem::is_read_only_call`.pub(crate) file_reads: Mutex<std::collections::HashSet<String>>,}@@ -303,7 +303,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Tooreads.insert(call.id.clone(), read);}}- if super::tool_output_file_read::is_file_read_call(&call.name, &call.arguments) {+ if tinytools_std::filesystem::is_read_only_call(&call.name, &call.arguments) {tracing::debug!(tool = %call.name,call_id = %call.id,@@ -494,7 +494,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Too// compaction. Past the budget it never gets an LLM summary (a// paraphrase of code it is about to edit, which it would only// fetch back): TinyJuice's deterministic handle and preview, then- // step 3's bound, apply. See [`super::tool_output_file_read`].+ // step 3's bound, apply. See `tinytools_std::filesystem::is_read_only_call`.let verbatim_file_read = file_read && (budget_bytes == 0 || content.len() <= budget_bytes);if file_read {tracing::info!(diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read.rsdeleted file mode 100644index 715f5b2707..0000000000--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read.rs+++ /dev/null@@ -1,91 +0,0 @@-//! Which tool calls only read files the agent can read again.-//!-//! [`super::tool_output::ToolOutputMiddleware`] skips TinyJuice's LLM summary-//! for these. A summary of source code is a paraphrase, and an agent about to-//! edit a file needs its exact text: on live coding runs every summarized-//! `cat` of a source file was followed by `juice_retrieve` of the whole-//! original or a fresh `sed -n` read of the file. The summary bought nothing-//! and cost a model call plus up to TinyJuice's 8-second summary timeout,-//! which it hit on most attempts.-//!-//! The test is deliberately narrow: a file-reading tool, or a shell command-//! made only of `cd` and plain reads (`cat`, `head`, `tail`, `nl`, `sed`-//! without `-i`, `echo`/`printf` separators), with no redirects, heredocs,-//! substitutions or other programs. Anything else (a build, a test run, a-//! search) keeps the normal pipeline: its output is not a file on disk.--use serde_json::Value;--/// Tools whose whole job is returning a file's contents.-const FILE_READ_TOOLS: &[&str] = &["file_read", "read_file", "read", "view_file"];--/// Shell tools, by the names OpenHuman and common harness adapters use.-const SHELL_TOOLS: &[&str] = &["shell", "bash", "exec", "run_command", "terminal"];--/// Programs that print a file (`sed` only without in-place editing).-const READERS: &[&str] = &["cat", "head", "tail", "nl", "sed"];--/// Programs allowed beside the readers: navigation and separators.-const NEUTRAL: &[&str] = &["cd", "echo", "printf", "true", "pwd"];--/// Whether this call only prints files the agent can re-read (see the module-/// docs). `use_skill` is followed into the tool it wraps.-pub(crate) fn is_file_read_call(tool_name: &str, args: &Value) -> bool {- let (name, args) = if tool_name == "use_skill" {- match (args.get("tool").and_then(Value::as_str), args.get("args")) {- (Some(inner), Some(inner_args)) => (inner, inner_args),- _ => return false,- }- } else {- (tool_name, args)- };- if FILE_READ_TOOLS.contains(&name) {- return true;- }- if !SHELL_TOOLS.contains(&name) {- return false;- }- args.get("command")- .or_else(|| args.get("cmd"))- .and_then(Value::as_str)- .is_some_and(is_file_read_command)-}--/// Whether a shell command line only prints files: every segment (split on-/// `&&`, `||`, `;`, `|` and newlines) runs a reader or a neutral program, at-/// least one runs a reader, and nothing redirects, substitutes or feeds a-/// heredoc.-pub(crate) fn is_file_read_command(command: &str) -> bool {- if command.contains(['>', '<', '`', '$']) {- return false;- }- let mut reads = false;- for segment in command- .split(['\n', ';', '|', '&'])- .map(str::trim)- .filter(|s| !s.is_empty())- {- let mut words = segment.split_whitespace();- let Some(program) = words.next() else {- continue;- };- let program = program.rsplit('/').next().unwrap_or(program);- if program == "sed"- && segment- .split_whitespace()- .any(|w| w.starts_with("-i") || w == "--in-place" || w.starts_with("--in-place="))- {- return false;- }- if READERS.contains(&program) {- reads = true;- } else if !NEUTRAL.contains(&program) {- return false;- }- }- reads-}--#[cfg(test)]-#[path = "tool_output_file_read_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read_tests.rsdeleted file mode 100644index d4650a37dc..0000000000--- a/crates/openhuman-core/src/agent/tinyagents/middleware/tool_output_file_read_tests.rs+++ /dev/null@@ -1,58 +0,0 @@-use super::*;-use serde_json::json;--#[test]-fn plain_reads_of_files_are_file_reads() {- for command in [- "cat vm/vmExprFunction.go",- "cd /app && cat vm/vmExprFunction.go",- "cd /app && cat -n parser/lexer.go",- "cd /app && sed -n '120,300p' vm/vmExprFunction.go",- "cd /app && cat parser/Makefile && echo \"=== parser.go.y ===\" && cat parser/parser.go.y",- "cd /app && sed -n '125,150p' ast/expr.go && echo \"=== vmExprFunction.go ===\" && cat vm/vmExprFunction.go",- "head -50 README.md; tail -20 CHANGELOG.md",- "cat -n src/lib.rs | sed -n '1,80p'",- ] {- assert!(is_file_read_command(command), "{command}");- }-}--#[test]-fn anything_that_runs_writes_or_searches_is_not() {- for command in [- "go test ./vm/...",- "cd /app && git diff",- "grep -rn FuncExpr .",- "cat foo.go > bar.go",- "sed -i 's/a/b/' foo.go",- "sed --in-place 's/a/b/' foo.go",- "sed --in-place=.bak -n 's/old/new/p' file",- "cat <<'EOF' > x.go\npackage x\nEOF",- "cat $(git ls-files)",- "cat README.md && printf '%s\\n' \"$BUILD_LOG\"",- "cd /app && cat a.go && go build ./...",- "echo hello",- "cd /app",- ] {- assert!(!is_file_read_command(command), "{command}");- }-}--#[test]-fn file_read_tools_and_wrapped_calls_are_recognised() {- assert!(is_file_read_call("file_read", &json!({"path": "a.rs"})));- assert!(is_file_read_call("shell", &json!({"command": "cat a.rs"})));- assert!(!is_file_read_call(- "shell",- &json!({"command": "cargo test"})- ));- assert!(!is_file_read_call(- "web_fetch",- &json!({"url": "https://example.com"})- ));- assert!(is_file_read_call(- "use_skill",- &json!({"tool": "shell", "args": {"command": "cat a.rs"}})- ));- assert!(!is_file_read_call("use_skill", &json!({"tool": "shell"})));-}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rsindex 7568cc59ba..17bfe1ee78 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs@@ -240,30 +240,3 @@ fn web_fetch_failure_scope_is_the_host_not_the_page() {);}-#[test]-fn fetched_site_status_reads_only_the_web_fetch_error_shape() {- let status = super::super::fetched_site::fetched_site_status;- assert_eq!(status(FETCH_403), Some(403));- assert_eq!(status(FETCH_429), Some(429));- assert_eq!(status(FETCH_404), Some(404));- assert_eq!(status(FETCH_503), Some(503));- assert_eq!(- status(" HTTP 403 Forbidden from 127.0.0.1; the site refused it."),- Some(403)- );- // Bare statuses, other tools' wording, success codes, and the shape- // buried mid-text are not the shape.- for text in [- "HTTP 403 Forbidden",- "HTTP 403",- "403 Forbidden",- "Gmail API error: 403 insufficient scopes",- "Command failed (exit 1)\nHTTP 403 Forbidden from example.test; x",- "HTTP 2000 Weird from example.test; x",- "HTTP 200 OK from example.test; x",- "HTTP 403 Forbidden from ; x",- "HTTP 403 Forbidden from example.test no semicolon",- ] {- assert_eq!(status(text), None, "{text}");- }-}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 365959b813..92dd1efc8d 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -412,8 +412,6 @@ mod research_budget_tests;mod memory_and_hooks_tests;#[path = "middleware_tool_output_artifact_tests.rs"]mod tool_output_artifact_tests;-#[path = "middleware_tool_output_file_read_tests.rs"]-mod tool_output_file_read_tests;#[path = "middleware_tool_output_tests.rs"]mod tool_output_tests;#[path = "middleware_tool_policy_tests.rs"]