argot-cmd 0.1.2

An agent-first command interface framework for Rust
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
# ARCHITECTURE.md

# Argot Architecture

Argot is an **agent-first command interface framework for Rust**.

Unlike traditional CLI frameworks that focus on parsing command-line arguments, Argot models a CLI as a **structured command language**. This allows the same command interface to support:

* humans using a CLI
* AI agents discovering commands
* automation systems invoking commands
* optional tool exposure through protocols such as MCP

The CLI is treated as **one interface** to the command model rather than the source of truth.

---

# Design Goals

Argot aims to provide:

### Agent Discoverability

Agents should be able to programmatically determine:

* what commands exist
* what each command does
* what arguments and flags are available
* safe usage examples
* recommended practices

Agents should **never need to scrape help text**.

---

### Stable Command Identity

Each command has a canonical identity.

Aliases and alternate spellings resolve to the same canonical command.

Example:

```
canonical: deploy
aliases: [release, ship, push]
```

Internally the system always operates on the canonical name.

---

### Structured Command Metadata

Commands include structured metadata for both humans and agents.

Typical metadata includes:

* summary
* description
* arguments
* flags
* examples
* best practices
* anti-patterns

This metadata becomes the single source of truth used to generate:

* CLI help output
* machine-readable command schemas
* documentation
* tool definitions

---

### Human-Friendly CLI

Although Argot prioritizes agent UX, the CLI should still feel familiar and ergonomic.

Design inspiration comes from:

* `clap` — the dominant Rust CLI argument parser

Argot should follow similar conventions for:

* command hierarchy
* flags
* help output
* examples

However, these outputs should be generated from the structured command model rather than written by hand.

---

# System Architecture

Argot is organized into several logical layers.

```
model
resolver
parser
query
render
cli
transport
```

Each layer should remain loosely coupled.

---

# Model Layer

The **model** layer defines the core command structures.

These structures represent the canonical command surface.

Example:

```rust
#[derive(Debug, Clone)]
pub struct Command {
    pub canonical: String,
    pub aliases: Vec<String>,
    pub spellings: Vec<String>,

    pub summary: String,
    pub description: String,

    pub arguments: Vec<Argument>,
    pub flags: Vec<Flag>,

    pub examples: Vec<Example>,

    pub best_practices: Vec<String>,
    pub anti_patterns: Vec<String>,
}

#[derive(Debug, Clone)]
pub struct Example {
    pub command: String,
    pub description: String,
}
```

The model layer should contain **no parsing logic or CLI behavior**.

---

# Resolver Layer

The resolver maps user input to canonical commands.

Responsibilities include:

* alias resolution
* spelling normalization
* ambiguity detection

Example:

```
release → deploy
ship → deploy
```

If multiple commands match an input, the resolver should surface the ambiguity rather than guessing.

---

# Parser Layer

The parser converts argv input into structured command execution.

Responsibilities include:

* tokenizing CLI input
* matching commands
* parsing arguments
* validating flags

The parser should rely on the resolver to determine canonical commands.

---

# Query Layer

The query layer provides programmatic access to command metadata.

Example queries:

```
list commands
get command deploy
get examples deploy
```

This layer exists primarily for agents and automation.

The CLI may expose these queries through commands such as:

```
tool query commands
tool query deploy
```

---

# Render Layer

The render layer produces human-readable outputs.

Examples include:

* CLI help text
* markdown documentation
* terminal summaries

All rendering should be generated from the command model.

Manual help text should be avoided whenever possible.

---

# CLI Layer

The CLI layer provides a human interface for executing commands.

Responsibilities include:

* reading argv
* invoking the parser
* formatting output
* presenting help

The CLI layer should remain thin.

Most logic should exist in earlier layers.

---

# Transport Layer

The transport layer exposes commands through machine interfaces.

Examples include:

* JSON APIs
* tool discovery endpoints
* MCP servers

MCP support is optional and should not introduce dependencies into the core packages.

It should be gated behind a Cargo feature flag:

```toml
[features]
mcp = ["dep:some-mcp-crate"]
```

---

# Command Example

Below is an example command definition using the builder pattern.

```rust
use argot::{Command, Example};

let deploy = Command::builder("deploy")
    .aliases(&["release", "ship"])
    .summary("Deploy a service to an environment")
    .description("Deploy builds and releases a service artifact to the specified environment.")
    .example(Example::new(
        "deploy api --env staging",
        "Deploy API service to staging",
    ))
    .example(Example::new(
        "deploy api --env prod",
        "Deploy API service to production",
    ))
    .best_practice("Deploy to staging before production")
    .anti_pattern("Deploy directly to production without validation")
    .build();
```

---

# CLI Example

Human usage:

```
tool deploy api --env prod
```

Help output:

```
deploy

Deploy a service to an environment.

Examples:
  deploy api --env staging
  deploy api --env prod
```

---

# Agent Query Example

Agents should be able to request structured data.

Example:

```
tool query deploy --json
```

Example output:

```json
{
  "canonical": "deploy",
  "summary": "Deploy a service",
  "arguments": ["service"],
  "flags": ["env"],
  "examples": [
    "deploy api --env prod"
  ]
}
```

---

# Ambiguity Handling

Argot should prefer **explicit resolution over guessing**.

Example ambiguous input:

```
dep
```

If this could match:

```
deploy
describe
delete
```

Argot should return:

```
Ambiguous command "dep".

Did you mean:
  deploy
  describe
  delete
```

Agents should receive a structured version of this response.

---

# Error Handling

Argot uses structured error types via `thiserror`.

```rust
#[derive(Debug, thiserror::Error)]
pub enum ResolveError {
    #[error("unknown command: {0}")]
    Unknown(String),

    #[error("ambiguous command \"{input}\": could match {candidates:?}")]
    Ambiguous {
        input: String,
        candidates: Vec<String>,
    },
}
```

Library code should never `unwrap()`. All fallible operations return `Result<T, E>`.

---

# Design Principles

Argot follows several guiding principles.

### Single Source of Truth

The command model drives all outputs.

### Deterministic Behavior

Parsing and resolution should be predictable.

### Explicit Over Magical

Avoid hidden behavior or implicit command guessing.

### Discoverability

Commands should be easy to explore programmatically.

### Idiomatic Rust

Follow Rust conventions: ownership, `Result`-based error handling, `derive` macros, and feature flags for optional integrations.

---

# Future Extensions

Potential future capabilities include:

* command intent mapping
* semantic aliasing
* interactive command exploration
* IDE integrations (via LSP or rust-analyzer plugins)
* automatic documentation generation
* tool protocol adapters (MCP, OpenAI tool calling, etc.)

These should build on the existing command model rather than replace it.