dakera-cli 0.6.0

Command-line interface for Dakera AI Agent Memory Platform
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
//! Clap command tree construction.
//!
//! Every `build_*_command()` function lives here. `main.rs` imports
//! `build_cli()` and stays under 100 lines.

use clap::{value_parser, Arg, ArgAction, Command};

pub fn build_cli() -> Command {
    Command::new("dk")
        .version(env!("CARGO_PKG_VERSION"))
        .author("Dakera Team")
        .about("Dakera CLI - Manage your AI agent memory platform from the command line")
        .after_help(
            "Examples:\n  dk health\n  dk namespace list\n  dk memory store my-agent 'Completed task X' --importance 0.8\n  dk memory recall my-agent 'recent tasks' --top-k 5\n  dk text search 'user preferences' --namespace default\n  dk completion zsh --install\n\nError exit codes:\n  0  success\n  1  general error\n  2  connection error (server unreachable)\n  3  not found\n  4  permission denied\n  5  invalid input\n  6  server error",
        )
        .arg(
            Arg::new("url")
                .short('u')
                .long("url")
                .env("DAKERA_URL")
                .default_value("http://localhost:3000")
                .help("Server URL"),
        )
        .arg(
            Arg::new("format")
                .short('f')
                .long("format")
                .default_value("table")
                .value_parser(["table", "json", "compact"])
                .help("Output format"),
        )
        .arg(
            Arg::new("verbose")
                .short('v')
                .long("verbose")
                .action(ArgAction::SetTrue)
                .help("Enable verbose output with HTTP request/response logging"),
        )
        .arg(
            Arg::new("profile")
                .short('p')
                .long("profile")
                .env("DAKERA_PROFILE")
                .help("Named server profile to use (overrides active_profile in config)"),
        )
        .subcommand(
            Command::new("init")
                .about("Interactive setup wizard — configure server URL and default namespace"),
        )
        .subcommand(
            Command::new("health")
                .about("Check server health and connectivity")
                .arg(
                    Arg::new("detailed")
                        .short('d')
                        .long("detailed")
                        .action(ArgAction::SetTrue)
                        .help("Show detailed health information"),
                ),
        )
        .subcommand(build_namespace_command())
        .subcommand(build_index_command())
        .subcommand(build_memory_command())
        .subcommand(build_session_command())
        .subcommand(build_agent_command())
        .subcommand(build_knowledge_command())
        .subcommand(build_keys_command())
        .subcommand(build_admin_command())
        .subcommand(build_config_command())
        .subcommand(build_completion_command())
        .subcommand(build_text_command())
}

pub fn build_config_command() -> Command {
    Command::new("config")
        .about("Show configuration or manage server profiles")
        .arg(
            Arg::new("show")
                .long("show")
                .action(ArgAction::SetTrue)
                .help("Show current configuration (default action)"),
        )
        .subcommand(
            Command::new("profile")
                .about("Manage named server profiles")
                .subcommand(
                    Command::new("add")
                        .about("Add or update a named profile")
                        .arg(
                            Arg::new("name")
                                .required(true)
                                .help("Profile name (e.g. local, staging, prod)"),
                        )
                        .arg(
                            Arg::new("url")
                                .short('u')
                                .long("url")
                                .required(true)
                                .help("Server URL for this profile"),
                        )
                        .arg(
                            Arg::new("namespace")
                                .short('n')
                                .long("namespace")
                                .help("Default namespace for this profile"),
                        ),
                )
                .subcommand(
                    Command::new("use").about("Switch the active profile").arg(
                        Arg::new("name")
                            .required(true)
                            .help("Profile name to activate"),
                    ),
                )
                .subcommand(Command::new("list").about("List all profiles")),
        )
}

pub fn build_completion_command() -> Command {
    Command::new("completion")
        .about("Generate shell completion scripts")
        .long_about(
            "Generate shell completion scripts for bash, zsh, or fish.\n\
             \n\
             Print to stdout:\n\
             \n  dk completion bash\n\
             \n  dk completion zsh\n\
             \n  dk completion fish\n\
             \nInstall automatically:\n\
             \n  dk completion bash --install\n\
             \n  dk completion zsh --install\n\
             \n  dk completion fish --install\n\
             \nDynamic completion provides namespace and agent names from the live server.",
        )
        .arg(
            Arg::new("shell")
                .required(true)
                .value_parser(["bash", "zsh", "fish"])
                .help("Shell to generate completion for"),
        )
        .arg(
            Arg::new("install")
                .long("install")
                .action(ArgAction::SetTrue)
                .help("Install the completion script to the appropriate location"),
        )
}

