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
Merge remote-tracking branch 'upstream/main' into goal-tools-text-dialect
Steven Enamakele31df46edd7a
diff --cc crates/openhuman-core/src/agent/session_host/runtime_session_tests.rsindex 551c61ec9d,db4b5bf757..fc912db025--- a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs@@@ -374,112 -374,73 +374,183 @@@ async fn session_locator_is_memoized_ac);}+const THREAD_GOAL_TOOLS: [&str; 3] = ["goal_get", "goal_set", "goal_complete"];+/// The goal tool this fixture's default (non-orchestrator) session surfaces on a+/// thread; the others are admitted only for agents that list them.+const SURFACED_GOAL_TOOL: &str = "goal_complete";++/// A text-dialect (XML) session over the real per-thread goal tools, optionally+/// bound to a chat thread, with its runtime session already initialised.+fn text_dialect_host(+ thread_id: Option<&str>,+) -> (crate::agent::OpenHumanSessionHost, tempfile::TempDir) {+ let _ = crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins();+ let action_dir = tempfile::tempdir().expect("tempdir");+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let tools = crate::agent::goals::goal_tools(action_dir.path());+ let mut host = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .tools(tools)+ .action_dir(action_dir.path().to_path_buf())+ .memory(crate::memory::test_support::noop_memory())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .build()+ .expect("session build");+ host.set_thread_id(thread_id);+ host.ensure_runtime_session().expect("runtime session");+ (host, action_dir)+}++/// Render the first-turn system prompt and declared tool list of `host`.+async fn prompt_and_declared_tools(+ host: &crate::agent::OpenHumanSessionHost,+) -> (String, ToolSnapshot) {+ let prelude = host+ .runtime_state+ .lock()+ .unwrap_or_else(|poisoned| poisoned.into_inner())+ .prelude+ .clone()+ .expect("prelude");+ let tiered = prelude+ .build_system_prompt_tiered(crate::agent::prompts::LearnedContextData::default())+ .expect("system prompt");+ let snapshot = prelude+ .prepare(true)+ .await+ .expect("tool surface")+ .tools+ .expect("declared tools");+ (tiered.text, snapshot)+}++fn assert_no_goal_tools(prompt: &str, snapshot: &ToolSnapshot) {+ for name in THREAD_GOAL_TOOLS {+ assert!(!prompt.contains(name), "{name} leaked into the prompt");+ assert!(+ !snapshot.specs().iter().any(|spec| spec.name == name),+ "{name} leaked into the declared tools"+ );+ }+}++/// Issue #6956 follow-up: the harness drops `goal_*` for a thread-less turn, so+/// a text-dialect prompt that still catalogued them taught the model tools that+/// answer "unregistered tool" when called.+#[tokio::test]+async fn text_dialect_prompt_omits_thread_goal_tools_without_a_thread() {+ let (host, _dir) = text_dialect_host(None);+ let (prompt, snapshot) = prompt_and_declared_tools(&host).await;+ assert_no_goal_tools(&prompt, &snapshot);+}++#[tokio::test]+async fn text_dialect_prompt_lists_thread_goal_tools_on_a_thread() {+ let (host, _dir) = text_dialect_host(Some("thread-goals"));+ let (prompt, snapshot) = prompt_and_declared_tools(&host).await;+ assert!(+ prompt.contains(SURFACED_GOAL_TOOL),+ "{SURFACED_GOAL_TOOL} missing from the prompt"+ );+ assert!(+ snapshot+ .specs()+ .iter()+ .any(|spec| spec.name == SURFACED_GOAL_TOOL),+ "{SURFACED_GOAL_TOOL} missing from the declared tools"+ );+}++/// The prompt and tool snapshot are cached from the first turn, so binding a+/// thread after the runtime session exists is refused: the thread-less+/// surface (no goal tools) must not be contradicted by a later thread id.+#[tokio::test]+async fn a_thread_bound_after_session_init_is_refused_and_keeps_goal_tools_out() {+ let (mut host, _dir) = text_dialect_host(None);+ host.set_thread_id(Some("late-thread"));+ assert_eq!(host.thread_id(), None, "late thread id must be refused");+ assert_eq!(host.session_id(), None, "no durable identity was minted");+ let (prompt, snapshot) = prompt_and_declared_tools(&host).await;+ assert_no_goal_tools(&prompt, &snapshot);+}++#[tokio::test]+async fn rebinding_the_same_thread_after_session_init_is_a_no_op() {+ let (mut host, _dir) = text_dialect_host(Some("same-thread"));+ host.set_thread_id(Some("same-thread"));+ assert_eq!(host.thread_id(), Some("same-thread"));+ let (prompt, _snapshot) = prompt_and_declared_tools(&host).await;+ assert!(prompt.contains(SURFACED_GOAL_TOOL));+}+++ #[tokio::test]+ async fn newly_connected_action_cannot_shadow_a_permanent_source() {+ use super::*;+ struct AttachedAction;+ #[async_trait::async_trait]+ impl tinytools::Tool for AttachedAction {+ fn name(&self) -> &str {+ "GMAIL_SEND_EMAIL"+ }+ fn description(&self) -> &str {+ "host-owned action"+ }+ fn parameters_schema(&self) -> serde_json::Value {+ serde_json::json!({"type":"object"})+ }+ async fn execute(&self, _: serde_json::Value) -> anyhow::Result<tinytools::ToolResult> {+ Ok(tinytools::ToolResult::success("host"))+ }+ }+ let _ = crate::agent::harness::definition::AgentDefinitionRegistry::init_global_builtins();+ let action_dir = tempfile::tempdir().unwrap();+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let mut host = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .tools(vec![Box::new(AttachedAction)])+ .permanent_tool_names(std::collections::HashSet::from(["GMAIL_SEND_EMAIL".into()]))+ .action_dir(action_dir.path().to_path_buf())+ .memory(crate::memory::test_support::noop_memory())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .agent_definition_name("orchestrator")+ .build()+ .unwrap();+ host.ensure_runtime_session().unwrap();+ let prelude = host.runtime_state.lock().unwrap().prelude.clone().unwrap();+ prelude.refresh_delegation_tool_surface().unwrap();+ let before = prelude+ .tool_surface+ .lock()+ .unwrap()+ .visible_tool_specs+ .clone();+ prelude.adopt_recorded_tools(Some(+ &ToolSnapshot::new(vec![spec("GMAIL_SEND_EMAIL")]).unwrap(),+ ));+ {+ let mut mutable = prelude.mutable.lock().unwrap();+ mutable.connected_integrations = vec![crate::agent::prompts::ConnectedIntegration {+ toolkit: "gmail".into(),+ description: String::new(),+ tools: Vec::new(),+ gated_tools: Vec::new(),+ connected: true,+ connections: Vec::new(),+ non_active_status: None,+ }];+ mutable.connected_integrations_authoritative = true;+ }+ let error = prelude.refresh_delegation_tool_surface().unwrap_err();+ assert!(error+ .to_string()+ .contains("collision with synthesized tool"));+ let surface = prelude.tool_surface.lock().unwrap();+ assert!(Arc::ptr_eq(&surface.visible_tool_specs, &before));+ assert_eq!(surface.tools[0].description(), "host-owned action");+ assert!(!surface+ .synthesized_tools+ .iter()+ .any(|tool| tool.name() == "GMAIL_SEND_EMAIL"));+ }diff --cc crates/openhuman-core/src/sandbox/grants_tests.rsindex 0000000000,3207348187..e490e6c464mode 000000,100644..100644--- a/crates/openhuman-core/src/sandbox/grants_tests.rs+++ b/crates/openhuman-core/src/sandbox/grants_tests.rs@@@ -1,0 -1,259 +1,265 @@@+ use super::*;+ use std::fs;+ use std::path::{Path, PathBuf};++ fn fake_home() -> tempfile::TempDir {+ let home = tempfile::tempdir().unwrap();+ for d in [+ ".ssh", ".gnupg", ".aws", ".cargo", ".rustup", ".nvm", ".npm",+ ] {+ fs::create_dir_all(home.path().join(d)).unwrap();+ }+ home+ }++ fn canon(p: &Path) -> PathBuf {+ p.canonicalize().unwrap()+ }++ fn has(grants: &[PathBuf], p: &Path) -> bool {+ grants.iter().any(|g| g == p)+ }++ fn all(g: &JailGrants) -> Vec<PathBuf> {+ g.read_only.iter().chain(&g.read_write).cloned().collect()+ }++ /// A grant reaches a credential store if it IS one, is inside one, or contains+ /// one (Landlock grants are recursive, so a parent grant exposes the child).+ fn reaches_credentials(grants: &[PathBuf], home: &Path) -> Option<PathBuf> {+ for cred in [".ssh", ".gnupg", ".aws"] {+ let cred = home.join(cred);+ for g in grants {+ if g.starts_with(&cred) || cred.starts_with(g) {+ return Some(g.clone());+ }+ }+ }+ None+ }++ #[test]+ fn credential_dirs_are_never_granted_by_default() {+ let home = fake_home();+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ assert_eq!(reaches_credentials(&all(&g), home.path()), None);+ }++ #[test]+ fn credential_dirs_are_never_granted_even_when_extras_ask() {+ let home = fake_home();+ let cfg = LocalJailConfig {+ extra_read_only: vec![+ "~/.ssh".into(),+ "~/.gnupg/".into(),+ format!("{}", home.path().join(".aws").display()),+ "~".into(),+ format!("{}", home.path().display()),+ "/".into(),+ ],+ extra_read_write: vec!["~/.ssh".into(), "~".into()],+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert_eq!(reaches_credentials(&all(&g), home.path()), None);+ assert!(!g.read_only.iter().any(|p| p == Path::new("/")));+ }++ #[test]+ fn credential_floor_holds_for_a_symlink_into_a_credential_dir() {+ let home = fake_home();+ std::os::unix::fs::symlink(home.path().join(".ssh"), home.path().join("innocent")).unwrap();+ let cfg = LocalJailConfig {+ extra_read_only: vec!["~/innocent".into()],+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert_eq!(reaches_credentials(&all(&g), home.path()), None);+ }++ #[test]+ fn toolchain_homes_are_granted_when_they_exist() {+ let home = fake_home();+ let cargo = home.path().join(".cargo");+ for dir in ["bin", "registry", "git"] {+ fs::create_dir_all(cargo.join(dir)).unwrap();+ }+ for file in ["config.toml", "config", "env"] {+ fs::write(cargo.join(file), "").unwrap();+ }+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ let h = canon(home.path());+ let cargo = h.join(".cargo");- assert!(!has(&g.read_write, &cargo), "Cargo home must never be writable");++ assert!(++ !has(&g.read_write, &cargo),++ "Cargo home must never be writable"++ );+ assert!(has(&g.read_only, &cargo.join("bin")));+ assert!(has(&g.read_write, &cargo.join("registry")));+ assert!(has(&g.read_write, &cargo.join("git")));+ for file in ["config.toml", "config", "env"] {- assert!(has(&g.read_only, &cargo.join(file)), "{file} should be read-only");++ assert!(++ has(&g.read_only, &cargo.join(file)),++ "{file} should be read-only"++ );+ }+ for ro in [".rustup", ".nvm", ".npm"] {+ assert!(has(&g.read_only, &h.join(ro)), "{ro} should be read-only");+ assert!(+ !has(&g.read_write, &h.join(ro)),+ "{ro} must not be writable"+ );+ }+ for sys in ["/usr/local", "/opt"] {+ if Path::new(sys).exists() {+ assert!(has(&g.read_only, &canon(Path::new(sys))), "{sys} missing");+ }+ }+ }++ #[test]+ fn absent_toolchain_homes_are_not_granted() {+ let home = tempfile::tempdir().unwrap();+ fs::create_dir_all(home.path().join(".nvm")).unwrap();+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ let h = canon(home.path());+ assert!(has(&g.read_only, &h.join(".nvm")));+ assert!(!all(&g).iter().any(|p| p.starts_with(h.join(".cargo"))));+ assert!(!all(&g).iter().any(|p| p.starts_with(h.join(".rustup"))));+ }++ #[test]+ fn toolchain_homes_can_be_switched_off() {+ let home = fake_home();+ fs::write(home.path().join(".gitconfig"), "[user]\n name = x\n").unwrap();+ let cfg = LocalJailConfig {+ toolchain_homes: false,+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert!(g.read_only.is_empty() && g.read_write.is_empty(), "{g:?}");+ }++ #[test]+ fn cargo_home_with_registry_credentials_is_granted_piecewise() {+ let home = fake_home();+ let cargo = home.path().join(".cargo");+ for d in ["bin", "registry", "git"] {+ fs::create_dir_all(cargo.join(d)).unwrap();+ }+ fs::write(+ cargo.join("credentials.toml"),+ "[registry]\ntoken = \"x\"\n",+ )+ .unwrap();+ fs::write(cargo.join("config.toml"), "").unwrap();+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ let c = canon(&cargo);+ assert!(+ !has(&g.read_write, &c),+ "whole ~/.cargo would expose credentials.toml"+ );+ assert!(!all(&g).iter().any(|p| p.ends_with("credentials.toml")));+ assert!(has(&g.read_write, &c.join("registry")));+ assert!(has(&g.read_write, &c.join("git")));+ assert!(has(&g.read_only, &c.join("bin")));+ assert!(has(&g.read_only, &c.join("config.toml")));+ }++ #[test]+ fn a_writable_grant_subsumes_the_same_path_read_only() {+ let home = fake_home();+ let cfg = LocalJailConfig {+ extra_read_only: vec!["~/.npm".into()],+ extra_read_write: vec!["~/.npm".into()],+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ let npm = canon(&home.path().join(".npm"));+ assert!(has(&g.read_write, &npm));+ assert!(!has(&g.read_only, &npm));+ }++ #[test]+ fn proc_is_off_by_default_and_only_the_toggle_grants_it() {+ let home = fake_home();+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ assert!(!all(&g).iter().any(|p| p.starts_with("/proc")));++ // An `extra_*` entry cannot smuggle it in: only `allow_proc` does.+ let cfg = LocalJailConfig {+ extra_read_only: vec!["/proc".into()],+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert!(!all(&g).iter().any(|p| p.starts_with("/proc")));++ let cfg = LocalJailConfig {+ allow_proc: true,+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert!(has(&g.read_only, Path::new("/proc")));+ assert!(!has(&g.read_write, Path::new("/proc")));+ }++ #[test]+ fn extras_expand_tilde_and_skip_missing_paths() {+ let home = fake_home();+ fs::create_dir_all(home.path().join("dotfiles")).unwrap();+ fs::create_dir_all(home.path().join("data")).unwrap();+ let cfg = LocalJailConfig {+ extra_read_only: vec!["~/dotfiles".into(), "~/nope".into()],+ extra_read_write: vec!["~/data/../data".into()],+ ..LocalJailConfig::default()+ };+ let g = resolve_local_jail_grants(Some(home.path()), &cfg);+ assert!(has(&g.read_only, &canon(&home.path().join("dotfiles"))));+ assert!(has(&g.read_write, &canon(&home.path().join("data"))));+ assert!(!all(&g).iter().any(|p| p.ends_with("nope")));+ }++ #[test]+ fn gitconfig_symlink_and_include_targets_are_canonicalized() {+ let home = fake_home();+ let dots = home.path().join("dotfiles");+ fs::create_dir_all(&dots).unwrap();+ fs::write(dots.join("work.gitconfig"), "[user]\n email = a@b\n").unwrap();+ fs::write(dots.join("local.gitconfig"), "").unwrap();+ fs::write(+ dots.join("gitconfig"),+ "[user]\n name = x\n[include]\n path = dotfiles/work.gitconfig\n\+ [includeIf \"gitdir:~/w/\"]\n\tpath = ~/dotfiles/local.gitconfig\n\+ [include]\n path = ~/.ssh/leaky\n",+ )+ .unwrap();+ std::os::unix::fs::symlink(dots.join("gitconfig"), home.path().join(".gitconfig")).unwrap();+ // The credential include must be dropped even though the file exists.+ fs::write(home.path().join(".ssh/leaky"), "").unwrap();++ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ let d = canon(&dots);+ assert!(has(&g.read_only, &d.join("gitconfig")), "{g:?}");+ assert!(has(&g.read_only, &d.join("work.gitconfig")), "{g:?}");+ assert!(has(&g.read_only, &d.join("local.gitconfig")), "{g:?}");+ assert_eq!(reaches_credentials(&all(&g), home.path()), None);+ }++ #[test]+ fn gitconfig_include_cycles_terminate() {+ let home = fake_home();+ fs::write(home.path().join(".gitconfig"), "[include]\n path = ~/b\n").unwrap();+ fs::write(home.path().join("b"), "[include]\n path = ~/.gitconfig\n").unwrap();+ let g = resolve_local_jail_grants(Some(home.path()), &LocalJailConfig::default());+ assert!(has(&g.read_only, &canon(&home.path().join("b"))));+ }++ #[test]+ fn no_home_yields_only_system_toolchain_dirs() {+ let g = resolve_local_jail_grants(None, &LocalJailConfig::default());+ assert!(g.read_write.is_empty());+ assert!(g+ .read_only+ .iter()+ .all(|p| p.starts_with("/usr/local") || p.starts_with("/opt")));+ }