Skip to main content

Shell

Struct Shell 

Source
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>>

Source

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.

Source

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>

Source

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.

Source

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.

Source

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.

Source

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

pub const fn sandbox(&self) -> &Sandbox

The sandbox this shell’s scripts run in, so an embedder that built the shell spawns its own processes in the same sandbox: the same live grants, environment source, network policy and backend.

Source§

impl<E> Shell<E>
where E: Executor + Clone + 'static,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn shell_sessions(&self) -> &ShellSessionRegistry

The SSH servers scripts may name as their location, shared with child terminals.

Source

pub const fn working_dir(&self) -> &PathBuf

Returns the working directory path.

Source

pub fn outputs_dir(&self) -> PathBuf

Returns the outputs directory path.

Source

pub const fn output_store(&self) -> &OutputStore

Returns the output store.

Source

pub const fn id_allocator(&self) -> &AnyIdAllocator

The allocator this terminal leases its model-facing ids from.

Source

pub fn jobs(&self) -> Jobs

This terminal’s jobs.

Source

pub const fn executor(&self) -> &E

The executor backing this terminal, for spawning watch tasks.

Source

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.

Source

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>
where E: Executor + Clone + 'static,

Source

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.

Source

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>
where E: Executor + Clone + 'static,

Source

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>

Source

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.

Source

pub fn tool(&self) -> ShellTool<E>

The model-facing tool of this shell, named and described as the embedder’s ShellToolSettings say.

Source

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>

Source

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§

Source§

impl<E: Clone> Clone for Shell<E>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E> Debug for Shell<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more