Skip to main content

lean_ctx/core/config/
defaults.rs

1use std::collections::HashMap;
2
3#[allow(clippy::wildcard_imports)]
4use super::*;
5/// Default BM25 cache cap from config (also used by `bm25_index` heuristics).
6pub fn default_bm25_max_cache_mb() -> u64 {
7    serde_defaults::default_bm25_max_cache_mb()
8}
9
10/// Effective on-disk ceiling (MB) for the persisted BM25 index when nothing is
11/// explicitly configured (no `bm25_max_cache_mb`, no `max_disk_mb` budget).
12///
13/// Deliberately decoupled from the RAM `MemoryProfile` (64/128/512 MB): this is
14/// a *disk* file, and tying it to the profile silently refused persistence on
15/// large repos under Low/Balanced, forcing a cold rebuild on every call (the
16/// perpetual "index warming" of issue #249). 512 MB compressed covers
17/// essentially every real repo; RAM pressure is governed separately by the
18/// eviction orchestrator (which measures real heap).
19pub const DEFAULT_BM25_PERSIST_MB: u64 = 512;
20
21// Compile-time regression guard (#249): the default disk ceiling must stay well
22// above the old RAM-profile caps (64/128 MB) that starved large repos.
23const _: () = assert!(DEFAULT_BM25_PERSIST_MB >= 512);
24
25/// lean-ctx tools whose sole purpose is editing the user's source files. When
26/// `prefer_native_editor` is set (#454) these are hidden from `list_tools` and
27/// refused at dispatch so the host's native editor handles edits instead.
28///
29/// Deliberately narrow: only the dedicated edit tools are blocked — `ctx_edit`
30/// (str_replace) and `ctx_patch` (anchored, #1008). LSP refactor
31/// (`ctx_refactor`) also exposes read-only sub-actions (references/definition),
32/// so it is left available; users wanting it gone can add it to `disabled_tools`.
33pub const EDIT_TOOL_NAMES: &[&str] = &["ctx_edit", "ctx_patch"];
34
35/// Default locations for shell output capture.
36///
37/// `/private/tmp` is the canonical target behind macOS's `/tmp` symlink, while
38/// `temp_dir()` also covers per-user scratch directories such as `$TMPDIR`.
39pub(crate) fn default_shell_write_allow_paths() -> Vec<String> {
40    #[allow(unused_mut)]
41    let mut paths = vec![std::env::temp_dir().to_string_lossy().into_owned()];
42    #[cfg(unix)]
43    for path in ["/tmp", "/private/tmp", "/var/tmp"] {
44        if !paths.iter().any(|existing| existing == path) {
45            paths.push(path.to_string());
46        }
47    }
48    paths
49}
50impl Default for Config {
51    fn default() -> Self {
52        Self {
53            ultra_compact: false,
54            tee_mode: TeeMode::default(),
55            recovery_hints: RecoveryHints::default(),
56            output_density: OutputDensity::default(),
57            checkpoint_interval: 15,
58            excluded_commands: Vec::new(),
59            passthrough_urls: Vec::new(),
60            custom_aliases: Vec::new(),
61            preserve_compact_formats: serde_defaults::default_preserve_compact_formats(),
62            crush_verbatim_json: false,
63            slow_command_threshold_ms: 5000,
64            theme: serde_defaults::default_theme(),
65            cloud: CloudConfig::default(),
66            gain: GainConfig::default(),
67            cost: CostConfig::default(),
68            code_health: CodeHealthConfig::default(),
69            autonomy: AutonomyConfig::default(),
70            providers: ProvidersConfig::default(),
71            proxy: ProxyConfig::default(),
72            conversation: ConversationConfig::default(),
73            response_shaping: ResponseShapingConfig::default(),
74            proxy_enabled: None,
75            proxy_port: None,
76            proxy_timeout_ms: None,
77            proxy_require_token: false,
78            proxy_loopback_open: false,
79            proxy_bind_host: None,
80            proxy_allowed_hosts: Vec::new(),
81            proxy_max_rps: None,
82            dashboard_auth: true,
83            dashboard_cache_hit_rate: None,
84            buddy_enabled: serde_defaults::default_buddy_enabled(),
85            enable_wakeup_ctx: true,
86            redirect_exclude: Vec::new(),
87            disabled_tools: Vec::new(),
88            prefer_native_editor: false,
89            default_tool_categories: Vec::new(),
90            no_degrade: false,
91            delta_explicit: false,
92            profile: None,
93            config_profile: None,
94            profiles: std::collections::BTreeMap::new(),
95            tool_profile: None,
96            tools_enabled: Vec::new(),
97            persona: None,
98            loop_detection: LoopDetectionConfig::default(),
99            rules_scope: None,
100            rules_injection: None,
101            permission_inheritance: None,
102            extra_ignore_patterns: Vec::new(),
103            terse_agent: TerseAgent::default(),
104            compression_level: CompressionLevel::default(),
105            compression_aggressiveness: None,
106            archive: ArchiveConfig::default(),
107            memory: MemoryPolicy::default(),
108            allow_paths: Vec::new(),
109            allow_ide_config_dirs: None,
110            extra_roots: Vec::new(),
111            read_only_roots: Vec::new(),
112            allow_symlink_roots: Vec::new(),
113            content_defined_chunking: false,
114            minimal_overhead: true,
115            symbol_map_auto: false,
116            structure_first: true,
117            progressive_disclosure: true,
118            progressive_threshold_lines: serde_defaults::default_progressive_threshold_lines(),
119            progressive_signatures_max: serde_defaults::default_progressive_signatures_max(),
120            auto_mode_learning: false,
121            team_url: None,
122            team_token: None,
123            team_auto_push: false,
124            journal_enabled: true,
125            auto_capture: true,
126            search: crate::core::hybrid_search::HybridConfig::default(),
127            graph: GraphConfig::default(),
128            index: IndexConfig::default(),
129            skillify: SkillifyConfig::default(),
130            summaries: SummariesConfig::default(),
131            llm: crate::core::llm_enhance::LlmConfig::default(),
132            embedding: EmbeddingConfig::default(),
133            shell_hook_disabled: false,
134            shadow_mode: true,
135            hook_mode: None,
136            debug_log: false,
137            shell_activation: ShellActivation::default(),
138            skip_agent_aliases: false,
139            read_redirect: ReadRedirect::default(),
140            read_dedup: ReadDedup::default(),
141            update_check_disabled: false,
142            updates: UpdatesConfig::default(),
143            context: ContextConfig::default(),
144            graph_index_max_files: serde_defaults::default_graph_index_max_files(),
145            bm25_max_cache_mb: serde_defaults::default_bm25_max_cache_mb(),
146            memory_profile: MemoryProfile::default(),
147            memory_cleanup: MemoryCleanup::default(),
148            max_ram_percent: serde_defaults::default_max_ram_percent(),
149            max_disk_mb: 0,
150            max_staleness_days: 0,
151            max_index_threads: 0,
152            savings_footer: SavingsFooter::default(),
153            compression_annotation: CompressionAnnotation::default(),
154            annotation_threshold_pct: serde_defaults::default_annotation_threshold_pct(),
155            turn_fresh_limit: serde_defaults::default_turn_fresh_limit(),
156            session_token_limit: serde_defaults::default_session_token_limit(),
157            project_root: None,
158            lsp: std::collections::HashMap::new(),
159            ide_paths: HashMap::new(),
160            model_context_windows: HashMap::new(),
161            response_verbosity: ResponseVerbosity::default(),
162            bypass_hints: None,
163            cache_policy: None,
164            cache_max_tokens: 0,
165            boundary_policy: crate::core::memory_boundary::BoundaryPolicy::default(),
166            secret_detection: SecretDetectionConfig::default(),
167            sensitivity: crate::core::sensitivity::SensitivityConfig::default(),
168            gateway: crate::core::mcp_catalog::GatewayConfig::default(),
169            gateway_server: GatewayServerConfig::default(),
170            addons: crate::core::addons::AddonsConfig::default(),
171            allow_auto_reroot: false,
172            hook_binary: None,
173            path_jail: None,
174            sandbox_level: 0,
175            reference_results: false,
176            agent_token_budget: 0,
177            shell_allowlist: default_shell_allowlist(),
178            shell_allowlist_extra: Vec::new(),
179            shell_strict_mode: false,
180            shell_security: None,
181            shell_timeout_secs: None,
182            shell_heavy_timeout_secs: None,
183            shell_heavy_prefixes: Vec::new(),
184            shell_allow_writes: false,
185            write_allow_paths: Vec::new(),
186            shell_allow_inline_scripts: false,
187            setup: SetupConfig::default(),
188        }
189    }
190}