use crate::constants::{defaults, execution, llm_generation, prompt_budget, tool_limits};
use crate::types::{
ReasoningEffortLevel, ShellPromptProfile, SystemPromptMode, ToolDocumentationMode, UiSurfacePreference,
VerbosityLevel,
};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
const DEFAULT_CHECKPOINTS_ENABLED: bool = true;
const DEFAULT_MAX_SNAPSHOTS: usize = 50;
const DEFAULT_MAX_AGE_DAYS: u64 = 30;
mod approval;
mod circuit_breaker;
mod codex_app_server;
mod harness;
mod memory;
mod onboarding;
mod open_responses;
mod prompt_suggestions;
mod small_model;
mod vibe_coding;
pub use approval::{AsyncApprovalConfig, ConfidenceEscalationConfig, SkepticPanelConfig};
pub use circuit_breaker::CircuitBreakerConfig;
pub use codex_app_server::AgentCodexAppServerConfig;
pub use harness::{
AgentHarnessConfig, ToolResultClearingConfig, TrackerContinuationConfig, VerificationAutoRecoveryConfig,
};
pub use memory::{MemoriesConfig, PersistentMemoryConfig};
pub use onboarding::AgentOnboardingConfig;
pub use open_responses::OpenResponsesConfig;
pub use prompt_suggestions::AgentPromptSuggestionsConfig;
pub use small_model::AgentSmallModelConfig;
pub use vibe_coding::AgentVibeCodingConfig;
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AgentConfig {
#[serde(default = "default_provider")]
pub provider: String,
#[serde(default = "default_api_key_env")]
pub api_key_env: String,
#[serde(default = "default_model")]
pub default_model: String,
#[serde(default = "default_theme")]
pub theme: String,
#[serde(default)]
pub system_prompt_mode: SystemPromptMode,
#[serde(default = "default_max_system_prompt_tokens")]
pub max_system_prompt_tokens: u64,
#[serde(default = "default_system_prompt_budget_warning")]
pub system_prompt_budget_warning: bool,
#[serde(default = "default_trim_system_prompt")]
pub trim_system_prompt: bool,
#[serde(default)]
pub tool_documentation_mode: ToolDocumentationMode,
#[serde(default)]
pub shell_prompt_profile: ShellPromptProfile,
#[serde(default = "default_enable_split_tool_results")]
pub enable_split_tool_results: bool,
#[serde(default = "default_todo_planning_mode")]
pub todo_planning_mode: bool,
#[serde(default)]
pub ui_surface: UiSurfacePreference,
#[serde(default = "default_max_conversation_turns")]
pub max_conversation_turns: usize,
#[serde(default = "default_idle_turn_limit")]
pub idle_turn_limit: usize,
#[serde(default = "default_reasoning_effort")]
pub reasoning_effort: ReasoningEffortLevel,
#[serde(default)]
pub allow_reasoning_effort_downgrade: bool,
#[serde(default = "default_verbosity")]
pub verbosity: VerbosityLevel,
#[serde(default = "default_temperature")]
pub temperature: f32,
#[serde(default = "default_refine_temperature")]
pub refine_temperature: f32,
#[serde(default = "default_enable_self_review")]
pub enable_self_review: bool,
#[serde(default = "default_max_review_passes")]
pub max_review_passes: usize,
#[serde(default = "default_refine_prompts_enabled")]
pub refine_prompts_enabled: bool,
#[serde(default = "default_refine_max_passes")]
pub refine_prompts_max_passes: usize,
#[serde(default)]
pub refine_prompts_model: String,
#[serde(default)]
pub small_model: AgentSmallModelConfig,
#[serde(default)]
pub prompt_suggestions: AgentPromptSuggestionsConfig,
#[serde(default)]
pub onboarding: AgentOnboardingConfig,
#[serde(default = "default_project_doc_max_bytes")]
pub project_doc_max_bytes: usize,
#[serde(default)]
pub project_doc_fallback_filenames: Vec<String>,
#[serde(default = "default_instruction_max_bytes", alias = "rule_doc_max_bytes")]
pub instruction_max_bytes: usize,
#[serde(default, alias = "instruction_paths", alias = "instructions")]
pub instruction_files: Vec<String>,
#[serde(default)]
pub instruction_excludes: Vec<String>,
#[serde(default = "default_instruction_import_max_depth")]
pub instruction_import_max_depth: usize,
#[serde(default)]
pub persistent_memory: PersistentMemoryConfig,
#[serde(default, skip_serializing)]
pub custom_api_keys: BTreeMap<String, String>,
#[serde(default)]
pub credential_storage_mode: crate::auth::AuthCredentialsStoreMode,
#[serde(default)]
pub checkpointing: AgentCheckpointingConfig,
#[serde(default)]
pub vibe_coding: AgentVibeCodingConfig,
#[serde(default = "default_max_task_retries")]
pub max_task_retries: u32,
#[serde(default)]
pub harness: AgentHarnessConfig,
#[serde(default)]
pub codex_app_server: AgentCodexAppServerConfig,
#[serde(default = "default_include_temporal_context")]
pub include_temporal_context: bool,
#[serde(default)]
pub temporal_context_use_utc: bool,
#[serde(default = "default_include_working_directory")]
pub include_working_directory: bool,
#[serde(default)]
pub include_structured_reasoning_tags: Option<bool>,
#[serde(default)]
pub user_instructions: Option<String>,
#[serde(default = "default_require_plan_confirmation")]
pub require_plan_confirmation: bool,
#[serde(default)]
pub circuit_breaker: CircuitBreakerConfig,
#[serde(default)]
pub open_responses: OpenResponsesConfig,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ContinuationPolicy {
Off,
ExecOnly,
#[default]
All,
}
impl ContinuationPolicy {
pub fn as_str(&self) -> &'static str {
match self {
Self::Off => "off",
Self::ExecOnly => "exec_only",
Self::All => "all",
}
}
fn parse(value: &str) -> Option<Self> {
let normalized = value.trim();
if normalized.eq_ignore_ascii_case("off") {
Some(Self::Off)
} else if normalized.eq_ignore_ascii_case("exec_only") || normalized.eq_ignore_ascii_case("exec-only") {
Some(Self::ExecOnly)
} else if normalized.eq_ignore_ascii_case("all") {
Some(Self::All)
} else {
None
}
}
}
impl<'de> Deserialize<'de> for ContinuationPolicy {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = String::deserialize(deserializer)?;
Ok(Self::parse(&raw).unwrap_or_default())
}
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ContextResetMode {
#[default]
Off,
OnStall,
OnCompaction,
}
impl ContextResetMode {
pub fn as_str(&self) -> &'static str {
match self {
Self::Off => "off",
Self::OnStall => "on_stall",
Self::OnCompaction => "on_compaction",
}
}
fn parse(value: &str) -> Option<Self> {
let normalized = value.trim();
if normalized.eq_ignore_ascii_case("off") {
Some(Self::Off)
} else if normalized.eq_ignore_ascii_case("on_stall") || normalized.eq_ignore_ascii_case("on-stall") {
Some(Self::OnStall)
} else if normalized.eq_ignore_ascii_case("on_compaction") || normalized.eq_ignore_ascii_case("on-compaction") {
Some(Self::OnCompaction)
} else {
None
}
}
}
impl<'de> Deserialize<'de> for ContextResetMode {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = String::deserialize(deserializer)?;
Ok(Self::parse(&raw).unwrap_or_default())
}
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum HarnessOrchestrationMode {
#[default]
PlanBuildEvaluate,
Single,
}
impl HarnessOrchestrationMode {
pub fn as_str(&self) -> &'static str {
match self {
Self::Single => "single",
Self::PlanBuildEvaluate => "plan_build_evaluate",
}
}
fn parse(value: &str) -> Option<Self> {
let normalized = value.trim();
if normalized.eq_ignore_ascii_case("single") {
Some(Self::Single)
} else if normalized.eq_ignore_ascii_case("plan_build_evaluate")
|| normalized.eq_ignore_ascii_case("plan-build-evaluate")
|| normalized.eq_ignore_ascii_case("planner_generator_evaluator")
|| normalized.eq_ignore_ascii_case("planner-generator-evaluator")
{
Some(Self::PlanBuildEvaluate)
} else {
None
}
}
}
impl<'de> Deserialize<'de> for HarnessOrchestrationMode {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = String::deserialize(deserializer)?;
Ok(Self::parse(&raw).unwrap_or_default())
}
}
impl Default for AgentConfig {
fn default() -> Self {
Self {
provider: default_provider(),
api_key_env: default_api_key_env(),
default_model: default_model(),
theme: default_theme(),
system_prompt_mode: SystemPromptMode::default(),
max_system_prompt_tokens: default_max_system_prompt_tokens(),
system_prompt_budget_warning: default_system_prompt_budget_warning(),
trim_system_prompt: default_trim_system_prompt(),
tool_documentation_mode: ToolDocumentationMode::default(),
shell_prompt_profile: ShellPromptProfile::default(),
enable_split_tool_results: default_enable_split_tool_results(),
todo_planning_mode: default_todo_planning_mode(),
ui_surface: UiSurfacePreference::default(),
max_conversation_turns: default_max_conversation_turns(),
idle_turn_limit: default_idle_turn_limit(),
reasoning_effort: default_reasoning_effort(),
allow_reasoning_effort_downgrade: false,
verbosity: default_verbosity(),
temperature: default_temperature(),
refine_temperature: default_refine_temperature(),
enable_self_review: default_enable_self_review(),
max_review_passes: default_max_review_passes(),
refine_prompts_enabled: default_refine_prompts_enabled(),
refine_prompts_max_passes: default_refine_max_passes(),
refine_prompts_model: String::new(),
small_model: AgentSmallModelConfig::default(),
prompt_suggestions: AgentPromptSuggestionsConfig::default(),
onboarding: AgentOnboardingConfig::default(),
project_doc_max_bytes: default_project_doc_max_bytes(),
project_doc_fallback_filenames: Vec::new(),
instruction_max_bytes: default_instruction_max_bytes(),
instruction_files: Vec::new(),
instruction_excludes: Vec::new(),
instruction_import_max_depth: default_instruction_import_max_depth(),
persistent_memory: PersistentMemoryConfig::default(),
custom_api_keys: BTreeMap::new(),
credential_storage_mode: crate::auth::AuthCredentialsStoreMode::default(),
checkpointing: AgentCheckpointingConfig::default(),
vibe_coding: AgentVibeCodingConfig::default(),
max_task_retries: default_max_task_retries(),
harness: AgentHarnessConfig::default(),
codex_app_server: AgentCodexAppServerConfig::default(),
include_temporal_context: default_include_temporal_context(),
temporal_context_use_utc: false, include_working_directory: default_include_working_directory(),
include_structured_reasoning_tags: None,
user_instructions: None,
require_plan_confirmation: default_require_plan_confirmation(),
circuit_breaker: CircuitBreakerConfig::default(),
open_responses: OpenResponsesConfig::default(),
}
}
}
impl AgentConfig {
pub fn should_include_structured_reasoning_tags(&self) -> bool {
self.include_structured_reasoning_tags.unwrap_or(false)
}
pub(crate) fn validate_llm_params(&self) -> Result<(), String> {
if !(0.0..=1.0).contains(&self.temperature) {
return Err(format!("temperature must be between 0.0 and 1.0, got {}", self.temperature));
}
if !(0.0..=1.0).contains(&self.refine_temperature) {
return Err(format!("refine_temperature must be between 0.0 and 1.0, got {}", self.refine_temperature));
}
if self.instruction_import_max_depth == 0 {
return Err("instruction_import_max_depth must be greater than 0".to_string());
}
if !(0.0..=1.0).contains(&self.harness.budget_warning_threshold) {
return Err(format!(
"harness.budget_warning_threshold must be between 0.0 and 1.0, got {}",
self.harness.budget_warning_threshold
));
}
self.persistent_memory.validate()?;
self.harness.tool_result_clearing.validate()?;
Ok(())
}
}
#[inline]
fn default_provider() -> String {
defaults::DEFAULT_PROVIDER.into()
}
#[inline]
fn default_api_key_env() -> String {
defaults::DEFAULT_API_KEY_ENV.into()
}
#[inline]
fn default_model() -> String {
defaults::DEFAULT_MODEL.into()
}
#[inline]
fn default_theme() -> String {
defaults::DEFAULT_THEME.into()
}
#[inline]
const fn default_todo_planning_mode() -> bool {
true
}
#[inline]
const fn default_enable_split_tool_results() -> bool {
true }
#[inline]
const fn default_max_conversation_turns() -> usize {
tool_limits::DEFAULT_MAX_CONVERSATION_TURNS
}
#[inline]
const fn default_idle_turn_limit() -> usize {
execution::IDLE_TURN_LIMIT
}
#[inline]
fn default_reasoning_effort() -> ReasoningEffortLevel {
ReasoningEffortLevel::None
}
#[inline]
fn default_verbosity() -> VerbosityLevel {
VerbosityLevel::default()
}
#[inline]
const fn default_temperature() -> f32 {
llm_generation::DEFAULT_TEMPERATURE
}
#[inline]
const fn default_refine_temperature() -> f32 {
llm_generation::DEFAULT_REFINE_TEMPERATURE
}
#[inline]
const fn default_enable_self_review() -> bool {
false
}
#[inline]
const fn default_max_review_passes() -> usize {
1
}
#[inline]
const fn default_refine_prompts_enabled() -> bool {
false
}
#[inline]
const fn default_refine_max_passes() -> usize {
1
}
#[inline]
const fn default_max_system_prompt_tokens() -> u64 {
prompt_budget::DEFAULT_MAX_SYSTEM_PROMPT_TOKENS
}
#[inline]
const fn default_system_prompt_budget_warning() -> bool {
true
}
#[inline]
const fn default_trim_system_prompt() -> bool {
true
}
#[inline]
const fn default_project_doc_max_bytes() -> usize {
prompt_budget::DEFAULT_MAX_BYTES
}
#[inline]
const fn default_instruction_max_bytes() -> usize {
prompt_budget::DEFAULT_MAX_BYTES
}
#[inline]
const fn default_instruction_import_max_depth() -> usize {
5
}
#[inline]
const fn default_max_task_retries() -> u32 {
2 }
#[inline]
const fn default_include_temporal_context() -> bool {
true }
#[inline]
const fn default_include_working_directory() -> bool {
true }
#[inline]
const fn default_require_plan_confirmation() -> bool {
true }
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AgentCheckpointingConfig {
#[serde(default = "default_checkpointing_enabled")]
pub enabled: bool,
#[serde(default)]
pub storage_dir: Option<String>,
#[serde(default = "default_checkpointing_max_snapshots")]
pub max_snapshots: usize,
#[serde(default = "default_checkpointing_max_age_days")]
pub max_age_days: Option<u64>,
}
impl Default for AgentCheckpointingConfig {
fn default() -> Self {
Self {
enabled: default_checkpointing_enabled(),
storage_dir: None,
max_snapshots: default_checkpointing_max_snapshots(),
max_age_days: default_checkpointing_max_age_days(),
}
}
}
#[inline]
const fn default_checkpointing_enabled() -> bool {
DEFAULT_CHECKPOINTS_ENABLED
}
#[inline]
const fn default_checkpointing_max_snapshots() -> usize {
DEFAULT_MAX_SNAPSHOTS
}
#[inline]
const fn default_checkpointing_max_age_days() -> Option<u64> {
Some(DEFAULT_MAX_AGE_DAYS)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_continuation_policy_defaults_and_parses() {
assert_eq!(ContinuationPolicy::default(), ContinuationPolicy::All);
assert_eq!(ContinuationPolicy::parse("off"), Some(ContinuationPolicy::Off));
assert_eq!(ContinuationPolicy::parse("exec-only"), Some(ContinuationPolicy::ExecOnly));
assert_eq!(ContinuationPolicy::parse("all"), Some(ContinuationPolicy::All));
assert_eq!(ContinuationPolicy::parse("invalid"), None);
}
#[test]
fn test_tracker_continuation_defaults_and_deserializes() {
assert!(TrackerContinuationConfig::default().auto_continue_tracker);
assert_eq!(TrackerContinuationConfig::default().cross_turn_turns, 32);
let parsed: AgentHarnessConfig =
toml::from_str("[continuation]\nauto_continue_tracker = false\ncross_turn_turns = 3")
.expect("valid harness config");
assert!(!parsed.continuation.auto_continue_tracker);
assert_eq!(parsed.continuation.cross_turn_turns, 3);
let fallback: AgentHarnessConfig = toml::from_str("").expect("empty harness config");
assert!(fallback.continuation.auto_continue_tracker);
assert_eq!(fallback.continuation.cross_turn_turns, 32);
}
#[test]
fn test_harness_config_continuation_policy_deserializes_with_fallback() {
let parsed: AgentHarnessConfig = toml::from_str("continuation_policy = \"all\"").expect("valid harness config");
assert_eq!(parsed.continuation_policy, ContinuationPolicy::All);
let fallback: AgentHarnessConfig =
toml::from_str("continuation_policy = \"unexpected\"").expect("fallback config");
assert_eq!(fallback.continuation_policy, ContinuationPolicy::All);
}
#[test]
fn test_harness_config_tool_call_budget_defaults_to_120() {
assert_eq!(AgentHarnessConfig::default().max_tool_calls_per_turn, tool_limits::DEFAULT_MAX_TOOL_CALLS_PER_TURN);
let parsed: AgentHarnessConfig = toml::from_str("").expect("default harness config");
assert_eq!(parsed.max_tool_calls_per_turn, tool_limits::DEFAULT_MAX_TOOL_CALLS_PER_TURN);
}
#[test]
fn test_harness_orchestration_mode_defaults_and_parses() {
assert_eq!(HarnessOrchestrationMode::default(), HarnessOrchestrationMode::PlanBuildEvaluate);
assert_eq!(HarnessOrchestrationMode::parse("single"), Some(HarnessOrchestrationMode::Single));
assert_eq!(
HarnessOrchestrationMode::parse("plan_build_evaluate"),
Some(HarnessOrchestrationMode::PlanBuildEvaluate)
);
assert_eq!(
HarnessOrchestrationMode::parse("planner-generator-evaluator"),
Some(HarnessOrchestrationMode::PlanBuildEvaluate)
);
assert_eq!(HarnessOrchestrationMode::parse("unexpected"), None);
}
#[test]
fn test_harness_config_orchestration_deserializes_with_fallback() {
let parsed: AgentHarnessConfig =
toml::from_str("orchestration_mode = \"plan_build_evaluate\"").expect("valid harness config");
assert_eq!(parsed.orchestration_mode, HarnessOrchestrationMode::PlanBuildEvaluate);
assert_eq!(parsed.max_revision_rounds, 2);
let fallback: AgentHarnessConfig =
toml::from_str("orchestration_mode = \"unexpected\"").expect("fallback config");
assert_eq!(fallback.orchestration_mode, HarnessOrchestrationMode::PlanBuildEvaluate);
}
#[test]
fn test_verification_auto_recovery_defaults_to_bounded_auto_execute() {
let config = VerificationAutoRecoveryConfig::default();
assert!(config.auto_execute);
assert_eq!(config.in_turn_attempts, 2);
assert_eq!(config.cross_turn_turns, 2);
assert_eq!(config.default_verifier_override, None);
assert_eq!(config.max_consecutive_failures, 3);
}
#[test]
fn test_verification_auto_recovery_survives_missing_field_for_backward_compatibility() {
let without_table: AgentHarnessConfig = toml::from_str("").expect("default harness config");
assert!(without_table.verification.auto_execute);
assert_eq!(without_table.verification.in_turn_attempts, 2);
let partial: VerificationAutoRecoveryConfig =
toml::from_str("auto_execute = false").expect("minimal verification config parses");
assert!(!partial.auto_execute);
assert_eq!(partial.in_turn_attempts, 2);
assert_eq!(partial.max_consecutive_failures, 3);
let full: VerificationAutoRecoveryConfig = toml::from_str(
"auto_execute = true\nin_turn_attempts = 1\ncross_turn_turns = 0\ndefault_verifier_override = \"cargo nextest run -p mycrate\"\nmax_consecutive_failures = 5",
)
.expect("full verification config parses");
assert_eq!(full.in_turn_attempts, 1);
assert_eq!(full.cross_turn_turns, 0);
assert_eq!(full.default_verifier_override.as_deref(), Some("cargo nextest run -p mycrate"));
assert_eq!(full.max_consecutive_failures, 5);
}
#[test]
fn test_plan_confirmation_config_default() {
let config = AgentConfig::default();
assert!(config.require_plan_confirmation);
}
#[test]
fn test_system_prompt_budget_defaults() {
let config = AgentConfig::default();
assert_eq!(config.max_system_prompt_tokens, prompt_budget::DEFAULT_MAX_SYSTEM_PROMPT_TOKENS);
assert!(config.system_prompt_budget_warning);
assert!(config.trim_system_prompt);
let parsed: AgentConfig = toml::from_str(
r#"
max_system_prompt_tokens = 4000
system_prompt_budget_warning = false
trim_system_prompt = true
"#,
)
.expect("agent config should parse");
assert_eq!(parsed.max_system_prompt_tokens, 4000);
assert!(!parsed.system_prompt_budget_warning);
assert!(parsed.trim_system_prompt);
}
#[test]
fn test_budget_warning_threshold_default_and_validation() {
let config = AgentConfig::default();
assert!((config.harness.budget_warning_threshold - 0.75).abs() < f64::EPSILON);
assert!(config.validate_llm_params().is_ok());
let parsed: AgentHarnessConfig = toml::from_str(
r#"
max_budget_usd = 5.0
budget_warning_threshold = 0.5
"#,
)
.expect("harness config should parse");
assert_eq!(parsed.max_budget_usd, Some(5.0));
assert!((parsed.budget_warning_threshold - 0.5).abs() < f64::EPSILON);
let mut invalid = AgentConfig::default();
invalid.harness.budget_warning_threshold = 1.5;
assert!(invalid.validate_llm_params().is_err());
}
#[test]
fn test_persistent_memory_is_disabled_by_default() {
let config = AgentConfig::default();
assert!(!config.persistent_memory.enabled);
assert!(config.persistent_memory.auto_write);
}
#[test]
fn test_tool_result_clearing_defaults() {
let config = AgentConfig::default();
let clearing = config.harness.tool_result_clearing;
assert!(clearing.enabled);
assert_eq!(clearing.trigger_tokens, 40_000);
assert_eq!(clearing.keep_tool_uses, 2);
assert_eq!(clearing.clear_at_least_tokens, 30_000);
assert!(clearing.clear_tool_inputs);
}
#[test]
fn test_tool_result_clearing_missing_key_defaults_clear_tool_inputs_true() {
let parsed: AgentHarnessConfig = toml::from_str(
r#"
[tool_result_clearing]
enabled = true
trigger_tokens = 40000
keep_tool_uses = 2
clear_at_least_tokens = 30000
"#,
)
.expect("valid harness config");
assert!(parsed.tool_result_clearing.clear_tool_inputs);
}
#[test]
fn test_tool_result_clearing_explicit_false_opts_out_of_input_clearing() {
let parsed: AgentHarnessConfig = toml::from_str(
r#"
[tool_result_clearing]
clear_tool_inputs = false
"#,
)
.expect("valid harness config");
assert!(!parsed.tool_result_clearing.clear_tool_inputs);
}
#[test]
fn test_codex_app_server_experimental_features_default_to_disabled() {
let config = AgentConfig::default();
assert!(!config.codex_app_server.experimental_features);
}
#[test]
fn test_codex_app_server_experimental_features_parse_from_toml() {
let parsed: AgentCodexAppServerConfig = toml::from_str(
r#"
command = "codex"
args = ["app-server"]
startup_timeout_secs = 15
experimental_features = true
"#,
)
.expect("valid codex app-server config");
assert!(parsed.experimental_features);
assert_eq!(parsed.startup_timeout_secs, 15);
}
#[test]
fn test_tool_result_clearing_parses_and_validates() {
let parsed: AgentHarnessConfig = toml::from_str(
r#"
[tool_result_clearing]
enabled = true
trigger_tokens = 123456
keep_tool_uses = 6
clear_at_least_tokens = 4096
clear_tool_inputs = true
"#,
)
.expect("valid harness config");
assert!(parsed.tool_result_clearing.enabled);
assert_eq!(parsed.tool_result_clearing.trigger_tokens, 123_456);
assert_eq!(parsed.tool_result_clearing.keep_tool_uses, 6);
assert_eq!(parsed.tool_result_clearing.clear_at_least_tokens, 4_096);
assert!(parsed.tool_result_clearing.clear_tool_inputs);
assert!(parsed.tool_result_clearing.validate().is_ok());
}
#[test]
fn test_tool_result_clearing_rejects_zero_values() {
let clearing = ToolResultClearingConfig {
trigger_tokens: 0,
..ToolResultClearingConfig::default()
};
assert!(clearing.validate().is_err());
let clearing = ToolResultClearingConfig {
keep_tool_uses: 0,
..ToolResultClearingConfig::default()
};
assert!(clearing.validate().is_err());
let clearing = ToolResultClearingConfig {
clear_at_least_tokens: 0,
..ToolResultClearingConfig::default()
};
assert!(clearing.validate().is_err());
}
#[test]
fn test_structured_reasoning_is_opt_in_for_every_prompt_mode() {
let default_prompt_config = AgentConfig {
system_prompt_mode: SystemPromptMode::Default,
..Default::default()
};
assert!(!default_prompt_config.should_include_structured_reasoning_tags());
let specialized_mode = AgentConfig {
system_prompt_mode: SystemPromptMode::Specialized,
..Default::default()
};
assert!(!specialized_mode.should_include_structured_reasoning_tags());
let minimal_mode = AgentConfig {
system_prompt_mode: SystemPromptMode::Minimal,
..Default::default()
};
assert!(!minimal_mode.should_include_structured_reasoning_tags());
let lightweight_mode = AgentConfig {
system_prompt_mode: SystemPromptMode::Lightweight,
..Default::default()
};
assert!(!lightweight_mode.should_include_structured_reasoning_tags());
}
#[test]
fn test_structured_reasoning_explicit_override() {
let mut config = AgentConfig {
system_prompt_mode: SystemPromptMode::Minimal,
include_structured_reasoning_tags: Some(true),
..AgentConfig::default()
};
assert!(config.should_include_structured_reasoning_tags());
config.include_structured_reasoning_tags = Some(false);
assert!(!config.should_include_structured_reasoning_tags());
}
}