Skip to main content

lean_ctx/cli/completions/
spec.rs

1//! Static command-tree specification for CLI completions.
2//!
3//! Every top-level command, its subcommands, flags and dynamic value kinds
4//! live here so the completion engine has a single source of truth.
5/// Describes a dynamic value set resolved at completion time.
6#[derive(Clone, Copy)]
7pub enum DynamicKind {
8    Agents,
9    Shells,
10    Modes,
11    ConfigKeys,
12    Profiles,
13    TerseLevel,
14}
15/// A flag/option accepted by a command.
16pub struct FlagSpec {
17    pub long: &'static str,
18    pub short: Option<char>,
19    pub description: &'static str,
20    pub takes_value: bool,
21    pub value_kind: Option<DynamicKind>,
22}
23/// A command or subcommand node in the tree.
24pub struct CommandNode {
25    pub name: &'static str,
26    pub aliases: &'static [&'static str],
27    pub description: &'static str,
28    pub subcommands: &'static [CommandNode],
29    pub flags: &'static [FlagSpec],
30    pub positional: Option<DynamicKind>,
31    pub hidden: bool,
32}
33pub static COMMAND_TREE: &[CommandNode] = &[
34    CommandNode {
35        name: "model",
36        aliases: &[],
37        description: "Install and manage local models",
38        subcommands: &[
39            CommandNode {
40                name: "install",
41                aliases: &[],
42                description: "Install a model",
43                subcommands: &[],
44                flags: &[],
45                positional: None,
46                hidden: false,
47            },
48            CommandNode {
49                name: "status",
50                aliases: &[],
51                description: "Show installed models",
52                subcommands: &[],
53                flags: &[],
54                positional: None,
55                hidden: false,
56            },
57            CommandNode {
58                name: "remove",
59                aliases: &[],
60                description: "Remove a model",
61                subcommands: &[],
62                flags: &[],
63                positional: None,
64                hidden: false,
65            },
66        ],
67        flags: &[],
68        positional: None,
69        hidden: false,
70    },
71    CommandNode {
72        name: "triage",
73        aliases: &[],
74        description: "Inspect semantic triage shadow accuracy",
75        subcommands: &[CommandNode {
76            name: "accuracy",
77            aliases: &[],
78            description: "Show semantic-shadow agreement report",
79            subcommands: &[],
80            flags: &[FlagSpec {
81                long: "--json",
82                short: None,
83                description: "JSON output",
84                takes_value: false,
85                value_kind: None,
86            }],
87            positional: None,
88            hidden: false,
89        }],
90        flags: &[],
91        positional: None,
92        hidden: false,
93    },
94    CommandNode {
95        name: "shell",
96        aliases: &[],
97        description: "Activate shell integration",
98        subcommands: &[],
99        flags: &[
100            FlagSpec {
101                long: "--agent",
102                short: Some('a'),
103                description: "Agent name",
104                takes_value: true,
105                value_kind: Some(DynamicKind::Agents),
106            },
107            FlagSpec {
108                long: "--mode",
109                short: Some('m'),
110                description: "Integration mode",
111                takes_value: true,
112                value_kind: Some(DynamicKind::Modes),
113            },
114        ],
115        positional: Some(DynamicKind::Shells),
116        hidden: false,
117    },
118    CommandNode {
119        name: "init",
120        aliases: &["setup", "onboard", "install", "bootstrap"],
121        description: "Initialize lean-ctx for an agent",
122        subcommands: &[],
123        flags: &[
124            FlagSpec {
125                long: "--agent",
126                short: Some('a'),
127                description: "Agent name",
128                takes_value: true,
129                value_kind: Some(DynamicKind::Agents),
130            },
131            FlagSpec {
132                long: "--mode",
133                short: Some('m'),
134                description: "Integration mode",
135                takes_value: true,
136                value_kind: Some(DynamicKind::Modes),
137            },
138            FlagSpec {
139                long: "--prompt",
140                short: None,
141                description: "Add the value segment to the shell prompt (`off` removes it)",
142                takes_value: false,
143                value_kind: None,
144            },
145            FlagSpec {
146                long: "--git-trailer",
147                short: None,
148                description: "Add a lean-ctx trailer to this repo's commits (`off` removes it)",
149                takes_value: false,
150                value_kind: None,
151            },
152        ],
153        positional: None,
154        hidden: false,
155    },
156    CommandNode {
157        name: "status",
158        aliases: &[],
159        description: "Show current status",
160        subcommands: &[],
161        flags: &[FlagSpec {
162            long: "--json",
163            short: None,
164            description: "JSON output",
165            takes_value: false,
166            value_kind: None,
167        }],
168        positional: None,
169        hidden: false,
170    },
171    CommandNode {
172        name: "config",
173        aliases: &[],
174        description: "Manage configuration",
175        subcommands: &[
176            CommandNode {
177                name: "get",
178                aliases: &[],
179                description: "Get a config value",
180                subcommands: &[],
181                flags: &[],
182                positional: Some(DynamicKind::ConfigKeys),
183                hidden: false,
184            },
185            CommandNode {
186                name: "set",
187                aliases: &[],
188                description: "Set a config value",
189                subcommands: &[],
190                flags: &[],
191                positional: Some(DynamicKind::ConfigKeys),
192                hidden: false,
193            },
194            CommandNode {
195                name: "edit",
196                aliases: &[],
197                description: "Open config in editor",
198                subcommands: &[],
199                flags: &[],
200                positional: None,
201                hidden: false,
202            },
203            CommandNode {
204                name: "show",
205                aliases: &[],
206                description: "Show current config",
207                subcommands: &[],
208                flags: &[FlagSpec {
209                    long: "--json",
210                    short: None,
211                    description: "JSON output",
212                    takes_value: false,
213                    value_kind: None,
214                }],
215                positional: None,
216                hidden: false,
217            },
218        ],
219        flags: &[],
220        positional: None,
221        hidden: false,
222    },
223    CommandNode {
224        name: "proxy",
225        aliases: &["serve"],
226        description: "Start the proxy server",
227        subcommands: &[
228            CommandNode {
229                name: "start",
230                aliases: &[],
231                description: "Start proxy",
232                subcommands: &[],
233                flags: &[
234                    FlagSpec {
235                        long: "--detach",
236                        short: Some('d'),
237                        description: "Run in background",
238                        takes_value: false,
239                        value_kind: None,
240                    },
241                    FlagSpec {
242                        long: "--port",
243                        short: Some('p'),
244                        description: "Port number",
245                        takes_value: true,
246                        value_kind: None,
247                    },
248                ],
249                positional: None,
250                hidden: false,
251            },
252            CommandNode {
253                name: "stop",
254                aliases: &[],
255                description: "Stop proxy",
256                subcommands: &[],
257                flags: &[],
258                positional: None,
259                hidden: false,
260            },
261        ],
262        flags: &[
263            FlagSpec {
264                long: "--port",
265                short: Some('p'),
266                description: "Port number",
267                takes_value: true,
268                value_kind: None,
269            },
270            FlagSpec {
271                long: "--detach",
272                short: Some('d'),
273                description: "Run in background",
274                takes_value: false,
275                value_kind: None,
276            },
277        ],
278        positional: None,
279        hidden: false,
280    },
281    CommandNode {
282        name: "dashboard",
283        aliases: &[],
284        description: "Open the dashboard",
285        subcommands: &[],
286        flags: &[FlagSpec {
287            long: "--port",
288            short: Some('p'),
289            description: "Port number",
290            takes_value: true,
291            value_kind: None,
292        }],
293        positional: None,
294        hidden: false,
295    },
296    CommandNode {
297        name: "cache",
298        aliases: &[],
299        description: "Manage the cache",
300        subcommands: &[
301            CommandNode {
302                name: "stats",
303                aliases: &[],
304                description: "Cache statistics",
305                subcommands: &[],
306                flags: &[],
307                positional: None,
308                hidden: false,
309            },
310            CommandNode {
311                name: "clear",
312                aliases: &[],
313                description: "Clear cache",
314                subcommands: &[],
315                flags: &[],
316                positional: None,
317                hidden: false,
318            },
319            CommandNode {
320                name: "export",
321                aliases: &[],
322                description: "Export cache",
323                subcommands: &[],
324                flags: &[],
325                positional: None,
326                hidden: false,
327            },
328        ],
329        flags: &[],
330        positional: None,
331        hidden: false,
332    },
333    CommandNode {
334        name: "terse",
335        aliases: &["compression"],
336        description: "Set compression level",
337        subcommands: &[],
338        flags: &[],
339        positional: Some(DynamicKind::TerseLevel),
340        hidden: false,
341    },
342    CommandNode {
343        name: "profile",
344        aliases: &[],
345        description: "Manage local context configuration profiles",
346        subcommands: &[],
347        flags: &[],
348        positional: Some(DynamicKind::Profiles),
349        hidden: false,
350    },
351    CommandNode {
352        name: "gain",
353        aliases: &[],
354        description: "Show local context-usage estimates",
355        subcommands: &[],
356        flags: &[
357            FlagSpec {
358                long: "--json",
359                short: None,
360                description: "JSON output",
361                takes_value: false,
362                value_kind: None,
363            },
364            FlagSpec {
365                long: "--by-tool",
366                short: None,
367                description: "Per-tool local context breakdown",
368                takes_value: false,
369                value_kind: None,
370            },
371        ],
372        positional: None,
373        hidden: false,
374    },
375    CommandNode {
376        name: "spend",
377        aliases: &["billing", "finops", "roi"],
378        description: "Show cost report",
379        subcommands: &[],
380        flags: &[FlagSpec {
381            long: "--json",
382            short: None,
383            description: "JSON output",
384            takes_value: false,
385            value_kind: None,
386        }],
387        positional: None,
388        hidden: false,
389    },
390    CommandNode {
391        name: "index",
392        aliases: &[],
393        description: "Build or rebuild search index",
394        subcommands: &[],
395        flags: &[FlagSpec {
396            long: "--force",
397            short: Some('f'),
398            description: "Force rebuild",
399            takes_value: false,
400            value_kind: None,
401        }],
402        positional: None,
403        hidden: false,
404    },
405    CommandNode {
406        name: "explore",
407        aliases: &["repomap", "repo-map"],
408        description: "Explore repository structure",
409        subcommands: &[],
410        flags: &[
411            FlagSpec {
412                long: "--depth",
413                short: Some('d'),
414                description: "Max depth",
415                takes_value: true,
416                value_kind: None,
417            },
418            FlagSpec {
419                long: "--json",
420                short: None,
421                description: "JSON output",
422                takes_value: false,
423                value_kind: None,
424            },
425        ],
426        positional: None,
427        hidden: false,
428    },
429    CommandNode {
430        name: "compress",
431        aliases: &["compact"],
432        description: "Compress input",
433        subcommands: &[],
434        flags: &[],
435        positional: None,
436        hidden: false,
437    },
438    CommandNode {
439        name: "update",
440        aliases: &["upgrade"],
441        description: "Update lean-ctx",
442        subcommands: &[],
443        flags: &[
444            FlagSpec {
445                long: "--check",
446                short: None,
447                description: "Check only, don't install",
448                takes_value: false,
449                value_kind: None,
450            },
451            FlagSpec {
452                long: "--pin",
453                short: None,
454                description: "Persist a release version pin",
455                takes_value: true,
456                value_kind: None,
457            },
458            FlagSpec {
459                long: "--unpin",
460                short: None,
461                description: "Clear the persistent release pin",
462                takes_value: false,
463                value_kind: None,
464            },
465            FlagSpec {
466                long: "--status",
467                short: None,
468                description: "Show active and retained binary receipt",
469                takes_value: false,
470                value_kind: None,
471            },
472            FlagSpec {
473                long: "--rollback",
474                short: None,
475                description: "Restore the retained verified binary",
476                takes_value: false,
477                value_kind: None,
478            },
479        ],
480        positional: None,
481        hidden: false,
482    },
483    CommandNode {
484        name: "stop",
485        aliases: &[],
486        description: "Stop all lean-ctx processes",
487        subcommands: &[],
488        flags: &[],
489        positional: None,
490        hidden: false,
491    },
492    CommandNode {
493        name: "restart",
494        aliases: &[],
495        description: "Restart lean-ctx",
496        subcommands: &[],
497        flags: &[],
498        positional: None,
499        hidden: false,
500    },
501    CommandNode {
502        name: "dev-install",
503        aliases: &[],
504        description: "Development install (stop+build+install+restart)",
505        subcommands: &[],
506        flags: &[],
507        positional: None,
508        hidden: false,
509    },
510    CommandNode {
511        name: "wrap",
512        aliases: &[],
513        description: "One-command setup for an agent",
514        subcommands: &[],
515        flags: &[],
516        positional: Some(DynamicKind::Agents),
517        hidden: false,
518    },
519    CommandNode {
520        name: "unwrap",
521        aliases: &[],
522        description: "Undo wrap, restore pre-wrap config",
523        subcommands: &[],
524        flags: &[],
525        positional: Some(DynamicKind::Agents),
526        hidden: false,
527    },
528    CommandNode {
529        name: "doctor",
530        aliases: &[],
531        description: "Diagnose installation issues",
532        subcommands: &[],
533        flags: &[],
534        positional: None,
535        hidden: false,
536    },
537    CommandNode {
538        name: "selftest",
539        aliases: &["health"],
540        description: "Run self-test",
541        subcommands: &[],
542        flags: &[],
543        positional: None,
544        hidden: false,
545    },
546    CommandNode {
547        name: "rules",
548        aliases: &[],
549        description: "Manage rules",
550        subcommands: &[],
551        flags: &[],
552        positional: None,
553        hidden: false,
554    },
555    CommandNode {
556        name: "export-rules",
557        aliases: &[],
558        description: "Export rules to file",
559        subcommands: &[],
560        flags: &[],
561        positional: None,
562        hidden: false,
563    },
564    CommandNode {
565        name: "harden",
566        aliases: &["security", "lockdown"],
567        description: "Harden security settings",
568        subcommands: &[],
569        flags: &[],
570        positional: None,
571        hidden: false,
572    },
573    CommandNode {
574        name: "completions",
575        aliases: &[],
576        description: "Generate shell completion script",
577        subcommands: &[],
578        flags: &[],
579        positional: Some(DynamicKind::Shells),
580        hidden: false,
581    },
582    CommandNode {
583        name: "gotchas",
584        aliases: &["bugs"],
585        description: "Show known gotchas",
586        subcommands: &[],
587        flags: &[],
588        positional: None,
589        hidden: false,
590    },
591    CommandNode {
592        name: "learn",
593        aliases: &[],
594        description: "Interactive learning",
595        subcommands: &[],
596        flags: &[],
597        positional: None,
598        hidden: false,
599    },
600    CommandNode {
601        name: "cloud",
602        aliases: &[],
603        description: "Research-only hosted development commands",
604        subcommands: &[],
605        flags: &[],
606        positional: None,
607        hidden: false,
608    },
609    CommandNode {
610        name: "help",
611        aliases: &[],
612        description: "Show help",
613        subcommands: &[],
614        flags: &[],
615        positional: None,
616        hidden: false,
617    },
618    CommandNode {
619        name: "eval",
620        aliases: &[],
621        description: "Evaluate compression quality",
622        subcommands: &[],
623        flags: &[],
624        positional: None,
625        hidden: false,
626    },
627    CommandNode {
628        name: "audit",
629        aliases: &["compliance"],
630        description: "Research-only local compliance artifact",
631        subcommands: &[],
632        flags: &[],
633        positional: None,
634        hidden: false,
635    },
636    CommandNode {
637        name: "agent",
638        aliases: &[],
639        description: "Manage agent integrations",
640        subcommands: &[],
641        flags: &[FlagSpec {
642            long: "--agent",
643            short: Some('a'),
644            description: "Agent name",
645            takes_value: true,
646            value_kind: Some(DynamicKind::Agents),
647        }],
648        positional: None,
649        hidden: false,
650    },
651    CommandNode {
652        name: "session",
653        aliases: &["sessions"],
654        description: "Manage sessions",
655        subcommands: &[],
656        flags: &[],
657        positional: None,
658        hidden: false,
659    },
660    CommandNode {
661        name: "knowledge",
662        aliases: &[],
663        description: "Manage knowledge base",
664        subcommands: &[],
665        flags: &[],
666        positional: None,
667        hidden: false,
668    },
669    CommandNode {
670        name: "stats",
671        aliases: &["introspect"],
672        description: "Show statistics",
673        subcommands: &[],
674        flags: &[FlagSpec {
675            long: "--json",
676            short: None,
677            description: "JSON output",
678            takes_value: false,
679            value_kind: None,
680        }],
681        positional: None,
682        hidden: false,
683    },
684    CommandNode {
685        name: "cheatsheet",
686        aliases: &[],
687        description: "Show cheatsheet",
688        subcommands: &[],
689        flags: &[],
690        positional: None,
691        hidden: false,
692    },
693    CommandNode {
694        name: "mcp",
695        aliases: &[],
696        description: "MCP server management",
697        subcommands: &[],
698        flags: &[],
699        positional: None,
700        hidden: false,
701    },
702    CommandNode {
703        name: "wrapped",
704        aliases: &[],
705        description: "Show wrapped summary",
706        subcommands: &[],
707        flags: &[],
708        positional: None,
709        hidden: false,
710    },
711    CommandNode {
712        name: "addon",
713        aliases: &["addons", "plugin", "plugins"],
714        description: "Unavailable: marketplace/addon surface is Research",
715        subcommands: &[
716            CommandNode {
717                name: "list",
718                aliases: &[],
719                description: "List addons",
720                subcommands: &[],
721                flags: &[],
722                positional: None,
723                hidden: false,
724            },
725            CommandNode {
726                name: "install",
727                aliases: &[],
728                description: "Install addon",
729                subcommands: &[],
730                flags: &[],
731                positional: None,
732                hidden: false,
733            },
734            CommandNode {
735                name: "remove",
736                aliases: &[],
737                description: "Remove addon",
738                subcommands: &[],
739                flags: &[],
740                positional: None,
741                hidden: false,
742            },
743            CommandNode {
744                name: "info",
745                aliases: &[],
746                description: "Addon info",
747                subcommands: &[],
748                flags: &[],
749                positional: None,
750                hidden: false,
751            },
752        ],
753        flags: &[],
754        positional: None,
755        hidden: true,
756    },
757    CommandNode {
758        name: "savings",
759        aliases: &[],
760        description: "Show local representation-change estimates",
761        subcommands: &[],
762        flags: &[
763            FlagSpec {
764                long: "--period",
765                short: None,
766                description: "Period: day, week, month, or all",
767                takes_value: true,
768                value_kind: None,
769            },
770            FlagSpec {
771                long: "--format",
772                short: None,
773                description: "Output: table, json, or markdown",
774                takes_value: true,
775                value_kind: None,
776            },
777        ],
778        positional: None,
779        hidden: false,
780    },
781    CommandNode {
782        name: "output-savings",
783        aliases: &["output_savings"],
784        description: "Local output-token estimate; not a workload benchmark",
785        subcommands: &[],
786        flags: &[FlagSpec {
787            long: "--json",
788            short: None,
789            description: "JSON output",
790            takes_value: false,
791            value_kind: None,
792        }],
793        positional: None,
794        hidden: false,
795    },
796    CommandNode {
797        name: "value-report",
798        aliases: &["value_report"],
799        description: "Show local Value Gate outcomes and cost",
800        subcommands: &[],
801        flags: &[
802            FlagSpec {
803                long: "--format",
804                short: None,
805                description: "Output: table, markdown, or json",
806                takes_value: true,
807                value_kind: None,
808            },
809            FlagSpec {
810                long: "--last",
811                short: None,
812                description: "Maximum assessments to include",
813                takes_value: true,
814                value_kind: None,
815            },
816            FlagSpec {
817                long: "--since",
818                short: None,
819                description: "Only assessments since YYYY-MM-DD",
820                takes_value: true,
821                value_kind: None,
822            },
823            FlagSpec {
824                long: "--live",
825                short: None,
826                description: "Read the live Value Gate store",
827                takes_value: false,
828                value_kind: None,
829            },
830        ],
831        positional: None,
832        hidden: false,
833    },
834    CommandNode {
835        name: "shadow",
836        aliases: &[],
837        description: "Inspect local Shadow Mode reports",
838        subcommands: &[],
839        flags: &[
840            FlagSpec {
841                long: "--latest",
842                short: None,
843                description: "Show the latest report",
844                takes_value: false,
845                value_kind: None,
846            },
847            FlagSpec {
848                long: "--list",
849                short: None,
850                description: "List recorded reports",
851                takes_value: false,
852                value_kind: None,
853            },
854            FlagSpec {
855                long: "--force",
856                short: None,
857                description: "Generate a fresh report",
858                takes_value: false,
859                value_kind: None,
860            },
861        ],
862        positional: None,
863        hidden: false,
864    },
865    CommandNode {
866        name: "scenario",
867        aliases: &[],
868        description: "Run Decision Loop scenarios",
869        subcommands: &[],
870        flags: &[FlagSpec {
871            long: "--format",
872            short: None,
873            description: "Output: text or json",
874            takes_value: true,
875            value_kind: None,
876        }],
877        positional: None,
878        hidden: false,
879    },
880    CommandNode {
881        name: "measure",
882        aliases: &[],
883        description: "Record and compare baseline versus lean-ctx treatment",
884        subcommands: &[
885            CommandNode {
886                name: "baseline-start",
887                aliases: &[],
888                description: "Start baseline recording",
889                subcommands: &[],
890                flags: &[],
891                positional: None,
892                hidden: false,
893            },
894            CommandNode {
895                name: "baseline-stop",
896                aliases: &[],
897                description: "Stop baseline recording",
898                subcommands: &[],
899                flags: &[],
900                positional: None,
901                hidden: false,
902            },
903            CommandNode {
904                name: "treatment-start",
905                aliases: &[],
906                description: "Start treatment recording",
907                subcommands: &[],
908                flags: &[],
909                positional: None,
910                hidden: false,
911            },
912            CommandNode {
913                name: "treatment-stop",
914                aliases: &[],
915                description: "Stop treatment recording",
916                subcommands: &[],
917                flags: &[],
918                positional: None,
919                hidden: false,
920            },
921            CommandNode {
922                name: "compare",
923                aliases: &[],
924                description: "Show side-by-side comparison",
925                subcommands: &[],
926                flags: &[],
927                positional: None,
928                hidden: false,
929            },
930            CommandNode {
931                name: "report",
932                aliases: &[],
933                description: "Generate customer-facing report",
934                subcommands: &[],
935                flags: &[FlagSpec {
936                    long: "--format",
937                    short: None,
938                    description: "Output: markdown or json",
939                    takes_value: true,
940                    value_kind: None,
941                }],
942                positional: None,
943                hidden: false,
944            },
945        ],
946        flags: &[],
947        positional: None,
948        hidden: false,
949    },
950    CommandNode {
951        name: "evidence-export",
952        aliases: &[],
953        description: "Export portable local evidence package",
954        subcommands: &[],
955        flags: &[
956            FlagSpec {
957                long: "--output",
958                short: None,
959                description: "Destination directory",
960                takes_value: true,
961                value_kind: None,
962            },
963            FlagSpec {
964                long: "--format",
965                short: None,
966                description: "Confirmation output: markdown or json",
967                takes_value: true,
968                value_kind: None,
969            },
970        ],
971        positional: None,
972        hidden: false,
973    },
974    CommandNode {
975        name: "prove",
976        aliases: &[],
977        description: "Generate Decision Loop evidence report",
978        subcommands: &[CommandNode {
979            name: "speed",
980            aliases: &[],
981            description: "Signed A/B proof: model latency with and without lean-ctx context",
982            subcommands: &[],
983            flags: &[
984                FlagSpec {
985                    long: "--suite",
986                    short: None,
987                    description: "Eval suite (lean-ctx eval init <dir>)",
988                    takes_value: true,
989                    value_kind: None,
990                },
991                FlagSpec {
992                    long: "--runs",
993                    short: None,
994                    description: "Timed runs per task and arm (default 3)",
995                    takes_value: true,
996                    value_kind: None,
997                },
998                FlagSpec {
999                    long: "--budget",
1000                    short: None,
1001                    description: "lean-ctx context budget in tokens",
1002                    takes_value: true,
1003                    value_kind: None,
1004                },
1005                FlagSpec {
1006                    long: "--out",
1007                    short: None,
1008                    description: "Write the signed proof to this file",
1009                    takes_value: true,
1010                    value_kind: None,
1011                },
1012                FlagSpec {
1013                    long: "--json",
1014                    short: None,
1015                    description: "Print the proof as JSON",
1016                    takes_value: false,
1017                    value_kind: None,
1018                },
1019                FlagSpec {
1020                    long: "--verify",
1021                    short: None,
1022                    description: "Verify a proof file (default: the latest)",
1023                    takes_value: false,
1024                    value_kind: None,
1025                },
1026            ],
1027            positional: None,
1028            hidden: false,
1029        }],
1030        flags: &[
1031            FlagSpec {
1032                long: "--format",
1033                short: None,
1034                description: "Output format: table, json, or markdown",
1035                takes_value: true,
1036                value_kind: None,
1037            },
1038            FlagSpec {
1039                long: "--output",
1040                short: None,
1041                description: "Write report to file",
1042                takes_value: true,
1043                value_kind: None,
1044            },
1045        ],
1046        positional: None,
1047        hidden: false,
1048    },
1049    CommandNode {
1050        name: "claude-mod",
1051        aliases: &["claude_mod"],
1052        description: "Install, refresh or remove the lean-ctx Claude Code mod",
1053        subcommands: &[
1054            CommandNode {
1055                name: "status",
1056                aliases: &[],
1057                description: "Show whether the mod is installed and current",
1058                subcommands: &[],
1059                flags: &[],
1060                positional: None,
1061                hidden: false,
1062            },
1063            CommandNode {
1064                name: "install",
1065                aliases: &["update"],
1066                description: "Install, or refresh to this engine's version",
1067                subcommands: &[],
1068                flags: &[],
1069                positional: None,
1070                hidden: false,
1071            },
1072            CommandNode {
1073                name: "uninstall",
1074                aliases: &["remove"],
1075                description: "Remove the mod and its local marketplace",
1076                subcommands: &[],
1077                flags: &[],
1078                positional: None,
1079                hidden: false,
1080            },
1081        ],
1082        flags: &[],
1083        positional: None,
1084        hidden: false,
1085    },
1086    CommandNode {
1087        name: "statusline",
1088        aliases: &[],
1089        description: "Claude Code status line: what lean-ctx did in this project",
1090        subcommands: &[],
1091        flags: &[FlagSpec {
1092            long: "--wrap",
1093            short: None,
1094            description: "Run an existing status line too and append to its first line",
1095            takes_value: true,
1096            value_kind: None,
1097        }],
1098        positional: None,
1099        hidden: false,
1100    },
1101    CommandNode {
1102        name: "inspect",
1103        aliases: &[],
1104        description: "Why the Context Gateway delivered, changed or withheld sources",
1105        subcommands: &[],
1106        flags: &[
1107            FlagSpec {
1108                long: "--last",
1109                short: None,
1110                description: "Show the N newest verified receipts",
1111                takes_value: true,
1112                value_kind: None,
1113            },
1114            FlagSpec {
1115                long: "--project",
1116                short: None,
1117                description: "Project root (default: the current project)",
1118                takes_value: true,
1119                value_kind: None,
1120            },
1121            FlagSpec {
1122                long: "--json",
1123                short: None,
1124                description: "Machine-readable output",
1125                takes_value: false,
1126                value_kind: None,
1127            },
1128        ],
1129        positional: None,
1130        hidden: false,
1131    },
1132    CommandNode {
1133        name: "prompt-segment",
1134        aliases: &[],
1135        description: "Shell prompt segment: what lean-ctx did in this project",
1136        subcommands: &[],
1137        flags: &[
1138            FlagSpec {
1139                long: "--shell",
1140                short: None,
1141                description: "Escape for this shell: zsh, bash, fish or plain (Starship)",
1142                takes_value: true,
1143                value_kind: None,
1144            },
1145            FlagSpec {
1146                long: "--json",
1147                short: None,
1148                description: "Segment and labelled breakdown as JSON (editor status bars)",
1149                takes_value: false,
1150                value_kind: None,
1151            },
1152            FlagSpec {
1153                long: "--dir",
1154                short: None,
1155                description: "Project directory (default: the current one)",
1156                takes_value: true,
1157                value_kind: None,
1158            },
1159        ],
1160        positional: None,
1161        hidden: false,
1162    },
1163    CommandNode {
1164        name: "value",
1165        aliases: &[],
1166        description: "Show what lean-ctx did, recomputed from the verified chains",
1167        subcommands: &[],
1168        flags: &[
1169            FlagSpec {
1170                long: "--session",
1171                short: None,
1172                description: "A specific session (default: the current/last one)",
1173                takes_value: true,
1174                value_kind: None,
1175            },
1176            FlagSpec {
1177                long: "--all",
1178                short: None,
1179                description: "Lifetime, across all sessions",
1180                takes_value: false,
1181                value_kind: None,
1182            },
1183            FlagSpec {
1184                long: "--json",
1185                short: None,
1186                description: "Machine-readable output",
1187                takes_value: false,
1188                value_kind: None,
1189            },
1190        ],
1191        positional: None,
1192        hidden: false,
1193    },
1194    CommandNode {
1195        name: "verify",
1196        aliases: &["proof"],
1197        description: "Verify cache integrity",
1198        subcommands: &[],
1199        flags: &[
1200            FlagSpec {
1201                long: "--real",
1202                short: None,
1203                description: "Measure the canonical ten-task production suite",
1204                takes_value: false,
1205                value_kind: None,
1206            },
1207            FlagSpec {
1208                long: "--json",
1209                short: None,
1210                description: "JSON output for --real",
1211                takes_value: false,
1212                value_kind: None,
1213            },
1214        ],
1215        positional: None,
1216        hidden: false,
1217    },
1218    CommandNode {
1219        name: "verify-cache",
1220        aliases: &["cache-selftest"],
1221        description: "Verify cache consistency",
1222        subcommands: &[],
1223        flags: &[],
1224        positional: None,
1225        hidden: false,
1226    },
1227    CommandNode {
1228        name: "visualize",
1229        aliases: &[],
1230        description: "Visualize context graph",
1231        subcommands: &[],
1232        flags: &[],
1233        positional: None,
1234        hidden: false,
1235    },
1236    CommandNode {
1237        name: "instructions",
1238        aliases: &[],
1239        description: "Show agent instructions",
1240        subcommands: &[],
1241        flags: &[],
1242        positional: None,
1243        hidden: false,
1244    },
1245    CommandNode {
1246        name: "semantic-search",
1247        aliases: &["search-code"],
1248        description: "Semantic code search",
1249        subcommands: &[],
1250        flags: &[],
1251        positional: None,
1252        hidden: false,
1253    },
1254    CommandNode {
1255        name: "read",
1256        aliases: &[],
1257        description: "Read and compress a file",
1258        subcommands: &[],
1259        flags: &[],
1260        positional: None,
1261        hidden: false,
1262    },
1263    CommandNode {
1264        name: "call",
1265        aliases: &[],
1266        description: "Call an MCP tool",
1267        subcommands: &[],
1268        flags: &[],
1269        positional: None,
1270        hidden: false,
1271    },
1272    CommandNode {
1273        name: "diff",
1274        aliases: &[],
1275        description: "Compressed diff",
1276        subcommands: &[],
1277        flags: &[],
1278        positional: None,
1279        hidden: false,
1280    },
1281    CommandNode {
1282        name: "grep",
1283        aliases: &["find"],
1284        description: "Search with compression",
1285        subcommands: &[],
1286        flags: &[],
1287        positional: None,
1288        hidden: false,
1289    },
1290    CommandNode {
1291        name: "glob",
1292        aliases: &[],
1293        description: "Glob file search",
1294        subcommands: &[],
1295        flags: &[],
1296        positional: None,
1297        hidden: false,
1298    },
1299    CommandNode {
1300        name: "ls",
1301        aliases: &[],
1302        description: "List directory contents",
1303        subcommands: &[],
1304        flags: &[],
1305        positional: None,
1306        hidden: false,
1307    },
1308    CommandNode {
1309        name: "deps",
1310        aliases: &[],
1311        description: "Show dependencies",
1312        subcommands: &[],
1313        flags: &[],
1314        positional: None,
1315        hidden: false,
1316    },
1317    CommandNode {
1318        name: "discover",
1319        aliases: &[],
1320        description: "Discover project structure",
1321        subcommands: &[],
1322        flags: &[],
1323        positional: None,
1324        hidden: false,
1325    },
1326    CommandNode {
1327        name: "ghost",
1328        aliases: &[],
1329        description: "Ghost context injection",
1330        subcommands: &[],
1331        flags: &[],
1332        positional: None,
1333        hidden: false,
1334    },
1335    CommandNode {
1336        name: "filter",
1337        aliases: &[],
1338        description: "Filter context",
1339        subcommands: &[],
1340        flags: &[],
1341        positional: None,
1342        hidden: false,
1343    },
1344    CommandNode {
1345        name: "heatmap",
1346        aliases: &[],
1347        description: "Show file heatmap",
1348        subcommands: &[],
1349        flags: &[],
1350        positional: None,
1351        hidden: false,
1352    },
1353    CommandNode {
1354        name: "graph",
1355        aliases: &[],
1356        description: "Show dependency graph",
1357        subcommands: &[],
1358        flags: &[],
1359        positional: None,
1360        hidden: false,
1361    },
1362    CommandNode {
1363        name: "smells",
1364        aliases: &[],
1365        description: "Detect code smells",
1366        subcommands: &[],
1367        flags: &[],
1368        positional: None,
1369        hidden: false,
1370    },
1371    CommandNode {
1372        name: "ledger",
1373        aliases: &[],
1374        description: "Token usage ledger",
1375        subcommands: &[],
1376        flags: &[],
1377        positional: None,
1378        hidden: false,
1379    },
1380    CommandNode {
1381        name: "control",
1382        aliases: &[],
1383        description: "Runtime control",
1384        subcommands: &[],
1385        flags: &[],
1386        positional: None,
1387        hidden: false,
1388    },
1389    CommandNode {
1390        name: "plan",
1391        aliases: &[],
1392        description: "Plan context strategy",
1393        subcommands: &[],
1394        flags: &[],
1395        positional: None,
1396        hidden: false,
1397    },
1398    CommandNode {
1399        name: "compile",
1400        aliases: &[],
1401        description: "Compile context",
1402        subcommands: &[],
1403        flags: &[],
1404        positional: None,
1405        hidden: false,
1406    },
1407    CommandNode {
1408        name: "skillify",
1409        aliases: &[],
1410        description: "Generate skill from code",
1411        subcommands: &[],
1412        flags: &[],
1413        positional: None,
1414        hidden: false,
1415    },
1416    CommandNode {
1417        name: "summary",
1418        aliases: &["overview"],
1419        description: "Show project summary",
1420        subcommands: &[],
1421        flags: &[],
1422        positional: None,
1423        hidden: false,
1424    },
1425    CommandNode {
1426        name: "benchmark-run",
1427        aliases: &["bench-run"],
1428        description: "Run a benchmark against a coding agent",
1429        subcommands: &[],
1430        flags: &[
1431            FlagSpec {
1432                long: "--profile",
1433                short: None,
1434                description: "Performance Profile to use",
1435                takes_value: true,
1436                value_kind: Some(DynamicKind::Profiles),
1437            },
1438            FlagSpec {
1439                long: "--suite",
1440                short: None,
1441                description: "Benchmark suite (default: coding-v1)",
1442                takes_value: true,
1443                value_kind: None,
1444            },
1445            FlagSpec {
1446                long: "--repeats",
1447                short: None,
1448                description: "Number of repetitions",
1449                takes_value: true,
1450                value_kind: None,
1451            },
1452            FlagSpec {
1453                long: "--dry-run",
1454                short: None,
1455                description: "Print BenchmarkSpec JSON and exit",
1456                takes_value: false,
1457                value_kind: None,
1458            },
1459        ],
1460        positional: None,
1461        hidden: false,
1462    },
1463    CommandNode {
1464        name: "pair",
1465        aliases: &[],
1466        description: "Pair with leanctx.com for remote benchmarks",
1467        subcommands: &[],
1468        flags: &[FlagSpec {
1469            long: "--server",
1470            short: None,
1471            description: "WebSocket server URL",
1472            takes_value: true,
1473            value_kind: None,
1474        }],
1475        positional: None,
1476        hidden: false,
1477    },
1478    CommandNode {
1479        name: "calibrate",
1480        aliases: &[],
1481        description: "Run profile calibration against a workload",
1482        subcommands: &[],
1483        flags: &[
1484            FlagSpec {
1485                long: "--quality-floor",
1486                short: None,
1487                description: "Minimum quality threshold (0.0-1.0)",
1488                takes_value: true,
1489                value_kind: None,
1490            },
1491            FlagSpec {
1492                long: "--max-candidates",
1493                short: None,
1494                description: "Maximum number of candidate profiles",
1495                takes_value: true,
1496                value_kind: None,
1497            },
1498        ],
1499        positional: Some(DynamicKind::Profiles),
1500        hidden: false,
1501    },
1502    CommandNode {
1503        name: "benchmark",
1504        aliases: &[],
1505        description: "Run compression benchmarks",
1506        subcommands: &[CommandNode {
1507            name: "replay",
1508            aliases: &[],
1509            description: "Replay paired sessions with and without compression",
1510            subcommands: &[],
1511            flags: &[FlagSpec {
1512                long: "--output",
1513                short: None,
1514                description: "Write Markdown report to a file",
1515                takes_value: true,
1516                value_kind: None,
1517            }],
1518            positional: None,
1519            hidden: false,
1520        }],
1521        flags: &[
1522            FlagSpec {
1523                long: "--real",
1524                short: None,
1525                description: "Run with real file system tasks",
1526                takes_value: false,
1527                value_kind: None,
1528            },
1529            FlagSpec {
1530                long: "--json",
1531                short: None,
1532                description: "JSON output",
1533                takes_value: false,
1534                value_kind: None,
1535            },
1536        ],
1537        positional: None,
1538        hidden: false,
1539    },
1540    CommandNode {
1541        name: "tools",
1542        aliases: &[],
1543        description: "List available MCP tools",
1544        subcommands: &[],
1545        flags: &[],
1546        positional: None,
1547        hidden: false,
1548    },
1549    CommandNode {
1550        name: "allow",
1551        aliases: &["trust"],
1552        description: "Allow a command/path",
1553        subcommands: &[],
1554        flags: &[],
1555        positional: None,
1556        hidden: false,
1557    },
1558    CommandNode {
1559        name: "allow-path",
1560        aliases: &[],
1561        description: "Let the path jail admit a directory outside ~ or a protected one",
1562        subcommands: &[],
1563        flags: &[],
1564        positional: None,
1565        hidden: false,
1566    },
1567    CommandNode {
1568        name: "untrust",
1569        aliases: &[],
1570        description: "Untrust a command/path",
1571        subcommands: &[],
1572        flags: &[],
1573        positional: None,
1574        hidden: false,
1575    },
1576    CommandNode {
1577        name: "theme",
1578        aliases: &[],
1579        description: "Set dashboard theme",
1580        subcommands: &[],
1581        flags: &[],
1582        positional: None,
1583        hidden: false,
1584    },
1585    CommandNode {
1586        name: "tee",
1587        aliases: &[],
1588        description: "Tee output to file",
1589        subcommands: &[],
1590        flags: &[],
1591        positional: None,
1592        hidden: false,
1593    },
1594    CommandNode {
1595        name: "codesign-setup",
1596        aliases: &[],
1597        description: "Setup code signing",
1598        subcommands: &[],
1599        flags: &[],
1600        positional: None,
1601        hidden: false,
1602    },
1603    CommandNode {
1604        name: "buddy",
1605        aliases: &[],
1606        description: "AI buddy assistant",
1607        subcommands: &[],
1608        flags: &[],
1609        positional: None,
1610        hidden: false,
1611    },
1612    CommandNode {
1613        name: "learning",
1614        aliases: &["conformance"],
1615        description: "Show learning progress",
1616        subcommands: &[],
1617        flags: &[],
1618        positional: None,
1619        hidden: false,
1620    },
1621    CommandNode {
1622        name: "token-report",
1623        aliases: &["report-tokens"],
1624        description: "Token usage report",
1625        subcommands: &[],
1626        flags: &[],
1627        positional: None,
1628        hidden: false,
1629    },
1630    CommandNode {
1631        name: "pack",
1632        aliases: &[],
1633        description: "Pack context for export",
1634        subcommands: &[],
1635        flags: &[],
1636        positional: None,
1637        hidden: false,
1638    },
1639    CommandNode {
1640        name: "policy",
1641        aliases: &[],
1642        description: "Manage security policies",
1643        subcommands: &[],
1644        flags: &[],
1645        positional: None,
1646        hidden: false,
1647    },
1648    CommandNode {
1649        name: "cep",
1650        aliases: &[],
1651        description: "Context engineering pipeline",
1652        subcommands: &[],
1653        flags: &[],
1654        positional: None,
1655        hidden: false,
1656    },
1657    CommandNode {
1658        name: "team",
1659        aliases: &[],
1660        description: "Team management",
1661        subcommands: &[],
1662        flags: &[],
1663        positional: None,
1664        hidden: false,
1665    },
1666    CommandNode {
1667        name: "provider",
1668        aliases: &[],
1669        description: "Manage LLM providers",
1670        subcommands: &[],
1671        flags: &[],
1672        positional: None,
1673        hidden: false,
1674    },
1675    CommandNode {
1676        name: "watch",
1677        aliases: &[],
1678        // #1602: removed in 3.9.20; kept only as a signpost to `dashboard`,
1679        // so it must not be completed as if it were a working command.
1680        description: "Removed — see `lean-ctx dashboard`",
1681        subcommands: &[],
1682        flags: &[],
1683        positional: None,
1684        hidden: true,
1685    },
1686    CommandNode {
1687        name: "yolo",
1688        aliases: &["secure"],
1689        description: "Toggle security mode",
1690        subcommands: &[],
1691        flags: &[],
1692        positional: None,
1693        hidden: false,
1694    },
1695    // Hidden internal commands
1696    CommandNode {
1697        name: "__complete",
1698        aliases: &[],
1699        description: "Dynamic completion (internal)",
1700        subcommands: &[],
1701        flags: &[],
1702        positional: None,
1703        hidden: true,
1704    },
1705    CommandNode {
1706        name: "telemetry",
1707        aliases: &[],
1708        description: "Manage anonymous usage telemetry",
1709        subcommands: &[
1710            CommandNode {
1711                name: "status",
1712                aliases: &[],
1713                description: "Show current telemetry status",
1714                subcommands: &[],
1715                flags: &[],
1716                positional: None,
1717                hidden: false,
1718            },
1719            CommandNode {
1720                name: "on",
1721                aliases: &[],
1722                description: "Enable telemetry",
1723                subcommands: &[],
1724                flags: &[],
1725                positional: None,
1726                hidden: false,
1727            },
1728            CommandNode {
1729                name: "off",
1730                aliases: &[],
1731                description: "Disable telemetry",
1732                subcommands: &[],
1733                flags: &[],
1734                positional: None,
1735                hidden: false,
1736            },
1737            CommandNode {
1738                name: "show",
1739                aliases: &[],
1740                description: "Show current heartbeat payload",
1741                subcommands: &[],
1742                flags: &[],
1743                positional: None,
1744                hidden: false,
1745            },
1746            CommandNode {
1747                name: "reset-id",
1748                aliases: &[],
1749                description: "Regenerate installation ID",
1750                subcommands: &[],
1751                flags: &[],
1752                positional: None,
1753                hidden: false,
1754            },
1755            CommandNode {
1756                name: "history",
1757                aliases: &["log"],
1758                description: "Show log of sent heartbeats",
1759                subcommands: &[],
1760                flags: &[],
1761                positional: None,
1762                hidden: false,
1763            },
1764        ],
1765        flags: &[],
1766        positional: None,
1767        hidden: false,
1768    },
1769    CommandNode {
1770        name: "daemon",
1771        aliases: &[],
1772        description: "Start daemon (internal)",
1773        subcommands: &[],
1774        flags: &[],
1775        positional: None,
1776        hidden: true,
1777    },
1778];
1779#[cfg(test)]
1780mod tests {
1781    use super::*;
1782    #[test]
1783    fn no_duplicate_names_at_top_level() {
1784        let mut seen = std::collections::HashSet::new();
1785        for node in COMMAND_TREE {
1786            assert!(seen.insert(node.name), "duplicate: {}", node.name);
1787        }
1788    }
1789    #[test]
1790    fn visible_count_exceeds_50() {
1791        let visible = COMMAND_TREE.iter().filter(|n| !n.hidden).count();
1792        assert!(
1793            visible >= 30,
1794            "expected at least 30 visible commands, got {visible}"
1795        );
1796    }
1797    #[test]
1798    fn command_tree_covers_known_commands() {
1799        let known = crate::cli::dispatch::suggest::KNOWN_COMMANDS;
1800        let tree_names: std::collections::HashSet<&str> = COMMAND_TREE
1801            .iter()
1802            .flat_map(|n| std::iter::once(n.name).chain(n.aliases.iter().copied()))
1803            .collect();
1804        let mut missing = Vec::new();
1805        for cmd in known {
1806            if !tree_names.contains(cmd) {
1807                missing.push(*cmd);
1808            }
1809        }
1810        assert!(
1811            missing.is_empty(),
1812            "KNOWN_COMMANDS entries missing from COMMAND_TREE: {missing:?}"
1813        );
1814    }
1815    #[test]
1816    fn benchmark_real_is_registered_for_completion() {
1817        assert!(crate::cli::dispatch::suggest::KNOWN_COMMANDS.contains(&"benchmark"));
1818        let benchmark = COMMAND_TREE
1819            .iter()
1820            .find(|node| node.name == "benchmark")
1821            .expect("benchmark command must be registered");
1822        assert!(benchmark.flags.iter().any(|flag| flag.long == "--real"));
1823        assert!(benchmark.flags.iter().any(|flag| flag.long == "--json"));
1824    }
1825
1826    /// #1602: `watch` was removed in 3.9.20, but the completion spec still
1827    /// offered it — under a third description ("Watch for file changes") that
1828    /// matched neither the removed TUI nor `index watch`. A removed command
1829    /// must not be advertised as a working one.
1830    #[test]
1831    fn removed_watch_command_is_not_advertised() {
1832        let watch = COMMAND_TREE
1833            .iter()
1834            .find(|node| node.name == "watch")
1835            .expect("watch stays in the tree as a signpost to `dashboard`");
1836        assert!(
1837            watch.hidden,
1838            "a removed command must not be completed as a working one"
1839        );
1840        assert!(
1841            watch.description.contains("Removed"),
1842            "the description must say the command is gone, got: {}",
1843            watch.description
1844        );
1845    }
1846}