Skip to main content

Run

Struct Run 

Source
pub struct Run { /* private fields */ }
Expand description

A run in progress.

Yields events through Run::recv and settles into an Outcome through Run::finish.

Dropping a Run kills the agent. That is the safe default for the hosts this crate targets: closing a window or cancelling a request should stop the work, not leave an agent running invisibly, spending quota and touching files with nobody watching. Call Run::detach when background execution is genuinely what you want.

On Unix, dropping synchronously signals the run’s process group and then aborts the driver task. What it cannot do is wait: Drop cannot await, so it does not block until the child has exited or its readers have been joined. Use Run::cancel when you need to know the tree has actually gone before continuing, such as before touching the files it was working on. On Windows only the direct child is signalled.

Implementations§

Source§

impl Run

Source

pub async fn recv(&mut self) -> Option<Event>

The next event, or None once the agent has finished producing them.

Source

pub async fn send(&self, message: &str) -> Result<()>

Send another message while the agent is still working.

The whole point of crate::Request::interactive: a user who types a correction mid-turn should not have to wait for the turn to finish.

The agent takes it at its next step boundary, not mid-token, so an answer already being written finishes first and a long tool-using task changes course at its next step. Verified against claude 2.1.212 and codex-cli 0.145.0.

§Ordering, and why there is no acknowledgement

The caller already knows what it sent, so the intended pattern is to append the message to the transcript immediately, below the user’s previous one, and carry on. This deliberately does not ask the agent to echo the message back for sequencing: an echo would only tell a UI something it already knew, and waiting for one would delay the very thing this exists to make immediate.

§Errors

Error::Unsupported on a run that did not open the channel with crate::Request::interactive. Error::Cancelled once the channel has closed, which happens when the turn settles or the run is torn down: a message sent after the turn ends is too late and belongs in a new run resuming the session, so this reports it rather than dropping it.

Source

pub async fn respond(&self, id: &str, decision: &Decision) -> Result<()>

Answer an Event::ApprovalRequest.

The agent is blocked until this is called, so a consumer that receives an approval request and never responds stalls the run until its timeout.

The id must be the one from the request. The agent ignores an answer carrying any other id and keeps waiting, so a mismatch presents as a hang rather than an error; this passes the id straight through and does not invent one.

§Errors

Error::Unsupported on a run that did not ask for approvals, since there is no channel to answer on. Error::Cancelled if the run has already finished or been torn down, which is the same reason a decision can no longer be delivered.

Source

pub fn argv(&self) -> &[String]

The exact command line that was spawned.

This contains the prompt and any session id. Treat it as sensitive: logging it verbatim puts user content into your logs. Use Run::redacted_argv for diagnostics.

Source

pub fn redacted_argv(&self) -> Vec<String>

The command line with every non-public value replaced by a placeholder.

Prompts, system prompts, session ids and anything from crate::Request::unchecked_args are removed; flag names are kept so the command stays recognisable. Sensitivity is recorded where each argument is built rather than inferred from the finished line, so a bare positional prompt or an opaque raw argument is covered too.

Source

pub async fn finish(self) -> Result<Outcome>

Wait for the run to finish.

Drains any events still queued, so a caller that only wants the result can call this without having consumed the stream.

§Errors

Whatever the run failed with. See Error.

Source

pub async fn cancel(self) -> Result<Outcome>

Stop the run and wait until the agent is actually gone.

Cooperative rather than an abort: the driver is asked to stop, signals the process group, reaps the child and joins its readers, and only then does this return. So when it returns the tree really has exited, which matters if the next thing you do touches the files it was working on.

Returns the partial Outcome if the run happened to finish first, otherwise Error::Cancelled.

§Errors

Error::Cancelled in the normal case, or whatever the run failed with if it failed before the request arrived.

Source

pub fn detach(self)

Let the run continue after this handle goes away.

The opposite of the default. Nothing can observe or stop the agent afterwards, so reach for this only when an unsupervised background run is genuinely intended.

Trait Implementations§

Source§

impl Debug for Run

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Run

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Run

§

impl !UnwindSafe for Run

§

impl Freeze for Run

§

impl Send for Run

§

impl Sync for Run

§

impl Unpin for Run

§

impl UnsafeUnpin for Run

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.