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 },
66 Open { name: String },
68 Tell {
70 name: String,
71 message: String,
72 #[arg(long, default_value = "terminal", value_name = "LABEL", value_parser = parse_from_label)]
73 from: String,
74 },
75 #[command(hide = true)]
77 Comments(CommentsArgs),
78 #[command(hide = true)]
80 Instructions(InstructionsArgs),
81}
82
83#[derive(clap::Args, Debug, PartialEq, Clone)]
84pub struct InitArgs {
85 #[arg(long)]
87 pub force: bool,
88
89 #[arg(long)]
91 pub print: bool,
92
93 #[arg(long)]
95 pub no_verify: bool,
96
97 #[arg(
99 long,
100 default_value = "on",
101 value_parser = ["on", "off"]
102 )]
103 pub sandbox: String,
104
105 #[arg(long, default_value = "600", value_name = "SECONDS")]
107 pub step_timeout: u64,
108}
109
110#[derive(clap::Args, Debug, PartialEq, Clone)]
111pub struct DashboardArgs {
112 #[arg(long, default_value = "7171", value_name = "N")]
114 pub port: u16,
115
116 #[arg(long = "root", value_name = "DIR")]
118 pub roots: Vec<PathBuf>,
119
120 #[arg(long = "runs-dir", value_name = "DIR")]
122 pub runs_dirs: Vec<PathBuf>,
123
124 #[arg(long, default_value = "24", value_name = "N")]
126 pub hours: u64,
127
128 #[arg(long)]
130 pub open: bool,
131}
132
133#[derive(Debug, PartialEq, Clone)]
134pub struct SurfaceArgs {
135 pub port: u16,
136 pub no_open: bool,
137 pub days: u64,
138 pub name: Option<String>,
139 pub resume: Option<String>,
140}
141
142impl Default for SurfaceArgs {
143 fn default() -> Self {
144 Self {
145 port: 0,
146 no_open: false,
147 days: 14,
148 name: None,
149 resume: None,
150 }
151 }
152}
153
154#[derive(clap::Args, Debug, PartialEq, Clone)]
155pub struct CombineArgs {
156 pub request: String,
158}
159
160#[derive(clap::Args, Debug, PartialEq, Clone)]
161pub struct EditStartArgs {
162 pub id: String,
164
165 #[arg(long, value_name = "TEXT")]
167 pub task: String,
168
169 #[arg(long, default_value = "HEAD")]
171 pub base: String,
172}
173
174#[derive(clap::Args, Debug, PartialEq, Clone)]
175pub struct EditFinishArgs {
176 pub id: String,
178
179 #[arg(long, value_name = "ID")]
181 pub request: Option<String>,
182
183 #[arg(long, value_name = "ID")]
185 pub surface: Option<String>,
186
187 #[arg(long, hide = true, value_name = "NAME")]
188 pub started_by: Option<String>,
189
190 #[arg(long, value_name = "TEXT")]
192 pub message: Option<String>,
193}
194
195#[derive(clap::Args, Debug, PartialEq, Clone)]
196pub struct DispatchArgs {
197 pub id: String,
199
200 pub task_file: Option<PathBuf>,
202
203 #[arg(short, long)]
205 pub gate: Option<String>,
206
207 #[arg(long = "tag", value_name = "TEXT")]
209 pub tags: Vec<String>,
210
211 #[arg(long, value_name = "PATH")]
213 pub plan: Option<String>,
214
215 #[arg(long, value_name = "TEXT")]
217 pub plan_task: Option<String>,
218
219 #[arg(long, value_name = "ID")]
221 pub request: Option<String>,
222
223 #[arg(long, value_name = "ID")]
225 pub surface: Option<String>,
226
227 #[arg(long, hide = true, value_name = "NAME")]
228 pub started_by: Option<String>,
229
230 #[arg(long, default_value = "HEAD")]
232 pub base: String,
233
234 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
236 pub research: bool,
237
238 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
240 pub report_to: Option<PathBuf>,
241
242 #[arg(short, long)]
244 pub model: Option<String>,
245
246 #[arg(long)]
248 pub max_seconds: Option<u64>,
249
250 #[arg(long)]
252 pub max_turns: Option<u32>,
253
254 #[arg(long = "max-cost")]
256 pub max_cost_usd: Option<f64>,
257
258 #[arg(long)]
260 pub fold_budget: Option<usize>,
261
262 #[arg(
264 long,
265 default_value = "on",
266 value_parser = ["on", "off"]
267 )]
268 pub sandbox: String,
269
270 #[arg(
272 long,
273 value_parser = ["on", "off"]
274 )]
275 pub network: Option<String>,
276
277 #[arg(long = "allow-read")]
279 pub allow_read: Vec<PathBuf>,
280
281 #[arg(long = "no-path-check")]
283 pub no_path_check: bool,
284
285 #[arg(long = "no-brief-check")]
287 pub no_brief_check: bool,
288
289 #[arg(long = "no-claim-check")]
291 pub no_claim_check: bool,
292
293 #[arg(long = "no-base-check")]
295 pub no_base_check: bool,
296
297 #[arg(long = "pass-env")]
299 pub pass_env: Vec<String>,
300}
301
302#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
303#[value(rename_all = "lowercase")]
304#[serde(rename_all = "lowercase")]
305pub enum ReviewVerdict {
306 Accepted,
307 Fixed,
308 Redone,
309}
310
311impl ReviewVerdict {
312 pub fn as_str(&self) -> &'static str {
313 match self {
314 Self::Accepted => "accepted",
315 Self::Fixed => "fixed",
316 Self::Redone => "redone",
317 }
318 }
319}
320
321impl std::fmt::Display for ReviewVerdict {
322 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
323 write!(f, "{}", self.as_str())
324 }
325}
326
327#[derive(clap::Args, Debug, PartialEq, Clone)]
328pub struct ReviewArgs {
329 pub id: String,
330
331 #[arg(long)]
332 pub diff: bool,
333
334 #[arg(long, value_enum)]
335 pub verdict: Option<ReviewVerdict>,
336
337 #[arg(long, value_name = "TEXT", requires = "verdict")]
338 pub notes: Option<String>,
339
340 #[arg(long, conflicts_with = "verdict")]
342 pub model_review: bool,
343}
344
345#[derive(clap::Args, Debug, PartialEq, Clone)]
346pub struct CleanArgs {
347 #[arg(long)]
349 pub dry_run: bool,
350
351 #[arg(long, default_value = "14", value_name = "DAYS")]
353 pub older_than: u64,
354
355 #[arg(long)]
357 pub all: bool,
358
359 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
360 pub quiet: bool,
361
362 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
363 pub skip: Option<String>,
364}
365
366#[derive(clap::Args, Debug, PartialEq, Clone)]
367pub struct CostArgs {
368 #[arg(long, value_name = "ID")]
370 pub session: Option<String>,
371
372 #[arg(long)]
374 pub by_session: bool,
375
376 #[arg(long, value_name = "UNIX_SECS")]
378 pub since: Option<u64>,
379
380 #[arg(long, value_name = "PATH")]
382 pub repo: Option<PathBuf>,
383
384 #[arg(long)]
386 pub json: bool,
387}
388
389#[derive(clap::Args, Debug, PartialEq, Clone)]
390pub struct StatuslineArgs {
391 #[arg(long, value_name = "COMMAND")]
393 pub after: Option<String>,
394}
395
396#[derive(clap::Args, Debug, PartialEq, Clone)]
397pub struct PlanArgs {
398 pub plan: PathBuf,
400
401 #[arg(long)]
403 pub json: bool,
404}
405
406#[derive(clap::Args, Debug, PartialEq, Clone)]
407pub struct CommentsArgs {
408 #[arg(long, value_name = "REV")]
410 pub base: String,
411}
412
413#[derive(clap::Args, Debug, PartialEq, Clone)]
414pub struct InstructionsArgs {
415 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
417 pub default_process: bool,
418
419 #[arg(long)]
421 pub one_shot: bool,
422
423 #[arg(long)]
425 pub dispatch_tool: bool,
426
427 #[arg(long, value_parser = ["on", "off"])]
429 pub sandbox: Option<String>,
430}
431
432#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
433pub enum SkillAction {
434 Install {
436 #[arg(long)]
438 project: bool,
439
440 #[arg(long)]
442 force: bool,
443
444 #[arg(long, hide = true)]
446 default: bool,
447
448 #[arg(long)]
450 no_default: bool,
451
452 #[arg(long)]
454 no_statusline: bool,
455
456 #[arg(long)]
458 no_autocompact: bool,
459
460 #[arg(
462 long,
463 default_value = "claude",
464 value_parser = ["claude", "codex", "all"]
465 )]
466 harness: String,
467
468 #[arg(long, value_name = "ID")]
470 model: Option<String>,
471 },
472
473 Uninstall {
475 #[arg(long)]
477 project: bool,
478
479 #[arg(
481 long,
482 default_value = "claude",
483 value_parser = ["claude", "codex", "all"]
484 )]
485 harness: String,
486 },
487
488 Print,
490}
491
492#[derive(clap::Args, Debug, PartialEq, Clone)]
493pub struct SkillArgs {
494 #[command(subcommand)]
495 pub action: SkillAction,
496}
497
498#[derive(Parser, Debug, PartialEq)]
499#[command(
500 name = "blyte",
501 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
502 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
503 subcommand_precedence_over_arg = true
504)]
505pub struct Cli {
506 #[command(subcommand)]
507 pub command: Option<Command>,
508
509 #[arg(index = 1)]
511 pub prompt: Option<String>,
512
513 #[arg(short, long)]
515 pub gate: Option<String>,
516
517 #[arg(long, conflicts_with = "gate")]
519 pub converse: bool,
520
521 #[arg(long, requires = "converse")]
523 pub dispatch_cmd: Option<String>,
524
525 #[arg(
527 long,
528 default_value = "folded",
529 value_parser = ["conversational", "folded"]
530 )]
531 pub context: String,
532
533 #[arg(short, long)]
535 pub model: Option<String>,
536
537 #[arg(long)]
539 pub container: Option<String>,
540
541 #[arg(long, default_value = "25")]
543 pub max_turns: usize,
544
545 #[arg(long, default_value = "5")]
547 pub max_gates: usize,
548
549 #[arg(
551 long,
552 default_value_t = true,
553 action = clap::ArgAction::Set,
554 num_args = 0..=1,
555 require_equals = true,
556 default_missing_value = "true",
557 value_parser = clap::builder::BoolishValueParser::new()
558 )]
559 pub rollback: bool,
560
561 #[arg(long, default_value = "/workspace")]
563 pub container_workdir: String,
564
565 #[arg(long)]
567 pub max_seconds: Option<u64>,
568
569 #[arg(long = "max-cost")]
571 pub max_cost_usd: Option<f64>,
572
573 #[arg(long)]
575 pub report: Option<PathBuf>,
576
577 #[arg(long)]
579 pub fold_budget: Option<usize>,
580
581 #[arg(
583 long,
584 default_value = "on",
585 value_parser = ["on", "off"]
586 )]
587 pub sandbox: String,
588
589 #[arg(
591 long,
592 value_parser = ["on", "off"]
593 )]
594 pub network: Option<String>,
595
596 #[arg(long = "allow-read")]
598 pub allow_read: Vec<PathBuf>,
599
600 #[arg(long = "pass-env")]
602 pub pass_env: Vec<String>,
603
604 #[arg(long = "read-root", value_name = "DIR")]
606 pub read_roots: Vec<PathBuf>,
607
608 #[arg(long)]
610 pub no_gate_slot: bool,
611
612 #[arg(long)]
614 pub research: bool,
615
616 #[arg(long = "claim-check")]
618 pub claim_check: bool,
619
620 #[arg(long = "base-check")]
622 pub base_check: bool,
623
624 #[arg(long = "base-check-dir", value_name = "DIR")]
626 pub base_check_dir: Option<PathBuf>,
627
628 #[arg(
629 long,
630 help = "Run the interactive terminal session instead of starting the live surface"
631 )]
632 pub terminal: bool,
633
634 #[arg(
635 long,
636 value_name = "N",
637 help = "Port to listen on (default: a free port)"
638 )]
639 pub port: Option<u16>,
640
641 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
642 pub no_open: bool,
643
644 #[arg(
645 long,
646 value_name = "N",
647 value_parser = clap::value_parser!(u64).range(1..=31),
648 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
649 )]
650 pub days: Option<u64>,
651
652 #[arg(
653 long,
654 value_name = "NAME",
655 help = "Name for this surface (default: the repository directory name)"
656 )]
657 pub name: Option<String>,
658
659 #[arg(
660 long,
661 value_name = "NAME",
662 conflicts_with = "name",
663 help = "Restart a stopped surface, by name or id, with its transcript"
664 )]
665 pub resume: Option<String>,
666}
667
668fn parse_from_label(raw: &str) -> Result<String, String> {
669 crate::surface_dir::validate_surface_name(raw)?;
670 Ok(raw.to_string())
671}
672
673pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
675 if !cli.converse {
676 return;
677 }
678 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
679 cli.max_turns = 1000;
680 }
681 if cli.fold_budget.is_none() {
682 cli.fold_budget = Some(100_000);
683 }
684}