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