wm-tools 9.0.0

Curated tool implementations for the WhiteMagic MCP server.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
//! Galaxy tools — stats, export, import, transfer, merge, snapshot, restore.

#![forbid(unsafe_code)]

use async_trait::async_trait;

use serde_json::{Value, json};
use std::sync::Arc;
use wm_core::{Context, EffectRow, Galaxy, Gana, Resource, Tool, ToolStats};
use wm_memory::{Memory, MemoryStore, SearchEngine};

use super::common::{galaxy_name, parse_galaxy, parse_galaxy_or};

pub struct GalaxyStatsTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyStatsTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow::read_only(vec![]),
        }
    }
}

#[async_trait]
impl Tool for GalaxyStatsTool {
    fn name(&self) -> &str {
        "galaxy.stats"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Statistics for all galaxies (count per galaxy)"
    }
    async fn call(&self, _ctx: &mut Context, _args: Value) -> wm_core::Result<Value> {
        let mut galaxy_counts = serde_json::Map::new();
        let mut total = 0usize;
        for galaxy in Galaxy::all() {
            let count = self.store.count(galaxy).unwrap_or(0);
            if count > 0 {
                galaxy_counts.insert(galaxy_name(galaxy).to_string(), json!(count));
                total += count;
            }
        }
        Ok(json!({
            "status": "success",
            "total_memories": total,
            "galaxies_with_data": galaxy_counts.len(),
            "galaxy_counts": galaxy_counts,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.export` — export all memories from a galaxy as JSON.
pub struct GalaxyExportTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyExportTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow::read_only(vec![Resource::Galaxy("codex".into())]),
        }
    }
}

#[async_trait]
impl Tool for GalaxyExportTool {
    fn name(&self) -> &str {
        "galaxy.export"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Export all memories from a galaxy as JSON"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let galaxy = parse_galaxy_or(args.get("galaxy").and_then(|v| v.as_str()), Galaxy::Codex)?;
        let limit = args
            .get("limit")
            .and_then(serde_json::Value::as_u64)
            .unwrap_or(1000) as usize;
        let memories = self.store.scan(galaxy, limit)?;
        let exported: Vec<Value> = memories
            .iter()
            .map(|m| {
                json!({
                    "id": m.metadata.id,
                    "content": m.content,
                    "tags": m.metadata.tags,
                    "importance": m.metadata.importance,
                    "created_at": m.metadata.created_at.to_rfc3339(),
                })
            })
            .collect();
        Ok(json!({
            "status": "success",
            "galaxy": galaxy_name(galaxy),
            "count": exported.len(),
            "memories": exported,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.import` — import memories into a galaxy from JSON.
pub struct GalaxyImportTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyImportTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow {
                writes: vec![Resource::Galaxy("codex".into())],
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyImportTool {
    fn name(&self) -> &str {
        "galaxy.import"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Import memories into a galaxy from JSON array"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let galaxy = parse_galaxy_or(args.get("galaxy").and_then(|v| v.as_str()), Galaxy::Codex)?;
        let memories = args
            .get("memories")
            .and_then(|v| v.as_array())
            .ok_or_else(|| wm_core::CoreError::InvalidArgs("Missing 'memories' array".into()))?;
        let mut imported = 0u32;
        for mem_val in memories {
            let content = mem_val
                .get("content")
                .and_then(|v| v.as_str())
                .unwrap_or("");
            let mut mem = Memory::new(galaxy, content.to_string());
            if let Some(tags) = mem_val.get("tags").and_then(|v| v.as_array()) {
                mem.metadata.tags = tags
                    .iter()
                    .filter_map(|t| t.as_str().map(String::from))
                    .collect();
            }
            if let Some(imp) = mem_val
                .get("importance")
                .and_then(serde_json::Value::as_f64)
            {
                mem.metadata.importance = imp as f32;
            }
            self.store.put(galaxy, &mem)?;
            imported += 1;
        }
        Ok(json!({
            "status": "success",
            "galaxy": galaxy_name(galaxy),
            "imported": imported,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.transfer` — move memories from one galaxy to another.
///
/// Reads memories from the source galaxy, writes them to the destination
/// galaxy, then deletes them from the source. Optionally filters by tags.
pub struct GalaxyTransferTool {
    store: Arc<MemoryStore>,
    search: Option<Arc<SearchEngine>>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyTransferTool {
    pub fn new(store: Arc<MemoryStore>, search: Option<Arc<SearchEngine>>) -> Self {
        Self {
            store,
            search,
            stats: ToolStats::default(),
            effects: EffectRow {
                // Transfer moves memories between any two galaxies chosen
                // at runtime.
                writes: super::common::memory_galaxy_writes(),
                reads: super::common::memory_galaxy_reads(),
                destructive: true,
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyTransferTool {
    fn name(&self) -> &str {
        "galaxy.transfer"
    }
    fn gana(&self) -> Gana {
        Gana::Neck
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Transfer memories from one galaxy to another (move, not copy)"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let from_galaxy = parse_galaxy(
            args.get("from_galaxy")
                .and_then(|v| v.as_str())
                .ok_or_else(|| {
                    wm_core::CoreError::InvalidArgs("Missing 'from_galaxy' parameter".into())
                })?,
        )?;
        let to_galaxy = parse_galaxy(args.get("to_galaxy").and_then(|v| v.as_str()).ok_or_else(
            || wm_core::CoreError::InvalidArgs("Missing 'to_galaxy' parameter".into()),
        )?)?;
        if from_galaxy == to_galaxy {
            return Err(wm_core::CoreError::InvalidArgs(
                "from_galaxy and to_galaxy must be different".into(),
            ));
        }
        let limit = args
            .get("limit")
            .and_then(serde_json::Value::as_u64)
            .unwrap_or(10_000) as usize;
        let tag_filter: Option<Vec<String>> =
            args.get("tags").and_then(|v| v.as_array()).map(|arr| {
                arr.iter()
                    .filter_map(|t| t.as_str().map(String::from))
                    .collect()
            });

        let memories = self.store.scan(from_galaxy, limit)?;
        let mut transferred = 0u32;
        let mut skipped = 0u32;

        for mem in &memories {
            if let Some(ref tags) = tag_filter {
                if !tags.iter().all(|t| mem.metadata.tags.contains(t)) {
                    skipped += 1;
                    continue;
                }
            }

            let mut new_mem = Memory::new(to_galaxy, mem.content.clone());
            new_mem.metadata.tags.clone_from(&mem.metadata.tags);
            new_mem.metadata.importance = mem.metadata.importance;
            self.store.put(to_galaxy, &new_mem)?;

            self.store.delete(from_galaxy, mem.metadata.id)?;
            super::common::deindex(self.search.as_deref(), &mem.metadata.id.to_string());
            transferred += 1;
        }

        Ok(json!({
            "status": "success",
            "from_galaxy": galaxy_name(from_galaxy),
            "to_galaxy": galaxy_name(to_galaxy),
            "scanned": memories.len(),
            "transferred": transferred,
            "skipped": skipped,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.merge` — merge memories from a source galaxy into a destination.
///
/// Copies all memories from the source galaxy into the destination galaxy.
/// Does not delete from the source. Deduplicates by content_hash.
pub struct GalaxyMergeTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyMergeTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow {
                writes: vec![Resource::Galaxy("codex".into())],
                reads: vec![Resource::Galaxy("research".into())],
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyMergeTool {
    fn name(&self) -> &str {
        "galaxy.merge"
    }
    fn gana(&self) -> Gana {
        Gana::Neck
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Merge memories from a source galaxy into a destination (copy + dedup)"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let from_galaxy = parse_galaxy(
            args.get("from_galaxy")
                .and_then(|v| v.as_str())
                .ok_or_else(|| {
                    wm_core::CoreError::InvalidArgs("Missing 'from_galaxy' parameter".into())
                })?,
        )?;
        let to_galaxy = parse_galaxy(args.get("to_galaxy").and_then(|v| v.as_str()).ok_or_else(
            || wm_core::CoreError::InvalidArgs("Missing 'to_galaxy' parameter".into()),
        )?)?;
        if from_galaxy == to_galaxy {
            return Err(wm_core::CoreError::InvalidArgs(
                "from_galaxy and to_galaxy must be different".into(),
            ));
        }
        let limit = args
            .get("limit")
            .and_then(serde_json::Value::as_u64)
            .unwrap_or(10_000) as usize;

        let dest_mems = self.store.scan(to_galaxy, 10_000)?;
        let existing_hashes: std::collections::HashSet<String> = dest_mems
            .iter()
            .map(|m| m.metadata.content_hash.clone())
            .collect();

        let source_mems = self.store.scan(from_galaxy, limit)?;
        let mut merged = 0u32;
        let mut duplicates = 0u32;

        for mem in &source_mems {
            if existing_hashes.contains(&mem.metadata.content_hash) {
                duplicates += 1;
                continue;
            }

            let mut new_mem = Memory::new(to_galaxy, mem.content.clone());
            new_mem.metadata.tags.clone_from(&mem.metadata.tags);
            new_mem.metadata.importance = mem.metadata.importance;
            self.store.put(to_galaxy, &new_mem)?;
            merged += 1;
        }

        Ok(json!({
            "status": "success",
            "from_galaxy": galaxy_name(from_galaxy),
            "to_galaxy": galaxy_name(to_galaxy),
            "source_count": source_mems.len(),
            "merged": merged,
            "duplicates_skipped": duplicates,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.snapshot` — capture a snapshot of a galaxy's state.
///
/// Exports all memories from a galaxy into a JSON-serializable snapshot
/// stored in the Journals galaxy. Returns the snapshot ID.
pub struct GalaxySnapshotTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxySnapshotTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow {
                writes: vec![Resource::Galaxy("journals".into())],
                reads: vec![Resource::Galaxy("codex".into())],
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxySnapshotTool {
    fn name(&self) -> &str {
        "galaxy.snapshot"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Capture a snapshot of a galaxy's state (stored in Journals galaxy)"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let galaxy = parse_galaxy_or(args.get("galaxy").and_then(|v| v.as_str()), Galaxy::Codex)?;
        let limit = args
            .get("limit")
            .and_then(serde_json::Value::as_u64)
            .unwrap_or(10_000) as usize;

        let memories = self.store.scan(galaxy, limit)?;

        let snapshot_data: Vec<Value> = memories
            .iter()
            .map(|m| {
                json!({
                    "id": m.metadata.id,
                    "content": m.content,
                    "tags": m.metadata.tags,
                    "importance": m.metadata.importance,
                    "created_at": m.metadata.created_at.to_rfc3339(),
                    "content_hash": m.metadata.content_hash,
                })
            })
            .collect();

        let snapshot_id = uuid::Uuid::new_v4();
        let snapshot_content = json!({
            "type": "galaxy_snapshot",
            "snapshot_id": snapshot_id,
            "galaxy": galaxy_name(galaxy),
            "timestamp": chrono::Utc::now().to_rfc3339(),
            "memory_count": memories.len(),
            "memories": snapshot_data,
        })
        .to_string();

        let mut snapshot_mem = Memory::new(Galaxy::Journals, snapshot_content);
        snapshot_mem.metadata.tags = vec!["snapshot".to_string(), galaxy_name(galaxy).to_string()];
        self.store.put(Galaxy::Journals, &snapshot_mem)?;

        Ok(json!({
            "status": "success",
            "galaxy": galaxy_name(galaxy),
            "snapshot_id": snapshot_id,
            "memory_count": memories.len(),
            "stored_in": "journals",
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.restore` — restore a galaxy from a stored snapshot.
///
/// Reads a snapshot from the Journals galaxy and restores the memories
/// into the target galaxy. Optionally clears the target first.
pub struct GalaxyRestoreTool {
    store: Arc<MemoryStore>,
    search: Option<Arc<SearchEngine>>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyRestoreTool {
    pub fn new(store: Arc<MemoryStore>, search: Option<Arc<SearchEngine>>) -> Self {
        Self {
            store,
            search,
            stats: ToolStats::default(),
            effects: EffectRow {
                // Restore writes to whichever galaxy the caller selects.
                writes: super::common::memory_galaxy_writes(),
                reads: super::common::memory_galaxy_reads(),
                destructive: true,
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyRestoreTool {
    fn name(&self) -> &str {
        "galaxy.restore"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Restore a galaxy from a stored snapshot in the Journals galaxy"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let snapshot_id = args
            .get("snapshot_id")
            .and_then(|v| v.as_str())
            .ok_or_else(|| {
                wm_core::CoreError::InvalidArgs("Missing 'snapshot_id' parameter".into())
            })?;
        let target_galaxy =
            parse_galaxy_or(args.get("galaxy").and_then(|v| v.as_str()), Galaxy::Codex)?;
        let clear_first = args
            .get("clear_first")
            .and_then(serde_json::Value::as_bool)
            .unwrap_or(false);

        let journals = self.store.scan(Galaxy::Journals, 10_000)?;
        let snapshot = journals.iter().find(|m| {
            m.metadata.tags.contains(&"snapshot".to_string()) && m.content.contains(snapshot_id)
        });

        let snapshot_mem = snapshot.ok_or_else(|| {
            wm_core::CoreError::NotFound(format!(
                "Snapshot {snapshot_id} not found in Journals galaxy"
            ))
        })?;

        let snapshot_data: Value = serde_json::from_str(&snapshot_mem.content)
            .map_err(|e| wm_core::CoreError::Memory(format!("Failed to parse snapshot: {e}")))?;

        let memories = snapshot_data
            .get("memories")
            .and_then(|v| v.as_array())
            .ok_or_else(|| wm_core::CoreError::Memory("Snapshot has no 'memories' array".into()))?;

        if clear_first {
            let existing = self.store.scan(target_galaxy, 10_000)?;
            for mem in &existing {
                self.store.delete(target_galaxy, mem.metadata.id)?;
                super::common::deindex(self.search.as_deref(), &mem.metadata.id.to_string());
            }
        }

        let mut restored = 0u32;
        for mem_val in memories {
            let content = mem_val
                .get("content")
                .and_then(|v| v.as_str())
                .unwrap_or("");
            let mut mem = Memory::new(target_galaxy, content.to_string());
            if let Some(tags) = mem_val.get("tags").and_then(|v| v.as_array()) {
                mem.metadata.tags = tags
                    .iter()
                    .filter_map(|t| t.as_str().map(String::from))
                    .collect();
            }
            if let Some(imp) = mem_val
                .get("importance")
                .and_then(serde_json::Value::as_f64)
            {
                mem.metadata.importance = imp as f32;
            }
            self.store.put(target_galaxy, &mem)?;
            super::common::index_memory(self.search.as_deref(), &mem);
            restored += 1;
        }

        Ok(json!({
            "status": "success",
            "snapshot_id": snapshot_id,
            "galaxy": galaxy_name(target_galaxy),
            "restored": restored,
            "cleared_first": clear_first,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.dashboard` — comprehensive overview of all galaxies with counts,
/// tags, importance stats, and recent activity.
pub struct GalaxyDashboardTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyDashboardTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow::read_only(vec![]),
        }
    }
}

#[async_trait]
impl Tool for GalaxyDashboardTool {
    fn name(&self) -> &str {
        "galaxy.dashboard"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Comprehensive dashboard overview of all galaxies"
    }
    async fn call(&self, _ctx: &mut Context, _args: Value) -> wm_core::Result<Value> {
        let mut galaxy_details = serde_json::Map::new();
        let mut total_memories = 0usize;
        let mut total_tags: std::collections::HashSet<String> = std::collections::HashSet::new();

        for galaxy in Galaxy::memory_galaxies() {
            let count = self.store.count(galaxy).unwrap_or(0);
            total_memories += count;
            if count == 0 {
                galaxy_details.insert(
                    galaxy_name(galaxy).to_string(),
                    json!({
                        "count": 0,
                        "avg_importance": 0.0,
                        "top_tags": [],
                    }),
                );
                continue;
            }

            let memories = self.store.scan(galaxy, 10_000)?;
            let mut tag_counts: std::collections::HashMap<String, u32> =
                std::collections::HashMap::new();
            let mut importance_sum = 0.0f64;
            for mem in &memories {
                for tag in &mem.metadata.tags {
                    *tag_counts.entry(tag.clone()).or_insert(0) += 1;
                    total_tags.insert(tag.clone());
                }
                importance_sum += f64::from(mem.metadata.importance);
            }
            let avg_importance = if memories.is_empty() {
                0.0
            } else {
                importance_sum / memories.len() as f64
            };
            let mut top_tags: Vec<(String, u32)> = tag_counts.into_iter().collect();
            top_tags.sort_by_key(|x| std::cmp::Reverse(x.1));
            top_tags.truncate(5);

            galaxy_details.insert(galaxy_name(galaxy).to_string(), json!({
                "count": count,
                "avg_importance": (avg_importance * 100.0).round() / 100.0,
                "top_tags": top_tags.into_iter().map(|(t, c)| json!({"tag": t, "count": c})).collect::<Vec<_>>(),
            }));
        }

        Ok(json!({
            "status": "success",
            "total_memories": total_memories,
            "total_galaxies_with_data": galaxy_details.len(),
            "unique_tags": total_tags.len(),
            "galaxies": galaxy_details,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.backup` — back up all memory galaxies into a single snapshot
/// stored in the Journals galaxy. Returns the backup ID.
pub struct GalaxyBackupTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyBackupTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow {
                writes: vec![Resource::Galaxy("journals".into())],
                reads: vec![],
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyBackupTool {
    fn name(&self) -> &str {
        "galaxy.backup"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Back up all memory galaxies into a single snapshot in Journals"
    }
    async fn call(&self, _ctx: &mut Context, _args: Value) -> wm_core::Result<Value> {
        let backup_id = uuid::Uuid::new_v4();
        let mut galaxy_data = serde_json::Map::new();
        let mut total_backed_up = 0usize;

        for galaxy in Galaxy::memory_galaxies() {
            let memories = self.store.scan(galaxy, 10_000)?;
            let count = memories.len();
            total_backed_up += count;
            galaxy_data.insert(
                galaxy_name(galaxy).to_string(),
                json!({
                    "count": count,
                    "memories": memories.iter().map(|m| {
                        json!({
                            "id": m.metadata.id,
                            "content": m.content,
                            "tags": m.metadata.tags,
                            "importance": m.metadata.importance,
                            "created_at": m.metadata.created_at.to_rfc3339(),
                            "content_hash": m.metadata.content_hash,
                        })
                    }).collect::<Vec<_>>(),
                }),
            );
        }

        let backup_content = json!({
            "type": "galaxy_backup",
            "backup_id": backup_id,
            "timestamp": chrono::Utc::now().to_rfc3339(),
            "total_memories": total_backed_up,
            "galaxies": galaxy_data,
        })
        .to_string();

        let mut backup_mem = Memory::new(Galaxy::Journals, backup_content);
        backup_mem.metadata.tags = vec!["backup".to_string()];
        backup_mem.metadata.importance = 1.0;
        self.store.put(Galaxy::Journals, &backup_mem)?;

        Ok(json!({
            "status": "success",
            "backup_id": backup_id,
            "total_memories": total_backed_up,
            "galaxies_backed_up": Galaxy::memory_galaxies().len(),
            "stored_in": "journals",
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.taxonomy` — list all galaxies with descriptions and counts.
pub struct GalaxyTaxonomyTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyTaxonomyTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow::read_only(vec![]),
        }
    }
}

#[async_trait]
impl Tool for GalaxyTaxonomyTool {
    fn name(&self) -> &str {
        "galaxy.taxonomy"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "List all galaxies with descriptions and memory counts"
    }
    async fn call(&self, _ctx: &mut Context, _args: Value) -> wm_core::Result<Value> {
        let galaxies: Vec<Value> = Galaxy::all()
            .iter()
            .map(|g| {
                let count = self.store.count(*g).unwrap_or(0);
                json!({
                    "name": galaxy_name(*g),
                    "description": g.description(),
                    "count": count,
                    "is_memory_galaxy": Galaxy::memory_galaxies().contains(g),
                })
            })
            .collect();

        Ok(json!({
            "status": "success",
            "total_galaxies": Galaxy::all().len(),
            "memory_galaxies": Galaxy::memory_galaxies().len(),
            "galaxies": galaxies,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.purge` — delete all memories from a specific galaxy.
pub struct GalaxyPurgeTool {
    store: Arc<MemoryStore>,
    search: Option<Arc<SearchEngine>>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyPurgeTool {
    pub fn new(store: Arc<MemoryStore>, search: Option<Arc<SearchEngine>>) -> Self {
        Self {
            store,
            search,
            stats: ToolStats::default(),
            effects: EffectRow {
                // Purge deletes every memory in whichever galaxy the
                // caller selects.
                writes: super::common::memory_galaxy_writes(),
                reads: super::common::memory_galaxy_reads(),
                destructive: true,
                ..Default::default()
            },
        }
    }
}

#[async_trait]
impl Tool for GalaxyPurgeTool {
    fn name(&self) -> &str {
        "galaxy.purge"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Delete all memories from a specific galaxy"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let galaxy =
            parse_galaxy(args.get("galaxy").and_then(|v| v.as_str()).ok_or_else(|| {
                wm_core::CoreError::InvalidArgs("Missing 'galaxy' parameter".into())
            })?)?;

        let memories = self.store.scan(galaxy, 10_000)?;
        let count = memories.len();
        for mem in &memories {
            self.store.delete(galaxy, mem.metadata.id)?;
            super::common::deindex(self.search.as_deref(), &mem.metadata.id.to_string());
        }

        Ok(json!({
            "status": "success",
            "galaxy": galaxy_name(galaxy),
            "purged": count,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

/// `galaxy.health` — check the health of a specific galaxy or all galaxies.
pub struct GalaxyHealthTool {
    store: Arc<MemoryStore>,
    stats: ToolStats,
    effects: EffectRow,
}

impl GalaxyHealthTool {
    pub fn new(store: Arc<MemoryStore>) -> Self {
        Self {
            store,
            stats: ToolStats::default(),
            effects: EffectRow::read_only(vec![]),
        }
    }
}

#[async_trait]
impl Tool for GalaxyHealthTool {
    fn name(&self) -> &str {
        "galaxy.health"
    }
    fn gana(&self) -> Gana {
        Gana::Void
    }
    fn effects(&self) -> &EffectRow {
        &self.effects
    }
    fn description(&self) -> &str {
        "Check health of a specific galaxy or all galaxies"
    }
    async fn call(&self, _ctx: &mut Context, args: Value) -> wm_core::Result<Value> {
        let target_galaxy = args.get("galaxy").and_then(|v| v.as_str());

        let galaxies_to_check: Vec<Galaxy> = if let Some(name) = target_galaxy {
            vec![parse_galaxy(name)?]
        } else {
            Galaxy::memory_galaxies().to_vec()
        };

        let mut results = serde_json::Map::new();
        let mut all_healthy = true;

        for galaxy in &galaxies_to_check {
            let count = self.store.count(*galaxy).unwrap_or(0);
            let scan_result = self.store.scan(*galaxy, 100);
            let accessible = scan_result.is_ok();
            if !accessible {
                all_healthy = false;
            }

            let mut avg_importance = 0.0;
            let mut tag_coverage = 0usize;
            if let Ok(mems) = &scan_result {
                if !mems.is_empty() {
                    let sum: f64 = mems.iter().map(|m| f64::from(m.metadata.importance)).sum();
                    avg_importance = sum / mems.len() as f64;
                    let tags: std::collections::HashSet<&String> =
                        mems.iter().flat_map(|m| m.metadata.tags.iter()).collect();
                    tag_coverage = tags.len();
                }
            }

            let health = if !accessible {
                "inaccessible"
            } else if count == 0 {
                "empty"
            } else {
                "healthy"
            };

            results.insert(
                galaxy_name(*galaxy).to_string(),
                json!({
                    "count": count,
                    "accessible": accessible,
                    "health": health,
                    "avg_importance": (avg_importance * 100.0).round() / 100.0,
                    "tag_coverage": tag_coverage,
                }),
            );
        }

        Ok(json!({
            "status": "success",
            "all_healthy": all_healthy,
            "galaxies_checked": galaxies_to_check.len(),
            "results": results,
        }))
    }
    fn stats(&self) -> &ToolStats {
        &self.stats
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::tempdir;

    fn open_store() -> (tempfile::TempDir, MemoryStore) {
        let tmp = tempdir().unwrap();
        let store = MemoryStore::open_default(tmp.path()).unwrap();
        (tmp, store)
    }

    #[tokio::test]
    async fn galaxy_transfer_moves_memories() {
        let (_tmp, store) = open_store();
        let mem = Memory::new(Galaxy::Codex, "test content".into());
        store.put(Galaxy::Codex, &mem).unwrap();
        assert_eq!(store.count(Galaxy::Codex).unwrap(), 1);
        assert_eq!(store.count(Galaxy::Research).unwrap(), 0);

        let tool = GalaxyTransferTool::new(Arc::new(store), None);
        let result = tool
            .call(
                &mut Context::default(),
                json!({"from_galaxy": "codex", "to_galaxy": "research"}),
            )
            .await
            .unwrap();
        let obj = result.as_object().unwrap();
        assert_eq!(obj["status"], "success");
        assert_eq!(obj["transferred"], 1);
    }

    #[tokio::test]
    async fn galaxy_transfer_same_galaxy_errors() {
        let (_tmp, store) = open_store();
        let tool = GalaxyTransferTool::new(Arc::new(store), None);
        let result = tool
            .call(
                &mut Context::default(),
                json!({"from_galaxy": "codex", "to_galaxy": "codex"}),
            )
            .await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn galaxy_transfer_missing_params_errors() {
        let (_tmp, store) = open_store();
        let tool = GalaxyTransferTool::new(Arc::new(store), None);
        assert!(
            tool.call(&mut Context::default(), json!({"from_galaxy": "codex"}))
                .await
                .is_err()
        );
        assert!(
            tool.call(&mut Context::default(), json!({"to_galaxy": "codex"}))
                .await
                .is_err()
        );
    }

    #[tokio::test]
    async fn galaxy_transfer_with_tag_filter() {
        let (_tmp, store) = open_store();
        let mut mem1 = Memory::new(Galaxy::Codex, "tagged content".into());
        mem1.metadata.tags = vec!["important".to_string()];
        let mem2 = Memory::new(Galaxy::Codex, "untagged content".into());
        store.put(Galaxy::Codex, &mem1).unwrap();
        store.put(Galaxy::Codex, &mem2).unwrap();

        let tool = GalaxyTransferTool::new(Arc::new(store), None);
        let result = tool
            .call(
                &mut Context::default(),
                json!({
                    "from_galaxy": "codex",
                    "to_galaxy": "research",
                    "tags": ["important"],
                }),
            )
            .await
            .unwrap();
        let obj = result.as_object().unwrap();
        assert_eq!(obj["transferred"], 1);
        assert_eq!(obj["skipped"], 1);
    }

    #[tokio::test]
    async fn galaxy_merge_copies_and_dedups() {
        let (_tmp, store) = open_store();
        let mem1 = Memory::new(Galaxy::Codex, "shared content".into());
        let mem2 = Memory::new(Galaxy::Codex, "unique to codex".into());
        store.put(Galaxy::Codex, &mem1).unwrap();
        store.put(Galaxy::Codex, &mem2).unwrap();

        let mem1_copy = Memory::new(Galaxy::Research, "shared content".into());
        store.put(Galaxy::Research, &mem1_copy).unwrap();

        let tool = GalaxyMergeTool::new(Arc::new(store));
        let result = tool
            .call(
                &mut Context::default(),
                json!({"from_galaxy": "codex", "to_galaxy": "research"}),
            )
            .await
            .unwrap();
        let obj = result.as_object().unwrap();
        assert_eq!(obj["status"], "success");
        assert_eq!(obj["merged"], 1);
        assert_eq!(obj["duplicates_skipped"], 1);
    }

    #[tokio::test]
    async fn galaxy_merge_same_galaxy_errors() {
        let (_tmp, store) = open_store();
        let tool = GalaxyMergeTool::new(Arc::new(store));
        let result = tool
            .call(
                &mut Context::default(),
                json!({"from_galaxy": "codex", "to_galaxy": "codex"}),
            )
            .await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn galaxy_snapshot_and_restore_roundtrip() {
        let (_tmp, store) = open_store();
        let store = Arc::new(store);

        let mem1 = Memory::new(Galaxy::Codex, "first memory".into());
        let mem2 = Memory::new(Galaxy::Codex, "second memory".into());
        store.put(Galaxy::Codex, &mem1).unwrap();
        store.put(Galaxy::Codex, &mem2).unwrap();

        let snap_tool = GalaxySnapshotTool::new(store.clone());
        let snap_result = snap_tool
            .call(&mut Context::default(), json!({"galaxy": "codex"}))
            .await
            .unwrap();
        let snap_obj = snap_result.as_object().unwrap();
        assert_eq!(snap_obj["status"], "success");
        assert_eq!(snap_obj["memory_count"], 2);
        let snapshot_id = snap_obj["snapshot_id"].as_str().unwrap();

        let _ = store.delete(Galaxy::Codex, mem1.metadata.id);
        let _ = store.delete(Galaxy::Codex, mem2.metadata.id);
        assert_eq!(store.count(Galaxy::Codex).unwrap(), 0);

        let restore_tool = GalaxyRestoreTool::new(store.clone(), None);
        let restore_result = restore_tool
            .call(
                &mut Context::default(),
                json!({
                    "snapshot_id": snapshot_id,
                    "galaxy": "codex",
                    "clear_first": false,
                }),
            )
            .await
            .unwrap();
        let restore_obj = restore_result.as_object().unwrap();
        assert_eq!(restore_obj["status"], "success");
        assert_eq!(restore_obj["restored"], 2);

        assert_eq!(store.count(Galaxy::Codex).unwrap(), 2);
    }

    #[tokio::test]
    async fn galaxy_restore_not_found_errors() {
        let (_tmp, store) = open_store();
        let tool = GalaxyRestoreTool::new(Arc::new(store), None);
        let result = tool
            .call(
                &mut Context::default(),
                json!({"snapshot_id": "nonexistent-id"}),
            )
            .await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn galaxy_restore_missing_snapshot_id_errors() {
        let (_tmp, store) = open_store();
        let tool = GalaxyRestoreTool::new(Arc::new(store), None);
        let result = tool.call(&mut Context::default(), json!({})).await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn galaxy_tool_names_are_correct() {
        let store = Arc::new(open_store().1);
        assert_eq!(
            GalaxyTransferTool::new(store.clone(), None).name(),
            "galaxy.transfer"
        );
        assert_eq!(GalaxyMergeTool::new(store.clone()).name(), "galaxy.merge");
        assert_eq!(
            GalaxySnapshotTool::new(store.clone()).name(),
            "galaxy.snapshot"
        );
        assert_eq!(GalaxyRestoreTool::new(store, None).name(), "galaxy.restore");
    }

    #[tokio::test]
    async fn galaxy_tool_ganas_are_correct() {
        let store = Arc::new(open_store().1);
        assert_eq!(
            GalaxyTransferTool::new(store.clone(), None).gana(),
            Gana::Neck
        );
        assert_eq!(GalaxyMergeTool::new(store.clone()).gana(), Gana::Neck);
        assert_eq!(GalaxySnapshotTool::new(store.clone()).gana(), Gana::Void);
        assert_eq!(GalaxyRestoreTool::new(store, None).gana(), Gana::Void);
    }

    #[tokio::test]
    async fn galaxy_dashboard_shows_counts() {
        let store = Arc::new(open_store().1);
        let mem = Memory::new(Galaxy::Codex, "test".into());
        store.put(Galaxy::Codex, &mem).unwrap();

        let tool = GalaxyDashboardTool::new(store);
        let result = tool.call(&mut Context::default(), json!({})).await.unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["total_memories"], 1);
        assert!(result["galaxies"]["codex"]["count"].as_u64() >= Some(1));
    }

    #[tokio::test]
    async fn galaxy_backup_creates_snapshot() {
        let store = Arc::new(open_store().1);
        let mem = Memory::new(Galaxy::Codex, "backup test".into());
        store.put(Galaxy::Codex, &mem).unwrap();

        let tool = GalaxyBackupTool::new(store.clone());
        let result = tool.call(&mut Context::default(), json!({})).await.unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["total_memories"], 1);
        assert!(result["backup_id"].as_str().is_some());

        let journals = store.scan(Galaxy::Journals, 100).unwrap();
        assert!(
            journals
                .iter()
                .any(|m| m.metadata.tags.contains(&"backup".to_string()))
        );
    }

    #[tokio::test]
    async fn galaxy_taxonomy_lists_all() {
        let store = Arc::new(open_store().1);
        let tool = GalaxyTaxonomyTool::new(store);
        let result = tool.call(&mut Context::default(), json!({})).await.unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["total_galaxies"], 14);
        assert_eq!(result["memory_galaxies"], 10);
        let galaxies = result["galaxies"].as_array().unwrap();
        assert_eq!(galaxies.len(), 14);
    }

    #[tokio::test]
    async fn galaxy_purge_clears_galaxy() {
        let store = Arc::new(open_store().1);
        let mem1 = Memory::new(Galaxy::Codex, "first".into());
        let mem2 = Memory::new(Galaxy::Codex, "second".into());
        store.put(Galaxy::Codex, &mem1).unwrap();
        store.put(Galaxy::Codex, &mem2).unwrap();
        assert_eq!(store.count(Galaxy::Codex).unwrap(), 2);

        let tool = GalaxyPurgeTool::new(store, None);
        let result = tool
            .call(&mut Context::default(), json!({"galaxy": "codex"}))
            .await
            .unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["purged"], 2);
    }

    #[tokio::test]
    async fn galaxy_purge_missing_param_errors() {
        let store = Arc::new(open_store().1);
        let tool = GalaxyPurgeTool::new(store, None);
        let result = tool.call(&mut Context::default(), json!({})).await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn galaxy_health_all_galaxies() {
        let store = Arc::new(open_store().1);
        let mem = Memory::new(Galaxy::Codex, "healthy".into());
        store.put(Galaxy::Codex, &mem).unwrap();

        let tool = GalaxyHealthTool::new(store);
        let result = tool.call(&mut Context::default(), json!({})).await.unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["all_healthy"], true);
        assert_eq!(result["galaxies_checked"], 10);
    }

    #[tokio::test]
    async fn galaxy_health_single_galaxy() {
        let store = Arc::new(open_store().1);
        let tool = GalaxyHealthTool::new(store);
        let result = tool
            .call(&mut Context::default(), json!({"galaxy": "codex"}))
            .await
            .unwrap();
        assert_eq!(result["status"], "success");
        assert_eq!(result["galaxies_checked"], 1);
        assert_eq!(result["results"]["codex"]["health"], "empty");
    }

    #[tokio::test]
    async fn galaxy_new_tool_names_are_correct() {
        let store = Arc::new(open_store().1);
        assert_eq!(
            GalaxyDashboardTool::new(store.clone()).name(),
            "galaxy.dashboard"
        );
        assert_eq!(GalaxyBackupTool::new(store.clone()).name(), "galaxy.backup");
        assert_eq!(
            GalaxyTaxonomyTool::new(store.clone()).name(),
            "galaxy.taxonomy"
        );
        assert_eq!(
            GalaxyPurgeTool::new(store.clone(), None).name(),
            "galaxy.purge"
        );
        assert_eq!(GalaxyHealthTool::new(store).name(), "galaxy.health");
    }

    #[tokio::test]
    async fn galaxy_new_tool_ganas_are_void() {
        let store = Arc::new(open_store().1);
        assert_eq!(GalaxyDashboardTool::new(store.clone()).gana(), Gana::Void);
        assert_eq!(GalaxyBackupTool::new(store.clone()).gana(), Gana::Void);
        assert_eq!(GalaxyTaxonomyTool::new(store.clone()).gana(), Gana::Void);
        assert_eq!(GalaxyPurgeTool::new(store.clone(), None).gana(), Gana::Void);
        assert_eq!(GalaxyHealthTool::new(store).gana(), Gana::Void);
    }
}