agent-file-tools 0.55.0

Agent File Tools — tree-sitter powered code analysis for AI agents
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
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

pub(crate) const DEFAULT_SEMANTIC_QUERY_TIMEOUT_MS: u64 = 3_000;
pub(crate) const MIN_SEMANTIC_QUERY_TIMEOUT_MS: u64 = 500;
pub(crate) const MAX_SEMANTIC_QUERY_TIMEOUT_MS: u64 = 15_000;
pub(crate) const DEFAULT_INSPECT_DIAGNOSTICS_TIMEOUT_MS: u64 = 120_000;
pub(crate) const MIN_INSPECT_DIAGNOSTICS_TIMEOUT_MS: u64 = 10_000;
pub(crate) const MAX_INSPECT_DIAGNOSTICS_TIMEOUT_MS: u64 = 600_000;

const fn default_semantic_query_timeout_ms() -> u64 {
    DEFAULT_SEMANTIC_QUERY_TIMEOUT_MS
}

const fn default_inspect_diagnostics_timeout_ms() -> u64 {
    DEFAULT_INSPECT_DIAGNOSTICS_TIMEOUT_MS
}

const fn default_bash_detach_on_user_message() -> bool {
    true
}

use crate::harness::Harness;

/// The durable index families that a standing root may maintain.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum IndexKind {
    Search,
    Semantic,
    Callgraph,
}

impl IndexKind {
    pub const ALL: [Self; 3] = [Self::Search, Self::Semantic, Self::Callgraph];

    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Search => "search",
            Self::Semantic => "semantic",
            Self::Callgraph => "callgraph",
        }
    }

    pub fn from_name(name: &str) -> Option<Self> {
        match name {
            "search" => Some(Self::Search),
            "semantic" => Some(Self::Semantic),
            "callgraph" => Some(Self::Callgraph),
            _ => None,
        }
    }
}

/// One user-configured root whose literal path spelling is its durable identity.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct IndexRootConfig {
    /// The unmodified Unicode spelling supplied in `index.roots[].path`.
    pub path: String,
    /// Normalized selected index families, in fixed [`IndexKind::ALL`] order.
    pub indexes: Vec<IndexKind>,
}

/// User-tier standing-index configuration.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct IndexConfig {
    pub roots: Vec<IndexRootConfig>,
}

/// Expand the supported `~` forms before validating that a configured root is
/// absolute. The literal string is retained separately for durable identity.
pub fn expand_index_root_path(
    path: &str,
    home: Option<&std::path::Path>,
) -> Result<PathBuf, String> {
    let expanded = if path == "~" {
        home.ok_or_else(|| {
            "index.roots path uses ~ but no home directory is available".to_string()
        })?
        .to_path_buf()
    } else if let Some(remainder) = path.strip_prefix("~/").or_else(|| path.strip_prefix("~\\")) {
        home.ok_or_else(|| {
            "index.roots path uses ~ but no home directory is available".to_string()
        })?
        .join(remainder)
    } else {
        PathBuf::from(path)
    };

    if !expanded.is_absolute() {
        return Err(format!(
            "index.roots path must be absolute after ~ expansion: {path:?}"
        ));
    }
    Ok(expanded)
}

/// Semantic backend selected by the currently resolved runtime configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SemanticBackend {
    Fastembed,
    #[serde(rename = "openai_compatible")]
    OpenAiCompatible,
    Ollama,
    Synapse,
}

