use crate::permission::PermissionMode;
#[derive(Debug, Clone)]
pub struct EngineConfig {
pub provider: Option<String>,
pub model: String,
pub max_tokens: u32,
pub permission_prompt_timeout_secs: u64,
pub tool_cancel_grace: std::time::Duration,
pub max_parallelism: usize,
pub max_api_calls_per_turn: u32,
pub strong_model: Option<String>,
pub permission_mode: PermissionMode,
pub sandbox: std::sync::Arc<crate::interface::exec::SandboxSettings>,
pub disable_skill_shell_execution: bool,
pub project_trust: crate::permission::ProjectTrust,
pub prompt_files: crate::paths::PromptFiles,
pub layout: crate::paths::Layout,
pub subprocess_env: crate::interface::exec::SubprocessEnv,
pub file_limits: FileLimits,
pub system_prompt: SystemPromptSettings,
pub max_agent_depth: u32,
pub verbose_tool_results: bool,
pub path_style: PathStyle,
pub deferred_tools: std::sync::Arc<std::collections::HashSet<String>>,
pub tool_results: ToolResultLimits,
pub model_autonomy: ModelAutonomy,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ModelAutonomy {
pub goal_max_rounds: u32,
pub max_jobs: u32,
pub min_job_interval_minutes: u32,
}
impl Default for ModelAutonomy {
fn default() -> Self {
Self {
goal_max_rounds: crate::context::goal::MAX_ROUNDS_LIMIT,
max_jobs: 20,
min_job_interval_minutes: 1,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolResultLimits {
pub inline_chars: usize,
pub dir: Option<std::path::PathBuf>,
}
impl ToolResultLimits {
pub const DEFAULT_INLINE_CHARS: usize = 30_000;
}
impl Default for ToolResultLimits {
fn default() -> Self {
Self {
inline_chars: Self::DEFAULT_INLINE_CHARS,
dir: None,
}
}
}
#[derive(Debug, Clone)]
pub struct FileLimits {
pub max_file_read_bytes: u64,
pub default_read_lines: usize,
pub max_line_chars: usize,
}
impl Default for FileLimits {
fn default() -> Self {
Self {
max_file_read_bytes: 10 * 1024 * 1024,
default_read_lines: 2000,
max_line_chars: 2000,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct SystemPromptSettings {
pub language: Option<String>,
pub global_cache_scope: bool,
pub mcp_tools_present: bool,
pub mcp_instructions: Vec<McpServerInstruction>,
pub memory_walk_up: bool,
pub output_style: Option<String>,
pub todo_v2_enabled: bool,
pub agent_teams_enabled: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct McpServerInstruction {
pub name: String,
pub instructions: String,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Default,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum PathStyle {
#[default]
Absolute,
Relative,
}
impl PathStyle {
pub fn render(self, path: &std::path::Path, cwd: &std::path::Path) -> String {
if self == PathStyle::Relative {
if let Ok(rel) = path.strip_prefix(cwd) {
return if rel.as_os_str().is_empty() {
".".to_string()
} else {
rel.display().to_string()
};
}
}
path.display().to_string()
}
}
impl EngineConfig {
pub fn defaults_for(model: impl Into<String>) -> Self {
let model = model.into();
Self {
provider: None,
model,
max_tokens: 16384,
permission_prompt_timeout_secs: 300,
tool_cancel_grace: std::time::Duration::from_secs(2),
max_parallelism: 10,
max_api_calls_per_turn: 25,
strong_model: None,
permission_mode: PermissionMode::Default,
sandbox: Default::default(),
disable_skill_shell_execution: false,
project_trust: crate::permission::ProjectTrust::default(),
prompt_files: crate::paths::PromptFiles::unscoped(),
layout: Default::default(),
subprocess_env: Default::default(),
file_limits: FileLimits::default(),
system_prompt: SystemPromptSettings {
memory_walk_up: true,
todo_v2_enabled: true,
agent_teams_enabled: false,
..Default::default()
},
max_agent_depth: 3,
verbose_tool_results: false,
path_style: PathStyle::default(),
deferred_tools: Default::default(),
tool_results: ToolResultLimits::default(),
model_autonomy: ModelAutonomy::default(),
}
}
}
pub fn infer_context_window_tokens(model: &str) -> usize {
let m = model.to_ascii_lowercase();
if m.contains("deepseek") || m.starts_with("ds-v") || m.starts_with("ds_") {
1_000_000
} else if m.contains("codex") {
400_000
} else {
200_000
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn render_is_relative_only_under_the_working_directory() {
use std::path::Path;
let cwd = Path::new("/ws");
let inside = Path::new("/ws/src/a.rs");
assert_eq!(PathStyle::Absolute.render(inside, cwd), "/ws/src/a.rs");
assert_eq!(PathStyle::Relative.render(inside, cwd), "src/a.rs");
assert_eq!(PathStyle::Relative.render(cwd, cwd), ".");
assert_eq!(
PathStyle::Relative.render(Path::new("/other/a.rs"), cwd),
"/other/a.rs"
);
}
}