Skip to main content

MockRuntime

Struct MockRuntime 

Source
pub struct MockRuntime {
    pub sessions: Vec<SessionSnapshot>,
    pub gate_mode: Mutex<Option<BrainGateMode>>,
    pub decisions: Vec<DecisionSummary>,
    pub review_queue: Vec<ReviewItemSummary>,
    pub leases: Vec<LeaseSummary>,
    pub handoffs: Vec<HandoffSummary>,
    pub interrupts: Vec<InterruptSummary>,
    pub tasks: Vec<TaskSummary>,
    pub agents: Vec<AgentDirectoryEntry>,
    pub roles: Vec<RoleBinding>,
    pub peers: Vec<(String, Option<String>)>,
    pub actions_log: Mutex<Vec<MockAction>>,
}
Expand description

In-memory runtime backed by Vecs and interior-mutable counters. Used by tests in this crate to verify the trait shapes compile and roundtrip cleanly, and by the future claudectl-tui crate’s tests to render the TUI against fixtures without dragging in brain / coord / bus.

Actions impls record their calls in actions_log so tests can assert “the TUI invoked the right side-effect” without spying on real I/O.

Fields§

§sessions: Vec<SessionSnapshot>§gate_mode: Mutex<Option<BrainGateMode>>§decisions: Vec<DecisionSummary>§review_queue: Vec<ReviewItemSummary>§leases: Vec<LeaseSummary>§handoffs: Vec<HandoffSummary>§interrupts: Vec<InterruptSummary>§tasks: Vec<TaskSummary>§agents: Vec<AgentDirectoryEntry>§roles: Vec<RoleBinding>§peers: Vec<(String, Option<String>)>

Paired peers hive_view_snapshot reports, so a test can exercise the peer picker without a relay on the machine running the suite.

§actions_log: Mutex<Vec<MockAction>>

Implementations§

Source§

impl MockRuntime

Source

pub fn into_runtime(self) -> Runtime

Source

pub fn into_runtime_shared(self) -> (Arc<Self>, Runtime)

Like into_runtime, but hands back the Arc as well so a test can read actions() after the TUI has driven the runtime. into_runtime alone moves the mock out of reach.

Source

pub fn actions(&self) -> Vec<MockAction>

Trait Implementations§

Source§

impl Actions for MockRuntime

Source§

fn terminate_session(&self, pid: u32) -> Result<(), String>

Terminate the OS process with the given PID. The TUI uses this for “kill session” hotkeys.
Source§

fn inject_text(&self, session_id: &str, text: &str) -> Result<(), String>

Inject text into the session’s terminal. Implementations pick the right backend (tmux, Kitty, etc.) from the session metadata. Read more
Source§

fn set_gate_mode(&self, mode: BrainGateMode) -> Result<(), String>

Update the persisted brain gate mode. Reflected back through BrainView::gate_mode on the next call.
Source§

fn log_observation(&self, observation: ObservationInput) -> Result<(), String>

Record an observation about a user action — non-LLM “the user did X.” Drives the brain’s outcome telemetry and preference distillation.
Source§

fn log_decision(&self, input: LogDecisionInput) -> Result<(), String>

Record a user’s accept/reject decision on a brain suggestion. The distinction from log_observation is that log_decision carries the actual suggestion that was on screen — the brain pairs it with the user’s response for outcome telemetry, counterfactual analysis, and few-shot retrieval.
Source§

fn mark_canonical( &self, decision_id: &str, note: Option<String>, ) -> Result<(), String>

Mark a past brain decision as canonical for teaching. Optional note is the operator’s annotation. Used by the Brain Review surface.
Source§

fn bind_bus_role(&self, name: &str, cwd: &str, pid: u32) -> Result<(), String>

Bind an agent-bus role to a (cwd, pid) pair. The TUI calls this from the new role-bind key (Ctrl+R) so the operator can attach a role to a specific running Claude session without dropping to another terminal. Returns Err when the bus feature is compiled out or the DB write fails. See issue #307.
Source§

fn cancel_task(&self, task_id: &str) -> Result<(), String>

