dakera-cli 0.5.3

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
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
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
//! Dakera CLI - Command-line interface for Dakera AI Agent Memory Platform

mod commands;
mod config;
pub mod error;
mod output;

use clap::{value_parser, Arg, ArgAction, Command};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

use crate::commands::{
    admin, agent, analytics, completion, config as config_cmd, health, index, init, keys,
    knowledge, memory, namespace, ops, session, vector,
};
use crate::config::Config;

/// Output format for CLI results
#[derive(Clone, Copy, Debug, Default)]
pub enum OutputFormat {
    #[default]
    Table,
    Json,
    Compact,
}

impl From<&str> for OutputFormat {
    fn from(s: &str) -> Self {
        match s.to_lowercase().as_str() {
            "json" => OutputFormat::Json,
            "compact" => OutputFormat::Compact,
            _ => OutputFormat::Table,
        }
    }
}

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 vector upsert -n my-ns --file vectors.json\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"),
        )
        .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_vector_command())
        .subcommand(build_index_command())
        .subcommand(build_ops_command())
        .subcommand(build_memory_command())
        .subcommand(build_session_command())
        .subcommand(build_agent_command())
        .subcommand(build_knowledge_command())
        .subcommand(build_analytics_command())
        .subcommand(build_admin_command())
        .subcommand(build_keys_command())
        .subcommand(build_config_command())
        .subcommand(build_completion_command())
}

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")),
        )
}

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"),
        )
}

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)")),
                ),
        )
}

fn build_vector_command() -> Command {
    Command::new("vector")
        .about("Manage vectors")
        .subcommand(
            Command::new("upsert")
                .about("Upsert vectors from a JSON file")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file containing vectors"),
                )
                .arg(
                    Arg::new("batch-size")
                        .short('b')
                        .long("batch-size")
                        .default_value("100")
                        .value_parser(value_parser!(usize))
                        .help("Batch size for large files"),
                ),
        )
        .subcommand(
            Command::new("upsert-one")
                .about("Upsert a single vector")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("id")
                        .short('i')
                        .long("id")
                        .required(true)
                        .help("Vector ID"),
                )
                .arg(
                    Arg::new("values")
                        .short('V')
                        .long("values")
                        .required(true)
                        .value_delimiter(',')
                        .value_parser(value_parser!(f32))
                        .help("Vector values (comma-separated floats)"),
                )
                .arg(
                    Arg::new("metadata")
                        .short('m')
                        .long("metadata")
                        .help("Optional metadata as JSON string"),
                ),
        )
        .subcommand(
            Command::new("query")
                .about("Query for similar vectors")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("values")
                        .short('V')
                        .long("values")
                        .required(true)
                        .value_delimiter(',')
                        .value_parser(value_parser!(f32))
                        .help("Query vector values (comma-separated floats)"),
                )
                .arg(
                    Arg::new("top-k")
                        .short('k')
                        .long("top-k")
                        .default_value("10")
                        .value_parser(value_parser!(u32))
                        .help("Number of results to return"),
                )
                .arg(
                    Arg::new("include-metadata")
                        .short('m')
                        .long("include-metadata")
                        .action(ArgAction::SetTrue)
                        .help("Include metadata in results"),
                )
                .arg(
                    Arg::new("filter")
                        .long("filter")
                        .help("Filter expression as JSON"),
                ),
        )
        .subcommand(
            Command::new("query-file")
                .about("Query from a file")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file containing query"),
                ),
        )
        .subcommand(
            Command::new("delete")
                .about("Delete vectors by ID")
                .after_help("Examples:\n  dk vector delete -n my-ns --ids id1,id2 --dry-run\n  dk vector delete -n my-ns --all --dry-run\n  dk vector delete -n my-ns --ids id1,id2 --yes")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("ids")
                        .short('i')
                        .long("ids")
                        .value_delimiter(',')
                        .help("Vector IDs to delete"),
                )
                .arg(
                    Arg::new("all")
                        .long("all")
                        .action(ArgAction::SetTrue)
                        .help("Delete all vectors (dangerous!)"),
                )
                .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("multi-search")
                .about("Multi-vector search with positive/negative vectors and MMR")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file with multi-vector search request"),
                ),
        )
        .subcommand(
            Command::new("unified-query")
                .about("Unified query combining vector and text search")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file with unified query request"),
                ),
        )
        .subcommand(
            Command::new("aggregate")
                .about("Aggregate vectors with grouping")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file with aggregation request"),
                ),
        )
        .subcommand(
            Command::new("export")
                .about("Export vectors with pagination")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("cursor")
                        .short('c')
                        .long("cursor")
                        .help("Pagination cursor from previous export"),
                )
                .arg(
                    Arg::new("limit")
                        .short('l')
                        .long("limit")
                        .default_value("100")
                        .value_parser(value_parser!(u32))
                        .help("Maximum number of vectors to export"),
                )
                .arg(
                    Arg::new("include-vectors")
                        .long("include-vectors")
                        .action(ArgAction::SetTrue)
                        .help("Include vector values in export"),
                ),
        )
        .subcommand(
            Command::new("explain")
                .about("Explain query execution plan")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("values")
                        .short('V')
                        .long("values")
                        .required(true)
                        .value_delimiter(',')
                        .value_parser(value_parser!(f32))
                        .help("Query vector values (comma-separated floats)"),
                )
                .arg(
                    Arg::new("top-k")
                        .short('k')
                        .long("top-k")
                        .default_value("10")
                        .value_parser(value_parser!(u32))
                        .help("Number of results to return"),
                )
                .arg(
                    Arg::new("include-metadata")
                        .short('m')
                        .long("include-metadata")
                        .action(ArgAction::SetTrue)
                        .help("Include metadata in results"),
                ),
        )
        .subcommand(
            Command::new("upsert-columns")
                .about("Column-format vector upsert from JSON file")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .required(true)
                        .help("Namespace name"),
                )
                .arg(
                    Arg::new("file")
                        .short('f')
                        .long("file")
                        .required(true)
                        .help("JSON file with column upsert data"),
                ),
        )
}

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"),
                ),
        )
}

