sen 0.7.0

Script to System CLI Engine - A type-safe, macro-powered CLI framework
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
# SEN: CLI Engine

[![Rust](https://img.shields.io/badge/rust-1.70%2B-orange.svg)](https://www.rust-lang.org/)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](LICENSE)

A type-safe, macro-powered CLI framework.

## ๐ŸŽฏ Philosophy

SEN transforms CLI development from ad-hoc scripts into systematic applications with:

- **Compile-time safety**: Enum-based routing with exhaustiveness checking
- **Zero boilerplate**: Derive macros generate all wiring code
- **Type-driven DI**: Handler parameters injected based on type signature
- **Fixed workflows**: Predictable behavior for humans and AI agents
- **Strict separation**: Prevents the "1000-line main.rs" problem

## ๐Ÿš€ Quick Start

### Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
sen = { version = "0.1", features = ["clap"] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
```

Or use `cargo add`:

```bash
cargo add sen --features clap
cargo add clap --features derive
cargo add tokio --features full
```

### Example (Router API with Clap - Recommended)

```rust
use sen::{Args, CliResult, Router, State};
use clap::Parser;

// 1. Define application state
#[derive(Clone)]
pub struct AppState {
    pub config: String,
}

// 2. Define arguments with Clap derive macro
//    These types are automatically parsed by SEN when clap feature is enabled
#[derive(Parser, Debug)]
struct BuildArgs {
    /// Build in release mode
    #[arg(long)]
    release: bool,

    /// Number of parallel jobs
    #[arg(short, long, default_value = "4")]
    jobs: usize,
}

// Add descriptions to handlers with #[sen::handler] macro (Router API)
// Or use #[sen(desc = "...")] for Enum API (see below)

#[derive(Parser, Debug)]
struct DeployArgs {
    /// Target environment (positional argument)
    environment: String,

    /// Docker image tag
    #[arg(long, default_value = "latest")]
    tag: String,
}

// 3. Implement handlers as async functions
//    Handlers can accept State, Args, or both in any order
//    Use #[sen::handler(desc = "...")] to add descriptions for help
mod handlers {
    use super::*;

    // Handler with State only (no arguments)
    // You can also use: #[sen::handler(desc = "Show application status")]
    pub async fn status(state: State<AppState>) -> CliResult<String> {
        let app = state.read().await;
        Ok(format!("Status: OK (config: {})", app.config))
    }

    // Handler with State + Args
    // Args(args): Args<BuildArgs> - Clap automatically parses CLI arguments here!
    #[sen::handler(desc = "Build the project")]
    pub async fn build(
        state: State<AppState>,
        Args(args): Args<BuildArgs>,  // ๐Ÿ‘ˆ Automatic parsing via Clap!
    ) -> CliResult<String> {
        let app = state.read().await;
        let mode = if args.release { "release" } else { "debug" };
        Ok(format!("Building in {} mode with {} jobs (config: {})",
                   mode, args.jobs, app.config))
    }

    // Order doesn't matter! Args can come before State
    #[sen::handler(desc = "Deploy to environment")]
    pub async fn deploy(
        Args(args): Args<DeployArgs>,  // ๐Ÿ‘ˆ Clap parses from CLI automatically!
        state: State<AppState>,
    ) -> CliResult<String> {
        let app = state.read().await;
        Ok(format!("Deploying to {} with tag {} (config: {})",
                   args.environment, args.tag, app.config))
    }
}

// 4. Wire it up with Router (< 30 lines of main.rs)
#[tokio::main]
async fn main() {
    // Create application state (shared across all handlers)
    let state = AppState {
        config: "production".to_string(),
    };

    // Build the router with command โ†’ handler mappings
    // Use #[sen::sen()] macro to set CLI metadata
    let router = build_router(state);

    // Execute the command from CLI arguments
    let response = router.execute().await;

    // Print output and exit with proper code
    if !response.output.is_empty() {
        println!("{}", response.output);
    }
    std::process::exit(response.exit_code);
}

// Set CLI metadata with #[sen::sen()] macro
#[sen::sen(
    name = "myapp",
    version = "1.0.0",
    about = "My awesome CLI application"
)]
fn build_router(state: AppState) -> Router<()> {
    Router::new()
        .route("status", handlers::status)   // myapp status
        .route("build", handlers::build)     // myapp build [--release] [--jobs N]
        .route("deploy", handlers::deploy)   // myapp deploy <env> [--tag TAG]
        .with_state(state)                   // Inject state into all handlers
}
```

**Usage:**
```bash
myapp status                              # No arguments
myapp build --release --jobs 8            # With arguments
myapp deploy production --tag v1.2.3      # Positional + flags
myapp --help                              # Hierarchical help
myapp build --help                        # Clap auto-generates detailed help
```

**Hierarchical `--help` output** (automatically generated):
```
myapp 1.0.0
My awesome CLI application

Usage: myapp [OPTIONS] <COMMAND>

Other Commands:
  build   Build the project
  deploy  Deploy to environment
  status

Options:
  -h, --help            Print help
      --help --json     Show CLI schema (JSON format)
  -V, --version         Print version
```

**Per-command `--help`** (via Clap):
```
$ myapp build --help
Usage: cmd [OPTIONS]

Options:
      --release          Build in release mode
  -j, --jobs <JOBS>      Number of parallel jobs [default: 4]
  -h, --help             Print help
```

### Example (Enum API with Clap - Type-safe alternative)

```rust
use sen::{Args, CliResult, State, SenRouter};
use clap::Parser;

// 1. Define application state
#[derive(Clone)]
pub struct AppState {
    pub config: String,
}

// 2. Define arguments with Clap derive macro
//    Same as Router API - just derive Parser on your argument types
#[derive(Parser, Debug)]
struct BuildArgs {
    /// Build in release mode
    #[arg(long)]
    release: bool,

    /// Number of parallel jobs
    #[arg(short, long, default_value = "4")]
    jobs: usize,
}

#[derive(Parser, Debug)]
struct DeployArgs {
    /// Target environment (positional argument)
    environment: String,

    /// Docker image tag
    #[arg(long, default_value = "latest")]
    tag: String,
}

// 3. Define commands with SenRouter derive macro
//    This generates the execute() method and routing logic at compile-time
#[derive(SenRouter)]
#[sen(state = AppState)]  // Tell macro what State type to use
enum Commands {
    #[sen(handler = handlers::status, desc = "Show application status")]
    Status,  // No arguments

    #[sen(handler = handlers::build, desc = "Build the project")]
    Build(BuildArgs),  // With Clap-parsed arguments

    #[sen(handler = handlers::deploy, desc = "Deploy to environment")]
    Deploy(DeployArgs),  // Compiler checks ALL variants have handlers!
}

// The macro also generates Commands::help() for displaying all commands
// Example: println!("{}", Commands::help());

// 4. Implement handlers as async functions
//    Same signature style as Router API
mod handlers {
    use super::*;

    // Handler with State only
    pub async fn status(state: State<AppState>) -> CliResult<String> {
        let app = state.read().await;
        Ok(format!("Status: OK (config: {})", app.config))
    }

    // Handler with State + Args
    pub async fn build(
        state: State<AppState>,
        Args(args): Args<BuildArgs>,  // ๐Ÿ‘ˆ Clap automatically parses here!
    ) -> CliResult<String> {
        let app = state.read().await;
        let mode = if args.release { "release" } else { "debug" };
        Ok(format!("Building in {} mode with {} jobs (config: {})",
                   mode, args.jobs, app.config))
    }

    // Order doesn't matter! Args can come before State
    pub async fn deploy(
        Args(args): Args<DeployArgs>,  // ๐Ÿ‘ˆ Automatic parsing via Clap!
        state: State<AppState>,
    ) -> CliResult<String> {
        let app = state.read().await;
        Ok(format!("Deploying to {} with tag {} (config: {})",
                   args.environment, args.tag, app.config))
    }
}

// 5. Wire it up (< 30 lines of main.rs)
#[tokio::main]
async fn main() {
    // Create application state (shared across all handlers)
    let state = State::new(AppState {
        config: "production".to_string(),
    });

    // Parse command from CLI arguments (your parsing logic)
    let cmd = Commands::parse();

    // Execute! The macro-generated execute() method handles routing
    let response = cmd.execute(state).await;

    // Print output and exit with proper code
    if !response.output.is_empty() {
        println!("{}", response.output);
    }
    std::process::exit(response.exit_code);
}
```

**Key Features of Enum API:**
- **Compile-time safety**: `#[derive(SenRouter)]` macro generates the `execute()` method
- **Exhaustive matching**: Compiler ensures all commands have handlers
- **Clap integration**: Just add `#[derive(Parser)]` to argument types
- **Type-driven DI**: Automatically injects `State<T>` and `Args<T>` based on handler signatures

## ๐Ÿ“ Project Structure

SEN enforces clean file separation from day one:

```
my-cli/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs              # Entry point only (< 50 lines)
โ”‚   โ”œโ”€โ”€ handlers/            # One file per command
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ status.rs
โ”‚   โ”‚   โ”œโ”€โ”€ build.rs
โ”‚   โ”‚   โ””โ”€โ”€ test.rs
โ”‚   โ”œโ”€โ”€ workflows/           # Multi-task operations
โ”‚   โ”‚   โ””โ”€โ”€ preflight.rs     # fmt โ†’ lint โ†’ test
โ”‚   โ”œโ”€โ”€ tasks/               # Atomic operations
โ”‚   โ”‚   โ”œโ”€โ”€ fmt.rs
โ”‚   โ”‚   โ””โ”€โ”€ lint.rs
โ”‚   โ””โ”€โ”€ lib.rs               # Re-exports
```

**Why?**
- Each command is independently testable
- No `println!` debugging (handlers return structured data)
- Impossible to create "1000-line main.rs"
- AI agents can understand and modify specific commands easily

## ๐ŸŽจ Key Features

### 1. Flexible Routing - Choose Your Style

**Router API (Axum-style)** - Dynamic and flexible:
```rust
// Register handlers dynamically
let router = Router::new()
    .route("status", handlers::status)
    .route("build", handlers::build)
    .with_state(app_state);

// Easy to integrate with existing CLIs
let response = router.execute(&args).await;
```

**Enum API** - Compile-time safety:
```rust
#[derive(SenRouter)]
#[sen(state = AppState)]
enum Commands {
    #[sen(handler = handlers::status)]  // Typo? Compile error!
    Status,
}
```

Both approaches are supported - choose based on your needs:
- **Router API**: Better for gradual migration, dynamic routes, existing CLIs
- **Enum API**: Better for new projects, compile-time exhaustiveness checking

### 2. Axum-Style Handler Signatures

```rust
// Order doesn't matter!
pub async fn handler1(state: State<App>, args: Args) -> CliResult<String>
pub async fn handler2(args: Args, state: State<App>) -> CliResult<String>

// State optional
pub async fn handler3(args: Args) -> CliResult<()>
```

### 3. Smart Error Handling

```rust
pub enum CliError {
    User(UserError),      // Exit code 1: user can fix
    System(SystemError),  // Exit code 101: bug/system failure
}
```

Errors automatically format with helpful hints:

```
Error: Invalid argument '--foo'

The value 'bar' is not supported.

Hint: Use one of: baz, qux
```

### 4. Professional Help Generation

**Automatic hierarchical grouping** - Commands are organized by prefix:

```
$ myctl --help

Configuration Commands:
  edit      Edit configuration in editor
  init      Initialize configuration file
  show      Show current configuration

Database Commands:
  create    Create a new database
  delete    Delete a database
  list      List all databases

Server Commands:
  start     Start server instances
  stop      Stop server instances
```

**Clap integration** - Per-command help with full argument details:

```
$ myctl db create --help
Usage: cmd [OPTIONS] <NAME>

Arguments:
  <NAME>  Database name

Options:
      --size <SIZE>      Storage size [default: 10GB]
      --engine <ENGINE>  Database engine [default: postgres]
  -h, --help             Print help
```

**JSON schema export** for AI agents and IDEs:

```bash
$ myctl --help --json
{
  "commands": {
    "db:create": {
      "description": "Create a new database",
      "arguments": [...],
      "options": [...]
    }
  }
}
```

**How grouping works:**
- Commands with `:` prefix are automatically grouped (e.g., `db:create` โ†’ "Database Commands")
- Commands are displayed with just the suffix (e.g., `create` instead of `db:create`)
- Groups are sorted alphabetically, with "Other Commands" last
- Use `#[sen::handler(desc = "...")]` to add descriptions

### 5. No Println! in Handlers

Handlers return structured data, framework handles output:

```rust
// โŒ Bad: Can't test, can't redirect
pub async fn status() -> CliResult<()> {
    println!("Status: OK");
    Ok(())
}

// โœ… Good: Testable, flexible
pub async fn status() -> CliResult<StatusReport> {
    Ok(StatusReport { status: "OK" })
}
```

## ๐Ÿค– Agent Mode (Machine-Readable Output)

SEN provides **automatic** AI agent integration through built-in `--agent-mode` flag support.

### Automatic Agent Mode (Recommended)

Simply call `.with_agent_mode()` and the framework handles everything:

```rust
use sen::Router;

#[tokio::main]
async fn main() {
    let router = Router::new()
        .route("build", handlers::build)
        .with_agent_mode()  // Enable automatic --agent-mode support
        .with_state(state);

    let response = router.execute().await;

    // Automatically outputs JSON if --agent-mode was passed
    if response.agent_mode {
        println!("{}", response.to_agent_json());
    } else {
        if !response.output.is_empty() {
            println!("{}", response.output);
        }
    }

    std::process::exit(response.exit_code);
}
```

**User runs:**
```bash
myapp build              # Normal text output
myapp --agent-mode build # JSON output
```

### How It Works

1. **Router detects** `--agent-mode` flag automatically
2. **Strips the flag** before passing args to handlers
3. **Sets `response.agent_mode = true`** for your output logic
4. **Zero boilerplate** - no manual arg parsing needed

### Example Output

```json
{
  "result": "success",
  "exit_code": 0,
  "output": "Build completed successfully",
  "tier": "safe",
  "tags": ["build", "production"],
  "sensors": {
    "timestamp": "2024-01-15T10:30:00Z",
    "os": "macos",
    "cwd": "/Users/user/project"
  }
}
```

### Advanced: Manual Agent Mode

For complex scenarios with global options, you can still manually implement agent mode (see `examples/practical-cli`).

### Features

- **Automatic `--agent-mode` detection**: Framework handles flag parsing
- **`to_agent_json()`**: Converts `Response` to structured JSON
- **Environment Sensors**: Automatic collection of system metadata (requires `sensors` feature)
- **Tier & Tags**: Safety tier and command categorization metadata
- **Structured Errors**: Exit codes and error messages in machine-readable format

## ๐Ÿ’ก Argument Parsing: Clap Integration (Recommended)

SEN has **built-in Clap integration** - the de-facto standard for Rust CLI argument parsing.

### ๐Ÿš€ Use Clap (Recommended for 99% of CLIs)

Simply derive `clap::Parser` on your argument types:

**Step 1**: Enable the `clap` feature:

```toml
[dependencies]
sen = { version = "0.1", features = ["clap"] }
clap = { version = "4", features = ["derive"] }
```

**Step 2**: Define arguments with `#[derive(Parser)]`:

```rust
use sen::{Args, CliResult};
use clap::Parser;

#[derive(Parser, Debug)]
struct BuildArgs {
    /// Build in release mode
    #[arg(long)]
    release: bool,

    /// Number of parallel jobs
    #[arg(short, long, default_value = "4")]
    jobs: usize,
}

async fn build(Args(args): Args<BuildArgs>) -> CliResult<String> {
    let mode = if args.release { "release" } else { "debug" };
    Ok(format!("Building in {} mode with {} jobs", mode, args.jobs))
}
```

**Step 3**: Register the handler - that's it!

```rust
let router = Router::new()
    .route("build", build)
    .with_state(state);
```

**How it works**: When the `clap` feature is enabled, SEN automatically implements `FromArgs` for any type implementing `clap::Parser`. Zero boilerplate required.

**Benefits**:
- โœ… Automatic help generation (`--help`)
- โœ… Type-safe with compile-time validation
- โœ… Supports complex options (enums, lists, subcommands)
- โœ… Battle-tested (used by cargo, ripgrep, etc.)
- โœ… **Recommended for all production CLIs**

**Example `--help` output** (auto-generated from your `#[arg]` attributes):
```bash
$ myapp build --help
Usage: myapp build [OPTIONS]

Options:
      --release          Build in release mode
  -j, --jobs <JOBS>      Number of parallel jobs [default: 4]
  -h, --help             Print help
```

All the documentation comments (`///`) in your struct become help text automatically!

### Global Options (For CLI-wide Flags)

For applications with global flags that apply to all commands:

```rust
use sen::FromGlobalArgs;

#[derive(Clone)]
pub struct GlobalOpts {
    pub verbose: bool,
    pub config_path: String,
}

impl FromGlobalArgs for GlobalOpts {
    fn from_global_args(args: &[String]) -> Result<(Self, Vec<String>), CliError> {
        let mut verbose = false;
        let mut config_path = "~/.config/myapp".to_string();
        let mut remaining_args = Vec::new();

        for arg in args {
            match arg.as_str() {
                "--verbose" | "-v" => verbose = true,
                "--config" => { /* handle next arg */ }
                _ => remaining_args.push(arg.clone()),
            }
        }

        Ok((GlobalOpts { verbose, config_path }, remaining_args))
    }
}
```

**Use Global Options when:**
- โœ… You need flags that apply to **all** commands (`--verbose`, `--config`)
- โœ… You want integration with `clap` or other parsers
- โœ… You have complex validation or conflicting flag logic
- โœ… Building a production CLI (like `practical-cli` example)

### Why practical-cli Uses Global Options

The `practical-cli` example intentionally uses `FromGlobalArgs` instead of `FromArgs`:

1. **Global flags**: `--verbose` and `--config` apply to all commands
2. **`clap` integration**: Uses `clap::Command` for help generation
3. **Flexibility**: Manual parsing allows complex validation
4. **Real-world pattern**: Mirrors production CLI tools like `kubectl`, `docker`, etc.

**Key Insight:** For complex CLIs with global flags, use `FromGlobalArgs` to parse them once, then use Clap's `#[derive(Parser)]` for per-command arguments.

See `examples/practical-cli` for a complete production-ready example showing:
- Global flags with `FromGlobalArgs`
- Per-command arguments with Clap's `#[derive(Parser)]`
- Nested routers for organizing commands by resource

### Advanced: Manual `FromArgs` Implementation (Rarely Needed)

If you need custom parsing logic and **cannot** use Clap, you can manually implement `FromArgs`:

```rust
use sen::{Args, FromArgs, CliError, CliResult};

#[derive(Debug)]
struct CustomArgs {
    flag: bool,
}

impl FromArgs for CustomArgs {
    fn from_args(args: &[String]) -> Result<Self, CliError> {
        // Your custom parsing logic
        Ok(CustomArgs {
            flag: args.contains(&"--flag".to_string()),
        })
    }
}

async fn handler(Args(args): Args<CustomArgs>) -> CliResult<String> {
    Ok(format!("Flag: {}", args.flag))
}
```

**Only use manual `FromArgs` when:**
- โŒ Clap doesn't support your use case (very rare)
- โŒ You need parsing logic that's impossible to express in Clap
- โŒ You're integrating with a non-Clap parser

**For 99% of use cases, use Clap's `#[derive(Parser)]` instead.**

## ๐Ÿ—๏ธ Architecture

SEN follows a three-layer design:

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Router Layer (Compile-time)            โ”‚
โ”‚  - Enum-based command tree              โ”‚
โ”‚  - Handler binding via proc macros      โ”‚
โ”‚  - Type-safe routing                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Handler Layer (Runtime)                โ”‚
โ”‚  - Dependency injection (State, Args)   โ”‚
โ”‚  - Business logic execution             โ”‚
โ”‚  - Result<T, E> return type             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Response Layer (Exit)                  โ”‚
โ”‚  - Exit code mapping (0, 1, 101)        โ”‚
โ”‚  - Structured output (JSON/Human)       โ”‚
โ”‚  - Logging & telemetry                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

See [DESIGN.md](./docs/DESIGN.md) for full architecture details.

## ๐Ÿ“š Examples

Check out the [examples/simple-cli](./examples/simple-cli) directory for a working CLI with:
- Status command (no args)
- Build command (with `--release` flag)
- Test command (with optional filter)
- Proper error handling

Run it:

```bash
cd examples/simple-cli
cargo build
./target/debug/admin status
./target/debug/admin build --release
./target/debug/admin test my_test
```

## ๐Ÿงช Testing

```bash
# Run all tests
cargo test

# Test specific crate
cargo test -p sen
cargo test -p sen-rs-macros
```

## ๐Ÿ“– Documentation

- [DESIGN.md]./docs/DESIGN.md - Complete design document

## ๐Ÿ›ฃ๏ธ Roadmap

- [x] Phase 1: Core framework (State, CliResult, IntoResponse)
- [x] Phase 2: Macro system (#[derive(SenRouter)])
- [ ] Phase 3: Advanced features (ReloadableConfig, tracing)
- [ ] Phase 4: Developer experience (CLI generator, templates)

## ๐Ÿค Contributing

Contributions welcome! Please read [DESIGN.md](./docs/DESIGN.md) to understand the architecture first.

## ๐Ÿ“œ License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## ๐Ÿ™ Inspiration

SEN is inspired by:
- [Axum]https://github.com/tokio-rs/axum - Type-safe handler functions
- [Clap]https://github.com/clap-rs/clap - CLI argument parsing
- The philosophy of Anti-Fragility and Fixed Workflows

---

**SEN** (็ทš/ๅ…ˆ): The Line to Success, Leading the Future of CLI Development