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
feat(settings): keep files from earlier folders trusted after a change
M3gA-Mind34071f1f547d
diff --git a/crates/openhuman-core/src/agent/artifacts/files.rs b/crates/openhuman-core/src/agent/artifacts/files.rsindex 9d6aec0ccc..4d4038204a 100644--- a/crates/openhuman-core/src/agent/artifacts/files.rs+++ b/crates/openhuman-core/src/agent/artifacts/files.rs@@ -62,9 +62,14 @@ impl FileRoots {self}- /// The folders for this host config.- pub fn from_config(_config: &crate::config::Config) -> Self {- Self::new(crate::config::default_files_dir())+ /// The folders for this host config: new files go to the configured+ /// folder, and records made in the default folder or any folder used+ /// before (`files_dir_history`) keep resolving.+ pub fn from_config(config: &crate::config::Config) -> Self {+ Self::new(config.files_dir()).with_trusted(+ std::iter::once(crate::config::default_files_dir())+ .chain(config.files_dir_history.iter().cloned()),+ )}/// Where new files are written.diff --git a/crates/openhuman-core/src/agent/artifacts/ops.rs b/crates/openhuman-core/src/agent/artifacts/ops.rsindex 8de92329fe..eb0cca8b57 100644--- a/crates/openhuman-core/src/agent/artifacts/ops.rs+++ b/crates/openhuman-core/src/agent/artifacts/ops.rs@@ -212,7 +212,7 @@ async fn regenerate_presentation());let tool = PresentationTool::with_config(config.workspace_dir.clone(),- config.files_dir(),+ super::files::FileRoots::from_config(config),security,config.clone(),);diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rsindex a250cd0466..89e994664f 100644--- a/crates/openhuman-core/src/config/ops/agent.rs+++ b/crates/openhuman-core/src/config/ops/agent.rs@@ -626,6 +626,7 @@ pub async fn apply_agent_paths_settings("[config][agent_paths] apply files_dir edit (input_len={})",trimmed.len());+ let previous = config.files_dir();if trimmed.is_empty() {config.files_dir_override = None;notes.push("files_dir override cleared (reverted to default)".to_string());@@ -634,6 +635,11 @@ pub async fn apply_agent_paths_settings(notes.push(format!("files_dir set to {}", candidate.display()));config.files_dir_override = Some(candidate);}+ // Existing artifacts stay where they are, so the folder they were+ // made in must stay trusted by the artifact escape guard.+ if previous != config.files_dir() && !config.files_dir_history.contains(&previous) {+ config.files_dir_history.push(previous);+ }config.save().await.map_err(|e| e.to_string())?;crate::core::bus::BUS.publish(crate::core::events::DomainEvent::AgentPathsChanged);log::debug!(diff --git a/crates/openhuman-core/src/config/ops_files_dir_tests.rs b/crates/openhuman-core/src/config/ops_files_dir_tests.rsindex 1ee0de1985..c1bed915c8 100644--- a/crates/openhuman-core/src/config/ops_files_dir_tests.rs+++ b/crates/openhuman-core/src/config/ops_files_dir_tests.rs@@ -177,3 +177,52 @@ async fn a_symlinked_route_into_the_data_folder_is_rejected() {let err = rejected(&mut cfg, &alias.join("Files").to_string_lossy()).await;assert!(err.contains("OpenHuman data folder"), "{err}");}++/// Changing the folder affects new files only: a file made in the previous+/// folder keeps resolving, because that folder is recorded as trusted.+#[tokio::test]+async fn files_made_before_a_folder_change_keep_resolving() {+ use crate::agent::artifacts::store::{create_artifact, finalize_artifact};+ use crate::agent::artifacts::{ArtifactKind, FileRoots};++ let tmp = tempdir().unwrap();+ let mut cfg = tmp_config(&tmp);+ let first = tmp.path().join("First");+ let second = tmp.path().join("Second");+ apply_agent_paths_settings(&mut cfg, patch(&first.to_string_lossy()))+ .await+ .unwrap();+ let (meta, path) = create_artifact(+ &cfg.workspace_dir,+ FileRoots::from_config(&cfg),+ ArtifactKind::Document,+ "Plan",+ "docx",+ )+ .await+ .unwrap();+ std::fs::write(&path, b"plan").unwrap();+ finalize_artifact(&cfg.workspace_dir, &meta.id, 4)+ .await+ .unwrap();+ assert!(path.starts_with(&first));++ apply_agent_paths_settings(&mut cfg, patch(&second.to_string_lossy()))+ .await+ .unwrap();++ assert!(+ cfg.files_dir_history.contains(&first),+ "{:?}",+ cfg.files_dir_history+ );+ let value = crate::agent::artifacts::ops::ai_get_artifact(&cfg, &meta.id)+ .await+ .expect("an artifact from the previous folder still resolves")+ .into_cli_compatible_json()+ .unwrap();+ assert_eq!(+ value["absolute_path"],+ serde_json::json!(path.to_string_lossy())+ );+}diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rsindex 004f8be3a4..9e80960f27 100644--- a/crates/openhuman-core/src/config/schema/types/config.rs+++ b/crates/openhuman-core/src/config/schema/types/config.rs@@ -80,6 +80,13 @@ pub struct Config {/// existing ones keep the folder recorded in their metadata.#[serde(default)]pub files_dir_override: Option<PathBuf>,+ /// Files folders used before the current one. Artifacts created there keep+ /// resolving, because the artifact escape guard trusts only folders the+ /// core records here (plus the current one and the default), never a+ /// folder an artifact's own metadata claims. Appended by+ /// `config.update_agent_paths`.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub files_dir_history: Vec<PathBuf>,#[serde(skip)]pub config_path: PathBuf,/// Per-load snapshot used to remove standalone CLI inference overridesdiff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rsindex 116d072871..bbcff6b359 100644--- a/crates/openhuman-core/src/config/schema/types/defaults.rs+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs@@ -29,6 +29,7 @@ impl Default for Config {action_dir: crate::config::default_action_dir(),action_dir_override: None,files_dir_override: None,+ files_dir_history: Vec::new(),config_path: openhuman_dir.join("config.toml"),cli_inference_snapshot: None,recovered_from_corruption: false,diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rsindex 01c292b75c..37bb1a11e6 100644--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs@@ -51,7 +51,7 @@ pub struct MediaArtifactTool<T: Tool> {kind: ArtifactKind,workspace_dir: PathBuf,/// Visible folder each generated file is moved into (#5505).- files_dir: PathBuf,+ files_dir: crate::agent::artifacts::FileRoots,}impl<T: Tool> MediaArtifactTool<T> {@@ -63,7 +63,7 @@ impl<T: Tool> MediaArtifactTool<T> {inner: T,kind: ArtifactKind,workspace_dir: impl Into<PathBuf>,- files_dir: impl Into<PathBuf>,+ files_dir: impl Into<crate::agent::artifacts::FileRoots>,) -> Self {Self {inner,diff --git a/crates/openhuman-core/src/media/generation/tools.rs b/crates/openhuman-core/src/media/generation/tools.rsindex aeb8a779f6..12e293ad20 100644--- a/crates/openhuman-core/src/media/generation/tools.rs+++ b/crates/openhuman-core/src/media/generation/tools.rs@@ -54,7 +54,7 @@ pub fn build_media_tools(root_config: &Config, action_dir: &Path) -> Vec<Box<dyngenerators,action_dir,&root_config.workspace_dir,- &root_config.files_dir(),+ crate::agent::artifacts::FileRoots::from_config(root_config),WaitPolicy::new(VIDEO_POLL_INTERVAL, VIDEO_WAIT_BUDGET),)}@@ -66,9 +66,10 @@ pub fn media_tools_from(generators: MediaGenerators,action_dir: &Path,workspace_dir: &Path,- files_dir: &Path,+ files_dir: impl Into<crate::agent::artifacts::FileRoots>,video_wait: WaitPolicy,) -> Vec<Box<dyn Tool>> {+ let files = files_dir.into();let MediaGenerators { image, video } = generators;let output = MediaOutput::new(action_dir).with_reference_policy(reference_policy(action_dir, workspace_dir));@@ -81,7 +82,7 @@ pub fn media_tools_from(.with_category(ToolCategory::Workflow),ArtifactKind::Image,workspace_dir.to_path_buf(),- files_dir.to_path_buf(),+ files.clone(),)),Box::new(MediaArtifactTool::new(GenerateVideoTool::new(Arc::clone(&video), output)@@ -92,7 +93,7 @@ pub fn media_tools_from(.with_wait_policy(video_wait),ArtifactKind::Video,workspace_dir.to_path_buf(),- files_dir.to_path_buf(),+ files,)),Box::new(MediaListModelsTool { image, video }),];diff --git a/crates/openhuman-core/src/tools/impl/document/mod.rs b/crates/openhuman-core/src/tools/impl/document/mod.rsindex 4ef9b2d2a2..3fddd85825 100644--- a/crates/openhuman-core/src/tools/impl/document/mod.rs+++ b/crates/openhuman-core/src/tools/impl/document/mod.rs@@ -72,7 +72,7 @@ pub const TOOL_NAME: &str = "generate_document";pub struct DocumentTool {workspace_dir: PathBuf,/// Visible folder the generated document is written into (#5505).- files_dir: PathBuf,+ files_dir: crate::agent::artifacts::FileRoots,/// Retained for constructor parity with [`PresentationTool`] (both are/// registered identically in `tools::ops`) and for future features/// (e.g. embedding a `File`-source image) that will need the same@@ -86,10 +86,14 @@ impl DocumentTool {/// directory the artifact pipeline writes into, plus the active/// [`SecurityPolicy`] (same signature as [`PresentationTool::new`] so/// both tools register with an identical call).- pub fn new(workspace_dir: PathBuf, files_dir: PathBuf, security: Arc<SecurityPolicy>) -> Self {+ pub fn new(+ workspace_dir: PathBuf,+ files_dir: impl Into<crate::agent::artifacts::FileRoots>,+ security: Arc<SecurityPolicy>,+ ) -> Self {Self {workspace_dir,- files_dir,+ files_dir: files_dir.into(),security,}}@@ -97,7 +101,11 @@ impl DocumentTool {/// The agent-registry constructor: the artifact metadata goes to/// `config.workspace_dir`, the document to the files folder (#5505).pub fn for_config(config: &crate::config::Config, security: Arc<SecurityPolicy>) -> Self {- Self::new(config.workspace_dir.clone(), config.files_dir(), security)+ Self::new(+ config.workspace_dir.clone(),+ crate::agent::artifacts::FileRoots::from_config(config),+ security,+ )}}diff --git a/crates/openhuman-core/src/tools/impl/presentation/mod.rs b/crates/openhuman-core/src/tools/impl/presentation/mod.rsindex 8f95a99b20..d9547675ae 100644--- a/crates/openhuman-core/src/tools/impl/presentation/mod.rs+++ b/crates/openhuman-core/src/tools/impl/presentation/mod.rs@@ -68,7 +68,7 @@ pub const TOOL_NAME: &str = "generate_presentation";pub struct PresentationTool {workspace_dir: PathBuf,/// Visible folder the generated deck is written into (#5505).- files_dir: PathBuf,+ files_dir: crate::agent::artifacts::FileRoots,/// Existing host config when the caller already owns the authoritative/// runtime snapshot. Keeping this optional preserves the ordinary agent/// constructor while avoiding a process-global config reload during@@ -86,10 +86,14 @@ impl PresentationTool {/// resolution, venv setup, or cache directory needed. Pass the/// workspace directory the artifact pipeline writes into, plus the/// active [`SecurityPolicy`] for validating `File`-source image paths.- pub fn new(workspace_dir: PathBuf, files_dir: PathBuf, security: Arc<SecurityPolicy>) -> Self {+ pub fn new(+ workspace_dir: PathBuf,+ files_dir: impl Into<crate::agent::artifacts::FileRoots>,+ security: Arc<SecurityPolicy>,+ ) -> Self {Self {workspace_dir,- files_dir,+ files_dir: files_dir.into(),config: None,security,}@@ -98,19 +102,23 @@ impl PresentationTool {/// The agent-registry constructor: the artifact metadata goes to/// `config.workspace_dir`, the deck to the files folder (#5505).pub fn for_config(config: &crate::config::Config, security: Arc<SecurityPolicy>) -> Self {- Self::new(config.workspace_dir.clone(), config.files_dir(), security)+ Self::new(+ config.workspace_dir.clone(),+ crate::agent::artifacts::FileRoots::from_config(config),+ security,+ )}/// Construct the tool with an authoritative host config snapshot.pub(crate) fn with_config(workspace_dir: PathBuf,- files_dir: PathBuf,+ files_dir: impl Into<crate::agent::artifacts::FileRoots>,security: Arc<SecurityPolicy>,config: crate::config::Config,) -> Self {Self {workspace_dir,- files_dir,+ files_dir: files_dir.into(),config: Some(config),security,}