oxi-cli 0.16.1

Terminal-based AI coding assistant — multi-provider, streaming-first, extensible
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
//! CLI argument parsing with clap
//!
//! Provides the unified command-line argument types for the oxi CLI.
//! This is the single source of truth for all CLI parsing — main.rs
//! imports from here rather than defining its own types.

use clap::{Parser, Subcommand};
use std::path::PathBuf;

// ── Re-exports ─────────────────────────────────────────────────────
// Use the canonical ThinkingLevel from settings (None/Minimal/Standard/Thorough).
pub use oxi_store::settings::ThinkingLevel;

// ── Main CLI arguments ─────────────────────────────────────────────

/// CLI arguments
#[derive(Debug, Clone, Parser)]
#[command(name = "oxi")]
#[command(about = "CLI coding harness for oxi")]
#[command(version)]
pub struct CliArgs {
    /// pub.
    #[command(subcommand)]
    pub command: Option<Commands>,

    /// Provider to use (e.g., anthropic, openai, google, deepseek)
    #[arg(short, long)]
    pub provider: Option<String>,

    /// Model to use (e.g., claude-sonnet-4-20250514, gpt-4o)
    #[arg(short, long)]
    pub model: Option<String>,

    /// Initial prompt (non-interactive mode)
    #[arg(default_value = "")]
    pub prompt: Vec<String>,

    /// Interactive mode (default when no prompt is given)
    #[arg(short, long)]
    pub interactive: bool,

    /// Thinking level (none, minimal, standard, thorough)
    #[arg(long)]
    pub thinking: Option<String>,

    /// Load an extension from a shared library (.so / .dll / .dylib).
    /// Can be specified multiple times.
    #[arg(short = 'e', long = "extension", value_name = "PATH")]
    pub extensions: Vec<PathBuf>,

    /// Output mode: text or json (newline-delimited JSON events)
    #[arg(long)]
    pub mode: Option<String>,

    /// Comma-separated list of tools to enable. Default: all builtins.
    #[arg(long)]
    pub tools: Option<String>,

    /// Append system prompt from a file
    #[arg(long)]
    pub append_system_prompt: Option<PathBuf>,

    /// Single-shot print mode (non-interactive)
    #[arg(long)]
    pub print: bool,

    /// Disable session persistence
    #[arg(long)]
    pub no_session: bool,

    /// Timeout in seconds for print mode
    #[arg(long)]
    pub timeout: Option<u64>,

    /// Resume the most recent session for this project
    #[arg(short, long)]
    pub continue_session: bool,
}

// ── Subcommands ────────────────────────────────────────────────────

/// CLI subcommands
#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
    /// List all sessions.
    Sessions,
    /// Show session tree structure.
    Tree {
        /// Session ID to show tree for (default: current/last session)
        #[arg(default_value = "")]
        session_id: String,
    },
    /// Fork a new session from a specific entry
    Fork {
        /// Parent session ID
        parent_id: String,
        /// Entry ID to branch from
        entry_id: String,
    },
    /// Delete a session
    Delete {
        /// Session ID to delete
        session_id: String,
    },
    /// Package management
    Pkg {
        /// action.
        #[command(subcommand)]
        action: PkgCommands,
    },
    /// Configuration management
    Config {
        /// action.
        #[command(subcommand)]
        action: ConfigCommands,
    },
    /// Extension management — install, update, remove WASM extensions
    Ext {
        /// action.
        #[command(subcommand)]
        action: ExtCommands,
    },
    /// List available models
    Models {
        /// Filter by provider name (e.g., openai, anthropic, minimax)
        #[arg(long)]
        provider: Option<String>,
    },
    /// Run the interactive setup wizard
    Setup {
        /// Reset all settings to defaults
        #[arg(long)]
        reset: bool,
    },
}

// ── Package subcommands ────────────────────────────────────────────

/// Package management subcommands
#[derive(Debug, Clone, Subcommand)]
pub enum PkgCommands {
    /// Install a package from a local path or npm:@scope/name
    Install {
        /// Package source: a local directory path or npm:@scope/name
        source: String,
    },
    /// List installed packages
    List,
    /// Uninstall a package by name
    Uninstall {
        /// Package name to uninstall
        name: String,
    },
    /// Update a package to the latest version
    Update {
        /// Package name to update (updates all if omitted)
        name: Option<String>,
    },
}

