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
/// Single source of truth for all command metadata.
///
/// # Invariants
///
/// 1. Every CLI command has exactly one entry
/// 2. Every MCP tool maps to exactly one command
/// 3. All examples are validated at build time
/// 4. No duplicate command names or aliases
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CommandRegistry {
/// Semantic version of the registry format
pub version: String,
/// All registered commands, keyed by canonical name
pub commands: HashMap<String, CommandMetadata>,
/// Global flags available to all commands
pub global_flags: Vec<FlagMetadata>,
/// Timestamp when registry was built
pub built_at: Option<String>,
}
/// Complete metadata for a single command.
///
/// This struct captures everything needed to:
/// - Generate accurate help text
/// - Create MCP tool schema
/// - Index for semantic search
/// - Validate documentation
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CommandMetadata {
/// Canonical command name (e.g., "analyze complexity")
pub name: String,
/// Short description for listings (max 80 chars)
pub short_description: String,
/// Long description for --help
pub long_description: String,
/// Command aliases (e.g., ["cx"] for complexity)
pub aliases: Vec<String>,
/// Command arguments
pub arguments: Vec<ArgumentMetadata>,
/// Working examples that MUST execute successfully
pub examples: Vec<ExampleMetadata>,
/// MCP-specific metadata (None if not exposed via MCP)
pub mcp: Option<McpToolMetadata>,
/// Subcommands (for nested commands)
pub subcommands: Vec<CommandMetadata>,
/// Semantic tags for RAG retrieval
pub tags: Vec<String>,
/// Related commands for cross-reference
pub related: Vec<String>,
/// Deprecation info if applicable
pub deprecated: Option<DeprecationInfo>,
/// Category for grouping (e.g., "analysis", "quality", "scaffolding")
pub category: String,
/// Whether this command modifies state
pub is_mutation: bool,
/// Estimated execution time category
pub execution_time: ExecutionTime,
}
/// Argument metadata with validation rules.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ArgumentMetadata {
/// Argument name (e.g., "project-path")
pub name: String,
/// Short flag (e.g., 'p' for -p)
pub short: Option<char>,
/// Long flag (e.g., "project-path" for --project-path)
pub long: Option<String>,
/// Description for help text
pub description: String,
/// Whether argument is required
pub required: bool,
/// Default value if not provided
pub default: Option<String>,
/// Type of the value
pub value_type: ValueType,
/// Possible values for enums
pub possible_values: Vec<String>,
/// Environment variable that can set this
pub env_var: Option<String>,
/// Whether this is a positional argument (not a flag)
pub positional: bool,
}
/// Value types for arguments
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub enum ValueType {
#[default]
String,
Integer,
Float,
Boolean,
Path,
Enum,
List,
}
/// Flag metadata for global flags
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FlagMetadata {
pub name: String,
pub short: Option<char>,
pub long: Option<String>,
pub description: String,
pub default: Option<String>,
}
/// Example that MUST be validated at build time.
///
/// # Build-Time Validation
///
/// During `cargo build`, all examples with `requires_project: false`
/// are executed to ensure they work. This guarantees documentation
/// accuracy (Toyota Way - Poka-yoke).
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ExampleMetadata {
/// Description of what this example demonstrates
pub description: String,
/// The exact command to run
pub command: String,
/// Expected exit code (default: 0)
pub expected_exit_code: i32,
/// Regex patterns that output must match (optional)
pub output_patterns: Vec<String>,
/// Whether this example requires a specific project structure
pub requires_project: bool,
/// Project type required (if requires_project is true)
pub project_type: Option<String>,
}
/// MCP tool-specific metadata.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct McpToolMetadata {
/// MCP tool name (may differ from CLI command)
pub tool_name: String,
/// JSON Schema for input validation
pub input_schema: serde_json::Value,
/// Whether this tool modifies state
pub is_mutation: bool,
/// Estimated execution time category
pub execution_time: ExecutionTime,
/// MCP annotations
pub annotations: McpAnnotations,
}
/// MCP tool annotations per spec
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct McpAnnotations {
pub title: String,
pub read_only_hint: bool,
pub destructive_hint: bool,
pub idempotent_hint: bool,
pub open_world_hint: bool,
}
/// Execution time categories
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub enum ExecutionTime {
/// < 1 second
#[default]
Fast,
/// 1-10 seconds
Medium,
/// > 10 seconds
Slow,
}
/// Deprecation information
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DeprecationInfo {
/// Version when deprecated
pub since_version: String,
/// Version when it will be removed
pub removal_version: Option<String>,
/// Replacement command (if any)
pub replacement: Option<String>,
/// Reason for deprecation
pub reason: String,
}