aft/config.rs
1use std::path::PathBuf;
2
3/// Runtime configuration for the aft process.
4///
5/// Holds project-scoped settings and tuning knobs. Values are set at startup
6/// and remain immutable for the lifetime of the process.
7#[derive(Debug, Clone)]
8pub struct Config {
9 /// Root directory of the project being analyzed. `None` if not scoped.
10 pub project_root: Option<PathBuf>,
11 /// How many levels of call-graph edges to follow during validation (default: 1).
12 pub validation_depth: u32,
13 /// Hours before a checkpoint expires and is eligible for cleanup (default: 24).
14 pub checkpoint_ttl_hours: u32,
15 /// Maximum depth for recursive symbol resolution (default: 10).
16 pub max_symbol_depth: u32,
17 /// Seconds before killing a formatter subprocess (default: 10).
18 pub formatter_timeout_secs: u32,
19 /// Seconds before killing a type-checker subprocess (default: 30).
20 pub type_checker_timeout_secs: u32,
21 /// Whether to auto-format files after edits (default: true).
22 pub format_on_edit: bool,
23 /// Whether to auto-validate files after edits (default: false).
24 /// When "syntax", only tree-sitter parse check. When "full", runs type checker.
25 pub validate_on_edit: Option<String>,
26 /// Per-language formatter overrides. Keys: "typescript", "python", "rust", "go".
27 /// Values: "biome", "prettier", "deno", "ruff", "black", "rustfmt", "goimports", "gofmt", "none".
28 pub formatter: std::collections::HashMap<String, String>,
29 /// Per-language type checker overrides. Keys: "typescript", "python", "rust", "go".
30 /// Values: "tsc", "biome", "pyright", "ruff", "cargo", "go", "staticcheck", "none".
31 pub checker: std::collections::HashMap<String, String>,
32 /// Whether to restrict file operations to within `project_root` (default: false).
33 /// When true, write-capable commands reject paths outside the project root.
34 pub restrict_to_project_root: bool,
35 /// Enable the experimental trigram search index (default: false).
36 pub experimental_search_index: bool,
37 /// Enable the experimental semantic search index (default: false).
38 pub experimental_semantic_search: bool,
39 /// Maximum file size to fully index in bytes (default: 1MB).
40 pub search_index_max_file_size: u64,
41 /// Persistent storage directory for indexes (trigram, semantic).
42 /// Set by the plugin to the XDG-compliant path (e.g. ~/.local/share/opencode/storage/plugin/aft/).
43 /// Falls back to ~/.cache/aft/ if not set.
44 pub storage_dir: Option<PathBuf>,
45}
46
47impl Default for Config {
48 fn default() -> Self {
49 Config {
50 project_root: None,
51 validation_depth: 1,
52 checkpoint_ttl_hours: 24,
53 max_symbol_depth: 10,
54 formatter_timeout_secs: 10,
55 type_checker_timeout_secs: 30,
56 format_on_edit: true,
57 validate_on_edit: None,
58 formatter: std::collections::HashMap::new(),
59 checker: std::collections::HashMap::new(),
60 // Default to false to match OpenCode's existing permission-based model.
61 // The plugin opts into root restriction explicitly when desired.
62 restrict_to_project_root: false,
63 experimental_search_index: false,
64 experimental_semantic_search: false,
65 search_index_max_file_size: 1_048_576,
66 storage_dir: None,
67 }
68 }
69}