Skip to main content

BrainEngine

Struct BrainEngine 

Source
pub struct BrainEngine {
    pub pending: HashMap<u32, BrainSuggestion>,
    /* private fields */
}
Expand description

The brain inference engine. Manages async inference threads and collects results.

Fields§

§pending: HashMap<u32, BrainSuggestion>

Pending suggestions waiting for user confirmation (advisory mode).

Implementations§

Source§

impl BrainEngine

Source

pub fn new(config: BrainConfig) -> Self

Source

pub fn tick( &mut self, sessions: &[ClaudeSession], deny_rules: &[AutoRule], ) -> Vec<(u32, String)>

Run one tick of the brain engine. Call this from app.tick() after refresh().

  1. Collect results from completed inference threads
  2. Spawn new inference threads for eligible sessions

Returns a list of (pid, status_message) for actions taken this tick.

Source

pub fn accept(&mut self, pid: u32, session: &ClaudeSession) -> Option<String>

Accept a pending brain suggestion (user pressed ‘b’).

Source

pub fn reject(&mut self, pid: u32) -> Option<BrainSuggestion>

Reject a pending brain suggestion (user pressed ‘B’).

Source

pub fn maybe_restart_saturated( &mut self, sessions: &[ClaudeSession], lifecycle: &LifecycleConfig, is_idle: bool, ) -> Vec<(u32, String)>

Check for sessions with saturated context and auto-restart them. Saves a checkpoint and spawns a fresh session with the summary as prompt.

Source

pub fn cleanup(&mut self, sessions: &[ClaudeSession])

Clear pending suggestions for PIDs that are no longer in NeedsInput/WaitingInput.

Source

pub fn maybe_orchestrate( &mut self, sessions: &[ClaudeSession], ) -> Vec<(u32, String)>

Run orchestration evaluation: ask the brain if any cross-session actions should be taken (spawn, route, terminate). Runs less frequently than per-session advisory (every orchestrate_interval_secs).

Source

pub fn handle_orchestration_result( &mut self, suggestion: &BrainSuggestion, sessions: &[ClaudeSession], ) -> Vec<(u32, String)>

Check if a result is an orchestration response (pid == 0).

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