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 mutation_canonical_bytes( operation: &str, path: &str, timestamp: &DateTime<Utc>, ) -> Vec<u8> ⓘ

Build the canonical bytes for a mutation signature.

Format: "<operation>|<path>|<timestamp_rfc3339>" encoded as UTF-8.

Source

pub fn mutation_sign_parts(event: &MutationEvent) -> Option<MutationSignParts>

Extract (operation, path, timestamp, signature) from a mutation event.

Source

pub fn verify_mutation_signature( event: &MutationEvent, pubkey: &VerifyingKey, ) -> Result<(), Box<dyn Error + Send + Sync>>

Verify an Ed25519 signature on a mutation event (WEFT-144).

Returns Ok(()) when the signature is present and valid under pubkey. Errors when the signature is missing, malformed, or does not verify.

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.

Does not verify signatures — prefer Self::apply_remote_mutation_verified for cross-node events (WEFT-144). Kept for local/unsigned bootstrap paths.

Source

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

Apply a remote mutation after verifying its Ed25519 signature against the peer’s public key (WEFT-144).

Rejects missing, malformed, and invalid signatures. Create is idempotent when the node already exists (replay-safe).

Source

pub fn merkle_diff( &self, other: &TreeManager, ) -> Result<MerkleDiff, Box<dyn Error + Send + Sync>>

Compute a minimal Merkle diff of self against other.

Only subtrees whose hashes differ are visited (O(changed), not O(tree)).

Source

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

Generate a Merkle inclusion proof for a resource path.

Source

pub fn verify_merkle_proof( &self, proof: &MerkleInclusionProof, ) -> Result<bool, Box<dyn Error + Send + Sync>>

Verify a Merkle inclusion proof against this tree’s root.

Source

pub fn signed_events_for_diff( &self, diff: &MerkleDiff, ) -> Result<Vec<MutationEvent>, Box<dyn Error + Send + Sync>>

Collect signed mutation events from the local log that touch paths in diff (Added / Modified / Removed). Used to ship authenticated deltas alongside a MerkleDiff (WEFT-106 + WEFT-144).

Source

pub fn apply_merkle_diff_verified( &self, diff: &MerkleDiff, signed_events: &[MutationEvent], peer_pubkey: &VerifyingKey, ) -> Result<usize, Box<dyn Error + Send + Sync>>

Apply a peer’s Merkle diff using verified signed mutation events (WEFT-106 wired to WEFT-144 apply_remote_mutation_verified).

Events are applied in log order. Each must carry a valid Ed25519 signature under peer_pubkey. After structural events, node payloads from the diff (metadata / scoring) are reconciled so Merkle roots converge — MutationEvent::Create does not carry full metadata, so the minimal-witness payload is authoritative for those fields once the path is authenticated by a signed Create/Update.

Source

pub fn tree_sync_response_from_diff( &self, diff: &MerkleDiff, ) -> Result<TreeSyncResponse, Box<dyn Error + Send + Sync>>

Build a mesh crate::mesh_tree::TreeSyncResponse from a MerkleDiff.

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> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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 = !

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