Skip to main content

blyte_cli/
cli.rs

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