Skip to main content

lean_ctx/core/config/
model.rs

1use serde::{Deserialize, Serialize};
2
3#[allow(clippy::wildcard_imports)]
4use super::*;
5fn default_true() -> bool {
6    true
7}
8
9/// Global lean-ctx configuration loaded from `config.toml`, merged with project-local overrides.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(default)]
12pub struct Config {
13    pub ultra_compact: bool,
14    #[serde(default, deserialize_with = "serde_defaults::deserialize_tee_mode")]
15    pub tee_mode: TeeMode,
16    /// Verbosity of the reactive recovery footer on compressed output
17    /// (`off|minimal|full`, default `minimal`). See [`RecoveryHints`].
18    #[serde(default)]
19    pub recovery_hints: RecoveryHints,
20    #[serde(default)]
21    pub output_density: OutputDensity,
22    pub checkpoint_interval: u32,
23    pub excluded_commands: Vec<String>,
24    pub passthrough_urls: Vec<String>,
25    pub custom_aliases: Vec<AliasEntry>,
26    /// Output formats that are already compact/token-oriented and must be
27    /// preserved verbatim instead of being recompressed (#342). Matched against
28    /// the *output shape* (not the command name), so any tool emitting the
29    /// format is covered without enumerating commands in `excluded_commands`.
30    /// Default: `["toon"]`. Set to `[]` to disable and always recompress.
31    #[serde(default = "serde_defaults::default_preserve_compact_formats")]
32    pub preserve_compact_formats: Vec<String>,
33    /// Opt-in: apply the lossless JSON crusher to *verbatim* data commands
34    /// (`gh api`, `jq`, `kubectl get -o json`, `curl` JSON). Off by default, so
35    /// those outputs stay byte-for-byte verbatim. When on, an array-heavy JSON
36    /// payload the crusher can at least halve is reshaped into a compact, fully
37    /// reconstructible form; everything else stays verbatim. See
38    /// [`Config::crush_verbatim_json_enabled`] (#936).
39    #[serde(default)]
40    pub crush_verbatim_json: bool,
41    /// Commands taking longer than this threshold (ms) are recorded in the slow log.
42    /// Set to 0 to disable slow logging.
43    pub slow_command_threshold_ms: u64,
44    #[serde(default = "serde_defaults::default_theme")]
45    pub theme: String,
46    /// Privacy-safe default-on telemetry with explicit and environment opt-outs.
47    #[serde(default)]
48    pub telemetry: TelemetryConfig,
49    /// LeanCTX | Cloud connector (`[cloud]`; the 3.12 table `[cloud]` is read
50    /// as an alias, `core::config::renamed`).
51    #[serde(default)]
52    pub cloud: crate::core::config::cloud::CloudConfig,
53    /// Model declaration for measured-vs-estimated cost reporting (MCP-only IDEs).
54    #[serde(default)]
55    pub cost: CostConfig,
56    #[serde(default)]
57    pub decision_loop: DecisionLoopConfig,
58    /// User-controlled never-lossy zones (#1570 P4): protected file globs
59    /// and `<protect>` span handling.
60    #[serde(default)]
61    pub protection: ProtectionConfig,
62    /// Code-health engine: cognitive complexity, naming, coupling, edit-gate.
63    #[serde(default)]
64    pub code_health: CodeHealthConfig,
65    /// Decision layer: pre-edit check mode for `.leanctx/decisions`.
66    #[serde(default)]
67    pub decisions: DecisionsConfig,
68    #[serde(default)]
69    pub autonomy: AutonomyConfig,
70    #[serde(default)]
71    pub providers: ProvidersConfig,
72    #[serde(default)]
73    pub knowledge_routing: KnowledgeRoutingConfig,
74    #[serde(default)]
75    pub proxy: ProxyConfig,
76    /// Conversation-history compression (`[conversation]`, opt-in; #1123).
77    #[serde(default)]
78    pub conversation: ConversationConfig,
79    /// Proxy-layer response shaping (`[response_shaping]`, #1125).
80    #[serde(default)]
81    pub response_shaping: ResponseShapingConfig,
82    #[serde(default)]
83    pub ocla: OclaConfig,
84    /// Global-only, explicit consent and independent pins for optional local code.
85    #[serde(default)]
86    pub intelligence_runtime: IntelligenceRuntimeConfig,
87    /// Counterfactual Shadow Mode reporting (`[shadow]`), opt-in.
88    #[serde(default)]
89    pub shadow: ShadowConfig,
90    /// User-only value display (`[value_display]`): status line, recaps,
91    /// prompt segment, milestones. Never reaches the model context.
92    #[serde(default)]
93    pub value_display: ValueDisplayConfig,
94    /// Generalized L1/L2/L3 cache settings (`[cache]`).
95    #[serde(default)]
96    pub cache: CacheConfig,
97    #[serde(default)]
98    pub agents: sections::AgentsConfig,
99    /// Whether the API proxy is enabled. Tri-state:
100    /// - None: undecided (fresh install, will prompt on interactive setup)
101    /// - Some(true): user opted in, proxy managed by lean-ctx
102    /// - Some(false): user opted out, never touch proxy or endpoints
103    #[serde(default)]
104    pub proxy_enabled: Option<bool>,
105    #[serde(default)]
106    pub proxy_port: Option<u16>,
107    /// Proxy reachability timeout in milliseconds. Default: 200.
108    /// Override via LEAN_CTX_PROXY_TIMEOUT_MS env var.
109    #[serde(default)]
110    pub proxy_timeout_ms: Option<u64>,
111    /// Strict proxy auth: when true, authenticate ONLY via the Bearer token
112    /// (`LEAN_CTX_PROXY_TOKEN`) and disable the provider-API-key fallback. Default
113    /// false keeps the loopback-friendly behavior where any local AI tool's own
114    /// provider key authenticates (the proxy never injects upstream credentials —
115    /// it forwards the caller's key verbatim). Enable on shared/multi-user hosts to
116    /// require the token; clients must then send `Authorization: Bearer [REDACTED:Authorization header]
117    #[serde(default)]
118    pub proxy_require_token: bool,
119    /// Skip ALL proxy authentication on loopback-bound listeners (#755).
120    /// When true **and** the proxy binds a loopback address, every request is
121    /// accepted without a Bearer token or provider API key — MCP clients,
122    /// browser dashboards, and CLI tools all work without auth setup.
123    /// Ignored on non-loopback binds (gateway mode always requires auth).
124    /// Env override: `LEAN_CTX_PROXY_LOOPBACK_OPEN`.
125    #[serde(default)]
126    pub proxy_loopback_open: bool,
127    /// Bind address for the proxy listener (gateway mode, enterprise#8).
128    /// Default `None` = `127.0.0.1` — local-safe, nothing changes for existing
129    /// installs. Set `"0.0.0.0"` (or a specific interface IP) to serve a whole
130    /// org from one host; any non-loopback bind hard-disables the provider-key
131    /// auth fallback (Bearer token becomes mandatory) and enables the
132    /// `proxy_allowed_hosts` Host-header allowlist. Env override:
133    /// `LEAN_CTX_PROXY_BIND_HOST`. An unparseable value falls back to loopback,
134    /// never to an open bind.
135    #[serde(default)]
136    pub proxy_bind_host: Option<String>,
137    /// Host-header allowlist for a non-loopback proxy bind (gateway mode):
138    /// DNS-rebinding protection. Entries are hostnames or IPs without port
139    /// (e.g. `"gateway.example.com"`). Loopback names are always allowed.
140    /// Ignored (loopback-only guard, today's behavior) while the bind is
141    /// loopback. Empty + non-loopback bind = only loopback Host headers pass,
142    /// so configure this when exposing the gateway.
143    #[serde(default)]
144    pub proxy_allowed_hosts: Vec<String>,
145    /// Proxy-wide request rate limit in requests/second (token bucket, burst =
146    /// 2x). `None` (default) = unlimited on a loopback bind — today's behavior —
147    /// and 50 rps with burst 100 on a non-loopback bind (gateway mode ships a
148    /// sane floor, enterprise#37). `0` disables the limiter even in gateway
149    /// mode (explicit opt-out).
150    #[serde(default)]
151    pub proxy_max_rps: Option<u32>,
152    /// Require Bearer-token authentication for the dashboard. Default `true`:
153    /// the dashboard generates (or uses the pinned) token and rejects `/api/*`
154    /// and `/metrics` without it. Set to `false` to run the dashboard with **no
155    /// auth token** — useful for a local/Docker setup where managing a token is
156    /// inconvenient. No-auth mode is not unprotected: cross-origin and CSRF
157    /// attacks from a malicious local website are blocked by request-header
158    /// validation instead (`Sec-Fetch-Site`, `Origin`/`Host` same-origin, and a
159    /// `Host` allowlist against DNS rebinding — see `dashboard::no_auth_request_ok`).
160    /// Override per-run via the `--no-auth` / `--auth=<bool>` flag or the
161    /// `LEAN_CTX_DASHBOARD_AUTH` env var.
162    #[serde(default = "serde_defaults::default_true")]
163    pub dashboard_auth: bool,
164    /// Provider prompt-cache hit rate for net-of-injection calculation (#1104).
165    /// Share of turns whose prefix is served from the provider cache; an
166    /// estimate, default 0.75. Prices: `context_overhead::prefix_cost_factor`.
167    #[serde(default)]
168    pub dashboard_cache_hit_rate: Option<f64>,
169    #[serde(default = "serde_defaults::default_buddy_enabled")]
170    pub buddy_enabled: bool,
171    #[serde(default = "serde_defaults::default_true")]
172    pub enable_wakeup_ctx: bool,
173    /// File globs delivered verbatim: native reads skip the hook redirect and
174    /// automatic `ctx_read` modes return them in full (#60).
175    #[serde(default)]
176    pub redirect_exclude: Vec<String>,
177    /// Tools to exclude from the MCP tool list returned by list_tools.
178    /// Accepts exact tool names (e.g. `["ctx_graph", "ctx_agent"]`).
179    /// Empty by default — all tools listed, no behaviour change.
180    #[serde(default)]
181    pub disabled_tools: Vec<String>,
182    /// Prefer the host agent's native editor over lean-ctx edit operations (#454).
183    /// When true, the lean-ctx edit tool(s) (see [`EDIT_TOOL_NAMES`]) are neither
184    /// advertised in `list_tools` nor dispatchable (direct or via `ctx_call`), so
185    /// the agent falls back to the host's built-in editing UI. Reads / search /
186    /// shell / memory tools are unaffected. Override via
187    /// `LEAN_CTX_PREFER_NATIVE_EDITOR=1`.
188    #[serde(default)]
189    pub prefer_native_editor: bool,
190    /// Tool categories to activate by default for dynamic-tool-capable clients.
191    /// Values: "core" (always on), "arch", "debug", "memory", "metrics", "session".
192    /// Example: `default_tool_categories = ["core", "arch", "memory"]`
193    /// Override via LCTX_DEFAULT_CATEGORIES env var (comma-separated).
194    /// Empty = lean-ctx default (`core`). Add `session` explicitly to evaluate
195    /// experimental local collaboration tools.
196    #[serde(default)]
197    pub default_tool_categories: Vec<String>,
198    /// Disable all automatic read-mode degradation (auto_degrade + context_gate pressure).
199    /// When true, lean-ctx never downgrades requested read modes regardless of pressure.
200    /// Override via LCTX_NO_DEGRADE=1 env var.
201    #[serde(default)]
202    pub no_degrade: bool,
203    /// Legacy opt-in delta preference. Concrete per-call full/lines requests
204    /// take precedence and stay fresh; this cannot replace their content with
205    /// a delta. Use mode=auto or mode=diff for reduced re-reads.
206    /// Retained for configuration compatibility. LCTX_DELTA_EXPLICIT=1/0 overrides.
207    #[serde(default)]
208    pub delta_explicit: bool,
209    /// Persistent profile name. Checked after LEAN_CTX_PROFILE env var.
210    /// Set via `lean-ctx config set profile passthrough` or editing config.toml.
211    #[serde(default)]
212    pub profile: Option<String>,
213    /// Active task-specific Context Kit. `LEAN_CTX_KIT` takes precedence.
214    /// Set with `lean-ctx kit load <name>`.
215    #[serde(default)]
216    pub active_kit: Option<String>,
217    /// Named configuration overlay selected from `[profiles.<name>]`.
218    /// `LEAN_CTX_CONFIG_PROFILE` takes precedence over this persisted selector.
219    #[serde(default)]
220    pub config_profile: Option<String>,
221    /// Partial configuration overlays keyed by profile name. Each overlay is
222    /// recursively merged over the base configuration at load time.
223    #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
224    pub profiles: std::collections::BTreeMap<String, toml::Table>,
225    /// Tool visibility profile: "minimal" (5), "standard" (15), or "power" (all).
226    /// Override via LEAN_CTX_TOOL_PROFILE env var.
227    /// Existing installs default to "power" (backward compat).
228    #[serde(default)]
229    pub tool_profile: Option<String>,
230    /// Explicit list of enabled tool names. Used only when no tool_profile is pinned (tool_profile takes precedence); leave tool_profile unset to apply this list.
231    /// The universal invoker `ctx_call` stays advertised so unlisted tools remain
232    /// reachable — add `ctx_call` to `disabled_tools` to make this allowlist authoritative.
233    /// Example: `tools_enabled = ["ctx_read", "ctx_shell", "ctx_search"]`
234    #[serde(default)]
235    pub tools_enabled: Vec<String>,
236    /// Active context persona (`persona-spec-v1`). Selects the domain bundle —
237    /// tool surface, read-mode/compressor/chunker defaults, intent taxonomy,
238    /// sensitivity floor. Override via `LEAN_CTX_PERSONA`. Defaults to `coding`.
239    #[serde(default)]
240    pub persona: Option<String>,
241    #[serde(default)]
242    pub loop_detection: LoopDetectionConfig,
243    /// Controls where lean-ctx installs agent rule files.
244    /// Values: "both" (default), "global" (home-dir only), "project" (repo-local only).
245    /// Override via LEAN_CTX_RULES_SCOPE env var.
246    #[serde(default)]
247    pub rules_scope: Option<String>,
248    /// Controls how rules are injected for shared-instruction-file agents.
249    /// Values: "shared" (default, marker block in CLAUDE.md/CODEBUDDY.md/AGENTS.md/GEMINI.md),
250    /// "dedicated" (never touch those files; use each agent's config-driven
251    /// auto-load: SessionStart hook / instructions[] / context.fileName, #343), or
252    /// "off" (write no rules file at all — for hosts that supply their own
253    /// tool-steering workflow or phase-isolated/non-caching harnesses, #361).
254    /// Override via LEAN_CTX_RULES_INJECTION env var.
255    #[serde(default)]
256    pub rules_injection: Option<String>,
257    /// Mirror the host IDE's tool-permission rules onto lean-ctx's own MCP tools.
258    /// Values: "on" (default, GH #1428) or "off". When "on", lean-ctx reads the active
259    /// IDE's permission config (v1: OpenCode) and applies the equivalent
260    /// deny/ask/allow decision to the matching lean-ctx tool — so `ctx_shell`
261    /// honors your `bash`/`rm *` rules instead of bypassing them.
262    /// Override via LEAN_CTX_PERMISSION_INHERITANCE env var.
263    #[serde(default)]
264    pub permission_inheritance: Option<String>,
265    /// Extra glob patterns to ignore in graph/overview/preload (repo-local).
266    /// Example: `["externals/**", "target/**", "temp/**"]`
267    #[serde(default)]
268    pub extra_ignore_patterns: Vec<String>,
269    /// Controls agent output verbosity via instructions injection.
270    /// Values: "off" (default), "lite", "full", "ultra".
271    /// Override via LEAN_CTX_TERSE_AGENT env var.
272    #[serde(default)]
273    pub terse_agent: TerseAgent,
274    /// Unified compression level (replaces separate terse_agent + output_density).
275    /// Values: "off" (default), "lite", "standard", "max".
276    /// Override via LEAN_CTX_COMPRESSION env var.
277    #[serde(default)]
278    pub compression_level: CompressionLevel,
279    /// Global compression intensity 0.0 (lossless) – 1.0 (max), mapped onto the
280    /// read modes / entropy / IB stages (see `core::aggressiveness`). `None`
281    /// (default) keeps each mode's built-in default. Override via the
282    /// `LEAN_CTX_AGGRESSIVENESS` env var or the `ctx_read` `aggressiveness` arg.
283    #[serde(default)]
284    pub compression_aggressiveness: Option<f64>,
285    /// Archive configuration for zero-loss compression.
286    #[serde(default)]
287    pub archive: ArchiveConfig,
288    /// Memory policy (knowledge/lifecycle budgets & thresholds; the episodic
289    /// and procedural sections are retired and have no effect).
290    #[serde(default)]
291    pub memory: MemoryPolicy,
292    /// Additional paths allowed by PathJail (absolute).
293    /// Useful for multi-project workspaces where the jail root is a parent directory.
294    /// Override via LEAN_CTX_ALLOW_PATH env var (path-list separator).
295    #[serde(default)]
296    pub allow_paths: Vec<String>,
297    /// Allow jailed tool access to home-level IDE config dirs (~/.cursor, VS Code,
298    /// Cline/Roo, JetBrains, …). Tri-state: `None` = not asked yet (setup prompts
299    /// once), `Some(false)` = declined, `Some(true)` = opted in. Those dirs can
300    /// expose other agents' sessions, MCP configs and credentials, so the effective
301    /// default is off. `~/.lean-ctx` (own data dir) is always allowed. The opt-in
302    /// set is registry-derived, covering every supported editor. Override via
303    /// LEAN_CTX_ALLOW_IDE_DIRS=1.
304    #[serde(default)]
305    pub allow_ide_config_dirs: Option<bool>,
306    /// Extra project roots for multi-root workspaces.
307    /// Tools like ctx_tree and ctx_search can scan across all roots in a single call.
308    /// These paths are automatically added to PathJail's allow-list.
309    /// Override via LEAN_CTX_EXTRA_ROOTS env var (path-list separator).
310    #[serde(default)]
311    pub extra_roots: Vec<String>,
312    /// Read-only roots: sibling subtrees the agent may READ but never WRITE.
313    /// Reads resolve as if they were extra_roots; every write tool (edit, refactor,
314    /// handoff/session export, memory compaction) is default-denied inside these
315    /// paths. Useful for reference repos mounted next to the project.
316    /// Override via LEAN_CTX_READ_ONLY_ROOTS env var (path-list separator).
317    #[serde(default)]
318    pub read_only_roots: Vec<String>,
319    /// Extra trusted roots OUTSIDE `$HOME` that lean-ctx may follow when an agent
320    /// config file/dir (`~/.claude.json`, `~/.codex/config.toml`, …) is a symlink
321    /// pointing there (#596). Empty by default → the strict `$HOME`-only boundary
322    /// stays in force (a planted symlink can never redirect a config write out of
323    /// the user's home, preserving the GL#442 symlink-hijack protection). Add a
324    /// parent like `/opt/dotfiles` only for a location you own and trust. Like
325    /// `extra_roots`, security-sensitive: stripped from untrusted project-local
326    /// configs. Override via LEAN_CTX_ALLOW_SYMLINK_ROOTS env var (path-list sep).
327    #[serde(default)]
328    pub allow_symlink_roots: Vec<String>,
329    /// Enable content-defined chunking (Rabin-Karp) for cache-optimal output ordering.
330    /// Stable chunks are emitted first to maximize prompt cache hits.
331    #[serde(default)]
332    pub content_defined_chunking: bool,
333    /// Skip session/knowledge/gotcha blocks in MCP instructions to minimize token overhead.
334    /// Override via LEAN_CTX_MINIMAL env var.
335    ///
336    /// Default `true` (deliberate): initialize-time instructions stay byte-stable
337    /// across sessions, which keeps the provider prompt-cache prefix warm (#498)
338    /// and holds the fixed per-session cost at the `doctor overhead --gate`
339    /// budget. Session continuity is NOT lost — the wakeup briefing (task,
340    /// findings, knowledge) is delivered through the first tool call's
341    /// `--- AUTO CONTEXT ---` block instead, which only bills when the agent
342    /// actually works. Set to `false` to additionally inject the ACTIVE SESSION
343    /// / PROJECT MEMORY blocks directly into the MCP `initialize` instructions.
344    /// #1540: this key never disables the archive/ephemeral firewall — only
345    /// the `LEAN_CTX_MINIMAL` env escape hatch skips that safety net.
346    /// `default_true`, not `default`: a field-level `#[serde(default)]` made
347    /// every config.toml without this key read `false` (bool's default), so
348    /// the documented default `true` only held for users with no config file
349    /// (focus analysis 2026-10-15).
350    #[serde(default = "default_true")]
351    pub minimal_overhead: bool,
352    /// Opt-in: substitute long identifiers with short α-codes (+ a `§MAP` table)
353    /// in `aggressive` reads for projects with >50 source files. Off by default —
354    /// the abbreviated form is confusing for editing/refactoring, where the agent
355    /// needs the real package and symbol names. Enable for max exploration savings.
356    #[serde(default)]
357    pub symbol_map_auto: bool,
358    /// Opt-in: bias `auto` toward structure-first reads (`map`) for medium code
359    /// files on a cold read. Off by default — interactive sessions keep the
360    /// conservative `full` floor that avoids a follow-up body read. Enable for
361    /// phase-isolated harnesses (no warm-session cache payback), where a cold
362    /// `full` read is pure overhead and structure-first reads aid localization.
363    /// Override via the LEAN_CTX_STRUCTURE_FIRST env var.
364    #[serde(default)]
365    pub structure_first: bool,
366    /// Progressive disclosure for first-time reads (LCLM arXiv 2606.09659).
367    /// When true (default), large files default to compact overviews on first read:
368    ///     - Below progressive_threshold_lines: full content
369    ///     - Below progressive_signatures_max_lines: signatures mode
370    ///     - Above: map (manifest) mode
371    /// Models can always bypass with explicit mode= or lines= parameters.
372    /// Override via LEAN_CTX_PROGRESSIVE_DISCLOSURE env var.
373    #[serde(default = "serde_defaults::default_true")]
374    pub progressive_disclosure: bool,
375    /// Files with fewer lines than this threshold are always delivered in full.
376    /// Default: 100 lines.
377    #[serde(default = "serde_defaults::default_progressive_threshold_lines")]
378    pub progressive_threshold_lines: u32,
379    /// Files between threshold and this limit get signatures mode.
380    /// Files above get map (manifest) mode. Default: 500 lines.
381    #[serde(default = "serde_defaults::default_progressive_signatures_max")]
382    pub progressive_signatures_max: u32,
383    /// Retired, no effect (kept so existing configs load; `DEPRECATIONS.toml`).
384    /// The learned `auto` signals it switched on are gone: `auto` is always the
385    /// deterministic capability-guard and size/task cascade (#498). The
386    /// `LEAN_CTX_AUTO_MODE_LEARNING` env var is ignored as well.
387    #[serde(default)]
388    pub auto_mode_learning: bool,
389    /// Team content sharing (strategy 2026-10-14, acceptance T07). When false,
390    /// nothing whose body is content leaves for the hosted Team service: no bus
391    /// post, work-graph write, knowledge entry or artifact publication. Presence,
392    /// leases and reads (metadata) keep working. On by default.
393    #[serde(default = "serde_defaults::default_true")]
394    pub team_share_content: bool,
395    /// Enable human-readable activity journal (~/.lean-ctx/journal.md).
396    #[serde(default)]
397    pub journal_enabled: bool,
398    /// Opt-in: auto-persist interesting findings as knowledge facts.
399    #[serde(default)]
400    pub auto_capture: bool,
401    /// Hybrid search weights (BM25/dense/candidates).
402    #[serde(default)]
403    pub search: crate::core::hybrid_search::HybridConfig,
404    /// Index-time file filters (#735): include/exclude globs + gitignore
405    /// handling, applied by every index builder via `core::index_filter`.
406    #[serde(default)]
407    pub index: IndexConfig,
408    /// Skillify miner settings (#290): codify recurring patterns into rules.
409    #[serde(default)]
410    pub skillify: SkillifyConfig,
411    /// AI session-summary settings (#292): periodic, semantically-recallable summaries.
412    #[serde(default)]
413    pub summaries: SummariesConfig,
414    /// Retired, no effect (kept so existing configs load; `DEPRECATIONS.toml`
415    /// `config-llm`): LeanCTX calls no model itself.
416    #[serde(default)]
417    pub llm: LlmConfig,
418    /// Semantic-embedding engine settings (which local ONNX model to use).
419    #[serde(default)]
420    pub embedding: EmbeddingConfig,
421    /// Disable shell hook injection (the _lc() function that wraps CLI commands).
422    /// Override via LEAN_CTX_NO_HOOK env var.
423    #[serde(default)]
424    pub shell_hook_disabled: bool,
425    /// Shadow mode (default: true): lean-ctx steers agents to ctx_* MCP tools,
426    /// and an explicit `hook_mode = "replace"` may deny native Grep/Glob.
427    /// `shadow_mode = false` caps every agent at Hybrid, so native tools are
428    /// never denied.
429    /// Native Shell/Bash coverage is governed separately by `shell_hook_mode`.
430    #[serde(default = "serde_defaults::default_true")]
431    pub shadow_mode: bool,
432    /// Shell hook mode (#1278): how the PreToolUse shell hook treats native
433    /// Bash/Shell calls.
434    /// - `rewrite` (default): rewrite known read/search/list commands to
435    ///   lean-ctx equivalents; anything unrecognized passes through raw.
436    /// - `deny`: block native shell calls outright so every command goes
437    ///   through `ctx_shell` (same fail-opens as the deny hook: lean-ctx
438    ///   disabled, MCP daemon dead, explicit shadow-only tool surface).
439    /// - `auto`: currently equals `rewrite`; reserved for a future default flip.
440    ///
441    /// Env override: `LEAN_CTX_SHELL_HOOK_MODE`. Lives in config.toml, so the
442    /// choice survives reinstalls and updates.
443    #[serde(default)]
444    pub shell_hook_mode: Option<String>,
445    /// Per-turn tool-routing reinjection (#1288): the UserPromptSubmit hook
446    /// emits a one-line `additionalContext` reminder of the ctx_* routing, so it
447    /// post-dates any session-level harness instruction preferring native Bash.
448    /// `on` | `off` | `auto` (default: auto = off, since the host's rules channel
449    /// already carries the routing once, A3). Env override:
450    /// `LEAN_CTX_PROMPT_REINJECT`. Costs ~45 tokens per turn when active.
451    #[serde(default)]
452    pub prompt_reinject: Option<String>,
453    /// Global hook mode override. When set, overrides the per-agent auto-detection.
454    /// - `replace`: native Grep/Glob (and non-rewritable shell where the host
455    ///   supports it) denied, lean-ctx MCP is the only path — opt-in only
456    /// - `hybrid`: MCP + shell hooks; native tools keep working
457    /// - `mcp`: MCP server only, no hooks
458    /// - `auto`/unset: Hybrid for hook-capable agents, else MCP
459    ///   (`recommend_hook_mode`)
460    #[serde(default)]
461    pub hook_mode: Option<String>,
462    /// MCP tool surface mode. Controls how many tools `tools/list` advertises.
463    /// - `auto` (default): shadow-only (`ctx_call` only) for hook-covered
464    ///   clients, full lazy-core surface for all others.
465    /// - `mcp`: always advertise the full lazy-core/profile surface.
466    /// - `shadow`: always advertise only `ctx_call` (requires installed hooks).
467    #[serde(default)]
468    pub tool_surface: Option<String>,
469    /// Opt-in (#520): write a human-readable debug log of intercepted MCP tool
470    /// calls and hook routing decisions (lean-ctx vs native, with reasons) to
471    /// `<state_dir>/logs/debug.log`. Override via the LEAN_CTX_DEBUG_LOG env var.
472    #[serde(default)]
473    pub debug_log: bool,
474    /// Controls when the shell hook auto-activates aliases.
475    /// - `agents-only`: (Default since #699) Aliases only active when an AI
476    ///   agent env var is detected — transparent in plain human terminals.
477    /// - `always`: Aliases active in every interactive shell (pre-#699 default).
478    /// - `off`: Aliases never auto-activate (user must call `lean-ctx-on` manually).
479    ///
480    /// Override via `LEAN_CTX_SHELL_ACTIVATION` env var.
481    #[serde(default)]
482    pub shell_activation: ShellActivation,
483    /// Do not install agent CLI aliases (`claude`, `codex`, `gemini`,
484    /// `codebuddy`) into `~/.zshrc` / `~/.bashrc` during `onboard` / `setup`.
485    /// Existing alias blocks are removed when this is toggled on (#754).
486    /// Does NOT affect the shell compression hook (`_lc()`) — use
487    /// `shell_hook_disabled` for that. Orthogonal to `shell_activation` which
488    /// controls *when* aliases activate, not *whether* they are installed.
489    #[serde(default)]
490    pub skip_agent_aliases: bool,
491    /// Controls the native-Read → `ctx_read` redirect hook (#637).
492    /// - `auto`: (Default) redirect everywhere except hosts with a native
493    ///   read-before-write guard (Claude Code / CodeBuddy), where the path-swap
494    ///   would break native Write/Edit.
495    /// - `on`: always redirect (legacy behavior).
496    /// - `off`: never redirect native Read.
497    ///
498    /// Override via the `LEAN_CTX_READ_REDIRECT` env var.
499    #[serde(default)]
500    pub read_redirect: ReadRedirect,
501    /// Controls the PostToolUse native-Read re-read dedup (GL #1140).
502    /// - `auto`: (Default) replace only re-reads of unchanged files, and only on
503    ///   guard hosts (Claude Code / CodeBuddy) where the PreToolUse redirect is
504    ///   disabled — the guard-safe way to win the dedup savings back.
505    /// - `on`: dedup wherever the PostToolUse hook fires.
506    /// - `off`: never replace a Read result.
507    ///
508    /// Override via the `LEAN_CTX_READ_DEDUP` env var.
509    #[serde(default)]
510    pub read_dedup: ReadDedup,
511    /// Ask the user to approve a command the shell allowlist does not name,
512    /// when the MCP client supports elicitation (`ask`, default) or refuse
513    /// it without asking (`off`). Global only. Override via the
514    /// `LEAN_CTX_SHELL_APPROVAL` env var.
515    #[serde(default)]
516    pub shell_approval: ShellApproval,
517    /// Languages `ctx_execute` runs without asking (`python`, `javascript`,
518    /// …): what "Always allow" in its approval prompt writes. Global only.
519    #[serde(default)]
520    pub execute_allowed_languages: Vec<String>,
521    /// Disable the daily version check against
522    /// api.github.com/repos/yvgude/lean-ctx/releases/latest.
523    /// Override via LEAN_CTX_NO_UPDATE_CHECK env var.
524    #[serde(default)]
525    pub update_check_disabled: bool,
526    #[serde(default)]
527    pub updates: UpdatesConfig,
528    /// Fixed-context budget accounting for `doctor overhead` / `gain` (#964).
529    #[serde(default)]
530    pub context: ContextConfig,
531    /// Maximum BM25 cache file size in MB. Indexes exceeding this are quarantined on load
532    /// and refused on save. Override via LEAN_CTX_BM25_MAX_CACHE_MB env var.
533    #[serde(default = "serde_defaults::default_bm25_max_cache_mb")]
534    pub bm25_max_cache_mb: u64,
535    /// Maximum number of files scanned by the lightweight JSON graph index.
536    /// 0 = unlimited (default). Set >0 to cap for constrained systems.
537    #[serde(default = "serde_defaults::default_graph_index_max_files")]
538    pub graph_index_max_files: u64,
539    /// Maximum number of files indexed into the BM25 corpus; the semantic index
540    /// chunks the same corpus (#737), so this bounds semantic coverage too.
541    /// 0 = unlimited. Default 5000 (MAX_BM25_FILES).
542    #[serde(default = "serde_defaults::default_bm25_max_files")]
543    pub bm25_max_files: u64,
544    /// Controls RAM vs feature trade-off. Values: "low", "balanced" (default), "performance".
545    /// Override via LEAN_CTX_MEMORY_PROFILE env var.
546    #[serde(default)]
547    pub memory_profile: MemoryProfile,
548    /// Controls how aggressively memory is freed when idle.
549    /// Values: "shared" (default, 1h TTL), "aggressive" (5 min TTL for low-memory devices).
550    /// Override via LEAN_CTX_MEMORY_CLEANUP env var.
551    #[serde(default)]
552    pub memory_cleanup: MemoryCleanup,
553    /// How the code graph uses local semantic backends (language servers, a
554    /// live JetBrains IDE). Values: "off", "auto" (default: only backends that
555    /// are already running), "eager" (may start language servers).
556    /// Override via LEAN_CTX_SEMANTIC_MODE env var.
557    #[serde(default)]
558    pub semantic_mode: SemanticMode,
559    /// Soft process-RSS target as a percentage of system RAM (default: 5).
560    /// The guardian throttles and evicts above it, but this is not an OS hard cap.
561    /// Use a cgroup/container MemoryMax when strict isolation is required.
562    /// Override via LEAN_CTX_MAX_RAM_PERCENT env var.
563    #[serde(default = "serde_defaults::default_max_ram_percent")]
564    pub max_ram_percent: u8,
565    /// Per-process RSS target (MB) of each stdio MCP server; the guardian uses
566    /// the lower of this and `max_ram_percent` (default 512, 0 = percent only).
567    /// Hosts like the Codex app-server keep one server per loaded thread alive
568    /// for days, so a percentage of a large machine's RAM alone is too loose.
569    /// Override via LEAN_CTX_MCP_MAX_RSS_MB env var.
570    #[serde(default = "serde_defaults::default_mcp_max_rss_mb")]
571    pub mcp_max_rss_mb: u64,
572    /// Process RSS target (MB) of the background daemon; the guardian uses the
573    /// lower of this and `max_ram_percent` (default 2048, 0 = percent only).
574    /// One daemon serves every session and project root on the machine for
575    /// days, so a percentage of a large machine's RAM alone is too loose (#2075).
576    /// Override via LEAN_CTX_DAEMON_MAX_RSS_MB env var.
577    #[serde(default = "serde_defaults::default_daemon_max_rss_mb")]
578    pub daemon_max_rss_mb: u64,
579    /// Exit a stdio MCP server after this many minutes without a tool call
580    /// (0 = never, the default). Off by default because some hosts (Codex)
581    /// do not restart an exited server: the resumed thread then loses
582    /// lean-ctx until the host restarts. Idle servers release their caches
583    /// either way (`memory_cleanup`). Override via LEAN_CTX_MCP_IDLE_EXIT_MINUTES.
584    #[serde(default)]
585    pub mcp_idle_exit_minutes: u64,
586    /// Simplified disk budget (MB). When set and detail values are at defaults,
587    /// distributes proportionally: archive=25%, bm25=10%, remainder for stores.
588    /// 0 = disabled (use individual settings). Override via LEAN_CTX_MAX_DISK_MB.
589    #[serde(default)]
590    pub max_disk_mb: u64,
591    /// Auto-purge data older than this many days. 0 = disabled.
592    /// Flows into archive.max_age_hours and lifecycle idle TTL.
593    #[serde(default)]
594    pub max_staleness_days: u32,
595    /// Retention window for explicit session cleanup. This is independent from
596    /// archive retention and always preserves the newest session per project.
597    /// Override via LEAN_CTX_SESSION_RETENTION_DAYS.
598    #[serde(default = "serde_defaults::default_session_retention_days")]
599    pub session_retention_days: u32,
600    /// Cap on the rayon worker threads used by the CPU-heavy index build
601    /// (call graph etc.). 0 = rayon default (all cores). Set >0 to bound
602    /// per-instance CPU so a fleet of concurrent sessions can't saturate the
603    /// host on startup. Override via LEANCTX_INDEX_THREADS env var.
604    #[serde(default)]
605    pub max_index_threads: usize,
606    /// Controls visibility of token savings footers in tool output.
607    /// Values: "never" (default), "always" (show on every response), "auto" (legacy compatibility).
608    /// Override via LEAN_CTX_SAVINGS_FOOTER or LEAN_CTX_SHOW_SAVINGS=1|0 env var.
609    #[serde(default)]
610    pub savings_footer: SavingsFooter,
611    /// Controls compression annotation style in savings footers.
612    /// Values: "quantized" (default, round to 10% buckets), "full" (exact %), "none" (suppress all).
613    /// Override via LEAN_CTX_COMPRESSION_ANNOTATION env var.
614    #[serde(default)]
615    pub compression_annotation: CompressionAnnotation,
616    /// Minimum savings percentage to emit a footer annotation. Below this threshold,
617    /// annotations are suppressed (the savings are too small to be worth the token cost).
618    /// Default: 5 (suppress annotations for savings below 5%).
619    #[serde(default = "serde_defaults::default_annotation_threshold_pct")]
620    pub annotation_threshold_pct: u8,
621    /// In-band behavior hints (heavy full/raw reads, search→read→search
622    /// chains): "auto" (default, one hint per pattern per session) or "off".
623    /// Detections are always counted for `tools health`, hints or not.
624    /// "off" also drops the OUTPUT-HINT line from a task-filtered
625    /// `ctx_overview`: that line shapes the assistant's answer rather than
626    /// reporting a retrieval result, so it belongs to the same switch (#1763).
627    #[serde(default = "serde_defaults::default_behavior_nudges")]
628    pub behavior_nudges: String,
629    /// Maximum fresh tokens per single tool response (turn budget).
630    /// 0 = unlimited. Default: 4096. Prevents context bloat from oversized responses.
631    /// Override via LEAN_CTX_TURN_FRESH_LIMIT env var.
632    #[serde(default = "serde_defaults::default_turn_fresh_limit")]
633    pub turn_fresh_limit: usize,
634    /// Turn budget for a response the caller explicitly asked to be verbatim
635    /// (`ctx_read` with `raw=true` or `mode="raw"`). 0 = unlimited.
636    /// Default: 32768. Override via LEAN_CTX_TURN_FRESH_LIMIT_VERBATIM.
637    ///
638    /// The ordinary `turn_fresh_limit` is a compression backstop for output the
639    /// agent did not size itself. A verbatim read is the documented recovery
640    /// path out of compression (#1582); capping it at the same 4096 tokens made
641    /// that path unreachable for any file above ~16 KB.
642    #[serde(default = "serde_defaults::default_turn_fresh_limit_verbatim")]
643    pub turn_fresh_limit_verbatim: usize,
644    /// Explicit project root override. When set, lean-ctx uses this instead of auto-detection.
645    /// This prevents accidental home-directory scans when running from $HOME.
646    /// Override via LEAN_CTX_PROJECT_ROOT env var.
647    #[serde(default)]
648    pub project_root: Option<String>,
649    /// LSP server overrides. Map language name to custom binary path.
650    /// Example: `[lsp]\nrust = "/opt/rust-analyzer"\npython = "~/.venvs/main/bin/pylsp"`
651    #[serde(default)]
652    pub lsp: std::collections::HashMap<String, String>,
653    /// Per-IDE allowed paths. Restricts which directories lean-ctx will scan/index for each IDE.
654    /// Example: `[ide_paths]\ncursor = ["/home/user/projects/app1"]\ncodex = ["/home/user/codex"]`
655    /// When set, only these paths are indexed for the matching agent. Global `allow_paths` still applies.
656    #[serde(default)]
657    pub ide_paths: HashMap<String, Vec<String>>,
658    /// Custom model context window overrides.
659    /// Example: `[model_context_windows]\n"my-custom-model" = 500000`
660    #[serde(default)]
661    pub model_context_windows: HashMap<String, usize>,
662    /// Controls how much detail tool responses include.
663    ///
664    /// - `full` (default): complete compressed output
665    /// - `headers_only`: metadata line only (path, mode, token count)
666    ///
667    /// Override via `LEAN_CTX_RESPONSE_VERBOSITY` env var.
668    #[serde(default)]
669    pub response_verbosity: ResponseVerbosity,
670    /// Bypass hint mode. When agents use native Read/Grep instead of lean-ctx tools,
671    /// a hint is appended to the next tool response.
672    /// Values: "on" (default), "off", "aggressive" (hint on every call, no cooldown).
673    /// Override via LEAN_CTX_BYPASS_HINTS env var.
674    #[serde(default)]
675    pub bypass_hints: Option<String>,
676    /// Cache policy for ctx_read. Controls behavior on cache hits.
677    /// Values: "aggressive" (default, 13-tok stubs + compaction-aware reset),
678    /// "safe" (delivers map instead of stub), "off" (no caching, always disk read).
679    /// Override via LEAN_CTX_CACHE_POLICY env var.
680    #[serde(default)]
681    pub cache_policy: Option<String>,
682    /// Token budget for the in-memory `ctx_read` cache. When the cached total
683    /// plus an incoming read would exceed this, lean-ctx evicts the least-valuable
684    /// entries *immediately* (RRF: recency × frequency × size) so the read always
685    /// proceeds — eviction is never deferred to the staleness TTL. `0` uses the
686    /// built-in default (2M). `LEAN_CTX_CACHE_MAX_TOKENS` env var overrides this.
687    #[serde(default)]
688    pub cache_max_tokens: usize,
689    /// Cross-project boundary policy.
690    /// Controls whether cross-project search/import is allowed and whether access is audited.
691    #[serde(default)]
692    pub boundary_policy: crate::core::memory_boundary::BoundaryPolicy,
693    #[serde(default)]
694    pub secret_detection: SecretDetectionConfig,
695    /// Per-item sensitivity model with a uniform policy floor (#212).
696    /// Disabled by default → fully no-op until `sensitivity.enabled = true`.
697    #[serde(default)]
698    pub sensitivity: crate::core::sensitivity::SensitivityConfig,
699    /// Context Gateway admission (`[context_gateway]`): built-in detectors
700    /// that run on every governed source before caching or compression.
701    /// On by default. Global-only: a project-local file cannot weaken it.
702    #[serde(default)]
703    pub context_gateway: crate::core::context_admission::ContextGatewayConfig,
704    /// Set by the loader when the global `config.toml` exists but could not be
705    /// read or parsed, so this snapshot holds built-in defaults instead of the
706    /// operator's settings. It travels with exactly this `Config` value: an
707    /// earlier failed snapshot stays marked after a later successful load.
708    /// Never read from or written to a file.
709    #[serde(skip)]
710    pub load_failure: Option<super::ConfigLoadFailure>,
711    /// Accept A2A handoff bundles and context packages whose signature
712    /// verifies but whose signer key is not anchored in `trusted-signers.toml`
713    /// (GHSA-gvg8-285q-m62g). Off by default: anyone can mint a key, so an
714    /// untrusted signature proves nothing about the sender. Global-only
715    /// (never merged from project-local config).
716    #[serde(default)]
717    pub a2a_accept_untrusted_signers: bool,
718    /// Let MCP tools (`ctx_handoff import`, `ctx_pack import`) import handoff
719    /// bundles and context packages that are unsigned or signed by a key not
720    /// anchored in `trusted-signers.toml` (GHSA-gvg8-285q-m62g). A tool
721    /// argument cannot grant this — the model could set it under prompt
722    /// injection. Off by default; global-only. CLI imports keep their own
723    /// human opt-in (`--allow-unsigned`).
724    #[serde(default)]
725    pub mcp_import_allow_unverified: bool,
726    /// MCP Tool-Catalog Gateway (#210): aggregate + query-route downstream MCP
727    /// servers. Global-only (never merged from project-local config) and a full
728    /// no-op until `gateway.enabled = true`.
729    #[serde(default)]
730    pub gateway: crate::core::mcp_catalog::GatewayConfig,
731    /// Self-hosted org gateway server (`[gateway_server]`, enterprise#20):
732    /// deployment parameters for the usage cockpit — seat count for the
733    /// org-wide projection, display label, and the central admin API the local
734    /// cockpit may read from. All optional; absent = local-only behavior.
735    #[serde(default)]
736    pub gateway_server: GatewayServerConfig,
737    /// Enterprise Suite connection (`[enterprise]`): connects this Runtime to
738    /// a LeanCTX Enterprise Gateway for economics tracking and model routing.
739    #[serde(default)]
740    pub enterprise: EnterpriseConfig,
741    /// Verbatim binary path/expression for generated agent-hook commands
742    /// (#708). Users who sync agent settings (`~/.claude/settings.json`, …)
743    /// across machines with different usernames need an env-based form like
744    /// `$HOME/.local/bin/lean-ctx` — agent hosts run hook commands through a
745    /// shell, which expands it. When set (env `LEAN_CTX_HOOK_BINARY` wins,
746    /// then this key), every hook writer emits the value verbatim instead of
747    /// the machine-absolute exe path, so `init`/`doctor --fix`/`update` stop
748    /// rewriting synced files into sync ping-pong. Autostart plists/services
749    /// and daemon spawns are NOT affected — launchd/systemd do not expand
750    /// shell variables, so those keep the real absolute path. Empty (default)
751    /// = automatic absolute-path resolution (#367).
752    #[serde(default)]
753    pub hook_binary: Option<String>,
754    /// Disable PathJail entirely by setting `path_jail = false` in config.toml.
755    /// Useful in container/Docker environments where the sandbox is the boundary.
756    /// (The former `LEAN_CTX_NO_JAIL=1` env override was removed in v3.7.3.)
757    #[serde(default)]
758    pub path_jail: Option<bool>,
759    /// What the enforced jail admits besides the project + allow-lists:
760    /// `projects` (default — every project below `$HOME` readable, writes only
761    /// in the session's project), `home` (all of `$HOME` read and write, except
762    /// dot entries, `~/Library`, `~/AppData`) or `project`. See `core::pathjail_scope`.
763    #[serde(default)]
764    pub path_jail_scope: Option<String>,
765    /// Sandbox level for code execution (ctx_exec).
766    /// 0 = subprocess only (current), 1 = OS-level restriction (Seatbelt/Landlock).
767    /// Override via LEAN_CTX_SANDBOX_LEVEL env var.
768    #[serde(default)]
769    pub sandbox_level: u8,
770    /// When true, large tool outputs (>4000 chars) are stored as references
771    /// and a short URI is returned instead of the full content.
772    /// Override via LEAN_CTX_REFERENCE_RESULTS env var.
773    #[serde(default)]
774    pub reference_results: bool,
775    /// Default per-agent token budget. 0 means unlimited.
776    /// Override per-agent via ctx_session or programmatically.
777    #[serde(default)]
778    pub agent_token_budget: usize,
779    /// Optional shell command allowlist. When non-empty, only commands whose base binary
780    /// is in this list are permitted by ctx_shell. Empty = disable allowlist (allow all).
781    /// Default includes common dev tools. Set to `[]` to disable.
782    /// Override via LEAN_CTX_SHELL_ALLOWLIST env var (comma-separated).
783    #[serde(default = "default_shell_allowlist")]
784    pub shell_allowlist: Vec<String>,
785
786    /// Extra commands MERGED on top of the effective `shell_allowlist` without replacing
787    /// the defaults. Setting `shell_allowlist` replaces the whole built-in list (a common
788    /// footgun); entries here are purely additive, which is what `lean-ctx allow <cmd>`
789    /// writes. Only applied in restricted mode (when the base allowlist is non-empty).
790    #[serde(default)]
791    pub shell_allowlist_extra: Vec<String>,
792
793    /// When true, block command substitution ($(), backticks) and process substitution
794    /// (<(), >()) in shell arguments. When false (default), only warn via tracing.
795    /// Default false preserves backward compatibility — set true for maximum security.
796    #[serde(default)]
797    pub shell_strict_mode: bool,
798
799    /// GH #1419 follow-up: scope a multi-word `shell_allowlist`/
800    /// `shell_allowlist_extra` entry to the exact subcommand/prefix it names
801    /// (`"git status"` no longer grants the whole `git` binary). Default
802    /// `true` (the secure grammar); set `false` to fall back to the old
803    /// base-binary-only matching as a compat/rollback path. Trust-gated: an
804    /// untrusted workspace cannot weaken this via a local override. Override
805    /// via `LEAN_CTX_SHELL_ALLOWLIST_SUBCOMMAND_SCOPING`.
806    #[serde(default = "serde_defaults::default_true")]
807    pub shell_allowlist_subcommand_scoping: bool,
808
809    /// Shell-security mode for ctx_shell / `lean-ctx -c` command gating (GL #788):
810    /// `enforce` (default, secure), `warn` (run checks, log violations, never
811    /// block) or `off` (skip the allowlist + dangerous-pattern blocks entirely —
812    /// a deliberate opt-out; compression stays active). Override via
813    /// LEAN_CTX_SHELL_SECURITY. `None` resolves to `enforce`.
814    #[serde(default)]
815    pub shell_security: Option<String>,
816
817    /// Default shell-command timeout in seconds for *normal* commands. `None`
818    /// resolves to the built-in 2-minute default; heavy builds/tests use
819    /// [`Config::shell_heavy_timeout_secs`]. Override via
820    /// `LEAN_CTX_SHELL_TIMEOUT_SECS` (`LEAN_CTX_SHELL_TIMEOUT_MS` still wins over
821    /// both, in milliseconds).
822    #[serde(default)]
823    pub shell_timeout_secs: Option<u64>,
824
825    /// Shell-command timeout in seconds for *heavy* commands (cargo build/test,
826    /// make, docker build, git commit/push, …). `None` resolves to the built-in
827    /// 10-minute ceiling. Override via `LEAN_CTX_SHELL_HEAVY_TIMEOUT_SECS`.
828    #[serde(default)]
829    pub shell_heavy_timeout_secs: Option<u64>,
830
831    /// Extra command prefixes that get the heavy timeout ceiling. Merged with
832    /// the built-in list. Useful for project-specific long-running scripts.
833    /// Example: `shell_heavy_prefixes = ["python3 ", "./scripts/"]`
834    #[serde(default)]
835    pub shell_heavy_prefixes: Vec<String>,
836    /// When true, `ctx_shell` accepts shell file-write redirects (`>`, `>>`,
837    /// `tee`, heredoc-to-file, `curl -o`, `wget` default mode). Default false —
838    /// the native Write/Edit tool is preferred. Opt-in for power users who want
839    /// classic shell syntax; the real command gating (allowlist,
840    /// dangerous-pattern and interpreter-eval blocks) still applies. Override
841    /// via `LEAN_CTX_SHELL_ALLOW_WRITES=1`.
842    #[serde(default)]
843    pub shell_allow_writes: bool,
844    /// Absolute paths where shell redirects and `tee` may capture output.
845    /// Empty uses the operating system's temporary directories. Project files
846    /// remain denied even when a configured path overlaps the project root.
847    #[serde(default)]
848    pub write_allow_paths: Vec<String>,
849
850    /// #814: opt-in to allow `python3 -c`, `node -e`, etc. in ctx_shell.
851    /// Default `false` — inline code is blocked because it leaves no auditable
852    /// artifact. Override via `LEAN_CTX_SHELL_ALLOW_INLINE_SCRIPTS=1`.
853    #[serde(default)]
854    pub shell_allow_inline_scripts: bool,
855
856    /// Setup behavior: controls what gets injected during setup and updates.
857    #[serde(default)]
858    pub setup: SetupConfig,
859    #[serde(default)]
860    pub solution: super::solution::SolutionConfig,
861    /// Claude Code governor rule modes (`[governor]`; env overrides win).
862    #[serde(default)]
863    pub governor: super::governor::GovernorConfig,
864    #[serde(default)]
865    pub provenance: super::provenance::ProvenanceConfig,
866    pub cross_agent: super::provenance::CrossAgentConfig,
867}
868
869/// `[llm]`: no effect. Its only consumers, query expansion and observation
870/// synthesis, are retired (DEPRECATIONS.toml `config-llm`); the section stays
871/// accepted so existing configs keep loading.
872#[derive(Debug, Clone, Serialize, Deserialize)]
873#[serde(default)]
874pub struct LlmConfig {
875    pub enabled: bool,
876    pub backend: LlmBackend,
877    pub model: String,
878    pub timeout_secs: u64,
879    pub base_url: Option<String>,
880}
881
882impl Default for LlmConfig {
883    fn default() -> Self {
884        Self {
885            enabled: false,
886            backend: LlmBackend::Ollama,
887            model: "qwen2.5-coder:1.5b".to_string(),
888            timeout_secs: 10,
889            base_url: None,
890        }
891    }
892}
893
894/// The `[llm] backend` values an existing config may still name.
895#[derive(Debug, Clone, Default, Serialize, Deserialize)]
896#[serde(rename_all = "lowercase")]
897pub enum LlmBackend {
898    #[default]
899    Ollama,
900    OpenRouter,
901    Anthropic,
902}