fn build_ops_command() -> Command {
    Command::new("ops")
        .about("Operations and maintenance")
        .subcommand(Command::new("diagnostics").about("Get system diagnostics"))
        .subcommand(Command::new("jobs").about("List background jobs"))
        .subcommand(
            Command::new("job")
                .about("Get specific job status")
                .arg(Arg::new("id").required(true).help("Job ID")),
        )
        .subcommand(
            Command::new("compact")
                .about("Trigger index compaction")
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Target namespace (optional, compacts all if not specified)"),
                )
                .arg(
                    Arg::new("force")
                        .short('f')
                        .long("force")
                        .action(ArgAction::SetTrue)
                        .help("Force compaction even if not needed"),
                ),
        )
        .subcommand(
            Command::new("shutdown")
                .about("Gracefully shutdown the server")
                .after_help("Examples:\n  dk ops shutdown --dry-run\n  dk ops shutdown --yes")
                .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 happen without initiating the shutdown"),
                ),
        )
        .subcommand(Command::new("metrics").about("Show server metrics"))
        .subcommand(
            Command::new("stats")
                .about("Show server statistics (version, state, vector count, uptime)"),
        )
}

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)"),
                ),
        )
}

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")),
        )
}

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"),
                ),
        )
}

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"),
                ),
        )
}

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)"),
                ),
        )
}

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")),
        )
}

fn build_analytics_command() -> Command {
    Command::new("analytics")
        .about("View platform analytics and metrics")
        .subcommand(
            Command::new("overview")
                .about("Analytics overview")
                .arg(
                    Arg::new("period")
                        .short('p')
                        .long("period")
                        .default_value("24h")
                        .help("Time period (e.g. 1h, 24h, 7d)"),
                )
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Filter by namespace"),
                ),
        )
        .subcommand(
            Command::new("latency")
                .about("Latency statistics")
                .arg(
                    Arg::new("period")
                        .short('p')
                        .long("period")
                        .default_value("24h")
                        .help("Time period (e.g. 1h, 24h, 7d)"),
                )
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Filter by namespace"),
                ),
        )
        .subcommand(
            Command::new("throughput")
                .about("Throughput statistics")
                .arg(
                    Arg::new("period")
                        .short('p')
                        .long("period")
                        .default_value("24h")
                        .help("Time period (e.g. 1h, 24h, 7d)"),
                )
                .arg(
                    Arg::new("namespace")
                        .short('n')
                        .long("namespace")
                        .help("Filter by namespace"),
                ),
        )
        .subcommand(
            Command::new("storage").about("Storage statistics").arg(
                Arg::new("namespace")
                    .short('n')
                    .long("namespace")
                    .help("Filter by namespace"),
            ),
        )
}