Cancel a supervisor task (move it to CANCELLED). Used by the Supervisor panel’s one-key cancel (#368). Err when the coord feature is compiled out, the task is already terminal, or the store write fails.
Source§

fn set_supervisor_drain(&self, draining: bool) -> Result<(), String>

Set or clear the supervisor drain marker. When draining, the reconciler stops issuing new task assignments while letting running tasks finish. Err when the coord feature is compiled out.
Source§

fn retry_task(&self, task_id: &str) -> Result<(), String>

Re-queue a failed/cancelled task (move it back to PENDING so the reconciler re-assigns it). Err for a DONE task (nothing to retry), a still-active task, or when the coord feature is compiled out.
Source§

fn approve_task(&self, task_id: &str) -> Result<(), String>

Approve a NEEDS_HUMAN task — accept the work as-is and move it to DONE, overriding the verifier that escalated it. Err when the task isn’t in NEEDS_HUMAN, or the coord feature is compiled out.
Source§

fn send_session_to_peer( &self, session_id: &str, transcript: Option<&Path>, cwd: &str, peer: &str, ) -> Result<String, String>

Move a conversation to a paired peer, so it can be resumed there (#510). The TUI calls this from the send hotkey; transcript is the path session discovery already resolved, which is more reliable than re-deriving it from cwd and the id. Read more
Source§

impl BrainReviewView for MockRuntime

Source§

fn all_decisions(&self) -> Vec<DecisionSummary>

Every decision on disk, newest first. Used by the Brain Review screen to render the full history list.
Source§

fn review_queue(&self) -> Vec<ReviewItemSummary>

Priority-ordered review queue. Built from all_decisions() plus the brain’s queue-building heuristics (counterfactual hits, Critical-tier safety cases, high-confidence misses).
Source§

impl BrainView for MockRuntime

Source§

fn gate_mode(&self) -> BrainGateMode

Source§

fn recent_decisions(&self, n: usize) -> Vec<DecisionSummary>

Most recent n decisions, newest first.
Source§

fn decision_count(&self) -> usize

Total count of brain decisions on disk. Drives the “decisions: N” status line.
Source§

impl BusView for MockRuntime

Source§

impl CoordView for MockRuntime

Source§

fn active_leases(&self) -> Vec<LeaseSummary>

Source§

fn pending_handoffs(&self) -> Vec<HandoffSummary>

Source§

fn pending_interrupts(&self) -> Vec<InterruptSummary>

Source§

fn tasks(&self) -> Vec<TaskSummary>

Supervisor task lifecycles, newest first. Empty when the coord feature is off so the TUI can render a “no supervisor” state without cfg.
Source§

impl Default for MockRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl HiveActions for MockRuntime

Source§

fn shared_skill_keys(&self) -> HashSet<String>

Semantic keys (skill:<lowered-name>) of skills already shared into the local hive store. Used by the Skills overlay to mark “already shared” rows.
Source§

fn share_skill(&self, _skill: &DiscoveredSkill) -> Result<String, String>

Share a discovered skill into the local hive store. Returns the new unit ID on success.
Source§

fn hive_view_snapshot(&self) -> HiveViewSnapshot

Current view of the local relay identity + known peers for the Hive tab.
Source§

impl Orchestrator for MockRuntime

Source§

fn deliver_mailbox(&self, _sessions: &[SessionSnapshot]) -> Vec<(u32, String)>

Drain pending mailbox messages addressed to running sessions and deliver them to the live terminals. Used by App::tick to surface "Brain → sess_X: 'go ahead'" style messages.
Source§

fn deliver_interrupts( &self, _sessions: &[SessionSnapshot], ) -> Vec<(String, String)>

Deliver pending coordination interrupts (cross-agent signals) to running sessions. Returns (interrupt_id, status_message) tuples.
Source§

fn expire_stale(&self)

Expire stale leases and interrupts that have passed their deadline. Bookkeeping side-effect; best-effort, no return. Implementations log failures rather than propagating them.
Source§

impl SessionSource for MockRuntime

Source§

fn list(&self) -> Vec<SessionSnapshot>

Snapshot of every running Claude Code session. Order is the implementor’s choice; the TUI sorts again client-side.
Source§

fn detail(&self, session_id: &str) -> Option<SessionSnapshot>

Fetch a specific session by its ID. None when the session has exited or never existed.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.