Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
25
akode-rs/utils/cli/src/approval_mode_cli_arg.rs
Normal file
25
akode-rs/utils/cli/src/approval_mode_cli_arg.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
//! Standard type to use with the `--approval-mode` CLI option.
|
||||
|
||||
use clap::ValueEnum;
|
||||
|
||||
use akode_protocol::protocol::AskForApproval;
|
||||
|
||||
#[derive(Clone, Copy, Debug, ValueEnum)]
|
||||
#[value(rename_all = "kebab-case")]
|
||||
pub enum ApprovalModeCliArg {
|
||||
/// The model decides when to ask the user for approval.
|
||||
OnRequest,
|
||||
|
||||
/// Never ask for user approval
|
||||
/// Execution failures are immediately returned to the model.
|
||||
Never,
|
||||
}
|
||||
|
||||
impl From<ApprovalModeCliArg> for AskForApproval {
|
||||
fn from(value: ApprovalModeCliArg) -> Self {
|
||||
match value {
|
||||
ApprovalModeCliArg::OnRequest => AskForApproval::OnRequest,
|
||||
ApprovalModeCliArg::Never => AskForApproval::Never,
|
||||
}
|
||||
}
|
||||
}
|
||||
203
akode-rs/utils/cli/src/config_override.rs
Normal file
203
akode-rs/utils/cli/src/config_override.rs
Normal file
@@ -0,0 +1,203 @@
|
||||
//! Support for `-c key=value` overrides shared across Codex CLI tools.
|
||||
//!
|
||||
//! This module provides a [`CliConfigOverrides`] struct that can be embedded
|
||||
//! into a `clap`-derived CLI struct using `#[clap(flatten)]`. Each occurrence
|
||||
//! of `-c key=value` (or `--config key=value`) will be collected as a raw
|
||||
//! string. Helper methods are provided to convert the raw strings into
|
||||
//! key/value pairs as well as to apply them onto a mutable
|
||||
//! `serde_json::Value` representing the configuration tree.
|
||||
|
||||
use clap::ArgAction;
|
||||
use clap::Parser;
|
||||
use serde::de::Error as SerdeError;
|
||||
use toml::Value;
|
||||
|
||||
/// CLI option that captures arbitrary configuration overrides specified as
|
||||
/// `-c key=value`. It intentionally keeps both halves **unparsed** so that the
|
||||
/// calling code can decide how to interpret the right-hand side.
|
||||
#[derive(Parser, Debug, Default, Clone)]
|
||||
pub struct CliConfigOverrides {
|
||||
/// Override a configuration value that would otherwise be loaded from
|
||||
/// `~/.akode/config.toml`. Use a dotted path (`foo.bar.baz`) to override
|
||||
/// nested values. The `value` portion is parsed as TOML. If it fails to
|
||||
/// parse as TOML, the raw string is used as a literal.
|
||||
///
|
||||
/// Examples:
|
||||
/// - `-c model="o3"`
|
||||
/// - `-c 'sandbox_permissions=["disk-full-read-access"]'`
|
||||
/// - `-c shell_environment_policy.inherit=all`
|
||||
#[arg(
|
||||
short = 'c',
|
||||
long = "config",
|
||||
value_name = "key=value",
|
||||
action = ArgAction::Append,
|
||||
global = true,
|
||||
)]
|
||||
pub raw_overrides: Vec<String>,
|
||||
}
|
||||
|
||||
impl CliConfigOverrides {
|
||||
/// Prepend root-level config flags so they have lower precedence than
|
||||
/// command-specific flags parsed after a subcommand.
|
||||
pub fn prepend_root_overrides(&mut self, root_overrides: Self) {
|
||||
self.raw_overrides
|
||||
.splice(0..0, root_overrides.raw_overrides);
|
||||
}
|
||||
|
||||
/// Parse the raw strings captured from the CLI into a list of `(path,
|
||||
/// value)` tuples where `value` is a `serde_json::Value`.
|
||||
pub fn parse_overrides(&self) -> Result<Vec<(String, Value)>, String> {
|
||||
self.raw_overrides
|
||||
.iter()
|
||||
.map(|s| {
|
||||
// Only split on the *first* '=' so values are free to contain
|
||||
// the character.
|
||||
let mut parts = s.splitn(2, '=');
|
||||
let key = match parts.next() {
|
||||
Some(k) => k.trim(),
|
||||
None => return Err("Override missing key".to_string()),
|
||||
};
|
||||
let value_str = parts
|
||||
.next()
|
||||
.ok_or_else(|| format!("Invalid override (missing '='): {s}"))?
|
||||
.trim();
|
||||
|
||||
if key.is_empty() {
|
||||
return Err(format!("Empty key in override: {s}"));
|
||||
}
|
||||
|
||||
// Attempt to parse as TOML. If that fails, treat it as a raw
|
||||
// string. This allows convenient usage such as
|
||||
// `-c model=o3` without the quotes.
|
||||
let value: Value = match parse_toml_value(value_str) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
// Strip leading/trailing quotes if present
|
||||
let trimmed = value_str.trim().trim_matches(|c| c == '"' || c == '\'');
|
||||
Value::String(trimmed.to_string())
|
||||
}
|
||||
};
|
||||
|
||||
Ok((canonicalize_override_key(key), value))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn canonicalize_override_key(key: &str) -> String {
|
||||
if key == "use_legacy_landlock" {
|
||||
"features.use_legacy_landlock".to_string()
|
||||
} else {
|
||||
key.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_toml_value(raw: &str) -> Result<Value, toml::de::Error> {
|
||||
let wrapped = format!("_x_ = {raw}");
|
||||
let table: toml::Table = toml::from_str(&wrapped)?;
|
||||
table
|
||||
.get("_x_")
|
||||
.cloned()
|
||||
.ok_or_else(|| SerdeError::custom("missing sentinel key"))
|
||||
}
|
||||
|
||||
/// Collects config overrides across command boundaries in argument order.
|
||||
///
|
||||
/// Clap keeps the deepest global argument's values instead of appending across
|
||||
/// scopes. Reparse with local config arguments after validating the typed CLI.
|
||||
pub fn collect_config_overrides(
|
||||
command: clap::Command,
|
||||
args: impl IntoIterator<Item = impl Into<std::ffi::OsString> + Clone>,
|
||||
) -> Result<CliConfigOverrides, clap::Error> {
|
||||
let matches = localize_config_arg(command).try_get_matches_from(args)?;
|
||||
let raw_overrides = std::iter::successors(Some(&matches), |scope| {
|
||||
scope.subcommand().map(|(_, child)| child)
|
||||
})
|
||||
.filter_map(|scope| scope.get_many::<String>("raw_overrides"))
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect();
|
||||
Ok(CliConfigOverrides { raw_overrides })
|
||||
}
|
||||
|
||||
fn localize_config_arg(mut command: clap::Command) -> clap::Command {
|
||||
use clap::CommandFactory;
|
||||
|
||||
if !command
|
||||
.get_arguments()
|
||||
.any(|arg| arg.get_id() == "raw_overrides")
|
||||
{
|
||||
command = command.args(CliConfigOverrides::command().get_arguments().cloned());
|
||||
}
|
||||
command
|
||||
.mut_arg("raw_overrides", |arg| arg.global(false))
|
||||
.mut_subcommands(localize_config_arg)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parses_basic_scalar() {
|
||||
let v = parse_toml_value("42").expect("parse");
|
||||
assert_eq!(v.as_integer(), Some(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_bool() {
|
||||
let true_literal = parse_toml_value("true").expect("parse");
|
||||
assert_eq!(true_literal.as_bool(), Some(true));
|
||||
|
||||
let false_literal = parse_toml_value("false").expect("parse");
|
||||
assert_eq!(false_literal.as_bool(), Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_on_unquoted_string() {
|
||||
assert!(parse_toml_value("hello").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_array() {
|
||||
let v = parse_toml_value("[1, 2, 3]").expect("parse");
|
||||
let arr = v.as_array().expect("array");
|
||||
assert_eq!(arr.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canonicalizes_use_legacy_landlock_alias() {
|
||||
let overrides = CliConfigOverrides {
|
||||
raw_overrides: vec!["use_legacy_landlock=true".to_string()],
|
||||
};
|
||||
let parsed = overrides.parse_overrides().expect("parse_overrides");
|
||||
assert_eq!(parsed[0].0.as_str(), "features.use_legacy_landlock");
|
||||
assert_eq!(parsed[0].1.as_bool(), Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepends_root_overrides() {
|
||||
let mut subcommand_overrides = CliConfigOverrides {
|
||||
raw_overrides: vec![r#"model="gpt-5.2""#.to_string()],
|
||||
};
|
||||
subcommand_overrides.prepend_root_overrides(CliConfigOverrides {
|
||||
raw_overrides: vec![r#"model="gpt-5.1""#.to_string()],
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
subcommand_overrides.raw_overrides,
|
||||
vec![
|
||||
r#"model="gpt-5.1""#.to_string(),
|
||||
r#"model="gpt-5.2""#.to_string(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_inline_table() {
|
||||
let v = parse_toml_value("{a = 1, b = 2}").expect("parse");
|
||||
let tbl = v.as_table().expect("table");
|
||||
assert_eq!(tbl.get("a").unwrap().as_integer(), Some(1));
|
||||
assert_eq!(tbl.get("b").unwrap().as_integer(), Some(2));
|
||||
}
|
||||
}
|
||||
72
akode-rs/utils/cli/src/format_env_display.rs
Normal file
72
akode-rs/utils/cli/src/format_env_display.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn format_env_display<S: AsRef<str>>(
|
||||
env: Option<&HashMap<String, String>>,
|
||||
env_vars: &[S],
|
||||
) -> String {
|
||||
let mut parts: Vec<String> = Vec::new();
|
||||
|
||||
if let Some(map) = env {
|
||||
let mut pairs: Vec<_> = map.iter().collect();
|
||||
pairs.sort_by_key(|(key, _)| *key);
|
||||
parts.extend(pairs.into_iter().map(|(key, _)| format!("{key}=*****")));
|
||||
}
|
||||
|
||||
if !env_vars.is_empty() {
|
||||
parts.extend(env_vars.iter().map(|var| format!("{}=*****", var.as_ref())));
|
||||
}
|
||||
|
||||
if parts.is_empty() {
|
||||
"-".to_string()
|
||||
} else {
|
||||
parts.join(", ")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn returns_dash_when_empty() {
|
||||
let empty_vars: &[String] = &[];
|
||||
assert_eq!(format_env_display(/*env*/ None, empty_vars), "-");
|
||||
|
||||
let empty_map = HashMap::new();
|
||||
assert_eq!(format_env_display(Some(&empty_map), empty_vars), "-");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_sorted_env_pairs() {
|
||||
let mut env = HashMap::new();
|
||||
env.insert("B".to_string(), "two".to_string());
|
||||
env.insert("A".to_string(), "one".to_string());
|
||||
|
||||
assert_eq!(
|
||||
format_env_display(Some(&env), &[] as &[String]),
|
||||
"A=*****, B=*****"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_env_vars_with_dollar_prefix() {
|
||||
let vars = vec!["TOKEN".to_string(), "PATH".to_string()];
|
||||
|
||||
assert_eq!(
|
||||
format_env_display(/*env*/ None, &vars),
|
||||
"TOKEN=*****, PATH=*****"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combines_env_pairs_and_vars() {
|
||||
let mut env = HashMap::new();
|
||||
env.insert("HOME".to_string(), "/tmp".to_string());
|
||||
let vars = vec!["TOKEN".to_string()];
|
||||
|
||||
assert_eq!(
|
||||
format_env_display(Some(&env), &vars),
|
||||
"HOME=*****, TOKEN=*****"
|
||||
);
|
||||
}
|
||||
}
|
||||
16
akode-rs/utils/cli/src/lib.rs
Normal file
16
akode-rs/utils/cli/src/lib.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
mod approval_mode_cli_arg;
|
||||
mod config_override;
|
||||
pub(crate) mod format_env_display;
|
||||
mod resume_command;
|
||||
mod sandbox_mode_cli_arg;
|
||||
mod shared_options;
|
||||
|
||||
pub use approval_mode_cli_arg::ApprovalModeCliArg;
|
||||
pub use akode_protocol::config_types::ProfileV2Name;
|
||||
pub use config_override::CliConfigOverrides;
|
||||
pub use config_override::collect_config_overrides;
|
||||
pub use format_env_display::format_env_display;
|
||||
pub use resume_command::resume_command;
|
||||
pub use resume_command::resume_hint;
|
||||
pub use sandbox_mode_cli_arg::SandboxModeCliArg;
|
||||
pub use shared_options::SharedCliOptions;
|
||||
103
akode-rs/utils/cli/src/resume_command.rs
Normal file
103
akode-rs/utils/cli/src/resume_command.rs
Normal file
@@ -0,0 +1,103 @@
|
||||
//! Shared formatting for user-facing `akode resume` command hints.
|
||||
|
||||
use akode_protocol::ThreadId;
|
||||
use akode_shell_command::parse_command::shlex_join;
|
||||
|
||||
pub fn resume_command(thread_name: Option<&str>, thread_id: Option<ThreadId>) -> Option<String> {
|
||||
let resume_target = thread_name
|
||||
.filter(|name| !name.is_empty())
|
||||
.map(str::to_string)
|
||||
.or_else(|| thread_id.map(|thread_id| thread_id.to_string()));
|
||||
resume_target.map(|target| {
|
||||
let needs_double_dash = target.starts_with('-');
|
||||
let escaped = shlex_join(&[target]);
|
||||
if needs_double_dash {
|
||||
format!("codex resume -- {escaped}")
|
||||
} else {
|
||||
format!("codex resume {escaped}")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resume_hint(thread_name: Option<&str>, thread_id: Option<ThreadId>) -> Option<String> {
|
||||
let thread_id = thread_id?;
|
||||
match thread_name.filter(|name| !name.is_empty()) {
|
||||
Some(thread_name) => Some(format!(
|
||||
"codex resume, then select {thread_name} ({thread_id})"
|
||||
)),
|
||||
None => resume_command(/*thread_name*/ None, Some(thread_id)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn prefers_name_over_id() {
|
||||
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
|
||||
let command = resume_command(Some("my-thread"), Some(thread_id));
|
||||
assert_eq!(command, Some("codex resume my-thread".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formats_thread_id_when_name_is_missing() {
|
||||
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
|
||||
let command = resume_command(/*thread_name*/ None, Some(thread_id));
|
||||
assert_eq!(
|
||||
command,
|
||||
Some("codex resume 123e4567-e89b-12d3-a456-426614174000".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_none_without_a_resume_target() {
|
||||
let command = resume_command(/*thread_name*/ None, /*thread_id*/ None);
|
||||
assert_eq!(command, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quotes_thread_names_when_needed() {
|
||||
let command = resume_command(Some("-starts-with-dash"), /*thread_id*/ None);
|
||||
assert_eq!(
|
||||
command,
|
||||
Some("codex resume -- -starts-with-dash".to_string())
|
||||
);
|
||||
|
||||
let command = resume_command(Some("two words"), /*thread_id*/ None);
|
||||
assert_eq!(command, Some("codex resume 'two words'".to_string()));
|
||||
|
||||
let command = resume_command(Some("quote'case"), /*thread_id*/ None);
|
||||
assert_eq!(command, Some("codex resume \"quote'case\"".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_hint_names_picker_item_with_id() {
|
||||
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
|
||||
let hint = resume_hint(Some("my-thread"), Some(thread_id));
|
||||
assert_eq!(
|
||||
hint,
|
||||
Some(
|
||||
"codex resume, then select my-thread (123e4567-e89b-12d3-a456-426614174000)"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_hint_uses_direct_id_command_without_name() {
|
||||
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
|
||||
let hint = resume_hint(/*thread_name*/ None, Some(thread_id));
|
||||
assert_eq!(
|
||||
hint,
|
||||
Some("codex resume 123e4567-e89b-12d3-a456-426614174000".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_hint_requires_thread_id() {
|
||||
let hint = resume_hint(Some("my-thread"), /*thread_id*/ None);
|
||||
assert_eq!(hint, None);
|
||||
}
|
||||
}
|
||||
47
akode-rs/utils/cli/src/sandbox_mode_cli_arg.rs
Normal file
47
akode-rs/utils/cli/src/sandbox_mode_cli_arg.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
//! Standard type to use with the `--sandbox` (`-s`) CLI option.
|
||||
//!
|
||||
//! This mirrors the variants of [`akode_protocol::protocol::SandboxPolicy`], but
|
||||
//! without any of the associated data so it can be expressed as a simple flag
|
||||
//! on the command-line. Users that need to tweak the advanced options for
|
||||
//! `workspace-write` can continue to do so via `-c` overrides or their
|
||||
//! `config.toml`.
|
||||
|
||||
use clap::ValueEnum;
|
||||
use akode_protocol::config_types::SandboxMode;
|
||||
|
||||
#[derive(Clone, Copy, Debug, ValueEnum)]
|
||||
#[value(rename_all = "kebab-case")]
|
||||
pub enum SandboxModeCliArg {
|
||||
ReadOnly,
|
||||
WorkspaceWrite,
|
||||
DangerFullAccess,
|
||||
}
|
||||
|
||||
impl From<SandboxModeCliArg> for SandboxMode {
|
||||
fn from(value: SandboxModeCliArg) -> Self {
|
||||
match value {
|
||||
SandboxModeCliArg::ReadOnly => SandboxMode::ReadOnly,
|
||||
SandboxModeCliArg::WorkspaceWrite => SandboxMode::WorkspaceWrite,
|
||||
SandboxModeCliArg::DangerFullAccess => SandboxMode::DangerFullAccess,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn maps_cli_args_to_protocol_modes() {
|
||||
assert_eq!(SandboxMode::ReadOnly, SandboxModeCliArg::ReadOnly.into());
|
||||
assert_eq!(
|
||||
SandboxMode::WorkspaceWrite,
|
||||
SandboxModeCliArg::WorkspaceWrite.into()
|
||||
);
|
||||
assert_eq!(
|
||||
SandboxMode::DangerFullAccess,
|
||||
SandboxModeCliArg::DangerFullAccess.into()
|
||||
);
|
||||
}
|
||||
}
|
||||
220
akode-rs/utils/cli/src/shared_options.rs
Normal file
220
akode-rs/utils/cli/src/shared_options.rs
Normal file
@@ -0,0 +1,220 @@
|
||||
//! Shared command-line flags used by both interactive and non-interactive Codex entry points.
|
||||
|
||||
use crate::CliConfigOverrides;
|
||||
use crate::SandboxModeCliArg;
|
||||
use clap::Args;
|
||||
use akode_protocol::config_types::ProfileV2Name;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Args, Clone, Debug, Default)]
|
||||
pub struct SharedCliOptions {
|
||||
/// Optional image(s) to attach to the initial prompt.
|
||||
#[arg(
|
||||
long = "image",
|
||||
short = 'i',
|
||||
value_name = "FILE",
|
||||
value_delimiter = ',',
|
||||
num_args = 1..
|
||||
)]
|
||||
pub images: Vec<PathBuf>,
|
||||
|
||||
/// Model the agent should use.
|
||||
#[arg(long, short = 'm')]
|
||||
pub model: Option<String>,
|
||||
|
||||
/// Use open-source provider.
|
||||
#[arg(long = "oss", default_value_t = false)]
|
||||
pub oss: bool,
|
||||
|
||||
/// Specify which local provider to use (lmstudio or ollama).
|
||||
/// If not specified with --oss, will use config default or show selection.
|
||||
#[arg(long = "local-provider")]
|
||||
pub oss_provider: Option<String>,
|
||||
|
||||
/// Layer $AKODE_HOME/<name>.config.toml on top of the base user config.
|
||||
#[arg(long = "profile", short = 'p')]
|
||||
pub config_profile_v2: Option<ProfileV2Name>,
|
||||
|
||||
/// Select the sandbox policy to use when executing model-generated shell
|
||||
/// commands.
|
||||
#[arg(long = "sandbox", short = 's')]
|
||||
pub sandbox_mode: Option<SandboxModeCliArg>,
|
||||
|
||||
/// Route approval requests through automatic review using the workspace-write sandbox.
|
||||
#[arg(
|
||||
long = "approve-for-me",
|
||||
alias = "not-so-yolo",
|
||||
default_value_t = false,
|
||||
conflicts_with_all = ["sandbox_mode", "dangerously_bypass_approvals_and_sandbox"]
|
||||
)]
|
||||
pub auto_review: bool,
|
||||
|
||||
/// Skip all confirmation prompts and execute commands without sandboxing.
|
||||
/// EXTREMELY DANGEROUS. Intended solely for running in environments that are externally sandboxed.
|
||||
#[arg(
|
||||
long = "dangerously-bypass-approvals-and-sandbox",
|
||||
alias = "yolo",
|
||||
default_value_t = false
|
||||
)]
|
||||
pub dangerously_bypass_approvals_and_sandbox: bool,
|
||||
|
||||
/// Run enabled hooks without requiring persisted hook trust for this invocation.
|
||||
/// DANGEROUS. Intended only for automation that already vets hook sources.
|
||||
#[arg(long = "dangerously-bypass-hook-trust", default_value_t = false)]
|
||||
pub bypass_hook_trust: bool,
|
||||
|
||||
/// Tell the agent to use the specified directory as its working root.
|
||||
#[clap(long = "cd", short = 'C', value_name = "DIR")]
|
||||
pub cwd: Option<PathBuf>,
|
||||
|
||||
/// Run the session in a new managed Git worktree.
|
||||
#[arg(long = "worktree", default_value_t = false)]
|
||||
pub worktree: bool,
|
||||
|
||||
/// Additional directories that should be writable alongside the primary workspace.
|
||||
#[arg(long = "add-dir", value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
|
||||
pub add_dir: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl SharedCliOptions {
|
||||
pub fn take_auto_review_config_overrides(&mut self, overrides: &mut CliConfigOverrides) {
|
||||
if self.auto_review {
|
||||
overrides
|
||||
.raw_overrides
|
||||
.push(r#"approvals_reviewer="auto_review""#.to_string());
|
||||
overrides
|
||||
.raw_overrides
|
||||
.push(r#"approval_policy="on-request""#.to_string());
|
||||
overrides
|
||||
.raw_overrides
|
||||
.push(r#"sandbox_mode="workspace-write""#.to_string());
|
||||
self.auto_review = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inherit_exec_root_options(&mut self, root: &Self) {
|
||||
let self_selected_sandbox_mode = self.sandbox_mode.is_some()
|
||||
|| self.auto_review
|
||||
|| self.dangerously_bypass_approvals_and_sandbox;
|
||||
let Self {
|
||||
images,
|
||||
model,
|
||||
oss,
|
||||
oss_provider,
|
||||
config_profile_v2,
|
||||
sandbox_mode,
|
||||
auto_review,
|
||||
dangerously_bypass_approvals_and_sandbox,
|
||||
bypass_hook_trust,
|
||||
cwd,
|
||||
worktree,
|
||||
add_dir,
|
||||
} = self;
|
||||
let Self {
|
||||
images: root_images,
|
||||
model: root_model,
|
||||
oss: root_oss,
|
||||
oss_provider: root_oss_provider,
|
||||
config_profile_v2: root_config_profile_v2,
|
||||
sandbox_mode: root_sandbox_mode,
|
||||
auto_review: root_auto_review,
|
||||
dangerously_bypass_approvals_and_sandbox: root_dangerously_bypass_approvals_and_sandbox,
|
||||
bypass_hook_trust: root_bypass_hook_trust,
|
||||
cwd: root_cwd,
|
||||
worktree: root_worktree,
|
||||
add_dir: root_add_dir,
|
||||
} = root;
|
||||
|
||||
if model.is_none() {
|
||||
model.clone_from(root_model);
|
||||
}
|
||||
if *root_oss {
|
||||
*oss = true;
|
||||
}
|
||||
if oss_provider.is_none() {
|
||||
oss_provider.clone_from(root_oss_provider);
|
||||
}
|
||||
if config_profile_v2.is_none() {
|
||||
config_profile_v2.clone_from(root_config_profile_v2);
|
||||
}
|
||||
if !self_selected_sandbox_mode {
|
||||
*sandbox_mode = *root_sandbox_mode;
|
||||
*auto_review = *root_auto_review;
|
||||
*dangerously_bypass_approvals_and_sandbox =
|
||||
*root_dangerously_bypass_approvals_and_sandbox;
|
||||
}
|
||||
if !*bypass_hook_trust {
|
||||
*bypass_hook_trust = *root_bypass_hook_trust;
|
||||
}
|
||||
if cwd.is_none() {
|
||||
cwd.clone_from(root_cwd);
|
||||
}
|
||||
*worktree |= *root_worktree;
|
||||
if !root_images.is_empty() {
|
||||
let mut merged_images = root_images.clone();
|
||||
merged_images.append(images);
|
||||
*images = merged_images;
|
||||
}
|
||||
if !root_add_dir.is_empty() {
|
||||
let mut merged_add_dir = root_add_dir.clone();
|
||||
merged_add_dir.append(add_dir);
|
||||
*add_dir = merged_add_dir;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_subcommand_overrides(&mut self, subcommand: Self) {
|
||||
let subcommand_selected_sandbox_mode = subcommand.sandbox_mode.is_some()
|
||||
|| subcommand.auto_review
|
||||
|| subcommand.dangerously_bypass_approvals_and_sandbox;
|
||||
let Self {
|
||||
images,
|
||||
model,
|
||||
oss,
|
||||
oss_provider,
|
||||
config_profile_v2,
|
||||
sandbox_mode,
|
||||
auto_review,
|
||||
dangerously_bypass_approvals_and_sandbox,
|
||||
bypass_hook_trust,
|
||||
cwd,
|
||||
worktree,
|
||||
add_dir,
|
||||
} = subcommand;
|
||||
|
||||
if let Some(model) = model {
|
||||
self.model = Some(model);
|
||||
}
|
||||
if oss {
|
||||
self.oss = true;
|
||||
}
|
||||
if let Some(oss_provider) = oss_provider {
|
||||
self.oss_provider = Some(oss_provider);
|
||||
}
|
||||
if let Some(config_profile_v2) = config_profile_v2 {
|
||||
self.config_profile_v2 = Some(config_profile_v2);
|
||||
}
|
||||
if subcommand_selected_sandbox_mode {
|
||||
self.sandbox_mode = sandbox_mode;
|
||||
self.auto_review = auto_review;
|
||||
self.dangerously_bypass_approvals_and_sandbox =
|
||||
dangerously_bypass_approvals_and_sandbox;
|
||||
}
|
||||
if bypass_hook_trust {
|
||||
self.bypass_hook_trust = true;
|
||||
}
|
||||
if let Some(cwd) = cwd {
|
||||
self.cwd = Some(cwd);
|
||||
}
|
||||
self.worktree |= worktree;
|
||||
if !images.is_empty() {
|
||||
self.images = images;
|
||||
}
|
||||
if !add_dir.is_empty() {
|
||||
self.add_dir.extend(add_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "shared_options_tests.rs"]
|
||||
mod tests;
|
||||
30
akode-rs/utils/cli/src/shared_options_tests.rs
Normal file
30
akode-rs/utils/cli/src/shared_options_tests.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
//! Tests shared command-line option inheritance.
|
||||
|
||||
use super::SharedCliOptions;
|
||||
|
||||
#[test]
|
||||
fn inherits_worktree_from_root_without_clearing_subcommand_choice() {
|
||||
let mut options = SharedCliOptions::default();
|
||||
let root = SharedCliOptions {
|
||||
worktree: true,
|
||||
..Default::default()
|
||||
};
|
||||
options.inherit_exec_root_options(&root);
|
||||
assert!(options.worktree);
|
||||
|
||||
options.inherit_exec_root_options(&SharedCliOptions::default());
|
||||
assert!(options.worktree);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applies_worktree_subcommand_override_without_clearing_root_choice() {
|
||||
let mut options = SharedCliOptions::default();
|
||||
options.apply_subcommand_overrides(SharedCliOptions {
|
||||
worktree: true,
|
||||
..Default::default()
|
||||
});
|
||||
assert!(options.worktree);
|
||||
|
||||
options.apply_subcommand_overrides(SharedCliOptions::default());
|
||||
assert!(options.worktree);
|
||||
}
|
||||
Reference in New Issue
Block a user