Skip to content

Commit a40b352

Browse files
committed
fix(cli): validate sandbox mode flag against allowed values
Fixes bounty issue #1420 The -s/--sandbox flag was accepting any string value without validation. Now it uses clap's value_enum to validate against the allowed modes: danger-full-access, read-only, and workspace-write. Invalid values now produce a clear error message showing the possible values.
1 parent 771ba8f commit a40b352

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

cortex-cli/src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! - Shell completions
1111
1212
use anyhow::Result;
13-
use clap::{Args, CommandFactory, Parser, Subcommand};
13+
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum};
1414
use clap_complete::{Shell, generate};
1515
use std::io;
1616
use std::path::PathBuf;
@@ -36,6 +36,24 @@ use cortex_cli::upgrade_cmd::UpgradeCli;
3636
use cortex_cli::{LandlockCommand, SeatbeltCommand, WindowsCommand};
3737
use cortex_common::CliConfigOverrides;
3838

39+
/// Sandbox mode for CLI argument parsing.
40+
///
41+
/// This enum is used by clap for argument validation and help text.
42+
/// It maps directly to the engine's SandboxMode type.
43+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
44+
pub enum CliSandboxMode {
45+
/// Full access, no restrictions (DANGEROUS - use with caution)
46+
#[value(name = "danger-full-access")]
47+
DangerFullAccess,
48+
/// Read-only filesystem access
49+
#[value(name = "read-only")]
50+
ReadOnly,
51+
/// Read access + write to workspace (default)
52+
#[default]
53+
#[value(name = "workspace-write")]
54+
WorkspaceWrite,
55+
}
56+
3957
/// Cortex CLI - AI Coding Agent
4058
///
4159
/// If no subcommand is specified, starts the interactive TUI.
@@ -74,8 +92,8 @@ struct InteractiveArgs {
7492
config_profile: Option<String>,
7593

7694
/// Select the sandbox policy for shell commands
77-
#[arg(long = "sandbox", short = 's')]
78-
sandbox_mode: Option<String>,
95+
#[arg(long = "sandbox", short = 's', value_enum)]
96+
sandbox_mode: Option<CliSandboxMode>,
7997

8098
/// Configure when the model requires human approval
8199
#[arg(long = "ask-for-approval", short = 'a')]

0 commit comments

Comments
 (0)