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