chasm-cli 2.0.0

Universal chat session manager - harvest, merge, and analyze AI chat history from VS Code, Cursor, and other editors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
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
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
// Copyright (c) 2024-2026 Nervosys LLC
// SPDX-License-Identifier: AGPL-3.0-only
//! CLI argument definitions using clap derive macros

use clap::{Parser, Subcommand};

/// CHAt System Manager (chasm) - Manage and merge chat sessions across workspaces
#[derive(Parser)]
#[command(name = "chasm")]
#[command(author = "Nervosys")]
#[command(version)]
#[command(about = "Manage and merge chat sessions across workspaces", long_about = None)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    // ============================================================================
    // List Commands
    // ============================================================================
    /// List workspaces, sessions, or paths
    #[command(visible_alias = "ls")]
    List {
        #[command(subcommand)]
        command: Option<ListCommands>,
    },

    // ============================================================================
    // Find Commands
    // ============================================================================
    /// Search workspaces or sessions by text pattern (title, content, ID)
    Find {
        #[command(subcommand)]
        command: Option<FindCommands>,
    },

    // ============================================================================
    // Show Commands
    // ============================================================================
    /// Show workspaces, sessions, or paths
    #[command(visible_alias = "info")]
    Show {
        #[command(subcommand)]
        command: Option<ShowCommands>,
    },

    // ============================================================================
    // Fetch Commands
    // ============================================================================
    /// Fetch chat sessions from workspaces, sessions, or paths
    Fetch {
        #[command(subcommand)]
        command: Option<FetchCommands>,
    },

    // ============================================================================
    // Merge Commands
    // ============================================================================
    /// Merge chat sessions from workspaces, sessions, or paths
    Merge {
        #[command(subcommand)]
        command: Option<MergeCommands>,
    },

    // ============================================================================
    // Export Commands
    // ============================================================================
    /// Export chat sessions from workspaces, sessions, or paths
    Export {
        #[command(subcommand)]
        command: Option<ExportCommands>,
    },

    // ============================================================================
    // Import Commands
    // ============================================================================
    /// Import session files from external directories into a workspace
    Import {
        #[command(subcommand)]
        command: Option<ImportCommands>,
    },

    // ============================================================================
    // Move Commands
    // ============================================================================
    /// Move chat sessions between workspaces
    #[command(visible_alias = "mv")]
    Move {
        #[command(subcommand)]
        command: Option<MoveCommands>,
    },

    // ============================================================================
    // Git Integration Commands
    // ============================================================================
    /// Git integration for chat session versioning
    Git {
        #[command(subcommand)]
        command: GitCommands,
    },

    // ============================================================================
    // Migration Commands
    // ============================================================================
    /// Migration commands for moving chat sessions between machines
    Migration {
        #[command(subcommand)]
        command: MigrationCommands,
    },

    // ============================================================================
    // Run Commands (Agent Launcher + TUI)
    // ============================================================================
    /// Launch an AI coding agent with auto-save, or run interactive tools
    ///
    /// Supported agents: claude, open, claw, cursor, codex, droid, gemini
    Run {
        #[command(subcommand)]
        command: RunCommands,
    },

    // ============================================================================
    // Watch Command (File-System Monitor)
    // ============================================================================
    /// Watch agent session directories for changes and auto-harvest
    ///
    /// Monitors session storage paths for new or modified files.
    /// Default: watches all known agent directories.
    #[command(visible_alias = "w")]
    Watch {
        /// Watch a specific agent's session directory (e.g., claude, gemini)
        #[arg(short, long)]
        agent: Option<String>,

        /// Watch a custom path instead of agent directories
        #[arg(short, long)]
        path: Option<String>,

        /// Debounce interval in seconds before harvesting (default: 3)
        #[arg(short, long, default_value = "3")]
        debounce: u64,

        /// Detect changes without harvesting (dry-run)
        #[arg(long)]
        no_harvest: bool,

        /// Show detailed file change events
        #[arg(short, long)]
        verbose: bool,
    },

    // ============================================================================
    // Provider Commands
    // ============================================================================
    /// Manage LLM providers (Ollama, vLLM, Foundry, Cursor, etc.)
    Provider {
        #[command(subcommand)]
        command: ProviderCommands,
    },

    // ============================================================================
    // Detect Commands
    // ============================================================================
    /// Auto-detect workspace and provider information
    Detect {
        #[command(subcommand)]
        command: Option<DetectCommands>,
    },

    // ============================================================================
    // Register Commands
    // ============================================================================
    /// Add on-disk sessions to VS Code's database index (makes orphaned sessions visible)
    Register {
        #[command(subcommand)]
        command: RegisterCommands,
    },

    // ============================================================================
    // Sync Commands (shortcut to harvest sync)
    // ============================================================================
    /// Sync sessions between the harvest database and provider workspaces
    Sync {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Push sessions from database to provider workspaces (restore)
        #[arg(long)]
        push: bool,

        /// Pull sessions from provider workspaces into database (backup)
        #[arg(long)]
        pull: bool,

        /// Filter by provider name
        #[arg(long)]
        provider: Option<String>,

        /// Filter by workspace/project path
        #[arg(long)]
        workspace: Option<String>,

        /// Session IDs to sync (space-separated)
        #[arg(long, num_args = 1..)]
        sessions: Option<Vec<String>>,

        /// Target format for push: auto (detect from provider), jsonl, json
        #[arg(long, default_value = "auto")]
        format: String,

        /// Overwrite existing files without prompting
        #[arg(long)]
        force: bool,

        /// Dry run - show what would be synced without making changes
        #[arg(long)]
        dry_run: bool,
    },

    // ============================================================================
    // Harvest Commands
    // ============================================================================
    /// Harvest chat sessions from all providers into a unified database
    Harvest {
        #[command(subcommand)]
        command: HarvestCommands,
    },

    // ============================================================================
    // Recover Commands
    // ============================================================================
    /// Recover lost chat sessions from backups, recording state, or corrupted files
    #[command(visible_alias = "restore")]
    Recover {
        #[command(subcommand)]
        command: RecoverCommands,
    },

    // ============================================================================
    // API Server Commands
    // ============================================================================
    /// Start the HTTP API server for the web frontend
    #[command(visible_alias = "serve")]
    Api {
        #[command(subcommand)]
        command: ApiCommands,
    },

    // ============================================================================
    // Agency Commands
    // ============================================================================
    /// Agent Development Kit - manage agents and orchestration
    Agency {
        #[command(subcommand)]
        command: AgencyCommands,
    },

    // ============================================================================
    // Telemetry Commands
    // ============================================================================
    /// Manage anonymous usage data collection (opt-in by default)
    Telemetry {
        #[command(subcommand)]
        command: Option<TelemetryCommands>,
    },

    // ============================================================================
    // Completions Command
    // ============================================================================
    /// Generate shell completions for bash, zsh, fish, or PowerShell
    Completions {
        /// Shell to generate completions for
        #[arg(value_enum)]
        shell: CompletionShell,
    },

    // ============================================================================
    // Shard Commands
    // ============================================================================
    /// Split oversized sessions into linked shards (by request count or file size)
    Shard {
        #[command(subcommand)]
        command: ShardCommands,
    },

    // ============================================================================
    // Doctor Command
    // ============================================================================
    /// Check system environment, providers, and configuration health
    #[command(visible_alias = "check")]
    Doctor {
        /// Run all checks including network connectivity
        #[arg(long)]
        full: bool,

        /// Output format: text, json
        #[arg(long, default_value = "text")]
        format: String,

        /// Attempt to fix detected issues automatically
        #[arg(long)]
        fix: bool,
    },

    // ============================================================================
    // Inspect Commands
    // ============================================================================
    /// Inspect VS Code state databases, session indices, caches, and file validity
    Inspect {
        #[command(subcommand)]
        command: InspectCommands,
    },

    // ============================================================================
    // Schema Commands
    // ============================================================================
    /// Database schema registry, version detection, ontology, and cross-provider mappings
    ///
    /// Provides persistent schema definitions for every known AI chat provider format,
    /// an ontology for AI agent discovery, and backwards compatibility guarantees.
    Schema {
        #[command(subcommand)]
        command: SchemaCommands,
    },

    // ============================================================================
    // Internal Commands (hidden)
    // ============================================================================
    /// Internal commands used by chasm background processes
    #[command(hide = true)]
    Internal {
        #[command(subcommand)]
        command: InternalCommands,
    },

    // ============================================================================
    // Easter Egg
    // ============================================================================
    /// Show banner
    #[command(hide = true)]
    Banner,
}

