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