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 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    // Always include Unix scratch paths — agents generate `/tmp` redirects
43    // even on Windows (Git Bash, WSL, cross-platform scripts).  (#1467)
44    for path in ["/tmp", "/private/tmp", "/var/tmp"] {
45        if !paths.iter().any(|existing| existing == path) {
46            paths.push(path.to_string());
47        }
48    }
49    paths
50}
51impl Default for Config {
52    fn default() -> Self {
53        Self {
54            ultra_compact: false,
55            tee_mode: TeeMode::default(),
56            recovery_hints: RecoveryHints::default(),
57            output_density: OutputDensity::default(),
58            checkpoint_interval: 15,
59            excluded_commands: Vec::new(),
60            passthrough_urls: Vec::new(),
61            custom_aliases: Vec::new(),
62            preserve_compact_formats: serde_defaults::default_preserve_compact_formats(),
63            crush_verbatim_json: false,
64            slow_command_threshold_ms: 5000,
65            theme: serde_defaults::default_theme(),
66            telemetry: TelemetryConfig::default(),
67            cloud: LegacyCloudConfig::default(),
68            hive: crate::core::config::hive::HiveConfig::default(),
69            cost: CostConfig::default(),
70            decision_loop: DecisionLoopConfig::default(),
71            protection: ProtectionConfig::default(),
72            code_health: CodeHealthConfig::default(),
73            autonomy: AutonomyConfig::default(),
74            providers: ProvidersConfig::default(),
75            knowledge_routing: KnowledgeRoutingConfig::default(),
76            proxy: ProxyConfig::default(),
77            conversation: ConversationConfig::default(),
78            response_shaping: ResponseShapingConfig::default(),
79            ocla: OclaConfig::default(),
80            intelligence_runtime: IntelligenceRuntimeConfig::default(),
81            shadow: ShadowConfig::default(),
82            value_display: ValueDisplayConfig::default(),
83            cache: CacheConfig::default(),
84            agents: AgentsConfig::default(),
85            proxy_enabled: None,
86            proxy_port: None,
87            proxy_timeout_ms: None,
88            proxy_require_token: false,
89            proxy_loopback_open: false,
90            proxy_bind_host: None,
91            proxy_allowed_hosts: Vec::new(),
92            proxy_max_rps: None,
93            dashboard_auth: true,
94            dashboard_cache_hit_rate: None,
95            buddy_enabled: serde_defaults::default_buddy_enabled(),
96            enable_wakeup_ctx: true,
97            redirect_exclude: Vec::new(),
98            disabled_tools: Vec::new(),
99            prefer_native_editor: false,
100            default_tool_categories: Vec::new(),
101            no_degrade: false,
102            delta_explicit: false,
103            profile: None,
104            config_profile: None,
105            profiles: std::collections::BTreeMap::new(),
106            tool_profile: None,
107            tools_enabled: Vec::new(),
108            persona: None,
109            loop_detection: LoopDetectionConfig::default(),
110            rules_scope: None,
111            rules_injection: None,
112            permission_inheritance: Some("on".to_string()),
113            extra_ignore_patterns: Vec::new(),
114            terse_agent: TerseAgent::default(),
115            compression_level: CompressionLevel::default(),
116            compression_aggressiveness: None,
117            archive: ArchiveConfig::default(),
118            memory: MemoryPolicy::default(),
119            allow_paths: Vec::new(),
120            allow_ide_config_dirs: None,
121            extra_roots: Vec::new(),
122            read_only_roots: Vec::new(),
123            allow_symlink_roots: Vec::new(),
124            content_defined_chunking: false,
125            minimal_overhead: true,
126            symbol_map_auto: false,
127            // Opt-in, as the field docs say. `true` here only ever applied to
128            // users without a config.toml; with one, `#[serde(default)]` read
129            // `false` (focus 2026-10-15) — now both agree.
130            structure_first: false,
131            progressive_disclosure: true,
132            progressive_threshold_lines: serde_defaults::default_progressive_threshold_lines(),
133            progressive_signatures_max: serde_defaults::default_progressive_signatures_max(),
134            auto_mode_learning: false,
135            team_share_content: true,
136            journal_enabled: false,
137            auto_capture: false,
138            search: crate::core::hybrid_search::HybridConfig::default(),
139            index: IndexConfig::default(),
140            skillify: SkillifyConfig::default(),
141            summaries: SummariesConfig::default(),
142            llm: LlmConfig::default(),
143            embedding: EmbeddingConfig::default(),
144            shell_hook_disabled: false,
145            shadow_mode: true,
146            shell_hook_mode: None,
147            prompt_reinject: None,
148            hook_mode: None,
149            tool_surface: None,
150            debug_log: false,
151            shell_activation: ShellActivation::default(),
152            skip_agent_aliases: false,
153            read_redirect: ReadRedirect::default(),
154            read_dedup: ReadDedup::default(),
155            shell_approval: ShellApproval::default(),
156            execute_allowed_languages: Vec::new(),
157            update_check_disabled: false,
158            updates: UpdatesConfig::default(),
159            context: ContextConfig::default(),
160            graph_index_max_files: serde_defaults::default_graph_index_max_files(),
161            bm25_max_files: serde_defaults::default_bm25_max_files(),
162            bm25_max_cache_mb: serde_defaults::default_bm25_max_cache_mb(),
163            memory_profile: MemoryProfile::default(),
164            memory_cleanup: MemoryCleanup::default(),
165            semantic_mode: SemanticMode::default(),
166            max_ram_percent: serde_defaults::default_max_ram_percent(),
167            mcp_max_rss_mb: serde_defaults::default_mcp_max_rss_mb(),
168            daemon_max_rss_mb: serde_defaults::default_daemon_max_rss_mb(),
169            mcp_idle_exit_minutes: 0,
170            max_disk_mb: 0,
171            max_staleness_days: 0,
172            session_retention_days: serde_defaults::default_session_retention_days(),
173            max_index_threads: 0,
174            savings_footer: SavingsFooter::default(),
175            compression_annotation: CompressionAnnotation::default(),
176            annotation_threshold_pct: serde_defaults::default_annotation_threshold_pct(),
177            behavior_nudges: serde_defaults::default_behavior_nudges(),
178            turn_fresh_limit: serde_defaults::default_turn_fresh_limit(),
179            turn_fresh_limit_verbatim: serde_defaults::default_turn_fresh_limit_verbatim(),
180            project_root: None,
181            lsp: std::collections::HashMap::new(),
182            ide_paths: HashMap::new(),
183            model_context_windows: HashMap::new(),
184            response_verbosity: ResponseVerbosity::default(),
185            active_kit: None,
186            bypass_hints: None,
187            cache_policy: None,
188            cache_max_tokens: 0,
189            boundary_policy: crate::core::memory_boundary::BoundaryPolicy::default(),
190            secret_detection: SecretDetectionConfig::default(),
191            sensitivity: crate::core::sensitivity::SensitivityConfig::default(),
192            context_gateway: crate::core::context_admission::ContextGatewayConfig::default(),
193            load_failure: None,
194            a2a_accept_untrusted_signers: false,
195            mcp_import_allow_unverified: false,
196            gateway: crate::core::mcp_catalog::GatewayConfig::default(),
197            gateway_server: GatewayServerConfig::default(),
198            enterprise: EnterpriseConfig::default(),
199            hook_binary: None,
200            path_jail: None,
201            path_jail_scope: None,
202            sandbox_level: 0,
203            reference_results: false,
204            agent_token_budget: 0,
205            shell_allowlist: default_shell_allowlist(),
206            shell_allowlist_extra: Vec::new(),
207            shell_strict_mode: false,
208            shell_allowlist_subcommand_scoping: true,
209            shell_security: None,
210            shell_timeout_secs: None,
211            shell_heavy_timeout_secs: None,
212            shell_heavy_prefixes: Vec::new(),
213            shell_allow_writes: false,
214            write_allow_paths: Vec::new(),
215            shell_allow_inline_scripts: false,
216            setup: SetupConfig::default(),
217            solution: super::solution::SolutionConfig::default(),
218            governor: super::governor::GovernorConfig::default(),
219            provenance: super::provenance::ProvenanceConfig::default(),
220            cross_agent: super::provenance::CrossAgentConfig::default(),
221        }
222    }
223}