Skip to main content

vtcode_config/core/
agent.rs

1use crate::constants::{defaults, instructions, llm_generation, project_doc};
2use crate::types::{
3    EditingMode, ReasoningEffortLevel, SystemPromptMode, ToolDocumentationMode,
4    UiSurfacePreference, 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, xai, 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 verbosity and token overhead
34    /// Options: minimal (~500-800 tokens), lightweight (~1-2k), default (~6-7k), specialized (~7-8k)
35    /// Inspired by pi-coding-agent: modern models often perform well with minimal prompts
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: grep_file, list_files, read_file, run_pty_cmd, write_file, edit_file
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    /// Reasoning effort level for models that support it (none, low, medium, high)
69    /// Applies to: Claude, GPT-5, GPT-5.1, Gemini, Qwen3, DeepSeek with reasoning capability
70    #[serde(default = "default_reasoning_effort")]
71    pub reasoning_effort: ReasoningEffortLevel,
72
73    /// Verbosity level for output text (low, medium, high)
74    /// Applies to: GPT-5.1 and other models that support verbosity control
75    #[serde(default = "default_verbosity")]
76    pub verbosity: VerbosityLevel,
77
78    /// Temperature for main LLM responses (0.0-1.0)
79    /// Lower values = more deterministic, higher values = more creative
80    /// Recommended: 0.7 for balanced creativity and consistency
81    /// Range: 0.0 (deterministic) to 1.0 (maximum randomness)
82    #[serde(default = "default_temperature")]
83    pub temperature: f32,
84
85    /// Temperature for prompt refinement (0.0-1.0, default: 0.3)
86    /// Lower values ensure prompt refinement is more deterministic/consistent
87    /// Keep lower than main temperature for stable prompt improvement
88    #[serde(default = "default_refine_temperature")]
89    pub refine_temperature: f32,
90
91    /// Enable an extra self-review pass to refine final responses
92    #[serde(default = "default_enable_self_review")]
93    pub enable_self_review: bool,
94
95    /// Maximum number of self-review passes
96    #[serde(default = "default_max_review_passes")]
97    pub max_review_passes: usize,
98
99    /// Enable prompt refinement pass before sending to LLM
100    #[serde(default = "default_refine_prompts_enabled")]
101    pub refine_prompts_enabled: bool,
102
103    /// Max refinement passes for prompt writing
104    #[serde(default = "default_refine_max_passes")]
105    pub refine_prompts_max_passes: usize,
106
107    /// Optional model override for the refiner (empty = auto pick efficient sibling)
108    #[serde(default)]
109    pub refine_prompts_model: String,
110
111    /// Small/lightweight model configuration for efficient operations
112    /// Used for tasks like large file reads, parsing, git history, conversation summarization
113    /// Typically 70-80% cheaper than main model; ~50% of VT Code's calls use this tier
114    #[serde(default)]
115    pub small_model: AgentSmallModelConfig,
116
117    /// Session onboarding and welcome message configuration
118    #[serde(default)]
119    pub onboarding: AgentOnboardingConfig,
120
121    /// Maximum bytes of AGENTS.md content to load from project hierarchy
122    #[serde(default = "default_project_doc_max_bytes")]
123    pub project_doc_max_bytes: usize,
124
125    /// Maximum bytes of instruction content to load from AGENTS.md hierarchy
126    #[serde(
127        default = "default_instruction_max_bytes",
128        alias = "rule_doc_max_bytes"
129    )]
130    pub instruction_max_bytes: usize,
131
132    /// Additional instruction files or globs to merge into the hierarchy
133    #[serde(default, alias = "instruction_paths", alias = "instructions")]
134    pub instruction_files: Vec<String>,
135
136    /// Provider-specific API keys captured from interactive configuration flows
137    #[serde(default)]
138    pub custom_api_keys: BTreeMap<String, String>,
139
140    /// Preferred storage backend for credentials (OAuth tokens, API keys, etc.)
141    ///
142    /// - `keyring`: Use OS-specific secure storage (macOS Keychain, Windows Credential
143    ///   Manager, Linux Secret Service). This is the default as it's the most secure.
144    /// - `file`: Use AES-256-GCM encrypted file with machine-derived key
145    /// - `auto`: Try keyring first, fall back to file if unavailable
146    #[serde(default)]
147    pub credential_storage_mode: crate::auth::AuthCredentialsStoreMode,
148
149    /// Checkpointing configuration for automatic turn snapshots
150    #[serde(default)]
151    pub checkpointing: AgentCheckpointingConfig,
152
153    /// Vibe coding configuration for lazy or vague request support
154    #[serde(default)]
155    pub vibe_coding: AgentVibeCodingConfig,
156
157    /// Maximum number of retries for agent task execution (default: 2)
158    /// When an agent task fails due to retryable errors (timeout, network, 503, etc.),
159    /// it will be retried up to this many times with exponential backoff
160    #[serde(default = "default_max_task_retries")]
161    pub max_task_retries: u32,
162
163    /// Harness configuration for turn-level budgets, telemetry, and execution limits
164    #[serde(default)]
165    pub harness: AgentHarnessConfig,
166
167    /// Include current date/time in system prompt for temporal awareness
168    /// Helps LLM understand context for time-sensitive tasks (default: true)
169    #[serde(default = "default_include_temporal_context")]
170    pub include_temporal_context: bool,
171
172    /// Use UTC instead of local time for temporal context in system prompts
173    #[serde(default)]
174    pub temporal_context_use_utc: bool,
175
176    /// Include current working directory in system prompt (default: true)
177    #[serde(default = "default_include_working_directory")]
178    pub include_working_directory: bool,
179
180    /// Custom instructions provided by the user via configuration to guide agent behavior
181    #[serde(default)]
182    pub user_instructions: Option<String>,
183
184    /// Default editing mode on startup: "edit" (default) or "plan"
185    /// Codex-inspired: Encourages structured planning before execution.
186    #[serde(default)]
187    pub default_editing_mode: EditingMode,
188
189    /// Require user confirmation before executing a plan generated in plan mode
190    /// When true, exiting plan mode shows the implementation blueprint and
191    /// requires explicit user approval before enabling edit tools.
192    #[serde(default = "default_require_plan_confirmation")]
193    pub require_plan_confirmation: bool,
194
195    /// Enable autonomous mode - auto-approve safe tools with reduced HITL prompts
196    /// When true, the agent operates with fewer confirmation prompts for safe tools.
197    #[serde(default = "default_autonomous_mode")]
198    pub autonomous_mode: bool,
199
200    /// Circuit breaker configuration for resilient tool execution
201    /// Controls when the agent should pause and ask for user guidance due to repeated failures
202    #[serde(default)]
203    pub circuit_breaker: CircuitBreakerConfig,
204
205    /// Open Responses specification compliance configuration
206    /// Enables vendor-neutral LLM API format for interoperable workflows
207    #[serde(default)]
208    pub open_responses: OpenResponsesConfig,
209}
210
211#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
212#[derive(Debug, Clone, Deserialize, Serialize)]
213pub struct AgentHarnessConfig {
214    /// Maximum number of tool calls allowed per turn
215    #[serde(default = "default_harness_max_tool_calls_per_turn")]
216    pub max_tool_calls_per_turn: usize,
217    /// Maximum wall clock time (seconds) for tool execution in a turn
218    #[serde(default = "default_harness_max_tool_wall_clock_secs")]
219    pub max_tool_wall_clock_secs: u64,
220    /// Maximum retries for retryable tool errors
221    #[serde(default = "default_harness_max_tool_retries")]
222    pub max_tool_retries: u32,
223    /// Optional JSONL event log path for harness events
224    #[serde(default)]
225    pub event_log_path: Option<String>,
226}
227
228impl Default for AgentHarnessConfig {
229    fn default() -> Self {
230        Self {
231            max_tool_calls_per_turn: default_harness_max_tool_calls_per_turn(),
232            max_tool_wall_clock_secs: default_harness_max_tool_wall_clock_secs(),
233            max_tool_retries: default_harness_max_tool_retries(),
234            event_log_path: None,
235        }
236    }
237}
238
239#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
240#[derive(Debug, Clone, Deserialize, Serialize)]
241pub struct CircuitBreakerConfig {
242    /// Enable circuit breaker functionality
243    #[serde(default = "default_circuit_breaker_enabled")]
244    pub enabled: bool,
245
246    /// Number of consecutive failures before opening circuit
247    #[serde(default = "default_failure_threshold")]
248    pub failure_threshold: u32,
249
250    /// Pause and ask user when circuit opens (vs auto-backoff)
251    #[serde(default = "default_pause_on_open")]
252    pub pause_on_open: bool,
253
254    /// Number of open circuits before triggering pause
255    #[serde(default = "default_max_open_circuits")]
256    pub max_open_circuits: usize,
257
258    /// Cooldown period between recovery prompts (seconds)
259    #[serde(default = "default_recovery_cooldown")]
260    pub recovery_cooldown: u64,
261}
262
263impl Default for CircuitBreakerConfig {
264    fn default() -> Self {
265        Self {
266            enabled: default_circuit_breaker_enabled(),
267            failure_threshold: default_failure_threshold(),
268            pause_on_open: default_pause_on_open(),
269            max_open_circuits: default_max_open_circuits(),
270            recovery_cooldown: default_recovery_cooldown(),
271        }
272    }
273}
274
275/// Open Responses specification compliance configuration
276///
277/// Enables vendor-neutral LLM API format per the Open Responses specification
278/// (<https://www.openresponses.org/>). When enabled, VT Code emits semantic
279/// streaming events and uses standardized response/item structures.
280#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
281#[derive(Debug, Clone, Deserialize, Serialize)]
282pub struct OpenResponsesConfig {
283    /// Enable Open Responses specification compliance layer
284    /// When true, VT Code emits semantic streaming events alongside internal events
285    /// Default: false (opt-in feature)
286    #[serde(default)]
287    pub enabled: bool,
288
289    /// Emit Open Responses events to the event sink
290    /// When true, streaming events follow Open Responses format
291    /// (response.created, response.output_item.added, response.output_text.delta, etc.)
292    #[serde(default = "default_open_responses_emit_events")]
293    pub emit_events: bool,
294
295    /// Include VT Code extension items (vtcode:file_change, vtcode:web_search, etc.)
296    /// When false, extension items are omitted from the Open Responses output
297    #[serde(default = "default_open_responses_include_extensions")]
298    pub include_extensions: bool,
299
300    /// Map internal tool calls to Open Responses function_call items
301    /// When true, command executions and MCP tool calls are represented as function_call items
302    #[serde(default = "default_open_responses_map_tool_calls")]
303    pub map_tool_calls: bool,
304
305    /// Include reasoning items in Open Responses output
306    /// When true, model reasoning/thinking is exposed as reasoning items
307    #[serde(default = "default_open_responses_include_reasoning")]
308    pub include_reasoning: bool,
309}
310
311impl Default for OpenResponsesConfig {
312    fn default() -> Self {
313        Self {
314            enabled: false, // Opt-in by default
315            emit_events: default_open_responses_emit_events(),
316            include_extensions: default_open_responses_include_extensions(),
317            map_tool_calls: default_open_responses_map_tool_calls(),
318            include_reasoning: default_open_responses_include_reasoning(),
319        }
320    }
321}
322
323#[inline]
324const fn default_open_responses_emit_events() -> bool {
325    true // When enabled, emit events by default
326}
327
328#[inline]
329const fn default_open_responses_include_extensions() -> bool {
330    true // Include VT Code-specific extensions by default
331}
332
333#[inline]
334const fn default_open_responses_map_tool_calls() -> bool {
335    true // Map tool calls to function_call items by default
336}
337
338#[inline]
339const fn default_open_responses_include_reasoning() -> bool {
340    true // Include reasoning items by default
341}
342
343impl Default for AgentConfig {
344    fn default() -> Self {
345        Self {
346            provider: default_provider(),
347            api_key_env: default_api_key_env(),
348            default_model: default_model(),
349            theme: default_theme(),
350            system_prompt_mode: SystemPromptMode::default(),
351            tool_documentation_mode: ToolDocumentationMode::default(),
352            enable_split_tool_results: default_enable_split_tool_results(),
353            todo_planning_mode: default_todo_planning_mode(),
354            ui_surface: UiSurfacePreference::default(),
355            max_conversation_turns: default_max_conversation_turns(),
356            reasoning_effort: default_reasoning_effort(),
357            verbosity: default_verbosity(),
358            temperature: default_temperature(),
359            refine_temperature: default_refine_temperature(),
360            enable_self_review: default_enable_self_review(),
361            max_review_passes: default_max_review_passes(),
362            refine_prompts_enabled: default_refine_prompts_enabled(),
363            refine_prompts_max_passes: default_refine_max_passes(),
364            refine_prompts_model: String::new(),
365            small_model: AgentSmallModelConfig::default(),
366            onboarding: AgentOnboardingConfig::default(),
367            project_doc_max_bytes: default_project_doc_max_bytes(),
368            instruction_max_bytes: default_instruction_max_bytes(),
369            instruction_files: Vec::new(),
370            custom_api_keys: BTreeMap::new(),
371            credential_storage_mode: crate::auth::AuthCredentialsStoreMode::default(),
372            checkpointing: AgentCheckpointingConfig::default(),
373            vibe_coding: AgentVibeCodingConfig::default(),
374            max_task_retries: default_max_task_retries(),
375            harness: AgentHarnessConfig::default(),
376            include_temporal_context: default_include_temporal_context(),
377            temporal_context_use_utc: false, // Default to local time
378            include_working_directory: default_include_working_directory(),
379            user_instructions: None,
380            default_editing_mode: EditingMode::default(),
381            require_plan_confirmation: default_require_plan_confirmation(),
382            autonomous_mode: default_autonomous_mode(),
383            circuit_breaker: CircuitBreakerConfig::default(),
384            open_responses: OpenResponsesConfig::default(),
385        }
386    }
387}
388
389impl AgentConfig {
390    /// Validate LLM generation parameters
391    pub fn validate_llm_params(&self) -> Result<(), String> {
392        // Validate temperature range
393        if !(0.0..=1.0).contains(&self.temperature) {
394            return Err(format!(
395                "temperature must be between 0.0 and 1.0, got {}",
396                self.temperature
397            ));
398        }
399
400        if !(0.0..=1.0).contains(&self.refine_temperature) {
401            return Err(format!(
402                "refine_temperature must be between 0.0 and 1.0, got {}",
403                self.refine_temperature
404            ));
405        }
406
407        Ok(())
408    }
409}
410
411// Optimized: Use inline defaults with constants to reduce function call overhead
412#[inline]
413fn default_provider() -> String {
414    defaults::DEFAULT_PROVIDER.into()
415}
416
417#[inline]
418fn default_api_key_env() -> String {
419    defaults::DEFAULT_API_KEY_ENV.into()
420}
421
422#[inline]
423fn default_model() -> String {
424    defaults::DEFAULT_MODEL.into()
425}
426
427#[inline]
428fn default_theme() -> String {
429    defaults::DEFAULT_THEME.into()
430}
431
432#[inline]
433const fn default_todo_planning_mode() -> bool {
434    true
435}
436
437#[inline]
438const fn default_enable_split_tool_results() -> bool {
439    true // Default: enabled for production use (84% token savings)
440}
441
442#[inline]
443const fn default_max_conversation_turns() -> usize {
444    defaults::DEFAULT_MAX_CONVERSATION_TURNS
445}
446
447#[inline]
448fn default_reasoning_effort() -> ReasoningEffortLevel {
449    ReasoningEffortLevel::default()
450}
451
452#[inline]
453fn default_verbosity() -> VerbosityLevel {
454    VerbosityLevel::default()
455}
456
457#[inline]
458const fn default_temperature() -> f32 {
459    llm_generation::DEFAULT_TEMPERATURE
460}
461
462#[inline]
463const fn default_refine_temperature() -> f32 {
464    llm_generation::DEFAULT_REFINE_TEMPERATURE
465}
466
467#[inline]
468const fn default_enable_self_review() -> bool {
469    false
470}
471
472#[inline]
473const fn default_max_review_passes() -> usize {
474    1
475}
476
477#[inline]
478const fn default_refine_prompts_enabled() -> bool {
479    false
480}
481
482#[inline]
483const fn default_refine_max_passes() -> usize {
484    1
485}
486
487#[inline]
488const fn default_project_doc_max_bytes() -> usize {
489    project_doc::DEFAULT_MAX_BYTES
490}
491
492#[inline]
493const fn default_instruction_max_bytes() -> usize {
494    instructions::DEFAULT_MAX_BYTES
495}
496
497#[inline]
498const fn default_max_task_retries() -> u32 {
499    2 // Retry twice on transient failures
500}
501
502#[inline]
503const fn default_harness_max_tool_calls_per_turn() -> usize {
504    defaults::DEFAULT_MAX_TOOL_CALLS_PER_TURN
505}
506
507#[inline]
508const fn default_harness_max_tool_wall_clock_secs() -> u64 {
509    defaults::DEFAULT_MAX_TOOL_WALL_CLOCK_SECS
510}
511
512#[inline]
513const fn default_harness_max_tool_retries() -> u32 {
514    defaults::DEFAULT_MAX_TOOL_RETRIES
515}
516
517#[inline]
518const fn default_include_temporal_context() -> bool {
519    true // Enable by default - minimal overhead (~20 tokens)
520}
521
522#[inline]
523const fn default_include_working_directory() -> bool {
524    true // Enable by default - minimal overhead (~10 tokens)
525}
526
527#[inline]
528const fn default_require_plan_confirmation() -> bool {
529    true // Default: require confirmation (HITL pattern)
530}
531
532#[inline]
533const fn default_autonomous_mode() -> bool {
534    false // Default: interactive mode with full HITL
535}
536
537#[inline]
538const fn default_circuit_breaker_enabled() -> bool {
539    true // Default: enabled for resilient execution
540}
541
542#[inline]
543const fn default_failure_threshold() -> u32 {
544    5 // Open circuit after 5 consecutive failures
545}
546
547#[inline]
548const fn default_pause_on_open() -> bool {
549    true // Default: ask user for guidance on circuit breaker
550}
551
552#[inline]
553const fn default_max_open_circuits() -> usize {
554    3 // Pause when 3+ tools have open circuits
555}
556
557#[inline]
558const fn default_recovery_cooldown() -> u64 {
559    60 // Cooldown between recovery prompts (seconds)
560}
561
562#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
563#[derive(Debug, Clone, Deserialize, Serialize)]
564pub struct AgentCheckpointingConfig {
565    /// Enable automatic checkpoints after each successful turn
566    #[serde(default = "default_checkpointing_enabled")]
567    pub enabled: bool,
568
569    /// Optional custom directory for storing checkpoints (relative to workspace or absolute)
570    #[serde(default)]
571    pub storage_dir: Option<String>,
572
573    /// Maximum number of checkpoints to retain on disk
574    #[serde(default = "default_checkpointing_max_snapshots")]
575    pub max_snapshots: usize,
576
577    /// Maximum age in days before checkpoints are removed automatically (None disables)
578    #[serde(default = "default_checkpointing_max_age_days")]
579    pub max_age_days: Option<u64>,
580}
581
582impl Default for AgentCheckpointingConfig {
583    fn default() -> Self {
584        Self {
585            enabled: default_checkpointing_enabled(),
586            storage_dir: None,
587            max_snapshots: default_checkpointing_max_snapshots(),
588            max_age_days: default_checkpointing_max_age_days(),
589        }
590    }
591}
592
593#[inline]
594const fn default_checkpointing_enabled() -> bool {
595    DEFAULT_CHECKPOINTS_ENABLED
596}
597
598#[inline]
599const fn default_checkpointing_max_snapshots() -> usize {
600    DEFAULT_MAX_SNAPSHOTS
601}
602
603#[inline]
604const fn default_checkpointing_max_age_days() -> Option<u64> {
605    Some(DEFAULT_MAX_AGE_DAYS)
606}
607
608#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
609#[derive(Debug, Clone, Deserialize, Serialize)]
610pub struct AgentOnboardingConfig {
611    /// Toggle onboarding message rendering
612    #[serde(default = "default_onboarding_enabled")]
613    pub enabled: bool,
614
615    /// Introductory text shown at session start
616    #[serde(default = "default_intro_text")]
617    pub intro_text: String,
618
619    /// Whether to include project overview in onboarding message
620    #[serde(default = "default_show_project_overview")]
621    pub include_project_overview: bool,
622
623    /// Whether to include language summary in onboarding message
624    #[serde(default = "default_show_language_summary")]
625    pub include_language_summary: bool,
626
627    /// Whether to include AGENTS.md highlights in onboarding message
628    #[serde(default = "default_show_guideline_highlights")]
629    pub include_guideline_highlights: bool,
630
631    /// Whether to surface usage tips inside the welcome text banner
632    #[serde(default = "default_show_usage_tips_in_welcome")]
633    pub include_usage_tips_in_welcome: bool,
634
635    /// Whether to surface suggested actions inside the welcome text banner
636    #[serde(default = "default_show_recommended_actions_in_welcome")]
637    pub include_recommended_actions_in_welcome: bool,
638
639    /// Maximum number of guideline bullets to surface
640    #[serde(default = "default_guideline_highlight_limit")]
641    pub guideline_highlight_limit: usize,
642
643    /// Tips for collaborating with the agent effectively
644    #[serde(default = "default_usage_tips")]
645    pub usage_tips: Vec<String>,
646
647    /// Recommended follow-up actions to display
648    #[serde(default = "default_recommended_actions")]
649    pub recommended_actions: Vec<String>,
650
651    /// Placeholder suggestion for the chat input bar
652    #[serde(default)]
653    pub chat_placeholder: Option<String>,
654}
655
656impl Default for AgentOnboardingConfig {
657    fn default() -> Self {
658        Self {
659            enabled: default_onboarding_enabled(),
660            intro_text: default_intro_text(),
661            include_project_overview: default_show_project_overview(),
662            include_language_summary: default_show_language_summary(),
663            include_guideline_highlights: default_show_guideline_highlights(),
664            include_usage_tips_in_welcome: default_show_usage_tips_in_welcome(),
665            include_recommended_actions_in_welcome: default_show_recommended_actions_in_welcome(),
666            guideline_highlight_limit: default_guideline_highlight_limit(),
667            usage_tips: default_usage_tips(),
668            recommended_actions: default_recommended_actions(),
669            chat_placeholder: None,
670        }
671    }
672}
673
674#[inline]
675const fn default_onboarding_enabled() -> bool {
676    true
677}
678
679const DEFAULT_INTRO_TEXT: &str =
680    "Let's get oriented. I preloaded workspace context so we can move fast.";
681
682#[inline]
683fn default_intro_text() -> String {
684    DEFAULT_INTRO_TEXT.into()
685}
686
687#[inline]
688const fn default_show_project_overview() -> bool {
689    true
690}
691
692#[inline]
693const fn default_show_language_summary() -> bool {
694    false
695}
696
697#[inline]
698const fn default_show_guideline_highlights() -> bool {
699    true
700}
701
702#[inline]
703const fn default_show_usage_tips_in_welcome() -> bool {
704    false
705}
706
707#[inline]
708const fn default_show_recommended_actions_in_welcome() -> bool {
709    false
710}
711
712#[inline]
713const fn default_guideline_highlight_limit() -> usize {
714    3
715}
716
717const DEFAULT_USAGE_TIPS: &[&str] = &[
718    "Describe your current coding goal or ask for a quick status overview.",
719    "Reference AGENTS.md guidelines when proposing changes.",
720    "Prefer asking for targeted file reads or diffs before editing.",
721];
722
723const DEFAULT_RECOMMENDED_ACTIONS: &[&str] = &[
724    "Review the highlighted guidelines and share the task you want to tackle.",
725    "Ask for a workspace tour if you need more context.",
726];
727
728fn default_usage_tips() -> Vec<String> {
729    DEFAULT_USAGE_TIPS.iter().map(|s| (*s).into()).collect()
730}
731
732fn default_recommended_actions() -> Vec<String> {
733    DEFAULT_RECOMMENDED_ACTIONS
734        .iter()
735        .map(|s| (*s).into())
736        .collect()
737}
738
739/// Small/lightweight model configuration for efficient operations
740///
741/// Following VT Code's pattern, use a smaller model (e.g., Haiku, GPT-4 Mini) for 50%+ of calls:
742/// - Large file reads and parsing (>50KB)
743/// - Web page summarization and analysis
744/// - Git history and commit message processing
745/// - One-word processing labels and simple classifications
746///
747/// Typically 70-80% cheaper than the main model while maintaining quality for these tasks.
748#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
749#[derive(Debug, Clone, Deserialize, Serialize)]
750pub struct AgentSmallModelConfig {
751    /// Enable small model tier for efficient operations
752    #[serde(default = "default_small_model_enabled")]
753    pub enabled: bool,
754
755    /// Small model to use (e.g., claude-4-5-haiku, "gpt-4-mini", "gemini-2.0-flash")
756    /// Leave empty to auto-select a lightweight sibling of the main model
757    #[serde(default)]
758    pub model: String,
759
760    /// Temperature for small model responses
761    #[serde(default = "default_small_model_temperature")]
762    pub temperature: f32,
763
764    /// Enable small model for large file reads (>50KB)
765    #[serde(default = "default_small_model_for_large_reads")]
766    pub use_for_large_reads: bool,
767
768    /// Enable small model for web content summarization
769    #[serde(default = "default_small_model_for_web_summary")]
770    pub use_for_web_summary: bool,
771
772    /// Enable small model for git history processing
773    #[serde(default = "default_small_model_for_git_history")]
774    pub use_for_git_history: bool,
775}
776
777impl Default for AgentSmallModelConfig {
778    fn default() -> Self {
779        Self {
780            enabled: default_small_model_enabled(),
781            model: String::new(),
782            temperature: default_small_model_temperature(),
783            use_for_large_reads: default_small_model_for_large_reads(),
784            use_for_web_summary: default_small_model_for_web_summary(),
785            use_for_git_history: default_small_model_for_git_history(),
786        }
787    }
788}
789
790#[inline]
791const fn default_small_model_enabled() -> bool {
792    true // Enable by default following VT Code pattern
793}
794
795#[inline]
796const fn default_small_model_temperature() -> f32 {
797    0.3 // More deterministic for parsing/summarization
798}
799
800#[inline]
801const fn default_small_model_for_large_reads() -> bool {
802    true
803}
804
805#[inline]
806const fn default_small_model_for_web_summary() -> bool {
807    true
808}
809
810#[inline]
811const fn default_small_model_for_git_history() -> bool {
812    true
813}
814
815/// Vibe coding configuration for lazy/vague request support
816///
817/// Enables intelligent context gathering and entity resolution to support
818/// casual, imprecise requests like "make it blue" or "decrease by half".
819#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
820#[derive(Debug, Clone, Deserialize, Serialize)]
821pub struct AgentVibeCodingConfig {
822    /// Enable vibe coding support
823    #[serde(default = "default_vibe_coding_enabled")]
824    pub enabled: bool,
825
826    /// Minimum prompt length for refinement (default: 5 chars)
827    #[serde(default = "default_vibe_min_prompt_length")]
828    pub min_prompt_length: usize,
829
830    /// Minimum prompt words for refinement (default: 2 words)
831    #[serde(default = "default_vibe_min_prompt_words")]
832    pub min_prompt_words: usize,
833
834    /// Enable fuzzy entity resolution
835    #[serde(default = "default_vibe_entity_resolution")]
836    pub enable_entity_resolution: bool,
837
838    /// Entity index cache file path (relative to workspace)
839    #[serde(default = "default_vibe_entity_cache")]
840    pub entity_index_cache: String,
841
842    /// Maximum entity matches to return (default: 5)
843    #[serde(default = "default_vibe_max_entity_matches")]
844    pub max_entity_matches: usize,
845
846    /// Track workspace state (file activity, value changes)
847    #[serde(default = "default_vibe_track_workspace")]
848    pub track_workspace_state: bool,
849
850    /// Maximum recent files to track (default: 20)
851    #[serde(default = "default_vibe_max_recent_files")]
852    pub max_recent_files: usize,
853
854    /// Track value history for inference
855    #[serde(default = "default_vibe_track_values")]
856    pub track_value_history: bool,
857
858    /// Enable conversation memory for pronoun resolution
859    #[serde(default = "default_vibe_conversation_memory")]
860    pub enable_conversation_memory: bool,
861
862    /// Maximum conversation turns to remember (default: 50)
863    #[serde(default = "default_vibe_max_memory_turns")]
864    pub max_memory_turns: usize,
865
866    /// Enable pronoun resolution (it, that, this)
867    #[serde(default = "default_vibe_pronoun_resolution")]
868    pub enable_pronoun_resolution: bool,
869
870    /// Enable proactive context gathering
871    #[serde(default = "default_vibe_proactive_context")]
872    pub enable_proactive_context: bool,
873
874    /// Maximum files to gather for context (default: 3)
875    #[serde(default = "default_vibe_max_context_files")]
876    pub max_context_files: usize,
877
878    /// Maximum code snippets per file (default: 20 lines)
879    #[serde(default = "default_vibe_max_snippets_per_file")]
880    pub max_context_snippets_per_file: usize,
881
882    /// Maximum search results to include (default: 5)
883    #[serde(default = "default_vibe_max_search_results")]
884    pub max_search_results: usize,
885
886    /// Enable relative value inference (by half, double, etc.)
887    #[serde(default = "default_vibe_value_inference")]
888    pub enable_relative_value_inference: bool,
889}
890
891impl Default for AgentVibeCodingConfig {
892    fn default() -> Self {
893        Self {
894            enabled: default_vibe_coding_enabled(),
895            min_prompt_length: default_vibe_min_prompt_length(),
896            min_prompt_words: default_vibe_min_prompt_words(),
897            enable_entity_resolution: default_vibe_entity_resolution(),
898            entity_index_cache: default_vibe_entity_cache(),
899            max_entity_matches: default_vibe_max_entity_matches(),
900            track_workspace_state: default_vibe_track_workspace(),
901            max_recent_files: default_vibe_max_recent_files(),
902            track_value_history: default_vibe_track_values(),
903            enable_conversation_memory: default_vibe_conversation_memory(),
904            max_memory_turns: default_vibe_max_memory_turns(),
905            enable_pronoun_resolution: default_vibe_pronoun_resolution(),
906            enable_proactive_context: default_vibe_proactive_context(),
907            max_context_files: default_vibe_max_context_files(),
908            max_context_snippets_per_file: default_vibe_max_snippets_per_file(),
909            max_search_results: default_vibe_max_search_results(),
910            enable_relative_value_inference: default_vibe_value_inference(),
911        }
912    }
913}
914
915// Vibe coding default functions
916#[inline]
917const fn default_vibe_coding_enabled() -> bool {
918    false // Conservative default, opt-in
919}
920
921#[inline]
922const fn default_vibe_min_prompt_length() -> usize {
923    5
924}
925
926#[inline]
927const fn default_vibe_min_prompt_words() -> usize {
928    2
929}
930
931#[inline]
932const fn default_vibe_entity_resolution() -> bool {
933    true
934}
935
936#[inline]
937fn default_vibe_entity_cache() -> String {
938    ".vtcode/entity_index.json".into()
939}
940
941#[inline]
942const fn default_vibe_max_entity_matches() -> usize {
943    5
944}
945
946#[inline]
947const fn default_vibe_track_workspace() -> bool {
948    true
949}
950
951#[inline]
952const fn default_vibe_max_recent_files() -> usize {
953    20
954}
955
956#[inline]
957const fn default_vibe_track_values() -> bool {
958    true
959}
960
961#[inline]
962const fn default_vibe_conversation_memory() -> bool {
963    true
964}
965
966#[inline]
967const fn default_vibe_max_memory_turns() -> usize {
968    50
969}
970
971#[inline]
972const fn default_vibe_pronoun_resolution() -> bool {
973    true
974}
975
976#[inline]
977const fn default_vibe_proactive_context() -> bool {
978    true
979}
980
981#[inline]
982const fn default_vibe_max_context_files() -> usize {
983    3
984}
985
986#[inline]
987const fn default_vibe_max_snippets_per_file() -> usize {
988    20
989}
990
991#[inline]
992const fn default_vibe_max_search_results() -> usize {
993    5
994}
995
996#[inline]
997const fn default_vibe_value_inference() -> bool {
998    true
999}
1000
1001#[cfg(test)]
1002mod tests {
1003    use super::*;
1004
1005    #[test]
1006    fn test_editing_mode_config_default() {
1007        let config = AgentConfig::default();
1008        assert_eq!(config.default_editing_mode, EditingMode::Edit);
1009        assert!(config.require_plan_confirmation);
1010        assert!(!config.autonomous_mode);
1011    }
1012}