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
// clap - Command Line Arguement Parsing
use clap::{Arg, ArgMatches, Command};
pub fn build_cli() -> ArgMatches {
// Collect the original command-line arguments
let mut args: Vec<String> = std::env::args().collect();
let mut bin_name = "cargo-ai";
// Check if runing as a cargo subcommand, i.e. cargo ai
if let Some(first_arg) = args.get(1) {
if first_arg == "ai" {
bin_name = "cargo ai";
args.remove(1);
}
}
Command::new("cargo-ai")
.bin_name(bin_name)
.version(env!("CARGO_PKG_VERSION"))
.subcommand(
Command::new("version")
.about("Print version information")
)
.subcommand(
Command::new("preflight")
.about("Internal: test agent config file")
.hide(true)
.arg(
Arg::new("server")
.long("server")
.short('s')
.value_name("CLIENT")
.help("Client Type - Ollama or OpenAI")
)
.arg(
Arg::new("model")
.long("model")
.short('m')
.value_name("MODEL")
.help("LLM model to use")
)
.arg(
Arg::new("token")
.long("token")
.value_name("TOKEN")
.help("API token"),
)
.arg(
Arg::new("timeout_in_sec")
.long("timeout_in_sec")
.value_name("SECONDS")
.help("Client timeout request")
.default_value("60")
)
.arg(
Arg::new("prompt")
.long("prompt")
.short('p')
.help("Prompt to provide to the agent at runtime")
.value_name("TEXT")
.num_args(1)
)
)
.subcommand(
Command::new("hatch")
.about("Hatch a new AI agent from a JSON config")
.arg(
Arg::new("name")
.help("Name of the new agent project")
.required(true)
)
.arg(
Arg::new("config")
.long("config")
.short('c')
.help("Path to the agent configuration file (JSON format)")
.value_name("FILE")
.num_args(1)
)
)
.get_matches_from(args)
}