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 Surfaces {
66 #[arg(long)]
67 json: bool,
68 },
69 Open { name: String },
71 #[command(hide = true)]
73 Comments(CommentsArgs),
74 #[command(hide = true)]
76 Instructions(InstructionsArgs),
77}
78
79#[derive(clap::Args, Debug, PartialEq, Clone)]
80pub struct InitArgs {
81 #[arg(long)]
83 pub force: bool,
84
85 #[arg(long)]
87 pub print: bool,
88
89 #[arg(long)]
91 pub no_verify: bool,
92
93 #[arg(
95 long,
96 default_value = "on",
97 value_parser = ["on", "off"]
98 )]
99 pub sandbox: String,
100
101 #[arg(long, default_value = "600", value_name = "SECONDS")]
103 pub step_timeout: u64,
104}
105
106#[derive(clap::Args, Debug, PartialEq, Clone)]
107pub struct DashboardArgs {
108 #[arg(long, default_value = "7171", value_name = "N")]
110 pub port: u16,
111
112 #[arg(long = "root", value_name = "DIR")]
114 pub roots: Vec<PathBuf>,
115
116 #[arg(long = "runs-dir", value_name = "DIR")]
118 pub runs_dirs: Vec<PathBuf>,
119
120 #[arg(long, default_value = "24", value_name = "N")]
122 pub hours: u64,
123
124 #[arg(long)]
126 pub open: bool,
127}
128
129#[derive(clap::Args, Debug, PartialEq, Clone)]
130pub struct SurfaceArgs {
131 #[arg(
132 long,
133 default_value_t = 0,
134 value_name = "N",
135 help = "Port to listen on (default: a free port)"
136 )]
137 pub port: u16,
138
139 #[arg(long, help = "Do not open the live surface in the browser")]
140 pub no_open: bool,
141
142 #[arg(
143 long,
144 default_value_t = 14,
145 value_name = "N",
146 value_parser = clap::value_parser!(u64).range(1..=31),
147 help = "How many days back to include finished runs (1 to 31)"
148 )]
149 pub days: u64,
150
151 #[arg(
152 long,
153 value_name = "NAME",
154 help = "Name for this surface (default: the repository directory name)"
155 )]
156 pub name: Option<String>,
157
158 #[arg(
159 long,
160 value_name = "NAME",
161 conflicts_with = "name",
162 help = "Restart a stopped surface, by name or id, with its transcript"
163 )]
164 pub resume: Option<String>,
165}
166
167impl Default for SurfaceArgs {
168 fn default() -> Self {
169 Self {
170 port: 0,
171 no_open: false,
172 days: 14,
173 name: None,
174 resume: None,
175 }
176 }
177}
178
179#[derive(clap::Args, Debug, PartialEq, Clone)]
180pub struct MockArgs {
181 #[arg(long, default_value = "7272", value_name = "N")]
183 pub port: u16,
184
185 #[arg(
187 long,
188 default_value = "7",
189 value_name = "N",
190 value_parser = clap::value_parser!(u64).range(1..=31)
191 )]
192 pub days: u64,
193
194 #[arg(long = "root", value_name = "DIR")]
196 pub roots: Vec<PathBuf>,
197}
198
199#[derive(clap::Args, Debug, PartialEq, Clone)]
200pub struct CombineArgs {
201 pub request: String,
203}
204
205#[derive(clap::Args, Debug, PartialEq, Clone)]
206pub struct EditStartArgs {
207 pub id: String,
209
210 #[arg(long, value_name = "TEXT")]
212 pub task: String,
213
214 #[arg(long, default_value = "HEAD")]
216 pub base: String,
217}
218
219#[derive(clap::Args, Debug, PartialEq, Clone)]
220pub struct EditFinishArgs {
221 pub id: String,
223
224 #[arg(long, value_name = "ID")]
226 pub request: Option<String>,
227
228 #[arg(long, value_name = "ID")]
230 pub surface: Option<String>,
231
232 #[arg(long, value_name = "TEXT")]
234 pub message: Option<String>,
235}
236
237#[derive(clap::Args, Debug, PartialEq, Clone)]
238pub struct DispatchArgs {
239 pub id: String,
241
242 pub task_file: Option<PathBuf>,
244
245 #[arg(short, long)]
247 pub gate: Option<String>,
248
249 #[arg(long = "tag", value_name = "TEXT")]
251 pub tags: Vec<String>,
252
253 #[arg(long, value_name = "PATH")]
255 pub plan: Option<String>,
256
257 #[arg(long, value_name = "TEXT")]
259 pub plan_task: Option<String>,
260
261 #[arg(long, value_name = "ID")]
263 pub request: Option<String>,
264
265 #[arg(long, value_name = "ID")]
267 pub surface: Option<String>,
268
269 #[arg(long, default_value = "HEAD")]
271 pub base: String,
272
273 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
275 pub research: bool,
276
277 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
279 pub report_to: Option<PathBuf>,
280
281 #[arg(short, long)]
283 pub model: Option<String>,
284
285 #[arg(long)]
287 pub max_seconds: Option<u64>,
288
289 #[arg(long)]
291 pub max_turns: Option<u32>,
292
293 #[arg(long = "max-cost")]
295 pub max_cost_usd: Option<f64>,
296
297 #[arg(long)]
299 pub fold_budget: Option<usize>,
300
301 #[arg(
303 long,
304 default_value = "on",
305 value_parser = ["on", "off"]
306 )]
307 pub sandbox: String,
308
309 #[arg(
311 long,
312 value_parser = ["on", "off"]
313 )]
314 pub network: Option<String>,
315
316 #[arg(long = "allow-read")]
318 pub allow_read: Vec<PathBuf>,
319
320 #[arg(long = "no-path-check")]
322 pub no_path_check: bool,
323
324 #[arg(long = "no-brief-check")]
326 pub no_brief_check: bool,
327
328 #[arg(long = "no-claim-check")]
330 pub no_claim_check: bool,
331
332 #[arg(long = "no-base-check")]
334 pub no_base_check: bool,
335
336 #[arg(long = "pass-env")]
338 pub pass_env: Vec<String>,
339}
340
341#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
342#[value(rename_all = "lowercase")]
343#[serde(rename_all = "lowercase")]
344pub enum ReviewVerdict {
345 Accepted,
346 Fixed,
347 Redone,
348}
349
350impl ReviewVerdict {
351 pub fn as_str(&self) -> &'static str {
352 match self {
353 Self::Accepted => "accepted",
354 Self::Fixed => "fixed",
355 Self::Redone => "redone",
356 }
357 }
358}
359
360impl std::fmt::Display for ReviewVerdict {
361 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
362 write!(f, "{}", self.as_str())
363 }
364}
365
366#[derive(clap::Args, Debug, PartialEq, Clone)]
367pub struct ReviewArgs {
368 pub id: String,
369
370 #[arg(long)]
371 pub diff: bool,
372
373 #[arg(long, value_enum)]
374 pub verdict: Option<ReviewVerdict>,
375
376 #[arg(long, value_name = "TEXT", requires = "verdict")]
377 pub notes: Option<String>,
378
379 #[arg(long, conflicts_with = "verdict")]
381 pub model_review: bool,
382}
383
384#[derive(clap::Args, Debug, PartialEq, Clone)]
385pub struct CleanArgs {
386 #[arg(long)]
388 pub dry_run: bool,
389
390 #[arg(long, default_value = "14", value_name = "DAYS")]
392 pub older_than: u64,
393
394 #[arg(long)]
396 pub all: bool,
397
398 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
399 pub quiet: bool,
400
401 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
402 pub skip: Option<String>,
403}
404
405#[derive(clap::Args, Debug, PartialEq, Clone)]
406pub struct CostArgs {
407 #[arg(long, value_name = "ID")]
409 pub session: Option<String>,
410
411 #[arg(long)]
413 pub by_session: bool,
414
415 #[arg(long, value_name = "UNIX_SECS")]
417 pub since: Option<u64>,
418
419 #[arg(long, value_name = "PATH")]
421 pub repo: Option<PathBuf>,
422
423 #[arg(long)]
425 pub json: bool,
426}
427
428#[derive(clap::Args, Debug, PartialEq, Clone)]
429pub struct StatuslineArgs {
430 #[arg(long, value_name = "COMMAND")]
432 pub after: Option<String>,
433}
434
435#[derive(clap::Args, Debug, PartialEq, Clone)]
436pub struct PlanArgs {
437 pub plan: PathBuf,
439
440 #[arg(long)]
442 pub json: bool,
443}
444
445#[derive(clap::Args, Debug, PartialEq, Clone)]
446pub struct CommentsArgs {
447 #[arg(long, value_name = "REV")]
449 pub base: String,
450}
451
452#[derive(clap::Args, Debug, PartialEq, Clone)]
453pub struct InstructionsArgs {
454 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
456 pub default_process: bool,
457
458 #[arg(long)]
460 pub one_shot: bool,
461
462 #[arg(long)]
464 pub dispatch_tool: bool,
465
466 #[arg(long, value_parser = ["on", "off"])]
468 pub sandbox: Option<String>,
469}
470
471#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
472pub enum SkillAction {
473 Install {
475 #[arg(long)]
477 project: bool,
478
479 #[arg(long)]
481 force: bool,
482
483 #[arg(long, hide = true)]
485 default: bool,
486
487 #[arg(long)]
489 no_default: bool,
490
491 #[arg(long)]
493 no_statusline: bool,
494
495 #[arg(long)]
497 no_autocompact: bool,
498
499 #[arg(
501 long,
502 default_value = "claude",
503 value_parser = ["claude", "codex", "all"]
504 )]
505 harness: String,
506
507 #[arg(long, value_name = "ID")]
509 model: Option<String>,
510 },
511
512 Uninstall {
514 #[arg(long)]
516 project: bool,
517
518 #[arg(
520 long,
521 default_value = "claude",
522 value_parser = ["claude", "codex", "all"]
523 )]
524 harness: String,
525 },
526
527 Print,
529}
530
531#[derive(clap::Args, Debug, PartialEq, Clone)]
532pub struct SkillArgs {
533 #[command(subcommand)]
534 pub action: SkillAction,
535}
536
537#[derive(Parser, Debug, PartialEq)]
538#[command(
539 name = "blyte",
540 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
541 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
542 subcommand_precedence_over_arg = true
543)]
544pub struct Cli {
545 #[command(subcommand)]
546 pub command: Option<Command>,
547
548 #[arg(index = 1)]
550 pub prompt: Option<String>,
551
552 #[arg(short, long)]
554 pub gate: Option<String>,
555
556 #[arg(long, conflicts_with = "gate")]
558 pub converse: bool,
559
560 #[arg(long, requires = "converse")]
562 pub dispatch_cmd: Option<String>,
563
564 #[arg(
566 long,
567 default_value = "folded",
568 value_parser = ["conversational", "folded"]
569 )]
570 pub context: String,
571
572 #[arg(short, long)]
574 pub model: Option<String>,
575
576 #[arg(long)]
578 pub container: Option<String>,
579
580 #[arg(long, default_value = "25")]
582 pub max_turns: usize,
583
584 #[arg(long, default_value = "5")]
586 pub max_gates: usize,
587
588 #[arg(
590 long,
591 default_value_t = true,
592 action = clap::ArgAction::Set,
593 num_args = 0..=1,
594 require_equals = true,
595 default_missing_value = "true",
596 value_parser = clap::builder::BoolishValueParser::new()
597 )]
598 pub rollback: bool,
599
600 #[arg(long, default_value = "/workspace")]
602 pub container_workdir: String,
603
604 #[arg(long)]
606 pub max_seconds: Option<u64>,
607
608 #[arg(long = "max-cost")]
610 pub max_cost_usd: Option<f64>,
611
612 #[arg(long)]
614 pub report: Option<PathBuf>,
615
616 #[arg(long)]
618 pub fold_budget: Option<usize>,
619
620 #[arg(
622 long,
623 default_value = "on",
624 value_parser = ["on", "off"]
625 )]
626 pub sandbox: String,
627
628 #[arg(
630 long,
631 value_parser = ["on", "off"]
632 )]
633 pub network: Option<String>,
634
635 #[arg(long = "allow-read")]
637 pub allow_read: Vec<PathBuf>,
638
639 #[arg(long = "pass-env")]
641 pub pass_env: Vec<String>,
642
643 #[arg(long = "read-root", value_name = "DIR")]
645 pub read_roots: Vec<PathBuf>,
646
647 #[arg(long)]
649 pub no_gate_slot: bool,
650
651 #[arg(long)]
653 pub research: bool,
654
655 #[arg(long = "claim-check")]
657 pub claim_check: bool,
658
659 #[arg(long = "base-check")]
661 pub base_check: bool,
662
663 #[arg(long = "base-check-dir", value_name = "DIR")]
665 pub base_check_dir: Option<PathBuf>,
666
667 #[arg(
668 long,
669 help = "Run the interactive terminal session instead of starting the live surface"
670 )]
671 pub terminal: bool,
672
673 #[arg(
674 long,
675 value_name = "N",
676 help = "Port to listen on (default: a free port)"
677 )]
678 pub port: Option<u16>,
679
680 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
681 pub no_open: bool,
682
683 #[arg(
684 long,
685 value_name = "N",
686 value_parser = clap::value_parser!(u64).range(1..=31),
687 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
688 )]
689 pub days: Option<u64>,
690
691 #[arg(
692 long,
693 value_name = "NAME",
694 help = "Name for this surface (default: the repository directory name)"
695 )]
696 pub name: Option<String>,
697
698 #[arg(
699 long,
700 value_name = "NAME",
701 conflicts_with = "name",
702 help = "Restart a stopped surface, by name or id, with its transcript"
703 )]
704 pub resume: Option<String>,
705}
706
707pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
709 if !cli.converse {
710 return;
711 }
712 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
713 cli.max_turns = 1000;
714 }
715 if cli.fold_budget.is_none() {
716 cli.fold_budget = Some(100_000);
717 }
718}