// ============================================================================
// Internal Subcommands (hidden, used by background processes)
// ============================================================================

#[derive(Subcommand)]
pub enum InternalCommands {
    /// Re-apply a pending session registration after VS Code exits
    ApplyPending {
        /// Path to the pending registration JSON file
        pending_file: String,
    },
}

// ============================================================================
// List Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ListCommands {
    /// List all VS Code workspaces
    #[command(visible_alias = "ws")]
    Workspaces,

    /// List all chat sessions
    #[command(visible_alias = "s")]
    Sessions {
        /// Filter by project path
        #[arg(long)]
        project_path: Option<String>,

        /// Show file sizes
        #[arg(long, short = 's')]
        size: bool,

        /// Filter by provider (vscode, cursor, claudecode, opencode, openclaw, antigravity)
        #[arg(long, short = 'p')]
        provider: Option<String>,

        /// Include all providers
        #[arg(long)]
        all_providers: bool,
    },

    /// List available AI coding agents and their installation status
    #[command(visible_alias = "a")]
    Agents,

    /// List agent mode sessions (Copilot Edits / chatEditingSessions)
    #[command(visible_alias = "e")]
    Edits {
        /// Filter by project path
        #[arg(long)]
        project_path: Option<String>,

        /// Show file sizes
        #[arg(long, short = 's')]
        size: bool,

        /// Filter by provider (vscode, cursor, claudecode, opencode, openclaw, antigravity)
        #[arg(long, short = 'p')]
        provider: Option<String>,
    },

    /// List sessions for a specific project path
    Path {
        /// Project path (default: current directory)
        project_path: Option<String>,
    },

    /// List unregistered sessions (exist on disk but invisible to VS Code)
    Orphaned {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,
    },
}

// ============================================================================
// Find Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum FindCommands {
    /// Search workspaces by name pattern (defaults to current directory name)
    #[command(visible_alias = "ws")]
    Workspace {
        /// Text pattern to match (case-insensitive, defaults to current directory name)
        pattern: Option<String>,
    },

    /// Search sessions by title, content, or ID pattern
    #[command(visible_alias = "s")]
    Session {
        /// Text pattern to match (case-insensitive, defaults to current directory name)
        pattern: Option<String>,

        /// Filter by project path or workspace name
        #[arg(long, short = 'w')]
        workspace: Option<String>,

        /// Only search in session titles (faster, skip content search)
        #[arg(long, short = 't')]
        title_only: bool,

        /// Include message content in search (slower)
        #[arg(long, short = 'c')]
        content: bool,

        /// Filter sessions modified after this date (YYYY-MM-DD)
        #[arg(long)]
        after: Option<String>,

        /// Filter sessions modified before this date (YYYY-MM-DD)
        #[arg(long)]
        before: Option<String>,

        /// Filter by internal message timestamp date (YYYY-MM-DD)
        #[arg(long)]
        date: Option<String>,

        /// Search across all workspaces (not just current project)
        #[arg(long, short = 'a')]
        all: bool,

        /// Filter by provider (vscode, cursor, claudecode, opencode, openclaw, antigravity)
        #[arg(long, short = 'p')]
        provider: Option<String>,

        /// Search across all providers
        #[arg(long)]
        all_providers: bool,

        /// Limit number of results
        #[arg(long, short = 'n', default_value = "50")]
        limit: usize,
    },

    /// Search sessions within a specific project path
    Path {
        /// Search pattern (case-insensitive, defaults to current directory name)
        pattern: Option<String>,

        /// Project path (default: current directory)
        #[arg(long)]
        project_path: Option<String>,
    },
}

// ============================================================================
// Show Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ShowCommands {
    /// Show workspace details
    #[command(visible_alias = "ws")]
    Workspace {
        /// Workspace name or hash
        workspace: String,
    },

    /// Show session details
    #[command(visible_alias = "s")]
    Session {
        /// Session ID or filename
        session_id: String,

        /// Project path to search in
        #[arg(long)]
        project_path: Option<String>,
    },

    /// Show agent mode session details (Copilot Edits)
    #[command(visible_alias = "a")]
    Agent {
        /// Agent session ID
        session_id: String,

        /// Project path to search in
        #[arg(long)]
        project_path: Option<String>,
    },

    /// Show the VS Code session index (state.vscdb) for a workspace
    #[command(visible_alias = "idx")]
    Index {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Show indexes for all workspaces that have chat sessions
        #[arg(long, short)]
        all: bool,
    },

    /// Show chat history timeline for a project path
    Path {
        /// Path to the project (default: current directory)
        project_path: Option<String>,
    },

    /// Show timeline of session activity with gaps visualization
    Timeline {
        /// Path to the project (default: current directory)
        project_path: Option<String>,

        /// Include agent mode sessions
        #[arg(long, short = 'a')]
        agents: bool,

        /// Filter by provider (vscode, cursor, claudecode, opencode, openclaw, antigravity)
        #[arg(long, short = 'p')]
        provider: Option<String>,

        /// Include all providers (aggregate timeline)
        #[arg(long)]
        all_providers: bool,
    },
}

