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
//! Modern CLI command architecture
//!
//! This module provides a unified command architecture with:
//! - **Command Trait**: Standard interface for all commands
//! - **Command Pipeline**: Orchestrates execution with middleware
//! - **Middleware System**: Cross-cutting concerns (logging, metrics, validation)
//! - **Command Context**: Shared state and configuration
//! - **Structured Output**: Type-safe command results
//!
//! # Architecture
//!
//! The CLI architecture follows a pipeline pattern:
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────┐
//! │ CommandPipeline │
//! ├─────────────────────────────────────────────────────────┤
//! │ 1. Run pre-execution middleware (logging, setup) │
//! │ 2. Validate command arguments and context │
//! │ 3. Execute command with shared context │
//! │ 4. Run post-execution middleware (metrics, cleanup) │
//! │ 5. Handle errors and format output │
//! └─────────────────────────────────────────────────────────┘
//! ```
//!
//! # Usage
//!
//! ## Creating a Command
//!
//! ```ignore
//! use inferno::interfaces::cli::{Command, CommandContext, CommandOutput};
//! use async_trait::async_trait;
//! use anyhow::Result;
//!
//! pub struct MyCommand {
//! arg1: String,
//! arg2: i32,
//! }
//!
//! #[async_trait]
//! impl Command for MyCommand {
//! fn name(&self) -> &str {
//! "my-command"
//! }
//!
//! fn description(&self) -> &str {
//! "Does something useful"
//! }
//!
//! async fn execute(&self, ctx: &mut CommandContext) -> Result<CommandOutput> {
//! // Access config
//! let models_dir = &ctx.config.models_dir;
//!
//! // Use command args
//! let arg1 = &self.arg1;
//!
//! // Do work...
//!
//! // Return structured output
//! Ok(CommandOutput::success("Command completed successfully"))
//! }
//! }
//! ```
//!
//! ## Executing a Command
//!
//! ```ignore
//! use inferno::interfaces::cli::CommandPipeline;
//!
//! let pipeline = CommandPipeline::builder()
//! .with_logging()
//! .with_metrics()
//! .build();
//!
//! let command = MyCommand {
//! arg1: "value".to_string(),
//! arg2: 42,
//! };
//!
//! let mut ctx = CommandContext::new(config);
//! let output = pipeline.execute(&command, &mut ctx).await?;
//!
//! if output.success {
//! println!("{}", output.to_display());
//! } else {
//! std::process::exit(output.exit_code);
//! }
//! ```
//!
//! ## Creating Middleware
//!
//! ```ignore
//! use inferno::interfaces::cli::{Middleware, CommandContext, CommandOutput};
//! use async_trait::async_trait;
//! use anyhow::Result;
//!
//! pub struct LoggingMiddleware;
//!
//! #[async_trait]
//! impl Middleware for LoggingMiddleware {
//! async fn before(&self, ctx: &mut CommandContext) -> Result<()> {
//! tracing::info!("Starting command: {}", ctx.execution_id);
//! Ok(())
//! }
//!
//! async fn after(&self, ctx: &mut CommandContext, result: &Result<CommandOutput>) -> Result<()> {
//! tracing::info!("Finished command in {:?}", ctx.elapsed());
//! Ok(())
//! }
//!
//! fn name(&self) -> &str {
//! "logging"
//! }
//! }
//! ```
//!
//! # Benefits
//!
//! - **Reduced Duplication**: Cross-cutting concerns handled once in middleware
//! - **Better Testing**: Commands can be tested in isolation with mock context
//! - **Consistent Behavior**: All commands get logging, metrics, error handling
//! - **Extensibility**: Easy to add new middleware or commands
//! - **Type Safety**: Compile-time guarantees for command structure
//!
//! # Migration
//!
//! The old command pattern is still supported for backward compatibility:
//!
//! ```ignore
//! // Old style (still works)
//! pub async fn execute(args: CommandArgs, config: &Config) -> Result<()> {
//! // Command logic
//! }
//!
//! // New style (recommended)
//! pub struct CommandImpl { args: CommandArgs }
//!
//! #[async_trait]
//! impl Command for CommandImpl {
//! async fn execute(&self, ctx: &mut CommandContext) -> Result<CommandOutput> {
//! // Command logic with context
//! }
//! }
//! ```
//!
//! See `.claude/plans/phase2-cli-architecture.md` for migration guide.
// Re-export main types for convenience
pub use ;
pub use CommandContext;
pub use ;
pub use ;
pub use ;