Skip to main content

ContextState

Struct ContextState 

Source
pub struct ContextState { /* private fields */ }
Expand description

The shared context for a Converge job.

Agents receive &dyn converge_pack::Context (immutable) during execution. Only the engine holds &mut Context during the merge phase.

Implementations§

Source§

impl ContextState

Source

pub fn new() -> Self

Creates a new empty context.

Source

pub fn snapshot(&self) -> ContextSnapshot

Captures a durable storage snapshot for later rehydration.

Source

pub fn from_snapshot(snapshot: ContextSnapshot) -> Result<Self, ConvergeError>

Rehydrates a context from a verified storage snapshot.

This restores previously promoted context state. It is not a promotion API: malformed snapshots, key mismatches, duplicate IDs, and Merkle mismatches are rejected before the context is returned.

Source

pub fn get(&self, key: ContextKey) -> &[ContextFact]

Returns all facts for a given key.

Source

pub fn has(&self, key: ContextKey) -> bool

Returns true if there are any facts for the given key.

Source

pub fn version(&self) -> u64

Returns the current version (for convergence detection).

Source

pub fn dirty_keys(&self) -> &[ContextKey]

Returns keys that changed in the last merge cycle.

Source

pub fn all_keys(&self) -> Vec<ContextKey>

Returns all keys that currently have facts in the context.

Source

pub fn has_pending_proposals(&self) -> bool

Returns true if any staged proposals are pending promotion.

Source

pub fn clear_dirty(&mut self)

Clears the dirty key tracker (called at start of each cycle).

Source

pub fn add_proposal( &mut self, proposal: ProposedFact, ) -> Result<bool, ConvergeError>

Stages a proposal for engine validation/promotion.

Returns Ok(true) if the proposal was new. Returns Ok(false) if an identical proposal is already pending.

Source

pub fn add_input( &mut self, key: ContextKey, id: impl Into<ProposalId>, content: impl Into<String>, ) -> Result<bool, ConvergeError>

Stages external input as a proposal to be governed by the engine.

Source

pub fn add_input_with_provenance( &mut self, key: ContextKey, id: impl Into<ProposalId>, content: impl Into<String>, provenance: impl Into<String>, ) -> Result<bool, ConvergeError>

Stages external input with explicit provenance.

Source

pub fn submit_observation( &mut self, request: AdmissionRequest, ) -> Result<AdmissionReceipt, ConvergeError>

Stages a typed external observation as a proposal.

This is the preferred boundary for systems such as Organism. It records actor and source provenance, but it does not create authoritative facts.

Trait Implementations§

Source§

impl Clone for ContextState

Source§

fn clone(&self) -> ContextState

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 Context for ContextState

Implement the converge-pack Context trait for the concrete Context struct. This allows agents to use &dyn converge_pack::Context.

Source§

fn has(&self, key: ContextKey) -> bool

Check whether any facts exist under this key.
Source§

fn get(&self, key: ContextKey) -> &[ContextFact]

Get all read-only context fact projections under this key.
Source§

fn get_proposals(&self, key: ContextKey) -> &[ProposedFact]

Get all proposed facts (unvalidated).
Source§

fn count(&self, key: ContextKey) -> usize

Count of facts under a key.
Source§

fn formation_kind(&self) -> Option<FormationKind>

The kind of formation orchestrating this suggestor’s current execution, if any. None means the suggestor is running outside a formation harness (e.g., the engine’s default registration path); fall back to standalone behavior. Read more
Source§

impl Debug for ContextState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ContextState

Source§

fn default() -> ContextState

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

impl Serialize for ContextState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<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> 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