Skip to main content

vtcode_config/core/
agent.rs

1use crate::constants::{defaults, execution, llm_generation, prompt_budget};
2use crate::types::{
3    ReasoningEffortLevel, SystemPromptMode, ToolDocumentationMode, UiSurfacePreference,
4    VerbosityLevel,
5};
6use serde::{Deserialize, Serialize};
7use std::collections::BTreeMap;
8
9const DEFAULT_CHECKPOINTS_ENABLED: bool = true;
10const DEFAULT_MAX_SNAPSHOTS: usize = 50;
11const DEFAULT_MAX_AGE_DAYS: u64 = 30;
12
13/// Agent-wide configuration
14#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
15#[derive(Debug, Clone, Deserialize, Serialize)]
16pub struct AgentConfig {
17    /// AI provider for single agent mode (gemini, openai, anthropic, openrouter, zai)
18    #[serde(default = "default_provider")]
19    pub provider: String,
20
21    /// Environment variable that stores the API key for the active provider
22    #[serde(default = "default_api_key_env")]
23    pub api_key_env: String,
24
25    /// Default model to use
26    #[serde(default = "default_model")]
27    pub default_model: String,
28
29    /// UI theme identifier controlling ANSI styling
30    #[serde(default = "default_theme")]
31    pub theme: String,
32
33    /// System prompt mode controlling prompt verbosity and token overhead.
34    /// Options target lean base prompts: minimal (~150-250 tokens), lightweight/default
35    /// (~250-350 tokens), specialized (~350-500 tokens) before dynamic runtime addenda.
36    #[serde(default)]
37    pub system_prompt_mode: SystemPromptMode,
38
39    /// Tool documentation mode controlling token overhead for tool definitions
40    /// Options: minimal (~800 tokens), progressive (~1.2k), full (~3k current)
41    /// Progressive: signatures upfront, detailed docs on-demand (recommended)
42    /// Minimal: signatures only, pi-coding-agent style (power users)
43    /// Full: all documentation upfront (current behavior, default)
44    #[serde(default)]
45    pub tool_documentation_mode: ToolDocumentationMode,
46
47    /// Enable split tool results for massive token savings (Phase 4)
48    /// When enabled, tools return dual-channel output:
49    /// - llm_content: Concise summary sent to LLM (token-optimized, 53-95% reduction)
50    /// - ui_content: Rich output displayed to user (full details preserved)
51    ///   Applies to: unified_search, unified_file, unified_exec
52    ///   Default: true (opt-out for compatibility), recommended for production use
53    #[serde(default = "default_enable_split_tool_results")]
54    pub enable_split_tool_results: bool,
55
56    /// Enable TODO planning helper mode for structured task management
57    #[serde(default = "default_todo_planning_mode")]
58    pub todo_planning_mode: bool,
59
60    /// Preferred rendering surface for the interactive chat UI (auto, alternate, inline)
61    #[serde(default)]
62    pub ui_surface: UiSurfacePreference,
63
64    /// Maximum number of conversation turns before auto-termination
65    #[serde(default = "default_max_conversation_turns")]
66    pub max_conversation_turns: usize,
67
68    /// Maximum consecutive idle turns (no tool calls, no meaningful response) before
69    /// the agent runner treats the session as stalled and aborts the loop.
70    #[serde(default = "default_idle_turn_limit")]
71    pub idle_turn_limit: usize,
72
73    /// Reasoning effort level for models that support it (none, minimal, low, medium, high, xhigh, max)
74    /// Applies to: Claude, GPT-5 family, Gemini, Qwen3, DeepSeek with reasoning capability
75    #[serde(default = "default_reasoning_effort")]
76    pub reasoning_effort: ReasoningEffortLevel,
77
78    /// Verbosity level for output text (low, medium, high)
79    /// Applies to: GPT-5.4-family Responses workflows and other models that support verbosity control
80    #[serde(default = "default_verbosity")]
81    pub verbosity: VerbosityLevel,
82
83    /// Temperature for main LLM responses (0.0-1.0)
84    /// Lower values = more deterministic, higher values = more creative
85    /// Recommended: 0.7 for balanced creativity and consistency
86    /// Range: 0.0 (deterministic) to 1.0 (maximum randomness)
87    #[serde(default = "default_temperature")]
88    pub temperature: f32,
89
90    /// Temperature for prompt refinement (0.0-1.0, default: 0.3)
91    /// Lower values ensure prompt refinement is more deterministic/consistent
92    /// Keep lower than main temperature for stable prompt improvement
93    #[serde(default = "default_refine_temperature")]
94    pub refine_temperature: f32,
95
96    /// Enable an extra self-review pass to refine final responses
97    #[serde(default = "default_enable_self_review")]
98    pub enable_self_review: bool,
99
100    /// Maximum number of self-review passes
101    #[serde(default = "default_max_review_passes")]
102    pub max_review_passes: usize,
103
104    /// Enable prompt refinement pass before sending to LLM
105    #[serde(default = "default_refine_prompts_enabled")]
106    pub refine_prompts_enabled: bool,
107
108    /// Max refinement passes for prompt writing
109    #[serde(default = "default_refine_max_passes")]
110    pub refine_prompts_max_passes: usize,
111
112    /// Optional model override for the refiner (empty = auto pick efficient sibling)
113    #[serde(default)]
114    pub refine_prompts_model: String,
115
116    /// Small/lightweight model configuration for efficient operations
117    /// Used for tasks like large file reads, parsing, git history, conversation summarization
118    /// Typically 70-80% cheaper than main model; ~50% of VT Code's calls use this tier
119    #[serde(default)]
120    pub small_model: AgentSmallModelConfig,
121
122    /// Inline prompt suggestion configuration for the chat composer
123    #[serde(default)]
124    pub prompt_suggestions: AgentPromptSuggestionsConfig,
125
126    /// Session onboarding and welcome message configuration
127    #[serde(default)]
128    pub onboarding: AgentOnboardingConfig,
129
130    /// Maximum bytes of AGENTS.md content to load from project hierarchy
131    #[serde(default = "default_project_doc_max_bytes")]
132    pub project_doc_max_bytes: usize,
133
134    /// Additional filenames to check when AGENTS.md is absent at a directory level.
135    #[serde(default)]
136    pub project_doc_fallback_filenames: Vec<String>,
137
138    /// Maximum bytes of instruction content to load from AGENTS.md hierarchy
139    #[serde(
140        default = "default_instruction_max_bytes",
141        alias = "rule_doc_max_bytes"
142    )]
143    pub instruction_max_bytes: usize,
144
145    /// Additional instruction files or globs to merge into the hierarchy
146    #[serde(default, alias = "instruction_paths", alias = "instructions")]
147    pub instruction_files: Vec<String>,
148
149    /// Instruction files or globs to exclude from AGENTS.md and rules discovery
150    #[serde(default)]
151    pub instruction_excludes: Vec<String>,
152
153    /// Maximum recursive `@path` import depth for instruction and rule files
154    #[serde(default = "default_instruction_import_max_depth")]
155    pub instruction_import_max_depth: usize,
156
157    /// Durable per-repository memory for main sessions
158    #[serde(default)]
159    pub persistent_memory: PersistentMemoryConfig,
160
161    /// Provider-specific API keys captured from interactive configuration flows
162    ///
163    /// Note: Actual API keys are stored securely in the OS keyring.
164    /// This field only tracks which providers have keys stored (for UI/migration purposes).
165    /// The keys themselves are NOT serialized to the config file for security.
166    #[serde(default, skip_serializing)]
167    pub custom_api_keys: BTreeMap<String, String>,
168
169    /// Preferred storage backend for credentials (OAuth tokens, API keys, etc.)
170    ///
171    /// - `keyring`: Use OS-specific secure storage (macOS Keychain, Windows Credential
172    ///   Manager, Linux Secret Service). This is the default as it's the most secure.
173    /// - `file`: Use AES-256-GCM encrypted file with machine-derived key
174    /// - `auto`: Try keyring first, fall back to file if unavailable
175    #[serde(default)]
176    pub credential_storage_mode: crate::auth::AuthCredentialsStoreMode,
177
178    /// Checkpointing configuration for automatic turn snapshots
179    #[serde(default)]
180    pub checkpointing: AgentCheckpointingConfig,
181
182    /// Vibe coding configuration for lazy or vague request support
183    #[serde(default)]
184    pub vibe_coding: AgentVibeCodingConfig,
185
186    /// Maximum number of retries for agent task execution (default: 2)
187    /// When an agent task fails due to retryable errors (timeout, network, 503, etc.),
188    /// it will be retried up to this many times with exponential backoff
189    #[serde(default = "default_max_task_retries")]
190    pub max_task_retries: u32,
191
192    /// Harness configuration for turn-level budgets, telemetry, and execution limits
193    #[serde(default)]
194    pub harness: AgentHarnessConfig,
195
196    /// Experimental Codex app-server sidecar configuration.
197    #[serde(default)]
198    pub codex_app_server: AgentCodexAppServerConfig,
199
200    /// Include current date/time in system prompt for temporal awareness
201    /// Helps LLM understand context for time-sensitive tasks (default: true)
202    #[serde(default = "default_include_temporal_context")]
203    pub include_temporal_context: bool,
204
205    /// Use UTC instead of local time for temporal context in system prompts
206    #[serde(default)]
207    pub temporal_context_use_utc: bool,
208
209    /// Include current working directory in system prompt (default: true)
210    #[serde(default = "default_include_working_directory")]
211    pub include_working_directory: bool,
212
213    /// Controls inclusion of the structured reasoning tag instructions block.
214    ///
215    /// Behavior:
216    /// - `Some(true)`: always include structured reasoning instructions.
217    /// - `Some(false)`: never include structured reasoning instructions.
218    /// - `None` (default): include only for `default` and `specialized` prompt modes.
219    ///
220    /// This keeps lightweight/minimal prompts smaller by default while allowing
221    /// explicit opt-in when users want tag-based reasoning guidance.
222    #[serde(default)]
223    pub include_structured_reasoning_tags: Option<bool>,
224
225    /// Custom instructions provided by the user via configuration to guide agent behavior
226    #[serde(default)]
227    pub user_instructions: Option<String>,
228
229    /// Require user confirmation before executing a plan generated in plan mode
230    /// When true, exiting plan mode shows the implementation blueprint and
231    /// requires explicit user approval before enabling edit tools.
232    #[serde(default = "default_require_plan_confirmation")]
233    pub require_plan_confirmation: bool,
234
235    /// Circuit breaker configuration for resilient tool execution
236    /// Controls when the agent should pause and ask for user guidance due to repeated failures
237    #[serde(default)]
238    pub circuit_breaker: CircuitBreakerConfig,
239
240    /// Open Responses specification compliance configuration
241    /// Enables vendor-neutral LLM API format for interoperable workflows
242    #[serde(default)]
243    pub open_responses: OpenResponsesConfig,
244}
245
246#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
247#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))]
248#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
249#[serde(rename_all = "snake_case")]
250pub enum ContinuationPolicy {
251    Off,
252    ExecOnly,
253    #[default]
254    All,
255}
256
257impl ContinuationPolicy {
258    pub fn as_str(&self) -> &'static str {
259        match self {
260            Self::Off => "off",
261            Self::ExecOnly => "exec_only",
262            Self::All => "all",
263        }
264    }
265
266    pub fn parse(value: &str) -> Option<Self> {
267        let normalized = value.trim();
268        if normalized.eq_ignore_ascii_case("off") {
269            Some(Self::Off)
270        } else if normalized.eq_ignore_ascii_case("exec_only")
271            || normalized.eq_ignore_ascii_case("exec-only")
272        {
273            Some(Self::ExecOnly)
274        } else if normalized.eq_ignore_ascii_case("all") {
275            Some(Self::All)
276        } else {
277            None
278        }
279    }
280}
281
282impl<'de> Deserialize<'de> for ContinuationPolicy {
283    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
284    where
285        D: serde::Deserializer<'de>,
286    {
287        let raw = String::deserialize(deserializer)?;
288        Ok(Self::parse(&raw).unwrap_or_default())
289    }
290}
291
292#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
293#[cfg_attr(feature = "schema", schemars(rename_all = "snake_case"))]
294#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
295#[serde(rename_all = "snake_case")]
296pub enum HarnessOrchestrationMode {
297    #[default]
298    Single,
299    PlanBuildEvaluate,
300}
301
302impl HarnessOrchestrationMode {
303    pub fn as_str(&self) -> &'static str {
304        match self {
305            Self::Single => "single",
306            Self::PlanBuildEvaluate => "plan_build_evaluate",
307        }
308    }
309
310    pub fn parse(value: &str) -> Option<Self> {
311        let normalized = value.trim();
312        if normalized.eq_ignore_ascii_case("single") {
313            Some(Self::Single)
314        } else if normalized.eq_ignore_ascii_case("plan_build_evaluate")
315            || normalized.eq_ignore_ascii_case("plan-build-evaluate")
316            || normalized.eq_ignore_ascii_case("planner_generator_evaluator")
317            || normalized.eq_ignore_ascii_case("planner-generator-evaluator")
318        {
319            Some(Self::PlanBuildEvaluate)
320        } else {
321            None
322        }
323    }
324}
325
326impl<'de> Deserialize<'de> for HarnessOrchestrationMode {
327    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
328    where
329        D: serde::Deserializer<'de>,
330    {
331        let raw = String::deserialize(deserializer)?;
332        Ok(Self::parse(&raw).unwrap_or_default())
333    }
334}
335
336#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
337#[derive(Debug, Clone, Deserialize, Serialize)]
338pub struct AgentHarnessConfig {
339    /// Maximum number of tool calls allowed per turn. Set to `0` to disable the cap.
340    #[serde(default = "default_harness_max_tool_calls_per_turn")]
341    pub max_tool_calls_per_turn: usize,
342    /// Maximum wall clock time (seconds) for tool execution in a turn
343    #[serde(default = "default_harness_max_tool_wall_clock_secs")]
344    pub max_tool_wall_clock_secs: u64,
345    /// Maximum retries for retryable tool errors
346    #[serde(default = "default_harness_max_tool_retries")]
347    pub max_tool_retries: u32,
348    /// Maximum number of tool calls that may execute concurrently within a single parallel batch.
349    /// Set to `0` to disable the cap (unlimited concurrency).  Default: 4.
350    #[serde(default = "default_harness_max_parallel_tool_calls")]
351    pub max_parallel_tool_calls: usize,
352    /// Enable automatic context compaction when token pressure crosses threshold.
353    ///
354    /// Disabled by default. When disabled, no automatic compaction is triggered.
355    #[serde(default = "default_harness_auto_compaction_enabled")]
356    pub auto_compaction_enabled: bool,
357    /// Optional absolute compact threshold (tokens) for Responses server-side compaction.
358    ///
359    /// When unset, VT Code derives a threshold from the provider context window.
360    #[serde(default)]
361    pub auto_compaction_threshold_tokens: Option<u64>,
362    /// Provider-native tool-result clearing policy.
363    #[serde(default)]
364    pub tool_result_clearing: ToolResultClearingConfig,
365    /// Optional maximum estimated API cost in USD before VT Code stops the session.
366    #[serde(default)]
367    pub max_budget_usd: Option<f64>,
368    /// Controls whether harness-managed continuation loops are enabled.
369    #[serde(default)]
370    pub continuation_policy: ContinuationPolicy,
371    /// Optional JSONL event log path for harness events.
372    /// Defaults to `~/.vtcode/sessions/` when unset.
373    #[serde(default)]
374    pub event_log_path: Option<String>,
375    /// Select the exec/full-auto harness orchestration path.
376    #[serde(default)]
377    pub orchestration_mode: HarnessOrchestrationMode,
378    /// Maximum generator revision rounds after evaluator rejection.
379    #[serde(default = "default_harness_max_revision_rounds")]
380    pub max_revision_rounds: usize,
381}
382
383impl Default for AgentHarnessConfig {
384    fn default() -> Self {
385        Self {
386            max_tool_calls_per_turn: default_harness_max_tool_calls_per_turn(),
387            max_tool_wall_clock_secs: default_harness_max_tool_wall_clock_secs(),
388            max_tool_retries: default_harness_max_tool_retries(),
389            max_parallel_tool_calls: default_harness_max_parallel_tool_calls(),
390            auto_compaction_enabled: default_harness_auto_compaction_enabled(),
391            auto_compaction_threshold_tokens: None,
392            tool_result_clearing: ToolResultClearingConfig::default(),
393            max_budget_usd: None,
394            continuation_policy: ContinuationPolicy::default(),
395            event_log_path: None,
396            orchestration_mode: HarnessOrchestrationMode::default(),
397            max_revision_rounds: default_harness_max_revision_rounds(),
398        }
399    }
400}
401
402#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
403#[derive(Debug, Clone, Deserialize, Serialize)]
404pub struct ToolResultClearingConfig {
405    #[serde(default = "default_tool_result_clearing_enabled")]
406    pub enabled: bool,
407    #[serde(default = "default_tool_result_clearing_trigger_tokens")]
408    pub trigger_tokens: u64,
409    #[serde(default = "default_tool_result_clearing_keep_tool_uses")]
410    pub keep_tool_uses: u32,
411    #[serde(default = "default_tool_result_clearing_clear_at_least_tokens")]
412    pub clear_at_least_tokens: u64,
413    #[serde(default)]
414    pub clear_tool_inputs: bool,
415}
416
417impl Default for ToolResultClearingConfig {
418    fn default() -> Self {
419        Self {
420            enabled: default_tool_result_clearing_enabled(),
421            trigger_tokens: default_tool_result_clearing_trigger_tokens(),
422            keep_tool_uses: default_tool_result_clearing_keep_tool_uses(),
423            clear_at_least_tokens: default_tool_result_clearing_clear_at_least_tokens(),
424            clear_tool_inputs: false,
425        }
426    }
427}
428
429impl ToolResultClearingConfig {
430    pub fn validate(&self) -> Result<(), String> {
431        if self.trigger_tokens == 0 {
432            return Err("tool_result_clearing.trigger_tokens must be greater than 0".to_string());
433        }
434        if self.keep_tool_uses == 0 {
435            return Err("tool_result_clearing.keep_tool_uses must be greater than 0".to_string());
436        }
437        if self.clear_at_least_tokens == 0 {
438            return Err(
439                "tool_result_clearing.clear_at_least_tokens must be greater than 0".to_string(),
440            );
441        }
442        Ok(())
443    }
444}
445
446#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
447#[derive(Debug, Clone, Deserialize, Serialize)]
448pub struct AgentCodexAppServerConfig {
449    /// Executable used to launch the official Codex app-server sidecar.
450    #[serde(default = "default_codex_app_server_command")]
451    pub command: String,
452    /// Arguments passed before VT Code appends `--listen stdio://`.
453    #[serde(default = "default_codex_app_server_args")]
454    pub args: Vec<String>,
455    /// Maximum startup handshake time when launching the sidecar.
456    #[serde(default = "default_codex_app_server_startup_timeout_secs")]
457    pub startup_timeout_secs: u64,
458    /// Enable experimental Codex app-server features such as collaboration modes
459    /// and native review routing.
460    #[serde(default = "default_codex_app_server_experimental_features")]
461    pub experimental_features: bool,
462}
463
464impl Default for AgentCodexAppServerConfig {
465    fn default() -> Self {
466        Self {
467            command: default_codex_app_server_command(),
468            args: default_codex_app_server_args(),
469            startup_timeout_secs: default_codex_app_server_startup_timeout_secs(),
470            experimental_features: default_codex_app_server_experimental_features(),
471        }
472    }
473}
474
475#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
476#[derive(Debug, Clone, Deserialize, Serialize)]
477pub struct CircuitBreakerConfig {
478    /// Enable circuit breaker functionality
479    #[serde(default = "default_circuit_breaker_enabled")]
480    pub enabled: bool,
481
482    /// Number of consecutive failures before opening circuit
483    #[serde(default = "default_failure_threshold")]
484    pub failure_threshold: u32,
485
486    /// Pause and ask user when circuit opens (vs auto-backoff)
487    #[serde(default = "default_pause_on_open")]
488    pub pause_on_open: bool,
489
490    /// Number of open circuits before triggering pause
491    #[serde(default = "default_max_open_circuits")]
492    pub max_open_circuits: usize,
493
494    /// Cooldown period between recovery prompts (seconds)
495    #[serde(default = "default_recovery_cooldown")]
496    pub recovery_cooldown: u64,
497}
498
499impl Default for CircuitBreakerConfig {
500    fn default() -> Self {
501        Self {
502            enabled: default_circuit_breaker_enabled(),
503            failure_threshold: default_failure_threshold(),
504            pause_on_open: default_pause_on_open(),
505            max_open_circuits: default_max_open_circuits(),
506            recovery_cooldown: default_recovery_cooldown(),
507        }
508    }
509}
510
511/// Open Responses specification compliance configuration
512///
513/// Enables vendor-neutral LLM API format per the Open Responses specification
514/// (<https://www.openresponses.org/>). When enabled, VT Code emits semantic
515/// streaming events and uses standardized response/item structures.
516#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
517#[derive(Debug, Clone, Deserialize, Serialize)]
518pub struct OpenResponsesConfig {
519    /// Enable Open Responses specification compliance layer
520    /// When true, VT Code emits semantic streaming events alongside internal events
521    /// Default: false (opt-in feature)
522    #[serde(default)]
523    pub enabled: bool,
524
525    /// Emit Open Responses events to the event sink
526    /// When true, streaming events follow Open Responses format
527    /// (response.created, response.output_item.added, response.output_text.delta, etc.)
528    #[serde(default = "default_open_responses_emit_events")]
529    pub emit_events: bool,
530
531    /// Include VT Code extension items (vtcode:file_change, vtcode:web_search, etc.)
532    /// When false, extension items are omitted from the Open Responses output
533    #[serde(default = "default_open_responses_include_extensions")]
534    pub include_extensions: bool,
535
536    /// Map internal tool calls to Open Responses function_call items
537    /// When true, command executions and MCP tool calls are represented as function_call items
538    #[serde(default = "default_open_responses_map_tool_calls")]
539    pub map_tool_calls: bool,
540
541    /// Include reasoning items in Open Responses output
542    /// When true, model reasoning/thinking is exposed as reasoning items
543    #[serde(default = "default_open_responses_include_reasoning")]
544    pub include_reasoning: bool,
545}
546
547impl Default for OpenResponsesConfig {
548    fn default() -> Self {
549        Self {
550            enabled: false, // Opt-in by default
551            emit_events: default_open_responses_emit_events(),
552            include_extensions: default_open_responses_include_extensions(),
553            map_tool_calls: default_open_responses_map_tool_calls(),
554            include_reasoning: default_open_responses_include_reasoning(),
555        }
556    }
557}
558
559#[inline]
560const fn default_open_responses_emit_events() -> bool {
561    true // When enabled, emit events by default
562}
563
564#[inline]
565const fn default_open_responses_include_extensions() -> bool {
566    true // Include VT Code-specific extensions by default
567}
568
569#[inline]
570const fn default_open_responses_map_tool_calls() -> bool {
571    true // Map tool calls to function_call items by default
572}
573
574#[inline]
575const fn default_open_responses_include_reasoning() -> bool {
576    true // Include reasoning items by default
577}
578
579#[inline]
580fn default_codex_app_server_command() -> String {
581    "codex".to_string()
582}
583
584#[inline]
585fn default_codex_app_server_args() -> Vec<String> {
586    vec!["app-server".to_string()]
587}
588
589#[inline]
590const fn default_codex_app_server_startup_timeout_secs() -> u64 {
591    10
592}
593
594#[inline]
595const fn default_codex_app_server_experimental_features() -> bool {
596    false
597}
598
599impl Default for AgentConfig {
600    fn default() -> Self {
601        Self {
602            provider: default_provider(),
603            api_key_env: default_api_key_env(),
604            default_model: default_model(),
605            theme: default_theme(),
606            system_prompt_mode: SystemPromptMode::default(),
607            tool_documentation_mode: ToolDocumentationMode::default(),
608            enable_split_tool_results: default_enable_split_tool_results(),
609            todo_planning_mode: default_todo_planning_mode(),
610            ui_surface: UiSurfacePreference::default(),
611            max_conversation_turns: default_max_conversation_turns(),
612            idle_turn_limit: default_idle_turn_limit(),
613            reasoning_effort: default_reasoning_effort(),
614            verbosity: default_verbosity(),
615            temperature: default_temperature(),
616            refine_temperature: default_refine_temperature(),
617            enable_self_review: default_enable_self_review(),
618            max_review_passes: default_max_review_passes(),
619            refine_prompts_enabled: default_refine_prompts_enabled(),
620            refine_prompts_max_passes: default_refine_max_passes(),
621            refine_prompts_model: String::new(),
622            small_model: AgentSmallModelConfig::default(),
623            prompt_suggestions: AgentPromptSuggestionsConfig::default(),
624            onboarding: AgentOnboardingConfig::default(),
625            project_doc_max_bytes: default_project_doc_max_bytes(),
626            project_doc_fallback_filenames: Vec::new(),
627            instruction_max_bytes: default_instruction_max_bytes(),
628            instruction_files: Vec::new(),
629            instruction_excludes: Vec::new(),
630            instruction_import_max_depth: default_instruction_import_max_depth(),
631            persistent_memory: PersistentMemoryConfig::default(),
632            custom_api_keys: BTreeMap::new(),
633            credential_storage_mode: crate::auth::AuthCredentialsStoreMode::default(),
634            checkpointing: AgentCheckpointingConfig::default(),
635            vibe_coding: AgentVibeCodingConfig::default(),
636            max_task_retries: default_max_task_retries(),
637            harness: AgentHarnessConfig::default(),
638            codex_app_server: AgentCodexAppServerConfig::default(),
639            include_temporal_context: default_include_temporal_context(),
640            temporal_context_use_utc: false, // Default to local time
641            include_working_directory: default_include_working_directory(),
642            include_structured_reasoning_tags: None,
643            user_instructions: None,
644            require_plan_confirmation: default_require_plan_confirmation(),
645            circuit_breaker: CircuitBreakerConfig::default(),
646            open_responses: OpenResponsesConfig::default(),
647        }
648    }
649}
650
651impl AgentConfig {
652    /// Determine whether structured reasoning tag instructions should be included.
653    pub fn should_include_structured_reasoning_tags(&self) -> bool {
654        self.include_structured_reasoning_tags.unwrap_or(matches!(
655            self.system_prompt_mode,
656            SystemPromptMode::Specialized
657        ))
658    }
659
660    /// Validate LLM generation parameters
661    pub fn validate_llm_params(&self) -> Result<(), String> {
662        // Validate temperature range
663        if !(0.0..=1.0).contains(&self.temperature) {
664            return Err(format!(
665                "temperature must be between 0.0 and 1.0, got {}",
666                self.temperature
667            ));
668        }
669
670        if !(0.0..=1.0).contains(&self.refine_temperature) {
671            return Err(format!(
672                "refine_temperature must be between 0.0 and 1.0, got {}",
673                self.refine_temperature
674            ));
675        }
676
677        if self.instruction_import_max_depth == 0 {
678            return Err("instruction_import_max_depth must be greater than 0".to_string());
679        }
680
681        self.persistent_memory.validate()?;
682        self.harness.tool_result_clearing.validate()?;
683
684        Ok(())
685    }
686}
687
688// Optimized: Use inline defaults with constants to reduce function call overhead
689#[inline]
690fn default_provider() -> String {
691    defaults::DEFAULT_PROVIDER.into()
692}
693
694#[inline]
695fn default_api_key_env() -> String {
696    defaults::DEFAULT_API_KEY_ENV.into()
697}
698
699#[inline]
700fn default_model() -> String {
701    defaults::DEFAULT_MODEL.into()
702}
703
704#[inline]
705fn default_theme() -> String {
706    defaults::DEFAULT_THEME.into()
707}
708
709#[inline]
710const fn default_todo_planning_mode() -> bool {
711    true
712}
713
714#[inline]
715const fn default_enable_split_tool_results() -> bool {
716    true // Default: enabled for production use (84% token savings)
717}
718
719#[inline]
720const fn default_max_conversation_turns() -> usize {
721    defaults::DEFAULT_MAX_CONVERSATION_TURNS
722}
723
724#[inline]
725const fn default_idle_turn_limit() -> usize {
726    execution::IDLE_TURN_LIMIT
727}
728
729#[inline]
730fn default_reasoning_effort() -> ReasoningEffortLevel {
731    ReasoningEffortLevel::None
732}
733
734#[inline]
735fn default_verbosity() -> VerbosityLevel {
736    VerbosityLevel::default()
737}
738
739#[inline]
740const fn default_temperature() -> f32 {
741    llm_generation::DEFAULT_TEMPERATURE
742}
743
744#[inline]
745const fn default_refine_temperature() -> f32 {
746    llm_generation::DEFAULT_REFINE_TEMPERATURE
747}
748
749#[inline]
750const fn default_enable_self_review() -> bool {
751    false
752}
753
754#[inline]
755const fn default_max_review_passes() -> usize {
756    1
757}
758
759#[inline]
760const fn default_refine_prompts_enabled() -> bool {
761    false
762}
763
764#[inline]
765const fn default_refine_max_passes() -> usize {
766    1
767}
768
769#[inline]
770const fn default_project_doc_max_bytes() -> usize {
771    prompt_budget::DEFAULT_MAX_BYTES
772}
773
774#[inline]
775const fn default_instruction_max_bytes() -> usize {
776    prompt_budget::DEFAULT_MAX_BYTES
777}
778
779#[inline]
780const fn default_instruction_import_max_depth() -> usize {
781    5
782}
783
784#[inline]
785const fn default_max_task_retries() -> u32 {
786    2 // Retry twice on transient failures
787}
788
789#[inline]
790const fn default_harness_max_tool_calls_per_turn() -> usize {
791    defaults::DEFAULT_MAX_TOOL_CALLS_PER_TURN
792}
793
794#[inline]
795const fn default_harness_max_tool_wall_clock_secs() -> u64 {
796    defaults::DEFAULT_MAX_TOOL_WALL_CLOCK_SECS
797}
798
799#[inline]
800const fn default_harness_max_tool_retries() -> u32 {
801    defaults::DEFAULT_MAX_TOOL_RETRIES
802}
803
804#[inline]
805const fn default_harness_max_parallel_tool_calls() -> usize {
806    4 // Cap parallel fan-out at 4; set to 0 in vtcode.toml to remove the limit.
807}
808
809#[inline]
810const fn default_harness_auto_compaction_enabled() -> bool {
811    false
812}
813
814#[inline]
815const fn default_tool_result_clearing_enabled() -> bool {
816    false
817}
818
819#[inline]
820const fn default_tool_result_clearing_trigger_tokens() -> u64 {
821    100_000
822}
823
824#[inline]
825const fn default_tool_result_clearing_keep_tool_uses() -> u32 {
826    3
827}
828
829#[inline]
830const fn default_tool_result_clearing_clear_at_least_tokens() -> u64 {
831    30_000
832}
833
834#[inline]
835const fn default_harness_max_revision_rounds() -> usize {
836    2
837}
838
839#[inline]
840const fn default_include_temporal_context() -> bool {
841    true // Enable by default - minimal overhead (~20 tokens)
842}
843
844#[inline]
845const fn default_include_working_directory() -> bool {
846    true // Enable by default - minimal overhead (~10 tokens)
847}
848
849#[inline]
850const fn default_require_plan_confirmation() -> bool {
851    true // Default: require confirmation (HITL pattern)
852}
853
854#[inline]
855const fn default_circuit_breaker_enabled() -> bool {
856    true // Default: enabled for resilient execution
857}
858
859#[inline]
860const fn default_failure_threshold() -> u32 {
861    7 // Open circuit after 7 consecutive failures
862}
863
864#[inline]
865const fn default_pause_on_open() -> bool {
866    true // Default: ask user for guidance on circuit breaker
867}
868
869#[inline]
870const fn default_max_open_circuits() -> usize {
871    3 // Pause when 3+ tools have open circuits
872}
873
874#[inline]
875const fn default_recovery_cooldown() -> u64 {
876    60 // Cooldown between recovery prompts (seconds)
877}
878
879#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
880#[derive(Debug, Clone, Deserialize, Serialize)]
881pub struct AgentCheckpointingConfig {
882    /// Enable automatic checkpoints after each successful turn
883    #[serde(default = "default_checkpointing_enabled")]
884    pub enabled: bool,
885
886    /// Optional custom directory for storing checkpoints (relative to workspace or absolute)
887    #[serde(default)]
888    pub storage_dir: Option<String>,
889
890    /// Maximum number of checkpoints to retain on disk
891    #[serde(default = "default_checkpointing_max_snapshots")]
892    pub max_snapshots: usize,
893
894    /// Maximum age in days before checkpoints are removed automatically (None disables)
895    #[serde(default = "default_checkpointing_max_age_days")]
896    pub max_age_days: Option<u64>,
897}
898
899impl Default for AgentCheckpointingConfig {
900    fn default() -> Self {
901        Self {
902            enabled: default_checkpointing_enabled(),
903            storage_dir: None,
904            max_snapshots: default_checkpointing_max_snapshots(),
905            max_age_days: default_checkpointing_max_age_days(),
906        }
907    }
908}
909
910#[inline]
911const fn default_checkpointing_enabled() -> bool {
912    DEFAULT_CHECKPOINTS_ENABLED
913}
914
915#[inline]
916const fn default_checkpointing_max_snapshots() -> usize {
917    DEFAULT_MAX_SNAPSHOTS
918}
919
920#[inline]
921const fn default_checkpointing_max_age_days() -> Option<u64> {
922    Some(DEFAULT_MAX_AGE_DAYS)
923}
924
925/// Codex-compatible memories configuration.
926///
927/// Controls whether VT Code extracts durable context from completed threads
928/// and injects it into future sessions. Mirrors the Codex `[memories]` table.
929#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
930#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
931pub struct MemoriesConfig {
932    /// Controls whether newly completed threads can be stored as
933    /// memory-generation inputs.
934    #[serde(default = "default_memories_generate")]
935    pub generate_memories: bool,
936
937    /// Controls whether VT Code injects existing memories into future sessions.
938    #[serde(default = "default_memories_use")]
939    pub use_memories: bool,
940
941    /// Overrides the model used for per-thread memory extraction.
942    #[serde(default)]
943    pub extract_model: Option<String>,
944
945    /// Overrides the model used for global memory consolidation.
946    #[serde(default)]
947    pub consolidation_model: Option<String>,
948}
949
950impl Default for MemoriesConfig {
951    fn default() -> Self {
952        Self {
953            generate_memories: default_memories_generate(),
954            use_memories: default_memories_use(),
955            extract_model: None,
956            consolidation_model: None,
957        }
958    }
959}
960
961#[inline]
962const fn default_memories_generate() -> bool {
963    true
964}
965
966#[inline]
967const fn default_memories_use() -> bool {
968    true
969}
970
971#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
972#[derive(Debug, Clone, Deserialize, Serialize)]
973pub struct PersistentMemoryConfig {
974    /// Toggle main-session persistent memory for this repository
975    #[serde(default = "default_persistent_memory_enabled")]
976    pub enabled: bool,
977
978    /// Write durable memory after completed turns and session finalization
979    #[serde(default = "default_persistent_memory_auto_write")]
980    pub auto_write: bool,
981
982    /// Optional user-local directory override for persistent memory storage
983    #[serde(default)]
984    pub directory_override: Option<String>,
985
986    /// Startup line budget scanned from memory_summary.md before VT Code renders a compact startup summary
987    #[serde(default = "default_persistent_memory_startup_line_limit")]
988    pub startup_line_limit: usize,
989
990    /// Startup byte budget scanned from memory_summary.md before VT Code renders a compact startup summary
991    #[serde(default = "default_persistent_memory_startup_byte_limit")]
992    pub startup_byte_limit: usize,
993
994    /// Codex-compatible memories sub-configuration
995    #[serde(default)]
996    pub memories: MemoriesConfig,
997}
998
999impl Default for PersistentMemoryConfig {
1000    fn default() -> Self {
1001        Self {
1002            enabled: default_persistent_memory_enabled(),
1003            auto_write: default_persistent_memory_auto_write(),
1004            directory_override: None,
1005            startup_line_limit: default_persistent_memory_startup_line_limit(),
1006            startup_byte_limit: default_persistent_memory_startup_byte_limit(),
1007            memories: MemoriesConfig::default(),
1008        }
1009    }
1010}
1011
1012impl PersistentMemoryConfig {
1013    pub fn validate(&self) -> Result<(), String> {
1014        if self.startup_line_limit == 0 {
1015            return Err("persistent_memory.startup_line_limit must be greater than 0".to_string());
1016        }
1017
1018        if self.startup_byte_limit == 0 {
1019            return Err("persistent_memory.startup_byte_limit must be greater than 0".to_string());
1020        }
1021
1022        Ok(())
1023    }
1024}
1025
1026#[inline]
1027const fn default_persistent_memory_enabled() -> bool {
1028    false
1029}
1030
1031#[inline]
1032const fn default_persistent_memory_auto_write() -> bool {
1033    true
1034}
1035
1036#[inline]
1037const fn default_persistent_memory_startup_line_limit() -> usize {
1038    200
1039}
1040
1041#[inline]
1042const fn default_persistent_memory_startup_byte_limit() -> usize {
1043    25 * 1024
1044}
1045
1046#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1047#[derive(Debug, Clone, Deserialize, Serialize)]
1048pub struct AgentOnboardingConfig {
1049    /// Toggle onboarding message rendering
1050    #[serde(default = "default_onboarding_enabled")]
1051    pub enabled: bool,
1052
1053    /// Introductory text shown at session start
1054    #[serde(default = "default_intro_text")]
1055    pub intro_text: String,
1056
1057    /// Whether to include project overview in onboarding message
1058    #[serde(default = "default_show_project_overview")]
1059    pub include_project_overview: bool,
1060
1061    /// Whether to include language summary in onboarding message
1062    #[serde(default = "default_show_language_summary")]
1063    pub include_language_summary: bool,
1064
1065    /// Whether to include AGENTS.md highlights in onboarding message
1066    #[serde(default = "default_show_guideline_highlights")]
1067    pub include_guideline_highlights: bool,
1068
1069    /// Whether to surface usage tips inside the welcome text banner
1070    #[serde(default = "default_show_usage_tips_in_welcome")]
1071    pub include_usage_tips_in_welcome: bool,
1072
1073    /// Whether to surface suggested actions inside the welcome text banner
1074    #[serde(default = "default_show_recommended_actions_in_welcome")]
1075    pub include_recommended_actions_in_welcome: bool,
1076
1077    /// Maximum number of guideline bullets to surface
1078    #[serde(default = "default_guideline_highlight_limit")]
1079    pub guideline_highlight_limit: usize,
1080
1081    /// Tips for collaborating with the agent effectively
1082    #[serde(default = "default_usage_tips")]
1083    pub usage_tips: Vec<String>,
1084
1085    /// Recommended follow-up actions to display
1086    #[serde(default = "default_recommended_actions")]
1087    pub recommended_actions: Vec<String>,
1088
1089    /// Placeholder suggestion for the chat input bar
1090    #[serde(default)]
1091    pub chat_placeholder: Option<String>,
1092}
1093
1094impl Default for AgentOnboardingConfig {
1095    fn default() -> Self {
1096        Self {
1097            enabled: default_onboarding_enabled(),
1098            intro_text: default_intro_text(),
1099            include_project_overview: default_show_project_overview(),
1100            include_language_summary: default_show_language_summary(),
1101            include_guideline_highlights: default_show_guideline_highlights(),
1102            include_usage_tips_in_welcome: default_show_usage_tips_in_welcome(),
1103            include_recommended_actions_in_welcome: default_show_recommended_actions_in_welcome(),
1104            guideline_highlight_limit: default_guideline_highlight_limit(),
1105            usage_tips: default_usage_tips(),
1106            recommended_actions: default_recommended_actions(),
1107            chat_placeholder: None,
1108        }
1109    }
1110}
1111
1112#[inline]
1113const fn default_onboarding_enabled() -> bool {
1114    true
1115}
1116
1117const DEFAULT_INTRO_TEXT: &str =
1118    "Let's get oriented. I preloaded workspace context so we can move fast.";
1119
1120#[inline]
1121fn default_intro_text() -> String {
1122    DEFAULT_INTRO_TEXT.into()
1123}
1124
1125#[inline]
1126const fn default_show_project_overview() -> bool {
1127    true
1128}
1129
1130#[inline]
1131const fn default_show_language_summary() -> bool {
1132    false
1133}
1134
1135#[inline]
1136const fn default_show_guideline_highlights() -> bool {
1137    true
1138}
1139
1140#[inline]
1141const fn default_show_usage_tips_in_welcome() -> bool {
1142    false
1143}
1144
1145#[inline]
1146const fn default_show_recommended_actions_in_welcome() -> bool {
1147    false
1148}
1149
1150#[inline]
1151const fn default_guideline_highlight_limit() -> usize {
1152    3
1153}
1154
1155const DEFAULT_USAGE_TIPS: &[&str] = &[
1156    "Describe your current coding goal or ask for a quick status overview.",
1157    "Reference AGENTS.md guidelines when proposing changes.",
1158    "Prefer asking for targeted file reads or diffs before editing.",
1159];
1160
1161const DEFAULT_RECOMMENDED_ACTIONS: &[&str] = &[
1162    "Review the highlighted guidelines and share the task you want to tackle.",
1163    "Ask for a workspace tour if you need more context.",
1164];
1165
1166fn default_usage_tips() -> Vec<String> {
1167    DEFAULT_USAGE_TIPS.iter().map(|s| (*s).into()).collect()
1168}
1169
1170fn default_recommended_actions() -> Vec<String> {
1171    DEFAULT_RECOMMENDED_ACTIONS
1172        .iter()
1173        .map(|s| (*s).into())
1174        .collect()
1175}
1176
1177/// Small/lightweight model configuration for efficient operations
1178///
1179/// Following VT Code's pattern, use a smaller model (e.g., Haiku, GPT-4 Mini) for 50%+ of calls:
1180/// - Large file reads and parsing (>50KB)
1181/// - Web page summarization and analysis
1182/// - Git history and commit message processing
1183/// - One-word processing labels and simple classifications
1184///
1185/// Typically 70-80% cheaper than the main model while maintaining quality for these tasks.
1186#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1187#[derive(Debug, Clone, Deserialize, Serialize)]
1188pub struct AgentSmallModelConfig {
1189    /// Enable small model tier for efficient operations
1190    #[serde(default = "default_small_model_enabled")]
1191    pub enabled: bool,
1192
1193    /// Small model to use (e.g., claude-4-5-haiku, "gpt-4-mini", "gemini-2.0-flash")
1194    /// Leave empty to auto-select a lightweight sibling of the main model
1195    #[serde(default)]
1196    pub model: String,
1197
1198    /// Temperature for small model responses
1199    #[serde(default = "default_small_model_temperature")]
1200    pub temperature: f32,
1201
1202    /// Enable small model for large file reads (>50KB)
1203    #[serde(default = "default_small_model_for_large_reads")]
1204    pub use_for_large_reads: bool,
1205
1206    /// Enable small model for web content summarization
1207    #[serde(default = "default_small_model_for_web_summary")]
1208    pub use_for_web_summary: bool,
1209
1210    /// Enable small model for git history processing
1211    #[serde(default = "default_small_model_for_git_history")]
1212    pub use_for_git_history: bool,
1213
1214    /// Enable small model for persistent memory classification and summary refresh
1215    #[serde(default = "default_small_model_for_memory")]
1216    pub use_for_memory: bool,
1217}
1218
1219impl Default for AgentSmallModelConfig {
1220    fn default() -> Self {
1221        Self {
1222            enabled: default_small_model_enabled(),
1223            model: String::new(),
1224            temperature: default_small_model_temperature(),
1225            use_for_large_reads: default_small_model_for_large_reads(),
1226            use_for_web_summary: default_small_model_for_web_summary(),
1227            use_for_git_history: default_small_model_for_git_history(),
1228            use_for_memory: default_small_model_for_memory(),
1229        }
1230    }
1231}
1232
1233#[inline]
1234const fn default_small_model_enabled() -> bool {
1235    true // Enable by default following VT Code pattern
1236}
1237
1238#[inline]
1239const fn default_small_model_temperature() -> f32 {
1240    0.3 // More deterministic for parsing/summarization
1241}
1242
1243#[inline]
1244const fn default_small_model_for_large_reads() -> bool {
1245    true
1246}
1247
1248#[inline]
1249const fn default_small_model_for_web_summary() -> bool {
1250    true
1251}
1252
1253#[inline]
1254const fn default_small_model_for_git_history() -> bool {
1255    true
1256}
1257
1258#[inline]
1259const fn default_small_model_for_memory() -> bool {
1260    true
1261}
1262
1263/// Inline prompt suggestion configuration for the chat composer.
1264#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1265#[derive(Debug, Clone, Deserialize, Serialize)]
1266pub struct AgentPromptSuggestionsConfig {
1267    /// Enable inline prompt suggestions in the chat composer.
1268    #[serde(default = "default_prompt_suggestions_enabled")]
1269    pub enabled: bool,
1270
1271    /// Lightweight model to use for suggestions.
1272    /// Leave empty to auto-select an efficient sibling of the main model.
1273    #[serde(default)]
1274    pub model: String,
1275
1276    /// Temperature for inline prompt suggestion generation.
1277    #[serde(default = "default_prompt_suggestions_temperature")]
1278    pub temperature: f32,
1279
1280    /// Whether VT Code should remind users that LLM-backed suggestions consume tokens.
1281    #[serde(default = "default_prompt_suggestions_show_cost_notice")]
1282    pub show_cost_notice: bool,
1283}
1284
1285impl Default for AgentPromptSuggestionsConfig {
1286    fn default() -> Self {
1287        Self {
1288            enabled: default_prompt_suggestions_enabled(),
1289            model: String::new(),
1290            temperature: default_prompt_suggestions_temperature(),
1291            show_cost_notice: default_prompt_suggestions_show_cost_notice(),
1292        }
1293    }
1294}
1295
1296#[inline]
1297const fn default_prompt_suggestions_enabled() -> bool {
1298    true
1299}
1300
1301#[inline]
1302const fn default_prompt_suggestions_temperature() -> f32 {
1303    0.3
1304}
1305
1306#[inline]
1307const fn default_prompt_suggestions_show_cost_notice() -> bool {
1308    true
1309}
1310
1311/// Vibe coding configuration for lazy/vague request support
1312///
1313/// Enables intelligent context gathering and entity resolution to support
1314/// casual, imprecise requests like "make it blue" or "decrease by half".
1315#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
1316#[derive(Debug, Clone, Deserialize, Serialize)]
1317pub struct AgentVibeCodingConfig {
1318    /// Enable vibe coding support
1319    #[serde(default = "default_vibe_coding_enabled")]
1320    pub enabled: bool,
1321
1322    /// Minimum prompt length for refinement (default: 5 chars)
1323    #[serde(default = "default_vibe_min_prompt_length")]
1324    pub min_prompt_length: usize,
1325
1326    /// Minimum prompt words for refinement (default: 2 words)
1327    #[serde(default = "default_vibe_min_prompt_words")]
1328    pub min_prompt_words: usize,
1329
1330    /// Enable fuzzy entity resolution
1331    #[serde(default = "default_vibe_entity_resolution")]
1332    pub enable_entity_resolution: bool,
1333
1334    /// Entity index cache file path (relative to workspace)
1335    #[serde(default = "default_vibe_entity_cache")]
1336    pub entity_index_cache: String,
1337
1338    /// Maximum entity matches to return (default: 5)
1339    #[serde(default = "default_vibe_max_entity_matches")]
1340    pub max_entity_matches: usize,
1341
1342    /// Track workspace state (file activity, value changes)
1343    #[serde(default = "default_vibe_track_workspace")]
1344    pub track_workspace_state: bool,
1345
1346    /// Maximum recent files to track (default: 20)
1347    #[serde(default = "default_vibe_max_recent_files")]
1348    pub max_recent_files: usize,
1349
1350    /// Track value history for inference
1351    #[serde(default = "default_vibe_track_values")]
1352    pub track_value_history: bool,
1353
1354    /// Enable conversation memory for pronoun resolution
1355    #[serde(default = "default_vibe_conversation_memory")]
1356    pub enable_conversation_memory: bool,
1357
1358    /// Maximum conversation turns to remember (default: 50)
1359    #[serde(default = "default_vibe_max_memory_turns")]
1360    pub max_memory_turns: usize,
1361
1362    /// Enable pronoun resolution (it, that, this)
1363    #[serde(default = "default_vibe_pronoun_resolution")]
1364    pub enable_pronoun_resolution: bool,
1365
1366    /// Enable proactive context gathering
1367    #[serde(default = "default_vibe_proactive_context")]
1368    pub enable_proactive_context: bool,
1369
1370    /// Maximum files to gather for context (default: 3)
1371    #[serde(default = "default_vibe_max_context_files")]
1372    pub max_context_files: usize,
1373
1374    /// Maximum code snippets per file (default: 20 lines)
1375    #[serde(default = "default_vibe_max_snippets_per_file")]
1376    pub max_context_snippets_per_file: usize,
1377
1378    /// Maximum search results to include (default: 5)
1379    #[serde(default = "default_vibe_max_search_results")]
1380    pub max_search_results: usize,
1381
1382    /// Enable relative value inference (by half, double, etc.)
1383    #[serde(default = "default_vibe_value_inference")]
1384    pub enable_relative_value_inference: bool,
1385}
1386
1387impl Default for AgentVibeCodingConfig {
1388    fn default() -> Self {
1389        Self {
1390            enabled: default_vibe_coding_enabled(),
1391            min_prompt_length: default_vibe_min_prompt_length(),
1392            min_prompt_words: default_vibe_min_prompt_words(),
1393            enable_entity_resolution: default_vibe_entity_resolution(),
1394            entity_index_cache: default_vibe_entity_cache(),
1395            max_entity_matches: default_vibe_max_entity_matches(),
1396            track_workspace_state: default_vibe_track_workspace(),
1397            max_recent_files: default_vibe_max_recent_files(),
1398            track_value_history: default_vibe_track_values(),
1399            enable_conversation_memory: default_vibe_conversation_memory(),
1400            max_memory_turns: default_vibe_max_memory_turns(),
1401            enable_pronoun_resolution: default_vibe_pronoun_resolution(),
1402            enable_proactive_context: default_vibe_proactive_context(),
1403            max_context_files: default_vibe_max_context_files(),
1404            max_context_snippets_per_file: default_vibe_max_snippets_per_file(),
1405            max_search_results: default_vibe_max_search_results(),
1406            enable_relative_value_inference: default_vibe_value_inference(),
1407        }
1408    }
1409}
1410
1411// Vibe coding default functions
1412#[inline]
1413const fn default_vibe_coding_enabled() -> bool {
1414    false // Conservative default, opt-in
1415}
1416
1417#[inline]
1418const fn default_vibe_min_prompt_length() -> usize {
1419    5
1420}
1421
1422#[inline]
1423const fn default_vibe_min_prompt_words() -> usize {
1424    2
1425}
1426
1427#[inline]
1428const fn default_vibe_entity_resolution() -> bool {
1429    true
1430}
1431
1432#[inline]
1433fn default_vibe_entity_cache() -> String {
1434    ".vtcode/entity_index.json".into()
1435}
1436
1437#[inline]
1438const fn default_vibe_max_entity_matches() -> usize {
1439    5
1440}
1441
1442#[inline]
1443const fn default_vibe_track_workspace() -> bool {
1444    true
1445}
1446
1447#[inline]
1448const fn default_vibe_max_recent_files() -> usize {
1449    20
1450}
1451
1452#[inline]
1453const fn default_vibe_track_values() -> bool {
1454    true
1455}
1456
1457#[inline]
1458const fn default_vibe_conversation_memory() -> bool {
1459    true
1460}
1461
1462#[inline]
1463const fn default_vibe_max_memory_turns() -> usize {
1464    50
1465}
1466
1467#[inline]
1468const fn default_vibe_pronoun_resolution() -> bool {
1469    true
1470}
1471
1472#[inline]
1473const fn default_vibe_proactive_context() -> bool {
1474    true
1475}
1476
1477#[inline]
1478const fn default_vibe_max_context_files() -> usize {
1479    3
1480}
1481
1482#[inline]
1483const fn default_vibe_max_snippets_per_file() -> usize {
1484    20
1485}
1486
1487#[inline]
1488const fn default_vibe_max_search_results() -> usize {
1489    5
1490}
1491
1492#[inline]
1493const fn default_vibe_value_inference() -> bool {
1494    true
1495}
1496
1497#[cfg(test)]
1498mod tests {
1499    use super::*;
1500
1501    #[test]
1502    fn test_continuation_policy_defaults_and_parses() {
1503        assert_eq!(ContinuationPolicy::default(), ContinuationPolicy::All);
1504        assert_eq!(
1505            ContinuationPolicy::parse("off"),
1506            Some(ContinuationPolicy::Off)
1507        );
1508        assert_eq!(
1509            ContinuationPolicy::parse("exec-only"),
1510            Some(ContinuationPolicy::ExecOnly)
1511        );
1512        assert_eq!(
1513            ContinuationPolicy::parse("all"),
1514            Some(ContinuationPolicy::All)
1515        );
1516        assert_eq!(ContinuationPolicy::parse("invalid"), None);
1517    }
1518
1519    #[test]
1520    fn test_harness_config_continuation_policy_deserializes_with_fallback() {
1521        let parsed: AgentHarnessConfig =
1522            toml::from_str("continuation_policy = \"all\"").expect("valid harness config");
1523        assert_eq!(parsed.continuation_policy, ContinuationPolicy::All);
1524
1525        let fallback: AgentHarnessConfig =
1526            toml::from_str("continuation_policy = \"unexpected\"").expect("fallback config");
1527        assert_eq!(fallback.continuation_policy, ContinuationPolicy::All);
1528    }
1529
1530    #[test]
1531    fn test_harness_orchestration_mode_defaults_and_parses() {
1532        assert_eq!(
1533            HarnessOrchestrationMode::default(),
1534            HarnessOrchestrationMode::Single
1535        );
1536        assert_eq!(
1537            HarnessOrchestrationMode::parse("single"),
1538            Some(HarnessOrchestrationMode::Single)
1539        );
1540        assert_eq!(
1541            HarnessOrchestrationMode::parse("plan_build_evaluate"),
1542            Some(HarnessOrchestrationMode::PlanBuildEvaluate)
1543        );
1544        assert_eq!(
1545            HarnessOrchestrationMode::parse("planner-generator-evaluator"),
1546            Some(HarnessOrchestrationMode::PlanBuildEvaluate)
1547        );
1548        assert_eq!(HarnessOrchestrationMode::parse("unexpected"), None);
1549    }
1550
1551    #[test]
1552    fn test_harness_config_orchestration_deserializes_with_fallback() {
1553        let parsed: AgentHarnessConfig =
1554            toml::from_str("orchestration_mode = \"plan_build_evaluate\"")
1555                .expect("valid harness config");
1556        assert_eq!(
1557            parsed.orchestration_mode,
1558            HarnessOrchestrationMode::PlanBuildEvaluate
1559        );
1560        assert_eq!(parsed.max_revision_rounds, 2);
1561
1562        let fallback: AgentHarnessConfig =
1563            toml::from_str("orchestration_mode = \"unexpected\"").expect("fallback config");
1564        assert_eq!(
1565            fallback.orchestration_mode,
1566            HarnessOrchestrationMode::Single
1567        );
1568    }
1569
1570    #[test]
1571    fn test_plan_confirmation_config_default() {
1572        let config = AgentConfig::default();
1573        assert!(config.require_plan_confirmation);
1574    }
1575
1576    #[test]
1577    fn test_persistent_memory_is_disabled_by_default() {
1578        let config = AgentConfig::default();
1579        assert!(!config.persistent_memory.enabled);
1580        assert!(config.persistent_memory.auto_write);
1581    }
1582
1583    #[test]
1584    fn test_tool_result_clearing_defaults() {
1585        let config = AgentConfig::default();
1586        let clearing = config.harness.tool_result_clearing;
1587
1588        assert!(!clearing.enabled);
1589        assert_eq!(clearing.trigger_tokens, 100_000);
1590        assert_eq!(clearing.keep_tool_uses, 3);
1591        assert_eq!(clearing.clear_at_least_tokens, 30_000);
1592        assert!(!clearing.clear_tool_inputs);
1593    }
1594
1595    #[test]
1596    fn test_codex_app_server_experimental_features_default_to_disabled() {
1597        let config = AgentConfig::default();
1598
1599        assert!(!config.codex_app_server.experimental_features);
1600    }
1601
1602    #[test]
1603    fn test_codex_app_server_experimental_features_parse_from_toml() {
1604        let parsed: AgentCodexAppServerConfig = toml::from_str(
1605            r#"
1606                command = "codex"
1607                args = ["app-server"]
1608                startup_timeout_secs = 15
1609                experimental_features = true
1610            "#,
1611        )
1612        .expect("valid codex app-server config");
1613
1614        assert!(parsed.experimental_features);
1615        assert_eq!(parsed.startup_timeout_secs, 15);
1616    }
1617
1618    #[test]
1619    fn test_tool_result_clearing_parses_and_validates() {
1620        let parsed: AgentHarnessConfig = toml::from_str(
1621            r#"
1622                [tool_result_clearing]
1623                enabled = true
1624                trigger_tokens = 123456
1625                keep_tool_uses = 6
1626                clear_at_least_tokens = 4096
1627                clear_tool_inputs = true
1628            "#,
1629        )
1630        .expect("valid harness config");
1631
1632        assert!(parsed.tool_result_clearing.enabled);
1633        assert_eq!(parsed.tool_result_clearing.trigger_tokens, 123_456);
1634        assert_eq!(parsed.tool_result_clearing.keep_tool_uses, 6);
1635        assert_eq!(parsed.tool_result_clearing.clear_at_least_tokens, 4_096);
1636        assert!(parsed.tool_result_clearing.clear_tool_inputs);
1637        assert!(parsed.tool_result_clearing.validate().is_ok());
1638    }
1639
1640    #[test]
1641    fn test_tool_result_clearing_rejects_zero_values() {
1642        let clearing = ToolResultClearingConfig {
1643            trigger_tokens: 0,
1644            ..ToolResultClearingConfig::default()
1645        };
1646        assert!(clearing.validate().is_err());
1647
1648        let clearing = ToolResultClearingConfig {
1649            keep_tool_uses: 0,
1650            ..ToolResultClearingConfig::default()
1651        };
1652        assert!(clearing.validate().is_err());
1653
1654        let clearing = ToolResultClearingConfig {
1655            clear_at_least_tokens: 0,
1656            ..ToolResultClearingConfig::default()
1657        };
1658        assert!(clearing.validate().is_err());
1659    }
1660
1661    #[test]
1662    fn test_structured_reasoning_defaults_follow_prompt_mode() {
1663        let default_mode = AgentConfig {
1664            system_prompt_mode: SystemPromptMode::Default,
1665            ..Default::default()
1666        };
1667        assert!(!default_mode.should_include_structured_reasoning_tags());
1668
1669        let specialized_mode = AgentConfig {
1670            system_prompt_mode: SystemPromptMode::Specialized,
1671            ..Default::default()
1672        };
1673        assert!(specialized_mode.should_include_structured_reasoning_tags());
1674
1675        let minimal_mode = AgentConfig {
1676            system_prompt_mode: SystemPromptMode::Minimal,
1677            ..Default::default()
1678        };
1679        assert!(!minimal_mode.should_include_structured_reasoning_tags());
1680
1681        let lightweight_mode = AgentConfig {
1682            system_prompt_mode: SystemPromptMode::Lightweight,
1683            ..Default::default()
1684        };
1685        assert!(!lightweight_mode.should_include_structured_reasoning_tags());
1686    }
1687
1688    #[test]
1689    fn test_structured_reasoning_explicit_override() {
1690        let mut config = AgentConfig {
1691            system_prompt_mode: SystemPromptMode::Minimal,
1692            include_structured_reasoning_tags: Some(true),
1693            ..AgentConfig::default()
1694        };
1695        assert!(config.should_include_structured_reasoning_tags());
1696
1697        config.include_structured_reasoning_tags = Some(false);
1698        assert!(!config.should_include_structured_reasoning_tags());
1699    }
1700}