// ============================================================================
// Fetch Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum FetchCommands {
    /// Fetch sessions from workspaces matching a pattern
    #[command(visible_alias = "ws")]
    Workspace {
        /// Workspace name pattern (case-insensitive)
        workspace_name: String,

        /// Target project path (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Overwrite existing sessions
        #[arg(long)]
        force: bool,

        /// Don't register sessions in VS Code index
        #[arg(long)]
        no_register: bool,
    },

    /// Fetch specific sessions by ID
    #[command(visible_alias = "s")]
    Session {
        /// Session IDs to fetch (space-separated)
        #[arg(required = true, num_args = 1..)]
        session_ids: Vec<String>,

        /// Target project path (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Overwrite existing sessions
        #[arg(long)]
        force: bool,

        /// Don't register sessions in VS Code index
        #[arg(long)]
        no_register: bool,
    },

    /// Fetch chat sessions from other workspaces by project path
    Path {
        /// Path to the project (default: current directory)
        project_path: Option<String>,

        /// Overwrite existing sessions and skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't register sessions in VS Code index
        #[arg(long)]
        no_register: bool,
    },
}

// ============================================================================
// Merge Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum MergeCommands {
    /// Merge sessions from workspaces matching a name pattern
    #[command(visible_alias = "ws")]
    Workspace {
        /// Workspace name pattern to search for (case-insensitive)
        workspace_name: String,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge sessions from multiple workspace name patterns
    #[command(visible_alias = "wss")]
    Workspaces {
        /// Workspace name patterns to search for (space-separated, case-insensitive)
        #[arg(required = true, num_args = 1..)]
        workspace_names: Vec<String>,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge specific sessions by their IDs or filenames
    #[command(visible_alias = "s")]
    Sessions {
        /// Session IDs or filenames (comma-separated or space-separated)
        #[arg(required = true, num_args = 1..)]
        sessions: Vec<String>,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge all sessions for a project path into one unified chat
    Path {
        /// Path to the project (default: current directory)
        project_path: Option<String>,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge sessions from an LLM provider (Ollama, Cursor, etc.)
    Provider {
        /// Provider name (copilot, cursor, ollama, vllm, foundry, etc.)
        provider_name: String,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Session IDs from the provider to include (omit for all)
        #[arg(long)]
        sessions: Option<Vec<String>>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge sessions from multiple providers
    #[command(name = "providers")]
    Providers {
        /// Provider names (space-separated: copilot cursor ollama)
        #[arg(required = true, num_args = 1..)]
        providers: Vec<String>,

        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Filter by workspace name pattern (applies to providers that support workspaces)
        #[arg(long)]
        workspace: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },

    /// Merge all sessions across all available providers
    All {
        /// Title for the merged session
        #[arg(short, long)]
        title: Option<String>,

        /// Target project path to save the merged session (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Filter by workspace name pattern (applies to providers that support workspaces)
        #[arg(long)]
        workspace: Option<String>,

        /// Skip VS Code running check
        #[arg(long)]
        force: bool,

        /// Don't create backup of current sessions
        #[arg(long)]
        no_backup: bool,
    },
}

// ============================================================================
// Export Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ExportCommands {
    /// Export sessions from a workspace by hash
    #[command(visible_alias = "ws")]
    Workspace {
        /// Destination directory for exported sessions
        destination: String,

        /// Source workspace hash
        hash: String,
    },

    /// Export specific sessions by ID
    #[command(visible_alias = "s")]
    Sessions {
        /// Destination directory for exported sessions
        destination: String,

        /// Session IDs to export (space-separated)
        #[arg(required = true, num_args = 1..)]
        session_ids: Vec<String>,

        /// Source project path
        #[arg(long)]
        project_path: Option<String>,
    },

    /// Export chat sessions from a project path
    Path {
        /// Destination directory for exported sessions
        destination: String,

        /// Source project path (default: current directory)
        project_path: Option<String>,
    },

    /// Export chat sessions from multiple project paths (batch operation)
    Batch {
        /// Base destination directory (subdirectories created per project)
        destination: String,

        /// Project paths to export (space-separated)
        #[arg(required = true, num_args = 1..)]
        project_paths: Vec<String>,
    },
}

// ============================================================================
// Import Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ImportCommands {
    /// Copy session files from external directory into a workspace
    #[command(visible_alias = "ws")]
    Workspace {
        /// Source directory containing session JSON files to import
        source: String,

        /// Target workspace hash
        hash: String,

        /// Overwrite existing sessions
        #[arg(long)]
        force: bool,
    },

    /// Copy specific session files into a workspace
    #[command(visible_alias = "s")]
    Sessions {
        /// Session files to import (space-separated paths)
        #[arg(required = true, num_args = 1..)]
        session_files: Vec<String>,

        /// Target project path (default: current directory)
        #[arg(long)]
        target_path: Option<String>,

        /// Overwrite existing sessions
        #[arg(long)]
        force: bool,
    },

    /// Copy session files from external directory into a project workspace
    Path {
        /// Source directory containing session JSON files to import
        source: String,

        /// Target project path (default: current directory)
        target_path: Option<String>,

        /// Overwrite existing sessions
        #[arg(long)]
        force: bool,
    },
}

// ============================================================================
// Move Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum MoveCommands {
    /// Move all sessions from one workspace to another
    #[command(visible_alias = "ws")]
    Workspace {
        /// Source workspace hash
        source_hash: String,

        /// Target workspace hash or project path
        target: String,
    },

    /// Move specific sessions by ID
    #[command(visible_alias = "s")]
    Sessions {
        /// Session IDs to move (space-separated)
        #[arg(required = true, num_args = 1..)]
        session_ids: Vec<String>,

        /// Target project path
        target_path: String,
    },

    /// Move sessions from a source path to target path
    Path {
        /// Source project path
        source_path: String,

        /// Target project path
        target_path: String,
    },
}

// ============================================================================
// Git Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum GitCommands {
    /// Configure git settings for chat sessions
    Config {
        /// Git user name
        #[arg(long)]
        name: Option<String>,

        /// Git user email
        #[arg(long)]
        email: Option<String>,

        /// Project path
        #[arg(long)]
        path: Option<String>,
    },

    /// Initialize git versioning for chat sessions
    Init {
        /// Project path
        path: String,
    },

    /// Add chat sessions to git (stage and optionally commit)
    Add {
        /// Project path
        path: String,

        /// Also commit the changes
        #[arg(long)]
        commit: bool,

        /// Commit message (requires --commit)
        #[arg(short, long)]
        message: Option<String>,
    },

    /// Show git status of chat sessions
    Status {
        /// Project path
        path: String,
    },

    /// Create a git tag snapshot of chat sessions
    Snapshot {
        /// Project path
        path: String,

        /// Tag name (auto-generated if not provided)
        #[arg(long)]
        tag: Option<String>,

        /// Snapshot message
        #[arg(short, long)]
        message: Option<String>,
    },

    /// Track chat sessions together with associated file changes
    Track {
        /// Project path
        path: String,

        /// Commit message describing the changes
        #[arg(short, long)]
        message: Option<String>,

        /// Include all staged and unstaged file changes
        #[arg(long)]
        all: bool,

        /// Include specific files in addition to chat sessions
        #[arg(long)]
        files: Option<Vec<String>>,

        /// Create a tag for this tracked state
        #[arg(long)]
        tag: Option<String>,
    },

    /// Show history of chat session commits with associated file changes
    Log {
        /// Project path
        path: String,

        /// Number of commits to show
        #[arg(short = 'n', long, default_value = "10")]
        count: usize,

        /// Show only commits that include chat session changes
        #[arg(long)]
        sessions_only: bool,
    },

    /// Diff chat sessions between commits or current state
    Diff {
        /// Project path
        path: String,

        /// First commit (default: HEAD)
        #[arg(long)]
        from: Option<String>,

        /// Second commit (default: working directory)
        #[arg(long)]
        to: Option<String>,

        /// Show associated file changes alongside chat diffs
        #[arg(long)]
        with_files: bool,
    },

    /// Restore chat sessions from a specific commit
    Restore {
        /// Project path
        path: String,

        /// Commit hash, tag, or reference to restore from
        commit: String,

        /// Also restore associated files from the same commit
        #[arg(long)]
        with_files: bool,

        /// Create a backup before restoring
        #[arg(long)]
        backup: bool,
    },
}

