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 Combine(CombineArgs),
14 Dispatch(DispatchArgs),
16 #[command(hide = true)]
18 EditStart(EditStartArgs),
19 #[command(hide = true)]
21 EditFinish(EditFinishArgs),
22 Review(ReviewArgs),
24 Clean(CleanArgs),
26 Status {
28 id: String,
29 #[arg(long)]
30 json: bool,
31 },
32 Wait {
34 #[arg(required = true, num_args = 1..)]
36 ids: Vec<String>,
37 #[arg(long)]
39 any: bool,
40 #[arg(long, default_value_t = 280)]
42 timeout: u64,
43 },
44 Skill(SkillArgs),
46 Update {
48 #[arg(long, conflicts_with = "rollback")]
50 check: bool,
51 #[arg(long)]
53 rollback: bool,
54 },
55 Cost(CostArgs),
57 Statusline(StatuslineArgs),
59 Plan(PlanArgs),
61 Surfaces {
63 #[arg(long)]
64 json: bool,
65 #[arg(long)]
67 stopped: bool,
68 },
69 Open {
71 name: String,
72 #[arg(long = "open-in", value_name = "app|browser")]
74 open_in: Option<String>,
75 },
76 Reload(ReloadArgs),
78 Stop(StopArgs),
80 Tell {
82 name: String,
83 message: String,
84 #[arg(long, default_value = "terminal", value_name = "LABEL", value_parser = parse_from_label)]
85 from: String,
86 },
87 #[command(hide = true)]
89 Comments(CommentsArgs),
90 #[command(hide = true)]
92 Instructions(InstructionsArgs),
93 Undo(UndoArgs),
95}
96
97#[derive(clap::Args, Debug, PartialEq, Clone)]
98pub struct UndoArgs {
99 pub id: String,
101}
102
103#[derive(clap::Args, Debug, PartialEq, Clone)]
104pub struct ReloadArgs {
105 #[arg(value_name = "NAME", conflicts_with = "all")]
107 pub target: Option<String>,
108
109 #[arg(long)]
111 pub all: bool,
112}
113
114#[derive(clap::Args, Debug, PartialEq, Clone)]
115pub struct StopArgs {
116 #[arg(value_name = "NAME", conflicts_with = "all")]
118 pub target: Option<String>,
119
120 #[arg(long)]
122 pub all: bool,
123
124 #[arg(long)]
126 pub force: bool,
127}
128
129#[derive(clap::Args, Debug, PartialEq, Clone)]
130pub struct InitArgs {
131 #[arg(long)]
133 pub force: bool,
134
135 #[arg(long)]
137 pub print: bool,
138
139 #[arg(long)]
141 pub no_verify: bool,
142
143 #[arg(
145 long,
146 default_value = "on",
147 value_parser = ["on", "off"]
148 )]
149 pub sandbox: String,
150
151 #[arg(long, default_value = "600", value_name = "SECONDS")]
153 pub step_timeout: u64,
154}
155
156#[derive(clap::Args, Debug, PartialEq, Clone)]
157pub struct DashboardArgs {
158 #[arg(long, default_value = "7171", value_name = "N")]
160 pub port: u16,
161
162 #[arg(long = "root", value_name = "DIR")]
164 pub roots: Vec<PathBuf>,
165
166 #[arg(long = "runs-dir", value_name = "DIR")]
168 pub runs_dirs: Vec<PathBuf>,
169
170 #[arg(long, default_value = "24", value_name = "N")]
172 pub hours: u64,
173
174 #[arg(long)]
176 pub open: bool,
177}
178
179#[derive(Debug, PartialEq, Clone)]
180pub struct SurfaceArgs {
181 pub port: u16,
182 pub no_open: bool,
183 pub open_in: crate::open_window::OpenIn,
184 pub days: u64,
185 pub name: Option<String>,
186 pub resume: Option<String>,
187}
188
189impl Default for SurfaceArgs {
190 fn default() -> Self {
191 Self {
192 port: 0,
193 no_open: false,
194 open_in: crate::open_window::OpenIn::App,
195 days: 14,
196 name: None,
197 resume: None,
198 }
199 }
200}
201
202#[derive(clap::Args, Debug, PartialEq, Clone)]
203pub struct CombineArgs {
204 pub request: String,
206}
207
208#[derive(clap::Args, Debug, PartialEq, Clone)]
209pub struct EditStartArgs {
210 pub id: String,
212
213 #[arg(long, value_name = "TEXT")]
215 pub task: String,
216
217 #[arg(long, default_value = "HEAD")]
219 pub base: String,
220}
221
222#[derive(clap::Args, Debug, PartialEq, Clone)]
223pub struct EditFinishArgs {
224 pub id: String,
226
227 #[arg(long, value_name = "ID")]
229 pub request: Option<String>,
230
231 #[arg(long, value_name = "ID")]
233 pub surface: Option<String>,
234
235 #[arg(long, hide = true, value_name = "NAME")]
236 pub started_by: Option<String>,
237
238 #[arg(long, value_name = "TEXT")]
240 pub message: Option<String>,
241}
242
243#[derive(clap::Args, Debug, PartialEq, Clone)]
244pub struct DispatchArgs {
245 pub id: String,
247
248 pub task_file: Option<PathBuf>,
250
251 #[arg(short, long)]
253 pub gate: Option<String>,
254
255 #[arg(long = "tag", value_name = "TEXT")]
257 pub tags: Vec<String>,
258
259 #[arg(long, value_name = "PATH")]
261 pub plan: Option<String>,
262
263 #[arg(long, value_name = "TEXT")]
265 pub plan_task: Option<String>,
266
267 #[arg(long, value_name = "ID")]
269 pub request: Option<String>,
270
271 #[arg(long, value_name = "ID")]
273 pub surface: Option<String>,
274
275 #[arg(long, hide = true, value_name = "NAME")]
276 pub started_by: Option<String>,
277
278 #[arg(long, default_value = "HEAD")]
280 pub base: String,
281
282 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
284 pub research: bool,
285
286 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
288 pub report_to: Option<PathBuf>,
289
290 #[arg(short, long)]
292 pub model: Option<String>,
293
294 #[arg(long)]
296 pub max_seconds: Option<u64>,
297
298 #[arg(long)]
300 pub max_turns: Option<u32>,
301
302 #[arg(long = "max-cost")]
304 pub max_cost_usd: Option<f64>,
305
306 #[arg(long)]
308 pub fold_budget: Option<usize>,
309
310 #[arg(
312 long,
313 default_value = "on",
314 value_parser = ["on", "off"]
315 )]
316 pub sandbox: String,
317
318 #[arg(
320 long,
321 value_parser = ["on", "off"]
322 )]
323 pub network: Option<String>,
324
325 #[arg(long = "allow-read")]
327 pub allow_read: Vec<PathBuf>,
328
329 #[arg(long = "no-path-check")]
331 pub no_path_check: bool,
332
333 #[arg(long = "no-brief-check")]
335 pub no_brief_check: bool,
336
337 #[arg(long = "no-claim-check")]
339 pub no_claim_check: bool,
340
341 #[arg(long = "no-base-check")]
343 pub no_base_check: bool,
344
345 #[arg(long = "pass-env")]
347 pub pass_env: Vec<String>,
348}
349
350#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
351#[value(rename_all = "lowercase")]
352#[serde(rename_all = "lowercase")]
353pub enum ReviewVerdict {
354 Accepted,
355 Fixed,
356 Redone,
357}
358
359impl ReviewVerdict {
360 pub fn as_str(&self) -> &'static str {
361 match self {
362 Self::Accepted => "accepted",
363 Self::Fixed => "fixed",
364 Self::Redone => "redone",
365 }
366 }
367}
368
369impl std::fmt::Display for ReviewVerdict {
370 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
371 write!(f, "{}", self.as_str())
372 }
373}
374
375#[derive(clap::Args, Debug, PartialEq, Clone)]
376pub struct ReviewArgs {
377 pub id: String,
378
379 #[arg(long)]
380 pub diff: bool,
381
382 #[arg(long, value_enum)]
383 pub verdict: Option<ReviewVerdict>,
384
385 #[arg(long, value_name = "TEXT", requires = "verdict")]
386 pub notes: Option<String>,
387
388 #[arg(long, conflicts_with = "verdict")]
390 pub model_review: bool,
391}
392
393#[derive(clap::Args, Debug, PartialEq, Clone)]
394pub struct CleanArgs {
395 #[arg(long)]
397 pub dry_run: bool,
398
399 #[arg(long, default_value = "14", value_name = "DAYS")]
401 pub older_than: u64,
402
403 #[arg(long)]
405 pub all: bool,
406
407 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
408 pub quiet: bool,
409
410 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
411 pub skip: Option<String>,
412}
413
414#[derive(clap::Args, Debug, PartialEq, Clone)]
415pub struct CostArgs {
416 #[arg(long, value_name = "ID")]
418 pub session: Option<String>,
419
420 #[arg(long)]
422 pub by_session: bool,
423
424 #[arg(long, value_name = "UNIX_SECS")]
426 pub since: Option<u64>,
427
428 #[arg(long, value_name = "PATH")]
430 pub repo: Option<PathBuf>,
431
432 #[arg(long)]
434 pub json: bool,
435}
436
437#[derive(clap::Args, Debug, PartialEq, Clone)]
438pub struct StatuslineArgs {
439 #[arg(long, value_name = "COMMAND")]
441 pub after: Option<String>,
442}
443
444#[derive(clap::Args, Debug, PartialEq, Clone)]
445pub struct PlanArgs {
446 pub plan: PathBuf,
448
449 #[arg(long)]
451 pub json: bool,
452}
453
454#[derive(clap::Args, Debug, PartialEq, Clone)]
455pub struct CommentsArgs {
456 #[arg(long, value_name = "REV")]
458 pub base: String,
459}
460
461#[derive(clap::Args, Debug, PartialEq, Clone)]
462pub struct InstructionsArgs {
463 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
465 pub default_process: bool,
466
467 #[arg(long)]
469 pub one_shot: bool,
470
471 #[arg(long)]
473 pub dispatch_tool: bool,
474
475 #[arg(long, value_parser = ["on", "off"])]
477 pub sandbox: Option<String>,
478}
479
480#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
481pub enum SkillAction {
482 Install {
484 #[arg(long)]
486 project: bool,
487
488 #[arg(long)]
490 force: bool,
491
492 #[arg(long, hide = true)]
494 default: bool,
495
496 #[arg(long)]
498 no_default: bool,
499
500 #[arg(long)]
502 no_statusline: bool,
503
504 #[arg(long)]
506 no_autocompact: bool,
507
508 #[arg(
510 long,
511 default_value = "claude",
512 value_parser = ["claude", "codex", "all"]
513 )]
514 harness: String,
515
516 #[arg(long, value_name = "ID")]
518 model: Option<String>,
519 },
520
521 Uninstall {
523 #[arg(long)]
525 project: bool,
526
527 #[arg(
529 long,
530 default_value = "claude",
531 value_parser = ["claude", "codex", "all"]
532 )]
533 harness: String,
534 },
535
536 Print,
538}
539
540#[derive(clap::Args, Debug, PartialEq, Clone)]
541pub struct SkillArgs {
542 #[command(subcommand)]
543 pub action: SkillAction,
544}
545
546#[derive(Parser, Debug, PartialEq)]
547#[command(
548 name = "blyte",
549 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
550 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
551 subcommand_precedence_over_arg = true
552)]
553pub struct Cli {
554 #[command(subcommand)]
555 pub command: Option<Command>,
556
557 #[arg(index = 1)]
559 pub prompt: Option<String>,
560
561 #[arg(short, long)]
563 pub gate: Option<String>,
564
565 #[arg(long, conflicts_with = "gate")]
567 pub converse: bool,
568
569 #[arg(long, requires = "converse")]
571 pub dispatch_cmd: Option<String>,
572
573 #[arg(
575 long,
576 default_value = "folded",
577 value_parser = ["conversational", "folded"]
578 )]
579 pub context: String,
580
581 #[arg(short, long)]
583 pub model: Option<String>,
584
585 #[arg(long)]
587 pub container: Option<String>,
588
589 #[arg(long, default_value = "25")]
591 pub max_turns: usize,
592
593 #[arg(long, default_value = "5")]
595 pub max_gates: usize,
596
597 #[arg(
599 long,
600 default_value_t = true,
601 action = clap::ArgAction::Set,
602 num_args = 0..=1,
603 require_equals = true,
604 default_missing_value = "true",
605 value_parser = clap::builder::BoolishValueParser::new()
606 )]
607 pub rollback: bool,
608
609 #[arg(long, default_value = "/workspace")]
611 pub container_workdir: String,
612
613 #[arg(long)]
615 pub max_seconds: Option<u64>,
616
617 #[arg(long = "max-cost")]
619 pub max_cost_usd: Option<f64>,
620
621 #[arg(long)]
623 pub report: Option<PathBuf>,
624
625 #[arg(long)]
627 pub fold_budget: Option<usize>,
628
629 #[arg(
631 long,
632 default_value = "on",
633 value_parser = ["on", "off"]
634 )]
635 pub sandbox: String,
636
637 #[arg(
639 long,
640 value_parser = ["on", "off"]
641 )]
642 pub network: Option<String>,
643
644 #[arg(long = "allow-read")]
646 pub allow_read: Vec<PathBuf>,
647
648 #[arg(long = "pass-env")]
650 pub pass_env: Vec<String>,
651
652 #[arg(long = "read-root", value_name = "DIR")]
654 pub read_roots: Vec<PathBuf>,
655
656 #[arg(long)]
658 pub no_gate_slot: bool,
659
660 #[arg(
661 long = "snapshot-dir",
662 hide = true,
663 value_name = "DIR",
664 requires = "snapshot_manifest",
665 conflicts_with_all = ["container", "converse"]
666 )]
667 pub snapshot_dir: Option<PathBuf>,
668
669 #[arg(
670 long = "snapshot-manifest",
671 hide = true,
672 value_name = "FILE",
673 requires = "snapshot_dir",
674 conflicts_with_all = ["container", "converse"]
675 )]
676 pub snapshot_manifest: Option<PathBuf>,
677
678 #[arg(long)]
680 pub research: bool,
681
682 #[arg(long = "claim-check")]
684 pub claim_check: bool,
685
686 #[arg(long = "base-check")]
688 pub base_check: bool,
689
690 #[arg(long = "base-check-dir", value_name = "DIR")]
692 pub base_check_dir: Option<PathBuf>,
693
694 #[arg(
695 long,
696 help = "Run the surface in the terminal instead of opening the page"
697 )]
698 pub terminal: bool,
699
700 #[arg(
701 long,
702 value_name = "N",
703 help = "Port to listen on (default: a free port)"
704 )]
705 pub port: Option<u16>,
706
707 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
708 pub no_open: bool,
709
710 #[arg(
711 long = "open-in",
712 value_name = "app|browser",
713 help = "Open the live surface in an app window (`app`, default) or the default browser (`browser`)"
714 )]
715 pub open_in: Option<String>,
716
717 #[arg(
718 long,
719 value_name = "N",
720 value_parser = clap::value_parser!(u64).range(1..=31),
721 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
722 )]
723 pub days: Option<u64>,
724
725 #[arg(
726 long,
727 value_name = "NAME",
728 help = "Name for this surface (default: the repository directory name)"
729 )]
730 pub name: Option<String>,
731
732 #[arg(
733 long,
734 value_name = "NAME",
735 conflicts_with = "name",
736 help = "Restart a stopped surface, by name or id, with its transcript"
737 )]
738 pub resume: Option<String>,
739
740 #[arg(
741 long,
742 help = "Keep the surface attached to the terminal instead of detaching"
743 )]
744 pub foreground: bool,
745
746 #[arg(
747 long,
748 conflicts_with = "resume",
749 help = "Start a fresh surface without prompting to open or resume"
750 )]
751 pub new: bool,
752}
753
754fn parse_from_label(raw: &str) -> Result<String, String> {
755 crate::surface_dir::validate_surface_name(raw)?;
756 Ok(raw.to_string())
757}
758
759pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
761 if !cli.converse {
762 return;
763 }
764 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
765 cli.max_turns = 1000;
766 }
767 if cli.fold_budget.is_none() {
768 cli.fold_budget = Some(100_000);
769 }
770}