pub fn build_namespace_command() -> Command {
    Command::new("namespace")
        .about("Manage namespaces")
        .after_help(
            "Examples:\n  dk namespace list\n  dk namespace get my-ns\n  dk namespace create my-ns\n  dk namespace delete my-ns --dry-run\n  dk namespace delete my-ns --yes\n  dk namespace policy get my-ns\n  dk namespace policy set my-ns --consolidation-enabled true --rate-limit-enabled true --rate-limit-stores-per-minute 100",
        )
        .subcommand(Command::new("list").about("List all namespaces"))
        .subcommand(
            Command::new("get")
                .about("Get namespace information")
                .arg(Arg::new("name").required(true).help("Namespace name")),
        )
        .subcommand(
            Command::new("create")
                .about("Create a new namespace")
                .arg(Arg::new("name").required(true).help("Namespace name"))
                .arg(
                    Arg::new("dimension")
                        .short('d')
                        .long("dimension")
                        .value_parser(value_parser!(u32))
                        .help("Vector dimension"),
                ),
        )
        .subcommand(
            Command::new("delete")
                .about("Delete a namespace and all its data")
                .after_help("Examples:\n  dk namespace delete my-ns --dry-run\n  dk namespace delete my-ns --yes")
                .arg(Arg::new("name").required(true).help("Namespace name"))
                .arg(
                    Arg::new("yes")
                        .short('y')
                        .long("yes")
                        .action(ArgAction::SetTrue)
                        .help("Skip confirmation prompt"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Show what would be deleted without making any changes"),
                ),
        )
        .subcommand(
            Command::new("policy")
                .about("Manage namespace memory lifecycle policy (TTLs, consolidation, rate limiting)")
                .after_help("Examples:\n  dk namespace policy get my-ns\n  dk namespace policy set my-ns --consolidation-enabled true\n  dk namespace policy set my-ns --rate-limit-enabled true --rate-limit-stores-per-minute 60")
                .subcommand(
                    Command::new("get")
                        .about("Show the current memory policy for a namespace")
                        .arg(Arg::new("namespace").required(true).help("Namespace name")),
                )
                .subcommand(
                    Command::new("set")
                        .about("Update memory policy fields for a namespace (only supplied flags are changed)")
                        .arg(Arg::new("namespace").required(true).help("Namespace name"))
                        .arg(Arg::new("working-ttl").long("working-ttl").value_parser(value_parser!(u64)).help("TTL for working memories in seconds (default: 14400 = 4h)"))
                        .arg(Arg::new("episodic-ttl").long("episodic-ttl").value_parser(value_parser!(u64)).help("TTL for episodic memories in seconds (default: 2592000 = 30d)"))
                        .arg(Arg::new("semantic-ttl").long("semantic-ttl").value_parser(value_parser!(u64)).help("TTL for semantic memories in seconds (default: 31536000 = 365d)"))
                        .arg(Arg::new("procedural-ttl").long("procedural-ttl").value_parser(value_parser!(u64)).help("TTL for procedural memories in seconds (default: 63072000 = 730d)"))
                        .arg(Arg::new("working-decay").long("working-decay").value_parser(["exponential", "power_law", "logarithmic", "flat"]).help("Decay curve for working memories"))
                        .arg(Arg::new("episodic-decay").long("episodic-decay").value_parser(["exponential", "power_law", "logarithmic", "flat"]).help("Decay curve for episodic memories"))
                        .arg(Arg::new("semantic-decay").long("semantic-decay").value_parser(["exponential", "power_law", "logarithmic", "flat"]).help("Decay curve for semantic memories"))
                        .arg(Arg::new("procedural-decay").long("procedural-decay").value_parser(["exponential", "power_law", "logarithmic", "flat"]).help("Decay curve for procedural memories"))
                        .arg(Arg::new("spaced-repetition-factor").long("spaced-repetition-factor").value_parser(value_parser!(f64)).help("TTL extension multiplier per recall hit (default: 1.0; 0.0 = disabled)"))
                        .arg(Arg::new("spaced-repetition-base-interval").long("spaced-repetition-base-interval").value_parser(value_parser!(u64)).help("Base interval in seconds for spaced repetition TTL extension (default: 86400 = 1d)"))
                        .arg(Arg::new("consolidation-enabled").long("consolidation-enabled").value_parser(value_parser!(bool)).help("Enable background DBSCAN deduplication (default: false)"))
                        .arg(Arg::new("consolidation-threshold").long("consolidation-threshold").value_parser(value_parser!(f32)).help("DBSCAN cosine-similarity threshold (default: 0.92; higher = stricter)"))
                        .arg(Arg::new("consolidation-interval-hours").long("consolidation-interval-hours").value_parser(value_parser!(u32)).help("Background consolidation sweep interval in hours (default: 24)"))
                        .arg(Arg::new("rate-limit-enabled").long("rate-limit-enabled").value_parser(value_parser!(bool)).help("Enable per-namespace store/recall rate limiting (default: false)"))
                        .arg(Arg::new("rate-limit-stores-per-minute").long("rate-limit-stores-per-minute").value_parser(value_parser!(u32)).help("Max store operations per minute (omit for unlimited)"))
                        .arg(Arg::new("rate-limit-recalls-per-minute").long("rate-limit-recalls-per-minute").value_parser(value_parser!(u32)).help("Max recall operations per minute (omit for unlimited)")),
                ),
        )
}

pub fn build_index_command() -> Command {
    Command::new("index")
        .about("Manage indexes")
        .subcommand(
            Command::new("stats")
                .about("Get index statistics for a namespace")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                ),
        )
        .subcommand(
            Command::new("fulltext-stats")
                .about("Get full-text index statistics")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                ),
        )
        .subcommand(
            Command::new("rebuild")
                .about("Rebuild index for a namespace")
                .after_help("Examples:\n  dk index rebuild -n my-ns --dry-run\n  dk index rebuild -n my-ns --index-type vector --yes")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("index-type")
                        .short('t')
                        .long("index-type")
                        .default_value("all")
                        .help("Index type to rebuild (vector, fulltext, all)"),
                )
                .arg(
                    Arg::new("yes")
                        .short('y')
                        .long("yes")
                        .action(ArgAction::SetTrue)
                        .help("Skip confirmation prompt"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Show what would be rebuilt without making any changes"),
                ),
        )
}

