1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum Command {
/// Detect this repository's checks and write blyte.toml
Init(InitArgs),
/// Serve a local dashboard of running and recent jobs
Dashboard(DashboardArgs),
/// Combine a request's passed runs on a work branch and run the repository's check
Combine(CombineArgs),
/// Run one task in its own git worktree (.wt/<id>, branch wip/<id>) and print a JSON summary
Dispatch(DispatchArgs),
/// Start a direct edit in its own git worktree (.wt/<id>, branch wip/<id>)
#[command(hide = true)]
EditStart(EditStartArgs),
/// Verify and record a direct edit started with `blyte edit-start`
#[command(hide = true)]
EditFinish(EditFinishArgs),
/// Show what a dispatched run did: commits, files, tree state, report, and optionally the diff
Review(ReviewArgs),
/// Remove finished worktrees and merged branches
Clean(CleanArgs),
/// Show what a dispatch is doing
Status {
id: String,
#[arg(long)]
json: bool,
},
/// Wait until dispatched runs finish (all of them, or the first with --any) and print one line per finished run
Wait {
/// Run ids, as given to `blyte dispatch`
#[arg(required = true, num_args = 1..)]
ids: Vec<String>,
/// Return as soon as at least one run has finished
#[arg(long)]
any: bool,
/// Give up after this many seconds (exit 2); stays under the 300 s shell-command limit
#[arg(long, default_value_t = 280)]
timeout: u64,
},
/// Install or print the Claude Code skill for the plan, delegate, review workflow
Skill(SkillArgs),
/// Replace this binary with the latest release (the old one is kept as blyte.prev)
Update {
/// Only show the installed and latest versions
#[arg(long, conflicts_with = "rollback")]
check: bool,
/// Swap back to the previous build (blyte.prev)
#[arg(long)]
rollback: bool,
},
/// Show conversation model and implementer costs
Cost(CostArgs),
/// Print Claude Code's status line with blyte costs
Statusline(StatuslineArgs),
/// List a plan's tasks with their state and the command to dispatch each ready one
Plan(PlanArgs),
/// List the surfaces running on this machine
Surfaces {
#[arg(long)]
json: bool,
/// List the stopped surfaces of the current folder
#[arg(long)]
stopped: bool,
},
/// Open a running surface's page by name
Open {
name: String,
/// Open the surface in an app window (`app`, default) or the default browser (`browser`)
#[arg(long = "open-in", value_name = "app|browser")]
open_in: Option<String>,
},
/// Send a message to a running surface
Tell {
name: String,
message: String,
#[arg(long, default_value = "terminal", value_name = "LABEL", value_parser = parse_from_label)]
from: String,
},
/// Fail when the working tree adds comments since a base commit
#[command(hide = true)]
Comments(CommentsArgs),
/// Print the instructions the conversation model is given
#[command(hide = true)]
Instructions(InstructionsArgs),
/// Restore a folder to its state before an in-place run
Undo(UndoArgs),
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct UndoArgs {
/// Run id to undo
pub id: String,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct InitArgs {
/// Overwrite an existing blyte.toml
#[arg(long)]
pub force: bool,
/// Print the file instead of writing it
#[arg(long)]
pub print: bool,
/// Skip gate verification on HEAD
#[arg(long)]
pub no_verify: bool,
/// Sandbox local command execution: 'on' or 'off' (default 'on')
#[arg(
long,
default_value = "on",
value_parser = ["on", "off"]
)]
pub sandbox: String,
/// Timeout in seconds for each verification step (default 600)
#[arg(long, default_value = "600", value_name = "SECONDS")]
pub step_timeout: u64,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct DashboardArgs {
/// Port to listen on (0 for a free port)
#[arg(long, default_value = "7171", value_name = "N")]
pub port: u16,
/// Directory holding repositories or worktrees (repeatable)
#[arg(long = "root", value_name = "DIR")]
pub roots: Vec<PathBuf>,
/// Directory holding run logs and reports (repeatable)
#[arg(long = "runs-dir", value_name = "DIR")]
pub runs_dirs: Vec<PathBuf>,
/// How far back finished jobs are listed, in hours
#[arg(long, default_value = "24", value_name = "N")]
pub hours: u64,
/// Open the dashboard in the default browser
#[arg(long)]
pub open: bool,
}
#[derive(Debug, PartialEq, Clone)]
pub struct SurfaceArgs {
pub port: u16,
pub no_open: bool,
pub open_in: crate::open_window::OpenIn,
pub days: u64,
pub name: Option<String>,
pub resume: Option<String>,
}
impl Default for SurfaceArgs {
fn default() -> Self {
Self {
port: 0,
no_open: false,
open_in: crate::open_window::OpenIn::App,
days: 14,
name: None,
resume: None,
}
}
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct CombineArgs {
/// Request identifier whose passed runs should be combined
pub request: String,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct EditStartArgs {
/// Identifier for this direct edit (used for worktree and branch wip/<id>)
pub id: String,
/// Short description of the requested change
#[arg(long, value_name = "TEXT")]
pub task: String,
/// The commit the new worktree starts from
#[arg(long, default_value = "HEAD")]
pub base: String,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct EditFinishArgs {
/// Identifier given to `blyte edit-start`
pub id: String,
/// Request identifier this edit belongs to
#[arg(long, value_name = "ID")]
pub request: Option<String>,
/// Surface identifier that started this edit
#[arg(long, value_name = "ID")]
pub surface: Option<String>,
#[arg(long, hide = true, value_name = "NAME")]
pub started_by: Option<String>,
/// Commit message used to commit uncommitted or untracked changes in the worktree
#[arg(long, value_name = "TEXT")]
pub message: Option<String>,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct DispatchArgs {
/// Identifier for this dispatch (used for worktree and branch wip/<id>)
pub id: String,
/// Path to the task description markdown file; optional with --plan and --plan-task, which take the task from the plan
pub task_file: Option<PathBuf>,
/// The check command; several lines are several steps, all of which must pass
#[arg(short, long)]
pub gate: Option<String>,
/// Tag for this dispatch (repeatable)
#[arg(long = "tag", value_name = "TEXT")]
pub tags: Vec<String>,
/// Path to the plan file this dispatch belongs to
#[arg(long, value_name = "PATH")]
pub plan: Option<String>,
/// Plan task this dispatch implements
#[arg(long, value_name = "TEXT")]
pub plan_task: Option<String>,
/// Request identifier this dispatch belongs to
#[arg(long, value_name = "ID")]
pub request: Option<String>,
/// Surface identifier that started this dispatch
#[arg(long, value_name = "ID")]
pub surface: Option<String>,
#[arg(long, hide = true, value_name = "NAME")]
pub started_by: Option<String>,
/// The commit a new worktree starts from
#[arg(long, default_value = "HEAD")]
pub base: String,
/// Run read-only research: scratch repository, report gate, findings in report.md
#[arg(long, conflicts_with = "gate", conflicts_with = "base")]
pub research: bool,
/// Copy the finished research report to this path (only with --research)
#[arg(long = "report-to", requires = "research", value_name = "PATH")]
pub report_to: Option<PathBuf>,
/// Model identifier or provider selection
#[arg(short, long)]
pub model: Option<String>,
/// Wall-clock budget in seconds (default 3600)
#[arg(long)]
pub max_seconds: Option<u64>,
/// Maximum turn budget (default 300)
#[arg(long)]
pub max_turns: Option<u32>,
/// Maximum spend in USD (default 25)
#[arg(long = "max-cost")]
pub max_cost_usd: Option<f64>,
/// Approximate token budget for the verbatim tail before folding
#[arg(long)]
pub fold_budget: Option<usize>,
/// Sandbox local command execution: 'on' or 'off' (default 'on')
#[arg(
long,
default_value = "on",
value_parser = ["on", "off"]
)]
pub sandbox: String,
/// Outbound network mode: 'on' or 'off' (default 'on')
#[arg(
long,
value_parser = ["on", "off"]
)]
pub network: Option<String>,
/// Let sandboxed commands read this path despite credential deny-list (repeatable)
#[arg(long = "allow-read")]
pub allow_read: Vec<PathBuf>,
/// Start even if the task names paths outside the workspace and --allow-read
#[arg(long = "no-path-check")]
pub no_path_check: bool,
/// Research runs: no warning for missing brief sections, and allow a question that names an unverified report
#[arg(long = "no-brief-check")]
pub no_brief_check: bool,
/// Skip the model claim check on report.md for research runs
#[arg(long = "no-claim-check")]
pub no_claim_check: bool,
/// Skip the pre-run gate check on the untouched worktree
#[arg(long = "no-base-check")]
pub no_base_check: bool,
/// Pass this environment variable to commands (repeatable)
#[arg(long = "pass-env")]
pub pass_env: Vec<String>,
}
#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[value(rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum ReviewVerdict {
Accepted,
Fixed,
Redone,
}
impl ReviewVerdict {
pub fn as_str(&self) -> &'static str {
match self {
Self::Accepted => "accepted",
Self::Fixed => "fixed",
Self::Redone => "redone",
}
}
}
impl std::fmt::Display for ReviewVerdict {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct ReviewArgs {
pub id: String,
#[arg(long)]
pub diff: bool,
#[arg(long, value_enum)]
pub verdict: Option<ReviewVerdict>,
#[arg(long, value_name = "TEXT", requires = "verdict")]
pub notes: Option<String>,
/// Ask the implementer model for a first review of the diff against the task (trial)
#[arg(long, conflicts_with = "verdict")]
pub model_review: bool,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct CleanArgs {
/// Show what would be removed without deleting anything
#[arg(long)]
pub dry_run: bool,
/// Worktrees older than this many days are removable without a verdict (default 14)
#[arg(long, default_value = "14", value_name = "DAYS")]
pub older_than: u64,
/// Clean every repository in the registry
#[arg(long)]
pub all: bool,
#[arg(long, hide = true, conflicts_with_all = ["all", "dry_run"])]
pub quiet: bool,
#[arg(long, hide = true, value_name = "ID", conflicts_with_all = ["all", "dry_run"])]
pub skip: Option<String>,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct CostArgs {
/// Session identifier to filter by (an unknown session prints zero totals and exits 0)
#[arg(long, value_name = "ID")]
pub session: Option<String>,
/// Break down totals by session id
#[arg(long)]
pub by_session: bool,
/// Filter runs at or after this Unix timestamp in seconds
#[arg(long, value_name = "UNIX_SECS")]
pub since: Option<u64>,
/// Repository path to filter by
#[arg(long, value_name = "PATH")]
pub repo: Option<PathBuf>,
/// Output totals as JSON
#[arg(long)]
pub json: bool,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct StatuslineArgs {
/// Command to generate the base line before appending blyte costs (5 s timeout; override in ms with BLYTE_STATUSLINE_AFTER_TIMEOUT_MS)
#[arg(long, value_name = "COMMAND")]
pub after: Option<String>,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct PlanArgs {
/// Path to the plan markdown file
pub plan: PathBuf,
/// Output task statuses as JSON
#[arg(long)]
pub json: bool,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct CommentsArgs {
/// Base commit or revision to compare the working tree against
#[arg(long, value_name = "REV")]
pub base: String,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct InstructionsArgs {
/// Print the built-in default process and exit
#[arg(long, conflicts_with_all = ["one_shot", "dispatch_tool"])]
pub default_process: bool,
/// Show the instructions for a one-shot run
#[arg(long)]
pub one_shot: bool,
/// Show the instructions for `--dispatch-cmd` mode
#[arg(long)]
pub dispatch_tool: bool,
/// Show the instructions for sandbox 'on' or 'off'
#[arg(long, value_parser = ["on", "off"])]
pub sandbox: Option<String>,
}
#[derive(clap::Subcommand, Debug, PartialEq, Clone)]
pub enum SkillAction {
/// Install the Claude Code skill
Install {
/// Install to repository instead of personal ~/.claude
#[arg(long)]
project: bool,
/// Overwrite even if existing skill was modified
#[arg(long)]
force: bool,
/// Also tell Claude Code to delegate implementation to blyte by default, in CLAUDE.md
#[arg(long, hide = true)]
default: bool,
/// Install the skill without making blyte the default in CLAUDE.md
#[arg(long)]
no_default: bool,
/// Do not set Claude Code's status line
#[arg(long)]
no_statusline: bool,
/// Do not set Claude Code's auto-compact window
#[arg(long)]
no_autocompact: bool,
/// Which conversation model to set up: claude (Claude Code), codex (Codex CLI) or all
#[arg(
long,
default_value = "claude",
value_parser = ["claude", "codex", "all"]
)]
harness: String,
/// Default implementer model to write to the env file
#[arg(long, value_name = "ID")]
model: Option<String>,
},
/// Remove the skill and the CLAUDE.md block
Uninstall {
/// Remove from repository instead of personal ~/.claude
#[arg(long)]
project: bool,
/// Which conversation model to set up: claude (Claude Code), codex (Codex CLI) or all
#[arg(
long,
default_value = "claude",
value_parser = ["claude", "codex", "all"]
)]
harness: String,
},
/// Print the skill markdown to stdout
Print,
}
#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct SkillArgs {
#[command(subcommand)]
pub action: SkillAction,
}
#[derive(Parser, Debug, PartialEq)]
#[command(
name = "blyte",
version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("BLYTE_BUILD"), ")"),
about = "A lean coding-agent harness with a sealed verification gate\nBare `blyte` starts the live surface for the current repository.",
subcommand_precedence_over_arg = true
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
/// Direct task prompt to run in single-shot / headless mode
#[arg(index = 1)]
pub prompt: Option<String>,
/// Verification gate command (e.g. 'pytest', 'cargo test'). Several steps may be given one per line: every step runs and all failures are reported together.
#[arg(short, long)]
pub gate: Option<String>,
/// Run blyte as the conversation model: plan, dispatch implementers with `blyte dispatch`, review and merge
#[arg(long, conflicts_with = "gate")]
pub converse: bool,
/// Command to run on the host when the conversation model delegates work via the `dispatch` tool
#[arg(long, requires = "converse")]
pub dispatch_cmd: Option<String>,
/// Context strategy: 'conversational' (append-all chat) or 'folded' (append-only chat, oldest half folded into digests past a budget)
#[arg(
long,
default_value = "folded",
value_parser = ["conversational", "folded"]
)]
pub context: String,
/// Model identifier or provider selection
#[arg(short, long)]
pub model: Option<String>,
/// Run inside an isolated container workspace instead of local host
#[arg(long)]
pub container: Option<String>,
/// Maximum turn budget
#[arg(long, default_value = "25")]
pub max_turns: usize,
/// Maximum verification gate attempts before failing
#[arg(long, default_value = "5")]
pub max_gates: usize,
/// Enable automatic rollback to baseline git commit if gate fails (disable with --rollback=false)
#[arg(
long,
default_value_t = true,
action = clap::ArgAction::Set,
num_args = 0..=1,
require_equals = true,
default_missing_value = "true",
value_parser = clap::builder::BoolishValueParser::new()
)]
pub rollback: bool,
/// Working directory inside the container when --container is set
#[arg(long, default_value = "/workspace")]
pub container_workdir: String,
/// Wall-clock budget in seconds; the run stops itself and reports when it is spent
#[arg(long)]
pub max_seconds: Option<u64>,
/// Maximum spend in USD; the run stops before a model call once reached
#[arg(long = "max-cost")]
pub max_cost_usd: Option<f64>,
/// Write a JSON run report to this path when the headless run exits
#[arg(long)]
pub report: Option<PathBuf>,
/// Approximate token budget for the verbatim tail before folding (folded context; default 48000)
#[arg(long)]
pub fold_budget: Option<usize>,
/// Sandbox the commands blyte runs on this machine (macOS Seatbelt, Linux Landlock): 'on' or 'off'
#[arg(
long,
default_value = "on",
value_parser = ["on", "off"]
)]
pub sandbox: String,
/// Let commands blyte runs connect out: 'on' or 'off' (default 'on', or 'off' under --converse). 'off' needs the sandbox
#[arg(
long,
value_parser = ["on", "off"]
)]
pub network: Option<String>,
/// Let sandboxed commands read this path despite the credential deny-list (repeatable)
#[arg(long = "allow-read")]
pub allow_read: Vec<PathBuf>,
/// Pass this environment variable to commands even though it looks like a credential (repeatable)
#[arg(long = "pass-env")]
pub pass_env: Vec<String>,
/// Directory allowed for reading with the read and grep tools (repeatable)
#[arg(long = "read-root", value_name = "DIR")]
pub read_roots: Vec<PathBuf>,
/// Gates in this run do not take a machine-wide slot
#[arg(long)]
pub no_gate_slot: bool,
#[arg(
long = "snapshot-dir",
hide = true,
value_name = "DIR",
requires = "snapshot_manifest",
conflicts_with_all = ["container", "converse"]
)]
pub snapshot_dir: Option<PathBuf>,
#[arg(
long = "snapshot-manifest",
hide = true,
value_name = "FILE",
requires = "snapshot_dir",
conflicts_with_all = ["container", "converse"]
)]
pub snapshot_manifest: Option<PathBuf>,
/// Whether this is a research run: periodically remind the model to keep report.md updated
#[arg(long)]
pub research: bool,
/// Research run: check report.md's claims against their cited lines
#[arg(long = "claim-check")]
pub claim_check: bool,
/// Run the verification gate once before the first model call and stop as blocked if it fails
#[arg(long = "base-check")]
pub base_check: bool,
/// Directory containing an untouched checkout of the base commit for running the base check beside the model's first turns
#[arg(long = "base-check-dir", value_name = "DIR")]
pub base_check_dir: Option<PathBuf>,
#[arg(
long,
help = "Run the surface in the terminal instead of opening the page"
)]
pub terminal: bool,
#[arg(
long,
value_name = "N",
help = "Port to listen on (default: a free port)"
)]
pub port: Option<u16>,
#[arg(long = "no-open", help = "Do not open the live surface in the browser")]
pub no_open: bool,
#[arg(
long = "open-in",
value_name = "app|browser",
help = "Open the live surface in an app window (`app`, default) or the default browser (`browser`)"
)]
pub open_in: Option<String>,
#[arg(
long,
value_name = "N",
value_parser = clap::value_parser!(u64).range(1..=31),
help = "How many days back to include finished runs in the live surface (1 to 31, default 14)"
)]
pub days: Option<u64>,
#[arg(
long,
value_name = "NAME",
help = "Name for this surface (default: the repository directory name)"
)]
pub name: Option<String>,
#[arg(
long,
value_name = "NAME",
conflicts_with = "name",
help = "Restart a stopped surface, by name or id, with its transcript"
)]
pub resume: Option<String>,
}
fn parse_from_label(raw: &str) -> Result<String, String> {
crate::surface_dir::validate_surface_name(raw)?;
Ok(raw.to_string())
}
/// Turn and context defaults for `--converse`. A flag the user gave explicitly wins.
pub fn apply_converse_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
if !cli.converse {
return;
}
if matches.value_source("max_turns") == Some(clap::parser::ValueSource::DefaultValue) {
cli.max_turns = 1000;
}
if cli.fold_budget.is_none() {
cli.fold_budget = Some(100_000);
}
}