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