pub struct Shell<E> { /* private fields */ }Expand description
The terminal tool for executing scripts in a sandbox.
Creates a shared working directory that persists across all executions, named by heel with four random words; that name is not one of the leased model-facing ids. Each execution creates a fresh sandbox but shares the working directory.
Implementations§
Source§impl Shell<Arc<AnyExecutor>>
impl Shell<Arc<AnyExecutor>>
Sourcepub const fn builder(
sandbox: Sandbox,
) -> ShellBuilder<Missing, Missing, Missing, Missing, Missing>
pub const fn builder( sandbox: Sandbox, ) -> ShellBuilder<Missing, Missing, Missing, Missing, Missing>
Starts a shell whose scripts run in sandbox, a sandbox on a
container: its working directory, live grants, environment source,
network policy, priority and backend are the shell’s, and the shell
is the one the container’s launch names. A sandbox on the host takes
builder_on_host.
Sourcepub const fn builder_on_host(
sandbox: Sandbox,
host_shell: HostLaunch,
) -> ShellBuilder<Missing, Missing, Missing, Missing, Missing>
pub const fn builder_on_host( sandbox: Sandbox, host_shell: HostLaunch, ) -> ShellBuilder<Missing, Missing, Missing, Missing, Missing>
Starts a shell whose scripts run in sandbox, a sandbox on the host,
under the shell host_shell names. A host sandbox spawns programs and
names no shell of its own, so the shell is an input of the shell that
needs one.
Source§impl<E: Executor + Clone + 'static> Shell<E>
impl<E: Executor + Clone + 'static> Shell<E>
Sourcepub fn with_approver(self, approver: impl Approver) -> Self
pub fn with_approver(self, approver: impl Approver) -> Self
Sets the approver that answers the approvals of scripts no tool call
carries (Shell::run and Self::run_background), and
of calls whose dispatcher attached none. Without one, such a script
that needs approval does not run.
Sourcepub fn with_shell_sessions(self, sessions: ShellSessionRegistry) -> Self
pub fn with_shell_sessions(self, sessions: ShellSessionRegistry) -> Self
Serves the SSH servers of sessions as the locations scripts may
name. Registries share their server set, so terminals given clones of
one see the same servers.
Sourcepub fn with_subagent_spaces(self, spaces: impl SubagentSpaces) -> Self
pub fn with_subagent_spaces(self, spaces: impl SubagentSpaces) -> Self
Has spaces prepare the space of every subagent launched from this
terminal and, at any depth, from theirs, before the subagent’s
terminal exists. A launch whose space cannot be prepared fails with
the error spaces gives.
Sourcepub fn with_id_allocator(self, ids: AnyIdAllocator) -> Self
pub fn with_id_allocator(self, ids: AnyIdAllocator) -> Self
Leases every word this terminal names something with for the model —
a command’s task id, a stored output’s file name, a subagent’s space —
from ids, as do the subagent terminals launched from it and the
subagent command bound to it. A terminal given none leases from its
own AnyIdAllocator::default.
Source§impl<E> Shell<E>
impl<E> Shell<E>
Sourcepub fn foreground_wait(&self) -> ForegroundWait
pub fn foreground_wait(&self) -> ForegroundWait
A handle on the foreground window, shared with every terminal derived from this one: a longer window put in force through it applies to the next foreground wait of each of them.
Sourcepub fn response_window(&self) -> ResponseWindow
pub fn response_window(&self) -> ResponseWindow
A handle on the response window, shared with every terminal derived from this one: a window set through it applies to the next final warning of each of them.
Sourcepub fn with_footprint_reader(self, reader: impl FootprintReader) -> Self
pub fn with_footprint_reader(self, reader: impl FootprintReader) -> Self
Reads job footprints and the machine’s physical memory through
reader instead of the platform’s own.
Sourcepub fn with_footprint_registry(self, registry: impl FootprintRegistry) -> Self
pub fn with_footprint_registry(self, registry: impl FootprintRegistry) -> Self
Shares the memory this terminal’s jobs hold with the machine’s other
agents through registry, so a final warning can name the agent that
contributes the most when all agents together exceed physical memory.
Sourcepub fn job_memory(&self) -> JobMemory
pub fn job_memory(&self) -> JobMemory
The memory the terminal’s jobs hold, for a guard that warns about and kills a runaway job.
The machine the embedder runs on is always judged. When the terminal runs in a container, the container’s own memory limit is judged too, read inside the container. Jobs of a remote execution environment are never judged.
Sourcepub fn container_probe(&self) -> Option<ContainerProbe>
pub fn container_probe(&self) -> Option<ContainerProbe>
A reader of the container the agent works in, when the terminal’s
home environment is a container; None when it is the local
machine. A remote execution environment is never a home environment.
Sourcepub fn subagent_import_budget(&self) -> ImportBudget
pub fn subagent_import_budget(&self) -> ImportBudget
A handle on the most bytes a subagent’s sandbox may send the host while its commits are imported, shared with every subagent this terminal launches: a change through it applies to the next import of each of them.
Sourcepub const fn shell_sessions(&self) -> &ShellSessionRegistry
pub const fn shell_sessions(&self) -> &ShellSessionRegistry
The SSH servers scripts may name as their location, shared with
child terminals.
Sourcepub const fn working_dir(&self) -> &PathBuf
pub const fn working_dir(&self) -> &PathBuf
Returns the working directory path.
Sourcepub fn outputs_dir(&self) -> PathBuf
pub fn outputs_dir(&self) -> PathBuf
Returns the outputs directory path.
Sourcepub const fn output_store(&self) -> &OutputStore
pub const fn output_store(&self) -> &OutputStore
Returns the output store.
Sourcepub const fn id_allocator(&self) -> &AnyIdAllocator
pub const fn id_allocator(&self) -> &AnyIdAllocator
The allocator this terminal leases its model-facing ids from.
Sourcepub const fn executor(&self) -> &E
pub const fn executor(&self) -> &E
The executor backing this terminal, for spawning watch tasks.
Sourcepub fn grants(&self) -> Grants
pub fn grants(&self) -> Grants
Paths mounted readable for commands, besides the working directory. The shared runtime grant handle: adding a grant through it affects every command launched afterwards, on this terminal and its clones.
Sourcepub fn events(&self) -> ShellEvents
pub fn events(&self) -> ShellEvents
The facts about this terminal’s jobs. Every handle shares the queues, so an event reaches one reader.
Source§impl<E> Shell<E>
impl<E> Shell<E>
Sourcepub async fn subagent(
&self,
grant: SubagentGrant,
caller: Option<&Path>,
name: impl Into<String>,
) -> Result<Self, SubagentGrantError>
pub async fn subagent( &self, grant: SubagentGrant, caller: Option<&Path>, name: impl Into<String>, ) -> Result<Self, SubagentGrantError>
Launches the shell of a subagent: it runs in a space of its own inside this shell’s working directory and never exceeds this shell’s authority.
grant is everything the subagent may write beyond its space, and
must lie inside what this shell can write. When this shell has
SubagentSpaces, they prepare the space first and are told
caller, the directory the launch is asked for from (this shell’s
working directory when None). Grants are resolved one at a time, so
what this shell handed out is recorded in one place. The subagent’s
shell shares this shell’s approver, output store, events and
policies’ definitions, with state of its own, and its own jobs.
name is the subagent’s name beneath this shell’s agent: every event
its shell raises carries that AgentPath, where the main shell’s
carry AgentPath::main. The subagent’s running jobs are killed when
the last handle of its shell is dropped, which a main shell never
does.
§Errors
Returns an error when grant names a path this shell cannot write or
a commit it cannot grant, when a container shell has no workspace
mount, or when the subagent’s space cannot be created or prepared.
Sourcepub fn prepared_space(&self) -> Option<PreparedSpace>
pub fn prepared_space(&self) -> Option<PreparedSpace>
What this terminal’s launcher prepared in its space; None for the
main agent’s terminal and when the launcher has no
SubagentSpaces.
Source§impl<E> Shell<E>
impl<E> Shell<E>
Sourcepub fn commit_ledger(&self) -> Option<CommitLedger>
pub fn commit_ledger(&self) -> Option<CommitLedger>
Lists the commits of the subagent this terminal serves, when it holds a commit grant.
Source§impl<E: Executor + Clone + 'static> Shell<E>
impl<E: Executor + Clone + 'static> Shell<E>
Sourcepub async fn run(&self, script: Script) -> Result<ScriptResult, ShellRunError>
pub async fn run(&self, script: Script) -> Result<ScriptResult, ShellRunError>
Runs script to its end, through the foreground window and past it,
and returns its output and how it ended; a script its timeout killed
ends CommandOutcome::Killed.
The run is under the shell’s whole policy: its grants, network
policy, backend, policies, priority, environment and jobserver. It
starts where script says and leaves the directory the shell carries
between calls alone. It is a job of the shell, listed and killable
like any other, but never announced as one: its end is told to the
caller alone.
§Errors
Returns an error when the timeout is out of range, a policy refuses the script, the directory does not map into the shell’s container, or the execution fails.
Sourcepub fn tool(&self) -> ShellTool<E>
pub fn tool(&self) -> ShellTool<E>
The model-facing tool of this shell, named and described as the
embedder’s ShellToolSettings say.
Sourcepub async fn call(
&self,
arguments: ShellArgs,
cx: ToolContext,
) -> Result<ToolResult>
pub async fn call( &self, arguments: ShellArgs, cx: ToolContext, ) -> Result<ToolResult>
Runs one terminal call: the script of arguments in its
interpreter, in the foreground window or detached.
§Errors
Returns an error when the arguments are out of range, the interpreter is not one the shell is configured with, a policy refuses the script or the execution fails.
Source§impl<E: Executor + Clone + 'static> Shell<E>
impl<E: Executor + Clone + 'static> Shell<E>
Sourcepub async fn run_background(&self, arguments: ShellArgs) -> Result<Job>
pub async fn run_background(&self, arguments: ShellArgs) -> Result<Job>
Runs script as a detached background job bounded by timeout, for
embedders that drive the terminal directly rather than through the
terminal tool schema, and returns the job. Shares Self::call’s
background: true path, so the job is announced as one.
§Errors
Fails the way a terminal call does: an invalid timeout, a
refused permission, a blocked command or a spawn failure.
Trait Implementations§
Auto Trait Implementations§
impl<E> !RefUnwindSafe for Shell<E>
impl<E> !Unpin for Shell<E>
impl<E> !UnsafeUnpin for Shell<E>
impl<E> !UnwindSafe for Shell<E>
impl<E> Forget for Shell<E>
impl<E> Freeze for Shell<E>where
E: Freeze,
impl<E> Move for Shell<E>
impl<E> Send for Shell<E>where
E: Send,
impl<E> Sync for Shell<E>where
E: Sync,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more