impl SemanticBackend {
    pub const fn as_str(&self) -> &'static str {
        match self {
            Self::Fastembed => "fastembed",
            Self::OpenAiCompatible => "openai_compatible",
            Self::Ollama => "ollama",
            Self::Synapse => "synapse",
        }
    }

    pub fn from_name(name: &str) -> Option<Self> {
        match name {
            "fastembed" => Some(Self::Fastembed),
            "openai_compatible" => Some(Self::OpenAiCompatible),
            "ollama" => Some(Self::Ollama),
            "synapse" => Some(Self::Synapse),
            _ => None,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SemanticBackendConfig {
    pub backend: SemanticBackend,
    pub model: String,
    pub base_url: Option<String>,
    pub api_key_env: Option<String>,
    pub timeout_ms: u64,
    /// Deadline for one interactive query embedding request. Unlike `timeout_ms`,
    /// this budget never controls background index builds.
    #[serde(default = "default_semantic_query_timeout_ms")]
    pub query_timeout_ms: u64,
    pub max_batch_size: usize,
    /// Maximum number of project files to semantically index. Guards local
    /// fastembed memory (model + embeddings + batch buffers) on huge project
    /// roots; remote backends that embed server-side can raise it freely.
    pub max_files: usize,
    /// User-tier SubC connection file used only by the Synapse embedding backend.
    #[serde(skip)]
    pub subc_connection_file: Option<PathBuf>,
    /// Project-root and harness identity used to route Synapse management calls
    /// to the correct project and execution environment.
    #[serde(skip)]
    pub route_project_root: Option<PathBuf>,
    #[serde(skip)]
    pub route_harness: Option<String>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct UserServerDef {
    pub id: String,
    pub extensions: Vec<String>,
    pub binary: String,
    pub args: Vec<String>,
    pub root_markers: Vec<String>,
    pub env: HashMap<String, String>,
    pub initialization_options: Option<serde_json::Value>,
    pub disabled: bool,
}

impl Default for SemanticBackendConfig {
    fn default() -> Self {
        Self {
            backend: SemanticBackend::Fastembed,
            model: DEFAULT_SEMANTIC_MODEL.to_string(),
            base_url: None,
            api_key_env: None,
            // Keep the default below the plugin bridge timeout to avoid bridge-killed
            // semantic_search requests when callers do not set an explicit timeout.
            timeout_ms: 25_000,
            query_timeout_ms: DEFAULT_SEMANTIC_QUERY_TIMEOUT_MS,
            max_batch_size: 64,
            max_files: 20_000,
            subc_connection_file: None,
            route_project_root: None,
            route_harness: None,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct InspectConfig {
    pub enabled: bool,
    /// Deadline for the blocking LSP diagnostics phase of `aft_inspect`.
    #[serde(default = "default_inspect_diagnostics_timeout_ms")]
    pub diagnostics_timeout_ms: u64,
    pub duplicates: InspectDuplicatesConfig,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct InspectDuplicatesConfig {
    pub expected_mirrors: Vec<[String; 2]>,
}

impl Default for InspectConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            diagnostics_timeout_ms: default_inspect_diagnostics_timeout_ms(),
            duplicates: InspectDuplicatesConfig::default(),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct BackupConfig {
    pub enabled: Option<bool>,
    pub max_depth: Option<usize>,
    pub max_file_size: Option<u64>,
}

impl Default for BackupConfig {
    fn default() -> Self {
        Self {
            enabled: Some(true),
            max_depth: Some(crate::backup::DEFAULT_MAX_UNDO_DEPTH),
            max_file_size: None,
        }
    }
}

/// `gh` routing shim operator hard-off.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct GhShimConfig {
    /// When false, the `gh` routing shim passes bytes through before any
    /// daemon or catalog probe, so a disabled shim produces no subc traffic.
    /// Default true. This is an operator hard-off for fleet rollout safety.
    pub enabled: bool,
    /// Optional deployed or development AFT image used by managed shim entries.
    /// The running executable is used when this user-tier field is absent.
    pub binary_path: Option<PathBuf>,
}

impl Default for GhShimConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            binary_path: None,
        }
    }
}

/// Operator opt-in for structured GitHub resource reads.
///
/// This gate is user-tier only because it changes the globally registered read
/// surface. Most users leave it disabled, so advertising issue and pull-request
/// spellings that can only return a refusal would waste prompt tokens and confuse
/// tool steering. Project-specific surfaces would also destabilize prompt-prefix
/// caches within one host.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct GhReadConfig {
    /// When false, `issue://` and `pr://` reads refuse before any cache, `gh`,
    /// or network activity. Default false keeps the in-flight feature opt-in.
    pub enabled: bool,
}

impl Default for GhReadConfig {
    fn default() -> Self {
        Self { enabled: false }
    }
}

/// Git behavior applied only to AFT-spawned agent children.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct GitConfig {
    /// `off` (default), `auto`, or one explicit `Name <email>` identity.
    pub co_author: String,
}

impl Default for GitConfig {
    fn default() -> Self {
        Self {
            co_author: "off".to_string(),
        }
    }
}

/// Normalize configuration values into `off`, `auto`, or `Name <email>`.
pub fn normalize_git_co_author(value: &str) -> Option<String> {
    let value = value.trim();
    if matches!(value, "off" | "auto") {
        return Some(value.to_string());
    }
    if value.contains(['\n', '\r']) || !value.ends_with('>') {
        return None;
    }
    let open = value.rfind('<')?;
    if open == 0 || !value.as_bytes()[open - 1].is_ascii_whitespace() {
        return None;
    }
    let name = value[..open].trim();
    let email = value[open + 1..value.len() - 1].trim();
    if name.is_empty()
        || name.contains(['<', '>'])
        || email.is_empty()
        || !email.contains('@')
        || email
            .chars()
            .any(|character| character.is_whitespace() || matches!(character, '<' | '>'))
    {
        return None;
    }
    Some(value.to_string())
}

/// Linked-worktree behavior that never writes shared on-disk artifacts.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct WorktreeConfig {
    /// When true, a borrow-only (linked worktree) root applies its own
    /// file-watcher events to the in-RAM trigram delta and invalidates the
    /// symbol cache so search reflects local edits. Default false. Semantic
    /// search and the callgraph stay frozen. Never persists to the shared
    /// `cache.bin`.
    pub ram_overlay: bool,
}

