use crate::agent_sessions;
pub fn add_workspace_root(
id: &str,
root: &str,
mount_mode: Option<crate::workspace_anchor::MountMode>,
reason: Option<String>,
policy: Option<&crate::orchestration::CapabilityPolicy>,
) -> Result<String, String> {
agent_sessions::add_workspace_root_verified(id, root, mount_mode, reason, |mounted| {
refuse_unenforceable_read_only(id, mounted, policy)
})
}
fn refuse_unenforceable_read_only(
id: &str,
root: &std::path::Path,
policy: Option<&crate::orchestration::CapabilityPolicy>,
) -> Result<(), String> {
use crate::workspace_anchor::MountMode;
let Some(anchor) = agent_sessions::workspace_anchor(id) else {
return Ok(());
};
let mounted_read_only = anchor
.additional_roots
.iter()
.any(|entry| entry.path == root && matches!(entry.mount_mode, MountMode::ReadOnly));
if !mounted_read_only {
return Ok(());
}
let Some(policy) = policy
.cloned()
.or_else(crate::orchestration::current_execution_policy)
else {
return Ok(());
};
let _session = agent_sessions::enter_current_session(id);
if crate::stdlib::sandbox::child_write::child_write_disposition(&policy, root)
== crate::stdlib::sandbox::child_write::ChildWriteDisposition::Writable
{
return Err(format!(
"cannot mount '{}' read_only: this platform's sandbox cannot subtract write \
access from a path inside a writable root, so a command could still write it",
root.display()
));
}
Ok(())
}