agentic-config 0.5.0

Unified configuration system for agentic tools ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
//! Configuration types for the agentic tools ecosystem.
//!
//! The root type is [`AgenticConfig`], which contains namespaced sub-configs
//! for different concerns: subagents, reasoning, services, orchestrator,
//! web retrieval, CLI tools, and logging.

use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;

/// Root configuration for all agentic tools.
///
/// This is the unified configuration that gets loaded from `agentic.toml` files.
/// All fields use `#[serde(default)]` so partial configs work correctly.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct AgenticConfig {
    /// Optional JSON Schema URL for IDE autocomplete support.
    /// In TOML: `"$schema" = "file://./agentic.schema.json"`
    #[serde(rename = "$schema", skip_serializing_if = "Option::is_none")]
    pub schema: Option<String>,

    /// Tool-specific config for coding-agent-tools subagents.
    pub subagents: SubagentsConfig,

    /// Tool-specific config for gpt5-reasoner.
    pub reasoning: ReasoningConfig,

    /// External service configurations (Anthropic, Exa).
    pub services: ServicesConfig,

    /// Review tools configuration.
    pub review: ReviewConfig,

    /// Thoughts tool configuration.
    pub thoughts: ThoughtsConfig,

    /// Orchestrator session and timing configuration.
    pub orchestrator: OrchestratorConfig,

    /// Web retrieval tool configuration.
    pub web_retrieval: WebRetrievalConfig,

    /// CLI tools (grep, glob, ls) configuration.
    pub cli_tools: CliToolsConfig,

    /// Logging and diagnostics configuration.
    pub logging: LoggingConfig,
}

//
// ─────────────────────────────────────────────────────────────────────────────
// SUBAGENTS CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for coding-agent-tools subagents (`ask_agent` tool).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct SubagentsConfig {
    // TODO(3): Model name handling could be more type-safe:
    // - Consider documenting supported models in code (enum or const list)
    // - Standardize approach between anthropic-async, claudecode_rs, and consumers
    // - Current string-based approach works but lacks IDE completion and validation
    /// Model for Locator subagent (fast discovery). Uses Claude CLI format.
    pub locator_model: String,
    /// Model for Analyzer subagent (deep analysis). Uses Claude CLI format.
    pub analyzer_model: String,
    /// Wall-clock timeout for `ask_agent` runtime in seconds. `0` disables the timeout.
    pub runtime_timeout_secs: u64,
}

