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 Mcp(McpArgs),
97}
98
99#[derive(clap::Args, Debug, PartialEq, Clone)]
100pub struct McpArgs {
101 #[command(subcommand)]
102 pub action: McpAction,
103}
104
105#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
106pub enum McpAction {
107 List {
109 #[arg(long)]
111 json: bool,
112 },
113 Add(McpAddArgs),
115 Remove {
117 name: String,
119 },
120 Auth {
122 name: String,
124 #[arg(long)]
126 no_open: bool,
127 },
128 Logout {
130 name: String,
132 },
133}
134
135#[derive(clap::Args, Debug, PartialEq, Clone)]
136pub struct McpAddArgs {
137 pub name: String,
139 #[arg(value_name = "URL_OR_COMMAND")]
141 pub target: String,
142 #[arg(long, value_enum)]
144 pub transport: Option<crate::mcp::config::TransportKind>,
145 #[arg(long = "header", value_name = "KEY=VAL")]
147 pub headers: Vec<String>,
148 #[arg(long = "env", value_name = "KEY=VAL")]
150 pub env: Vec<String>,
151 #[arg(long, value_enum, default_value_t = crate::mcp::config::ApprovalPolicy::ReadOnly)]
153 pub approval: crate::mcp::config::ApprovalPolicy,
154 #[arg(long)]
156 pub replace: bool,
157 #[arg(last = true, value_name = "ARGS")]
159 pub args: Vec<String>,
160}
161
162#[derive(clap::Args, Debug, PartialEq, Clone)]
163pub struct UndoArgs {
164 pub id: String,
166}
167
168#[derive(clap::Args, Debug, PartialEq, Clone)]
169pub struct ReloadArgs {
170 #[arg(value_name = "NAME", conflicts_with = "all")]
172 pub target: Option<String>,
173
174 #[arg(long)]
176 pub all: bool,
177}
178
179#[derive(clap::Args, Debug, PartialEq, Clone)]
180pub struct StopArgs {
181 #[arg(value_name = "NAME", conflicts_with = "all")]
183 pub target: Option<String>,
184
185 #[arg(long)]
187 pub all: bool,
188
189 #[arg(long)]
191 pub force: bool,
192}
193
194#[derive(clap::Args, Debug, PartialEq, Clone)]
195pub struct InitArgs {
196 #[arg(long)]
198 pub force: bool,
199
200 #[arg(long)]
202 pub print: bool,
203
204 #[arg(long)]
206 pub no_verify: bool,
207
208 #[arg(
210 long,
211 default_value = "on",
212 value_parser = ["on", "off"]
213 )]
214 pub sandbox: String,
215
216 #[arg(long, default_value = "600", value_name = "SECONDS")]
218 pub step_timeout: u64,
219}
220
221#[derive(clap::Args, Debug, PartialEq, Clone)]
222pub struct DashboardArgs {
223 #[arg(long, default_value = "7171", value_name = "N")]
225 pub port: u16,
226
227 #[arg(long = "root", value_name = "DIR")]
229 pub roots: Vec<PathBuf>,
230
231 #[arg(long = "runs-dir", value_name = "DIR")]
233 pub runs_dirs: Vec<PathBuf>,
234
235 #[arg(long, default_value = "24", value_name = "N")]
237 pub hours: u64,
238
239 #[arg(long)]
241 pub open: bool,
242}
243
244#[derive(Debug, PartialEq, Clone)]
245pub struct SurfaceArgs {
246 pub port: u16,
247 pub no_open: bool,
248 pub open_in: crate::open_window::OpenIn,
249 pub days: u64,
250 pub name: Option<String>,
251 pub resume: Option<String>,
252}
253
254impl Default for SurfaceArgs {
255 fn default() -> Self {
256 Self {
257 port: 0,
258 no_open: false,
259 open_in: crate::open_window::OpenIn::App,
260 days: 14,
261 name: None,
262 resume: None,
263 }
264 }
265}
266
267#[derive(clap::Args, Debug, PartialEq, Clone)]
268pub struct CombineArgs {
269 pub request: String,
271}
272
273#[derive(clap::Args, Debug, PartialEq, Clone)]
274pub struct EditStartArgs {
275 pub id: String,
277
278 #[arg(long, value_name = "TEXT")]
280 pub task: String,
281
282 #[arg(long, default_value = "HEAD")]
284 pub base: String,
285}
286
287#[derive(clap::Args, Debug, PartialEq, Clone)]
288pub struct EditFinishArgs {
289 pub id: String,
291
292 #[arg(long, value_name = "ID")]
294 pub request: Option<String>,
295
296 #[arg(long, value_name = "ID")]
298 pub surface: Option<String>,
299
300 #[arg(long, hide = true, value_name = "NAME")]
301 pub started_by: Option<String>,
302
303 #[arg(long, value_name = "TEXT")]
305 pub message: Option<String>,
306}
307
308#[derive(clap::Args, Debug, PartialEq, Clone)]
309pub struct DispatchArgs {
310 pub id: String,
312
313 pub task_file: Option<PathBuf>,
315
316 #[arg(short, long)]
318 pub gate: Option<String>,
319
320 #[arg(long = "tag", value_name = "TEXT")]
322 pub tags: Vec<String>,
323
324 #[arg(long, value_name = "PATH")]
326 pub plan: Option<String>,
327
328 #[arg(long, value_name = "TEXT")]
330 pub plan_task: Option<String>,
331
332 #[arg(long, value_name = "ID")]
334 pub request: Option<String>,
335
336 #[arg(long, value_name = "ID")]
338 pub surface: Option<String>,
339
340 #[arg(long, hide = true, value_name = "NAME")]
341 pub started_by: Option<String>,
342
343 #[arg(long, default_value = "HEAD")]
345 pub base: String,
346
347 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
349 pub research: bool,
350
351 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
353 pub report_to: Option<PathBuf>,
354
355 #[arg(short, long)]
357 pub model: Option<String>,
358
359 #[arg(long)]
361 pub max_seconds: Option<u64>,
362
363 #[arg(long)]
365 pub max_turns: Option<u32>,
366
367 #[arg(long = "max-cost")]
369 pub max_cost_usd: Option<f64>,
370
371 #[arg(long)]
373 pub fold_budget: Option<usize>,
374
375 #[arg(
377 long,
378 default_value = "on",
379 value_parser = ["on", "off"]
380 )]
381 pub sandbox: String,
382
383 #[arg(
385 long,
386 value_parser = ["on", "off"]
387 )]
388 pub network: Option<String>,
389
390 #[arg(long = "allow-read")]
392 pub allow_read: Vec<PathBuf>,
393
394 #[arg(long = "no-path-check")]
396 pub no_path_check: bool,
397
398 #[arg(long = "no-brief-check")]
400 pub no_brief_check: bool,
401
402 #[arg(long = "no-claim-check")]
404 pub no_claim_check: bool,
405
406 #[arg(long = "no-base-check")]
408 pub no_base_check: bool,
409
410 #[arg(long = "pass-env")]
412 pub pass_env: Vec<String>,
413}
414
415#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
416#[value(rename_all = "lowercase")]
417#[serde(rename_all = "lowercase")]
418pub enum ReviewVerdict {
419 Accepted,
420 Fixed,
421 Redone,
422}
423
424impl ReviewVerdict {
425 pub fn as_str(&self) -> &'static str {
426 match self {
427 Self::Accepted => "accepted",
428 Self::Fixed => "fixed",
429 Self::Redone => "redone",
430 }
431 }
432}
433
434impl std::fmt::Display for ReviewVerdict {
435 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
436 write!(f, "{}", self.as_str())
437 }
438}
439
440#[derive(clap::Args, Debug, PartialEq, Clone)]
441pub struct ReviewArgs {
442 pub id: String,
443
444 #[arg(long)]
445 pub diff: bool,
446
447 #[arg(long, value_enum)]
448 pub verdict: Option<ReviewVerdict>,
449
450 #[arg(long, value_name = "TEXT", requires = "verdict")]
451 pub notes: Option<String>,
452
453 #[arg(long, conflicts_with = "verdict")]
455 pub model_review: bool,
456}
457
458#[derive(clap::Args, Debug, PartialEq, Clone)]
459pub struct CleanArgs {
460 #[arg(long)]
462 pub dry_run: bool,
463
464 #[arg(long, default_value = "14", value_name = "DAYS")]
466 pub older_than: u64,
467
468 #[arg(long)]
470 pub all: bool,
471
472 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
473 pub quiet: bool,
474
475 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
476 pub skip: Option<String>,
477}
478
479#[derive(clap::Args, Debug, PartialEq, Clone)]
480pub struct CostArgs {
481 #[arg(long, value_name = "ID")]
483 pub session: Option<String>,
484
485 #[arg(long)]
487 pub by_session: bool,
488
489 #[arg(long, value_name = "UNIX_SECS")]
491 pub since: Option<u64>,
492
493 #[arg(long, value_name = "PATH")]
495 pub repo: Option<PathBuf>,
496
497 #[arg(long)]
499 pub json: bool,
500}
501
502#[derive(clap::Args, Debug, PartialEq, Clone)]
503pub struct StatuslineArgs {
504 #[arg(long, value_name = "COMMAND")]
506 pub after: Option<String>,
507}
508
509#[derive(clap::Args, Debug, PartialEq, Clone)]
510pub struct PlanArgs {
511 pub plan: PathBuf,
513
514 #[arg(long)]
516 pub json: bool,
517}
518
519#[derive(clap::Args, Debug, PartialEq, Clone)]
520pub struct CommentsArgs {
521 #[arg(long, value_name = "REV")]
523 pub base: String,
524}
525
526#[derive(clap::Args, Debug, PartialEq, Clone)]
527pub struct InstructionsArgs {
528 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
530 pub default_process: bool,
531
532 #[arg(long)]
534 pub one_shot: bool,
535
536 #[arg(long)]
538 pub dispatch_tool: bool,
539
540 #[arg(long, value_parser = ["on", "off"])]
542 pub sandbox: Option<String>,
543}
544
545#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
546pub enum SkillAction {
547 Install {
549 #[arg(long)]
551 project: bool,
552
553 #[arg(long)]
555 force: bool,
556
557 #[arg(long, hide = true)]
559 default: bool,
560
561 #[arg(long)]
563 no_default: bool,
564
565 #[arg(long)]
567 no_statusline: bool,
568
569 #[arg(long)]
571 no_autocompact: bool,
572
573 #[arg(
575 long,
576 default_value = "claude",
577 value_parser = ["claude", "codex", "all"]
578 )]
579 harness: String,
580
581 #[arg(long, value_name = "ID")]
583 model: Option<String>,
584 },
585
586 Uninstall {
588 #[arg(long)]
590 project: bool,
591
592 #[arg(
594 long,
595 default_value = "claude",
596 value_parser = ["claude", "codex", "all"]
597 )]
598 harness: String,
599 },
600
601 Print,
603}
604
605#[derive(clap::Args, Debug, PartialEq, Clone)]
606pub struct SkillArgs {
607 #[command(subcommand)]
608 pub action: SkillAction,
609}
610
611#[derive(Parser, Debug, PartialEq)]
612#[command(
613 name = "blyte",
614 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
615 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
616 subcommand_precedence_over_arg = true
617)]
618pub struct Cli {
619 #[command(subcommand)]
620 pub command: Option<Command>,
621
622 #[arg(index = 1)]
624 pub prompt: Option<String>,
625
626 #[arg(short, long)]
628 pub gate: Option<String>,
629
630 #[arg(long, conflicts_with = "gate")]
632 pub converse: bool,
633
634 #[arg(long, requires = "converse")]
636 pub dispatch_cmd: Option<String>,
637
638 #[arg(
640 long,
641 default_value = "folded",
642 value_parser = ["conversational", "folded"]
643 )]
644 pub context: String,
645
646 #[arg(short, long)]
648 pub model: Option<String>,
649
650 #[arg(long)]
652 pub container: Option<String>,
653
654 #[arg(long, default_value = "25")]
656 pub max_turns: usize,
657
658 #[arg(long, default_value = "5")]
660 pub max_gates: usize,
661
662 #[arg(
664 long,
665 default_value_t = true,
666 action = clap::ArgAction::Set,
667 num_args = 0..=1,
668 require_equals = true,
669 default_missing_value = "true",
670 value_parser = clap::builder::BoolishValueParser::new()
671 )]
672 pub rollback: bool,
673
674 #[arg(long, default_value = "/workspace")]
676 pub container_workdir: String,
677
678 #[arg(long)]
680 pub max_seconds: Option<u64>,
681
682 #[arg(long = "max-cost")]
684 pub max_cost_usd: Option<f64>,
685
686 #[arg(long)]
688 pub report: Option<PathBuf>,
689
690 #[arg(long)]
692 pub fold_budget: Option<usize>,
693
694 #[arg(
696 long,
697 default_value = "on",
698 value_parser = ["on", "off"]
699 )]
700 pub sandbox: String,
701
702 #[arg(
704 long,
705 value_parser = ["on", "off"]
706 )]
707 pub network: Option<String>,
708
709 #[arg(long = "allow-read")]
711 pub allow_read: Vec<PathBuf>,
712
713 #[arg(long = "pass-env")]
715 pub pass_env: Vec<String>,
716
717 #[arg(long = "read-root", value_name = "DIR")]
719 pub read_roots: Vec<PathBuf>,
720
721 #[arg(long)]
723 pub no_gate_slot: bool,
724
725 #[arg(
726 long = "snapshot-dir",
727 hide = true,
728 value_name = "DIR",
729 requires = "snapshot_manifest",
730 conflicts_with_all = ["container", "converse"]
731 )]
732 pub snapshot_dir: Option<PathBuf>,
733
734 #[arg(
735 long = "snapshot-manifest",
736 hide = true,
737 value_name = "FILE",
738 requires = "snapshot_dir",
739 conflicts_with_all = ["container", "converse"]
740 )]
741 pub snapshot_manifest: Option<PathBuf>,
742
743 #[arg(long)]
745 pub research: bool,
746
747 #[arg(long = "claim-check")]
749 pub claim_check: bool,
750
751 #[arg(long = "base-check")]
753 pub base_check: bool,
754
755 #[arg(long = "base-check-dir", value_name = "DIR")]
757 pub base_check_dir: Option<PathBuf>,
758
759 #[arg(
760 long,
761 help = "Run the surface in the terminal instead of opening the page"
762 )]
763 pub terminal: bool,
764
765 #[arg(
766 long,
767 value_name = "N",
768 help = "Port to listen on (default: a free port)"
769 )]
770 pub port: Option<u16>,
771
772 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
773 pub no_open: bool,
774
775 #[arg(
776 long = "open-in",
777 value_name = "app|browser",
778 help = "Open the live surface in an app window (`app`, default) or the default browser (`browser`)"
779 )]
780 pub open_in: Option<String>,
781
782 #[arg(
783 long,
784 value_name = "N",
785 value_parser = clap::value_parser!(u64).range(1..=31),
786 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
787 )]
788 pub days: Option<u64>,
789
790 #[arg(
791 long,
792 value_name = "NAME",
793 help = "Name for this surface (default: the repository directory name)"
794 )]
795 pub name: Option<String>,
796
797 #[arg(
798 long,
799 value_name = "NAME",
800 conflicts_with = "name",
801 help = "Restart a stopped surface, by name or id, with its transcript"
802 )]
803 pub resume: Option<String>,
804
805 #[arg(
806 long,
807 help = "Keep the surface attached to the terminal instead of detaching"
808 )]
809 pub foreground: bool,
810
811 #[arg(
812 long,
813 conflicts_with = "resume",
814 help = "Start a fresh surface without prompting to open or resume"
815 )]
816 pub new: bool,
817}
818
819fn parse_from_label(raw: &str) -> Result<String, String> {
820 crate::surface_dir::validate_surface_name(raw)?;
821 Ok(raw.to_string())
822}
823
824pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
826 if !cli.converse {
827 return;
828 }
829 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
830 cli.max_turns = 1000;
831 }
832 if cli.fold_budget.is_none() {
833 cli.fold_budget = Some(100_000);
834 }
835}