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
// 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("profile")
.long("profile")
.short('P')
.help("Use a saved connection profile instead of manual flags")
.required(false)
.value_name("PROFILE")
)
.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("url")
.long("url")
.help("Custom transformer server URL (HTTPS preferred)")
.required(false)
.value_name("URL")
)
.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 (local .json file or remote registry name)")
.value_name("FILE")
.num_args(1)
)
)
.subcommand(
Command::new("profile")
.about("Manage connection profiles in the Cargo-AI config file")
.subcommand(
Command::new("list")
.about("List all configured profiles")
)
.subcommand(
Command::new("show")
.about("Show detailed information for a specific profile")
.arg(
Arg::new("name")
.help("Name of the profile to display")
.required(true)
.value_name("NAME")
)
)
.subcommand(
Command::new("add")
.about("Add a new connection profile or overwrite an existing one")
.arg(
Arg::new("name")
.help("Name of the profile to add or update")
.required(true)
.value_name("NAME")
)
.arg(
Arg::new("server")
.long("server")
.short('s')
.help("LLM server (e.g., openai or ollama)")
.required(true)
.value_name("SERVER")
)
.arg(
Arg::new("model")
.long("model")
.short('m')
.help("LLM model identifier (e.g., gpt-4o, mistral)")
.required(true)
.value_name("MODEL")
)
.arg(
Arg::new("url")
.long("url")
.help("Custom transformer server URL (HTTPS preferred)")
.required(false)
.value_name("URL")
)
.arg(
Arg::new("token")
.long("token")
.help("API token for the server")
.required(false)
.value_name("TOKEN")
)
.arg(
Arg::new("description")
.long("description")
.short('d')
.help("Optional description for the profile")
.required(false)
.value_name("TEXT")
)
.arg(
Arg::new("default")
.long("default")
.help("Set this profile as the default")
.action(clap::ArgAction::SetTrue)
)
)
.subcommand(
Command::new("remove")
.about("Remove an existing connection profile by name")
.arg(
Arg::new("name")
.help("Name of the profile to remove")
.required(true)
.value_name("NAME")
)
)
)
.get_matches_from(args)
}