// ============================================================================
// Migration Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum MigrationCommands {
    /// Create a migration package for moving to a new machine
    Create {
        /// Output directory for migration package
        output: String,

        /// Comma-separated list of project paths to include
        #[arg(long)]
        projects: Option<String>,

        /// Include all workspaces with chat sessions
        #[arg(long)]
        all: bool,
    },

    /// Restore a migration package on a new machine
    Restore {
        /// Path to migration package directory
        package: String,

        /// Project path mapping: 'old1:new1;old2:new2'
        #[arg(long)]
        mapping: Option<String>,

        /// Show what would be done without doing it
        #[arg(long)]
        dry_run: bool,
    },
}

// ============================================================================
// Run Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum RunCommands {
    /// Launch interactive TUI (Text User Interface)
    Tui,

    /// Launch Claude Code with auto-save
    #[command(visible_aliases = ["claude-code", "claudecode"])]
    Claude {
        /// Extra arguments to pass to the agent
        #[arg(last = true)]
        args: Vec<String>,
        /// Disable auto-save
        #[arg(long)]
        no_save: bool,
        /// Verbose output
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch OpenCode with auto-save
    #[command(visible_aliases = ["opencode", "open-code"])]
    Open {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch OpenClaw (ClawdBot) with auto-save
    #[command(visible_aliases = ["openclaw", "clawdbot"])]
    Claw {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch Cursor CLI with auto-save
    Cursor {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch Codex CLI (OpenAI) with auto-save
    #[command(visible_aliases = ["codex-cli", "codexcli"])]
    Codex {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch Droid CLI (Factory) with auto-save
    #[command(visible_aliases = ["droid-cli", "droidcli", "factory"])]
    Droid {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },

    /// Launch Gemini CLI (Google) with auto-save
    #[command(visible_aliases = ["gemini-cli", "geminicli"])]
    Gemini {
        #[arg(last = true)]
        args: Vec<String>,
        #[arg(long)]
        no_save: bool,
        #[arg(short, long)]
        verbose: bool,
    },
}

// ============================================================================
// Provider Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ProviderCommands {
    /// List all discovered LLM providers
    List,

    /// Show detailed info about a specific provider
    Info {
        /// Provider name (copilot, cursor, ollama, vllm, foundry, lm-studio, etc.)
        provider: String,
    },

    /// Configure a provider
    Config {
        /// Provider name
        provider: String,

        /// API endpoint URL
        #[arg(long)]
        endpoint: Option<String>,

        /// API key
        #[arg(long)]
        api_key: Option<String>,

        /// Default model
        #[arg(long)]
        model: Option<String>,

        /// Enable or disable the provider
        #[arg(long)]
        enabled: Option<bool>,
    },

    /// Import sessions from another provider
    Import {
        /// Source provider name
        #[arg(long)]
        from: String,

        /// Target project path (or current directory)
        #[arg(long)]
        path: Option<String>,

        /// Session ID to import (omit for all)
        #[arg(long)]
        session: Option<String>,
    },

    /// Test connection to a provider
    Test {
        /// Provider name
        provider: String,
    },
}

// ============================================================================
// Detect Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum DetectCommands {
    /// Detect workspace for a path
    Workspace {
        /// Project path (default: current directory)
        path: Option<String>,
    },

    /// Detect available providers
    Providers {
        /// Only show providers with sessions
        #[arg(long)]
        with_sessions: bool,
    },

    /// Detect which provider a session belongs to
    Session {
        /// Session ID or filename
        session_id: String,

        /// Project path to search in
        #[arg(long)]
        path: Option<String>,
    },

    /// Detect everything (workspace, providers, sessions) for a path
    All {
        /// Project path (default: current directory)
        path: Option<String>,

        /// Show detailed information
        #[arg(long)]
        verbose: bool,
    },

    /// Find all workspace hashes for a project path (including orphaned workspaces with sessions)
    Orphaned {
        /// Project path (default: current directory)
        path: Option<String>,

        /// Automatically recover orphaned sessions by copying to active workspace
        #[arg(long, short)]
        recover: bool,
    },
}

// ============================================================================
// Register Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum RegisterCommands {
    /// Register all on-disk sessions into VS Code's index (fixes orphaned sessions)
    All {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Merge all sessions into one before registering
        #[arg(long, short)]
        merge: bool,

        /// Force registration (from external terminal: close/reopen VS Code without prompt;
        /// from VS Code terminal: write to DB with background watchdog to survive shutdown)
        #[arg(long, short)]
        force: bool,

        /// Close VS Code before registering (ensures index is not overwritten by cache)
        #[arg(long)]
        close_vscode: bool,

        /// Reopen VS Code after registering (implies --close-vscode)
        #[arg(long)]
        reopen: bool,

        /// Write directly to DB without closing VS Code. A background watchdog
        /// re-applies the index after VS Code exits to survive the shutdown cache flush.
        #[arg(long, short = 'w')]
        write_only: bool,
    },

    /// Register specific sessions by ID or title into VS Code's index
    #[command(visible_alias = "s")]
    Session {
        /// Session IDs or filenames (without .json extension)
        #[arg(required_unless_present = "title")]
        ids: Vec<String>,

        /// Match sessions by title instead of ID
        #[arg(long, short, num_args = 1.., value_delimiter = ' ')]
        title: Option<Vec<String>>,

        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Force registration even if VS Code is running
        #[arg(long, short)]
        force: bool,
    },

    /// Recursively walk directories to find and register orphaned sessions for all workspaces
    #[command(visible_alias = "r")]
    Recursive {
        /// Root path to start recursive search (default: current directory)
        path: Option<String>,

        /// Maximum directory depth to recurse (default: unlimited)
        #[arg(long, short)]
        depth: Option<usize>,

        /// Force registration even if VS Code is running
        #[arg(long, short)]
        force: bool,

        /// Only show what would be registered without making changes
        #[arg(long)]
        dry_run: bool,

        /// Skip directories matching these patterns (can be used multiple times)
        #[arg(long, short = 'x')]
        exclude: Vec<String>,
    },

    /// Repair sessions: compact large JSONL files and rebuild the index with correct metadata
    #[command(visible_alias = "fix")]
    Repair {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Repair all workspaces that have chat sessions
        #[arg(long, short)]
        all: bool,

        /// Recursively scan a directory tree for workspaces and repair all discovered sessions
        #[arg(long, short)]
        recursive: bool,

        /// Maximum directory depth when using --recursive (default: unlimited)
        #[arg(long, short)]
        depth: Option<usize>,

        /// Skip directories matching these patterns when using --recursive
        #[arg(long, short = 'x')]
        exclude: Vec<String>,

        /// Only show what would be repaired without making changes
        #[arg(long)]
        dry_run: bool,

        /// Force even if VS Code is running
        #[arg(long, short)]
        force: bool,

        /// Close VS Code before repairing (ensures index is not overwritten)
        #[arg(long)]
        close_vscode: bool,

        /// Reopen VS Code after repairing (implies --close-vscode)
        #[arg(long)]
        reopen: bool,
    },

    /// Trim oversized sessions by keeping only the most recent requests
    #[command(visible_alias = "t")]
    Trim {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Number of recent requests to keep (default: 20)
        #[arg(long, short, default_value = "20")]
        keep: usize,

        /// Session ID to trim (default: largest session)
        #[arg(long, short)]
        session: Option<String>,

        /// Trim all sessions over the size threshold
        #[arg(long, short)]
        all: bool,

        /// Only trim sessions larger than this size in MB (default: 10)
        #[arg(long, default_value = "10")]
        threshold_mb: u64,

        /// Force even if VS Code is running
        #[arg(long, short)]
        force: bool,
    },
}

// ============================================================================
// Harvest Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum HarvestCommands {
    /// Initialize a harvest database
    Init {
        /// Path to the database file (default: ./chat_sessions.db)
        #[arg(long)]
        path: Option<String>,

        /// Initialize git tracking for the database
        #[arg(long)]
        git: bool,
    },

    /// Scan for available providers and sessions
    Scan {
        /// Show individual sessions
        #[arg(long)]
        sessions: bool,

        /// Scan for web-based LLM providers (ChatGPT, Claude, etc.)
        #[arg(long)]
        web: bool,

        /// Timeout in seconds for web provider checks (default: 5)
        #[arg(long, default_value = "5")]
        timeout: u64,

        /// Show verbose debug output for browser scanning
        #[arg(long, short)]
        verbose: bool,
    },

    /// Run the harvest to collect sessions from all providers
    Run {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Only include specific providers (comma-separated: copilot,cursor,ollama)
        #[arg(long, value_delimiter = ',')]
        providers: Option<Vec<String>>,

        /// Exclude specific providers (comma-separated)
        #[arg(long, value_delimiter = ',')]
        exclude: Option<Vec<String>>,

        /// Only harvest sessions changed since last run
        #[arg(long)]
        incremental: bool,

        /// Auto-commit changes to git after harvest
        #[arg(long)]
        commit: bool,

        /// Commit message (requires --commit)
        #[arg(short, long)]
        message: Option<String>,
    },

    /// Show harvest database status
    Status {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },

    /// List sessions in the harvest database
    List {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Filter by provider name
        #[arg(long)]
        provider: Option<String>,

        /// Maximum number of sessions to show
        #[arg(long, default_value = "20")]
        limit: usize,

        /// Search sessions by title or ID
        #[arg(long)]
        search: Option<String>,
    },

    /// Export sessions from the harvest database
    Export {
        /// Output file path
        output: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Export format: json, jsonl, md (markdown)
        #[arg(long, default_value = "json")]
        format: String,

        /// Filter by provider name
        #[arg(long)]
        provider: Option<String>,

        /// Export specific sessions by ID (comma-separated)
        #[arg(long, value_delimiter = ',')]
        sessions: Option<Vec<String>>,
    },

    /// Import a shared chat session from a URL
    Share {
        /// Share link URL (ChatGPT, Claude, etc.)
        url: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Custom name for the imported session
        #[arg(long)]
        name: Option<String>,

        /// Associate with a workspace path
        #[arg(long)]
        workspace: Option<String>,
    },

    /// List pending or imported share links
    Shares {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Filter by status: pending, imported, failed, expired
        #[arg(long)]
        status: Option<String>,

        /// Maximum number of links to show
        #[arg(long, default_value = "20")]
        limit: usize,
    },

    /// Create a checkpoint (version snapshot) of a session
    Checkpoint {
        /// Session ID to checkpoint
        session: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Checkpoint description message
        #[arg(short, long)]
        message: Option<String>,
    },

    /// List checkpoints for a session
    Checkpoints {
        /// Session ID to list checkpoints for
        session: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },

    /// Revert a session to a previous checkpoint
    Revert {
        /// Session ID to revert
        session: String,

        /// Checkpoint number to revert to
        checkpoint: i64,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },

    /// Sync sessions between the harvest database and provider workspaces
    Sync {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Push sessions from database to provider workspaces (restore)
        #[arg(long)]
        push: bool,

        /// Pull sessions from provider workspaces into database (backup)
        #[arg(long)]
        pull: bool,

        /// Filter by provider name
        #[arg(long)]
        provider: Option<String>,

        /// Filter by workspace/project path
        #[arg(long)]
        workspace: Option<String>,

        /// Session IDs to sync (space-separated)
        #[arg(long, num_args = 1..)]
        sessions: Option<Vec<String>>,

        /// Target format for push: auto (detect from provider), jsonl, json
        #[arg(long, default_value = "auto")]
        format: String,

        /// Overwrite existing files without prompting
        #[arg(long)]
        force: bool,

        /// Dry run - show what would be synced without making changes
        #[arg(long)]
        dry_run: bool,
    },

    /// Compact the database by stripping session_json blobs (data preserved in messages_v2)
    #[command(visible_alias = "gc")]
    Compact {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Show what would be compacted without making changes
        #[arg(long)]
        dry_run: bool,
    },

    /// Rebuild the full-text search index
    Rebuild {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },

    /// Search messages across all sessions (full-text search)
    Search {
        /// Search query
        query: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Filter by provider
        #[arg(long)]
        provider: Option<String>,

        /// Maximum results to show
        #[arg(long, default_value = "20")]
        limit: usize,
    },

    /// Git operations for the harvest database
    Git {
        #[command(subcommand)]
        command: HarvestGitCommands,
    },
}

