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, value_name = "UNIX_SECS")]
376 pub since: Option<u64>,
377
378 #[arg(long, value_name = "PATH")]
380 pub repo: Option<PathBuf>,
381
382 #[arg(long)]
384 pub json: bool,
385}
386
387#[derive(clap::Args, Debug, PartialEq, Clone)]
388pub struct StatuslineArgs {
389 #[arg(long, value_name = "COMMAND")]
391 pub after: Option<String>,
392}
393
394#[derive(clap::Args, Debug, PartialEq, Clone)]
395pub struct PlanArgs {
396 pub plan: PathBuf,
398
399 #[arg(long)]
401 pub json: bool,
402}
403
404#[derive(clap::Args, Debug, PartialEq, Clone)]
405pub struct CommentsArgs {
406 #[arg(long, value_name = "REV")]
408 pub base: String,
409}
410
411#[derive(clap::Args, Debug, PartialEq, Clone)]
412pub struct InstructionsArgs {
413 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
415 pub default_process: bool,
416
417 #[arg(long)]
419 pub one_shot: bool,
420
421 #[arg(long)]
423 pub dispatch_tool: bool,
424
425 #[arg(long, value_parser = ["on", "off"])]
427 pub sandbox: Option<String>,
428}
429
430#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
431pub enum SkillAction {
432 Install {
434 #[arg(long)]
436 project: bool,
437
438 #[arg(long)]
440 force: bool,
441
442 #[arg(long, hide = true)]
444 default: bool,
445
446 #[arg(long)]
448 no_default: bool,
449
450 #[arg(long)]
452 no_statusline: bool,
453
454 #[arg(long)]
456 no_autocompact: bool,
457
458 #[arg(
460 long,
461 default_value = "claude",
462 value_parser = ["claude", "codex", "all"]
463 )]
464 harness: String,
465
466 #[arg(long, value_name = "ID")]
468 model: Option<String>,
469 },
470
471 Uninstall {
473 #[arg(long)]
475 project: bool,
476
477 #[arg(
479 long,
480 default_value = "claude",
481 value_parser = ["claude", "codex", "all"]
482 )]
483 harness: String,
484 },
485
486 Print,
488}
489
490#[derive(clap::Args, Debug, PartialEq, Clone)]
491pub struct SkillArgs {
492 #[command(subcommand)]
493 pub action: SkillAction,
494}
495
496#[derive(Parser, Debug, PartialEq)]
497#[command(
498 name = "blyte",
499 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
500 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
501 subcommand_precedence_over_arg = true
502)]
503pub struct Cli {
504 #[command(subcommand)]
505 pub command: Option<Command>,
506
507 #[arg(index = 1)]
509 pub prompt: Option<String>,
510
511 #[arg(short, long)]
513 pub gate: Option<String>,
514
515 #[arg(long, conflicts_with = "gate")]
517 pub orchestrate: bool,
518
519 #[arg(long, requires = "orchestrate")]
521 pub dispatch_cmd: Option<String>,
522
523 #[arg(
525 long,
526 default_value = "folded",
527 value_parser = ["conversational", "folded"]
528 )]
529 pub context: String,
530
531 #[arg(short, long)]
533 pub model: Option<String>,
534
535 #[arg(long)]
537 pub container: Option<String>,
538
539 #[arg(long, default_value = "25")]
541 pub max_turns: usize,
542
543 #[arg(long, default_value = "5")]
545 pub max_gates: usize,
546
547 #[arg(
549 long,
550 default_value_t = true,
551 action = clap::ArgAction::Set,
552 num_args = 0..=1,
553 require_equals = true,
554 default_missing_value = "true",
555 value_parser = clap::builder::BoolishValueParser::new()
556 )]
557 pub rollback: bool,
558
559 #[arg(long, default_value = "/workspace")]
561 pub container_workdir: String,
562
563 #[arg(long)]
565 pub max_seconds: Option<u64>,
566
567 #[arg(long = "max-cost")]
569 pub max_cost_usd: Option<f64>,
570
571 #[arg(long)]
573 pub report: Option<PathBuf>,
574
575 #[arg(long)]
577 pub fold_budget: Option<usize>,
578
579 #[arg(
581 long,
582 default_value = "on",
583 value_parser = ["on", "off"]
584 )]
585 pub sandbox: String,
586
587 #[arg(
589 long,
590 value_parser = ["on", "off"]
591 )]
592 pub network: Option<String>,
593
594 #[arg(long = "allow-read")]
596 pub allow_read: Vec<PathBuf>,
597
598 #[arg(long = "pass-env")]
600 pub pass_env: Vec<String>,
601
602 #[arg(long = "read-root", value_name = "DIR")]
604 pub read_roots: Vec<PathBuf>,
605
606 #[arg(long)]
608 pub no_gate_slot: bool,
609
610 #[arg(long)]
612 pub research: bool,
613
614 #[arg(long = "claim-check")]
616 pub claim_check: bool,
617
618 #[arg(long = "base-check")]
620 pub base_check: bool,
621
622 #[arg(long = "base-check-dir", value_name = "DIR")]
624 pub base_check_dir: Option<PathBuf>,
625
626 #[arg(
627 long,
628 help = "Run the interactive terminal session instead of starting the live surface"
629 )]
630 pub terminal: bool,
631
632 #[arg(
633 long,
634 value_name = "N",
635 help = "Port for the live surface (0 picks a free port)"
636 )]
637 pub port: Option<u16>,
638
639 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
640 pub no_open: bool,
641
642 #[arg(
643 long,
644 value_name = "N",
645 value_parser = clap::value_parser!(u64).range(1..=31),
646 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
647 )]
648 pub days: Option<u64>,
649}
650
651pub fn apply_orchestrate_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
653 if !cli.orchestrate {
654 return;
655 }
656 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
657 cli.max_turns = 1000;
658 }
659 if cli.fold_budget.is_none() {
660 cli.fold_budget = Some(100_000);
661 }
662}