core: require tool runtimes to provide workspace roots

This commit is contained in:
pakrym-oai
2026-07-09 19:39:42 -07:00
parent e1cb296253
commit 2bb2cd25c6
6 changed files with 12 additions and 18 deletions
+4
View File
@@ -1076,6 +1076,10 @@ async fn danger_full_access_tool_attempts_do_not_enforce_managed_network() -> an
}
impl crate::tools::sandboxing::ToolRuntime<(), ()> for ProbeToolRuntime {
fn workspace_roots<'a>(&self, _req: &'a ()) -> &'a [PathUri] {
&[]
}
async fn run(
&mut self,
_req: &(),
+1 -9
View File
@@ -265,15 +265,7 @@ impl ToolOrchestrator {
.sandbox_cwd(req)
.cloned()
.unwrap_or_else(|| PathUri::from_abs_path(&turn_ctx.cwd));
let workspace_roots = tool
.workspace_roots(req)
.or_else(|| {
turn_ctx
.environments
.primary()
.map(|environment| environment.workspace_roots())
})
.unwrap_or_default();
let workspace_roots = tool.workspace_roots(req);
let permissions = workspace_roots
.iter()
.map(PathUri::to_abs_path)
@@ -219,8 +219,8 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
}
impl ToolRuntime<ApplyPatchRequest, ApplyPatchRuntimeOutput> for ApplyPatchRuntime {
fn workspace_roots<'a>(&self, req: &'a ApplyPatchRequest) -> Option<&'a [PathUri]> {
Some(req.turn_environment.workspace_roots())
fn workspace_roots<'a>(&self, req: &'a ApplyPatchRequest) -> &'a [PathUri] {
req.turn_environment.workspace_roots()
}
fn sandbox_cwd<'a>(&self, req: &'a ApplyPatchRequest) -> Option<&'a PathUri> {
+2 -2
View File
@@ -209,8 +209,8 @@ impl Approvable<ShellRequest> for ShellRuntime {
}
impl ToolRuntime<ShellRequest, ExecToolCallOutput> for ShellRuntime {
fn workspace_roots<'a>(&self, req: &'a ShellRequest) -> Option<&'a [PathUri]> {
Some(req.turn_environment.workspace_roots())
fn workspace_roots<'a>(&self, req: &'a ShellRequest) -> &'a [PathUri] {
req.turn_environment.workspace_roots()
}
fn network_approval_spec(
@@ -255,8 +255,8 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
}
impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRuntime<'a> {
fn workspace_roots<'b>(&self, req: &'b UnifiedExecRequest) -> Option<&'b [PathUri]> {
Some(req.turn_environment.workspace_roots())
fn workspace_roots<'b>(&self, req: &'b UnifiedExecRequest) -> &'b [PathUri] {
req.turn_environment.workspace_roots()
}
fn sandbox_cwd<'b>(&self, req: &'b UnifiedExecRequest) -> Option<&'b PathUri> {
+1 -3
View File
@@ -394,9 +394,7 @@ pub(crate) enum ToolError {
}
pub(crate) trait ToolRuntime<Req, Out>: Approvable<Req> + Sandboxable {
fn workspace_roots<'a>(&self, _req: &'a Req) -> Option<&'a [PathUri]> {
None
}
fn workspace_roots<'a>(&self, req: &'a Req) -> &'a [PathUri];
fn network_approval_spec(&self, _req: &Req, _ctx: &ToolCtx) -> Option<NetworkApprovalSpec> {
None