#[derive(Subcommand)]
pub enum HarvestGitCommands {
    /// Initialize git tracking for the harvest database
    Init {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },

    /// Commit changes to the harvest database
    Commit {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Commit message
        #[arg(short, long)]
        message: Option<String>,
    },

    /// Show git log for the harvest database
    Log {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Number of commits to show
        #[arg(short = 'n', long, default_value = "10")]
        count: usize,
    },

    /// Show changes to the harvest database
    Diff {
        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,

        /// Compare against specific commit
        #[arg(long)]
        commit: Option<String>,
    },

    /// Restore harvest database from a commit
    Restore {
        /// Commit hash to restore from
        commit: String,

        /// Path to the harvest database
        #[arg(long)]
        path: Option<String>,
    },
}

// ============================================================================
// Recover Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum RecoverCommands {
    /// Scan for recoverable sessions from various sources
    Scan {
        /// Provider to scan: vscode, cursor, all (default: all)
        #[arg(long, default_value = "all")]
        provider: String,

        /// Show detailed information about each session
        #[arg(short, long)]
        verbose: bool,

        /// Include sessions older than normal retention period
        #[arg(long)]
        include_old: bool,
    },

    /// Recover sessions from the recording API server
    Recording {
        /// Server URL (default: http://localhost:8787)
        #[arg(long, default_value = "http://localhost:8787")]
        server: String,

        /// Only recover specific session ID
        #[arg(long)]
        session: Option<String>,

        /// Output directory for recovered sessions
        #[arg(short, long)]
        output: Option<String>,
    },

    /// Recover sessions from SQLite database backups
    Database {
        /// Path to the database backup file
        backup: String,

        /// Extract specific session by ID
        #[arg(long)]
        session: Option<String>,

        /// Output directory for recovered sessions
        #[arg(short, long)]
        output: Option<String>,

        /// Output format: json, jsonl, md (default: json)
        #[arg(long, default_value = "json")]
        format: String,
    },

    /// Recover sessions from incomplete/corrupted JSONL files
    Jsonl {
        /// Path to the JSONL file to repair
        file: String,

        /// Output file for recovered sessions (default: same name with .recovered suffix)
        #[arg(short, long)]
        output: Option<String>,

        /// Attempt aggressive recovery (may produce incomplete sessions)
        #[arg(long)]
        aggressive: bool,
    },

    /// List sessions from VS Code's workspaceStorage that may be orphaned
    Orphans {
        /// Provider to check: vscode, cursor, all (default: all)
        #[arg(long, default_value = "all")]
        provider: String,

        /// Show sessions not in the SQLite state database
        #[arg(long)]
        unindexed: bool,

        /// Check if files actually exist on disk
        #[arg(long)]
        verify: bool,
    },

    /// Repair corrupted session files in place
    Repair {
        /// Path to the session directory or file
        path: String,

        /// Create backup before repair
        #[arg(long, default_value = "true")]
        backup: bool,

        /// Dry run - show what would be repaired without making changes
        #[arg(long)]
        dry_run: bool,
    },

    /// Show recovery status and recommendations
    Status {
        /// Provider to check: vscode, cursor, all (default: all)
        #[arg(long, default_value = "all")]
        provider: String,

        /// Check disk space and file system health
        #[arg(long)]
        system: bool,
    },

    /// Convert session files between JSON and JSONL formats
    Convert {
        /// Input file to convert (.json or .jsonl)
        input: String,

        /// Output file (auto-detects format from extension, or uses --format)
        #[arg(short, long)]
        output: Option<String>,

        /// Output format: json, jsonl (default: opposite of input)
        #[arg(long)]
        format: Option<String>,

        /// VS Code version compatibility: legacy (< 1.109), modern (>= 1.109), both
        #[arg(long, default_value = "both")]
        compat: String,
    },

    /// Extract sessions from a VS Code workspace by project path
    Extract {
        /// Project directory path (will find corresponding workspace hash)
        path: String,

        /// Output directory for extracted sessions
        #[arg(short, long)]
        output: Option<String>,

        /// Include both JSON and JSONL formats if available
        #[arg(long)]
        all_formats: bool,

        /// Include editing session fragments (agent mode work)
        #[arg(long)]
        include_edits: bool,
    },

    /// Detect and display session format and version information
    Detect {
        /// Session file to analyze (.json or .jsonl)
        file: String,

        /// Show raw format detection details
        #[arg(long)]
        verbose: bool,

        /// Output detection result as JSON
        #[arg(long)]
        json: bool,
    },

    /// Upgrade session files to the current provider format (JSON to JSONL for VS Code 1.109+)
    Upgrade {
        /// Project paths to upgrade (space-separated)
        #[arg(required = true, num_args = 1..)]
        project_paths: Vec<String>,

        /// Provider to use: vscode, cursor, auto (default: auto-detect)
        #[arg(long, default_value = "auto")]
        provider: String,

        /// Target format: jsonl (VS Code 1.109+), json (legacy). Default: jsonl
        #[arg(long, default_value = "jsonl")]
        target_format: String,

        /// Skip creating backup of original files
        #[arg(long)]
        no_backup: bool,

        /// Dry run - show what would be upgraded without making changes
        #[arg(long)]
        dry_run: bool,
    },

    /// Show Copilot Chat extension version info and compatibility analysis
    CopilotInfo {
        /// Path to session directory to scan for version info (default: auto-detect)
        #[arg(long)]
        session_dir: Option<String>,

        /// Output as JSON instead of human-readable table
        #[arg(long)]
        json: bool,
    },

    /// Restore truncated sessions from .jsonl.bak backup files across all workspaces
    #[command(visible_alias = "b")]
    Backups {
        /// Root path to scan (default: all VS Code workspaces)
        path: Option<String>,

        /// Only show what would be restored without making changes
        #[arg(long)]
        dry_run: bool,

        /// Force operation even if VS Code is running
        #[arg(long, short)]
        force: bool,
    },

    /// Recursively walk directories to find and recover orphaned sessions for all workspaces
    #[command(visible_alias = "r")]
    Recursive {
        /// Root path to start recursive search (default: current directory)
        path: Option<String>,

        /// Maximum directory depth to recurse (default: unlimited)
        #[arg(long, short)]
        depth: Option<usize>,

        /// Force registration even if VS Code is running
        #[arg(long, short)]
        force: bool,

        /// Only show what would be recovered without making changes
        #[arg(long)]
        dry_run: bool,

        /// Skip directories matching these patterns (can be used multiple times)
        #[arg(long, short = 'x')]
        exclude: Vec<String>,

        /// Also register recovered sessions in VS Code's index
        #[arg(long)]
        register: bool,
    },
}

