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
//! 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 crate::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,
}
// ── 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,
},
}
// ── 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>,
},
}
// ── 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,
},
}
// ── 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::Standard),
"Standard"
);
}
}