Skip to main content

State

Struct State 

Source
pub struct State {
Show 15 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 cwd: PathBuf, pub temp_dir: PathBuf, pub ids: IdAllocatorBundle, pub confirm: Option<Confirmation>, pub pending_approval: VecDeque<PendingApproval>, pub runtime: RuntimeState, pub should_exit: bool, 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.

§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).

§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.

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