// ============================================================================
// Shard Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ShardCommands {
    /// Shard a single session file into linked parts
    Session {
        /// Path to the session file (.json or .jsonl)
        file: String,

        /// Maximum requests per shard (default: 50). Mutually exclusive with --max-size
        #[arg(long, short = 'n')]
        max_requests: Option<usize>,

        /// Maximum file size per shard (e.g. "10MB", "500KB"). Mutually exclusive with --max-requests
        #[arg(long, short = 's')]
        max_size: Option<String>,

        /// Output directory for shard files (default: same directory as input)
        #[arg(long, short = 'o')]
        output: Option<String>,

        /// Update the VS Code session index after sharding
        #[arg(long)]
        update_index: bool,

        /// Workspace hash or project path (for --update-index; auto-detected from file path if omitted)
        #[arg(long, short = 'w')]
        workspace: Option<String>,

        /// Show what would be done without writing any files
        #[arg(long)]
        dry_run: bool,

        /// Skip creating a .oversized backup of the original file
        #[arg(long)]
        no_backup: bool,
    },

    /// Shard all oversized sessions in a workspace
    Workspace {
        /// Workspace hash or project path (default: current directory)
        #[arg(long, short = 'w')]
        workspace: Option<String>,

        /// Maximum requests per shard (default: 50). Mutually exclusive with --max-size
        #[arg(long, short = 'n')]
        max_requests: Option<usize>,

        /// Maximum file size per shard (e.g. "10MB", "500KB"). Mutually exclusive with --max-requests
        #[arg(long, short = 's')]
        max_size: Option<String>,

        /// Show what would be done without writing any files
        #[arg(long)]
        dry_run: bool,

        /// Skip creating .oversized backups of original files
        #[arg(long)]
        no_backup: bool,
    },

    /// Show shard metadata for a session file
    Info {
        /// Path to the session file (.json or .jsonl)
        file: String,
    },
}