impl Default for WorktreeConfig {
    fn default() -> Self {
        Self { ram_overlay: false }
    }
}

pub const DEFAULT_SEMANTIC_MODEL: &str = "all-MiniLM-L6-v2";

impl Config {
    pub fn semantic_backend_label(&self) -> &'static str {
        self.semantic.backend.as_str()
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SandboxConfig {
    /// Route first-party bash commands through the native platform sandbox.
    pub enabled: bool,
    /// User-approved writable roots in addition to projects, task artifacts, and caches.
    pub write_allow: Vec<PathBuf>,
    /// Extra paths that native backends should deny reading.
    pub read_deny: Vec<PathBuf>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct BashConfig {
    /// Permit plugin-side break-glass execution when its AFT transport is unavailable.
    /// Rust accepts this for cross-language config parity but never acts on it.
    pub host_fallback: bool,
    /// Whether the hosting plugin detaches wait:true bash calls on user messages.
    /// Rust accepts this for cross-language config parity but never acts on it.
    #[serde(default = "default_bash_detach_on_user_message")]
    pub detach_on_user_message: bool,
    /// Pi-only fallback gate for its optional PowerShell default tool. The Rust
    /// executor accepts this solely to keep shared config parsing in parity.
    pub powershell_tool: bool,
}

impl Default for BashConfig {
    fn default() -> Self {
        Self {
            host_fallback: false,
            detach_on_user_message: default_bash_detach_on_user_message(),
            powershell_tool: false,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct Config {
    /// Root directory of the project being analyzed. `None` if not scoped.
    pub project_root: Option<PathBuf>,
    /// How many levels of call-graph edges to follow during validation (default: 1).
    pub validation_depth: u32,
    /// Hours before legacy backup-session maintenance may collect inactive history
    /// (default: 24). Named checkpoint retention is intentionally fixed at fourteen
    /// days and is not controlled by configuration.
    pub checkpoint_ttl_hours: u32,
    /// Maximum depth for recursive symbol resolution (default: 10).
    pub max_symbol_depth: u32,
    /// Seconds before killing a formatter subprocess (default: 10).
    pub formatter_timeout_secs: u32,
    /// Seconds before killing a type-checker subprocess (default: 30).
    pub type_checker_timeout_secs: u32,
    /// Whether to auto-format files after edits (default: false).
    pub format_on_edit: bool,
    /// Whether the hashline edit/read surface is enabled for eligible sessions.
    /// Resolved from the public `edit_mode` enum in aft.jsonc.
    pub hashline_enabled: bool,
    /// Whether to auto-validate files after edits (default: false).
    /// When "syntax", only tree-sitter parse check. When "full", runs type checker.
    pub validate_on_edit: Option<String>,
    /// Per-language formatter overrides. Keys: "typescript", "python", "rust", "go".
    /// Values: "biome", "oxfmt", "prettier", "deno", "ruff", "black", "rustfmt", "goimports", "gofmt", "none".
    pub formatter: HashMap<String, String>,
    /// Per-language type checker overrides. Keys: "typescript", "python", "rust", "go".
    /// Values: "tsc", "tsgo", "biome", "pyright", "ruff", "cargo", "go", "staticcheck", "none".
    pub checker: HashMap<String, String>,
    /// Whether to restrict file operations to within `project_root` (default: false).
    /// When true, write-capable commands reject paths outside the project root.
    pub restrict_to_project_root: bool,
    /// Enable the trigram search index (default: false).
    pub search_index: bool,
    /// User-tier standing roots. Empty by default, so normal session indexing is unchanged.
    pub index: IndexConfig,
    /// Enable semantic search (default: false).
    pub semantic_search: bool,
    /// Whether the plugin registered the `aft_search` tool for this surface
    /// (default: false). Forwarded by the plugin's resolved registration
    /// predicate (semantic on + not minimal + not disabled). Used only to pick
    /// the grep-rewrite footer: when true the footer steers to `aft_search`,
    /// otherwise to the `grep` tool. Not a capability gate.
    pub aft_search_registered: bool,
    /// Enable the persisted callgraph store substrate (default: true).
    pub callgraph_store: bool,
    /// Number of files to parse in a single batch during callgraph store cold build (default: 100).
    /// Lower values reduce peak memory during cold build.
    /// Set to 0 to disable chunking and parse all files at once.
    pub callgraph_chunk_size: usize,
    /// Enable experimental bash command rewriting (default: false).
    pub experimental_bash_rewrite: bool,
    /// Enable experimental bash command compression (default: false).
    pub experimental_bash_compress: bool,
    /// Enable experimental bash background execution (default: false).
    pub experimental_bash_background: bool,
    /// Maximum number of background bash tasks allowed to run concurrently (default: 8).
    pub max_background_bash_tasks: usize,
    /// Emit reminders for long-running bash tasks (default: true).
    pub bash_long_running_reminder_enabled: bool,
    /// Milliseconds between long-running bash reminders (default: 10 minutes).
    pub bash_long_running_reminder_interval_ms: u64,
    /// Milliseconds to wait before a foreground bash task is promoted to background handling.
    #[serde(skip, default = "default_foreground_wait_window_ms")]
    pub foreground_wait_window_ms: u64,
    /// Plugin-owned bash settings accepted by configure but inert in the engine.
    pub bash: BashConfig,
    /// Enable OpenCode-style bash permission prompts (default: false).
    pub bash_permissions: bool,
    /// Native sandbox policy for first-party bash and PTY processes.
    pub sandbox: SandboxConfig,
    /// Maximum file size to fully index in bytes (default: 1MB).
    pub search_index_max_file_size: u64,
    pub semantic: SemanticBackendConfig,
    pub inspect: InspectConfig,
    pub backup: BackupConfig,
    /// Linked-worktree RAM overlay. Default off; see [`WorktreeConfig`].
    pub worktree: WorktreeConfig,
    /// `gh` routing shim operator gate. Default on; see [`GhShimConfig`].
    pub gh_shim: GhShimConfig,
    /// Structured GitHub resource read gate. Default off; see [`GhReadConfig`].
    pub gh_read: GhReadConfig,
    /// Git attribution for AFT-spawned agent children. Default off.
    pub git: GitConfig,
    /// Enable Astral ty as an experimental Python LSP server (default: false).
    pub experimental_lsp_ty: bool,
    /// User-defined LSP servers registered by the OpenCode plugin.
    pub lsp_servers: Vec<UserServerDef>,
    /// Lowercase LSP server IDs disabled by user config.
    pub disabled_lsp: HashSet<String>,
    /// Whether the system should request inline diagnostics after a tool call edits or writes a file.
    #[serde(skip)]
    pub diagnostics_on_edit: bool,
    /// Extra directories to search when resolving LSP binaries.
    /// The plugin populates these from its own auto-install cache (e.g.
    /// `~/.cache/aft/lsp-packages/<pkg>/node_modules/.bin/`) so an LSP binary
    /// installed by AFT is discoverable without needing it on PATH.
    /// Resolution order: `<project_root>/node_modules/.bin/<bin>` →
    /// `lsp_paths_extra/<bin>` (in order) → PATH via `which`. Python-family
    /// servers additionally probe the selected workspace's `.venv`/`venv` first.
    pub lsp_paths_extra: Vec<PathBuf>,
    /// Binary names the hosting plugin knows how to auto-install.
    ///
    /// Built-in LSPs discovered from files only emit missing-binary warnings
    /// when their binary is in this set. User-configured `lsp_servers` keep
    /// warning unconditionally.
    pub lsp_auto_install_binaries: HashSet<String>,
    /// Binary names with plugin-managed auto-installs currently in flight.
    ///
    /// Missing-binary warnings are suppressed while the install is actively
    /// running; install failure reporting is handled by the plugin after the
    /// background work settles.
    pub lsp_inflight_installs: HashSet<String>,
    /// Persistent storage directory for indexes (trigram, semantic).
    /// Set by the plugin to the XDG-compliant path (e.g. ~/.local/share/opencode/storage/plugin/aft/).
    /// Falls back to ~/.cache/aft/ if not set.
    pub storage_dir: Option<PathBuf>,
    /// Allow URL-fetch commands to access private network hosts.
    /// Default false; hosting plugins only forward this from user-level config.
    pub url_fetch_allow_private: bool,
    /// Resolved host-tool registration preference. The Rust core retains this
    /// value for cross-harness config parity; the hosting plugin owns registration.
    pub hoist_builtin_tools: bool,
    /// Hosting harness identity supplied by configure.
    #[serde(default)]
    pub harness: Option<Harness>,
    /// Maximum number of (server, file) entries kept in the in-memory
    /// diagnostic cache. Older entries are evicted in LRU order when the
    /// cap is exceeded. Set to 0 to disable the cap entirely.
    /// Default: 5000 (covers very large monorepos with bounded memory).
    pub diagnostic_cache_size: usize,
}

impl Default for Config {
    fn default() -> Self {
        Config {
            project_root: None,
            validation_depth: 1,
            checkpoint_ttl_hours: 24,
            max_symbol_depth: 10,
            formatter_timeout_secs: 10,
            type_checker_timeout_secs: 30,
            // Default OFF: formatting after an edit can silently reflow the file
            // under the agent (a formatter splitting/joining lines), staling the
            // context for the next edit/patch. Agents that want formatting opt in
            // via `format_on_edit: true`.
            format_on_edit: false,
            hashline_enabled: false,
            validate_on_edit: None,
            formatter: HashMap::new(),
            checker: HashMap::new(),
            // Default to false to match OpenCode's existing permission-based model.
            // The plugin opts into root restriction explicitly when desired.
            restrict_to_project_root: false,
            search_index: false,
            index: IndexConfig::default(),
            semantic_search: false,
            aft_search_registered: false,
            callgraph_store: true,
            callgraph_chunk_size: 100,
            experimental_bash_rewrite: false,
            experimental_bash_compress: false,
            experimental_bash_background: false,
            max_background_bash_tasks: 8,
            bash_long_running_reminder_enabled: true,
            bash_long_running_reminder_interval_ms: 600_000,
            foreground_wait_window_ms: default_foreground_wait_window_ms(),
            bash: BashConfig::default(),
            bash_permissions: false,
            sandbox: SandboxConfig::default(),
            search_index_max_file_size: 1_048_576,
            semantic: SemanticBackendConfig::default(),
            inspect: InspectConfig::default(),
            backup: BackupConfig::default(),
            worktree: WorktreeConfig::default(),
            gh_shim: GhShimConfig::default(),
            gh_read: GhReadConfig::default(),
            git: GitConfig::default(),
            experimental_lsp_ty: false,
            lsp_servers: Vec::new(),
            disabled_lsp: HashSet::new(),
            diagnostics_on_edit: false,
            lsp_paths_extra: Vec::new(),
            lsp_auto_install_binaries: HashSet::new(),
            lsp_inflight_installs: HashSet::new(),
            storage_dir: None,
            url_fetch_allow_private: false,
            hoist_builtin_tools: true,
            harness: None,
            diagnostic_cache_size: 5000,
        }
    }
}

fn default_foreground_wait_window_ms() -> u64 {
    15_000
}

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

    #[test]
    fn index_root_path_expands_tilde_before_absolute_validation() {
        let home = std::env::temp_dir().join("aft-home");
        assert_eq!(
            expand_index_root_path("~/workspace", Some(&home)).unwrap(),
            home.join("workspace")
        );
        assert!(expand_index_root_path("relative/root", Some(&home)).is_err());
        assert!(expand_index_root_path("~", None).is_err());
    }
}