pub fn build_memory_command() -> Command {
    Command::new("memory")
        .about("Manage agent memories")
        .subcommand(
            Command::new("store")
                .about("Store a memory for an agent")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("content")
                        .required(true)
                        .help("Memory content text"),
                )
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .default_value("episodic")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Memory type"),
                )
                .arg(
                    Arg::new("importance")
                        .short('i')
                        .long("importance")
                        .default_value("0.5")
                        .value_parser(value_parser!(f32))
                        .help("Importance score (0.0 to 1.0)"),
                )
                .arg(
                    Arg::new("session-id")
                        .short('s')
                        .long("session-id")
                        .help("Session ID to associate with"),
                ),
        )
        .subcommand(
            Command::new("recall")
                .about("Recall memories by semantic query")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(Arg::new("query").required(true).help("Search query"))
                .arg(
                    Arg::new("top-k")
                        .short('k')
                        .long("top-k")
                        .default_value("5")
                        .value_parser(value_parser!(usize))
                        .help("Number of results to return"),
                )
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Filter by memory type"),
                ),
        )
        .subcommand(
            Command::new("get")
                .about("Get a specific memory by ID")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(Arg::new("memory_id").required(true).help("Memory ID")),
        )
        .subcommand(
            Command::new("update")
                .about("Update an existing memory")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(Arg::new("memory_id").required(true).help("Memory ID"))
                .arg(
                    Arg::new("content")
                        .short('c')
                        .long("content")
                        .help("New content text"),
                )
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("New memory type"),
                ),
        )
        .subcommand(
            Command::new("forget")
                .about("Delete a memory")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("memory_id")
                        .required(true)
                        .help("Memory ID to delete"),
                ),
        )
        .subcommand(
            Command::new("search")
                .about("Search memories with advanced filters")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(Arg::new("query").required(true).help("Search query"))
                .arg(
                    Arg::new("top-k")
                        .short('k')
                        .long("top-k")
                        .default_value("10")
                        .value_parser(value_parser!(usize))
                        .help("Number of results to return"),
                )
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Filter by memory type"),
                ),
        )
        .subcommand(
            Command::new("importance")
                .about("Update importance score for memories")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("ids")
                        .long("ids")
                        .required(true)
                        .help("Comma-separated memory IDs"),
                )
                .arg(
                    Arg::new("value")
                        .long("value")
                        .required(true)
                        .value_parser(value_parser!(f32))
                        .help("New importance value (0.0 to 1.0)"),
                ),
        )
        .subcommand(
            Command::new("consolidate")
                .about("Consolidate similar memories")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Filter by memory type"),
                )
                .arg(
                    Arg::new("threshold")
                        .long("threshold")
                        .default_value("0.8")
                        .value_parser(value_parser!(f32))
                        .help("Similarity threshold for consolidation"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Preview consolidation without applying changes"),
                ),
        )
        .subcommand(
            Command::new("feedback")
                .about("Submit feedback on a memory recall")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(Arg::new("memory_id").required(true).help("Memory ID"))
                .arg(Arg::new("feedback").required(true).help("Feedback text"))
                .arg(
                    Arg::new("score")
                        .short('s')
                        .long("score")
                        .value_parser(value_parser!(f32))
                        .help("Relevance score (0.0 to 1.0)"),
                ),
        )
        .subcommand(
            Command::new("batch-forget")
                .about("Batch delete memories matching filters")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Delete memories of this type"),
                )
                .arg(
                    Arg::new("min-importance")
                        .long("min-importance")
                        .value_parser(value_parser!(f32))
                        .help("Delete memories with importance below this value"),
                )
                .arg(
                    Arg::new("max-age-days")
                        .long("max-age-days")
                        .value_parser(value_parser!(u32))
                        .help("Delete memories older than this many days"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Preview deletions without removing any memories"),
                ),
        )
}