#[tokio::main]
async fn main() {
    // Parse CLI arguments first so we can read --profile before loading config
    let matches = build_cli().get_matches();

    // Initialize logging if verbose
    if matches.get_flag("verbose") {
        tracing_subscriber::registry()
            .with(tracing_subscriber::EnvFilter::new("info"))
            .with(tracing_subscriber::fmt::layer())
            .init();
    }

    // Resolve output format early so we can use it in error reporting
    let format_str = matches.get_one::<String>("format").unwrap();
    let format = OutputFormat::from(format_str.as_str());

    if let Err(err) = run(matches, format).await {
        // Classify the error and choose the appropriate exit code
        let cli_err = error::classify(&err);
        let exit_code = cli_err.exit_code();

        match format {
            OutputFormat::Json | OutputFormat::Compact => {
                let json_err = error::JsonError {
                    error: true,
                    code: cli_err.error_code(),
                    exit_code,
                    message: cli_err.to_string(),
                };
                let s = if matches!(format, OutputFormat::Json) {
                    serde_json::to_string_pretty(&json_err)
                } else {
                    serde_json::to_string(&json_err)
                };
                eprintln!("{}", s.unwrap_or_else(|_| cli_err.to_string()));
            }
            OutputFormat::Table => {
                output::error(&cli_err.to_string());
            }
        }

        std::process::exit(exit_code);
    }
}

async fn run(matches: clap::ArgMatches, format: OutputFormat) -> anyhow::Result<()> {
    // Load configuration, honouring --profile / DAKERA_PROFILE if provided
    let config = match matches.get_one::<String>("profile") {
        Some(p) => Config::load_with_profile(p),
        None => Config::load(),
    };

    // Get URL from args or config
    let cli_url = matches.get_one::<String>("url").unwrap();
    let url = if cli_url != "http://localhost:3000" {
        cli_url.clone()
    } else {
        config.server_url.clone()
    };

    // Execute command
    match matches.subcommand() {
        Some(("init", _)) => {
            init::execute().await?;
        }
        Some(("health", sub_matches)) => {
            let detailed = sub_matches.get_flag("detailed");
            health::execute(&url, detailed, format).await?;
        }
        Some(("namespace", sub_matches)) => {
            namespace::execute(&url, sub_matches, format).await?;
        }
        Some(("vector", sub_matches)) => {
            vector::execute(&url, sub_matches, format).await?;
        }
        Some(("index", sub_matches)) => {
            index::execute(&url, sub_matches, format).await?;
        }
        Some(("ops", sub_matches)) => {
            ops::execute(&url, sub_matches, format).await?;
        }
        Some(("memory", sub_matches)) => {
            memory::execute(&url, sub_matches, format).await?;
        }
        Some(("session", sub_matches)) => {
            session::execute(&url, sub_matches, format).await?;
        }
        Some(("agent", sub_matches)) => {
            agent::execute(&url, sub_matches, format).await?;
        }
        Some(("knowledge", sub_matches)) => {
            knowledge::execute(&url, sub_matches, format).await?;
        }
        Some(("analytics", sub_matches)) => {
            analytics::execute(&url, sub_matches, format).await?;
        }
        Some(("admin", sub_matches)) => {
            admin::execute(&url, sub_matches, format).await?;
        }
        Some(("keys", sub_matches)) => {
            keys::execute(&url, sub_matches, format).await?;
        }
        Some(("completion", sub_matches)) => {
            let shell = sub_matches.get_one::<String>("shell").unwrap();
            let install = sub_matches.get_flag("install");
            completion::execute(shell, install)?;
        }
        Some(("config", sub_matches)) => {
            config_cmd::execute(sub_matches).await?;
        }
        _ => {
            build_cli().print_help()?;
        }
    }

    Ok(())
}