a3s_code_core/config/mod.rs
1//! Configuration module for A3S Code
2//!
3//! Provides configuration for:
4//! - LLM providers and models (defaultModel in "provider/model" format, providers)
5//! - Queue configuration (a3s-lane integration)
6//! - Search configuration (a3s-search integration)
7//! - Directories for dynamic skill and agent loading
8//!
9//! Configuration is loaded from ACL-compatible files or strings.
10//! Existing `.acl` config filenames are still accepted for compatibility.
11//! JSON support has been removed.
12
13mod acl_render;
14pub mod agent_dir;
15mod editor;
16mod loader;
17#[cfg(test)]
18mod loader_tests;
19mod provider;
20mod search;
21#[cfg(test)]
22mod tests;
23
24pub use agent_dir::{AgentDir, ScheduleSpec, ScriptToolLimits, ScriptToolSpec, ToolSpec};
25pub use editor::{rewrite_acl_sections, ConfigSection};
26pub use provider::{ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
27pub use search::{
28 BrowserBackend, DocumentCacheConfig, DocumentParserConfig, HeadlessConfig, SearchConfig,
29 SearchEngineConfig, SearchHealthConfig,
30};
31
32use crate::memory::MemoryConfig;
33use serde::{Deserialize, Serialize};
34use std::path::PathBuf;
35
36// ============================================================================
37// Storage Configuration
38// ============================================================================
39
40/// Session storage backend type
41#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
42#[serde(rename_all = "lowercase")]
43pub enum StorageBackend {
44 /// In-memory storage (no persistence)
45 Memory,
46 /// File-based storage (JSON files)
47 #[default]
48 File,
49 /// Custom external storage (Redis, PostgreSQL, etc.)
50 ///
51 /// Requires a `SessionStore` implementation registered on `AgentSession` options.
52 /// Use `storage_url` in config to pass connection details.
53 Custom,
54}
55
56// ============================================================================
57// Main Configuration
58// ============================================================================
59
60/// Automatic subagent delegation controls.
61#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
62#[serde(default, rename_all = "camelCase")]
63pub struct AutoDelegationConfig {
64 /// Enable runtime-driven automatic child agent delegation.
65 pub enabled: bool,
66 /// Allow automatic delegation to launch multiple child agents in parallel.
67 ///
68 /// Manual `task` fan-out and legacy `parallel_task` calls remain available
69 /// when this is false.
70 #[serde(alias = "auto_parallel")]
71 pub auto_parallel: bool,
72 /// Allow the model-visible `task` tool and hidden `parallel_task`
73 /// compatibility alias.
74 ///
75 /// Set this to false for cost control or debugging when child-agent tools
76 /// should be absent from the session tool surface. This is not a security
77 /// sandbox: the parent agent may still have other tools such as `bash`,
78 /// MCP tools, or skills.
79 #[serde(alias = "allow_manual_delegation")]
80 pub allow_manual_delegation: bool,
81 /// Minimum local confidence required to auto-delegate a child task.
82 pub min_confidence: f32,
83 /// Maximum number of automatic child tasks per user request.
84 pub max_tasks: usize,
85}
86
87impl Default for AutoDelegationConfig {
88 fn default() -> Self {
89 Self {
90 enabled: false,
91 auto_parallel: true,
92 allow_manual_delegation: true,
93 min_confidence: 0.72,
94 max_tasks: 4,
95 }
96 }
97}
98
99/// Optional platform endpoint used by hosts for account login.
100#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
101#[serde(rename_all = "camelCase")]
102pub struct OsConfig {
103 /// Base address of the configured platform instance.
104 #[serde(alias = "url", alias = "baseUrl", alias = "base_url")]
105 pub address: String,
106}
107
108/// Configuration for A3S Code
109#[derive(Debug, Clone, Serialize, Deserialize, Default)]
110#[serde(rename_all = "camelCase")]
111pub struct CodeConfig {
112 /// Default model in "provider/model" format (e.g., "anthropic/claude-sonnet-4-20250514")
113 #[serde(default, alias = "default_model")]
114 pub default_model: Option<String>,
115
116 /// Provider configurations
117 #[serde(default)]
118 pub providers: Vec<ProviderConfig>,
119
120 /// Session storage backend
121 #[serde(default)]
122 pub storage_backend: StorageBackend,
123
124 /// Sessions directory (for file backend)
125 #[serde(skip_serializing_if = "Option::is_none")]
126 pub sessions_dir: Option<PathBuf>,
127
128 /// Memory directory for the default file-backed memory store.
129 ///
130 /// If unset, sessions use `<workspace>/.a3s/memory` unless the host passes
131 /// an explicit memory store or file memory directory.
132 #[serde(default, alias = "memoryDir", skip_serializing_if = "Option::is_none")]
133 pub memory_dir: Option<PathBuf>,
134
135 /// Connection URL for custom storage backend (e.g., "redis://localhost:6379", "postgres://user:pass@localhost/a3s")
136 #[serde(default, skip_serializing_if = "Option::is_none")]
137 pub storage_url: Option<String>,
138
139 /// Directories to scan for skill files (*.md with tool definitions)
140 #[serde(default, alias = "skill_dirs")]
141 pub skill_dirs: Vec<PathBuf>,
142
143 /// Directories to scan for agent files (*.yaml or *.md)
144 #[serde(default, alias = "agent_dirs")]
145 pub agent_dirs: Vec<PathBuf>,
146
147 /// Directory containing personal instructions loaded before project files.
148 ///
149 /// When unset, instruction discovery checks `~/.a3s/AGENTS.override.md`
150 /// and then `~/.a3s/AGENTS.md`, using the first non-empty regular file.
151 #[serde(
152 default,
153 alias = "user_instructions_dir",
154 alias = "globalInstructionsDir",
155 alias = "global_instructions_dir",
156 skip_serializing_if = "Option::is_none"
157 )]
158 pub user_instructions_dir: Option<PathBuf>,
159
160 /// Maximum combined bytes loaded from personal and project instruction files.
161 ///
162 /// When unset, instruction discovery uses the Codex-compatible 32 KiB
163 /// default. A value of zero disables all automatic instruction loading.
164 #[serde(default, alias = "project_doc_max_bytes")]
165 pub project_doc_max_bytes: Option<usize>,
166
167 /// Ordered fallback filenames checked after `AGENTS.override.md` and
168 /// `AGENTS.md` in every directory from the project root to the workspace.
169 #[serde(default, alias = "project_doc_fallback_filenames")]
170 pub project_doc_fallback_filenames: Vec<String>,
171
172 /// Maximum tool execution rounds per turn (default: 25)
173 #[serde(default, alias = "max_tool_rounds")]
174 pub max_tool_rounds: Option<usize>,
175
176 /// Maximum sibling branches/tools to run concurrently in bounded parallel fan-out paths.
177 #[serde(default, alias = "max_parallel_tasks")]
178 pub max_parallel_tasks: Option<usize>,
179
180 /// Agent-wide priority and concurrency admission shared by all sessions.
181 #[serde(default, alias = "task_scheduler")]
182 pub task_scheduler: crate::task_scheduler::TaskSchedulerConfig,
183
184 /// Global automatic child-agent delegation settings.
185 #[serde(default, alias = "auto_delegation")]
186 pub auto_delegation: AutoDelegationConfig,
187
188 /// Convenience global kill switch for automatic parallel child-agent fan-out.
189 ///
190 /// When set, overrides `auto_delegation.auto_parallel`.
191 #[serde(default, alias = "auto_parallel")]
192 pub auto_parallel: Option<bool>,
193
194 /// Thinking/reasoning budget in tokens
195 #[serde(default, alias = "thinking_budget")]
196 pub thinking_budget: Option<usize>,
197
198 /// Per-model API HTTP timeout in milliseconds. Separate from tool execution
199 /// timeouts so provider/network deadlines do not constrain local tools.
200 #[serde(
201 default,
202 alias = "llm_api_timeout_ms",
203 alias = "api_timeout_ms",
204 alias = "model_api_timeout_ms"
205 )]
206 pub llm_api_timeout_ms: Option<u64>,
207
208 /// Memory system configuration
209 #[serde(default, skip_serializing_if = "Option::is_none")]
210 pub memory: Option<MemoryConfig>,
211
212 /// Queue configuration (a3s-lane integration)
213 #[serde(default, skip_serializing_if = "Option::is_none")]
214 pub queue: Option<crate::queue::SessionQueueConfig>,
215
216 /// Search configuration (a3s-search integration)
217 #[serde(default, skip_serializing_if = "Option::is_none")]
218 pub search: Option<SearchConfig>,
219
220 /// Optional platform endpoint. When set, hosts may enable account login.
221 #[serde(default, skip_serializing_if = "Option::is_none")]
222 pub os: Option<OsConfig>,
223
224 /// Built-in document context extraction configuration.
225 #[serde(default, skip_serializing_if = "Option::is_none")]
226 pub document_parser: Option<DocumentParserConfig>,
227
228 /// MCP server configurations
229 #[serde(default, alias = "mcp_servers")]
230 pub mcp_servers: Vec<crate::mcp::McpServerConfig>,
231}