pub fn build_session_command() -> Command {
    Command::new("session")
        .about("Manage agent sessions")
        .subcommand(
            Command::new("start")
                .about("Start a new session for an agent")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("metadata")
                        .short('m')
                        .long("metadata")
                        .help("Session metadata as JSON string"),
                ),
        )
        .subcommand(
            Command::new("end")
                .about("End an active session")
                .arg(Arg::new("session_id").required(true).help("Session ID"))
                .arg(
                    Arg::new("summary")
                        .short('s')
                        .long("summary")
                        .help("Session summary text"),
                ),
        )
        .subcommand(
            Command::new("get")
                .about("Get session details")
                .arg(Arg::new("session_id").required(true).help("Session ID")),
        )
        .subcommand(
            Command::new("list")
                .about("List sessions")
                .arg(
                    Arg::new("agent-id")
                        .short('a')
                        .long("agent-id")
                        .help("Filter by agent ID"),
                )
                .arg(
                    Arg::new("active-only")
                        .long("active-only")
                        .action(ArgAction::SetTrue)
                        .help("Show only active sessions"),
                )
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("50")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of sessions to return"),
                ),
        )
        .subcommand(
            Command::new("memories")
                .about("Get memories for a session")
                .arg(Arg::new("session_id").required(true).help("Session ID")),
        )
}

pub fn build_agent_command() -> Command {
    Command::new("agent")
        .about("Manage agents")
        .subcommand(Command::new("list").about("List all agents"))
        .subcommand(
            Command::new("memories")
                .about("Get memories for an agent")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Filter by memory type"),
                )
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("50")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of memories to return"),
                ),
        )
        .subcommand(
            Command::new("stats")
                .about("Get agent statistics")
                .arg(Arg::new("agent_id").required(true).help("Agent ID")),
        )
        .subcommand(
            Command::new("sessions")
                .about("Get sessions for an agent")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("active-only")
                        .long("active-only")
                        .action(ArgAction::SetTrue)
                        .help("Show only active sessions"),
                )
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("50")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of sessions to return"),
                ),
        )
}

