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 Dispatch(DispatchArgs),
16 Review(ReviewArgs),
18 Clean(CleanArgs),
20 Status {
22 id: String,
23 #[arg(long)]
24 json: bool,
25 },
26 Wait {
28 #[arg(required = true, num_args = 1..)]
30 ids: Vec<String>,
31 #[arg(long)]
33 any: bool,
34 #[arg(long, default_value_t = 280)]
36 timeout: u64,
37 },
38 Skill(SkillArgs),
40 Update {
42 #[arg(long, conflicts_with = "rollback")]
44 check: bool,
45 #[arg(long)]
47 rollback: bool,
48 },
49 Cost(CostArgs),
51 Statusline(StatuslineArgs),
53 Plan(PlanArgs),
55 Comments(CommentsArgs),
57 Instructions(InstructionsArgs),
59}
60
61#[derive(clap::Args, Debug, PartialEq, Clone)]
62pub struct InitArgs {
63 #[arg(long)]
65 pub force: bool,
66
67 #[arg(long)]
69 pub print: bool,
70
71 #[arg(long)]
73 pub no_verify: bool,
74
75 #[arg(
77 long,
78 default_value = "on",
79 value_parser = ["on", "off"]
80 )]
81 pub sandbox: String,
82
83 #[arg(long, default_value = "600", value_name = "SECONDS")]
85 pub step_timeout: u64,
86}
87
88#[derive(clap::Args, Debug, PartialEq, Clone)]
89pub struct DashboardArgs {
90 #[arg(long, default_value = "7171", value_name = "N")]
92 pub port: u16,
93
94 #[arg(long = "root", value_name = "DIR")]
96 pub roots: Vec<PathBuf>,
97
98 #[arg(long = "runs-dir", value_name = "DIR")]
100 pub runs_dirs: Vec<PathBuf>,
101
102 #[arg(long, default_value = "24", value_name = "N")]
104 pub hours: u64,
105
106 #[arg(long)]
108 pub open: bool,
109}
110
111#[derive(clap::Args, Debug, PartialEq, Clone)]
112pub struct SurfaceArgs {
113 #[arg(
114 long,
115 default_value_t = 0,
116 value_name = "N",
117 help = "Port to listen on (0 picks a free port)"
118 )]
119 pub port: u16,
120
121 #[arg(long, help = "Do not open the live surface in the browser")]
122 pub no_open: bool,
123
124 #[arg(
125 long,
126 default_value_t = 14,
127 value_name = "N",
128 value_parser = clap::value_parser!(u64).range(1..=31),
129 help = "How many days back to include finished runs (1 to 31)"
130 )]
131 pub days: u64,
132}
133
134impl Default for SurfaceArgs {
135 fn default() -> Self {
136 Self {
137 port: 0,
138 no_open: false,
139 days: 14,
140 }
141 }
142}
143
144#[derive(clap::Args, Debug, PartialEq, Clone)]
145pub struct MockArgs {
146 #[arg(long, default_value = "7272", value_name = "N")]
148 pub port: u16,
149
150 #[arg(
152 long,
153 default_value = "7",
154 value_name = "N",
155 value_parser = clap::value_parser!(u64).range(1..=31)
156 )]
157 pub days: u64,
158
159 #[arg(long = "root", value_name = "DIR")]
161 pub roots: Vec<PathBuf>,
162}
163
164#[derive(clap::Args, Debug, PartialEq, Clone)]
165pub struct DispatchArgs {
166 pub id: String,
168
169 pub task_file: Option<PathBuf>,
171
172 #[arg(short, long)]
174 pub gate: Option<String>,
175
176 #[arg(long = "tag", value_name = "TEXT")]
178 pub tags: Vec<String>,
179
180 #[arg(long, value_name = "PATH")]
182 pub plan: Option<String>,
183
184 #[arg(long, value_name = "TEXT")]
186 pub plan_task: Option<String>,
187
188 #[arg(long, value_name = "ID")]
190 pub request: Option<String>,
191
192 #[arg(long, default_value = "HEAD")]
194 pub base: String,
195
196 #[arg(long, conflicts_with = "gate", conflicts_with = "base")]
198 pub research: bool,
199
200 #[arg(long = "report-to", requires = "research", value_name = "PATH")]
202 pub report_to: Option<PathBuf>,
203
204 #[arg(short, long)]
206 pub model: Option<String>,
207
208 #[arg(long)]
210 pub max_seconds: Option<u64>,
211
212 #[arg(long)]
214 pub max_turns: Option<u32>,
215
216 #[arg(long = "max-cost")]
218 pub max_cost_usd: Option<f64>,
219
220 #[arg(long)]
222 pub fold_budget: Option<usize>,
223
224 #[arg(
226 long,
227 default_value = "on",
228 value_parser = ["on", "off"]
229 )]
230 pub sandbox: String,
231
232 #[arg(
234 long,
235 value_parser = ["on", "off"]
236 )]
237 pub network: Option<String>,
238
239 #[arg(long = "allow-read")]
241 pub allow_read: Vec<PathBuf>,
242
243 #[arg(long = "no-path-check")]
245 pub no_path_check: bool,
246
247 #[arg(long = "no-brief-check")]
249 pub no_brief_check: bool,
250
251 #[arg(long = "no-claim-check")]
253 pub no_claim_check: bool,
254
255 #[arg(long = "no-base-check")]
257 pub no_base_check: bool,
258
259 #[arg(long = "pass-env")]
261 pub pass_env: Vec<String>,
262}
263
264#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
265#[value(rename_all = "lowercase")]
266#[serde(rename_all = "lowercase")]
267pub enum ReviewVerdict {
268 Accepted,
269 Fixed,
270 Redone,
271}
272
273impl ReviewVerdict {
274 pub fn as_str(&self) -> &'static str {
275 match self {
276 Self::Accepted => "accepted",
277 Self::Fixed => "fixed",
278 Self::Redone => "redone",
279 }
280 }
281}
282
283impl std::fmt::Display for ReviewVerdict {
284 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
285 write!(f, "{}", self.as_str())
286 }
287}
288
289#[derive(clap::Args, Debug, PartialEq, Clone)]
290pub struct ReviewArgs {
291 pub id: String,
292
293 #[arg(long)]
294 pub diff: bool,
295
296 #[arg(long, value_enum)]
297 pub verdict: Option<ReviewVerdict>,
298
299 #[arg(long, value_name = "TEXT", requires = "verdict")]
300 pub notes: Option<String>,
301
302 #[arg(long, conflicts_with = "verdict")]
304 pub model_review: bool,
305}
306
307#[derive(clap::Args, Debug, PartialEq, Clone)]
308pub struct CleanArgs {
309 #[arg(long)]
311 pub dry_run: bool,
312
313 #[arg(long, default_value = "14", value_name = "DAYS")]
315 pub older_than: u64,
316
317 #[arg(long)]
319 pub all: bool,
320
321 #[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
322 pub quiet: bool,
323
324 #[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
325 pub skip: Option<String>,
326}
327
328#[derive(clap::Args, Debug, PartialEq, Clone)]
329pub struct CostArgs {
330 #[arg(long, value_name = "ID")]
332 pub session: Option<String>,
333
334 #[arg(long, value_name = "UNIX_SECS")]
336 pub since: Option<u64>,
337
338 #[arg(long, value_name = "PATH")]
340 pub repo: Option<PathBuf>,
341
342 #[arg(long)]
344 pub json: bool,
345}
346
347#[derive(clap::Args, Debug, PartialEq, Clone)]
348pub struct StatuslineArgs {
349 #[arg(long, value_name = "COMMAND")]
351 pub after: Option<String>,
352}
353
354#[derive(clap::Args, Debug, PartialEq, Clone)]
355pub struct PlanArgs {
356 pub plan: PathBuf,
358
359 #[arg(long)]
361 pub json: bool,
362}
363
364#[derive(clap::Args, Debug, PartialEq, Clone)]
365pub struct CommentsArgs {
366 #[arg(long, value_name = "REV")]
368 pub base: String,
369}
370
371#[derive(clap::Args, Debug, PartialEq, Clone)]
372pub struct InstructionsArgs {
373 #[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
375 pub default_process: bool,
376
377 #[arg(long)]
379 pub one_shot: bool,
380
381 #[arg(long)]
383 pub dispatch_tool: bool,
384
385 #[arg(long, value_parser = ["on", "off"])]
387 pub sandbox: Option<String>,
388}
389
390#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
391pub enum SkillAction {
392 Install {
394 #[arg(long)]
396 project: bool,
397
398 #[arg(long)]
400 force: bool,
401
402 #[arg(long, hide = true)]
404 default: bool,
405
406 #[arg(long)]
408 no_default: bool,
409
410 #[arg(long)]
412 no_statusline: bool,
413
414 #[arg(long)]
416 no_autocompact: bool,
417
418 #[arg(
420 long,
421 default_value = "claude",
422 value_parser = ["claude", "codex", "all"]
423 )]
424 harness: String,
425
426 #[arg(long, value_name = "ID")]
428 model: Option<String>,
429 },
430
431 Uninstall {
433 #[arg(long)]
435 project: bool,
436
437 #[arg(
439 long,
440 default_value = "claude",
441 value_parser = ["claude", "codex", "all"]
442 )]
443 harness: String,
444 },
445
446 Print,
448}
449
450#[derive(clap::Args, Debug, PartialEq, Clone)]
451pub struct SkillArgs {
452 #[command(subcommand)]
453 pub action: SkillAction,
454}
455
456#[derive(Parser, Debug, PartialEq)]
457#[command(
458 name = "blyte",
459 version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
460 about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
461 subcommand_precedence_over_arg = true
462)]
463pub struct Cli {
464 #[command(subcommand)]
465 pub command: Option<Command>,
466
467 #[arg(index = 1)]
469 pub prompt: Option<String>,
470
471 #[arg(short, long)]
473 pub gate: Option<String>,
474
475 #[arg(long, conflicts_with = "gate")]
477 pub orchestrate: bool,
478
479 #[arg(long, requires = "orchestrate")]
481 pub dispatch_cmd: Option<String>,
482
483 #[arg(
485 long,
486 default_value = "folded",
487 value_parser = ["conversational", "folded"]
488 )]
489 pub context: String,
490
491 #[arg(short, long)]
493 pub model: Option<String>,
494
495 #[arg(long)]
497 pub container: Option<String>,
498
499 #[arg(long, default_value = "25")]
501 pub max_turns: usize,
502
503 #[arg(long, default_value = "5")]
505 pub max_gates: usize,
506
507 #[arg(
509 long,
510 default_value_t = true,
511 action = clap::ArgAction::Set,
512 num_args = 0..=1,
513 require_equals = true,
514 default_missing_value = "true",
515 value_parser = clap::builder::BoolishValueParser::new()
516 )]
517 pub rollback: bool,
518
519 #[arg(long, default_value = "/workspace")]
521 pub container_workdir: String,
522
523 #[arg(long)]
525 pub max_seconds: Option<u64>,
526
527 #[arg(long = "max-cost")]
529 pub max_cost_usd: Option<f64>,
530
531 #[arg(long)]
533 pub report: Option<PathBuf>,
534
535 #[arg(long)]
537 pub fold_budget: Option<usize>,
538
539 #[arg(
541 long,
542 default_value = "on",
543 value_parser = ["on", "off"]
544 )]
545 pub sandbox: String,
546
547 #[arg(
549 long,
550 value_parser = ["on", "off"]
551 )]
552 pub network: Option<String>,
553
554 #[arg(long = "allow-read")]
556 pub allow_read: Vec<PathBuf>,
557
558 #[arg(long = "pass-env")]
560 pub pass_env: Vec<String>,
561
562 #[arg(long = "read-root", value_name = "DIR")]
564 pub read_roots: Vec<PathBuf>,
565
566 #[arg(long)]
568 pub no_gate_slot: bool,
569
570 #[arg(long)]
572 pub research: bool,
573
574 #[arg(long = "claim-check")]
576 pub claim_check: bool,
577
578 #[arg(long = "base-check")]
580 pub base_check: bool,
581
582 #[arg(
583 long,
584 help = "Run the interactive terminal session instead of starting the live surface"
585 )]
586 pub terminal: bool,
587
588 #[arg(
589 long,
590 value_name = "N",
591 help = "Port for the live surface (0 picks a free port)"
592 )]
593 pub port: Option<u16>,
594
595 #[arg(long = "no-open", help = "Do not open the live surface in the browser")]
596 pub no_open: bool,
597
598 #[arg(
599 long,
600 value_name = "N",
601 value_parser = clap::value_parser!(u64).range(1..=31),
602 help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
603 )]
604 pub days: Option<u64>,
605}
606
607pub fn apply_orchestrate_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
609 if !cli.orchestrate {
610 return;
611 }
612 if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
613 cli.max_turns = 1000;
614 }
615 if cli.fold_budget.is_none() {
616 cli.fold_budget = Some(100_000);
617 }
618}