Skip to main content

Context

Struct Context 

Source
pub struct Context {
Show 22 fields pub brain_wave: BrainWave, pub session_id: Option<Uuid>, pub user_id: Option<String>, pub meta: HashMap<String, Value>, pub scratchpad: HashMap<String, Value>, pub dharma_profile: Option<String>, pub compartment: Option<String>, pub karma_debt: f32, pub intent_score: f32, pub citta_coherence: f32, pub citta_valence: f32, pub self_model_confidence: f32, pub drive_curiosity: f32, pub drive_caution: f32, pub drive_energy: f32, pub drive_exploration_weight: f32, pub drive_conservative_weight: f32, pub last_gana: Option<Gana>, pub readonly: bool, pub explicit_confirm: bool, pub operation_id: Option<String>, pub spawn: SpawnPolicy,
}
Expand description

Per-request execution context.

Fields§

§brain_wave: BrainWave

Current brain-wave state

§session_id: Option<Uuid>

Session ID (if in a session)

§user_id: Option<String>

User ID (for multi-user isolation)

§meta: HashMap<String, Value>

Request metadata (from MCP client)

§scratchpad: HashMap<String, Value>

Scratchpad for intermediate results within a single dispatch

§dharma_profile: Option<String>

Whether this request is running under a Dharma governance profile

§compartment: Option<String>

Mandala compartment (research/sandbox/production/secure)

§karma_debt: f32

Cached karma debt (updated post-dispatch, synced periodically)

§intent_score: f32

Intent score for this request (0.0 = low intent, 1.0 = high intent)

§citta_coherence: f32

Citta coherence at dispatch time (0.0–1.0). Low coherence blocks writes.

§citta_valence: f32

Citta valence at dispatch time (−1.0 to 1.0). Negative = displeasure.

§self_model_confidence: f32

Self-model confidence at dispatch time (0.0–1.0). Below 0.5 triggers conservative dispatch (prefer cached results).

§drive_curiosity: f32

Drive curiosity level (0.0–1.0). High curiosity → exploration bias.

§drive_caution: f32

Drive caution level (0.0–1.0). High caution → conservative bias.

§drive_energy: f32

Drive energy level (0.0–1.0). Low energy → lightweight tool bias.

§drive_exploration_weight: f32

Drive exploration weight (0.0–1.0). Derived from curiosity.

§drive_conservative_weight: f32

Drive conservative weight (0.0–1.0). Derived from caution.

§last_gana: Option<Gana>

Last Gana dispatched in this context (for co-usage tracking, Phase 6)

§readonly: bool

Read-only server mode — the dispatch pipeline refuses any tool that declares writes while this is set.

§explicit_confirm: bool

Whether this dispatch carries an explicit confirm: true from the caller. The dispatch pipeline sets it before the Dharma gate runs so that deliberate operator intent can pass the brain-wave strict-mode block (Theta/Delta) for destructive tools — stressed-homeostasis blocks stay absolute. 9.1.6.

§operation_id: Option<String>

Operation ID (monotonic time-ordered ID) grouping multi-step write sequences (U6). Enables crash detection across multi-tool dispatches.

§spawn: SpawnPolicy

Subprocess spawn confinement policy (B2). The dispatcher resolves it for tools that declare Sandbox::Subprocess (or spawns) and tools build every external command through SpawnPolicy::command.

Implementations§

Source§

impl Context

Source

pub fn new(brain_wave: BrainWave) -> Self

Create a new context with the given brain-wave state.

Source

pub fn with_operation_id(self, op_id: impl Into<String>) -> Self

Set the operation ID for this context (U6).

Source

pub const fn brain_wave(&self) -> BrainWave

Get the current brain-wave state.

Source

pub fn set(&mut self, key: impl Into<String>, value: Value)

Set a scratchpad value.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get a scratchpad value.

Source

pub fn can_access_galaxy(&self, galaxy: Galaxy) -> bool

Check if this context has access to the given galaxy.

Compartment-based access control:

  • None (default): full access to all galaxies (backward compatible)
  • sandbox: only Tutorial and Research (no production data)
  • production: all memory galaxies except system (Karma, Dharma, Substrate)
  • secure: all memory galaxies
Source

pub fn can_write_galaxy(&self, galaxy: Galaxy) -> bool

Check if this context allows write operations to the given galaxy.

Sandbox is read-only for Research (can write to Tutorial only).

Trait Implementations§

Source§

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> 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 = !

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