1use clap::Parser;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
6#[allow(clippy::large_enum_variant)]
7pub enum Command {
8 Init(InitArgs),
10 Dashboard(DashboardArgs),
12 #[command(hide = true)]
14 Mock(MockArgs),
15 Combine(CombineArgs),
17 Dispatch(DispatchArgs),
19 #[command(hide = true)]
21 EditStart(EditStartArgs),
22 #[command(hide = true)]
24 EditFinish(EditFinishArgs),
25 Review(ReviewArgs),
27 Clean(CleanArgs),
29 Status {
31 id: String,
32 #[arg(long)]
33 json: bool,
34 },
35 Wait {
37 #[arg(required = true, num_args = 1..)]
39 ids: Vec<String>,
40 #[arg(long)]
42 any: bool,
43 #[arg(long, default_value_t = 280)]
45 timeout: u64,
46 },
47 Skill(SkillArgs),
49 Update {
51 #[arg(long, conflicts_with = "rollback")]
53 check: bool,
54 #[arg(long)]
56 rollback: bool,
57 },
58 Cost(CostArgs),
60 Statusline(StatuslineArgs),
62 Plan(PlanArgs),
64 #[command(hide = true)]
66 Comments(CommentsArgs),
67 #[command(hide = true)]
69 Instructions(InstructionsArgs),
70}
71
72#[derive(clap::Args, Debug, PartialEq, Clone)]
73pub struct InitArgs {
74 #[arg(long)]
76 pub force: bool,
77
78 #[arg(long)]
80 pub print: bool,
81
82 #[arg(long)]
84 pub no_verify: bool,
85
86 #[arg(
88 long,
89 default_value = "on",
90 value_parser = ["on", "off"]
91 )]
92 pub sandbox: String,
93
94 #[arg(long, default_value = "600", value_name = "SECONDS")]
96 pub step_timeout: u64,
97}
98
99#[derive(clap::Args, Debug, PartialEq, Clone)]
100pub struct DashboardArgs {
101 #[arg(long, default_value = "7171", value_name = "N")]
103 pub port: u16,
104
105 #[arg(long = "root", value_name = "DIR")]
107 pub roots: Vec<PathBuf>,
108
109 #[arg(long = "runs-dir", value_name = "DIR")]
111 pub runs_dirs: Vec<PathBuf>,
112
113 #[arg(long, default_value = "24", value_name = "N")]
115 pub hours: u64,
116
117 #[arg(long)]
119 pub open: bool,
120}
121
122#[derive(clap::Args, Debug, PartialEq, Clone)]
123pub struct SurfaceArgs {
124 #[arg(
125 long,
126 default_value_t = 0,
127 value_name = "N",
128 help = "Port to listen on (0 picks a free port)"
129 )]
130 pub port: u16,
131
132 #[arg(long, help = "Do not open the live surface in the browser")]
133 pub no_open: bool,
134
135 #[arg(
136 long,
137 default_value_t = 14,
138 value_name = "N",
139 value_parser = clap::value_parser!(u64).range(1..=31),
140 help = "How many days back to include finished runs (1 to 31)"
141 )]
142 pub days: u64,
143}
144
145impl Default for SurfaceArgs {
146 fn default() -> Self {
147 Self {
148 port: 0,
149 no_open: false,
150 days: 14,
151 }
152 }
153}
154
155#[derive(clap::Args, Debug, PartialEq, Clone)]
156pub struct MockArgs {
157 #[arg(long, default_value = "7272", value_name = "N")]
159 pub port: u16,
160
161 #[arg(
163 long,
164 default_value = "7",
165 value_name = "N",
166 value_parser = clap::value_parser!(u64).range(1..=31)
167 )]
168 pub days: u64,
169
170 #[arg(long = "root", value_name = "DIR")]
172 pub roots: Vec<PathBuf>,
173}
174
175#[derive(clap::Args, Debug, PartialEq, Clone)]
176pub struct CombineArgs {
177 pub request: String,
179}
180
181#[derive(clap::Args, Debug, PartialEq, Clone)]
182pub struct EditStartArgs {
183 pub id: String,
185
186 #[arg(long, value_name = "TEXT")]
188 pub task: String,
189
190 #[arg(long, default_value = "HEAD")]
192 pub base: String,
193}
194
195#[derive(clap::Args, Debug, PartialEq, Clone)]
196pub struct EditFinishArgs {
197 pub id: String,
199
200 #[arg(long, value_name = "ID")]
202 pub request: Option<String>,
203
204 #[arg(long, value_name = "TEXT")]
206 pub message: Option<String>,
207}
208
209#[derive(clap::Args, Debug, PartialEq, Clone)]
210pub struct DispatchArgs {
211 pub id: String,
213
214 pub task_file: Option<PathBuf>,
216
217 #[arg(short, long)]
219 pub gate: Option<String>,
220
221 #[arg(long = "tag", value_name = "TEXT")]
223 pub tags: Vec<String>,
224
225 #[arg(long, value_name = "PATH")]
227 pub plan: Option<String>,
228
229 #[arg(long, value_name = "TEXT")]
231 pub plan_task: Option<String>,
232
233 #[arg(long, value_name = "ID")]
235 pub request: Option<String>,
236
237 #[arg(long, default_value = "HEAD")]
239 pub base: String,
240
241 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
243 pub research: bool,
244
245 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
247 pub report_to: Option<PathBuf>,
248
249 #[arg(short, long)]
251 pub model: Option<String>,
252
253 #[arg(long)]
255 pub max_seconds: Option<u64>,
256
257 #[arg(long)]
259 pub max_turns: Option<u32>,
260
261 #[arg(long = "max-cost")]
263 pub max_cost_usd: Option<f64>,
264
265 #[arg(long)]
267 pub fold_budget: Option<usize>,
268
269 #[arg(
271 long,
272 default_value = "on",
273 value_parser = ["on", "off"]
274 )]
275 pub sandbox: String,
276
277 #[arg(
279 long,
280 value_parser = ["on", "off"]
281 )]
282 pub network: Option<String>,
283
284 #[arg(long = "allow-read")]
286 pub allow_read: Vec<PathBuf>,
287
288 #[arg(long = "no-path-check")]
290 pub no_path_check: bool,
291
292 #[arg(long = "no-brief-check")]
294 pub no_brief_check: bool,
295
296 #[arg(long = "no-claim-check")]
298 pub no_claim_check: bool,
299
300 #[arg(long = "no-base-check")]
302 pub no_base_check: bool,
303
304 #[arg(long = "pass-env")]
306 pub pass_env: Vec<String>,
307}
308
309#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
310#[value(rename_all = "lowercase")]
311#[serde(rename_all = "lowercase")]
312pub enum ReviewVerdict {
313 Accepted,
314 Fixed,
315 Redone,
316}
317
318impl ReviewVerdict {
319 pub fn as_str(&self) -> &'static str {
320 match self {
321 Self::Accepted => "accepted",
322 Self::Fixed => "fixed",
323 Self::Redone => "redone",
324 }
325 }
326}
327
328impl std::fmt::Display for ReviewVerdict {
329 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
330 write!(f, "{}", self.as_str())
331 }
332}
333
334#[derive(clap::Args, Debug, PartialEq, Clone)]
335pub struct ReviewArgs {
336 pub id: String,
337
338 #[arg(long)]
339 pub diff: bool,
340
341 #[arg(long, value_enum)]
342 pub verdict: Option<ReviewVerdict>,
343
344 #[arg(long, value_name = "TEXT", requires = "verdict")]
345 pub notes: Option<String>,
346
347 #[arg(long, conflicts_with = "verdict")]
349 pub model_review: bool,
350}
351
352#[derive(clap::Args, Debug, PartialEq, Clone)]
353pub struct CleanArgs {
354 #[arg(long)]
356 pub dry_run: bool,
357
358 #[arg(long, default_value = "14", value_name = "DAYS")]
360 pub older_than: u64,
361
362 #[arg(long)]
364 pub all: bool,
365
366 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
367 pub quiet: bool,
368
369 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
370 pub skip: Option<String>,
371}
372
373#[derive(clap::Args, Debug, PartialEq, Clone)]
374pub struct CostArgs {
375 #[arg(long, value_name = "ID")]
377 pub session: Option<String>,
378
379 #[arg(long)]
381 pub by_session: bool,
382
383 #[arg(long, value_name = "UNIX_SECS")]
385 pub since: Option<u64>,
386
387 #[arg(long, value_name = "PATH")]
389 pub repo: Option<PathBuf>,
390
391 #[arg(long)]
393 pub json: bool,
394}
395
396#[derive(clap::Args, Debug, PartialEq, Clone)]
397pub struct StatuslineArgs {
398 #[arg(long, value_name = "COMMAND")]
400 pub after: Option<String>,
401}
402
403#[derive(clap::Args, Debug, PartialEq, Clone)]
404pub struct PlanArgs {
405 pub plan: PathBuf,
407
408 #[arg(long)]
410 pub json: bool,
411}
412
413#[derive(clap::Args, Debug, PartialEq, Clone)]
414pub struct CommentsArgs {
415 #[arg(long, value_name = "REV")]
417 pub base: String,
418}
419
420#[derive(clap::Args, Debug, PartialEq, Clone)]
421pub struct InstructionsArgs {
422 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
424 pub default_process: bool,
425
426 #[arg(long)]
428 pub one_shot: bool,
429
430 #[arg(long)]
432 pub dispatch_tool: bool,
433
434 #[arg(long, value_parser = ["on", "off"])]
436 pub sandbox: Option<String>,
437}
438
439#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
440pub enum SkillAction {
441 Install {
443 #[arg(long)]
445 project: bool,
446
447 #[arg(long)]
449 force: bool,
450
451 #[arg(long, hide = true)]
453 default: bool,
454
455 #[arg(long)]
457 no_default: bool,
458
459 #[arg(long)]
461 no_statusline: bool,
462
463 #[arg(long)]
465 no_autocompact: bool,
466
467 #[arg(
469 long,
470 default_value = "claude",
471 value_parser = ["claude", "codex", "all"]
472 )]
473 harness: String,
474
475 #[arg(long, value_name = "ID")]
477 model: Option<String>,
478 },
479
480 Uninstall {
482 #[arg(long)]
484 project: bool,
485
486 #[arg(
488 long,
489 default_value = "claude",
490 value_parser = ["claude", "codex", "all"]
491 )]
492 harness: String,
493 },
494
495 Print,
497}
498
499#[derive(clap::Args, Debug, PartialEq, Clone)]
500pub struct SkillArgs {
501 #[command(subcommand)]
502 pub action: SkillAction,
503}
504
505#[derive(Parser, Debug, PartialEq)]
506#[command(
507 name = "blyte",
508 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
509 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
510 subcommand_precedence_over_arg = true
511)]
512pub struct Cli {
513 #[command(subcommand)]
514 pub command: Option<Command>,
515
516 #[arg(index = 1)]
518 pub prompt: Option<String>,
519
520 #[arg(short, long)]
522 pub gate: Option<String>,
523
524 #[arg(long, conflicts_with = "gate")]
526 pub converse: bool,
527
528 #[arg(long, requires = "converse")]
530 pub dispatch_cmd: Option<String>,
531
532 #[arg(
534 long,
535 default_value = "folded",
536 value_parser = ["conversational", "folded"]
537 )]
538 pub context: String,
539
540 #[arg(short, long)]
542 pub model: Option<String>,
543
544 #[arg(long)]
546 pub container: Option<String>,
547
548 #[arg(long, default_value = "25")]
550 pub max_turns: usize,
551
552 #[arg(long, default_value = "5")]
554 pub max_gates: usize,
555
556 #[arg(
558 long,
559 default_value_t = true,
560 action = clap::ArgAction::Set,
561 num_args = 0..=1,
562 require_equals = true,
563 default_missing_value = "true",
564 value_parser = clap::builder::BoolishValueParser::new()
565 )]
566 pub rollback: bool,
567
568 #[arg(long, default_value = "/workspace")]
570 pub container_workdir: String,
571
572 #[arg(long)]
574 pub max_seconds: Option<u64>,
575
576 #[arg(long = "max-cost")]
578 pub max_cost_usd: Option<f64>,
579
580 #[arg(long)]
582 pub report: Option<PathBuf>,
583
584 #[arg(long)]
586 pub fold_budget: Option<usize>,
587
588 #[arg(
590 long,
591 default_value = "on",
592 value_parser = ["on", "off"]
593 )]
594 pub sandbox: String,
595
596 #[arg(
598 long,
599 value_parser = ["on", "off"]
600 )]
601 pub network: Option<String>,
602
603 #[arg(long = "allow-read")]
605 pub allow_read: Vec<PathBuf>,
606
607 #[arg(long = "pass-env")]
609 pub pass_env: Vec<String>,
610
611 #[arg(long = "read-root", value_name = "DIR")]
613 pub read_roots: Vec<PathBuf>,
614
615 #[arg(long)]
617 pub no_gate_slot: bool,
618
619 #[arg(long)]
621 pub research: bool,
622
623 #[arg(long = "claim-check")]
625 pub claim_check: bool,
626
627 #[arg(long = "base-check")]
629 pub base_check: bool,
630
631 #[arg(long = "base-check-dir", value_name = "DIR")]
633 pub base_check_dir: Option<PathBuf>,
634
635 #[arg(
636 long,
637 help = "Run the interactive terminal session instead of starting the live surface"
638 )]
639 pub terminal: bool,
640
641 #[arg(
642 long,
643 value_name = "N",
644 help = "Port for the live surface (0 picks a free port)"
645 )]
646 pub port: Option<u16>,
647
648 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
649 pub no_open: bool,
650
651 #[arg(
652 long,
653 value_name = "N",
654 value_parser = clap::value_parser!(u64).range(1..=31),
655 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
656 )]
657 pub days: Option<u64>,
658}
659
660pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
662 if !cli.converse {
663 return;
664 }
665 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
666 cli.max_turns = 1000;
667 }
668 if cli.fold_budget.is_none() {
669 cli.fold_budget = Some(100_000);
670 }
671}