Skip to main content

State

Struct State 

Source
pub struct State {
Show 21 fields pub session: Session, pub turn: TurnState, pub ui: UiState, pub mcp: McpState, pub settings: Config, pub instructions: Option<LoadedInstructions>, pub memory: Option<LoadedMemory>, pub skills: Option<LoadedSkills>, pub pending_hook_context: Vec<String>, pub pending_task_notices: Vec<String>, pub cwd: PathBuf, pub temp_dir: PathBuf, pub ids: IdAllocatorBundle, pub confirm: Option<Confirmation>, pub pending_approval: VecDeque<PendingApproval>, pub pending_question: VecDeque<PendingQuestionSet>, pub runtime: RuntimeState, pub should_exit: bool, pub plugin_commands: Vec<PluginCommand>, pub output_schema: Option<Value>, pub now: DateTime<Local>,
}
Expand description

Root state. The reducer takes State by value, returns a new State, and emits any side-effects as a Vec<Cmd>. No &mut — a deliberate choice so tests can diff before/after without aliasing worries, and so replay (“compute the final State that this Msg log would produce”) is a straight fold.

Fields§

§session: Session§turn: TurnState§ui: UiState§mcp: McpState§settings: Config§instructions: Option<LoadedInstructions>§memory: Option<LoadedMemory>

Durable semantic memory snapshot (auto-derived index + entries), refreshed per turn like instructions. Its index is injected into the model prompt alongside project instructions.

§skills: Option<LoadedSkills>

Discovered SKILL.md playbooks (project/user/plugin) plus the rendered index injected into the model prompt alongside instructions and memory. Loaded once at startup — skills are authored artifacts, not live state.

§pending_hook_context: Vec<String>

Context strings injected by before_tool_use plugin hooks (additionalContext), buffered until the next dispatched model request consumes them (see push_call_model). Byte-capped; transient (never persisted with the session).

§pending_task_notices: Vec<String>

One-line notices about the task checklist for the model’s next request: user /todos edits, vetoed completions, staleness nudges. Same lifecycle as pending_hook_context (consumed by the next real dispatch, transient, never persisted).

§cwd: PathBuf

Current working directory. Captured once at startup; tools receive it via ExecContext::workdir and spawned subprocesses inherit it. Centralized here so tests can inject a fake cwd.

§temp_dir: PathBuf

System temp dir, captured once at startup (std::env::temp_dir()). Pasted-image attachments build their scratch path from it; holding it here keeps the reducer free of the env read it used to do inline (#54).

§ids: IdAllocatorBundle§confirm: Option<Confirmation>

When Some, the next render should pop up a modal confirmation (e.g. “are you sure you want to /clear?”). Cleared by the reducer when the user answers.

§pending_approval: VecDeque<PendingApproval>

FIFO queue of tool actions awaiting the user’s inline approval (interactive ask mode + Auto-mode escalations). The front item is rendered as a modal; answering it pops the item and emits Cmd::ResolveApproval, which unblocks the parked tool task. Empty in headless mode (no broker → the out-of-band /approve flow instead).

§pending_question: VecDeque<PendingQuestionSet>

FIFO queue of ask_user_question batches awaiting the user’s answers. The front item renders as a selectable modal; submitting pops it and emits Cmd::ResolveQuestion, unblocking the parked tool task. Empty in headless mode (no broker → the tool proceeds without asking).

§runtime: RuntimeState

Runtime-only observability state: process registry, provider capability snapshot, and lifecycle timeline. Not sent to the model.

§should_exit: bool

Quit flag. When set, the main loop drains pending effects and exits. The reducer never panics on its own; it sets this instead.

§plugin_commands: Vec<PluginCommand>

Prompt-backed slash commands contributed by enabled plugins (manifest.prompts). Loaded once at startup by the run loop (like skills); the reducer expands /name args into a normal Msg::SubmitPrompt, so recordings replay without the plugin installed. Sorted by name.

§output_schema: Option<Value>

mermaid run --output-schema: set by the headless driver before the dedicated formatting turn; build_chat_request copies it onto the request (dropping all tools for that turn). Never set interactively.

§now: DateTime<Local>

Wall-clock for the current reducer step, injected as data (Cause 3). The driver stamps this once per tick — Local::now() live, or the recorded entry’s ts on replay — before calling update. The reducer and the transition helpers read state.now instead of Local::now() / SystemTime::now(), so update(State, Msg) is a pure function of its inputs: the same (State, Msg) always yields the same State, and folding a recorded Msg log recomputes State exactly.

Implementations§

Source§

impl State

Source

pub fn new( settings: Config, cwd: PathBuf, model_id: String, now: DateTime<Local>, ) -> Self

Build a fresh state tied to a specific model + project dir.

Pure given its inputs: now seeds the injected clock and derives the initial conversation’s id/title, so --replay reconstructs the same starting state from a recorded header. (The one environment read left is env::temp_dir() — stable within a machine, and only feeds paste scratch paths.) Nothing here touches the filesystem or tokio.

Source

pub fn seed_conversation(&mut self, history: ConversationHistory)

Apply a --continue / --sessions seed: replace the fresh conversation with the loaded history and re-dispatch the terminal title once. Shared by the live driver and --replay so both construct the same starting state by definition.

Source

pub fn is_busy(&self) -> bool

True iff the reducer is currently mid-turn. UI uses this for the “⏎ cancels generation” hint and for keybind routing.

Source

pub fn current_turn_id(&self) -> Option<TurnId>

The active TurnId, if any turn is in flight. The reducer filters incoming effect messages by comparing their embedded TurnId to this value — if the user cancelled and started a new turn, stale results from the old turn are dropped cleanly.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

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 Debug for State

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

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