blyte 0.28.1

The blyte coding-agent harness: headless runs with a sealed verification gate, and a REPL.
Documentation
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
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),
    /// Run one task in its own git worktree (.wt/<id>, branch wip/<id>) and print a JSON summary
    Dispatch(DispatchArgs),
    /// 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 orchestrator 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),
}

#[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(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>,

    /// 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
    #[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>,

    /// 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,
}

#[derive(clap::Args, Debug, PartialEq, Clone)]
pub struct CostArgs {
    /// Session identifier to filter by
    #[arg(long, value_name = "ID")]
    pub session: Option<String>,

    /// 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
    #[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::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,

        /// Which orchestrator to set up: claude (Claude Code), codex (Codex CLI) or all
        #[arg(
            long,
            default_value = "claude",
            value_parser = ["claude", "codex", "all"]
        )]
        harness: String,
    },

    /// Remove the skill and the CLAUDE.md block
    Uninstall {
        /// Remove from repository instead of personal ~/.claude
        #[arg(long)]
        project: bool,

        /// Which orchestrator 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",
    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 interactive blyte as the orchestrator: plan, dispatch implementers with `blyte dispatch`, review and merge
    #[arg(long, conflicts_with = "gate")]
    pub orchestrate: bool,

    /// 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'). 'off' needs the sandbox
    #[arg(
        long,
        default_value = "on",
        value_parser = ["on", "off"]
    )]
    pub network: 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,

    /// Whether this is a research run: periodically remind the model to keep report.md updated
    #[arg(long)]
    pub research: bool,
}

/// Turn and context defaults for `--orchestrate`. A flag the user gave explicitly wins.
pub fn apply_orchestrate_defaults(cli: &mut Cli, matches: &clap::ArgMatches) {
    if !cli.orchestrate {
        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);
    }
}