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(desktop): delegate tool metadata to declarations
Steven Enamakel837973071a5d
diff --git a/crates/openhuman-core/src/desktop/control/tools.rs b/crates/openhuman-core/src/desktop/control/tools.rsindex 4600e3c2cd..f91f69ce9d 100644--- a/crates/openhuman-core/src/desktop/control/tools.rs+++ b/crates/openhuman-core/src/desktop/control/tools.rs@@ -3,7 +3,7 @@use std::sync::Arc;use async_trait::async_trait;-use serde_json::{json, Value};+use serde_json::Value;use tinycomputer_bus::desktop_tool::{self as declared, ActRequest, DesktopTool as Declared};use tinycomputer_bus::{names, GoalContinuation, RunGoalRequest};use tinytools::{@@ -174,7 +174,10 @@ impl Tool for DesktopTool {to_value(request).map(|request| (member, request))}Ok((member, _)) => Err(anyhow::anyhow!("unsupported act request for {member}")),- Err(error) => return Ok(ToolResult::error(error.to_string())),+ Err(declared::ToolArgError::UnsupportedOperation) => {+ return Ok(ToolResult::error("Unsupported desktop operation"))+ }+ Err(error) => Err(error.into()),},DesktopToolKind::Goal => {let live_config = match crate::config::rpc::load_config_with_timeout().await {@@ -208,10 +211,7 @@ impl Tool for DesktopTool {to_value(request).map(|request| (names::methods::RUN_GOAL, request))}};- let (member, request) = match built {- Ok(pair) => pair,- Err(error) => return Err(error),- };+ let (member, request) = built?;let reply = crate::modules::desktop::call(&self.config, member, request).await;match reply {Ok(response) if response.ok => {diff --git a/crates/openhuman-core/src/desktop/control/tools_tests.rs b/crates/openhuman-core/src/desktop/control/tools_tests.rsindex 7ea58ca7df..6b2c2b0918 100644--- a/crates/openhuman-core/src/desktop/control/tools_tests.rs+++ b/crates/openhuman-core/src/desktop/control/tools_tests.rs@@ -1,18 +1,5 @@use super::*;--#[test]-fn desktop_arguments_reject_missing_or_blank_required_values() {- assert_eq!(- required(&json!({"app":" TextEdit "}), "app").unwrap(),- "TextEdit"- );- for args in [json!({}), json!({"app":" "}), json!({"app":42})] {- assert!(required(&args, "app")- .unwrap_err()- .to_string()- .contains("missing required parameter: app"));- }-}+use serde_json::json;#[tokio::test]async fn deferred_tool_is_discoverable_but_fails_closed_when_disabled() {@@ -26,172 +13,45 @@ async fn deferred_tool_is_discoverable_but_fails_closed_when_disabled() {}#[test]-fn launch_tool_cannot_accept_process_arguments_or_environment() {- let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Launch);- let schema = tool.parameters_schema();- assert_eq!(tool.exposure(), ToolExposure::Deferred);- assert_eq!(tool.permission_level(), PermissionLevel::Write);- assert!(tool.external_effect());- assert_eq!(schema["required"], json!(["app"]));- assert!(schema["properties"].get("args").is_none());- assert!(schema["properties"].get("env").is_none());- assert!(schema["properties"].get("cdp_port").is_none());-}--#[test]-fn raw_ref_action_requires_a_snapshot_ref_and_declares_a_write_effect() {- let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Act);- let schema = tool.parameters_schema();- assert_eq!(tool.name(), "desktop_act");- assert_eq!(tool.permission_level(), PermissionLevel::Write);- assert!(tool.external_effect());- assert_eq!(schema["required"], json!(["operation", "ref_id"]));- assert_eq!(- schema["properties"]["operation"]["enum"],- json!(["click", "focus", "type", "check", "uncheck", "expand", "collapse"])- );- assert!(schema["properties"].get("args").is_none());- assert!(schema["properties"].get("env").is_none());-}--#[test]-fn snapshot_can_bind_the_window_listed_by_desktop() {- let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Snapshot);- assert_eq!(tool.exposure(), ToolExposure::Deferred);- assert!(tool.parameters_schema()["properties"]- .get("window_id")- .is_some());- let request = snapshot_request(&json!({"app":"TextEdit","window_id":"w-515619"})).unwrap();- assert_eq!(request.app.as_deref(), Some("TextEdit"));- assert_eq!(request.window_id.as_deref(), Some("w-515619"));- assert!(snapshot_request(&json!({"window_id":" "})).is_err());+fn every_wrapper_takes_name_description_and_schema_from_the_declaration() {+ let kinds = [+ (DesktopToolKind::Apps, Declared::Apps),+ (DesktopToolKind::Windows, Declared::Windows),+ (DesktopToolKind::Launch, Declared::Launch),+ (DesktopToolKind::Snapshot, Declared::Snapshot),+ (DesktopToolKind::Find, Declared::Find),+ (DesktopToolKind::Act, Declared::Act),+ (DesktopToolKind::Goal, Declared::Goal),+ (DesktopToolKind::ContinueGoal, Declared::ContinueGoal),+ ];+ for (kind, declaration) in kinds {+ let tool = DesktopTool::new(Arc::new(Config::default()), kind);+ assert_eq!(tool.name(), declaration.name());+ assert_eq!(tool.description(), declaration.description());+ assert_eq!(tool.parameters_schema(), declaration.parameters_schema());+ assert_eq!(tool.exposure(), ToolExposure::Deferred);+ assert_eq!(tool.family(), Some("desktop"));+ assert_eq!(tool.external_effect(), declaration.mutates());+ }}#[test]-fn goal_and_continuation_have_distinct_required_inputs() {+fn mutating_tools_declare_write_and_listing_tools_stay_read_only() {let config = Arc::new(Config::default());- let goal = DesktopTool::new(config.clone(), DesktopToolKind::Goal);- let continuation = DesktopTool::new(config, DesktopToolKind::ContinueGoal);- assert_eq!(- goal.parameters_schema()["required"],- json!([- "app",- "goal",- "allowed_operations",- "allowed_targets",- "success"- ])- );- assert!(goal.parameters_schema()["properties"]- .get("confirmation_id")- .is_none());- assert!(- !goal.parameters_schema()["properties"]["success"]["items"]["properties"]["kind"]["enum"]- .as_array()- .unwrap()- .contains(&json!("name_absent"))- );- assert_eq!(- continuation.parameters_schema()["required"],- json!(["confirmation_id"])- );- assert!(continuation.parameters_schema()["properties"]- .get("approve")- .is_none());- assert!(super::super::confirmation::take_approved("unknown", Some("thread-a")).is_err());-}--#[test]-fn goal_request_carries_scoped_task_and_disables_confirmations() {- let args = json!({- "app":"TextEdit", "window":"Untitled", "window_id":"w-515619",- "goal":"Enter a disposable marker",- "allowed_operations":["TYPE_TEXT"], "allowed_targets":["Text Entry Area"],- "text_slots":{"Text Entry Area":"desktop-test-42"},- "success":[{"kind":"value_equals","name":"Text Entry Area","value":"desktop-test-42"}],- "max_steps":3, "max_model_calls":5, "max_elapsed_ms":20_000- });- let request = goal_request(&args, false).unwrap();- assert_eq!(request["require_confirmations"], false);- assert_eq!(request["window"], "Untitled");- assert_eq!(request["window_id"], "w-515619");- let goal = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Goal);- assert!(goal.parameters_schema()["properties"]- .get("window_id")- .is_some());- assert!(- goal.parameters_schema()["properties"]["success"]["items"]["properties"]["kind"]["enum"]- .as_array()- .unwrap()- .contains(&json!("name_contains"))- );- assert_eq!(request["allowed_operations"], json!(["TYPE_TEXT"]));- assert_eq!(request["allowed_targets"], json!(["Text Entry Area"]));- assert_eq!(request["text_slots"]["Text Entry Area"], "desktop-test-42");- assert_eq!(request["success"], args["success"]);- assert_eq!(request["max_elapsed_ms"], 20_000);- assert!(request["continuation"].is_null());- assert_eq!(- goal_request(&args, true).unwrap()["require_confirmations"],- true- );- assert!(goal_request(&json!({"app":"TextEdit","goal":"type"}), false).is_err());- let without_targets = json!({"app":"TextEdit","goal":"type", "allowed_operations":["TYPE_TEXT"],- "success":[{"kind":"name_present","name":"Text Entry Area"}]});- assert!(goal_request(&without_targets, false)- .unwrap_err()- .to_string()- .contains("needs_inspection"));- let mut blank_target = without_targets.clone();- blank_target["allowed_targets"] = json!([" "]);- assert!(goal_request(&blank_target, false).is_err());- let mut blank_window = args.clone();- blank_window["window_id"] = json!(" ");- assert!(goal_request(&blank_window, false).is_err());- let malformed = json!({"app":"TextEdit","goal":"type", "allowed_operations":["TYPE_TEXT"],- "allowed_targets":["Text Entry Area"],- "success":[{"kind":"value_contains","name":"Text Entry Area"}]});- assert!(goal_request(&malformed, false).is_err());- for predicate in [- json!({"kind":"name_absent","name":"Play"}),- json!({"kind":"name_present","name":" "}),- json!({"kind":"value_contains","name":"Text Entry Area","value":""}),- json!({"kind":"value_equals","name":"","value":"marker"}),- json!({"kind":"state_contains","name":"Play","state":" "}),+ for (kind, level) in [+ (DesktopToolKind::Launch, PermissionLevel::Write),+ (DesktopToolKind::Act, PermissionLevel::Write),+ (DesktopToolKind::Goal, PermissionLevel::Write),+ (DesktopToolKind::ContinueGoal, PermissionLevel::Write),+ (DesktopToolKind::Apps, PermissionLevel::ReadOnly),+ (DesktopToolKind::Windows, PermissionLevel::ReadOnly),+ (DesktopToolKind::Snapshot, PermissionLevel::ReadOnly),+ (DesktopToolKind::Find, PermissionLevel::ReadOnly),] {- let mut request = args.clone();- request["success"] = json!([predicate]);- assert!(goal_request(&request, false).is_err());+ let tool = DesktopTool::new(config.clone(), kind);+ assert_eq!(tool.permission_level(), level, "{}", tool.name());+ assert_eq!(tool.external_effect(), level == PermissionLevel::Write);}- let mut cleared = args.clone();- cleared["success"] = json!([{"kind":"value_equals","name":"Text Entry Area","value":""}]);- assert!(goal_request(&cleared, false).is_ok());-- let outbound = json!({- "app":"WhatsApp", "goal":"Send exactly the prepared text to Alex Rivera",- "allowed_operations":["CLICK","TYPE_TEXT"],- "allowed_targets":["Compose message","Send"],- "text_slots":{"Compose message":"Hello from OpenHuman! "},- "success":[- {"kind":"name_present","name":"Messages in chat with Alex Rivera"},- {"kind":"name_contains","fragment":"Your message, Hello from OpenHuman! ","within":"Messages in chat with Alex Rivera"}- ]- });- let prepared = goal_request(&outbound, false).unwrap();- assert_eq!(- prepared["text_slots"]["Compose message"],- "Hello from OpenHuman! "- );- assert_eq!(- prepared["success"][1]["fragment"],- "Your message, Hello from OpenHuman! "- );- let mut wrong_slot = outbound.clone();- wrong_slot["text_slots"] = json!({"Other field":"Hello from OpenHuman! "});- assert!(goal_request(&wrong_slot, false).is_err());- let mut missing_scope = outbound;- missing_scope["success"][1]["within"] = json!(" ");- assert!(goal_request(&missing_scope, false).is_err());}#[test]@@ -202,11 +62,42 @@ fn goal_timeout_outlives_the_module_loop_budget() {ToolTimeout::Millis(150_000));assert_eq!(- goal.timeout_policy(&json!({"max_elapsed_ms":300_000})),+ goal.timeout_policy(&json!({"max_elapsed_ms":999_999})),ToolTimeout::Millis(330_000));+ let resume = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::ContinueGoal);assert_eq!(- goal.timeout_policy(&json!({"max_elapsed_ms":999_999})),+ resume.timeout_policy(&json!({})),ToolTimeout::Millis(330_000));+ let apps = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Apps);+ assert_eq!(apps.timeout_policy(&json!({})), ToolTimeout::Inherit);+}++#[test]+fn catalogue_order_is_unchanged_and_omits_the_raw_act_tool() {+ let tools = registered_tools(Arc::new(Config::default()));+ let names: Vec<&str> = tools.iter().map(|tool| tool.name()).collect();+ assert_eq!(+ names,+ [+ "desktop_list_apps",+ "desktop_list_windows",+ "desktop_launch",+ "desktop_snapshot",+ "desktop_find",+ "desktop_goal",+ "desktop_continue_goal"+ ]+ );+}++#[test]+fn model_visible_launch_schema_accepts_no_process_arguments() {+ let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Launch);+ let schema = tool.parameters_schema();+ assert_eq!(schema["required"], json!(["app"]));+ for key in ["args", "env", "cdp_port"] {+ assert!(schema["properties"].get(key).is_none(), "{key}");+ }}