Skip to main content

ExecContext

Struct ExecContext 

Source
pub struct ExecContext {
Show 23 fields pub token: CancellationToken, pub background: CancellationToken, pub notify: Option<Sender<Msg>>, pub progress: Sender<ProgressEvent>, pub call_id: ToolCallId, pub turn: TurnId, pub workdir: PathBuf, pub config: Arc<Config>, pub model_id: String, pub task_id: Option<String>, pub session_id: Option<String>, pub message_index: Option<i64>, pub scratchpad: Option<PathBuf>, pub safety_mode: SafetyMode, pub plan_file: Option<PathBuf>, pub plan_permissions: PlanPermissions, pub context_percent: Option<u8>, pub intent: Option<String>, pub classifier: Option<Arc<dyn AutoClassifier>>, pub approval: Option<ApprovalBroker>, pub questions: Option<QuestionBroker>, pub tasks: Option<TaskBroker>, pub web_bytes: Arc<AtomicUsize>,
}
Expand description

What a ToolExecutor::execute() receives.

Fields§

§token: CancellationToken§background: CancellationToken

Ctrl+B “background this” signal, parallel to token. Tools that can detach a running child (execute_command, agent) select on it; the live path sets it from the turn scope, tests leave it never-fired.

§notify: Option<Sender<Msg>>

Turn-independent channel back to the main reducer loop. Detached work (a backgrounded subagent) reports through this after the owning turn is gone — the per-turn progress channel dies with the turn. None in tests and contexts that never detach.

§progress: Sender<ProgressEvent>§call_id: ToolCallId§turn: TurnId§workdir: PathBuf§config: Arc<Config>

Parent session’s app::Config. Needed by SubagentTool so the child reducer uses the same Ollama host, reasoning prefs, MCP servers, etc. Other tools don’t consult it — keeping it as a typed field (rather than a global) means the dependency is explicit in the signature.

§model_id: String

Parent session’s active model id (e.g. "anthropic/claude-opus-4-7"). Subagents inherit this so they hit the same provider.

§task_id: Option<String>

Durable daemon task that owns this tool call, when execution was launched through the runtime task queue.

§session_id: Option<String>

Conversation id of the interactive session dispatching this call — stamped by the reducer onto Cmd::ExecuteTool so checkpoints can be anchored to a conversation position. None on headless/daemon paths.

§message_index: Option<i64>

Conversation length (messages().len()) at dispatch; pairs with session_id for checkpoint anchoring (see CheckpointOrigin).

§scratchpad: Option<PathBuf>

Per-session scratch directory, when the session has one materialized (Msg::ScratchpadReady). Stamped by the reducer onto Cmd::ExecuteTool; like background/notify it is field-set after construction on the live path — None in tests and before the directory is confirmed on disk.

§safety_mode: SafetyMode

Effective live safety mode for this call (from the session, not the static config; floored to ReadOnly while a plan is being drafted). The policy gate builds its PolicyEngine from this.

§plan_file: Option<PathBuf>

Some(path) while the session is in plan mode: the one path the policy gate exempts from the read-only floor, and the flag the plan carve-outs (memory writes, known-safe builds) and the task tools key on. Defaults to None in new — the live dispatch path sets it, like background/notify.

§plan_permissions: PlanPermissions

LIVE per-category plan permission levels, threaded from the reducer (the frozen startup config would go stale under /plan config edits). Only consulted while plan_file is Some; defaults in new.

§context_percent: Option<u8>

Context-window fill at dispatch, when known (exit_plan_mode shows it on the clear-context approval option). Defaults to None in new.

§intent: Option<String>

The user’s stated intent for the turn (latest user message), passed to the Auto-mode classifier so it can judge whether an action is aligned.

§classifier: Option<Arc<dyn AutoClassifier>>

LLM classifier for SafetyMode::Auto. Some only when the effective mode is Auto and a provider is bound; the gate awaits it to resolve a PolicyDecision::Classify. None ⇒ the gate fails safe (escalate).

§approval: Option<ApprovalBroker>

Inline-approval back-channel (interactive runs only). Some lets the gate prompt the user and park until they answer; None (headless) falls back to the out-of-band DB-approval flow.

§questions: Option<QuestionBroker>

Inline-question back-channel for ask_user_question (interactive runs only). Some lets the tool park until the user answers; None (headless) makes the tool proceed with best judgment instead of blocking.

§tasks: Option<TaskBroker>

The checklist broker for the task tools (single writer for all task state). Present on every live path — interactive, headless, and subagent runners each own one; None only in bare test contexts, where the tools degrade to a graceful no-op.

§web_bytes: Arc<AtomicUsize>

Decoded web bytes accepted by every sibling tool call in this turn. The effect runner replaces the constructor default with the owning TurnScope counter so parallel calls share one aggregate budget.

Implementations§

Source§

impl ExecContext

Source

pub fn new( token: CancellationToken, progress: Sender<ProgressEvent>, call_id: ToolCallId, turn: TurnId, workdir: PathBuf, config: Arc<Config>, model_id: String, task_id: Option<String>, session_id: Option<String>, message_index: Option<i64>, safety_mode: SafetyMode, intent: Option<String>, classifier: Option<Arc<dyn AutoClassifier>>, approval: Option<ApprovalBroker>, questions: Option<QuestionBroker>, tasks: Option<TaskBroker>, ) -> Self

Source

pub fn charge_web_bytes(&self, bytes: usize) -> Result<usize, usize>

Charge decoded web bytes to this turn without ever crossing the fixed aggregate limit. Returns the new total on success.

Source

pub fn web_budget(&self) -> WebByteBudget

A cloneable handle for transport code to charge each decoded chunk at the point it is accepted, including failed responses and retries.

Source

pub fn checkpoint_origin(&self) -> CheckpointOrigin

Checkpoint provenance for this call — every checkpoint-creating tool passes this so file snapshots anchor to the conversation position that produced them (rewind/fork surfaces them by anchor).

Trait Implementations§

Source§

impl Debug for ExecContext

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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, 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.
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