// ── Extension subcommands ──────────────────────────────────────────────

/// Extension management subcommands
#[derive(Debug, Clone, Subcommand)]
pub enum ExtCommands {
    /// Install a WASM extension from a GitHub repo (owner/repo or owner/repo@version)
    Install {
        /// Extension source: owner/repo or owner/repo@version
        source: String,
        /// Include pre-release versions
        #[arg(long)]
        prerelease: bool,
    },
    /// List installed extensions
    List,
    /// Remove an installed extension
    Remove {
        /// Extension name to remove
        name: String,
    },
    /// Update extension(s) to latest version
    Update {
        /// Extension name to update (updates all if omitted)
        name: Option<String>,
    },
    /// Show info about a remote extension (without installing)
    Info {
        /// Extension source: owner/repo
        source: String,
    },
}

// ── Config subcommands ─────────────────────────────────────────────

/// Configuration management subcommands
#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommands {
    /// Show current configuration
    Show,
    /// List all enabled resources
    List {
        /// Resource type filter (extensions, skills, prompts, themes)
        resource_type: Option<String>,
    },
    /// Enable a resource (extension, skill, prompt, or theme)
    Enable {
        /// Resource type: extension, skill, prompt, or theme
        resource_type: String,
        /// Resource path or name
        name: String,
    },
    /// Disable a resource
    Disable {
        /// Resource type: extension, skill, prompt, or theme
        resource_type: String,
        /// Resource path or name
        name: String,
    },
    /// Set a configuration value
    Set {
        /// Setting key (e.g. theme, default_model, thinking_level)
        key: String,
        /// Setting value
        value: String,
    },
    /// Get a configuration value
    Get {
        /// Setting key
        key: String,
    },
    /// Add a custom OpenAI-compatible provider
    AddProvider {
        /// Provider name (e.g. minimax)
        name: String,
        /// Base URL (e.g. https://api.minimax.chat/v1)
        base_url: String,
        /// Environment variable name for API key (e.g. MINIMAX_API_KEY)
        api_key_env: String,
        /// API type: openai-completions or openai-responses (default: openai-completions)
        #[arg(default_value = "openai-completions")]
        api: String,
    },
    /// Remove a custom provider
    RemoveProvider {
        /// Provider name to remove
        name: String,
    },
    /// Reset credentials (auth.json) and optionally settings
    Reset {
        /// Also reset settings (settings.toml / settings.json)
        #[arg(long, short)]
        all: bool,
    },
}

// ── Parsing helpers ────────────────────────────────────────────────

/// Parse CLI arguments from the command line
///
/// # Examples
///
/// ```ignore
/// use oxi_cli::CliArgs;
///
/// fn main() {
///     let args = CliArgs::parse();
///     match args.command {
///         Some(Commands::Sessions) => { /* list sessions */ }
///         Some(Commands::Tree { session_id }) => { /* show tree */ }
///         _ => { /* interactive mode */ }
///     }
/// }
/// ```
pub fn parse_args() -> CliArgs {
    CliArgs::parse()
}

