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
use crate::model::IssueSeverity;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "archmap")]
#[command(about = "Generate architectural context for AI agents")]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
/// Path to analyze (defaults to current directory)
/// Used when no subcommand is specified for backward compatibility
#[arg(default_value = ".")]
pub path: PathBuf,
/// Output MCP server manifest JSON for MCP client configuration
#[arg(long)]
pub mcp_manifest: bool,
}
#[derive(Subcommand, Debug, Clone)]
pub enum Command {
/// Run full architectural analysis (default behavior)
Analyze(AnalyzeArgs),
/// Generate AI-optimized context output
Ai(AiArgs),
/// Analyze change impact for a specific file
Impact(ImpactArgs),
/// Save an architectural snapshot
Snapshot(SnapshotArgs),
/// Compare current state against a baseline snapshot
Diff(DiffArgs),
/// Launch interactive graph visualization
Graph(GraphArgs),
/// Generate a starter .archmap.toml configuration file
Init(InitArgs),
/// Start MCP server for AI assistant integration (stdio transport)
Mcp(McpArgs),
}
#[derive(Parser, Debug, Clone)]
pub struct AnalyzeArgs {
/// Path to analyze (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
/// Output format
#[arg(short, long, default_value = "markdown")]
pub format: OutputFormat,
/// Output file (defaults to stdout)
#[arg(short, long)]
pub output: Option<PathBuf>,
/// Minimum severity to report
#[arg(long, default_value = "info")]
pub min_severity: IssueSeverity,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
/// Watch for file changes and re-analyze
#[arg(short, long)]
pub watch: bool,
/// Maximum dependency chain depth before flagging (default: 5)
#[arg(long, default_value = "5")]
pub max_depth: usize,
/// Minimum cohesion score before flagging (0.0-1.0, default: 0.3)
#[arg(long, default_value = "0.3")]
pub min_cohesion: f64,
/// Directories to exclude (can be specified multiple times)
#[arg(long = "exclude", short = 'x', value_name = "DIR")]
pub exclude: Vec<String>,
}
impl Default for AnalyzeArgs {
fn default() -> Self {
Self {
path: PathBuf::from("."),
format: OutputFormat::Markdown,
output: None,
min_severity: IssueSeverity::Info,
lang: None,
watch: false,
max_depth: 5,
min_cohesion: 0.3,
exclude: Vec::new(),
}
}
}
#[derive(Parser, Debug, Clone)]
pub struct AiArgs {
/// Path to analyze (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
/// Maximum tokens for output (uses tiktoken for accurate counting)
#[arg(long)]
pub tokens: Option<usize>,
/// Output only architectural signatures (public API surface)
#[arg(long)]
pub signatures: bool,
/// Use topological ordering (dependencies before dependents)
#[arg(long, default_value = "true")]
pub topo_order: bool,
/// Output format
#[arg(short, long, default_value = "markdown")]
pub format: AiOutputFormat,
/// Output file (defaults to stdout)
#[arg(short, long)]
pub output: Option<PathBuf>,
/// Prioritization strategy for token budgeting
#[arg(long, default_value = "fan-in")]
pub priority: PriorityStrategy,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
}
#[derive(Parser, Debug, Clone)]
pub struct ImpactArgs {
/// File to analyze for change impact
pub file: PathBuf,
/// Project path (defaults to current directory)
#[arg(long, default_value = ".")]
pub path: PathBuf,
/// Maximum depth to traverse (unlimited if not specified)
#[arg(short, long)]
pub depth: Option<usize>,
/// Output format
#[arg(short, long, default_value = "markdown")]
pub format: OutputFormat,
/// Output file (defaults to stdout)
#[arg(short, long)]
pub output: Option<PathBuf>,
/// Show ASCII tree visualization
#[arg(long)]
pub tree: bool,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
}
#[derive(Parser, Debug, Clone)]
pub struct SnapshotArgs {
/// Save snapshot to this file
#[arg(long)]
pub save: PathBuf,
/// Path to analyze (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
}
#[derive(Parser, Debug, Clone)]
pub struct DiffArgs {
/// Baseline snapshot file to compare against
pub baseline: PathBuf,
/// Path to analyze (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
/// Output format
#[arg(short, long, default_value = "markdown")]
pub format: OutputFormat,
/// Output file (defaults to stdout)
#[arg(short, long)]
pub output: Option<PathBuf>,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
/// Exit with error if architectural regressions are found
#[arg(long)]
pub fail_on_regression: bool,
}
#[derive(Parser, Debug, Clone)]
pub struct GraphArgs {
/// Start HTTP server for interactive visualization
#[arg(long)]
pub serve: bool,
/// Port for HTTP server
#[arg(long, default_value = "3000")]
pub port: u16,
/// Path to analyze (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
/// Open browser automatically
#[arg(long)]
pub open: bool,
/// Watch for file changes and live-update the visualization
#[arg(short, long)]
pub watch: bool,
/// Export graph as static HTML file instead of serving
#[arg(long)]
pub export: Option<PathBuf>,
/// Languages to analyze (comma-separated: rust,typescript,python)
#[arg(long, value_delimiter = ',')]
pub lang: Option<Vec<String>>,
}
#[derive(Parser, Debug, Clone)]
pub struct InitArgs {
/// Path where to create .archmap.toml (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
}
#[derive(Parser, Debug, Clone)]
pub struct McpArgs {
/// Working directory for analysis (defaults to current directory)
#[arg(default_value = ".")]
pub path: PathBuf,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, clap::ValueEnum)]
pub enum OutputFormat {
#[default]
Markdown,
Json,
}
#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)]
pub enum AiOutputFormat {
#[default]
Markdown,
Json,
Xml,
}
#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)]
pub enum PriorityStrategy {
/// Prioritize modules by number of dependents (most imported first)
#[default]
FanIn,
/// Prioritize modules by number of dependencies
FanOut,
/// Combined score using fan-in, fan-out, and data structures
Combined,
}