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(long = "client-id", value_name = "ID")]
159 pub client_id: Option<String>,
160 #[arg(long = "client-secret", value_name = "SECRET")]
162 pub client_secret: Option<String>,
163 #[arg(long = "callback-port", value_name = "PORT")]
165 pub callback_port: Option<u16>,
166 #[arg(long = "scope", value_name = "SCOPE")]
168 pub scopes: Vec<String>,
169 #[arg(last = true, value_name = "ARGS")]
171 pub args: Vec<String>,
172}
173
174#[derive(clap::Args, Debug, PartialEq, Clone)]
175pub struct UndoArgs {
176 pub id: String,
178}
179
180#[derive(clap::Args, Debug, PartialEq, Clone)]
181pub struct ReloadArgs {
182 #[arg(value_name = "NAME", conflicts_with = "all")]
184 pub target: Option<String>,
185
186 #[arg(long)]
188 pub all: bool,
189}
190
191#[derive(clap::Args, Debug, PartialEq, Clone)]
192pub struct StopArgs {
193 #[arg(value_name = "NAME", conflicts_with = "all")]
195 pub target: Option<String>,
196
197 #[arg(long)]
199 pub all: bool,
200
201 #[arg(long)]
203 pub force: bool,
204}
205
206#[derive(clap::Args, Debug, PartialEq, Clone)]
207pub struct InitArgs {
208 #[arg(long)]
210 pub force: bool,
211
212 #[arg(long)]
214 pub print: bool,
215
216 #[arg(long)]
218 pub no_verify: bool,
219
220 #[arg(
222 long,
223 default_value = "on",
224 value_parser = ["on", "off"]
225 )]
226 pub sandbox: String,
227
228 #[arg(long, default_value = "600", value_name = "SECONDS")]
230 pub step_timeout: u64,
231}
232
233#[derive(clap::Args, Debug, PartialEq, Clone)]
234pub struct DashboardArgs {
235 #[arg(long, default_value = "7171", value_name = "N")]
237 pub port: u16,
238
239 #[arg(long = "root", value_name = "DIR")]
241 pub roots: Vec<PathBuf>,
242
243 #[arg(long = "runs-dir", value_name = "DIR")]
245 pub runs_dirs: Vec<PathBuf>,
246
247 #[arg(long, default_value = "24", value_name = "N")]
249 pub hours: u64,
250
251 #[arg(long)]
253 pub open: bool,
254}
255
256#[derive(Debug, PartialEq, Clone)]
257pub struct SurfaceArgs {
258 pub port: u16,
259 pub no_open: bool,
260 pub open_in: crate::open_window::OpenIn,
261 pub days: u64,
262 pub name: Option<String>,
263 pub resume: Option<String>,
264}
265
266impl Default for SurfaceArgs {
267 fn default() -> Self {
268 Self {
269 port: 0,
270 no_open: false,
271 open_in: crate::open_window::OpenIn::App,
272 days: 14,
273 name: None,
274 resume: None,
275 }
276 }
277}
278
279#[derive(clap::Args, Debug, PartialEq, Clone)]
280pub struct CombineArgs {
281 pub request: String,
283}
284
285#[derive(clap::Args, Debug, PartialEq, Clone)]
286pub struct EditStartArgs {
287 pub id: String,
289
290 #[arg(long, value_name = "TEXT")]
292 pub task: String,
293
294 #[arg(long, default_value = "HEAD")]
296 pub base: String,
297}
298
299#[derive(clap::Args, Debug, PartialEq, Clone)]
300pub struct EditFinishArgs {
301 pub id: String,
303
304 #[arg(long, value_name = "ID")]
306 pub request: Option<String>,
307
308 #[arg(long, value_name = "ID")]
310 pub surface: Option<String>,
311
312 #[arg(long, hide = true, value_name = "NAME")]
313 pub started_by: Option<String>,
314
315 #[arg(long, value_name = "TEXT")]
317 pub message: Option<String>,
318}
319
320#[derive(clap::Args, Debug, PartialEq, Clone)]
321pub struct DispatchArgs {
322 pub id: String,
324
325 pub task_file: Option<PathBuf>,
327
328 #[arg(short, long)]
330 pub gate: Option<String>,
331
332 #[arg(long = "tag", value_name = "TEXT")]
334 pub tags: Vec<String>,
335
336 #[arg(long, value_name = "PATH")]
338 pub plan: Option<String>,
339
340 #[arg(long, value_name = "TEXT")]
342 pub plan_task: Option<String>,
343
344 #[arg(long, value_name = "ID")]
346 pub request: Option<String>,
347
348 #[arg(long, value_name = "ID")]
350 pub surface: Option<String>,
351
352 #[arg(long, hide = true, value_name = "NAME")]
353 pub started_by: Option<String>,
354
355 #[arg(long, default_value = "HEAD")]
357 pub base: String,
358
359 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
361 pub research: bool,
362
363 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
365 pub report_to: Option<PathBuf>,
366
367 #[arg(short, long)]
369 pub model: Option<String>,
370
371 #[arg(long)]
373 pub max_seconds: Option<u64>,
374
375 #[arg(long)]
377 pub max_turns: Option<u32>,
378
379 #[arg(long = "max-cost")]
381 pub max_cost_usd: Option<f64>,
382
383 #[arg(long)]
385 pub fold_budget: Option<usize>,
386
387 #[arg(
389 long,
390 default_value = "on",
391 value_parser = ["on", "off"]
392 )]
393 pub sandbox: String,
394
395 #[arg(
397 long,
398 value_parser = ["on", "off"]
399 )]
400 pub network: Option<String>,
401
402 #[arg(long = "allow-read")]
404 pub allow_read: Vec<PathBuf>,
405
406 #[arg(long = "no-path-check")]
408 pub no_path_check: bool,
409
410 #[arg(long = "no-brief-check")]
412 pub no_brief_check: bool,
413
414 #[arg(long = "no-claim-check")]
416 pub no_claim_check: bool,
417
418 #[arg(long = "no-base-check")]
420 pub no_base_check: bool,
421
422 #[arg(long = "pass-env")]
424 pub pass_env: Vec<String>,
425}
426
427#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
428#[value(rename_all = "lowercase")]
429#[serde(rename_all = "lowercase")]
430pub enum ReviewVerdict {
431 Accepted,
432 Fixed,
433 Redone,
434}
435
436impl ReviewVerdict {
437 pub fn as_str(&self) -> &'static str {
438 match self {
439 Self::Accepted => "accepted",
440 Self::Fixed => "fixed",
441 Self::Redone => "redone",
442 }
443 }
444}
445
446impl std::fmt::Display for ReviewVerdict {
447 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
448 write!(f, "{}", self.as_str())
449 }
450}
451
452#[derive(clap::Args, Debug, PartialEq, Clone)]
453pub struct ReviewArgs {
454 pub id: String,
455
456 #[arg(long)]
457 pub diff: bool,
458
459 #[arg(long, value_enum)]
460 pub verdict: Option<ReviewVerdict>,
461
462 #[arg(long, value_name = "TEXT", requires = "verdict")]
463 pub notes: Option<String>,
464
465 #[arg(long, conflicts_with = "verdict")]
467 pub model_review: bool,
468}
469
470#[derive(clap::Args, Debug, PartialEq, Clone)]
471pub struct CleanArgs {
472 #[arg(long)]
474 pub dry_run: bool,
475
476 #[arg(long, default_value = "14", value_name = "DAYS")]
478 pub older_than: u64,
479
480 #[arg(long)]
482 pub all: bool,
483
484 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
485 pub quiet: bool,
486
487 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
488 pub skip: Option<String>,
489}
490
491#[derive(clap::Args, Debug, PartialEq, Clone)]
492pub struct CostArgs {
493 #[arg(long, value_name = "ID")]
495 pub session: Option<String>,
496
497 #[arg(long)]
499 pub by_session: bool,
500
501 #[arg(long, value_name = "UNIX_SECS")]
503 pub since: Option<u64>,
504
505 #[arg(long, value_name = "PATH")]
507 pub repo: Option<PathBuf>,
508
509 #[arg(long)]
511 pub json: bool,
512}
513
514#[derive(clap::Args, Debug, PartialEq, Clone)]
515pub struct StatuslineArgs {
516 #[arg(long, value_name = "COMMAND")]
518 pub after: Option<String>,
519}
520
521#[derive(clap::Args, Debug, PartialEq, Clone)]
522pub struct PlanArgs {
523 pub plan: PathBuf,
525
526 #[arg(long)]
528 pub json: bool,
529}
530
531#[derive(clap::Args, Debug, PartialEq, Clone)]
532pub struct CommentsArgs {
533 #[arg(long, value_name = "REV")]
535 pub base: String,
536}
537
538#[derive(clap::Args, Debug, PartialEq, Clone)]
539pub struct InstructionsArgs {
540 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
542 pub default_process: bool,
543
544 #[arg(long)]
546 pub one_shot: bool,
547
548 #[arg(long)]
550 pub dispatch_tool: bool,
551
552 #[arg(long, value_parser = ["on", "off"])]
554 pub sandbox: Option<String>,
555}
556
557#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
558pub enum SkillAction {
559 Install {
561 #[arg(long)]
563 project: bool,
564
565 #[arg(long)]
567 force: bool,
568
569 #[arg(long, hide = true)]
571 default: bool,
572
573 #[arg(long)]
575 no_default: bool,
576
577 #[arg(long)]
579 no_statusline: bool,
580
581 #[arg(long)]
583 no_autocompact: bool,
584
585 #[arg(
587 long,
588 default_value = "claude",
589 value_parser = ["claude", "codex", "all"]
590 )]
591 harness: String,
592
593 #[arg(long, value_name = "ID")]
595 model: Option<String>,
596 },
597
598 Uninstall {
600 #[arg(long)]
602 project: bool,
603
604 #[arg(
606 long,
607 default_value = "claude",
608 value_parser = ["claude", "codex", "all"]
609 )]
610 harness: String,
611 },
612
613 Print,
615}
616
617#[derive(clap::Args, Debug, PartialEq, Clone)]
618pub struct SkillArgs {
619 #[command(subcommand)]
620 pub action: SkillAction,
621}
622
623#[derive(Parser, Debug, PartialEq)]
624#[command(
625 name = "blyte",
626 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
627 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
628 subcommand_precedence_over_arg = true
629)]
630pub struct Cli {
631 #[command(subcommand)]
632 pub command: Option<Command>,
633
634 #[arg(index = 1)]
636 pub prompt: Option<String>,
637
638 #[arg(short, long)]
640 pub gate: Option<String>,
641
642 #[arg(long, conflicts_with = "gate")]
644 pub converse: bool,
645
646 #[arg(long, requires = "converse")]
648 pub dispatch_cmd: Option<String>,
649
650 #[arg(
652 long,
653 default_value = "folded",
654 value_parser = ["conversational", "folded"]
655 )]
656 pub context: String,
657
658 #[arg(short, long)]
660 pub model: Option<String>,
661
662 #[arg(long)]
664 pub container: Option<String>,
665
666 #[arg(long, default_value = "25")]
668 pub max_turns: usize,
669
670 #[arg(long, default_value = "5")]
672 pub max_gates: usize,
673
674 #[arg(
676 long,
677 default_value_t = true,
678 action = clap::ArgAction::Set,
679 num_args = 0..=1,
680 require_equals = true,
681 default_missing_value = "true",
682 value_parser = clap::builder::BoolishValueParser::new()
683 )]
684 pub rollback: bool,
685
686 #[arg(long, default_value = "/workspace")]
688 pub container_workdir: String,
689
690 #[arg(long)]
692 pub max_seconds: Option<u64>,
693
694 #[arg(long = "max-cost")]
696 pub max_cost_usd: Option<f64>,
697
698 #[arg(long)]
700 pub report: Option<PathBuf>,
701
702 #[arg(long)]
704 pub fold_budget: Option<usize>,
705
706 #[arg(
708 long,
709 default_value = "on",
710 value_parser = ["on", "off"]
711 )]
712 pub sandbox: String,
713
714 #[arg(
716 long,
717 value_parser = ["on", "off"]
718 )]
719 pub network: Option<String>,
720
721 #[arg(long = "allow-read")]
723 pub allow_read: Vec<PathBuf>,
724
725 #[arg(long = "pass-env")]
727 pub pass_env: Vec<String>,
728
729 #[arg(long = "read-root", value_name = "DIR")]
731 pub read_roots: Vec<PathBuf>,
732
733 #[arg(long)]
735 pub no_gate_slot: bool,
736
737 #[arg(
738 long = "snapshot-dir",
739 hide = true,
740 value_name = "DIR",
741 requires = "snapshot_manifest",
742 conflicts_with_all = ["container", "converse"]
743 )]
744 pub snapshot_dir: Option<PathBuf>,
745
746 #[arg(
747 long = "snapshot-manifest",
748 hide = true,
749 value_name = "FILE",
750 requires = "snapshot_dir",
751 conflicts_with_all = ["container", "converse"]
752 )]
753 pub snapshot_manifest: Option<PathBuf>,
754
755 #[arg(long)]
757 pub research: bool,
758
759 #[arg(long = "claim-check")]
761 pub claim_check: bool,
762
763 #[arg(long = "base-check")]
765 pub base_check: bool,
766
767 #[arg(long = "base-check-dir", value_name = "DIR")]
769 pub base_check_dir: Option<PathBuf>,
770
771 #[arg(
772 long,
773 help = "Run the surface in the terminal instead of opening the page"
774 )]
775 pub terminal: bool,
776
777 #[arg(
778 long,
779 value_name = "N",
780 help = "Port to listen on (default: a free port)"
781 )]
782 pub port: Option<u16>,
783
784 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
785 pub no_open: bool,
786
787 #[arg(
788 long = "open-in",
789 value_name = "app|browser",
790 help = "Open the live surface in an app window (`app`, default) or the default browser (`browser`)"
791 )]
792 pub open_in: Option<String>,
793
794 #[arg(
795 long,
796 value_name = "N",
797 value_parser = clap::value_parser!(u64).range(1..=31),
798 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
799 )]
800 pub days: Option<u64>,
801
802 #[arg(
803 long,
804 value_name = "NAME",
805 help = "Name for this surface (default: the repository directory name)"
806 )]
807 pub name: Option<String>,
808
809 #[arg(
810 long,
811 value_name = "NAME",
812 conflicts_with = "name",
813 help = "Restart a stopped surface, by name or id, with its transcript"
814 )]
815 pub resume: Option<String>,
816
817 #[arg(
818 long,
819 help = "Keep the surface attached to the terminal instead of detaching"
820 )]
821 pub foreground: bool,
822
823 #[arg(
824 long,
825 conflicts_with = "resume",
826 help = "Start a fresh surface without prompting to open or resume"
827 )]
828 pub new: bool,
829}
830
831fn parse_from_label(raw: &str) -> Result<String, String> {
832 crate::surface_dir::validate_surface_name(raw)?;
833 Ok(raw.to_string())
834}
835
836pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
838 if !cli.converse {
839 return;
840 }
841 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
842 cli.max_turns = 1000;
843 }
844 if cli.fold_budget.is_none() {
845 cli.fold_budget = Some(100_000);
846 }
847}