Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions crates/acp_thread/src/acp_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ pub fn meta_with_tool_name(tool_name: &str) -> acp::Meta {
/// Key used in ACP ToolCall meta to store the session id and message indexes
pub const SUBAGENT_SESSION_INFO_META_KEY: &str = "subagent_session_info";

pub const SANDBOX_AUTHORIZATION_META_KEY: &str = "sandbox_authorization";

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct SandboxAuthorizationDetails {
#[serde(default)]
pub network: bool,
#[serde(default)]
pub allow_fs_write_all: bool,
#[serde(default)]
pub unsandboxed: bool,
#[serde(default)]
pub write_paths: Vec<PathBuf>,
}

pub fn meta_with_sandbox_authorization(details: SandboxAuthorizationDetails) -> acp::Meta {
acp::Meta::from_iter([(
SANDBOX_AUTHORIZATION_META_KEY.into(),
serde_json::to_value(details).unwrap_or_default(),
)])
}

pub fn sandbox_authorization_details_from_meta(
meta: &Option<acp::Meta>,
) -> Option<SandboxAuthorizationDetails> {
meta.as_ref()
.and_then(|m| m.get(SANDBOX_AUTHORIZATION_META_KEY))
.and_then(|v| serde_json::from_value(v.clone()).ok())
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SubagentSessionInfo {
/// The session id of the subagent sessiont that was spawned
Expand Down Expand Up @@ -268,6 +297,7 @@ pub struct ToolCall {
pub raw_output: Option<serde_json::Value>,
pub tool_name: Option<SharedString>,
pub subagent_session_info: Option<SubagentSessionInfo>,
pub sandbox_authorization_details: Option<SandboxAuthorizationDetails>,
}

impl ToolCall {
Expand Down Expand Up @@ -309,6 +339,8 @@ impl ToolCall {
let tool_name = tool_name_from_meta(&tool_call.meta);

let subagent_session_info = subagent_session_info_from_meta(&tool_call.meta);
let sandbox_authorization_details =
sandbox_authorization_details_from_meta(&tool_call.meta);

let label = if tool_call.kind == acp::ToolKind::Execute {
cx.new(|cx| Markdown::new_text(title.into(), cx))
Expand All @@ -329,6 +361,7 @@ impl ToolCall {
raw_output: tool_call.raw_output,
tool_name,
subagent_session_info,
sandbox_authorization_details,
};
Ok(result)
}
Expand Down Expand Up @@ -364,6 +397,10 @@ impl ToolCall {
if let Some(subagent_session_info) = subagent_session_info_from_meta(&meta) {
self.subagent_session_info = Some(subagent_session_info);
}
if let Some(sandbox_authorization_details) = sandbox_authorization_details_from_meta(&meta)
{
self.sandbox_authorization_details = Some(sandbox_authorization_details);
}

if let Some(title) = title {
if self.kind == acp::ToolKind::Execute {
Expand Down Expand Up @@ -1956,6 +1993,7 @@ impl AcpThread {
raw_output: None,
tool_name: None,
subagent_session_info: None,
sandbox_authorization_details: None,
};
self.push_entry(AgentThreadEntry::ToolCall(failed_tool_call), cx);
return Ok(());
Expand Down
9 changes: 8 additions & 1 deletion crates/acp_thread/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ pub struct SandboxWrap {
/// here — *not* the command's working directory, which is model-
/// controlled and would let the model widen its own writable scope.
pub writable_paths: Vec<PathBuf>,
/// Additional write subtrees the user explicitly approved for this
/// command (per-path write grants). Kept separate from `writable_paths`
/// to make the trust boundary explicit: these originate from
/// model-requested paths that passed a user-approval prompt. They are
/// merged with `writable_paths` when generating the sandbox policy.
pub extra_write_paths: Vec<PathBuf>,
/// Allow outbound network access for this command.
pub allow_network: bool,
/// Allow unrestricted filesystem writes (ignores `writable_paths`).
/// Allow unrestricted filesystem writes (ignores all writable paths).
pub allow_fs_write: bool,
}

Expand Down Expand Up @@ -70,6 +76,7 @@ pub(crate) fn apply_sandbox_wrap(
let writable: Vec<&std::path::Path> = sandbox_wrap
.writable_paths
.iter()
.chain(sandbox_wrap.extra_write_paths.iter())
.map(|p| p.as_path())
.collect();
let permissions = sandbox::macos_seatbelt::SandboxPermissions {
Expand Down
Loading
Loading