Skip to main content

zeph_config/
agent.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use std::path::PathBuf;
5
6use serde::{Deserialize, Deserializer, Serialize, Serializer};
7
8use crate::providers::ProviderName;
9use crate::subagent::{HookDef, MemoryScope, PermissionMode};
10
11/// Specifies which LLM provider a sub-agent should use.
12///
13/// Used in `SubAgentDef.model` frontmatter field.
14#[derive(Debug, Clone, PartialEq, Eq)]
15#[non_exhaustive]
16pub enum ModelSpec {
17    /// Use the parent agent's active provider at spawn time.
18    Inherit,
19    /// Use a specific named provider from `[[llm.providers]]`.
20    Named(String),
21}
22
23impl ModelSpec {
24    /// Return the string representation: `"inherit"` or the provider name.
25    #[must_use]
26    pub fn as_str(&self) -> &str {
27        match self {
28            ModelSpec::Inherit => "inherit",
29            ModelSpec::Named(s) => s.as_str(),
30        }
31    }
32}
33
34impl Serialize for ModelSpec {
35    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
36        match self {
37            ModelSpec::Inherit => serializer.serialize_str("inherit"),
38            ModelSpec::Named(s) => serializer.serialize_str(s),
39        }
40    }
41}
42
43impl<'de> Deserialize<'de> for ModelSpec {
44    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
45        let s = String::deserialize(deserializer)?;
46        if s == "inherit" {
47            Ok(ModelSpec::Inherit)
48        } else {
49            Ok(ModelSpec::Named(s))
50        }
51    }
52}
53
54/// Controls how the parent agent's conversation history is sanitized before passing to a
55/// spawned sub-agent.
56///
57/// Prompt injection is a documented attack vector when the parent history contains untrusted
58/// content from web scrapes, tool results, or A2A messages.  `InheritSanitized` is the safe
59/// default: messages pass through `ContentSanitizer` (in `zeph-sanitizer`) before injection.
60///
61/// # Examples
62///
63/// ```toml
64/// [subagent]
65/// parent_context_policy = "inherit_sanitized"   # default
66/// ```
67#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
68#[serde(rename_all = "snake_case")]
69#[non_exhaustive]
70pub enum ParentContextPolicy {
71    /// Pass the parent history verbatim — legacy behaviour, no sanitization.
72    Inherit,
73    /// Sanitize text parts of each message through the IPI pipeline before injection.
74    #[default]
75    InheritSanitized,
76    /// Do not inject any parent history into the sub-agent context.
77    None,
78}
79
80/// Controls how parent agent context is injected into a spawned sub-agent's task prompt.
81#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
82#[serde(rename_all = "snake_case")]
83#[non_exhaustive]
84pub enum ContextInjectionMode {
85    /// No parent context injected.
86    None,
87    /// Prepend the last assistant turn from parent history as a preamble.
88    #[default]
89    LastAssistantTurn,
90    /// LLM-generated summary of parent context (not yet implemented in Phase 1).
91    Summary,
92}
93
94fn default_max_parent_messages() -> usize {
95    20
96}
97
98fn default_summary_max_chars() -> usize {
99    600
100}
101
102fn default_llm_timeout_secs() -> u64 {
103    120
104}
105
106fn default_max_tool_iterations() -> usize {
107    10
108}
109
110fn default_auto_update_check() -> bool {
111    true
112}
113
114fn default_focus_compression_interval() -> usize {
115    12
116}
117
118fn default_focus_reminder_interval() -> usize {
119    15
120}
121
122fn default_focus_min_messages_per_focus() -> usize {
123    8
124}
125
126fn default_focus_max_knowledge_tokens() -> usize {
127    4096
128}
129
130fn default_focus_auto_consolidate_min_window() -> usize {
131    6
132}
133
134fn default_max_tool_retries() -> usize {
135    2
136}
137
138fn default_max_retry_duration_secs() -> u64 {
139    30
140}
141
142fn default_tool_repeat_threshold() -> usize {
143    2
144}
145
146fn default_tool_filter_top_k() -> usize {
147    6
148}
149
150fn default_tool_filter_min_description_words() -> usize {
151    5
152}
153
154fn default_tool_filter_always_on() -> Vec<String> {
155    vec![
156        "memory_search".into(),
157        "memory_save".into(),
158        "load_skill".into(),
159        "invoke_skill".into(),
160        "bash".into(),
161        "read".into(),
162        "edit".into(),
163    ]
164}
165
166fn default_instruction_auto_detect() -> bool {
167    true
168}
169
170fn default_max_concurrent() -> usize {
171    5
172}
173
174fn default_context_window_turns() -> usize {
175    10
176}
177
178fn default_max_spawn_depth() -> u32 {
179    3
180}
181
182fn default_transcript_enabled() -> bool {
183    true
184}
185
186fn default_transcript_max_files() -> usize {
187    50
188}
189
190/// Configuration for focus-based active context compression (#1850).
191#[derive(Debug, Clone, Deserialize, Serialize)]
192#[serde(default)]
193pub struct FocusConfig {
194    /// Enable focus tools (`start_focus` / `complete_focus`). Default: `false`.
195    pub enabled: bool,
196    /// Suggest focus after this many turns without one. Default: `12`.
197    #[serde(default = "default_focus_compression_interval")]
198    pub compression_interval: usize,
199    /// Remind the agent every N turns when focus is overdue. Default: `15`.
200    #[serde(default = "default_focus_reminder_interval")]
201    pub reminder_interval: usize,
202    /// Minimum messages required before suggesting a focus. Default: `8`.
203    #[serde(default = "default_focus_min_messages_per_focus")]
204    pub min_messages_per_focus: usize,
205    /// Maximum tokens the Knowledge block may grow to before old entries are trimmed.
206    /// Default: `4096`.
207    #[serde(default = "default_focus_max_knowledge_tokens")]
208    pub max_knowledge_tokens: usize,
209    /// Minimum turns since the last auto-consolidation before the next one fires.
210    ///
211    /// Must be >= 1. `Config::validate()` rejects `0` at startup. Default: `6`.
212    #[serde(default = "default_focus_auto_consolidate_min_window")]
213    pub auto_consolidate_min_window: usize,
214}
215
216impl Default for FocusConfig {
217    fn default() -> Self {
218        Self {
219            enabled: false,
220            compression_interval: default_focus_compression_interval(),
221            reminder_interval: default_focus_reminder_interval(),
222            min_messages_per_focus: default_focus_min_messages_per_focus(),
223            max_knowledge_tokens: default_focus_max_knowledge_tokens(),
224            auto_consolidate_min_window: default_focus_auto_consolidate_min_window(),
225        }
226    }
227}
228
229/// Dynamic tool schema filtering configuration (#2020).
230///
231/// When enabled, only a subset of tool definitions is sent to the LLM on each turn,
232/// selected by embedding similarity between the user query and tool descriptions.
233#[derive(Debug, Clone, Deserialize, Serialize)]
234#[serde(default)]
235pub struct ToolFilterConfig {
236    /// Enable dynamic tool schema filtering. Default: `false` (opt-in).
237    pub enabled: bool,
238    /// Number of top-scoring filterable tools to include per turn.
239    /// Set to `0` to include all filterable tools.
240    #[serde(default = "default_tool_filter_top_k")]
241    pub top_k: usize,
242    /// Tool IDs that are never filtered out.
243    #[serde(default = "default_tool_filter_always_on")]
244    pub always_on: Vec<String>,
245    /// MCP tools with fewer description words than this are auto-included.
246    #[serde(default = "default_tool_filter_min_description_words")]
247    pub min_description_words: usize,
248}
249
250impl Default for ToolFilterConfig {
251    fn default() -> Self {
252        Self {
253            enabled: false,
254            top_k: default_tool_filter_top_k(),
255            always_on: default_tool_filter_always_on(),
256            min_description_words: default_tool_filter_min_description_words(),
257        }
258    }
259}
260
261/// Core agent behavior configuration, nested under `[agent]` in TOML.
262///
263/// Controls the agent's name, tool-loop limits, instruction loading, and retry
264/// behavior. All fields have sensible defaults; only `name` is typically changed
265/// by end users.
266///
267/// # Example (TOML)
268///
269/// ```toml
270/// [agent]
271/// name = "Zeph"
272/// max_tool_iterations = 15
273/// max_tool_retries = 3
274/// ```
275#[derive(Debug, Deserialize, Serialize)]
276pub struct AgentConfig {
277    /// Human-readable agent name surfaced in the TUI and Telegram header. Default: `"Zeph"`.
278    pub name: String,
279    /// Maximum number of tool-call iterations per agent turn before the loop is aborted.
280    /// Must be `<= 100`. Default: `10`.
281    #[serde(default = "default_max_tool_iterations")]
282    pub max_tool_iterations: usize,
283    /// Check for new Zeph releases at startup. Default: `true`.
284    #[serde(default = "default_auto_update_check")]
285    pub auto_update_check: bool,
286    /// Additional instruction files to always load, regardless of provider.
287    #[serde(default)]
288    pub instruction_files: Vec<std::path::PathBuf>,
289    /// When true, automatically detect provider-specific instruction files
290    /// (e.g. `CLAUDE.md` for Claude, `AGENTS.md` for `OpenAI`).
291    #[serde(default = "default_instruction_auto_detect")]
292    pub instruction_auto_detect: bool,
293    /// Maximum retry attempts for transient tool errors (0 to disable).
294    #[serde(default = "default_max_tool_retries")]
295    pub max_tool_retries: usize,
296    /// Number of identical tool+args calls within the recent window to trigger repeat-detection
297    /// abort (0 to disable).
298    #[serde(default = "default_tool_repeat_threshold")]
299    pub tool_repeat_threshold: usize,
300    /// Maximum total wall-clock time (seconds) to spend on retries for a single tool call.
301    #[serde(default = "default_max_retry_duration_secs")]
302    pub max_retry_duration_secs: u64,
303    /// Focus-based active context compression configuration (#1850).
304    #[serde(default)]
305    pub focus: FocusConfig,
306    /// Dynamic tool schema filtering configuration (#2020).
307    #[serde(default)]
308    pub tool_filter: ToolFilterConfig,
309    /// Inject a `<budget>` XML block into the volatile system prompt section so the LLM
310    /// can self-regulate tool calls and cost. Self-suppresses when no budget data is
311    /// available (#2267).
312    #[serde(default = "default_budget_hint_enabled")]
313    pub budget_hint_enabled: bool,
314    /// Background task supervisor tuning. Controls concurrency limits and turn-boundary abort.
315    #[serde(default)]
316    pub supervisor: TaskSupervisorConfig,
317}
318
319fn default_budget_hint_enabled() -> bool {
320    true
321}
322
323fn default_goal_max_text_chars() -> usize {
324    2000
325}
326
327fn default_goal_max_history() -> usize {
328    50
329}
330
331fn default_autonomous_max_turns() -> u32 {
332    20
333}
334
335fn default_verify_interval() -> u32 {
336    5
337}
338
339fn default_supervisor_timeout_secs() -> u64 {
340    30
341}
342
343fn default_max_stuck_count() -> u32 {
344    3
345}
346
347fn default_autonomous_turn_delay_ms() -> u64 {
348    500
349}
350
351fn default_autonomous_turn_timeout_secs() -> u64 {
352    300
353}
354
355fn default_max_supervisor_fail_count() -> u32 {
356    3
357}
358
359/// Long-horizon goal lifecycle configuration (`[goals]` TOML section).
360///
361/// When enabled, the agent tracks a single active goal across turns, injecting an
362/// `<active_goal>` block into the volatile system-prompt region and accounting for
363/// token consumption per turn.
364///
365/// Set `autonomous_enabled = true` to allow the agent to run multi-turn goal execution
366/// without waiting for user input between turns. A supervisor LLM call periodically checks
367/// whether the goal condition has been satisfied.
368///
369/// # Example (TOML)
370///
371/// ```toml
372/// [goals]
373/// enabled = true
374/// autonomous_enabled = true
375/// autonomous_max_turns = 20
376/// supervisor_provider = "fast"
377/// verify_interval = 5
378/// supervisor_timeout_secs = 30
379/// max_stuck_count = 3
380/// autonomous_turn_delay_ms = 500
381/// default_token_budget = 50000
382/// ```
383#[derive(Debug, Clone, Deserialize, Serialize)]
384#[serde(default)]
385pub struct GoalConfig {
386    /// Enable the goal lifecycle subsystem. Default: `false`.
387    pub enabled: bool,
388    /// Inject `<active_goal>` block into the volatile system-prompt region. Default: `true`.
389    pub inject_into_system_prompt: bool,
390    /// Maximum characters allowed for goal text at creation time. Default: `2000`.
391    #[serde(default = "default_goal_max_text_chars")]
392    pub max_text_chars: usize,
393    /// Default token budget for new goals (`None` = unlimited). Default: `None`.
394    pub default_token_budget: Option<u64>,
395    /// Maximum number of goals to return in `/goal list`. Default: `50`.
396    #[serde(default = "default_goal_max_history")]
397    pub max_history: usize,
398    /// Enable autonomous multi-turn execution mode (`/goal create ... --auto`). Default: `false`.
399    pub autonomous_enabled: bool,
400    /// Maximum number of turns the agent may run without user input per session. Default: `20`.
401    #[serde(default = "default_autonomous_max_turns")]
402    pub autonomous_max_turns: u32,
403    /// Provider name for the supervisor verifier LLM call (references `[[llm.providers]] name`).
404    /// Falls back to the main provider when `None`.
405    pub supervisor_provider: Option<ProviderName>,
406    /// How many turns to execute between supervisor verification checks. Default: `5`.
407    #[serde(default = "default_verify_interval")]
408    pub verify_interval: u32,
409    /// Timeout in seconds for a single supervisor verification LLM call. Default: `30`.
410    #[serde(default = "default_supervisor_timeout_secs")]
411    pub supervisor_timeout_secs: u64,
412    /// Maximum consecutive stuck-turn detections before the session is aborted. Default: `3`.
413    #[serde(default = "default_max_stuck_count")]
414    pub max_stuck_count: u32,
415    /// Delay in milliseconds between autonomous turns to avoid busy-looping. Default: `500`.
416    #[serde(default = "default_autonomous_turn_delay_ms")]
417    pub autonomous_turn_delay_ms: u64,
418    /// Maximum wall-clock time in seconds for a single autonomous LLM turn before it is
419    /// cancelled and the session transitions to `Stuck`. Default: `300` (5 minutes).
420    #[serde(default = "default_autonomous_turn_timeout_secs")]
421    pub autonomous_turn_timeout_secs: u64,
422    /// Maximum consecutive supervisor verification failures before the session is paused.
423    /// Default: `3`.
424    #[serde(default = "default_max_supervisor_fail_count")]
425    pub max_supervisor_fail_count: u32,
426}
427
428impl Default for GoalConfig {
429    fn default() -> Self {
430        Self {
431            enabled: false,
432            inject_into_system_prompt: true,
433            max_text_chars: default_goal_max_text_chars(),
434            default_token_budget: None,
435            max_history: default_goal_max_history(),
436            autonomous_enabled: false,
437            autonomous_max_turns: default_autonomous_max_turns(),
438            supervisor_provider: None,
439            verify_interval: default_verify_interval(),
440            supervisor_timeout_secs: default_supervisor_timeout_secs(),
441            max_stuck_count: default_max_stuck_count(),
442            autonomous_turn_delay_ms: default_autonomous_turn_delay_ms(),
443            autonomous_turn_timeout_secs: default_autonomous_turn_timeout_secs(),
444            max_supervisor_fail_count: default_max_supervisor_fail_count(),
445        }
446    }
447}
448
449fn default_enrichment_limit() -> usize {
450    4
451}
452
453fn default_telemetry_limit() -> usize {
454    8
455}
456
457fn default_background_shell_limit() -> usize {
458    8
459}
460
461/// Background task supervisor configuration, nested under `[agent.supervisor]` in TOML.
462///
463/// Controls per-class concurrency limits and turn-boundary behaviour for the
464/// `BackgroundSupervisor` in `zeph-core`.
465/// All fields have sensible defaults that match the Phase 1 hardcoded values; only change
466/// these if you observe excessive background task drops under load.
467///
468/// # Example (TOML)
469///
470/// ```toml
471/// [agent.supervisor]
472/// enrichment_limit = 4
473/// telemetry_limit = 8
474/// abort_enrichment_on_turn = false
475/// ```
476#[derive(Debug, Clone, Deserialize, Serialize)]
477#[serde(default)]
478pub struct TaskSupervisorConfig {
479    /// Maximum concurrent enrichment tasks (summarization, graph/persona/trajectory extraction).
480    /// Default: `4`.
481    #[serde(default = "default_enrichment_limit")]
482    pub enrichment_limit: usize,
483    /// Maximum concurrent telemetry tasks (audit log writes, graph count sync).
484    /// Default: `8`.
485    #[serde(default = "default_telemetry_limit")]
486    pub telemetry_limit: usize,
487    /// Abort all inflight enrichment tasks at turn boundary to prevent backlog buildup.
488    /// Default: `false`.
489    #[serde(default)]
490    pub abort_enrichment_on_turn: bool,
491    /// Maximum concurrent background shell runs tracked by the supervisor.
492    ///
493    /// Should match `tools.shell.max_background_runs` so both layers agree on capacity.
494    /// Default: `8`.
495    #[serde(default = "default_background_shell_limit")]
496    pub background_shell_limit: usize,
497}
498
499impl Default for TaskSupervisorConfig {
500    fn default() -> Self {
501        Self {
502            enrichment_limit: default_enrichment_limit(),
503            telemetry_limit: default_telemetry_limit(),
504            abort_enrichment_on_turn: false,
505            background_shell_limit: default_background_shell_limit(),
506        }
507    }
508}
509
510/// Sub-agent pool configuration, nested under `[agents]` in TOML.
511///
512/// When `enabled = true`, the agent can spawn isolated sub-agent sessions from
513/// SKILL.md-based agent definitions. Sub-agents inherit the parent's provider pool
514/// unless overridden by `model` in their definition frontmatter.
515///
516/// # Example (TOML)
517///
518/// ```toml
519/// [agents]
520/// enabled = true
521/// max_concurrent = 3
522/// max_spawn_depth = 2
523/// ```
524#[derive(Debug, Clone, Deserialize, Serialize)]
525#[serde(default)]
526pub struct SubAgentConfig {
527    /// Enable the sub-agent subsystem. Default: `false`.
528    pub enabled: bool,
529    /// Maximum number of sub-agents that can run concurrently.
530    #[serde(default = "default_max_concurrent")]
531    pub max_concurrent: usize,
532    /// Additional directories to search for `.agent.md` definition files.
533    pub extra_dirs: Vec<PathBuf>,
534    /// User-level agents directory.
535    #[serde(default)]
536    pub user_agents_dir: Option<PathBuf>,
537    /// Default permission mode applied to sub-agents that do not specify one.
538    pub default_permission_mode: Option<PermissionMode>,
539    /// Global denylist applied to all sub-agents in addition to per-agent `tools.except`.
540    #[serde(default)]
541    pub default_disallowed_tools: Vec<String>,
542    /// Allow sub-agents to use `bypass_permissions` mode.
543    #[serde(default)]
544    pub allow_bypass_permissions: bool,
545    /// Default memory scope applied to sub-agents that do not set `memory` in their definition.
546    #[serde(default)]
547    pub default_memory_scope: Option<MemoryScope>,
548    /// Lifecycle hooks executed when any sub-agent starts or stops.
549    #[serde(default)]
550    pub hooks: SubAgentLifecycleHooks,
551    /// Directory where transcript JSONL files and meta sidecars are stored.
552    #[serde(default)]
553    pub transcript_dir: Option<PathBuf>,
554    /// Enable writing JSONL transcripts for sub-agent sessions.
555    #[serde(default = "default_transcript_enabled")]
556    pub transcript_enabled: bool,
557    /// Maximum number of `.jsonl` transcript files to keep.
558    #[serde(default = "default_transcript_max_files")]
559    pub transcript_max_files: usize,
560    /// Number of recent parent conversation turns to pass to spawned sub-agents.
561    /// Set to 0 to disable history propagation.
562    #[serde(default = "default_context_window_turns")]
563    pub context_window_turns: usize,
564    /// Maximum nesting depth for sub-agent spawns.
565    #[serde(default = "default_max_spawn_depth")]
566    pub max_spawn_depth: u32,
567    /// How parent context is injected into the sub-agent's task prompt.
568    #[serde(default)]
569    pub context_injection_mode: ContextInjectionMode,
570    /// Whether to sanitize parent conversation history before passing to a spawned sub-agent.
571    ///
572    /// Defaults to [`ParentContextPolicy::InheritSanitized`] which runs each text message part
573    /// through the IPI sanitizer, stripping prompt-injection payloads that may have entered the
574    /// parent history via tool results, web scrapes, or A2A messages.
575    #[serde(default)]
576    pub parent_context_policy: ParentContextPolicy,
577    /// Maximum number of parent messages to inject, independent of `context_window_turns`.
578    ///
579    /// Acts as a hard upper bound on context propagation volume to limit the blast radius
580    /// of poisoned histories.  When `max_parent_messages < context_window_turns * 2` this cap
581    /// wins and fewer messages are passed; otherwise `context_window_turns * 2` is the binding
582    /// limit.  The tighter of the two limits always applies.
583    #[serde(default = "default_max_parent_messages")]
584    pub max_parent_messages: usize,
585    /// Maximum character count for the `Summary` context injection mode.
586    ///
587    /// When `context_injection_mode = "summary"`, the extracted summary is truncated
588    /// to this many characters at a UTF-8 char boundary before being prepended to the
589    /// sub-agent's task prompt.  Consistent with the `max_state_chars` naming convention.
590    ///
591    /// Default: `600` (≈200 tokens at 3 chars/token).
592    #[serde(default = "default_summary_max_chars")]
593    pub summary_max_chars: usize,
594    /// Maximum wall time in seconds for a single LLM call inside a sub-agent turn.
595    ///
596    /// If the provider does not return a response within this window, the call is
597    /// cancelled and the sub-agent turn fails with a timeout error. Default: 120.
598    #[serde(default = "default_llm_timeout_secs")]
599    pub llm_timeout_secs: u64,
600    /// Worktree isolation settings propagated from the top-level `[worktree]` section.
601    ///
602    /// Passed to the subagent manager's spawn function so it can determine whether
603    /// and how to create a per-agent git worktree without needing a reference to
604    /// the full `Config`.
605    ///
606    /// # Invariant
607    ///
608    /// This field is always populated from `Config::worktree` in `runner.rs` bootstrap.
609    /// Do not set defaults independently — changes here will not take effect in production
610    /// because the bootstrap overwrites this value before passing it to `SubAgentManager`.
611    #[serde(default)]
612    pub worktree: crate::worktree::WorktreeConfig,
613}
614
615impl Default for SubAgentConfig {
616    fn default() -> Self {
617        Self {
618            enabled: false,
619            max_concurrent: default_max_concurrent(),
620            extra_dirs: Vec::new(),
621            user_agents_dir: None,
622            default_permission_mode: None,
623            default_disallowed_tools: Vec::new(),
624            allow_bypass_permissions: false,
625            default_memory_scope: None,
626            hooks: SubAgentLifecycleHooks::default(),
627            transcript_dir: None,
628            transcript_enabled: default_transcript_enabled(),
629            transcript_max_files: default_transcript_max_files(),
630            context_window_turns: default_context_window_turns(),
631            max_spawn_depth: default_max_spawn_depth(),
632            context_injection_mode: ContextInjectionMode::default(),
633            parent_context_policy: ParentContextPolicy::default(),
634            max_parent_messages: default_max_parent_messages(),
635            summary_max_chars: default_summary_max_chars(),
636            llm_timeout_secs: default_llm_timeout_secs(),
637            worktree: crate::worktree::WorktreeConfig::default(),
638        }
639    }
640}
641
642/// Config-level lifecycle hooks fired when any sub-agent starts or stops.
643#[derive(Debug, Clone, Default, Deserialize, Serialize)]
644#[serde(default)]
645pub struct SubAgentLifecycleHooks {
646    /// Hooks run after a sub-agent is spawned (fire-and-forget).
647    pub start: Vec<HookDef>,
648    /// Hooks run after a sub-agent finishes or is cancelled (fire-and-forget).
649    pub stop: Vec<HookDef>,
650}
651
652#[cfg(test)]
653mod tests {
654    use super::*;
655
656    #[test]
657    fn subagent_config_defaults() {
658        let cfg = SubAgentConfig::default();
659        assert_eq!(cfg.context_window_turns, 10);
660        assert_eq!(cfg.max_spawn_depth, 3);
661        assert_eq!(
662            cfg.context_injection_mode,
663            ContextInjectionMode::LastAssistantTurn
664        );
665        assert_eq!(
666            cfg.parent_context_policy,
667            ParentContextPolicy::InheritSanitized
668        );
669        assert_eq!(cfg.max_parent_messages, 20);
670    }
671
672    #[test]
673    fn subagent_config_deserialize_new_fields() {
674        let toml_str = r#"
675            enabled = true
676            context_window_turns = 5
677            max_spawn_depth = 2
678            context_injection_mode = "none"
679        "#;
680        let cfg: SubAgentConfig = toml::from_str(toml_str).unwrap();
681        assert_eq!(cfg.context_window_turns, 5);
682        assert_eq!(cfg.max_spawn_depth, 2);
683        assert_eq!(cfg.context_injection_mode, ContextInjectionMode::None);
684    }
685
686    #[test]
687    fn subagent_config_deserialize_parent_context_policy() {
688        let toml_str = r#"
689            parent_context_policy = "none"
690            max_parent_messages = 10
691        "#;
692        let cfg: SubAgentConfig = toml::from_str(toml_str).unwrap();
693        assert_eq!(cfg.parent_context_policy, ParentContextPolicy::None);
694        assert_eq!(cfg.max_parent_messages, 10);
695    }
696
697    #[test]
698    fn subagent_config_deserialize_parent_context_policy_inherit_sanitized() {
699        let toml_str = r#"
700            parent_context_policy = "inherit_sanitized"
701        "#;
702        let cfg: SubAgentConfig = toml::from_str(toml_str).unwrap();
703        assert_eq!(
704            cfg.parent_context_policy,
705            ParentContextPolicy::InheritSanitized
706        );
707    }
708
709    #[test]
710    fn model_spec_deserialize_inherit() {
711        let spec: ModelSpec = serde_json::from_str("\"inherit\"").unwrap();
712        assert_eq!(spec, ModelSpec::Inherit);
713    }
714
715    #[test]
716    fn model_spec_deserialize_named() {
717        let spec: ModelSpec = serde_json::from_str("\"fast\"").unwrap();
718        assert_eq!(spec, ModelSpec::Named("fast".to_owned()));
719    }
720
721    #[test]
722    fn model_spec_as_str() {
723        assert_eq!(ModelSpec::Inherit.as_str(), "inherit");
724        assert_eq!(ModelSpec::Named("x".to_owned()).as_str(), "x");
725    }
726
727    #[test]
728    fn focus_config_auto_consolidate_min_window_default_is_six() {
729        let cfg = FocusConfig::default();
730        assert_eq!(cfg.auto_consolidate_min_window, 6);
731    }
732
733    #[test]
734    fn focus_config_auto_consolidate_min_window_deserializes() {
735        let toml_str = "auto_consolidate_min_window = 10";
736        let cfg: FocusConfig = toml::from_str(toml_str).unwrap();
737        assert_eq!(cfg.auto_consolidate_min_window, 10);
738    }
739
740    #[test]
741    fn goal_config_new_field_defaults() {
742        let cfg = GoalConfig::default();
743        assert_eq!(cfg.autonomous_turn_timeout_secs, 300);
744        assert_eq!(cfg.max_supervisor_fail_count, 3);
745    }
746
747    #[test]
748    fn goal_config_new_fields_deserialize() {
749        let toml_str = r"
750            autonomous_turn_timeout_secs = 120
751            max_supervisor_fail_count = 5
752        ";
753        let cfg: GoalConfig = toml::from_str(toml_str).unwrap();
754        assert_eq!(cfg.autonomous_turn_timeout_secs, 120);
755        assert_eq!(cfg.max_supervisor_fail_count, 5);
756    }
757
758    #[test]
759    fn goal_config_omitted_new_fields_use_defaults() {
760        let toml_str = "enabled = true";
761        let cfg: GoalConfig = toml::from_str(toml_str).unwrap();
762        assert_eq!(cfg.autonomous_turn_timeout_secs, 300);
763        assert_eq!(cfg.max_supervisor_fail_count, 3);
764    }
765}