pub trait CommandLauncher: Send + Sync {
// Required methods
fn command(
&self,
ws: &Workspace,
script: &str,
ctx: &dyn ToolContext,
) -> Result<Command, DevToolError>;
fn isolation(&self) -> &str;
// Provided methods
fn guarded_command(
&self,
ws: &Workspace,
script: &str,
ctx: &dyn ToolContext,
) -> Result<(Command, Option<LaunchGuard>), DevToolError> { ... }
fn egress(&self) -> ToolEgress { ... }
}Expand description
Builds the process that runs one bash script.
BashTool owns everything around the process: the timeout ceiling,
the output cap, streaming, standard input, the new session and the process-group kill.
A launcher decides only what runs and where: the program and its arguments, the working
directory and the environment. That lets a sandbox wrap the script without forking the
tool. HostLauncher is the default and runs sh -c <script> on the host.
The returned command must not set a process group or a session: BashTool starts it in
a new session (setsid), which fails for a process that already leads a group. It also
replaces the command’s standard streams and sets kill_on_drop. On Windows it replaces
the command’s creation flags with CREATE_SUSPENDED, so the process runs only once it is
in the call’s Job Object (spec 3.2 §10 W1). A Windows launcher whose confinement cannot
be set on a command, such as a restricted token, starts the process itself through
spawn_contained instead (spec 3.2 §10 W5).
Implements spec 3.1 §10 D1.
§Example
use std::sync::Arc;
use adk_core::ToolContext;
use adk_devtools::{BashTool, CommandLauncher, DevToolError, Workspace};
/// Runs every script under `nice`, otherwise as the host launcher does.
struct NiceLauncher;
impl CommandLauncher for NiceLauncher {
fn command(
&self,
ws: &Workspace,
script: &str,
_ctx: &dyn ToolContext,
) -> Result<tokio::process::Command, DevToolError> {
let mut cmd = tokio::process::Command::new("nice");
cmd.args(["sh", "-c", script]).current_dir(ws.root());
if !ws.inherits_env() {
cmd.env_clear().envs(ws.bash_env());
}
Ok(cmd)
}
fn isolation(&self) -> &str {
"host-nice"
}
}
let workspace = Workspace::new("./my-repo").allow_bash(true);
let bash = BashTool::new(workspace).with_launcher(Arc::new(NiceLauncher));Required Methods§
Sourcefn command(
&self,
ws: &Workspace,
script: &str,
ctx: &dyn ToolContext,
) -> Result<Command, DevToolError>
fn command( &self, ws: &Workspace, script: &str, ctx: &dyn ToolContext, ) -> Result<Command, DevToolError>
Builds the command that runs script for the call described by ctx.
§Errors
Returns a DevToolError when the command cannot be built, for example when a
sandbox the launcher requires is unavailable. The call then fails without running
anything.
Provided Methods§
Sourcefn guarded_command(
&self,
ws: &Workspace,
script: &str,
ctx: &dyn ToolContext,
) -> Result<(Command, Option<LaunchGuard>), DevToolError>
fn guarded_command( &self, ws: &Workspace, script: &str, ctx: &dyn ToolContext, ) -> Result<(Command, Option<LaunchGuard>), DevToolError>
Builds the command as command does, with what must live until its
process has ended, such as the egress proxy the process reaches the network through.
BashTool holds the guard until the process exits. The default keeps
nothing; a wrapping launcher forwards its inner launcher’s guard.
§Errors
As for command.
Sourcefn egress(&self) -> ToolEgress
fn egress(&self) -> ToolEgress
What the commands this launcher builds reach on the network, which bash declares as
its Tool::egress. The default,
ToolEgress::Undeclared, is refused under a run egress policy; a wrapping launcher
forwards its inner launcher’s.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".