pub struct TreeManager { /* private fields */ }Expand description
Unified facade over ResourceTree + MutationLog + ChainManager.
Every mutating operation on the tree also:
- Appends a
MutationEventto the mutation log - Appends a
ChainEventto the chain - Stores
chain_seqmetadata on the affected tree node
Implementations§
Source§impl TreeManager
impl TreeManager
Sourcepub fn new(chain: Arc<ChainManager>) -> Self
pub fn new(chain: Arc<ChainManager>) -> Self
Create a new TreeManager with an empty tree and mutation log.
Sourcepub fn set_signing_key(&mut self, key: SigningKey)
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.
Sourcepub fn bootstrap(&self) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn insert(
&self,
id: ResourceId,
kind: ResourceKind,
parent: ResourceId,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn remove(&self, id: ResourceId) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn update_meta(
&self,
id: &ResourceId,
key: &str,
value: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn register_service(
&self,
name: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn register_service_with_manifest(
&self,
name: &str,
service_type: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn register_agent(
&self,
agent_id: &str,
pid: Pid,
caps: &AgentCapabilities,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn unregister_agent(
&self,
agent_id: &str,
pid: Pid,
exit_code: i32,
) -> Result<(), Box<dyn Error + Send + Sync>>
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).
Sourcepub fn update_agent_state(
&self,
agent_id: &str,
state: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn tree(&self) -> &Mutex<ResourceTree>
pub fn tree(&self) -> &Mutex<ResourceTree>
Get direct access to the resource tree (for read-only queries).
Sourcepub fn mutation_log(&self) -> &Mutex<MutationLog>
pub fn mutation_log(&self) -> &Mutex<MutationLog>
Get direct access to the mutation log.
Sourcepub fn chain(&self) -> &Arc<ChainManager>
pub fn chain(&self) -> &Arc<ChainManager>
Get the chain manager.
Sourcepub fn update_scoring(
&self,
id: &ResourceId,
scoring: NodeScoring,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn blend_scoring(
&self,
id: &ResourceId,
observation: &NodeScoring,
alpha: f32,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn get_scoring(&self, id: &ResourceId) -> Option<NodeScoring>
pub fn get_scoring(&self, id: &ResourceId) -> Option<NodeScoring>
Get the scoring vector for a node.
Sourcepub fn find_similar(
&self,
target_id: &ResourceId,
count: usize,
) -> Vec<(ResourceId, f32)>
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.
Sourcepub fn rank_by_score(
&self,
weights: &[f32; 6],
count: usize,
) -> Vec<(ResourceId, f32)>
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.
Sourcepub fn build_tool(
&self,
name: &str,
wasm_bytes: &[u8],
signing_key: &SigningKey,
) -> Result<ToolVersion, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn deploy_tool(
&self,
spec: &BuiltinToolSpec,
version: &ToolVersion,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn update_tool_version(
&self,
name: &str,
new_version: &ToolVersion,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn revoke_tool_version(
&self,
name: &str,
version: u32,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn get_tool_versions(&self, name: &str) -> Vec<Value>
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.
Sourcepub fn save_checkpoint(
&self,
path: &Path,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn load_checkpoint(
&self,
path: &Path,
) -> Result<(), Box<dyn Error + Send + Sync>>
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.
Sourcepub fn checkpoint(&self) -> Result<Value, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn snapshot(&self) -> Result<TreeSnapshot, Box<dyn Error + Send + Sync>>
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.
Sourcepub fn apply_remote_mutation(
&self,
event: MutationEvent,
) -> Result<(), Box<dyn Error + Send + Sync>>
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§
Auto Trait Implementations§
impl !Freeze for TreeManager
impl RefUnwindSafe for TreeManager
impl Send for TreeManager
impl Sync for TreeManager
impl Unpin for TreeManager
impl UnsafeUnpin for TreeManager
impl UnwindSafe for TreeManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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