Skip to main content

TreeManager

Struct TreeManager 

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

Unified facade over ResourceTree + MutationLog + ChainManager.

Every mutating operation on the tree also:

  1. Appends a MutationEvent to the mutation log
  2. Appends a ChainEvent to the chain
  3. Stores chain_seq metadata on the affected tree node

Implementations§

Source§

impl TreeManager

Source

pub fn new(chain: Arc<ChainManager>) -> Self

Create a new TreeManager with an empty tree and mutation log.

Source

pub fn set_signing_key(&mut self, key: SigningKey)

Set the Ed25519 signing key for signing tree mutations. When set, all mutations will have their signature field populated.

Source

pub fn bootstrap(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Bootstrap the tree with well-known WeftOS namespaces.

Creates the standard namespace hierarchy (/kernel, /kernel/services, etc.), logs a MutationEvent::Create for each bootstrapped node, and appends a tree.bootstrap chain event with node count and root hash.

Source

pub fn insert( &self, id: ResourceId, kind: ResourceKind, parent: ResourceId, ) -> Result<(), Box<dyn Error + Send + Sync>>

Insert a new resource node into the tree.

Creates the tree node, appends a MutationEvent::Create, appends a tree.insert chain event, and stores the chain sequence number as metadata on the node for two-way traceability.

Source

pub fn remove(&self, id: ResourceId) -> Result<(), Box<dyn Error + Send + Sync>>

Remove a leaf node from the tree.

Removes the node, appends a MutationEvent::Remove and a tree.remove chain event.

Source

pub fn update_meta( &self, id: &ResourceId, key: &str, value: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>

Update metadata on a resource node.

Sets the key-value pair on the node, appends a MutationEvent::UpdateMeta and a tree.update_meta chain event.

Source

pub fn register_service( &self, name: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service in the tree, creating /kernel/services/{name}.

This is the unified path for service registration: it inserts the tree node AND creates the chain event atomically.

Source

pub fn register_service_with_manifest( &self, name: &str, service_type: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register a service with a manifest chain event.

Inserts the tree node and emits an additional service.manifest chain event with structured metadata (name, type, tree path, registration time). This produces an RVF-auditable registration when the chain is persisted as RVF segments.

Source

pub fn register_agent( &self, agent_id: &str, pid: Pid, caps: &AgentCapabilities, ) -> Result<(), Box<dyn Error + Send + Sync>>

Register an agent in the tree, creating /kernel/agents/{agent_id}.

Creates the tree node with kind Agent, sets metadata (pid, state, spawn_time), and emits an agent.spawn chain event.

Source

pub fn unregister_agent( &self, agent_id: &str, pid: Pid, exit_code: i32, ) -> Result<(), Box<dyn Error + Send + Sync>>

Unregister an agent from the tree.

Updates the tree node metadata (state=exited, exit_code, stop_time) and emits an agent.stop chain event. Does NOT remove the node (preserves audit trail).

Source

pub fn update_agent_state( &self, agent_id: &str, state: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>

Update an agent’s state in the tree.

Source

pub fn tree(&self) -> &Mutex<ResourceTree>

Get direct access to the resource tree (for read-only queries).

Source

pub fn mutation_log(&self) -> &Mutex<MutationLog>

Get direct access to the mutation log.

Source

pub fn chain(&self) -> &Arc<ChainManager>

Get the chain manager.

Source

pub fn root_hash(&self) -> [u8; 32]

Get the root hash of the resource tree.

Source

pub fn stats(&self) -> TreeStats

Get a statistics snapshot.

Source

pub fn update_scoring( &self, id: &ResourceId, scoring: NodeScoring, ) -> Result<(), Box<dyn Error + Send + Sync>>

Set the scoring vector for a node.

Updates the tree, logs a MutationEvent::UpdateScoring, and emits a scoring.update chain event.

Source

pub fn blend_scoring( &self, id: &ResourceId, observation: &NodeScoring, alpha: f32, ) -> Result<(), Box<dyn Error + Send + Sync>>

EMA-blend an observation into a node’s scoring.

Emits a scoring.blend chain event.

Source

pub fn get_scoring(&self, id: &ResourceId) -> Option<NodeScoring>

Get the scoring vector for a node.

Source

pub fn find_similar( &self, target_id: &ResourceId, count: usize, ) -> Vec<(ResourceId, f32)>

Find nodes most similar to a target node by cosine similarity.

Returns up to count (ResourceId, similarity) pairs sorted by descending similarity.

Source

pub fn rank_by_score( &self, weights: &[f32; 6], count: usize, ) -> Vec<(ResourceId, f32)>

Rank all nodes by weighted score.

Returns up to count (ResourceId, weighted_score) pairs sorted by descending score.

Source

pub fn build_tool( &self, name: &str, wasm_bytes: &[u8], signing_key: &SigningKey, ) -> Result<ToolVersion, Box<dyn Error + Send + Sync>>

Build a tool: validate WASM bytes, compute hash, sign with Ed25519.

Returns a ToolVersion with the computed module hash and Ed25519 signature. Emits a tool.build chain event.

Source

pub fn deploy_tool( &self, spec: &BuiltinToolSpec, version: &ToolVersion, ) -> Result<(), Box<dyn Error + Send + Sync>>

Deploy a tool to the resource tree.

Creates the tool node at /kernel/tools/{category}/{name}, stores version metadata, and emits a tool.deploy chain event.

Source

pub fn update_tool_version( &self, name: &str, new_version: &ToolVersion, ) -> Result<(), Box<dyn Error + Send + Sync>>

Update a tool to a new version.

Updates the tool node’s metadata with new version info and emits a tool.version.update chain event linking old to new.

Source

pub fn revoke_tool_version( &self, name: &str, version: u32, ) -> Result<(), Box<dyn Error + Send + Sync>>

Revoke a tool version.

Marks the specified version as revoked in metadata. Does NOT delete the tree node (preserves audit trail). Emits a tool.version.revoke chain event.

Source

pub fn get_tool_versions(&self, name: &str) -> Vec<Value>

Query version history for a tool (K4 B2).

Returns the list of version entries persisted in the tree metadata, or an empty vec if the tool has no versions.

Source

pub fn save_checkpoint( &self, path: &Path, ) -> Result<(), Box<dyn Error + Send + Sync>>

Save tree state to a checkpoint file on disk.

Serializes the tree via exo_resource_tree::to_checkpoint() and writes the bytes to the given path.

Source

pub fn load_checkpoint( &self, path: &Path, ) -> Result<(), Box<dyn Error + Send + Sync>>

Load tree state from a checkpoint file.

Reads the file, deserializes via exo_resource_tree::from_checkpoint(), and replaces the internal tree. The mutation log is cleared.

Source

pub fn checkpoint(&self) -> Result<Value, Box<dyn Error + Send + Sync>>

Create a combined checkpoint of tree + mutation log + chain state.

Returns JSON with the tree checkpoint, mutation count, and chain checkpoint info. Full checkpoint persistence is a K1 concern.

Source

pub fn snapshot(&self) -> Result<TreeSnapshot, Box<dyn Error + Send + Sync>>

Create a serializable snapshot of the full tree state. Used for cross-node tree synchronization in K6.4.

Source

pub fn apply_remote_mutation( &self, event: MutationEvent, ) -> Result<(), Box<dyn Error + Send + Sync>>

Apply a remote mutation received from a peer node. Records the mutation in the local log.

Security note (K6.4): Full implementation should verify event.signature against the sending node’s Ed25519 public key before applying. Currently signature verification is deferred to the mesh transport layer (Noise channel authenticates the peer).

Trait Implementations§

Source§

impl Debug for TreeManager

Source§

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

Formats the value using the given formatter. 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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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: 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: 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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