// ============================================================================
// API Server Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum ApiCommands {
    /// Start the API server
    Serve {
        /// Host to bind to (default: 0.0.0.0 for all interfaces)
        #[arg(long, default_value = "0.0.0.0")]
        host: String,

        /// Port to listen on (default: 8787)
        #[arg(short, long, default_value = "8787")]
        port: u16,

        /// Path to the database file
        #[arg(long)]
        database: Option<String>,
    },
}

// ============================================================================
// Agency (Agent Development Kit) Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum AgencyCommands {
    /// List available agents and their roles
    List {
        /// Show detailed information
        #[arg(short, long)]
        verbose: bool,
    },

    /// Show agent information
    Info {
        /// Agent name or ID
        name: String,
    },

    /// List supported orchestration modes
    Modes,

    /// Run an agent with a prompt
    Run {
        /// Agent name to run
        #[arg(short, long, default_value = "assistant")]
        agent: String,

        /// Prompt or task for the agent
        prompt: String,

        /// Model to use (e.g., gemini-2.0-flash, gpt-4o)
        #[arg(short, long)]
        model: Option<String>,

        /// Orchestration mode (single, sequential, parallel, swarm)
        #[arg(long, default_value = "single")]
        orchestration: String,

        /// Enable verbose output
        #[arg(short, long)]
        verbose: bool,
    },

    /// Create a new agent configuration
    Create {
        /// Agent name
        name: String,

        /// Agent role (coordinator, researcher, coder, reviewer, executor, writer, tester, custom)
        #[arg(short, long, default_value = "custom")]
        role: String,

        /// System instruction for the agent
        #[arg(short, long)]
        instruction: Option<String>,

        /// Model to use
        #[arg(short, long)]
        model: Option<String>,
    },

    /// List available tools
    Tools,

    /// Show swarm templates
    Templates,
}

