|
1
|
//! The `si` command tree. |
|
2
|
|
|
3
|
use {clap::Parser, sigit_si_api::Environment, std::str::FromStr}; |
|
4
|
|
|
5
|
#[derive(Parser)] |
|
6
|
#[command(name = "si", version, about = "The sigit.si command line interface.")] |
|
7
|
pub struct Cli { |
|
8
|
/// Which sigit.si deployment to talk to. Overridden by SIGIT_HOST. |
|
9
|
#[arg(short, long, global = true, env = "SIGIT_ENVIRONMENT", default_value = "production", value_parser = Environment::from_str)] |
|
10
|
pub environment: Environment, |
|
11
|
|
|
12
|
/// Print machine-readable JSON instead of formatted text, where supported. |
|
13
|
#[arg(long, global = true)] |
|
14
|
pub json: bool, |
|
15
|
|
|
16
|
#[command(subcommand)] |
|
17
|
pub command: Command, |
|
18
|
} |
|
19
|
|
|
20
|
#[derive(clap::Subcommand)] |
|
21
|
pub enum Command { |
|
22
|
/// Sign in, sign out, and inspect your session. |
|
23
|
#[command(subcommand)] |
|
24
|
Auth(AuthCommand), |
|
25
|
|
|
26
|
/// Your sigit.si profile. |
|
27
|
Me, |
|
28
|
|
|
29
|
/// List, create, and inspect repositories. |
|
30
|
#[command(subcommand)] |
|
31
|
Repo(RepoCommand), |
|
32
|
|
|
33
|
/// List, open, and comment on pull requests. |
|
34
|
#[command(subcommand)] |
|
35
|
Pr(PrCommand), |
|
36
|
|
|
37
|
/// List, open, and comment on issues. |
|
38
|
#[command(subcommand)] |
|
39
|
Issue(IssueCommand), |
|
40
|
|
|
41
|
/// Read files and search code in a repository. |
|
42
|
#[command(subcommand)] |
|
43
|
Code(CodeCommand), |
|
44
|
|
|
45
|
/// Start and follow siGit Code Cloud Agent runs. |
|
46
|
#[command(subcommand)] |
|
47
|
Run(RunCommand), |
|
48
|
|
|
49
|
/// Publish a repository's default branch as a static site. |
|
50
|
#[command(subcommand)] |
|
51
|
Site(SiteCommand), |
|
52
|
|
|
53
|
/// Report and read commit statuses, the checks CI shows on a commit. |
|
54
|
#[command(subcommand)] |
|
55
|
Status(StatusCommand), |
|
56
|
|
|
57
|
/// Manage a repository's deploy webhooks. |
|
58
|
#[command(subcommand)] |
|
59
|
Hook(HookCommand), |
|
60
|
|
|
61
|
/// Manage siGit Code Cloud Sessions. |
|
62
|
#[command(subcommand)] |
|
63
|
Session(SessionCommand), |
|
64
|
|
|
65
|
/// Plan, usage, and the hosted billing portal. |
|
66
|
#[command(subcommand)] |
|
67
|
Billing(BillingCommand), |
|
68
|
|
|
69
|
/// List the models a session can use. |
|
70
|
Models, |
|
71
|
|
|
72
|
/// Open something on sigit.si in your browser. |
|
73
|
Browse(BrowseArgs), |
|
74
|
|
|
75
|
/// Call the sigit.si API directly. The escape hatch for anything without |
|
76
|
/// a dedicated command. |
|
77
|
Api(ApiArgs), |
|
78
|
|
|
79
|
/// Serve these commands to an AI agent as MCP tools over stdio. |
|
80
|
Mcp(McpArgs), |
|
81
|
} |
|
82
|
|
|
83
|
#[derive(clap::Subcommand)] |
|
84
|
pub enum AuthCommand { |
|
85
|
/// Sign in with your sigit.si email and password. |
|
86
|
Login { |
|
87
|
#[arg(long)] |
|
88
|
email: Option<String>, |
|
89
|
}, |
|
90
|
/// Sign out and remove the stored token. |
|
91
|
Logout, |
|
92
|
/// Show who is currently signed in. |
|
93
|
Status, |
|
94
|
/// Create a sigit.si account. A confirmation email follows. |
|
95
|
Signup { |
|
96
|
#[arg(long)] |
|
97
|
email: Option<String>, |
|
98
|
}, |
|
99
|
/// Send the confirmation email again. |
|
100
|
Resend { |
|
101
|
#[arg(long)] |
|
102
|
email: Option<String>, |
|
103
|
}, |
|
104
|
/// Email instructions for choosing a new password. |
|
105
|
ResetPassword { |
|
106
|
#[arg(long)] |
|
107
|
email: Option<String>, |
|
108
|
}, |
|
109
|
/// Permanently delete your account. |
|
110
|
DeleteAccount { |
|
111
|
/// Skip the typed confirmation. |
|
112
|
#[arg(short, long)] |
|
113
|
yes: bool, |
|
114
|
}, |
|
115
|
/// Let git use your sigit.si sign-in for clones and fetches, by adding a |
|
116
|
/// credential helper to your global git config. |
|
117
|
SetupGit, |
|
118
|
/// Git's credential helper protocol. Git runs this; you don't need to. |
|
119
|
#[command(hide = true)] |
|
120
|
GitCredential { |
|
121
|
#[arg(value_enum)] |
|
122
|
operation: GitCredentialOperation, |
|
123
|
}, |
|
124
|
} |
|
125
|
|
|
126
|
#[derive(Clone, Copy, clap::ValueEnum)] |
|
127
|
pub enum GitCredentialOperation { |
|
128
|
Get, |
|
129
|
Store, |
|
130
|
Erase, |
|
131
|
} |
|
132
|
|
|
133
|
#[derive(clap::Subcommand)] |
|
134
|
pub enum RepoCommand { |
|
135
|
/// List your repositories. |
|
136
|
List, |
|
137
|
/// Search all repositories you can see. |
|
138
|
Search { |
|
139
|
/// Case-insensitive substring of the owner or repo name. |
|
140
|
query: Option<String>, |
|
141
|
#[arg(long, default_value_t = 30)] |
|
142
|
limit: u32, |
|
143
|
}, |
|
144
|
/// Show a repository's details. |
|
145
|
View { |
|
146
|
/// OWNER/NAME. Defaults to the repo in the current directory. |
|
147
|
repo: Option<String>, |
|
148
|
}, |
|
149
|
/// Create a new (empty) repository to push to. |
|
150
|
Create { |
|
151
|
name: String, |
|
152
|
#[arg(long)] |
|
153
|
private: bool, |
|
154
|
#[arg(long)] |
|
155
|
description: Option<String>, |
|
156
|
/// Skip the confirmation prompt. |
|
157
|
#[arg(short, long)] |
|
158
|
yes: bool, |
|
159
|
}, |
|
160
|
/// Open a repository in your browser. |
|
161
|
Browse { repo: Option<String> }, |
|
162
|
/// Clone a repository with git, signing in through `si` so the token |
|
163
|
/// never lands in the URL or on disk. |
|
164
|
Clone { |
|
165
|
/// OWNER/NAME. |
|
166
|
repo: String, |
|
167
|
/// Directory to clone into. |
|
168
|
dir: Option<String>, |
|
169
|
/// Extra arguments for `git clone`, after `--`. |
|
170
|
#[arg(last = true)] |
|
171
|
git_args: Vec<String>, |
|
172
|
}, |
|
173
|
} |
|
174
|
|
|
175
|
#[derive(clap::Subcommand)] |
|
176
|
pub enum PrCommand { |
|
177
|
/// List pull requests in a repository. |
|
178
|
List { |
|
179
|
repo: Option<String>, |
|
180
|
#[arg(long, default_value = "open")] |
|
181
|
state: String, |
|
182
|
}, |
|
183
|
/// Show a pull request's details, comments, and diff. |
|
184
|
View { number: i64, repo: Option<String> }, |
|
185
|
/// Print a pull request's unified diff. |
|
186
|
Diff { number: i64, repo: Option<String> }, |
|
187
|
/// Open a pull request from one branch into another. |
|
188
|
Create { |
|
189
|
#[arg(long)] |
|
190
|
title: String, |
|
191
|
#[arg(long)] |
|
192
|
head: Option<String>, |
|
193
|
#[arg(long, default_value = "main")] |
|
194
|
base: String, |
|
195
|
#[arg(long)] |
|
196
|
body: Option<String>, |
|
197
|
repo: Option<String>, |
|
198
|
}, |
|
199
|
/// Comment on a pull request. |
|
200
|
Comment { |
|
201
|
number: i64, |
|
202
|
#[arg(long)] |
|
203
|
body: String, |
|
204
|
repo: Option<String>, |
|
205
|
}, |
|
206
|
} |
|
207
|
|
|
208
|
#[derive(clap::Subcommand)] |
|
209
|
pub enum IssueCommand { |
|
210
|
/// List issues in a repository. |
|
211
|
List { |
|
212
|
repo: Option<String>, |
|
213
|
#[arg(long, default_value = "open")] |
|
214
|
state: String, |
|
215
|
#[arg(long)] |
|
216
|
query: Option<String>, |
|
217
|
}, |
|
218
|
/// Show an issue's details and comments. |
|
219
|
View { number: i64, repo: Option<String> }, |
|
220
|
/// Open a new issue. |
|
221
|
Create { |
|
222
|
#[arg(long)] |
|
223
|
title: String, |
|
224
|
#[arg(long)] |
|
225
|
body: Option<String>, |
|
226
|
repo: Option<String>, |
|
227
|
}, |
|
228
|
/// Comment on an issue. |
|
229
|
Comment { |
|
230
|
number: i64, |
|
231
|
#[arg(long)] |
|
232
|
body: String, |
|
233
|
repo: Option<String>, |
|
234
|
}, |
|
235
|
} |
|
236
|
|
|
237
|
#[derive(clap::Subcommand)] |
|
238
|
pub enum CodeCommand { |
|
239
|
/// Print a file's contents at a ref. |
|
240
|
View { |
|
241
|
path: String, |
|
242
|
#[arg(long)] |
|
243
|
r#ref: Option<String>, |
|
244
|
repo: Option<String>, |
|
245
|
}, |
|
246
|
/// Search a repository's tracked files for a fixed string. |
|
247
|
Search { |
|
248
|
query: String, |
|
249
|
#[arg(long)] |
|
250
|
r#ref: Option<String>, |
|
251
|
#[arg(long, default_value_t = 20)] |
|
252
|
limit: u32, |
|
253
|
repo: Option<String>, |
|
254
|
}, |
|
255
|
} |
|
256
|
|
|
257
|
#[derive(clap::Subcommand)] |
|
258
|
pub enum RunCommand { |
|
259
|
/// List your agent runs, newest first. |
|
260
|
List, |
|
261
|
/// Show a run's status and the end of its transcript. |
|
262
|
View { id: i64 }, |
|
263
|
/// Start a run on a GitHub repository where the siGit Code app is |
|
264
|
/// installed and your connected GitHub account can write. |
|
265
|
Start { |
|
266
|
/// OWNER/NAME of the GitHub repository. |
|
267
|
#[arg(long)] |
|
268
|
repo: String, |
|
269
|
/// What the agent should do. |
|
270
|
prompt: String, |
|
271
|
}, |
|
272
|
/// Ask a running agent to stop. |
|
273
|
Cancel { id: i64 }, |
|
274
|
/// Print the branch, prompt and command for continuing a run on your own |
|
275
|
/// machine. |
|
276
|
Handoff { id: i64 }, |
|
277
|
} |
|
278
|
|
|
279
|
#[derive(clap::Subcommand)] |
|
280
|
pub enum SiteCommand { |
|
281
|
/// Show a repository's site: its address and whether it is live. |
|
282
|
View { |
|
283
|
#[arg(long)] |
|
284
|
repo: Option<String>, |
|
285
|
}, |
|
286
|
/// Publish the default branch, or publish it again. |
|
287
|
Publish { |
|
288
|
/// Wait until the site is live or the publish has failed. |
|
289
|
#[arg(long)] |
|
290
|
wait: bool, |
|
291
|
#[arg(long)] |
|
292
|
repo: Option<String>, |
|
293
|
}, |
|
294
|
/// Take the site offline. |
|
295
|
Unpublish { |
|
296
|
#[arg(long)] |
|
297
|
repo: Option<String>, |
|
298
|
/// Skip the confirmation prompt. |
|
299
|
#[arg(short, long)] |
|
300
|
yes: bool, |
|
301
|
}, |
|
302
|
} |
|
303
|
|
|
304
|
#[derive(clap::Subcommand)] |
|
305
|
pub enum StatusCommand { |
|
306
|
/// Report a status on a commit. |
|
307
|
Set { |
|
308
|
/// A commit SHA, or a branch, tag or other ref in the current repo. |
|
309
|
sha: String, |
|
310
|
#[arg(long, value_parser = ["pending", "success", "failure", "error"])] |
|
311
|
state: String, |
|
312
|
/// Which check this is, such as ci/test. Defaults to "default". |
|
313
|
#[arg(long)] |
|
314
|
context: Option<String>, |
|
315
|
#[arg(long)] |
|
316
|
description: Option<String>, |
|
317
|
/// Where to see the details, such as a CI run. |
|
318
|
#[arg(long)] |
|
319
|
url: Option<String>, |
|
320
|
#[arg(long)] |
|
321
|
repo: Option<String>, |
|
322
|
}, |
|
323
|
/// Show the combined status of a commit and each check behind it. |
|
324
|
View { |
|
325
|
/// A commit SHA or ref. Defaults to HEAD. |
|
326
|
sha: Option<String>, |
|
327
|
#[arg(long)] |
|
328
|
repo: Option<String>, |
|
329
|
}, |
|
330
|
} |
|
331
|
|
|
332
|
#[derive(clap::Subcommand)] |
|
333
|
pub enum HookCommand { |
|
334
|
/// List a repository's webhooks. |
|
335
|
List { repo: Option<String> }, |
|
336
|
/// Register a new webhook. Prints the signing secret once — it cannot be |
|
337
|
/// retrieved again. |
|
338
|
Create { |
|
339
|
#[arg(long)] |
|
340
|
url: String, |
|
341
|
#[arg(long, value_delimiter = ',', default_value = "push")] |
|
342
|
events: Vec<String>, |
|
343
|
repo: Option<String>, |
|
344
|
}, |
|
345
|
/// Remove a webhook. |
|
346
|
Delete { |
|
347
|
id: i64, |
|
348
|
repo: Option<String>, |
|
349
|
#[arg(short, long)] |
|
350
|
yes: bool, |
|
351
|
}, |
|
352
|
} |
|
353
|
|
|
354
|
#[derive(clap::Subcommand)] |
|
355
|
pub enum SessionCommand { |
|
356
|
/// List your Cloud Sessions. |
|
357
|
List, |
|
358
|
/// Show a session and its transcript. |
|
359
|
View { id: i64 }, |
|
360
|
/// Start a new session. |
|
361
|
New { |
|
362
|
#[arg(long)] |
|
363
|
title: Option<String>, |
|
364
|
#[arg(long)] |
|
365
|
model: Option<String>, |
|
366
|
}, |
|
367
|
/// Rename a session or change its model. |
|
368
|
Update { |
|
369
|
id: i64, |
|
370
|
#[arg(long)] |
|
371
|
title: Option<String>, |
|
372
|
#[arg(long)] |
|
373
|
model: Option<String>, |
|
374
|
}, |
|
375
|
/// Delete a session. |
|
376
|
Delete { |
|
377
|
id: i64, |
|
378
|
#[arg(short, long)] |
|
379
|
yes: bool, |
|
380
|
}, |
|
381
|
} |
|
382
|
|
|
383
|
#[derive(clap::Subcommand)] |
|
384
|
pub enum BillingCommand { |
|
385
|
/// Show your current plan and cloud usage. |
|
386
|
Show, |
|
387
|
/// Open the hosted checkout to subscribe or change plans. |
|
388
|
Checkout { plan: String }, |
|
389
|
/// Open the hosted billing portal. |
|
390
|
Portal, |
|
391
|
} |
|
392
|
|
|
393
|
#[derive(clap::Args)] |
|
394
|
pub struct BrowseArgs { |
|
395
|
/// What to open: a repo, "OWNER/NAME/pull/N", "OWNER/NAME/issue/N", or |
|
396
|
/// left blank for the current repository. |
|
397
|
pub target: Option<String>, |
|
398
|
} |
|
399
|
|
|
400
|
#[derive(clap::Args)] |
|
401
|
pub struct McpArgs { |
|
402
|
/// Drop every tool that writes, leaving only the ones that read. |
|
403
|
#[arg(long)] |
|
404
|
pub read_only: bool, |
|
405
|
|
|
406
|
/// Expose only these tool groups, comma-separated. Defaults to all of |
|
407
|
/// them: account, repo, issue, pr, code, hook, session, billing. |
|
408
|
#[arg(long, value_delimiter = ',', env = "SIGIT_TOOLSETS")] |
|
409
|
pub toolsets: Vec<String>, |
|
410
|
} |
|
411
|
|
|
412
|
#[derive(clap::Args)] |
|
413
|
pub struct ApiArgs { |
|
414
|
/// Path under /api/v1, e.g. "repos" or "billing". |
|
415
|
pub path: String, |
|
416
|
#[arg(short = 'X', long, default_value = "GET")] |
|
417
|
pub method: String, |
|
418
|
/// Raw JSON request body. |
|
419
|
#[arg(long)] |
|
420
|
pub body: Option<String>, |
|
421
|
} |