pub fn build_knowledge_command() -> Command {
    Command::new("knowledge")
        .about("Knowledge graph operations")
        .subcommand(
            Command::new("graph")
                .about("Build knowledge graph from a seed memory")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("memory-id")
                        .short('m')
                        .long("memory-id")
                        .help("Seed memory ID"),
                )
                .arg(
                    Arg::new("depth")
                        .short('d')
                        .long("depth")
                        .value_parser(value_parser!(u32))
                        .help("Graph traversal depth"),
                )
                .arg(
                    Arg::new("min-similarity")
                        .short('s')
                        .long("min-similarity")
                        .value_parser(value_parser!(f32))
                        .help("Minimum similarity threshold (0.0 to 1.0)"),
                ),
        )
        .subcommand(
            Command::new("full-graph")
                .about("Build full knowledge graph for an agent")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("max-nodes")
                        .long("max-nodes")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of nodes"),
                )
                .arg(
                    Arg::new("min-similarity")
                        .short('s')
                        .long("min-similarity")
                        .value_parser(value_parser!(f32))
                        .help("Minimum similarity threshold (0.0 to 1.0)"),
                )
                .arg(
                    Arg::new("cluster-threshold")
                        .long("cluster-threshold")
                        .value_parser(value_parser!(f32))
                        .help("Cluster similarity threshold (0.0 to 1.0)"),
                )
                .arg(
                    Arg::new("max-edges")
                        .long("max-edges")
                        .value_parser(value_parser!(u32))
                        .help("Maximum edges per node"),
                ),
        )
        .subcommand(
            Command::new("summarize")
                .about("Summarize agent memories")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("memory-ids")
                        .long("memory-ids")
                        .help("Comma-separated memory IDs to summarize"),
                )
                .arg(
                    Arg::new("target-type")
                        .short('t')
                        .long("target-type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Target memory type for the summary"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Preview summarization without applying changes"),
                ),
        )
        .subcommand(
            Command::new("deduplicate")
                .about("Find and remove duplicate memories")
                .arg(Arg::new("agent_id").required(true).help("Agent ID"))
                .arg(
                    Arg::new("threshold")
                        .long("threshold")
                        .value_parser(value_parser!(f32))
                        .help("Similarity threshold for deduplication (0.0 to 1.0)"),
                )
                .arg(
                    Arg::new("type")
                        .short('t')
                        .long("type")
                        .value_parser(["episodic", "semantic", "procedural", "working"])
                        .help("Filter by memory type"),
                )
                .arg(
                    Arg::new("dry-run")
                        .long("dry-run")
                        .action(ArgAction::SetTrue)
                        .help("Preview deduplication without applying changes"),
                ),
        )
}