// ============================================================================
// Telemetry Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum TelemetryCommands {
    /// Show telemetry status and what data is collected
    #[command(visible_alias = "status")]
    Info,

    /// Enable anonymous usage data collection (this is the default)
    #[command(visible_alias = "enable")]
    OptIn,

    /// Disable anonymous usage data collection
    #[command(visible_alias = "disable")]
    OptOut,

    /// Reset telemetry ID (generates new anonymous identifier)
    Reset,

    /// Record structured data for later AI analysis
    #[command(visible_alias = "log")]
    Record {
        /// Event category (e.g., 'workflow', 'error', 'performance', 'usage')
        #[arg(short, long, default_value = "custom")]
        category: String,

        /// Event name or type
        #[arg(short, long)]
        event: String,

        /// JSON data payload (or use --kv for key=value pairs)
        #[arg(short, long)]
        data: Option<String>,

        /// Key-value pairs (can be repeated: -k foo=bar -k baz=123)
        #[arg(short = 'k', long = "kv", value_parser = parse_key_value)]
        kv: Vec<(String, String)>,

        /// Add tags for filtering (can be repeated: -t important -t session-123)
        #[arg(short, long)]
        tags: Vec<String>,

        /// Optional session or context ID to associate with
        #[arg(long)]
        context: Option<String>,

        /// Print recorded event details
        #[arg(short, long)]
        verbose: bool,
    },

    /// Show recorded telemetry data
    #[command(visible_alias = "logs")]
    Show {
        /// Filter by category
        #[arg(short, long)]
        category: Option<String>,

        /// Filter by event name
        #[arg(short, long)]
        event: Option<String>,

        /// Filter by tag
        #[arg(short, long)]
        tag: Option<String>,

        /// Maximum number of records to show
        #[arg(short = 'n', long, default_value = "20")]
        limit: usize,

        /// Output format: table, json, jsonl
        #[arg(short, long, default_value = "table")]
        format: String,

        /// Show records after this date (YYYY-MM-DD)
        #[arg(long)]
        after: Option<String>,

        /// Show records before this date (YYYY-MM-DD)
        #[arg(long)]
        before: Option<String>,
    },

    /// Export recorded data for AI analysis
    Export {
        /// Output file path
        output: String,

        /// Export format: json, jsonl, csv
        #[arg(short, long, default_value = "jsonl")]
        format: String,

        /// Filter by category
        #[arg(short, long)]
        category: Option<String>,

        /// Include installation metadata in export
        #[arg(long)]
        with_metadata: bool,
    },

    /// Clear recorded telemetry data
    Clear {
        /// Skip confirmation prompt
        #[arg(short, long)]
        force: bool,

        /// Only clear records older than N days
        #[arg(long)]
        older_than: Option<u32>,
    },

    /// Configure remote telemetry endpoint
    Config {
        /// Set the remote endpoint URL
        #[arg(long)]
        endpoint: Option<String>,

        /// Set the API key for authentication
        #[arg(long)]
        api_key: Option<String>,

        /// Enable remote telemetry sending
        #[arg(long)]
        enable_remote: bool,

        /// Disable remote telemetry sending
        #[arg(long)]
        disable_remote: bool,
    },

    /// Sync telemetry records to remote server
    Sync {
        /// Maximum number of records to sync
        #[arg(short = 'n', long)]
        limit: Option<usize>,

        /// Clear local records after successful sync
        #[arg(long)]
        clear_after: bool,
    },

    /// Test connection to remote telemetry server
    Test,
}

// ============================================================================
// Inspect Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum InspectCommands {
    /// Show the ChatSessionStore index entries from state.vscdb
    Index {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Show session memento (input history and active session state)
    Memento {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Show agentSessions model and state caches (drives sidebar visibility)
    Cache {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Validate session files on disk (format, size, parse, index consistency)
    Validate {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// List keys in state.vscdb with value sizes
    Keys {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Show ALL keys (not just session-related)
        #[arg(long, short)]
        all: bool,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// List all files in the chatSessions directory with format and size details
    Files {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Rebuild session index and model cache from session files on disk
    ///
    /// Scans the chatSessions directory, parses each file to extract metadata
    /// (title, timestamps, request count), then overwrites the index and
    /// rebuilds the agentSessions.model.cache so sessions appear in the Chat
    /// sidebar. Also cleans up the state cache and fixes the active-session
    /// memento.
    #[command(visible_alias = "fix")]
    Rebuild {
        /// Project path (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Only show what would change without writing (dry run)
        #[arg(long)]
        dry_run: bool,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
}

/// Parse key=value pairs for telemetry record command
fn parse_key_value(s: &str) -> std::result::Result<(String, String), String> {
    let pos = s
        .find('=')
        .ok_or_else(|| format!("invalid key=value pair: no '=' found in '{s}'"))?;
    Ok((s[..pos].to_string(), s[pos + 1..].to_string()))
}

// ============================================================================
// Schema Subcommands
// ============================================================================

#[derive(Subcommand)]
pub enum SchemaCommands {
    /// List all known provider schemas (session formats and DB key layouts)
    #[command(visible_alias = "ls")]
    List {
        /// Filter by provider name (e.g., copilot, cursor, claude-code)
        #[arg(long, short = 'p')]
        provider: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Show detailed schema for a specific version ID
    ///
    /// Example IDs: copilot-json-v3, copilot-jsonl-v1, cursor-jsonl-v1
    Show {
        /// Schema version ID (use `chasm schema list` to see available IDs)
        schema_id: String,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Auto-detect the schema version for a workspace or session file
    Detect {
        /// Path to a session file or workspace directory (default: current directory)
        #[arg(long)]
        path: Option<String>,

        /// Workspace storage hash (alternative to --path)
        #[arg(long, short = 'w')]
        workspace_id: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Export the full schema registry + ontology as JSON (for AI agent consumption)
    Export {
        /// Compact JSON output (single line)
        #[arg(long)]
        compact: bool,

        /// Write to file instead of stdout
        #[arg(long, short = 'o')]
        output: Option<String>,
    },

    /// Show the cross-provider ontology (entity types, relationships, semantic tags)
    Ontology {
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },

    /// Show cross-provider field mappings and transformation rules
    Mappings {
        /// Source schema ID (e.g., copilot-json-v3)
        #[arg(long, short = 's')]
        source: Option<String>,

        /// Target schema ID (e.g., copilot-jsonl-v1)
        #[arg(long, short = 't')]
        target: Option<String>,

        /// Filter mappings by semantic tag (e.g., session_id, message_content)
        #[arg(long)]
        tag: Option<String>,

        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
}

// ============================================================================
// Shell Completion Enum
// ============================================================================

/// Supported shells for completion generation
#[derive(Clone, Debug, clap::ValueEnum)]
pub enum CompletionShell {
    /// Bash shell
    Bash,
    /// Zsh shell
    Zsh,
    /// Fish shell
    Fish,
    /// PowerShell
    Powershell,
    /// Elvish shell
    Elvish,
}