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 Mock(MockArgs),
14 Combine(CombineArgs),
16 Dispatch(DispatchArgs),
18 EditStart(EditStartArgs),
20 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 Comments(CommentsArgs),
63 Instructions(InstructionsArgs),
65}
66
67#[derive(clap::Args, Debug, PartialEq, Clone)]
68pub struct InitArgs {
69 #[arg(long)]
71 pub force: bool,
72
73 #[arg(long)]
75 pub print: bool,
76
77 #[arg(long)]
79 pub no_verify: bool,
80
81 #[arg(
83 long,
84 default_value = "on",
85 value_parser = ["on", "off"]
86 )]
87 pub sandbox: String,
88
89 #[arg(long, default_value = "600", value_name = "SECONDS")]
91 pub step_timeout: u64,
92}
93
94#[derive(clap::Args, Debug, PartialEq, Clone)]
95pub struct DashboardArgs {
96 #[arg(long, default_value = "7171", value_name = "N")]
98 pub port: u16,
99
100 #[arg(long = "root", value_name = "DIR")]
102 pub roots: Vec<PathBuf>,
103
104 #[arg(long = "runs-dir", value_name = "DIR")]
106 pub runs_dirs: Vec<PathBuf>,
107
108 #[arg(long, default_value = "24", value_name = "N")]
110 pub hours: u64,
111
112 #[arg(long)]
114 pub open: bool,
115}
116
117#[derive(clap::Args, Debug, PartialEq, Clone)]
118pub struct SurfaceArgs {
119 #[arg(
120 long,
121 default_value_t = 0,
122 value_name = "N",
123 help = "Port to listen on (0 picks a free port)"
124 )]
125 pub port: u16,
126
127 #[arg(long, help = "Do not open the live surface in the browser")]
128 pub no_open: bool,
129
130 #[arg(
131 long,
132 default_value_t = 14,
133 value_name = "N",
134 value_parser = clap::value_parser!(u64).range(1..=31),
135 help = "How many days back to include finished runs (1 to 31)"
136 )]
137 pub days: u64,
138}
139
140impl Default for SurfaceArgs {
141 fn default() -> Self {
142 Self {
143 port: 0,
144 no_open: false,
145 days: 14,
146 }
147 }
148}
149
150#[derive(clap::Args, Debug, PartialEq, Clone)]
151pub struct MockArgs {
152 #[arg(long, default_value = "7272", value_name = "N")]
154 pub port: u16,
155
156 #[arg(
158 long,
159 default_value = "7",
160 value_name = "N",
161 value_parser = clap::value_parser!(u64).range(1..=31)
162 )]
163 pub days: u64,
164
165 #[arg(long = "root", value_name = "DIR")]
167 pub roots: Vec<PathBuf>,
168}
169
170#[derive(clap::Args, Debug, PartialEq, Clone)]
171pub struct CombineArgs {
172 pub request: String,
174}
175
176#[derive(clap::Args, Debug, PartialEq, Clone)]
177pub struct EditStartArgs {
178 pub id: String,
180
181 #[arg(long, value_name = "TEXT")]
183 pub task: String,
184
185 #[arg(long, default_value = "HEAD")]
187 pub base: String,
188}
189
190#[derive(clap::Args, Debug, PartialEq, Clone)]
191pub struct EditFinishArgs {
192 pub id: String,
194
195 #[arg(long, value_name = "ID")]
197 pub request: Option<String>,
198
199 #[arg(long, value_name = "TEXT")]
201 pub message: Option<String>,
202}
203
204#[derive(clap::Args, Debug, PartialEq, Clone)]
205pub struct DispatchArgs {
206 pub id: String,
208
209 pub task_file: Option<PathBuf>,
211
212 #[arg(short, long)]
214 pub gate: Option<String>,
215
216 #[arg(long = "tag", value_name = "TEXT")]
218 pub tags: Vec<String>,
219
220 #[arg(long, value_name = "PATH")]
222 pub plan: Option<String>,
223
224 #[arg(long, value_name = "TEXT")]
226 pub plan_task: Option<String>,
227
228 #[arg(long, value_name = "ID")]
230 pub request: Option<String>,
231
232 #[arg(long, default_value = "HEAD")]
234 pub base: String,
235
236 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
238 pub research: bool,
239
240 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
242 pub report_to: Option<PathBuf>,
243
244 #[arg(short, long)]
246 pub model: Option<String>,
247
248 #[arg(long)]
250 pub max_seconds: Option<u64>,
251
252 #[arg(long)]
254 pub max_turns: Option<u32>,
255
256 #[arg(long = "max-cost")]
258 pub max_cost_usd: Option<f64>,
259
260 #[arg(long)]
262 pub fold_budget: Option<usize>,
263
264 #[arg(
266 long,
267 default_value = "on",
268 value_parser = ["on", "off"]
269 )]
270 pub sandbox: String,
271
272 #[arg(
274 long,
275 value_parser = ["on", "off"]
276 )]
277 pub network: Option<String>,
278
279 #[arg(long = "allow-read")]
281 pub allow_read: Vec<PathBuf>,
282
283 #[arg(long = "no-path-check")]
285 pub no_path_check: bool,
286
287 #[arg(long = "no-brief-check")]
289 pub no_brief_check: bool,
290
291 #[arg(long = "no-claim-check")]
293 pub no_claim_check: bool,
294
295 #[arg(long = "no-base-check")]
297 pub no_base_check: bool,
298
299 #[arg(long = "pass-env")]
301 pub pass_env: Vec<String>,
302}
303
304#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
305#[value(rename_all = "lowercase")]
306#[serde(rename_all = "lowercase")]
307pub enum ReviewVerdict {
308 Accepted,
309 Fixed,
310 Redone,
311}
312
313impl ReviewVerdict {
314 pub fn as_str(&self) -> &'static str {
315 match self {
316 Self::Accepted => "accepted",
317 Self::Fixed => "fixed",
318 Self::Redone => "redone",
319 }
320 }
321}
322
323impl std::fmt::Display for ReviewVerdict {
324 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
325 write!(f, "{}", self.as_str())
326 }
327}
328
329#[derive(clap::Args, Debug, PartialEq, Clone)]
330pub struct ReviewArgs {
331 pub id: String,
332
333 #[arg(long)]
334 pub diff: bool,
335
336 #[arg(long, value_enum)]
337 pub verdict: Option<ReviewVerdict>,
338
339 #[arg(long, value_name = "TEXT", requires = "verdict")]
340 pub notes: Option<String>,
341
342 #[arg(long, conflicts_with = "verdict")]
344 pub model_review: bool,
345}
346
347#[derive(clap::Args, Debug, PartialEq, Clone)]
348pub struct CleanArgs {
349 #[arg(long)]
351 pub dry_run: bool,
352
353 #[arg(long, default_value = "14", value_name = "DAYS")]
355 pub older_than: u64,
356
357 #[arg(long)]
359 pub all: bool,
360
361 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
362 pub quiet: bool,
363
364 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
365 pub skip: Option<String>,
366}
367
368#[derive(clap::Args, Debug, PartialEq, Clone)]
369pub struct CostArgs {
370 #[arg(long, value_name = "ID")]
372 pub session: Option<String>,
373
374 #[arg(long)]
376 pub by_session: bool,
377
378 #[arg(long, value_name = "UNIX_SECS")]
380 pub since: Option<u64>,
381
382 #[arg(long, value_name = "PATH")]
384 pub repo: Option<PathBuf>,
385
386 #[arg(long)]
388 pub json: bool,
389}
390
391#[derive(clap::Args, Debug, PartialEq, Clone)]
392pub struct StatuslineArgs {
393 #[arg(long, value_name = "COMMAND")]
395 pub after: Option<String>,
396}
397
398#[derive(clap::Args, Debug, PartialEq, Clone)]
399pub struct PlanArgs {
400 pub plan: PathBuf,
402
403 #[arg(long)]
405 pub json: bool,
406}
407
408#[derive(clap::Args, Debug, PartialEq, Clone)]
409pub struct CommentsArgs {
410 #[arg(long, value_name = "REV")]
412 pub base: String,
413}
414
415#[derive(clap::Args, Debug, PartialEq, Clone)]
416pub struct InstructionsArgs {
417 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
419 pub default_process: bool,
420
421 #[arg(long)]
423 pub one_shot: bool,
424
425 #[arg(long)]
427 pub dispatch_tool: bool,
428
429 #[arg(long, value_parser = ["on", "off"])]
431 pub sandbox: Option<String>,
432}
433
434#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
435pub enum SkillAction {
436 Install {
438 #[arg(long)]
440 project: bool,
441
442 #[arg(long)]
444 force: bool,
445
446 #[arg(long, hide = true)]
448 default: bool,
449
450 #[arg(long)]
452 no_default: bool,
453
454 #[arg(long)]
456 no_statusline: bool,
457
458 #[arg(long)]
460 no_autocompact: bool,
461
462 #[arg(
464 long,
465 default_value = "claude",
466 value_parser = ["claude", "codex", "all"]
467 )]
468 harness: String,
469
470 #[arg(long, value_name = "ID")]
472 model: Option<String>,
473 },
474
475 Uninstall {
477 #[arg(long)]
479 project: bool,
480
481 #[arg(
483 long,
484 default_value = "claude",
485 value_parser = ["claude", "codex", "all"]
486 )]
487 harness: String,
488 },
489
490 Print,
492}
493
494#[derive(clap::Args, Debug, PartialEq, Clone)]
495pub struct SkillArgs {
496 #[command(subcommand)]
497 pub action: SkillAction,
498}
499
500#[derive(Parser, Debug, PartialEq)]
501#[command(
502 name = "blyte",
503 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
504 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
505 subcommand_precedence_over_arg = true
506)]
507pub struct Cli {
508 #[command(subcommand)]
509 pub command: Option<Command>,
510
511 #[arg(index = 1)]
513 pub prompt: Option<String>,
514
515 #[arg(short, long)]
517 pub gate: Option<String>,
518
519 #[arg(long, conflicts_with = "gate")]
521 pub orchestrate: bool,
522
523 #[arg(long, requires = "orchestrate")]
525 pub dispatch_cmd: Option<String>,
526
527 #[arg(
529 long,
530 default_value = "folded",
531 value_parser = ["conversational", "folded"]
532 )]
533 pub context: String,
534
535 #[arg(short, long)]
537 pub model: Option<String>,
538
539 #[arg(long)]
541 pub container: Option<String>,
542
543 #[arg(long, default_value = "25")]
545 pub max_turns: usize,
546
547 #[arg(long, default_value = "5")]
549 pub max_gates: usize,
550
551 #[arg(
553 long,
554 default_value_t = true,
555 action = clap::ArgAction::Set,
556 num_args = 0..=1,
557 require_equals = true,
558 default_missing_value = "true",
559 value_parser = clap::builder::BoolishValueParser::new()
560 )]
561 pub rollback: bool,
562
563 #[arg(long, default_value = "/workspace")]
565 pub container_workdir: String,
566
567 #[arg(long)]
569 pub max_seconds: Option<u64>,
570
571 #[arg(long = "max-cost")]
573 pub max_cost_usd: Option<f64>,
574
575 #[arg(long)]
577 pub report: Option<PathBuf>,
578
579 #[arg(long)]
581 pub fold_budget: Option<usize>,
582
583 #[arg(
585 long,
586 default_value = "on",
587 value_parser = ["on", "off"]
588 )]
589 pub sandbox: String,
590
591 #[arg(
593 long,
594 value_parser = ["on", "off"]
595 )]
596 pub network: Option<String>,
597
598 #[arg(long = "allow-read")]
600 pub allow_read: Vec<PathBuf>,
601
602 #[arg(long = "pass-env")]
604 pub pass_env: Vec<String>,
605
606 #[arg(long = "read-root", value_name = "DIR")]
608 pub read_roots: Vec<PathBuf>,
609
610 #[arg(long)]
612 pub no_gate_slot: bool,
613
614 #[arg(long)]
616 pub research: bool,
617
618 #[arg(long = "claim-check")]
620 pub claim_check: bool,
621
622 #[arg(long = "base-check")]
624 pub base_check: bool,
625
626 #[arg(long = "base-check-dir", value_name = "DIR")]
628 pub base_check_dir: Option<PathBuf>,
629
630 #[arg(
631 long,
632 help = "Run the interactive terminal session instead of starting the live surface"
633 )]
634 pub terminal: bool,
635
636 #[arg(
637 long,
638 value_name = "N",
639 help = "Port for the live surface (0 picks a free port)"
640 )]
641 pub port: Option<u16>,
642
643 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
644 pub no_open: bool,
645
646 #[arg(
647 long,
648 value_name = "N",
649 value_parser = clap::value_parser!(u64).range(1..=31),
650 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
651 )]
652 pub days: Option<u64>,
653}
654
655pub fn apply_orchestrate_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
657 if !cli.orchestrate {
658 return;
659 }
660 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
661 cli.max_turns = 1000;
662 }
663 if cli.fold_budget.is_none() {
664 cli.fold_budget = Some(100_000);
665 }
666}