pub fn build_admin_command() -> Command {
    Command::new("admin")
        .about("Cluster administration, caching, backups, and configuration")
        .subcommand(Command::new("cluster-status").about("Get cluster status overview"))
        .subcommand(Command::new("cluster-nodes").about("List cluster nodes"))
        .subcommand(
            Command::new("optimize")
                .about("Optimize a namespace (compact indexes, reclaim space)")
                .arg(
                    Arg::new("namespace")
                        .required(true)
                        .help("Namespace to optimize"),
                ),
        )
        .subcommand(
            Command::new("index-stats")
                .about("Get index statistics for a namespace")
                .arg(Arg::new("namespace").required(true).help("Namespace name")),
        )
        .subcommand(
            Command::new("rebuild-indexes")
                .about("Rebuild indexes for a namespace")
                .arg(Arg::new("namespace").required(true).help("Namespace name")),
        )
        .subcommand(Command::new("cache-stats").about("Get cache statistics"))
        .subcommand(
            Command::new("cache-clear")
                .about("Clear cache (optionally for a specific namespace)")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Namespace to clear cache for (all if omitted)"),
                ),
        )
        .subcommand(Command::new("config-get").about("Get current server configuration"))
        .subcommand(
            Command::new("config-set")
                .about("Update a configuration value")
                .arg(
                    Arg::new("key")
                        .short('k')
                        .long("key")
                        .required(true)
                        .help("Configuration key"),
                )
                .arg(
                    Arg::new("value")
                        .short('V')
                        .long("value")
                        .required(true)
                        .help("Configuration value (string or JSON)"),
                ),
        )
        .subcommand(Command::new("quotas-get").about("List all namespace quotas"))
        .subcommand(
            Command::new("quotas-set")
                .about("Set namespace quotas")
                .arg(
                    Arg::new("data")
                        .short('d')
                        .long("data")
                        .required(true)
                        .help("Quota configuration as JSON string"),
                ),
        )
        .subcommand(
            Command::new("slow-queries")
                .about("List slow queries")
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("20")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of queries to return"),
                )
                .arg(
                    Arg::new("min-duration")
                        .long("min-duration")
                        .value_parser(value_parser!(f64))
                        .help("Minimum duration in milliseconds"),
                ),
        )
        .subcommand(
            Command::new("backup-create")
                .about("Create a new backup")
                .arg(
                    Arg::new("no-data")
                        .long("no-data")
                        .action(ArgAction::SetTrue)
                        .help("Create schema-only backup without vector data"),
                ),
        )
        .subcommand(Command::new("backup-list").about("List all backups"))
        .subcommand(
            Command::new("backup-restore")
                .about("Restore from a backup")
                .arg(
                    Arg::new("backup_id")
                        .required(true)
                        .help("Backup ID to restore"),
                ),
        )
        .subcommand(
            Command::new("backup-delete").about("Delete a backup").arg(
                Arg::new("backup_id")
                    .required(true)
                    .help("Backup ID to delete"),
            ),
        )
        .subcommand(
            Command::new("configure-ttl")
                .about("Configure TTL (time-to-live) for a namespace")
                .arg(Arg::new("namespace").required(true).help("Namespace name"))
                .arg(
                    Arg::new("ttl-seconds")
                        .long("ttl-seconds")
                        .required(true)
                        .value_parser(value_parser!(u64))
                        .help("TTL in seconds for vectors in this namespace"),
                )
                .arg(
                    Arg::new("strategy")
                        .long("strategy")
                        .help("TTL strategy (e.g. delete, archive)"),
                ),
        )
}

pub fn build_keys_command() -> Command {
    Command::new("keys")
        .about("Manage API keys")
        .subcommand(
            Command::new("create")
                .about("Create a new API key")
                .arg(
                    Arg::new("name")
                        .required(true)
                        .help("Human-readable name for the key"),
                )
                .arg(
                    Arg::new("permissions")
                        .short('p')
                        .long("permissions")
                        .help("Permission scope (e.g. read, write, admin)"),
                )
                .arg(
                    Arg::new("expires")
                        .short('e')
                        .long("expires")
                        .value_parser(value_parser!(u64))
                        .help("Expiration in days"),
                ),
        )
        .subcommand(Command::new("list").about("List all API keys"))
        .subcommand(
            Command::new("get")
                .about("Get API key details")
                .arg(Arg::new("key_id").required(true).help("API key ID")),
        )
        .subcommand(
            Command::new("delete")
                .about("Delete (revoke) an API key")
                .arg(Arg::new("key_id").required(true).help("API key ID")),
        )
        .subcommand(
            Command::new("deactivate")
                .about("Deactivate an API key without deleting it")
                .arg(Arg::new("key_id").required(true).help("API key ID")),
        )
        .subcommand(
            Command::new("rotate")
                .about("Rotate an API key (generate new secret)")
                .arg(Arg::new("key_id").required(true).help("API key ID")),
        )
        .subcommand(
            Command::new("usage")
                .about("Get usage statistics for an API key")
                .arg(Arg::new("key_id").required(true).help("API key ID")),
        )
}

pub fn build_text_command() -> Command {
    Command::new("text")
        .about("Full-text (BM25) search across memories")
        .subcommand(
            Command::new("search")
                .about("BM25 full-text search")
                .arg(Arg::new("query").required(true).help("Search query"))
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Namespace to search in"),
                )
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("10")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of results"),
                ),
        )
}