/// Parse CLI arguments from a specific iterator
pub fn parse_args_from<I, T>(iter: I) -> Result<CliArgs, clap::Error>
where
    I: IntoIterator<Item = T>,
    T: Into<std::ffi::OsString> + Clone,
{
    CliArgs::try_parse_from(iter)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parse_basic_prompt() {
        let args = parse_args_from(["oxi", "Hello", "world"]).unwrap();
        assert_eq!(args.prompt, vec!["Hello", "world"]);
    }

    #[test]
    fn test_parse_with_provider_and_model() {
        let args = parse_args_from([
            "oxi",
            "--provider",
            "anthropic",
            "--model",
            "claude-sonnet-4-20250514",
            "Hello",
        ])
        .unwrap();
        assert_eq!(args.provider, Some("anthropic".to_string()));
        assert_eq!(args.model, Some("claude-sonnet-4-20250514".to_string()));
    }

    #[test]
    fn test_parse_interactive_flag() {
        let args = parse_args_from(["oxi", "-i"]).unwrap();
        assert!(args.interactive);
    }

    #[test]
    fn test_parse_extension_paths() {
        let args =
            parse_args_from(["oxi", "-e", "/path/to/ext.so", "-e", "/other/ext.so"]).unwrap();
        assert_eq!(args.extensions.len(), 2);
    }

    #[test]
    fn test_parse_sessions_command() {
        let args = parse_args_from(["oxi", "sessions"]).unwrap();
        assert!(matches!(args.command, Some(Commands::Sessions)));
    }

    #[test]
    fn test_parse_tree_command() {
        let args = parse_args_from(["oxi", "tree", "abc-123"]).unwrap();
        match args.command {
            Some(Commands::Tree { session_id }) => {
                assert_eq!(session_id, "abc-123");
            }
            _ => panic!("Expected Tree command"),
        }
    }

    #[test]
    fn test_parse_tree_command_default() {
        let args = parse_args_from(["oxi", "tree"]).unwrap();
        match args.command {
            Some(Commands::Tree { session_id }) => {
                assert_eq!(session_id, "");
            }
            _ => panic!("Expected Tree command"),
        }
    }

    #[test]
    fn test_parse_fork_command() {
        let args = parse_args_from(["oxi", "fork", "parent-id", "entry-id"]).unwrap();
        match args.command {
            Some(Commands::Fork {
                parent_id,
                entry_id,
            }) => {
                assert_eq!(parent_id, "parent-id");
                assert_eq!(entry_id, "entry-id");
            }
            _ => panic!("Expected Fork command"),
        }
    }

    #[test]
    fn test_parse_delete_command() {
        let args = parse_args_from(["oxi", "delete", "session-123"]).unwrap();
        match args.command {
            Some(Commands::Delete { session_id }) => {
                assert_eq!(session_id, "session-123");
            }
            _ => panic!("Expected Delete command"),
        }
    }

    #[test]
    fn test_parse_pkg_install() {
        let args = parse_args_from(["oxi", "pkg", "install", "npm:@scope/name"]).unwrap();
        match args.command {
            Some(Commands::Pkg { action }) => match action {
                PkgCommands::Install { source } => {
                    assert_eq!(source, "npm:@scope/name");
                }
                _ => panic!("Expected Install subcommand"),
            },
            _ => panic!("Expected Pkg command"),
        }
    }

    #[test]
    fn test_parse_pkg_list() {
        let args = parse_args_from(["oxi", "pkg", "list"]).unwrap();
        match args.command {
            Some(Commands::Pkg { action }) => {
                assert!(matches!(action, PkgCommands::List));
            }
            _ => panic!("Expected Pkg command"),
        }
    }

    #[test]
    fn test_parse_pkg_update_all() {
        let args = parse_args_from(["oxi", "pkg", "update"]).unwrap();
        match args.command {
            Some(Commands::Pkg { action }) => match action {
                PkgCommands::Update { name } => assert!(name.is_none()),
                _ => panic!("Expected Update subcommand"),
            },
            _ => panic!("Expected Pkg command"),
        }
    }

    #[test]
    fn test_parse_pkg_update_named() {
        let args = parse_args_from(["oxi", "pkg", "update", "my-pkg"]).unwrap();
        match args.command {
            Some(Commands::Pkg { action }) => match action {
                PkgCommands::Update { name } => assert_eq!(name, Some("my-pkg".to_string())),
                _ => panic!("Expected Update subcommand"),
            },
            _ => panic!("Expected Pkg command"),
        }
    }

    #[test]
    fn test_parse_config_show() {
        let args = parse_args_from(["oxi", "config", "show"]).unwrap();
        assert!(matches!(
            args.command,
            Some(Commands::Config {
                action: ConfigCommands::Show
            })
        ));
    }

    #[test]
    fn test_parse_config_set() {
        let args = parse_args_from(["oxi", "config", "set", "theme", "dracula"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::Set { key, value } => {
                    assert_eq!(key, "theme");
                    assert_eq!(value, "dracula");
                }
                _ => panic!("Expected Set subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_get() {
        let args = parse_args_from(["oxi", "config", "get", "theme"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::Get { key } => {
                    assert_eq!(key, "theme");
                }
                _ => panic!("Expected Get subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_enable() {
        let args = parse_args_from(["oxi", "config", "enable", "extension", "my-ext"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::Enable {
                    resource_type,
                    name,
                } => {
                    assert_eq!(resource_type, "extension");
                    assert_eq!(name, "my-ext");
                }
                _ => panic!("Expected Enable subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_disable() {
        let args = parse_args_from(["oxi", "config", "disable", "skill", "my-skill"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::Disable {
                    resource_type,
                    name,
                } => {
                    assert_eq!(resource_type, "skill");
                    assert_eq!(name, "my-skill");
                }
                _ => panic!("Expected Disable subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_list() {
        let args = parse_args_from(["oxi", "config", "list"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::List { resource_type } => {
                    assert!(resource_type.is_none());
                }
                _ => panic!("Expected List subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_list_filtered() {
        let args = parse_args_from(["oxi", "config", "list", "extensions"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::List { resource_type } => {
                    assert_eq!(resource_type, Some("extensions".to_string()));
                }
                _ => panic!("Expected List subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_thinking_level_reexport() {
        // Verify the re-export from settings works
        assert_eq!(format!("{:?}", ThinkingLevel::Medium), "Medium");
    }

    #[test]
    fn test_parse_config_add_provider() {
        let args = parse_args_from([
            "oxi",
            "config",
            "add-provider",
            "minimax",
            "https://api.minimax.chat/v1",
            "MINIMAX_API_KEY",
            "openai-completions",
        ])
        .unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::AddProvider {
                    name,
                    base_url,
                    api_key_env,
                    api,
                } => {
                    assert_eq!(name, "minimax");
                    assert_eq!(base_url, "https://api.minimax.chat/v1");
                    assert_eq!(api_key_env, "MINIMAX_API_KEY");
                    assert_eq!(api, "openai-completions");
                }
                _ => panic!("Expected AddProvider subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_add_provider_default_api() {
        let args = parse_args_from([
            "oxi",
            "config",
            "add-provider",
            "zai",
            "https://api.z.ai/v1",
            "ZAI_API_KEY",
        ])
        .unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::AddProvider {
                    name,
                    base_url,
                    api_key_env,
                    api,
                } => {
                    assert_eq!(name, "zai");
                    assert_eq!(base_url, "https://api.z.ai/v1");
                    assert_eq!(api_key_env, "ZAI_API_KEY");
                    assert_eq!(api, "openai-completions"); // default
                }
                _ => panic!("Expected AddProvider subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_config_remove_provider() {
        let args = parse_args_from(["oxi", "config", "remove-provider", "minimax"]).unwrap();
        match args.command {
            Some(Commands::Config { action }) => match action {
                ConfigCommands::RemoveProvider { name } => {
                    assert_eq!(name, "minimax");
                }
                _ => panic!("Expected RemoveProvider subcommand"),
            },
            _ => panic!("Expected Config command"),
        }
    }

    #[test]
    fn test_parse_models_command() {
        let args = parse_args_from(["oxi", "models"]).unwrap();
        match args.command {
            Some(Commands::Models { provider }) => {
                assert!(provider.is_none());
            }
            _ => panic!("Expected Models command"),
        }
    }

    #[test]
    fn test_parse_models_with_provider() {
        let args = parse_args_from(["oxi", "models", "--provider", "minimax"]).unwrap();
        match args.command {
            Some(Commands::Models { provider }) => {
                assert_eq!(provider, Some("minimax".to_string()));
            }
            _ => panic!("Expected Models command"),
        }
    }

    #[test]
    fn test_parse_setup_command() {
        let args = parse_args_from(["oxi", "setup"]).unwrap();
        match args.command {
            Some(Commands::Setup { reset }) => {
                assert!(!reset);
            }
            _ => panic!("Expected Setup command"),
        }
    }

    #[test]
    fn test_parse_setup_reset() {
        let args = parse_args_from(["oxi", "setup", "--reset"]).unwrap();
        match args.command {
            Some(Commands::Setup { reset }) => {
                assert!(reset);
            }
            _ => panic!("Expected Setup command with reset"),
        }
    }
}