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
use clap::Subcommand;
pub mod shell_runner;
#[derive(Subcommand, Debug)]
pub enum CLICommand {
/// Show LeanKG version
Version,
/// Initialize a new LeanKG project
Init {
#[arg(long, default_value = ".leankg")]
path: String,
},
/// Index the codebase
Index {
/// Path to index
path: Option<String>,
#[arg(long, short)]
incremental: bool,
/// Filter by language (e.g., go,ts,py)
#[arg(long, short)]
lang: Option<String>,
/// Exclude patterns (comma-separated)
#[arg(long)]
exclude: Option<String>,
/// Verbose output
#[arg(long, short)]
verbose: bool,
},
/// Query the knowledge graph
Query {
/// Query string
query: String,
/// Query type: name, type, rel, pattern
#[arg(long, default_value = "name")]
kind: String,
},
/// Generate documentation
Generate {
#[arg(long, short)]
template: Option<String>,
},
/// Start web UI server (deprecated - use 'web' command instead)
Serve {
/// Port to listen on (default: from PORT env var or 8080)
#[arg(long)]
port: Option<u16>,
},
/// Start the embedded web UI server
Web {
/// Port to listen on (default: from PORT env var or 8080)
#[arg(long)]
port: Option<u16>,
},
/// Start MCP server with stdio transport (for opencode integration)
McpStdio {
/// Enable auto-indexing with file watcher
#[arg(long)]
watch: bool,
},
/// Calculate impact radius
Impact {
/// File to analyze
file: String,
/// Depth of analysis
#[arg(long, default_value = "3")]
depth: u32,
},
/// Auto-install MCP config
Install,
/// Show index status
Status,
/// Start file watcher for incremental re-indexing
Watch {
/// Path to watch (default: project root)
#[arg(long)]
path: Option<String>,
},
/// Find oversized functions
Quality {
/// Minimum line count (default: 50)
#[arg(long, default_value = "50")]
min_lines: u32,
/// Filter by language
#[arg(long)]
lang: Option<String>,
},
/// Export knowledge graph
Export {
/// Output file path
#[arg(long, default_value = "graph.json")]
output: String,
/// Export format: json, dot, or mermaid
#[arg(long, default_value = "json")]
format: String,
/// Scope export to a specific file's subgraph
#[arg(long)]
file: Option<String>,
/// Max depth for subgraph traversal (used with --file)
#[arg(long, default_value = "3")]
depth: u32,
},
/// Annotate code element with business logic description
Annotate {
/// Element qualified name (e.g., src/main.rs::main)
element: String,
/// Business logic description
#[arg(long, short)]
description: String,
/// User story ID (optional)
#[arg(long)]
user_story: Option<String>,
/// Feature ID (optional)
#[arg(long)]
feature: Option<String>,
},
/// Link code element to user story or feature
Link {
/// Element qualified name
element: String,
/// User story or feature ID
id: String,
/// Link type: story or feature
#[arg(long, default_value = "story")]
kind: String,
},
/// Search business logic annotations
SearchAnnotations {
/// Search query
query: String,
},
/// Show annotations for an element
ShowAnnotations {
/// Element qualified name
element: String,
},
/// Show feature-to-code traceability
Trace {
/// Feature ID to trace
#[arg(long)]
feature: Option<String>,
/// User story ID to trace
#[arg(long)]
user_story: Option<String>,
/// Show all traceabilities
#[arg(long, short)]
all: bool,
},
/// Find code elements by business domain
FindByDomain {
/// Business domain (e.g., authentication, validation)
domain: String,
},
/// Run benchmark comparison
Benchmark {
/// Specific category to run (optional)
#[arg(long)]
category: Option<String>,
/// CLI tool to use: opencode, gemini, or kilo (default: kilo)
#[arg(long, default_value = "kilo")]
cli: String,
},
/// Register current directory in global registry
Register {
/// Name for the repository
name: String,
},
/// Unregister a repository from global registry
Unregister {
/// Name of the repository to unregister
name: String,
},
/// List all registered repositories
List,
/// Show status for a registered repository
StatusRepo {
/// Name of the repository
name: String,
},
/// Global setup: configure MCP for all registered repos at once
Setup {},
/// Run a shell command with optional RTK-style compression
Run {
/// Command to run (e.g., "git status", "cargo test")
command: Vec<String>,
/// Enable compression (RTK-style)
#[arg(long)]
compress: bool,
},
/// Run community detection to identify code clusters
DetectClusters {
/// Path to the project (default: current directory)
#[arg(long)]
path: Option<String>,
/// Minimum edges for a node to be considered a hub
#[arg(long, default_value = "5")]
min_hub_edges: usize,
},
/// Start the REST API server
ApiServe {
/// Port to listen on (default: 8081)
#[arg(long, default_value = "8081")]
port: u16,
/// Require API key authentication
#[arg(long)]
auth: bool,
},
/// Manage API keys for REST API access
ApiKey {
#[command(subcommand)]
command: ApiKeyCommand,
},
/// Obsidian vault sync commands
Obsidian {
#[command(subcommand)]
command: ObsidianCommand,
},
/// Show context metrics (token savings, usage stats)
Metrics {
/// Show metrics from the last N days (e.g., 7d, 30d)
#[arg(long)]
since: Option<String>,
/// Filter by tool name (e.g., search_code, get_context)
#[arg(long)]
tool: Option<String>,
/// Output in JSON format
#[arg(long, short)]
json: bool,
/// Show metrics for current session only
#[arg(long)]
session: bool,
/// Reset all metrics
#[arg(long)]
reset: bool,
/// Set retention period in days (for cleanup)
#[arg(long)]
retention: Option<i32>,
/// Run cleanup to remove old metrics
#[arg(long)]
cleanup: bool,
/// Seed test metrics data
#[arg(long)]
seed: bool,
},
/// Update LeanKG to the latest version from GitHub releases
Update,
}
#[derive(Subcommand, Debug)]
pub enum ApiKeyCommand {
/// Create a new API key
Create {
/// Name for the API key
#[arg(long)]
name: String,
},
/// List all API keys
List,
/// Revoke an API key
Revoke {
/// ID of the API key to revoke
#[arg(long)]
id: String,
},
}
#[derive(Subcommand, Debug)]
pub enum ObsidianCommand {
/// Initialize Obsidian vault structure
Init {
/// Custom vault path (default: .leankg/obsidian/vault)
#[arg(long)]
vault: Option<String>,
},
/// Push LeanKG data to Obsidian notes
Push {
/// Custom vault path (default: .leankg/obsidian/vault)
#[arg(long)]
vault: Option<String>,
},
/// Pull annotation edits from Obsidian to LeanKG
Pull {
/// Custom vault path (default: .leankg/obsidian/vault)
#[arg(long)]
vault: Option<String>,
},
/// Watch Obsidian vault for changes and auto-pull
Watch {
/// Custom vault path (default: .leankg/obsidian/vault)
#[arg(long)]
vault: Option<String>,
/// Debounce delay in milliseconds (default: 1000)
#[arg(long, default_value = "1000")]
debounce_ms: u64,
},
/// Show vault status
Status {
/// Custom vault path (default: .leankg/obsidian/vault)
#[arg(long)]
vault: Option<String>,
},
}