Skip to main content

wm_tools/expansion/
mod.rs

1//! Expansion tools — 77 tool implementations organized by category.
2//!
3//! Modules:
4//! - `memory_ops`: consolidate, decay, batch_read, update, tag, stats, hybrid_recall, sort, filter, deduplicate, export
5//! - `session`: start, checkpoint, recall, end
6//! - `consciousness`: citta.status, citta.reflect, dream.status, dream.trigger
7//! - `tools_mgmt`: usage_report, effectiveness_report, retire
8//! - `patterns`: pattern.search, salience.spotlight, serendipity.surface
9//! - `constellation`: detect, list
10//! - `galaxy`: stats, export, import, transfer, merge, snapshot, restore, dashboard, backup, taxonomy, purge, health
11//! - `karma`: history, clear
12//! - `dharma`: rules, audit
13//! - `agents`: register, list, heartbeat, trust, descriptions, capabilities, heartbeat.history, deregister
14//! - `tasks`: distribute, status
15//! - `system`: health, config, flush
16//! - `association`: associate_mine
17//! - `network`: association.mine, pattern.detect, emergence.report, network.stats, network.centrality, network.clusters
18//! - `additional`: count, tags, session_list, citta_coherence, dharma_profiles, nearby
19//! - `autonomous`: spiral.report, consolidation.connect/compress, emergence.scan, retention.prune
20//! - `knowledge_graph`: kg.extract, kg.query, kg.top
21//! - `graph`: graph.walk, graph.community, graph.propagate
22//! - `archaeology`: archaeology.search, learning.pattern, learning.suggest
23//! - `reasoning`: reasoning.bicameral, think, explain
24//! - `pipeline`: pipeline.create/list/status, skill.invoke/list
25//! - `anomaly`: anomaly.detect, state.snapshot, state.revert
26//! - `correlation`: correlation.analyze, god.nodes, kaizen.correlate
27//! - `geneseed`: geneseed.mine, geneseed.stats
28//! - `boundary`: anti_loop.check, boundary.enforce
29//! - `homeostasis`: homeostasis.check, homeostasis.adjust, homeostasis.history, homeostasis.alerts
30//! - `transaction`: transaction.begin, transaction.commit, transaction.rollback
31
32#![forbid(unsafe_code)]
33
34pub mod additional;
35pub mod agents;
36pub mod anomaly;
37pub mod archaeology;
38pub mod army;
39pub mod association;
40pub mod autonomous;
41pub mod bagua;
42pub mod bayesian_tools;
43pub mod bicameral;
44pub mod boundary;
45pub mod bounty_connector;
46pub mod bounty_evidence;
47pub mod bounty_ledger;
48pub mod captains;
49pub mod claims_tools;
50pub mod code;
51pub mod common;
52pub mod conformal;
53pub mod consciousness;
54pub mod constellation;
55pub mod coordination;
56pub mod correlation;
57pub mod dharma;
58pub mod drive;
59pub mod firewall;
60pub mod galaxy;
61pub mod geneseed;
62pub mod glyph;
63pub mod graph;
64pub mod homeostasis;
65pub mod imagination;
66pub mod karma;
67pub mod knowledge_graph;
68pub mod lkep;
69pub mod memory_ops;
70pub mod mesh_tools;
71pub mod network;
72pub mod nlu_tools;
73pub mod oss_bounty;
74pub mod patterns;
75pub mod pipeline;
76pub mod pray;
77pub mod reasoning;
78pub mod research;
79pub mod resonance;
80pub mod rsi;
81pub mod sandbox;
82pub mod sangha_tools;
83pub mod security_breaker;
84pub mod security_probe;
85pub mod self_play;
86pub mod selfmodel;
87pub mod sensorimotor_tools;
88pub mod session;
89pub mod session_ops;
90pub mod simulation_tools;
91pub mod system;
92pub mod tasks;
93pub mod tools_mgmt;
94pub mod transaction;
95pub mod v4;
96pub mod violet;
97pub mod web;
98
99// Re-export all tool structs for registration
100pub use additional::{
101    CittaCoherenceTool, DharmaProfilesTool, MemoryCountTool, MemoryNearbyTool, MemoryTagsTool,
102    SessionListTool,
103};
104pub use agents::{
105    AgentCapabilitiesTool, AgentDeregisterTool, AgentDescriptionsTool, AgentHeartbeatHistoryTool,
106    AgentHeartbeatTool, AgentListTool, AgentRegisterTool, AgentTrustTool,
107};
108pub use anomaly::{AnomalyDetectTool, StateRevertTool, StateSnapshotTool};
109pub use archaeology::{ArchaeologySearchTool, LearningPatternTool, LearningSuggestTool};
110pub use army::{ArmyDeployTool, GalacticColdRotateTool, GalacticTriageTool};
111pub use association::{MemoryAssociateMineTool, MemoryCorroborateTool, MemoryRelateTool};
112pub use autonomous::{
113    ConsolidationCompressTool, ConsolidationConnectTool, EmergenceScanTool, RetentionPruneTool,
114    SensorimotorScanTool, SpiralReportTool,
115};
116pub use bagua::BaguaDispatchTool;
117pub use bayesian_tools::{McOptimizeTool, McSurrogateTool};
118pub use bicameral::{BicameralReasonTool, BicameralStatusTool};
119pub use boundary::{AntiLoopCheckTool, BoundaryEnforceTool};
120pub use captains::{CaptainDeployTool, HologramQueryTool, HologramRebalanceTool};
121pub use claims_tools::{ClaimsTool, register_claims};
122pub use consciousness::{
123    ApotheosisCheckTool, CittaHistoryTool, CittaReflectTool, CittaStatusTool,
124    ConsciousnessDepthTool, DreamAnalyzeTool, DreamStatusTool, DreamTriggerTool, SmaranaStatusTool,
125    SmaranaTraceTool,
126};
127pub use constellation::{ConstellationDetectTool, ConstellationListTool};
128pub use coordination::{
129    CodeCheckTool, CodeClaimTool, CodeListTool, CodeReleaseTool, Lease, LeaseLedger,
130    register_coordination,
131};
132pub use correlation::{CorrelationAnalyzeTool, GodNodesTool, KaizenCorrelateTool};
133pub use dharma::{
134    DharmaAcsTool, DharmaAuditTool, DharmaEscalateTool, DharmaResolveReviewTool,
135    DharmaReviewQueueTool, DharmaRulesTool,
136};
137pub use drive::{DriveEventTool, DriveSnapshotTool};
138pub use galaxy::{
139    GalaxyBackupTool, GalaxyDashboardTool, GalaxyExportTool, GalaxyHealthTool, GalaxyImportTool,
140    GalaxyMergeTool, GalaxyPurgeTool, GalaxyRestoreTool, GalaxySnapshotTool, GalaxyStatsTool,
141    GalaxyTaxonomyTool, GalaxyTransferTool,
142};
143pub use geneseed::{GeneseedMineTool, GeneseedStatsTool};
144pub use graph::{GraphCommunityTool, GraphPropagateTool, GraphWalkTool};
145pub use homeostasis::{
146    HomeostasisAdjustTool, HomeostasisAlertsTool, HomeostasisCheckTool, HomeostasisHistoryTool,
147};
148pub use imagination::{
149    ImaginePredictTool, ImagineReflectTool, ImagineScenarioTool, register_imagination,
150};
151pub use karma::{KarmaAnchorTool, KarmaClearTool, KarmaHistoryTool, KarmaVerifyChainTool};
152pub use knowledge_graph::{KgExtractTool, KgQueryTool, KgTopTool};
153pub use memory_ops::{
154    MemoryAggregateTool, MemoryBatchReadTool, MemoryConsolidateTool, MemoryDecayTool,
155    MemoryDeduplicateTool, MemoryEpisodicSearchTool, MemoryExportTool, MemoryFilterTool,
156    MemoryHybridRecallTool, MemoryRecallFeedbackTool, MemoryRevisionsTool, MemorySortTool,
157    MemoryStatsTool, MemoryTagTool, MemoryUpdateTool,
158};
159pub use mesh_tools::{
160    MeshChatTool, MeshJoinTool, MeshQuarantineTool, MeshReadTool, MeshStatusTool,
161    register_sangha_mesh,
162};
163pub use network::{
164    AssociationMineTool, EmergenceReportTool, NetworkCentralityTool, NetworkClustersTool,
165    NetworkStatsTool, PatternDetectTool,
166};
167pub use nlu_tools::NluShadowReportTool;
168pub use patterns::{PatternSearchTool, SalienceSpotlightTool, SerendipitySurfaceTool};
169pub use pipeline::{
170    PipelineCreateTool, PipelineListTool, PipelineStatusTool, SkillInvokeTool, SkillListTool,
171};
172pub use pray::{HongmenRank, PrayMetaTool, WhiteLotusLodge};
173pub use reasoning::{ExplainTool, ReasoningBicameralTool, ThinkTool};
174pub use research::{
175    ResearchRabbitHoleTool, ResearchRepoTool, ResearchTopicTool, register_research,
176};
177pub use resonance::{BusEmitTool, BusRecentTool, BusStatsTool};
178pub use rsi::{
179    ActiveProposalsTool, DispatchTelemetry, FrictionAutoLogTool, FrictionLogTool,
180    FrictionResolveTool, FrictionReviewTool, ImproveProposalsTool, RedteamCoverageReportTool,
181    RedteamFromFrictionTool, RedteamProposalsTool, friction_hash, friction_hash_exists,
182};
183pub use sangha_tools::{
184    SanghaChatTool, SanghaDiscoverTool, SanghaLocksTool, SanghaPeersTool, SanghaQuarantineTool,
185    SanghaSignalTool,
186};
187pub use self_play::{
188    SelfPlayExportTool, SelfPlayRunTool, SelfPlayStatusTool, SharedSelfPlayLoop,
189    build_self_play_loop, new_shared_loop, register_self_play,
190};
191pub use sensorimotor_tools::{
192    ActuatorCommandTool, ActuatorEStopTool, ActuatorListTool, ReflexAddTool, ReflexEvaluateTool,
193    ReflexListTool, SensorHistoryTool, SensorListTool, SensorPollTool, SensorReadTool,
194};
195pub use session::{
196    SessionCheckpointTool, SessionEndTool, SessionRecallTool, SessionStartTool, SessionVerifyTool,
197};
198pub use session_ops::{
199    SessionContinuityTool, SessionDigestTool, SessionExportTool, SessionHandoffTool,
200    SessionImportTool, SessionRecordTool, SessionReplayTool, register_session_ops,
201};
202pub use simulation_tools::{SimCounterfactualTool, SimForecastTool, SimMcTool};
203pub use system::{SystemConfigTool, SystemFlushTool, SystemHealthTool};
204pub use tasks::{TaskDistributeTool, TaskStatusTool};
205pub use tools_mgmt::{ToolsEffectivenessReportTool, ToolsRetireTool, ToolsUsageReportTool};
206pub use transaction::{
207    TransactionBeginTool, TransactionCommitTool, TransactionRollbackTool, TransactionState,
208};
209pub use v4::{
210    ReflexDispatchTool, ReflexStatusTool, TimescaleHooksTool, TimescaleStatusTool,
211    WorkspaceEventsTool, WorkspacePublishTool, WorkspaceSpotlightTool, WorkspaceStatsTool,
212};
213pub use web::{WebDeepFetchTool, WebFetchTool, WebSearchAndReadTool, WebSearchTool, register_web};
214
215use std::sync::Arc;
216use wm_cognitive::GanYingBus;
217use wm_governance::KarmaLedger;
218use wm_memory::{AssociationStore, MemoryStore, RecallEngine, SearchEngine};
219use wm_substrate::SubstrateMonitor;
220use wm_substrate::anomaly::AnomalyDetector;
221use wm_substrate::homeostatic::HomeostaticLoop;
222use wm_substrate::sensorimotor::{ReflexLoop, SensorimotorBus};
223
224/// Build the PRAY meta-tool with the same cleanup wiring its cold-rotation
225/// child receives standalone, so the wrapper never silently degrades it.
226fn pray_meta_tool(
227    store: &Arc<MemoryStore>,
228    search: Option<Arc<SearchEngine>>,
229    associations: Arc<AssociationStore>,
230) -> Arc<PrayMetaTool> {
231    let mut tool = PrayMetaTool::new(store.clone()).with_associations(associations);
232    if let Some(search) = search {
233        tool = tool.with_search(search);
234    }
235    Arc::new(tool)
236}
237
238/// Build the cold-rotation tool with full cleanup wiring: Tantivy
239/// de-indexing plus association cleanup (mirrors `memory.deduplicate`).
240fn cold_rotate_tool(
241    store: &Arc<MemoryStore>,
242    search: Option<Arc<SearchEngine>>,
243    associations: Arc<AssociationStore>,
244) -> Arc<GalacticColdRotateTool> {
245    let mut tool = GalacticColdRotateTool::new(store.clone()).with_associations(associations);
246    if let Some(search) = search {
247        tool = tool.with_search(search);
248    }
249    Arc::new(tool)
250}
251
252/// Register all expansion tools into a registry.
253///
254/// Registry persistence is an explicit construction input so evaluator
255/// preservation never depends on mutable process-global state.
256#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
257pub enum RegistryPersistenceMode {
258    /// Ordinary writable and readonly servers retain stable Violet identity.
259    #[default]
260    Normal,
261    /// Frozen evaluators use process-local Violet identity and write no keys.
262    EvaluatorPreservation,
263}
264
265#[allow(clippy::too_many_arguments)]
266pub fn register_expansion(
267    registry: &wm_dispatch::ToolRegistry,
268    store: &Arc<MemoryStore>,
269    search: Option<Arc<SearchEngine>>,
270    recall: Option<Arc<RecallEngine>>,
271    associations: Arc<AssociationStore>,
272    spiral_tracker: Arc<std::sync::Mutex<wm_cognitive::SpiralTracker>>,
273    karma: Option<Arc<KarmaLedger>>,
274    substrate: Option<Arc<SubstrateMonitor>>,
275    homeostatic_loop: Option<Arc<std::sync::Mutex<HomeostaticLoop>>>,
276    anomaly_detector: Option<Arc<std::sync::Mutex<AnomalyDetector>>>,
277    sensorimotor_bus: Option<Arc<std::sync::Mutex<SensorimotorBus>>>,
278    reflex_loop: Option<Arc<std::sync::Mutex<ReflexLoop>>>,
279    gan_ying_bus: Option<&Arc<std::sync::Mutex<GanYingBus>>>,
280    transaction_state: TransactionState,
281    resource_rules: Option<&Arc<wm_governance::ResourceRules>>,
282    escalation_queue: Option<&Arc<std::sync::Mutex<wm_governance::EscalationQueue>>>,
283    dharma_gate: Option<&Arc<wm_governance::DharmaGate>>,
284    firewall: Option<&Arc<crate::expansion::firewall::TxFirewall>>,
285    code_graph: Option<&Arc<std::sync::Mutex<crate::expansion::code::CodeGraph>>>,
286    registry_persistence: RegistryPersistenceMode,
287) -> wm_dispatch::ToolRegistry {
288    let reg = registry
289        // Memory ops (7)
290        .register(Arc::new(MemoryConsolidateTool::new(
291            store.clone(),
292            search.clone(),
293        )))
294        .register(Arc::new(MemoryDecayTool::new(store.clone())))
295        .register(Arc::new(MemoryBatchReadTool::new(store.clone())))
296        .register(Arc::new(MemoryUpdateTool::new(store.clone(), search.clone())))
297        .register(Arc::new(MemoryRevisionsTool::new(store.clone())))
298        .register(Arc::new(MemoryTagTool::new(store.clone())))
299        .register(Arc::new(MemoryStatsTool::new(store.clone())))
300        .register(Arc::new(
301            MemoryHybridRecallTool::new(store.clone(), search.clone(), recall.clone())
302                .with_associations(Some(associations.clone())),
303        ))
304        .register(Arc::new(MemoryRecallFeedbackTool::new(recall)))
305        .register(Arc::new(MemoryEpisodicSearchTool::new(store.clone())))
306        .register(Arc::new(MemoryAggregateTool::new(
307            search.clone(),
308            store.clone(),
309        )))        // Memory ops Tier 7 (4) — WinnowingBasket
310        .register(Arc::new(MemorySortTool::new(store.clone())))
311        .register(Arc::new(MemoryFilterTool::new(store.clone())))
312        .register(Arc::new(MemoryDeduplicateTool::new(store.clone(), search.clone())))
313        .register(Arc::new(MemoryExportTool::new(store.clone())))
314        // Session (6)
315        .register(Arc::new(SessionStartTool::new(store.clone())))
316        .register(Arc::new(SessionCheckpointTool::new(store.clone())))
317        .register(Arc::new(SessionVerifyTool::new(store.clone())))
318        .register(Arc::new(SessionRecallTool::new(store.clone())))
319        .register(Arc::new(SessionDigestTool::new(store.clone())))
320        .register(Arc::new(SessionEndTool::new(store.clone())))
321        // Coordination (4) — advisory claim leases (Phase 2, full surface)
322        ;
323    let reg = register_coordination(&reg, gan_ying_bus);
324    let mut reg = reg
325        // Consciousness (4)
326        .register(Arc::new(CittaStatusTool::new()))
327        .register(Arc::new(CittaReflectTool::new(store.clone())))
328        .register(Arc::new(DreamStatusTool::new(store.clone())))
329        .register(Arc::new(DreamTriggerTool::new(store.clone())))
330        // Tools management (2)
331        .register(Arc::new(ToolsEffectivenessReportTool::new()))
332        .register(Arc::new(ToolsRetireTool::new()))
333        // Patterns (3)
334        .register(Arc::new(PatternSearchTool::new(store.clone())))
335        .register(Arc::new(SalienceSpotlightTool::new(store.clone())))
336        .register(Arc::new(SerendipitySurfaceTool::new(store.clone())))
337        // Constellation (2)
338        .register(Arc::new(ConstellationDetectTool::new(store.clone())))
339        .register(Arc::new(ConstellationListTool::new(store.clone())))
340        // Galaxy (12)
341        .register(Arc::new(GalaxyStatsTool::new(store.clone())))
342        .register(Arc::new(GalaxyExportTool::new(store.clone())))
343        .register(Arc::new(GalaxyImportTool::new(store.clone())))
344        .register(Arc::new(GalaxyTransferTool::new(
345            store.clone(),
346            search.clone(),
347        )))
348        .register(Arc::new(GalaxyMergeTool::new(store.clone())))
349        .register(Arc::new(GalaxySnapshotTool::new(store.clone())))
350        .register(Arc::new(GalaxyRestoreTool::new(
351            store.clone(),
352            search.clone(),
353        )))
354        .register(Arc::new(GalaxyDashboardTool::new(store.clone())))
355        .register(Arc::new(GalaxyBackupTool::new(store.clone())))
356        .register(Arc::new(GalaxyTaxonomyTool::new(store.clone())))
357        .register(Arc::new(GalaxyPurgeTool::new(store.clone(), search.clone())))
358        .register(Arc::new(GalaxyHealthTool::new(store.clone())))
359        // Tokio Army & Galactic Triage & Cold Rotate (3)
360        .register(Arc::new(ArmyDeployTool::new(store.clone())))
361        .register(Arc::new(GalacticTriageTool::new(store.clone())))
362        .register(cold_rotate_tool(store, search.clone(), associations.clone()))
363        // Subagent Captains, 5D Hologram, Bagua Dispatch & PRAY Universal Meta-Tool (5)
364        .register(pray_meta_tool(store, search.clone(), associations.clone()))
365        .register(Arc::new(CaptainDeployTool::new(store.clone())))
366        .register(Arc::new(HologramRebalanceTool::new(store.clone())))
367        .register(Arc::new(HologramQueryTool::new(store.clone())))
368        .register(Arc::new(BaguaDispatchTool::new(store.clone())))
369        // Geneseed pattern miner & stats (2)
370        .register(Arc::new(GeneseedMineTool::new(store.clone())))
371        .register(Arc::new(GeneseedStatsTool::new(store.clone())))
372        // Knowledge graph (3)
373        .register(Arc::new(KgExtractTool::new(store.clone())))
374        .register(Arc::new(KgQueryTool::new(store.clone())))
375        .register(Arc::new(KgTopTool::new(store.clone())))
376        // Graph traversal (3)
377        .register(Arc::new(GraphWalkTool::new(store.clone())))
378        .register(Arc::new(GraphCommunityTool::new(store.clone())))
379        .register(Arc::new(GraphPropagateTool::new(store.clone())))
380        // Archaeology & learning (3)
381        .register(Arc::new(ArchaeologySearchTool::new(store.clone())))
382        .register(Arc::new(LearningPatternTool::new(store.clone())))
383        .register(Arc::new(LearningSuggestTool::new(store.clone())))
384        // Reasoning (3)
385        .register(Arc::new(ReasoningBicameralTool::new(store.clone())))
386        .register(Arc::new(ThinkTool::new(store.clone())))
387        .register(Arc::new(ExplainTool::new(store.clone())))
388        // Pipeline & skills (5)
389        .register(Arc::new(PipelineCreateTool::new(store.clone())))
390        .register(Arc::new(PipelineListTool::new(store.clone())))
391        .register(Arc::new(PipelineStatusTool::new(store.clone())))
392        .register(Arc::new(SkillInvokeTool::new(store.clone())))
393        .register(Arc::new(SkillListTool::new(store.clone())))
394        // Anomaly & state (3)
395        .register(Arc::new(AnomalyDetectTool::new(store.clone())))
396        .register(Arc::new(StateSnapshotTool::new(store.clone())))
397        .register(Arc::new(StateRevertTool::new(store.clone())))
398        // Correlation & god nodes & Kaizen engine (3)
399        .register(Arc::new(CorrelationAnalyzeTool::new(store.clone())))
400        .register(Arc::new(GodNodesTool::new(store.clone())))
401        .register(Arc::new(KaizenCorrelateTool::new(store.clone())))
402        // Anti-loop & boundary (2)
403        .register(Arc::new(AntiLoopCheckTool::new(store.clone())))
404        .register(Arc::new(BoundaryEnforceTool::new(store.clone())))
405        // Karma (2) — only if karma ledger is available
406        ;
407    if let Some(k) = karma {
408        reg = reg
409            .register(Arc::new(KarmaHistoryTool::new(k.clone())))
410            .register(Arc::new(KarmaVerifyChainTool::new(k.clone())))
411            .register(Arc::new(KarmaClearTool::new(k.clone())))
412            .register(Arc::new(KarmaAnchorTool::new(k)));
413    }
414    let mut reg = reg
415        // Dharma (3)
416        .register(Arc::new(DharmaRulesTool::new()))
417        .register(Arc::new(DharmaAuditTool::new(store.clone())))
418        .register(Arc::new(DharmaAcsTool::new()))
419        // Agents (8)
420        .register(Arc::new(AgentRegisterTool::new(store.clone())))
421        .register(Arc::new(AgentListTool::new(store.clone())))
422        .register(Arc::new(AgentHeartbeatTool::new(store.clone())))
423        .register(Arc::new(AgentTrustTool::new(store.clone())))
424        .register(Arc::new(AgentDescriptionsTool::new(store.clone())))
425        .register(Arc::new(AgentCapabilitiesTool::new(store.clone())))
426        .register(Arc::new(AgentHeartbeatHistoryTool::new(store.clone())))
427        .register(Arc::new(AgentDeregisterTool::new(
428            store.clone(),
429            search.clone(),
430        )))
431        // Tasks (2)
432        .register(Arc::new(TaskDistributeTool::new(store.clone())))
433        .register(Arc::new(TaskStatusTool::new(store.clone())))
434        // System (3)
435        .register(Arc::new(
436            if let Some(ref se) = search {
437                SystemHealthTool::with_search(store.clone(), se.clone())
438            } else {
439                SystemHealthTool::new(store.clone())
440            },
441        ))
442        .register(Arc::new(SystemConfigTool::new()))
443        .register(Arc::new(SystemFlushTool::new(store.clone(), search.clone())))
444        // Association mining (1)
445        .register(Arc::new(MemoryAssociateMineTool::new(store.clone())))
446        // Typed relation tool (V8 S6) — relate + derive_follows
447        .register(Arc::new(MemoryRelateTool::new(store.clone())))
448        // Bridging consensus counter (2nd PR after Slice B) — corroborate
449        .register(Arc::new(MemoryCorroborateTool::new(store.clone())))
450        // Additional (5)
451        .register(Arc::new(MemoryCountTool::new(store.clone())))
452        .register(Arc::new(MemoryTagsTool::new(store.clone())))
453        .register(Arc::new(SessionListTool::new(store.clone())))
454        .register(Arc::new(CittaCoherenceTool::new()))
455        .register(Arc::new(DharmaProfilesTool::new()))
456        // Spatial queries (1)
457        .register(Arc::new(MemoryNearbyTool::new(store.clone())))
458        // Autonomous cycles (4) — Phase E
459        .register(Arc::new(ConsolidationConnectTool::new(
460            store.clone(),
461            associations.clone(),
462            spiral_tracker.clone(),
463        )))
464        .register(Arc::new(ConsolidationCompressTool::new(
465            store.clone(),
466            associations.clone(),
467            spiral_tracker.clone(),
468        )))
469        .register(Arc::new(EmergenceScanTool::new(
470            store.clone(),
471            associations.clone(),
472            spiral_tracker.clone(),
473        )))
474        .register(Arc::new(RetentionPruneTool::new(
475            store.clone(),
476            associations.clone(),
477            spiral_tracker.clone(),
478        )))
479        // Spiral tracker (1) — Phase F
480        .register(Arc::new(SpiralReportTool::new(spiral_tracker.clone())))
481        // Tier 5: Net tools (6)
482        .register(Arc::new(AssociationMineTool::new(store.clone())))
483        .register(Arc::new(PatternDetectTool::new(store.clone())))
484        .register(Arc::new(EmergenceReportTool::new(store.clone())))
485        .register(Arc::new(NetworkStatsTool::new(store.clone())))
486        .register(Arc::new(NetworkCentralityTool::new(store.clone())))
487        .register(Arc::new(NetworkClustersTool::new(store.clone())))
488        // Tier 5: Ghost tools (6)
489        .register(Arc::new(SmaranaStatusTool::new(store.clone())))
490        .register(Arc::new(SmaranaTraceTool::new(store.clone())))
491        .register(Arc::new(ApotheosisCheckTool::new(store.clone())))
492        .register(Arc::new(CittaHistoryTool::new(store.clone())))
493        .register(Arc::new(DreamAnalyzeTool::new(store.clone())))
494        .register(Arc::new(ConsciousnessDepthTool::new(store.clone())));
495
496    // Homeostasis (4) — Tier 7 Dipper — only if substrate monitor is available
497    if let Some(sm) = substrate {
498        let loop_ = homeostatic_loop
499            .unwrap_or_else(|| Arc::new(std::sync::Mutex::new(HomeostaticLoop::default())));
500        let detector = anomaly_detector
501            .unwrap_or_else(|| Arc::new(std::sync::Mutex::new(AnomalyDetector::default())));
502        reg = reg
503            .register(Arc::new(HomeostasisCheckTool::new(
504                sm.clone(),
505                loop_,
506                detector.clone(),
507            )))
508            .register(Arc::new(HomeostasisAdjustTool::new(sm.clone())))
509            .register(Arc::new(HomeostasisHistoryTool::new(sm.clone())))
510            .register(Arc::new(HomeostasisAlertsTool::new(sm, detector)));
511    }
512
513    let _ = &mut reg; // suppress unused_mut warning
514
515    // RSI: Friction logging + improvement + redteam + resolve (7) — Phase 1-3
516    reg = rsi::register_rsi(&reg, store, None, &associations, None, None);
517
518    // Sensorimotor tools (10) — Embodiment I/O
519    let bus = sensorimotor_bus.unwrap_or_else(|| {
520        Arc::new(std::sync::Mutex::new(
521            wm_substrate::sensorimotor::linux_hardware_bus(),
522        ))
523    });
524    let reflex = reflex_loop.unwrap_or_else(|| Arc::new(std::sync::Mutex::new(ReflexLoop::new())));
525    reg =
526        sensorimotor_tools::register_sensorimotor(&reg, bus.clone(), reflex.clone(), gan_ying_bus);
527
528    // Sensorimotor autonomous cycle (1) — Embodiment
529    reg = reg.register(Arc::new(SensorimotorScanTool::new(
530        store.clone(),
531        associations,
532        spiral_tracker,
533        bus,
534        reflex,
535    )));
536
537    // Transaction tools (3) — snapshot/rollback for multi-tool sequences
538    reg = reg
539        .register(Arc::new(TransactionBeginTool::new(
540            store.clone(),
541            transaction_state.clone(),
542        )))
543        .register(Arc::new(TransactionCommitTool::new(
544            store.clone(),
545            transaction_state.clone(),
546            search.clone(),
547        )))
548        .register(Arc::new(TransactionRollbackTool::new(
549            store.clone(),
550            transaction_state,
551            search.clone(),
552        )));
553
554    // Imagination tools (3) — scenario generation, prediction, reflection
555    reg = register_imagination(&reg, store);
556
557    // Self-play tools (3) — training loop, status, export
558    reg = register_self_play(&reg, store, new_shared_loop());
559
560    // Web research tools (4) — fetch, deep_fetch, search, search_and_read
561    reg = register_web(&reg);
562
563    // Research tools (3) — topic, repo, rabbit_hole (bus-wired Gan Ying loop)
564    reg = register_research(&reg, store, gan_ying_bus);
565
566    // Session ops (4) — record, replay, continuity, handoff
567    reg = register_session_ops(&reg, store, search);
568
569    // Dharma escalation (3) — escalate, review_queue, resolve_review
570    if let (Some(queue), Some(gate)) = (escalation_queue, dharma_gate) {
571        reg = reg
572            .register(Arc::new(DharmaEscalateTool::new(
573                gate.clone(),
574                queue.clone(),
575            )))
576            .register(Arc::new(DharmaReviewQueueTool::new(queue.clone())))
577            .register(Arc::new(DharmaResolveReviewTool::new(queue.clone())));
578    }
579
580    // Sandbox tools (2) — set_limits, limits
581    reg = crate::expansion::sandbox::register_sandbox(&reg, resource_rules);
582
583    // Transaction firewall (2) — set_policy, status
584    if let Some(fw) = firewall {
585        reg = crate::expansion::firewall::register_firewall(&reg, fw.clone());
586    }
587
588    // Code graph tools (4) — graph, query, affected_by, fragment.search
589    if let Some(cg) = code_graph {
590        reg = crate::expansion::code::register_code(&reg, cg.clone());
591    }
592
593    // Violet security tools (5) — ordinary construction retains stable
594    // identities; evaluator preservation keeps the same route topology with
595    // fresh process-local keys and no filesystem fallback.
596    reg = match registry_persistence {
597        RegistryPersistenceMode::Normal => {
598            crate::expansion::violet::register_violet_persistent(&reg, &store.path().join("violet"))
599        }
600        RegistryPersistenceMode::EvaluatorPreservation => {
601            crate::expansion::violet::register_violet(&reg)
602        }
603    };
604
605    // Security circuit breaker (4) — runtime tool-call anomaly monitor
606    reg = crate::expansion::security_breaker::register_security_breaker(&reg);
607
608    // Security probe planning (3) — authorized-testing technique plans + triage
609    reg = crate::expansion::security_probe::register_security_probe(&reg);
610
611    // Bounty connector (2) — bounty.scan, bounty.import; static-JSON fixture
612    // platform is opt-in via WM_BOUNTY_STATIC_JSON (real adapters are follow-ups).
613    let board_path = store.path().join("bounty_board.json");
614    match crate::expansion::bounty_connector::BountyBoard::open(board_path) {
615        Ok(board) => {
616            let mut connector =
617                crate::expansion::bounty_connector::BountyConnector::new(Arc::new(board));
618            if let Ok(fixture) = std::env::var("WM_BOUNTY_STATIC_JSON") {
619                connector = connector.with_platform(Arc::new(
620                    crate::expansion::bounty_connector::StaticJsonPlatform::new(
621                        "static",
622                        std::path::PathBuf::from(fixture),
623                    ),
624                ));
625            }
626            reg = crate::expansion::bounty_connector::register_bounty(&reg, Arc::new(connector));
627        }
628        Err(e) => tracing::warn!("bounty board unavailable: {e}"),
629    }
630
631    // Bounty ledger (4) — submission tracking + compounding stats
632    reg = crate::expansion::bounty_ledger::register_bounty_ledger(
633        &reg,
634        store.path().join("bounty_ledger.jsonl"),
635    );
636
637    // Bounty evidence packager (2) — structured packs + preflight
638    reg = crate::expansion::bounty_evidence::register_bounty_evidence(
639        &reg,
640        store.path().join("evidence"),
641    );
642
643    // OSS bounty scanner (2) — GitHub bounty issues via gh (read-only)
644    reg = crate::expansion::oss_bounty::register_oss_bounty(&reg);
645
646    reg
647}