impl Default for SubagentsConfig {
    fn default() -> Self {
        Self {
            locator_model: "claude-haiku-4-5".into(),
            analyzer_model: "claude-sonnet-4-6".into(),
            runtime_timeout_secs: 3600,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// REASONING CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Schema-only enum for `reasoning_effort` IDE autocomplete.
/// Runtime storage remains Option<String> for advisory validation semantics.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
enum ReasoningEffortLevel {
    Low,
    Medium,
    High,
    Xhigh,
}

// Note on external type dependencies: We investigated using model types from the
// async-openai crate but found they use plain `String` for most model fields (chat
// completions, embeddings, assistants, fine-tuning, audio transcription). Only image
// generation (ImageModel) and TTS (SpeechModel) have typed enums, and those include
// `Other(String)` escape hatches with #[serde(untagged)]. Their Model struct (for
// listing available models) also uses `id: String`. Copying their types would not
// improve our type safety since they face the same constraints we do and chose the
// same approach. See research/pr127-group7-type-safety-external-type-dependencies.md.

/// Configuration for gpt5-reasoner tool.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ReasoningConfig {
    /// `OpenRouter` model ID for optimizer step.
    pub optimizer_model: String,
    /// `OpenRouter` model ID for executor/reasoner step.
    pub executor_model: String,
    /// Optional reasoning effort level: low, medium, high, xhigh.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[schemars(with = "Option<ReasoningEffortLevel>")]
    pub reasoning_effort: Option<String>,
    /// Optional API base URL override for reasoning service.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub api_base_url: Option<String>,
    /// Max tokens allowed in the final input prompt after file injection.
    /// If None, `gpt5_reasoner` enforces its internal default (`250_000`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_input_tokens: Option<u32>,
    /// Upper bound for generated completion tokens (visible + reasoning).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_completion_tokens: Option<u32>,
    /// Executor timeout in seconds.
    pub executor_timeout_secs: u64,
    /// Suppress empty-response retry when attempt duration exceeds this threshold.
    pub empty_response_no_retry_after_secs: u64,
    /// Heartbeat cadence for executor streaming logs.
    pub stream_heartbeat_secs: u64,
}

impl Default for ReasoningConfig {
    fn default() -> Self {
        Self {
            optimizer_model: "anthropic/claude-sonnet-4.6".into(),
            executor_model: "openai/gpt-5.2".into(),
            reasoning_effort: None,
            api_base_url: None,
            max_input_tokens: None,
            max_completion_tokens: Some(128_000),
            executor_timeout_secs: 2700,
            empty_response_no_retry_after_secs: 600,
            stream_heartbeat_secs: 30,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// ORCHESTRATOR CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for opencode-orchestrator-mcp.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct OrchestratorConfig {
    /// Maximum session duration in seconds (default: 3600 = 1 hour).
    pub session_deadline_secs: u64,
    /// Inactivity timeout in seconds before session ends (default: 300 = 5 minutes).
    pub inactivity_timeout_secs: u64,
    /// Context compaction threshold as fraction 0.0-1.0 (default: 0.80).
    pub compaction_threshold: f64,
    /// Command filtering policy for orchestrator-exposed `OpenCode` commands.
    pub commands: OrchestratorCommandsConfig,
}

/// Command filtering policy for orchestrator-exposed `OpenCode` commands.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct OrchestratorCommandsConfig {
    /// Exact case-sensitive command names to allow. Empty means no allowlist restriction.
    pub allow: Vec<String>,
    /// Exact case-sensitive command names to deny. Deny wins over allow.
    pub deny: Vec<String>,
}

impl Default for OrchestratorConfig {
    fn default() -> Self {
        Self {
            session_deadline_secs: 3600,
            inactivity_timeout_secs: 300,
            compaction_threshold: 0.80,
            commands: OrchestratorCommandsConfig::default(),
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// WEB RETRIEVAL CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for web-retrieval tools (`web_fetch`, `web_search`).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct WebRetrievalConfig {
    /// HTTP request timeout in seconds (default: 30).
    pub request_timeout_secs: u64,
    /// Default maximum bytes to fetch (default: 5MB).
    pub default_max_bytes: u64,
    /// Default number of search results (default: 8).
    pub default_search_results: u32,
    /// Maximum number of search results allowed (default: 20).
    pub max_search_results: u32,
    /// Summarizer configuration for Haiku-based summarization.
    pub summarizer: WebSummarizerConfig,
}

impl Default for WebRetrievalConfig {
    fn default() -> Self {
        Self {
            request_timeout_secs: 30,
            default_max_bytes: 5 * 1024 * 1024, // 5MB
            default_search_results: 8,
            max_search_results: 20,
            summarizer: WebSummarizerConfig::default(),
        }
    }
}

/// Configuration for the web summarizer (Haiku).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct WebSummarizerConfig {
    /// Model to use for summarization (default: claude-haiku-4-5).
    pub model: String,
    /// Maximum tokens for summary output (default: 300).
    pub max_tokens: u32,
    /// Temperature for summary generation (default: 0.2).
    pub temperature: f64,
}

impl Default for WebSummarizerConfig {
    fn default() -> Self {
        Self {
            model: "claude-haiku-4-5".into(),
            max_tokens: 300,
            temperature: 0.2,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// CLI TOOLS CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for CLI tools (grep, glob, ls).
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct CliToolsConfig {
    /// Default page size for ls results (default: 100).
    pub ls_page_size: u32,
    /// Default `head_limit` for grep results (default: 200).
    pub grep_default_limit: u32,
    /// Default `head_limit` for glob results (default: 500).
    pub glob_default_limit: u32,
    /// Maximum directory traversal depth (default: 10).
    pub max_depth: u32,
    /// Pagination cache TTL in seconds (default: 300 = 5 minutes).
    pub pagination_cache_ttl_secs: u64,
    /// Wall-clock timeout for `cli_just_execute` in seconds. `0` disables the timeout.
    pub just_execute_timeout_secs: u64,
    /// Wall-clock timeout for `cli_just_search` in seconds. `0` disables the timeout.
    pub just_search_timeout_secs: u64,
    /// Additional ignore patterns to append to builtin ignores.
    #[serde(default)]
    pub extra_ignore_patterns: Vec<String>,
}

impl Default for CliToolsConfig {
    fn default() -> Self {
        Self {
            ls_page_size: 100,
            grep_default_limit: 200,
            glob_default_limit: 500,
            max_depth: 10,
            pagination_cache_ttl_secs: 300,
            just_execute_timeout_secs: 1800,
            just_search_timeout_secs: 30,
            extra_ignore_patterns: vec![],
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// SERVICES CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// External service configurations.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ServicesConfig {
    /// Anthropic API configuration.
    pub anthropic: AnthropicServiceConfig,
    /// Exa search API configuration.
    pub exa: ExaServiceConfig,
    /// Linear API configuration.
    pub linear: LinearServiceConfig,
    /// GitHub API configuration.
    pub github: GitHubServiceConfig,
}

/// Anthropic API service configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct AnthropicServiceConfig {
    /// Base URL for the Anthropic API.
    pub base_url: String,
}

impl Default for AnthropicServiceConfig {
    fn default() -> Self {
        Self {
            base_url: "https://api.anthropic.com".into(),
        }
    }
}

/// Exa search API service configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ExaServiceConfig {
    /// Base URL for the Exa API.
    pub base_url: String,
}

impl Default for ExaServiceConfig {
    fn default() -> Self {
        Self {
            base_url: "https://api.exa.ai".into(),
        }
    }
}

/// Linear API service configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct LinearServiceConfig {
    /// Base URL for the Linear GraphQL API.
    pub base_url: String,
    /// Connection establishment timeout in seconds. `0` disables the timeout.
    pub connect_timeout_secs: u64,
    /// Per-request timeout in seconds. `0` disables the timeout.
    pub request_timeout_secs: u64,
}

impl Default for LinearServiceConfig {
    fn default() -> Self {
        Self {
            base_url: "https://api.linear.app/graphql".into(),
            connect_timeout_secs: 10,
            request_timeout_secs: 60,
        }
    }
}

/// GitHub API service configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct GitHubServiceConfig {
    /// Base URL for the GitHub API.
    pub base_url: String,
    /// Total timeout for multi-request operations in seconds. `0` disables the timeout.
    pub total_timeout_secs: u64,
}

impl Default for GitHubServiceConfig {
    fn default() -> Self {
        Self {
            base_url: "https://api.github.com".into(),
            total_timeout_secs: 120,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// REVIEW CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for review tools.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ReviewConfig {
    /// Wall-clock timeout for `review_run` sessions in seconds. `0` disables the timeout.
    pub run_timeout_secs: u64,
}

impl Default for ReviewConfig {
    fn default() -> Self {
        Self {
            run_timeout_secs: 1800,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// THOUGHTS CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Configuration for thoughts MCP-adjacent operations.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ThoughtsConfig {
    /// Wall-clock timeout for `thoughts_add_reference` in seconds. `0` disables the timeout.
    pub add_reference_timeout_secs: u64,
}

impl Default for ThoughtsConfig {
    fn default() -> Self {
        Self {
            add_reference_timeout_secs: 600,
        }
    }
}

//
// ─────────────────────────────────────────────────────────────────────────────
// LOGGING CONFIG
// ─────────────────────────────────────────────────────────────────────────────
//

/// Logging and diagnostics configuration.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct LoggingConfig {
    /// Log level (trace, debug, info, warn, error).
    pub level: String,

    /// Whether to enable JSON-formatted logs.
    pub json: bool,
}

impl Default for LoggingConfig {
    fn default() -> Self {
        Self {
            level: "info".into(),
            json: false,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default_config_serializes() {
        let config = AgenticConfig::default();
        let toml_str = toml::to_string_pretty(&config).unwrap();
        assert!(toml_str.contains("[subagents]"));
        assert!(toml_str.contains("[reasoning]"));
        // Services sections serialize as [services.anthropic], [services.exa], etc.
        assert!(toml_str.contains("[services.anthropic]"));
        assert!(toml_str.contains("[services.exa]"));
        assert!(toml_str.contains("[services.linear]"));
        assert!(toml_str.contains("[services.github]"));
        assert!(toml_str.contains("[review]"));
        assert!(toml_str.contains("[thoughts]"));
        assert!(toml_str.contains("[orchestrator]"));
        assert!(toml_str.contains("[orchestrator.commands]"));
        assert!(toml_str.contains("[web_retrieval]"));
        assert!(toml_str.contains("[cli_tools]"));
        assert!(toml_str.contains("[logging]"));
        // Ensure old sections are NOT present
        assert!(!toml_str.contains("[models]"));
    }

    #[test]
    fn test_default_models_use_undated_names() {
        let subagents = SubagentsConfig::default();
        assert!(!subagents.locator_model.contains("20"));
        assert!(!subagents.analyzer_model.contains("20"));

        let reasoning = ReasoningConfig::default();
        assert!(!reasoning.optimizer_model.contains("20"));
        assert!(!reasoning.executor_model.contains("20"));
    }

    #[test]
    fn test_partial_config_deserializes() {
        let toml_str = r#"
[subagents]
locator_model = "custom-model"
"#;
        let config: AgenticConfig = toml::from_str(toml_str).unwrap();
        assert_eq!(config.subagents.locator_model, "custom-model");
        // Other fields get defaults
        assert_eq!(config.subagents.analyzer_model, "claude-sonnet-4-6");
        assert_eq!(config.subagents.runtime_timeout_secs, 3600);
        assert_eq!(
            config.services.anthropic.base_url,
            "https://api.anthropic.com"
        );
        assert_eq!(
            config.services.linear.base_url,
            "https://api.linear.app/graphql"
        );
        assert!(config.orchestrator.commands.allow.is_empty());
        assert!(config.orchestrator.commands.deny.is_empty());
    }

    #[test]
    fn test_orchestrator_commands_deserialize() {
        let toml_str = r#"
[orchestrator.commands]
allow = ["plan", "research"]
deny = ["commit"]
"#;

        let config: AgenticConfig = toml::from_str(toml_str).unwrap();

        assert_eq!(config.orchestrator.commands.allow, ["plan", "research"]);
        assert_eq!(config.orchestrator.commands.deny, ["commit"]);
    }

    #[test]
    fn test_schema_field_optional() {
        let toml_str = r#""$schema" = "file://./agentic.schema.json""#;
        let config: AgenticConfig = toml::from_str(toml_str).unwrap();
        assert_eq!(config.schema, Some("file://./agentic.schema.json".into()));
    }

    // Default value assertion tests - ensure defaults match current hardcoded behavior
    #[test]
    fn test_web_retrieval_defaults_match_hardcoded() {
        let cfg = WebRetrievalConfig::default();
        assert_eq!(cfg.request_timeout_secs, 30);
        assert_eq!(cfg.default_max_bytes, 5 * 1024 * 1024); // 5MB
        assert_eq!(cfg.default_search_results, 8);
        assert_eq!(cfg.max_search_results, 20);
        assert_eq!(cfg.summarizer.model, "claude-haiku-4-5");
        assert_eq!(cfg.summarizer.max_tokens, 300);
        assert!((cfg.summarizer.temperature - 0.2).abs() < f64::EPSILON);
    }

    #[test]
    fn test_cli_tools_defaults_match_hardcoded() {
        let cfg = CliToolsConfig::default();
        assert_eq!(cfg.ls_page_size, 100);
        assert_eq!(cfg.grep_default_limit, 200);
        assert_eq!(cfg.glob_default_limit, 500);
        assert_eq!(cfg.max_depth, 10);
        assert_eq!(cfg.pagination_cache_ttl_secs, 300);
        assert_eq!(cfg.just_execute_timeout_secs, 1800);
        assert_eq!(cfg.just_search_timeout_secs, 30);
        assert!(cfg.extra_ignore_patterns.is_empty());
    }

    #[test]
    fn test_orchestrator_defaults_match_hardcoded() {
        let cfg = OrchestratorConfig::default();
        assert_eq!(cfg.session_deadline_secs, 3600);
        assert_eq!(cfg.inactivity_timeout_secs, 300);
        assert!((cfg.compaction_threshold - 0.80).abs() < f64::EPSILON);
        assert!(cfg.commands.allow.is_empty());
        assert!(cfg.commands.deny.is_empty());
    }

    #[test]
    fn test_services_defaults_match_hardcoded() {
        let cfg = ServicesConfig::default();

        // Anthropic
        assert_eq!(cfg.anthropic.base_url, "https://api.anthropic.com");

        // Exa
        assert_eq!(cfg.exa.base_url, "https://api.exa.ai");

        // Linear
        assert_eq!(cfg.linear.base_url, "https://api.linear.app/graphql");
        assert_eq!(cfg.linear.connect_timeout_secs, 10);
        assert_eq!(cfg.linear.request_timeout_secs, 60);

        // GitHub
        assert_eq!(cfg.github.base_url, "https://api.github.com");
        assert_eq!(cfg.github.total_timeout_secs, 120);
    }

    #[test]
    fn test_new_timeout_defaults_match_plan() {
        let cfg = AgenticConfig::default();

        assert_eq!(cfg.subagents.runtime_timeout_secs, 3600);
        assert_eq!(cfg.review.run_timeout_secs, 1800);
        assert_eq!(cfg.thoughts.add_reference_timeout_secs, 600);
    }
}