diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs index 2b9f7cfbaa6..61e05a99c74 100644 --- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs +++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs @@ -404,12 +404,11 @@ impl SessionHostBuilder { }); let hosted_base = definitions.map(|definitions| { Arc::new(crate::agent::tinyagents::host::OpenHumanHostBase { + // A caller-supplied policy wins. Otherwise `hosted_config`'s own dirs + // were just set from these two, so this is the same policy plus the + // config's account root. security_policy: security_policy.clone().unwrap_or_else(|| { - Arc::new(crate::security::SecurityPolicy::from_config( - &hosted_config.autonomy, - &workspace_dir, - &action_dir, - )) + Arc::new(crate::security::SecurityPolicy::for_config(&hosted_config)) }), config: Arc::clone(&hosted_config), definitions, diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs b/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs index 0f523288e7c..b3ce33fee4c 100644 --- a/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs +++ b/crates/openhuman-core/src/agent/session_host/builder/factory/build_session.rs @@ -20,11 +20,7 @@ impl OpenHumanSessionHost { let runtime: Arc = Arc::from( host_runtime::create_runtime(&config.runtime, config.shell.hide_window)?, ); - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(config)); let audit = crate::security::get_or_create_workspace_audit_sink( config.audit.clone(), config.workspace_dir.clone(), diff --git a/crates/openhuman-core/src/artifacts/ops.rs b/crates/openhuman-core/src/artifacts/ops.rs index ca9e471d499..866032fae0b 100644 --- a/crates/openhuman-core/src/artifacts/ops.rs +++ b/crates/openhuman-core/src/artifacts/ops.rs @@ -205,11 +205,7 @@ async fn regenerate_presentation( // A fresh policy from the live config — cheap, sync, and mirrors how // the agent harness builds the same tool (see `tools::ops`). - let security = std::sync::Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = std::sync::Arc::new(SecurityPolicy::for_config(config)); // The regenerate target is an explicit constructor argument of the tool // that produces the artifact: its `create_artifact_regenerating` call // reuses this id instead of minting a new one. diff --git a/crates/openhuman-core/src/attachments/mod.rs b/crates/openhuman-core/src/attachments/mod.rs index e10113692be..89dcdba7854 100644 --- a/crates/openhuman-core/src/attachments/mod.rs +++ b/crates/openhuman-core/src/attachments/mod.rs @@ -210,7 +210,7 @@ pub(crate) async fn thread_action_dir( } fn policy(config: &Config, root: &Path) -> SecurityPolicy { - let policy = SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, root); + let policy = SecurityPolicy::for_config_in(config, root); *policy .media_files_roots .lock() diff --git a/crates/openhuman-core/src/attachments/provider_cache.rs b/crates/openhuman-core/src/attachments/provider_cache.rs index a09f71d3dcd..398055f5c0a 100644 --- a/crates/openhuman-core/src/attachments/provider_cache.rs +++ b/crates/openhuman-core/src/attachments/provider_cache.rs @@ -72,11 +72,7 @@ impl AttachmentModel { .parent()? .join(".openhuman-derived") .join("readout.txt"); - let policy = crate::security::SecurityPolicy::from_config( - &self.config.autonomy, - &self.config.workspace_dir, - &root, - ); + let policy = crate::security::SecurityPolicy::for_config_in(&self.config, &root); if !policy .path_allowed(crate::security::policy::PathKind::ResolvedWrite, &cache) .await @@ -132,11 +128,7 @@ impl AttachmentModel { }; let parent = cache.parent().expect("derivative parent"); let root = super::super::action_root(&self.config, scope); - let policy = crate::security::SecurityPolicy::from_config( - &self.config.autonomy, - &self.config.workspace_dir, - &root, - ); + let policy = crate::security::SecurityPolicy::for_config_in(&self.config, &root); if policy .validate_parent_path(&cache.to_string_lossy()) .await diff --git a/crates/openhuman-core/src/attachments/provider_source.rs b/crates/openhuman-core/src/attachments/provider_source.rs index e0cc5d47775..cf271320e0b 100644 --- a/crates/openhuman-core/src/attachments/provider_source.rs +++ b/crates/openhuman-core/src/attachments/provider_source.rs @@ -209,11 +209,7 @@ impl AttachmentModel { .join(id) .join(super::super::filename(name)); let root = super::super::action_root(&self.config, scope); - let preliminary = crate::security::SecurityPolicy::from_config( - &self.config.autonomy, - &self.config.workspace_dir, - &root, - ); + let preliminary = crate::security::SecurityPolicy::for_config_in(&self.config, &root); preliminary .validate_parent_path(&root.join(&relative).to_string_lossy()) .await @@ -224,11 +220,7 @@ impl AttachmentModel { let root = tokio::fs::canonicalize(root) .await .map_err(|e| tinyinference_llm::Error::Model(e.to_string()))?; - let policy = crate::security::SecurityPolicy::from_config( - &self.config.autonomy, - &self.config.workspace_dir, - &root, - ); + let policy = crate::security::SecurityPolicy::for_config_in(&self.config, &root); let path = root.join(&relative); policy .validate_parent_path(&path.to_string_lossy()) diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs index 4ab1767c77c..2afbb15c3ab 100644 --- a/crates/openhuman-core/src/channels/providers/relay/ops.rs +++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs @@ -191,10 +191,8 @@ pub(crate) async fn run_relay_turn( } }; - let security = Arc::new( - SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir) - .with_privacy_mode(config.privacy.mode), - ); + let security = + Arc::new(SecurityPolicy::for_config(&config).with_privacy_mode(config.privacy.mode)); let parts = match build_channel_turn_parts( &dispatch_ctx, &config, diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs index 36003f6fac4..3c3919108a4 100644 --- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs +++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs @@ -75,12 +75,9 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) -> // and picked up by the next session. let security = crate::security::live_policy::install( Arc::new( - SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ) - .with_privacy_mode(config.privacy.mode), + SecurityPolicy::for_config(&config) + // `for_config` already attaches the config's account root. + .with_privacy_mode(config.privacy.mode), ), config.workspace_dir.clone(), config.action_dir.clone(), diff --git a/crates/openhuman-core/src/core/runtime/bootstrap.rs b/crates/openhuman-core/src/core/runtime/bootstrap.rs index be4d9191fdf..dd4722de767 100644 --- a/crates/openhuman-core/src/core/runtime/bootstrap.rs +++ b/crates/openhuman-core/src/core/runtime/bootstrap.rs @@ -236,7 +236,8 @@ pub(crate) async fn bootstrap_core_runtime( &workspace_dir, &action_dir, ) - .with_privacy_mode(cfg.privacy.mode), + .with_privacy_mode(cfg.privacy.mode) + .with_account_dir(cfg.config_path.parent()), ), workspace_dir.clone(), action_dir, @@ -345,8 +346,8 @@ pub(crate) async fn bootstrap_core_runtime( let _ = crate::security::approval::ApprovalGate::init_global(cfg.clone(), session_id.clone()); log::info!( - "[runtime] approval gate installed (on by default; set OPENHUMAN_APPROVAL_GATE=0 to disable, session_id={session_id}) — \ - Prompt-class external-effect tool calls park for approval in interactive chat turns" + "[runtime] approval gate installed (on by default; set OPENHUMAN_APPROVAL_GATE=0 to disable, session_id={session_id}) — {}", + crate::security::approval::gate::arming_note(cfg.autonomy.enabled) ); // (The approval/plan-review surface bridge is registered unconditionally // above — it must run even when this gate-install branch is skipped.) diff --git a/crates/openhuman-core/src/cron/ops.rs b/crates/openhuman-core/src/cron/ops.rs index 62ecf653a9a..01ebbf1809c 100644 --- a/crates/openhuman-core/src/cron/ops.rs +++ b/crates/openhuman-core/src/cron/ops.rs @@ -86,11 +86,7 @@ pub async fn cron_update( crate::core::runtime::components::require_config(config, "tinyflows")?; if let Some(command) = &patch.command { - let security = SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ); + let security = SecurityPolicy::for_config(config); crate::cron::scheduler::shell_job::authorize_shell_command(config, &security, command) .await?; } diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rs index 43f713b9a47..086d7f848e0 100644 --- a/crates/openhuman-core/src/cron/scheduler.rs +++ b/crates/openhuman-core/src/cron/scheduler.rs @@ -68,11 +68,7 @@ pub async fn run(ctx: &crate::core::runtime::DispatchCtx, config: Config) -> Res let poll_secs = config.reliability.scheduler_poll_secs.max(5); let mut interval = time::interval(Duration::from_secs(poll_secs)); - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(&config)); BUS.publish(DomainEvent::SystemStartup { component: "scheduler".to_string(), diff --git a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs index b8023a2adc3..6162ff796d6 100644 --- a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs +++ b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs @@ -81,11 +81,7 @@ async fn own_manual_run( // Keep the invocation's CoreContext strongly pinned while Binding itself // retains only a Weak reference. The task is the acyclic lifetime owner. let _context_pin = ctx.core().cloned(); - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(&config)); let binding = Binding::new(&ctx, &config, security); let host = bus_host::register(binding.clone()) .await diff --git a/crates/openhuman-core/src/cron/schemas/handlers.rs b/crates/openhuman-core/src/cron/schemas/handlers.rs index b0d89e16daf..7c1074d564b 100644 --- a/crates/openhuman-core/src/cron/schemas/handlers.rs +++ b/crates/openhuman-core/src/cron/schemas/handlers.rs @@ -81,11 +81,7 @@ pub(super) fn handle_add(ctx: DispatchCtx, params: Map) -> Contro let job = match job_type { "shell" => { let cmd = command.ok_or("'command' is required for shell jobs")?; - let security = crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ); + let security = crate::security::SecurityPolicy::for_config(&config); crate::cron::scheduler::shell_job::authorize_shell_command( &config, &security, &cmd, ) diff --git a/crates/openhuman-core/src/flows/authoring_host.rs b/crates/openhuman-core/src/flows/authoring_host.rs index d5a691dfbaf..e56cf626c23 100644 --- a/crates/openhuman-core/src/flows/authoring_host.rs +++ b/crates/openhuman-core/src/flows/authoring_host.rs @@ -126,11 +126,7 @@ impl ApprovalCallbacks { use crate::security::SecurityPolicy; use tinyflows_bus::catalog::{ManifestCandidate, ManifestClass}; - let security = SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ); + let security = SecurityPolicy::for_config(&config); async fn gated( security: &SecurityPolicy, class: CommandClass, diff --git a/crates/openhuman-core/src/flows/caps_host/binding.rs b/crates/openhuman-core/src/flows/caps_host/binding.rs index 1fe57a8bbfd..5e1df72793a 100644 --- a/crates/openhuman-core/src/flows/caps_host/binding.rs +++ b/crates/openhuman-core/src/flows/caps_host/binding.rs @@ -182,11 +182,7 @@ pub(crate) async fn serve( }, }; let ctx = ctx.with_turn_origin(origin); - let security = Arc::new(crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(crate::security::SecurityPolicy::for_config(&config)); let approval = crate::security::approval::ApprovalTurnContext { flow_run: Some(crate::security::approval::FlowRunContext { flow_id: flow_id.clone(), diff --git a/crates/openhuman-core/src/hooks/host.rs b/crates/openhuman-core/src/hooks/host.rs index 372b933e1b4..d57a82118e2 100644 --- a/crates/openhuman-core/src/hooks/host.rs +++ b/crates/openhuman-core/src/hooks/host.rs @@ -65,12 +65,8 @@ async fn admit_command_hooks(ctx: &DispatchCtx, loaded: &mut HookConfig) { // The configured privacy mode, not only the live one: hooks load // before the live policy is installed, and with security off the // local-only refusal of network commands reads the policy's mode. - crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ) - .with_privacy_mode(config.privacy.mode) + crate::security::SecurityPolicy::for_config(&config) + .with_privacy_mode(config.privacy.mode) }) .map_err(|error| error.to_string()); let mut refused = Vec::new(); diff --git a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs b/crates/openhuman-core/src/inference/host_runtime/service/speech.rs index ee3dc0afc92..d70f9be94b5 100644 --- a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs +++ b/crates/openhuman-core/src/inference/host_runtime/service/speech.rs @@ -197,11 +197,7 @@ async fn validated_tts_output_path( let candidate_string = candidate .to_str() .ok_or_else(|| "invalid output_path".to_string())?; - let mut policy = crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ); + let mut policy = crate::security::SecurityPolicy::for_config(config); policy.trusted_roots.push(crate::security::TrustedRoot { path: config.workspace_dir.display().to_string(), access: crate::security::TrustedAccess::ReadWrite, diff --git a/crates/openhuman-core/src/integrations/prelude_integrations.rs b/crates/openhuman-core/src/integrations/prelude_integrations.rs index 519b755ef0e..069a04cfe2c 100644 --- a/crates/openhuman-core/src/integrations/prelude_integrations.rs +++ b/crates/openhuman-core/src/integrations/prelude_integrations.rs @@ -339,11 +339,7 @@ impl OpenHumanTurnPrelude { .mcp_tools .configured .clone(); - let security = Arc::new(crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(crate::security::SecurityPolicy::for_config(config)); crate::tools::implementations::network::configured_server_tools_from_presentations( config, presentations, diff --git a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs index 9258c9cff7b..d18908aa713 100644 --- a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs +++ b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs @@ -182,8 +182,7 @@ async fn enforce_read_policy(ctx: &DispatchCtx, tool_name: &str) -> Result<(), T ))); } }; - let policy = - SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir); + let policy = SecurityPolicy::for_config(&config); // A policy denial *is* something the caller can act on (toggle autonomy, // approve the tool) — keep that as `InvalidParams` so clients surface the // reason text instead of a generic internal-error banner. @@ -205,8 +204,7 @@ async fn enforce_act_policy(ctx: &DispatchCtx, tool_name: &str) -> Result<(), To ))); } }; - let policy = - SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir); + let policy = SecurityPolicy::for_config(&config); policy .enforce_tool_operation(ToolOperation::Act, tool_name) .await diff --git a/crates/openhuman-core/src/mcp/server/write_dispatch.rs b/crates/openhuman-core/src/mcp/server/write_dispatch.rs index 15f24f9891a..bb64ae43504 100644 --- a/crates/openhuman-core/src/mcp/server/write_dispatch.rs +++ b/crates/openhuman-core/src/mcp/server/write_dispatch.rs @@ -35,8 +35,7 @@ pub(super) async fn enforce_write_policy_for_config( tool_name: &str, config: &Config, ) -> Result<(), ToolCallError> { - let policy = - SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir); + let policy = SecurityPolicy::for_config(config); match policy .enforce_tool_operation(ToolOperation::Act, tool_name) .await diff --git a/crates/openhuman-core/src/mcp/ui/schemas.rs b/crates/openhuman-core/src/mcp/ui/schemas.rs index 67ea603a43a..ce6b1a6fdb6 100644 --- a/crates/openhuman-core/src/mcp/ui/schemas.rs +++ b/crates/openhuman-core/src/mcp/ui/schemas.rs @@ -108,13 +108,8 @@ fn handle_tool_call(ctx: DispatchCtx, params: Map) -> ControllerF let arguments = params.get("arguments").cloned(); let confirmed = read_optional::(¶ms, "confirmed")?.unwrap_or(false); let config = ctx.load_config().await?; - let security = crate::security::live_policy::current().unwrap_or_else(|| { - Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )) - }); + let security = crate::security::live_policy::current() + .unwrap_or_else(|| Arc::new(SecurityPolicy::for_config(&config))); let port = HostUiPort::new(Arc::new(config)); let outcome = ops::tool_call(&port, &security, server_id, tool_name, arguments, confirmed).await?; diff --git a/crates/openhuman-core/src/memory/brain.rs b/crates/openhuman-core/src/memory/brain.rs index 0aae9513dd3..6892cdebb7a 100644 --- a/crates/openhuman-core/src/memory/brain.rs +++ b/crates/openhuman-core/src/memory/brain.rs @@ -157,11 +157,7 @@ pub struct BrainIngestView { /// /// [`SecurityPolicy::validate_path`]: crate::security::SecurityPolicy::validate_path async fn ingest_path(config: &Config, path: &str) -> Result { - let policy = crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ); + let policy = crate::security::SecurityPolicy::for_config(config); policy.validate_path(path.trim()).await.map_err(|error| { tracing::warn!("[memory:brain] ingest path refused by the security policy"); Error::InvalidRequest(format!("cannot read the file: {error}")) diff --git a/crates/openhuman-core/src/profiles/capabilities.rs b/crates/openhuman-core/src/profiles/capabilities.rs index 593cc149bff..e98ae4bf705 100644 --- a/crates/openhuman-core/src/profiles/capabilities.rs +++ b/crates/openhuman-core/src/profiles/capabilities.rs @@ -168,11 +168,7 @@ impl ProfileCapabilities { // profile. The named packs narrow registration within those domains. let assembly = ctx.derive_with(ContextOverlay::new(config.clone(), ctx.domains(), groups)); - let security = Arc::new(crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(crate::security::SecurityPolicy::for_config(config)); let native = CoreContext::scope(assembly, async { crate::tools::ops::all_tools( Arc::new(config.clone()), diff --git a/crates/openhuman-core/src/profiles/cron.rs b/crates/openhuman-core/src/profiles/cron.rs index bfd1f58fa06..afe2fc68c8a 100644 --- a/crates/openhuman-core/src/profiles/cron.rs +++ b/crates/openhuman-core/src/profiles/cron.rs @@ -104,11 +104,7 @@ pub async fn sweep(host: &ProfileHost, now: DateTime) -> SweepReport { let profile_config = profile.config.clone(); let profile_ctx = Arc::clone(profile.context()); let outcome = CoreContext::scope(Arc::clone(&profile_ctx), async move { - let security = Arc::new(crate::security::SecurityPolicy::from_config( - &profile_config.autonomy, - &profile_config.workspace_dir, - &profile_config.action_dir, - )); + let security = Arc::new(crate::security::SecurityPolicy::for_config(&profile_config)); let dispatch = crate::core::runtime::DispatchCtx::new(Arc::clone(&profile_ctx)); let mut dispatcher = JobDispatcher::new(&dispatch, &profile_config, &security).agent_only(); diff --git a/crates/openhuman-core/src/profiles/host.rs b/crates/openhuman-core/src/profiles/host.rs index b505e4fbc64..d474d5efcef 100644 --- a/crates/openhuman-core/src/profiles/host.rs +++ b/crates/openhuman-core/src/profiles/host.rs @@ -670,12 +670,7 @@ pub(super) fn create_dirs(layout: &ProfileLayout) -> Result<(), String> { /// its workspace and sandbox, never the operator's live policy. fn profile_policy(config: &Config) -> Arc { Arc::new( - crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ) - .with_privacy_mode(config.privacy.mode), + crate::security::SecurityPolicy::for_config(config).with_privacy_mode(config.privacy.mode), ) } diff --git a/crates/openhuman-core/src/sandbox/spawn_plan/facts.rs b/crates/openhuman-core/src/sandbox/spawn_plan/facts.rs index fb588b00000..673c1f512a4 100644 --- a/crates/openhuman-core/src/sandbox/spawn_plan/facts.rs +++ b/crates/openhuman-core/src/sandbox/spawn_plan/facts.rs @@ -169,12 +169,7 @@ fn configured(config: &Config) -> bool { /// chose for this spawn (its workspace and the mounts it resolved). The module still /// refuses the protected floor and the core's internal state under every root. fn paths(config: &Config, policy: &SandboxPolicy) -> PathPolicy { - let mut paths = crate::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - ) - .native_path_policy(); + let mut paths = crate::security::SecurityPolicy::for_config(config).native_path_policy(); // Reserved names protect internal files from the path tools (`.env`, `SOUL.md`...) // wherever they sit under the action dir. A jail's workspace grant is the whole // action dir by design, so under that rule no workspace could ever be granted. diff --git a/crates/openhuman-core/src/security/approval/gate.rs b/crates/openhuman-core/src/security/approval/gate.rs index ae866680389..a20227c87c3 100644 --- a/crates/openhuman-core/src/security/approval/gate.rs +++ b/crates/openhuman-core/src/security/approval/gate.rs @@ -542,6 +542,47 @@ fn publish_flow_gate_notification( }); } +/// What an installed gate will actually park, given the autonomy policy's +/// master switch. +/// +/// The gate is installed independently of `[autonomy] enabled`, but what +/// *reaches* it is not. A tool declares itself external-effect through +/// [`crate::security::SecurityPolicy::gate_decision`], which returns +/// `GateDecision::Allow` for every [`crate::security::CommandClass`] while the +/// policy is off — and off is the shipped default +/// (`AutonomyConfig::enabled = false`). `shell`, `node_exec`, `npm_exec` and +/// `python_exec` once derived `external_effect_with_args` from exactly that +/// call. **That is no longer how it works**, and the note must not say so: a +/// `shell` call reaches the gate (`ShellTool` declares an external effect for +/// any non-empty command) and is settled by the shell-specific stage, +/// `SecurityGate::shell_decision`, which classifies the command and returns +/// `gate_decision`. With the policy off that answers `Allow`, so the call is +/// **allowed without parking** — not "reports no external effect". +/// +/// Only that stage is shell-specific. A tool that declares an external effect +/// outright and never goes through `shell_decision` still parks with the policy +/// off — `ScheduleTool` returns `true` for every mutating action independently +/// of [`crate::security::SecurityPolicy`] — so the disabled note must not claim +/// that nothing parks at all. +/// +/// Describe the outcome, not the mechanism: an earlier revision of this note +/// named four tools and an internal reason, and both went stale within a week +/// when the shell authorization path was rebuilt on TinyBox analysis upstream. +/// +/// The boot line is the one place an operator learns whether they are +/// protected, so it must not claim a park that cannot happen. +pub(crate) fn arming_note(autonomy_enabled: bool) -> &'static str { + if autonomy_enabled { + "Prompt-class external-effect tool calls park for approval in interactive chat turns" + } else { + "shell commands are allowed without parking: [autonomy] enabled = false (the shipped \ + default) makes gate_decision() answer Allow for every command class, so the shell \ + decision stage settles the call instead of parking it. Tools that declare an external \ + effect outright (schedule, channel sends, …) still park — set [autonomy] enabled = true \ + to gate commands too" + } +} + #[cfg(test)] #[path = "gate_tests.rs"] mod tests; diff --git a/crates/openhuman-core/src/security/approval/gate_tests.rs b/crates/openhuman-core/src/security/approval/gate_tests.rs index 59b334d05f1..261da6511ec 100644 --- a/crates/openhuman-core/src/security/approval/gate_tests.rs +++ b/crates/openhuman-core/src/security/approval/gate_tests.rs @@ -239,3 +239,21 @@ mod triage_tests; mod ttl_and_triage_tests; #[path = "gate_turn_context_tests.rs"] mod turn_context_tests; + +/// The boot line is where an operator learns whether the installed gate can +/// park anything, so it must track `[autonomy] enabled` rather than assert a +/// park unconditionally. +#[test] +fn arming_note_tracks_the_autonomy_master_switch() { + assert!(arming_note(true).contains("park for approval")); + + let disabled = arming_note(false); + // Scoped to the four command tools, and explicit that other + // external-effect tools still park — `ScheduleTool` returns `true` for + // every mutating action regardless of the policy. + assert!(disabled.contains("allowed without parking"), "{disabled}"); + assert!(!disabled.contains("no external effect"), "{disabled}"); + assert!(disabled.contains("still park"), "{disabled}"); + assert!(disabled.contains("[autonomy] enabled = true"), "{disabled}"); + assert!(!disabled.contains("nothing parks"), "{disabled}"); +} diff --git a/crates/openhuman-core/src/security/live_policy.rs b/crates/openhuman-core/src/security/live_policy.rs index 9018a7e55ff..8732d72c021 100644 --- a/crates/openhuman-core/src/security/live_policy.rs +++ b/crates/openhuman-core/src/security/live_policy.rs @@ -25,6 +25,11 @@ struct LiveState { policy: RwLock>, workspace_dir: RwLock, action_dir: RwLock, + /// Stored account / credential root so an autonomy-only [`reload_from`] + /// preserves it. `from_config` cannot infer it (see + /// [`SecurityPolicy::account_dir`]), so without this a reload would + /// silently fall back to guarding `workspace_dir`'s parent. + account_dir: RwLock>, /// Stored Privacy Mode so an autonomy-only [`reload_from`] preserves the /// active mode (autonomy config carries no privacy field) and a later /// [`reload_privacy`] can swap it without rebuilding from a full `Config`. @@ -47,6 +52,7 @@ pub fn install( policy: RwLock::new(Arc::clone(&policy)), workspace_dir: RwLock::new(workspace_dir.clone()), action_dir: RwLock::new(action_dir.clone()), + account_dir: RwLock::new(policy.account_dir.clone()), privacy_mode: RwLock::new(policy.privacy_mode), generation: AtomicU64::new(0), }); @@ -66,6 +72,11 @@ pub fn install( if let Ok(mut guard) = state.privacy_mode.write() { *guard = policy.privacy_mode; } + // Same reasoning as the privacy mode above: re-seed on every install, not + // just the first, or a reload rebuilds without the account root. + if let Ok(mut guard) = state.account_dir.write() { + *guard = policy.account_dir.clone(); + } log::debug!( "[privacy][live_policy] installed policy with privacy_mode={:?}", policy.privacy_mode @@ -233,9 +244,15 @@ pub fn reload_from(autonomy_config: &crate::config::AutonomyConfig) { // privacy mode so an autonomy-only change does not silently reset egress // posture (autonomy config carries no privacy field). let stored_privacy = state.privacy_mode.read().map(|g| *g).unwrap_or_default(); + let stored_account = state + .account_dir + .read() + .map(|g| g.clone()) + .unwrap_or_default(); let rebuilt = Arc::new( SecurityPolicy::from_config(autonomy_config, &workspace, &action) - .with_privacy_mode(stored_privacy), + .with_privacy_mode(stored_privacy) + .with_account_dir(stored_account.as_deref()), ); *policy_guard = rebuilt; drop(policy_guard); diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs index 6e92ae54c94..59d0e391340 100644 --- a/crates/openhuman-core/src/security/live_policy_tests.rs +++ b/crates/openhuman-core/src/security/live_policy_tests.rs @@ -80,11 +80,21 @@ fn install_then_reload_swaps_policy_and_bumps_generation() { // which all take this same lock — otherwise a parallel install races. let _env = crate::config::TEST_ENV_LOCK.blocking_lock(); let workspace = std::env::temp_dir().join("openhuman_live_policy_test"); - let initial = Arc::new(SecurityPolicy { - autonomy: AutonomyLevel::Supervised, - workspace_dir: workspace.clone(), - ..SecurityPolicy::default() - }); + // The account root rides along on this cycle rather than in a test of its + // own: asserting it needs an install and a reload, and a third test + // mutating this process-global measurably destabilises the env-sensitive + // tests that read it (an added install/reload cycle turned the suite from + // 2/2 green into an intermittent failure in `trusted_roots` and the + // approval origin-intercept tests). + let account = workspace.join("account"); + let initial = Arc::new( + SecurityPolicy { + autonomy: AutonomyLevel::Supervised, + workspace_dir: workspace.clone(), + ..SecurityPolicy::default() + } + .with_account_dir(Some(account.as_path())), + ); install(initial, workspace.clone(), workspace.clone()); let before = generation(); @@ -102,9 +112,17 @@ fn install_then_reload_swaps_policy_and_bumps_generation() { reload_from(&cfg); assert!(generation() > before, "generation must increase on reload"); + let after = current().expect("policy still installed"); + assert_eq!(after.autonomy, AutonomyLevel::Full); + // `reload_from` rebuilds through `from_config`, which cannot infer the + // account root (it is not derivable from `workspace_dir`). Without the + // stored copy the field would be right at boot and silently lost on the + // first `config.update_autonomy_settings` — the predicate would still run, + // just against the wrong directory. assert_eq!( - current().expect("policy still installed").autonomy, - AutonomyLevel::Full + after.account_dir.as_deref(), + Some(account.as_path()), + "the configured account root must survive a reload" ); } diff --git a/crates/openhuman-core/src/security/ops.rs b/crates/openhuman-core/src/security/ops.rs index 7ba43d8d883..4a390c6138f 100644 --- a/crates/openhuman-core/src/security/ops.rs +++ b/crates/openhuman-core/src/security/ops.rs @@ -19,8 +19,7 @@ fn policy_info_payload(policy: SecurityPolicy) -> serde_json::Value { } pub fn security_policy_info_for_config(config: &Config) -> Outcome { - let policy = - SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir); + let policy = SecurityPolicy::for_config(config); let payload = policy_info_payload(policy); Outcome::single_log(payload, "security_policy_info computed from active config") } diff --git a/crates/openhuman-core/src/security/policy/enforcement.rs b/crates/openhuman-core/src/security/policy/enforcement.rs index a37c9353ffd..72dc90f06bb 100644 --- a/crates/openhuman-core/src/security/policy/enforcement.rs +++ b/crates/openhuman-core/src/security/policy/enforcement.rs @@ -451,6 +451,10 @@ impl SecurityPolicy { // effective enforcement mode correct without touching every caller. privacy_mode: crate::config::PrivacyMode::default(), workspace_dir: workspace_dir.to_path_buf(), + // The caller layers the real credential root on with + // `with_account_dir`; unset keeps the `workspace_dir`-parent + // inference every existing call site already relied on. + account_dir: None, action_dir: action_dir.to_path_buf(), workspace_only: autonomy_config.workspace_only, allowed_commands: autonomy_config.allowed_commands.clone(), @@ -486,6 +490,45 @@ impl SecurityPolicy { self } + /// [`from_config`](Self::from_config) for a whole [`Config`], with that + /// config's own account root attached. + /// + /// This is the form almost every caller wants, and the reason it exists is + /// that the alternative is a footgun: the account root is not derivable + /// from `workspace_dir` (see [`SecurityPolicy::account_dir`]), so it has to + /// be chained on, and a carve-out that silently does not apply wherever one + /// call site forgot is worse than no carve-out — you cannot tell the two + /// apart by reading the predicate. Prefer this over `from_config` wherever + /// a `Config` is in hand. + #[must_use] + pub fn for_config(config: &crate::config::Config) -> Self { + Self::for_config_in(config, &config.action_dir) + } + + /// [`for_config`](Self::for_config) with the action root overridden, for the + /// callers that scope a policy to a directory of their own (an attachment + /// root, a turn workspace) rather than the config's `action_dir`. + #[must_use] + pub fn for_config_in(config: &crate::config::Config, action_dir: &Path) -> Self { + Self::from_config(&config.autonomy, &config.workspace_dir, action_dir) + .with_account_dir(config.config_path.parent()) + } + + /// Return a copy of this policy with the account / credential root set — + /// `config_path`'s parent, which is not always `workspace_dir`'s parent + /// (see [`SecurityPolicy::account_dir`]). Builder-style to match + /// [`with_privacy_mode`](Self::with_privacy_mode), so a call site reads as + /// `SecurityPolicy::from_config(..).with_account_dir(config.config_path.parent())`. + #[must_use] + pub fn with_account_dir(mut self, account_dir: Option<&Path>) -> Self { + self.account_dir = account_dir.map(Path::to_path_buf); + log::debug!( + "[openhuman:policy] account dir set on SecurityPolicy: {:?}", + self.account_dir + ); + self + } + /// The active data-egress posture (Privacy Mode). Read by the inference /// chokepoint to enforce local-only model routing; later slices (S4/S7) also /// branch on `Sensitive` here. diff --git a/crates/openhuman-core/src/security/policy/mod.rs b/crates/openhuman-core/src/security/policy/mod.rs index d56a3c9f220..7731d0f26d7 100644 --- a/crates/openhuman-core/src/security/policy/mod.rs +++ b/crates/openhuman-core/src/security/policy/mod.rs @@ -30,6 +30,10 @@ use std::path::PathBuf; #[path = "policy_tests.rs"] mod tests; +#[cfg(test)] +#[path = "native_paths_tests.rs"] +mod native_paths_tests; + #[cfg(all(test, feature = "security-module"))] #[path = "policy_media_artifact_tests.rs"] mod policy_media_artifact_tests; diff --git a/crates/openhuman-core/src/security/policy/native_paths.rs b/crates/openhuman-core/src/security/policy/native_paths.rs index 5afaae9187e..551a601ca3c 100644 --- a/crates/openhuman-core/src/security/policy/native_paths.rs +++ b/crates/openhuman-core/src/security/policy/native_paths.rs @@ -11,8 +11,9 @@ use tinysecurity_bus::{ }; use super::types::{ - SecurityPolicy, TrustedAccess, ACCOUNT_CONFIG_FILE, ARTIFACTS_DIR, ARTIFACT_TOOL_RESULTS_DIR, - WORKSPACE_INTERNAL_DIRS, WORKSPACE_INTERNAL_FILES, WORKSPACE_INTERNAL_PREFIXES, + SecurityPolicy, TrustedAccess, ACCOUNT_CONFIG_FILE, ACCOUNT_INTERNAL_FILES, ARTIFACTS_DIR, + ARTIFACT_TOOL_RESULTS_DIR, WORKSPACE_INTERNAL_DIRS, WORKSPACE_INTERNAL_FILES, + WORKSPACE_INTERNAL_PREFIXES, }; use tinytools::status::POLICY_BLOCKED_MARKER; @@ -49,12 +50,40 @@ impl SecurityPolicy { children_only: false, }) .collect(); - if let Some(account_dir) = self.workspace_dir.parent() { + // The account dir is reachable on purpose — a trusted root over it + // grants its files (#5505) — so its secrets and privilege files are + // carved out by name rather than contained. Reserving them here hands + // the module the comparison, so canonicalisation and the case/Unicode + // folding it applies on normalising filesystems come for free; an agent + // cannot reach `.secret_key` through a symlinked root or create + // `CLAUDE_CODE_SETTINGS.JSON` where the provider later reads the lower + // case name. + // + // The explicit root takes the whole list; `workspace_dir`'s parent is + // only a fallback, so it keeps the single name it has always refused — + // once the two directories diverge, the parent is not the account dir + // and must not have its other files reserved. + let mut reserve_name = |dir: &std::path::Path, name: &str| { + let path = dir.join(name); + if reserved_paths + .iter() + .any(|reservation: &PathReservation| reservation.path == path) + { + return; + } reserved_paths.push(PathReservation { - path: account_dir.join(ACCOUNT_CONFIG_FILE), + path, exceptions: Vec::new(), children_only: false, }); + }; + if let Some(account_dir) = self.account_dir.as_deref() { + for name in ACCOUNT_INTERNAL_FILES { + reserve_name(account_dir, name); + } + } + if let Some(workspace_parent) = self.workspace_dir.parent() { + reserve_name(workspace_parent, ACCOUNT_CONFIG_FILE); } let tool_results = self .workspace_dir diff --git a/crates/openhuman-core/src/security/policy/native_paths_tests.rs b/crates/openhuman-core/src/security/policy/native_paths_tests.rs new file mode 100644 index 00000000000..d5d5ecbc8ad --- /dev/null +++ b/crates/openhuman-core/src/security/policy/native_paths_tests.rs @@ -0,0 +1,186 @@ +use super::types::{ACCOUNT_CONFIG_FILE, ACCOUNT_INTERNAL_FILES}; +use super::*; + +/// The reserved paths the host hands TinySecurity, as plain path buffers. +fn reserved(policy: &SecurityPolicy) -> Vec { + policy + .native_path_policy() + .reserved_paths + .into_iter() + .map(|reservation| reservation.path) + .collect() +} + +fn policy_with(workspace: &str, account: Option<&str>) -> SecurityPolicy { + SecurityPolicy { + enabled: true, + workspace_dir: PathBuf::from(workspace), + account_dir: account.map(PathBuf::from), + ..SecurityPolicy::default() + } +} + +#[test] +fn the_account_root_reserves_every_internal_file_not_just_the_config() { + // The split layout: internal state was moved, the credential root stayed. + let policy = policy_with("/proj/workspace", Some("/proj/.openhuman")); + let reserved = reserved(&policy); + + for name in ACCOUNT_INTERNAL_FILES { + let expected = PathBuf::from("/proj/.openhuman").join(name); + assert!( + reserved.contains(&expected), + "{name} is not reserved under the account root: {reserved:?}" + ); + } + // `.secret_key` and the rest are secrets, so the carve-out must cover more + // than the one name #5505 carved out. + assert!(ACCOUNT_INTERNAL_FILES.len() > 1); +} + +#[test] +fn the_workspace_parent_fallback_keeps_only_the_config_once_the_roots_diverge() { + let policy = policy_with("/proj/workspace", Some("/proj/.openhuman")); + let reserved = reserved(&policy); + + // The parent is not the account dir here, so reserving its other files + // would guard the wrong directory. + assert!(reserved.contains(&PathBuf::from("/proj").join(ACCOUNT_CONFIG_FILE))); + for name in ACCOUNT_INTERNAL_FILES + .iter() + .filter(|name| **name != ACCOUNT_CONFIG_FILE) + { + assert!( + !reserved.contains(&PathBuf::from("/proj").join(name)), + "{name} must not be reserved under the workspace parent: {reserved:?}" + ); + } +} + +#[test] +fn without_an_account_root_only_the_legacy_config_carve_out_applies() { + let policy = policy_with("/proj/workspace", None); + let reserved = reserved(&policy); + + assert!(reserved.contains(&PathBuf::from("/proj").join(ACCOUNT_CONFIG_FILE))); + assert!(!reserved.contains(&PathBuf::from("/proj").join(".secret_key"))); +} + +#[test] +fn a_coincident_account_root_reserves_the_config_once() { + // The default layout: `/` holds both config and workspace. + let policy = policy_with("/home/u/.openhuman/workspace", Some("/home/u/.openhuman")); + let config = PathBuf::from("/home/u/.openhuman").join(ACCOUNT_CONFIG_FILE); + + assert_eq!( + reserved(&policy) + .iter() + .filter(|path| **path == config) + .count(), + 1, + "the account root and the workspace parent agree here, so the \ + reservation must not be pushed twice" + ); +} + +fn config_with(workspace: &str, config_path: &str) -> crate::config::Config { + crate::config::Config { + workspace_dir: PathBuf::from(workspace), + action_dir: PathBuf::from(workspace), + config_path: PathBuf::from(config_path), + ..crate::config::Config::default() + } +} + +#[test] +fn every_config_constructor_carries_the_config_paths_account_root() { + // The split layout again: the account root is `config_path`'s parent, + // not `workspace_dir`'s, so it can only come from the config. + let config = config_with("/proj/workspace", "/proj/.openhuman/config.toml"); + let account = PathBuf::from("/proj/.openhuman"); + + for (name, policy) in [ + ("for_config", SecurityPolicy::for_config(&config)), + ( + "for_config_in", + SecurityPolicy::for_config_in(&config, std::path::Path::new("/proj/turn")), + ), + ] { + assert_eq!( + policy.account_dir.as_deref(), + Some(account.as_path()), + "{name}" + ); + let reserved = reserved(&policy); + assert!( + reserved.contains(&account.join(".secret_key")), + "{name} does not reserve the account files: {reserved:?}" + ); + } +} + +/// A policy built from a whole `Config` must go through `for_config` / +/// `for_config_in`, or it silently loses the account root and guards only +/// `config.toml`. Only the sites that build from dirs of their own and chain +/// `with_account_dir` themselves may call `from_config` directly. +#[test] +fn production_code_builds_config_policies_through_for_config() { + const ALLOWED: &[&str] = &[ + "openhuman-core/src/core/runtime/bootstrap.rs", + "openhuman-core/src/security/live_policy.rs", + "openhuman-core/src/security/policy/enforcement.rs", + ]; + fn walk(dir: &std::path::Path, out: &mut Vec) { + for entry in std::fs::read_dir(dir).expect("read source dir") { + let path = entry.expect("source dir entry").path(); + if path.is_dir() { + if path.file_name().is_some_and(|name| name != "tests") { + walk(&path, out); + } + } else if path.extension().is_some_and(|ext| ext == "rs") + && !path.to_string_lossy().ends_with("tests.rs") + { + out.push(path); + } + } + } + + let crates = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .expect("crates dir"); + let mut files = Vec::new(); + for krate in ["openhuman-core", "openhuman-embed", "openhuman-tinyhumans"] { + walk(&crates.join(krate).join("src"), &mut files); + } + // The scan has to see the tree, or an empty walk would pass. + assert!(files.len() > 100, "only {} source files found", files.len()); + + let offenders: Vec = files + .iter() + .filter_map(|path| { + let rel = path + .strip_prefix(crates) + .ok()? + .to_string_lossy() + .replace('\\', "/"); + if ALLOWED.contains(&rel.as_str()) { + return None; + } + let source = std::fs::read_to_string(path).ok()?; + let hits: Vec = source + .lines() + .enumerate() + .filter(|(_, line)| { + !line.trim_start().starts_with("//") + && line.contains("SecurityPolicy::from_config(") + }) + .map(|(index, _)| index + 1) + .collect(); + (!hits.is_empty()).then(|| format!("{rel}:{hits:?}")) + }) + .collect(); + assert!( + offenders.is_empty(), + "use SecurityPolicy::for_config / for_config_in instead: {offenders:?}" + ); +} diff --git a/crates/openhuman-core/src/security/policy/types.rs b/crates/openhuman-core/src/security/policy/types.rs index b527507f58a..d1341f12445 100644 --- a/crates/openhuman-core/src/security/policy/types.rs +++ b/crates/openhuman-core/src/security/policy/types.rs @@ -128,9 +128,37 @@ pub(super) const WORKSPACE_INTERNAL_PREFIXES: &[&str] = /// internal state (reserved by TinySecurity); only /// [`ARTIFACT_TOOL_RESULTS_DIR`] inside it stays agent-readable. pub(super) const ARTIFACTS_DIR: &str = "artifacts"; -/// The account config file, stored beside `workspace_dir` (see -/// the TinySecurity path policy). +/// The account config, the one name the workspace-parent fallback has always +/// refused (#5505). Kept separate from the rest of +/// [`ACCOUNT_INTERNAL_FILES`] because a configured account root and the +/// workspace's parent are not always the same directory, and only this name +/// applies to the latter once they diverge. pub(super) const ACCOUNT_CONFIG_FILE: &str = "config.toml"; +/// Files in the account dir ([`SecurityPolicy::account_dir`]) that are core +/// state rather than agent surface. That directory is reachable by design — a +/// trusted root over it grants its files (#5505) — so this is a carve-out +/// list, not a containment boundary. +/// +/// Each entry carries secrets or privilege that the protected-path floor does +/// not cover: `.secret_key` is the keyring's on-disk encryption key and +/// `auth-profiles.json` the credential profiles it decrypts (the floor covers +/// `~/.ssh` and friends, not these); `config.toml.bak` is the config one save +/// behind, written by `config::schema::load::atomic_commit`; and +/// `claude_code_settings.json` switches the Claude Code provider to +/// `--permission-mode bypassPermissions` with its full native toolset, whose +/// calls never reach the approval gate because that provider runs its tools +/// internally and never returns them to the harness. +/// +/// Enforced as TinySecurity path reservations (`native_paths.rs`), so the +/// module's canonicalisation and its case/Unicode folding on normalising +/// filesystems apply — the host does not re-implement either. +pub(super) const ACCOUNT_INTERNAL_FILES: &[&str] = &[ + ACCOUNT_CONFIG_FILE, + "config.toml.bak", + ".secret_key", + "auth-profiles.json", + "claude_code_settings.json", +]; /// Where oversized tool outputs are persisted for the agent to read back. pub(super) const ARTIFACT_TOOL_RESULTS_DIR: &str = "tool-results"; @@ -202,6 +230,17 @@ pub struct SecurityPolicy { /// intentionally NOT implemented in S1 (#4435). pub privacy_mode: PrivacyMode, pub workspace_dir: PathBuf, + /// The account / credential root — `config_path`'s parent — when the host + /// supplied it. `None` falls back to `workspace_dir`'s parent, which is the + /// same directory in the default layout. + /// + /// Needed as its own field because the two can be split deliberately: + /// `RuntimeBuilder::workspace_dir` moves internal state while leaving the + /// credential root where the `Workspace` put it, and the legacy + /// `/workspace` layout keeps config in a sibling `/.openhuman` + /// (`config::schema::load::dirs`). Inferring the account dir from the + /// workspace guards the wrong directory in both. + pub account_dir: Option, /// Agent action sandbox root — tools resolve relative paths and default /// their cwd here instead of `workspace_dir`. Kept separate so internal /// state (memory DBs, sessions, tokens) under `workspace_dir` is not @@ -266,6 +305,7 @@ impl Default for SecurityPolicy { autonomy: AutonomyLevel::Supervised, privacy_mode: PrivacyMode::Standard, workspace_dir: PathBuf::from("."), + account_dir: None, action_dir: PathBuf::from("."), workspace_only: true, // When adding a new entry to this allowlist, re-audit diff --git a/crates/openhuman-core/src/tools/native_ops.rs b/crates/openhuman-core/src/tools/native_ops.rs index 219bc91a436..9093ea4be41 100644 --- a/crates/openhuman-core/src/tools/native_ops.rs +++ b/crates/openhuman-core/src/tools/native_ops.rs @@ -78,11 +78,7 @@ async fn command_class_for_tool( } pub async fn build_runtime_tools(config: &Config) -> Result>, String> { - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(config)); build_runtime_tools_with_security(config, security).await } @@ -139,11 +135,7 @@ pub async fn classify_tool_call( tool_name: &str, args: &serde_json::Value, ) -> Result { - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(config)); classify_tool_call_with_security(config, security, tool_name, args).await } @@ -180,11 +172,7 @@ pub async fn execute_tool( args: serde_json::Value, prefer_markdown: bool, ) -> Result { - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(config)); execute_tool_with_security(config, security, tool_name, args, prefer_markdown).await } diff --git a/crates/openhuman-embed/src/agent/attachments.rs b/crates/openhuman-embed/src/agent/attachments.rs index 0c13151ac7e..12f67449a5a 100644 --- a/crates/openhuman-embed/src/agent/attachments.rs +++ b/crates/openhuman-embed/src/agent/attachments.rs @@ -79,11 +79,7 @@ impl Agent { .map(|entry| entry.name), ); let config = &self.inner.config; - let security = Arc::new(openhuman_core::security::SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(openhuman_core::security::SecurityPolicy::for_config(config)); occupied.extend( openhuman_core::tools::ops::all_tools( Arc::new(config.clone()), diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs index 09ea817c8e2..564c31b5d60 100644 --- a/crates/openhuman-embed/src/agent/build.rs +++ b/crates/openhuman-embed/src/agent/build.rs @@ -348,12 +348,9 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result Option { let client = crate::integrations::build_client(config).await?; - let security = Arc::new(SecurityPolicy::from_config( - &config.autonomy, - &config.workspace_dir, - &config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(config)); Some(Arc::new(move |file_store| { Arc::new( StorageArtifactPublisher::new(client.clone(), Arc::clone(&security)) diff --git a/crates/openhuman-tinyhumans/src/integrations/file_storage/tools/registry.rs b/crates/openhuman-tinyhumans/src/integrations/file_storage/tools/registry.rs index 3a940b681cc..2ece0116f62 100644 --- a/crates/openhuman-tinyhumans/src/integrations/file_storage/tools/registry.rs +++ b/crates/openhuman-tinyhumans/src/integrations/file_storage/tools/registry.rs @@ -27,11 +27,7 @@ pub async fn build_file_storage_tools( }; let action_dir = action_dir.to_path_buf(); - let security = Arc::new(SecurityPolicy::from_config( - &root_config.autonomy, - &root_config.workspace_dir, - &root_config.action_dir, - )); + let security = Arc::new(SecurityPolicy::for_config(root_config)); let tools: Vec> = vec![ Box::new(StorageUploadFileTool::new_with_security( Arc::clone(&client),