返回 CodeWhale
config_toml.rs
根目录 / crates / config / src / config_toml.rs
1 use crate::catalog;
2 use crate::extension_toml::{
3 ControlSocketToml, HookSinksToml, LifecycleOutboxToml, SkillsToml, SnapshotsToml, ToolsToml,
4 };
5 use crate::fleet::FleetConfigToml;
6 use crate::hotbar::HotbarBindingToml;
7 use crate::provider_kind::ProviderKind;
8 use crate::provider_toml::ProvidersToml;
9 use crate::provider_toml::{deserialize_root_provider, http_headers_are_effectively_empty};
10 use crate::service_toml::{
11 LspConfigToml, NetworkPolicyToml, VerifierConfigToml, WorkflowConfigToml,
12 };
13 use serde::{Deserialize, Serialize};
14 use std::collections::BTreeMap;
15
16 #[derive(Debug, Clone, Serialize, Deserialize, Default)]
17 pub struct ConfigToml {
18 // There is no top-level `api_key` or `base_url`: every parse moves the
19 // legacy root keys into `[providers.<name>]` first (`legacy_root`, #6394).
20 /// Optional extra HTTP headers forwarded to model API requests.
21 #[serde(default, skip_serializing_if = "http_headers_are_effectively_empty")]
22 pub http_headers: BTreeMap<String, String>,
23 /// TUI-compatible default DeepSeek model.
24 pub default_text_model: Option<String>,
25 #[serde(default, deserialize_with = "deserialize_root_provider")]
26 pub provider: ProviderKind,
27 /// Exact saved selector for a named custom provider or a built-in alias.
28 ///
29 /// This is runtime parse state rather than a second on-disk key. The
30 /// serialized `provider` value is restored by `ConfigStore` so a typed
31 /// dispatcher read/write cannot collapse a named route to `custom` or a
32 /// regional selector to its catalog parent.
33 #[doc(hidden)]
34 #[serde(skip)]
35 pub selected_provider_id: Option<String>,
36 pub model: Option<String>,
37 pub auth_mode: Option<String>,
38 pub verbosity: Option<String>,
39 pub log_level: Option<String>,
40 pub telemetry: Option<bool>,
41 /// Where telemetry batches are sent, when telemetry is enabled at all.
42 ///
43 /// Unset here means "take the shipped default",
44 /// `DEFAULT_TELEMETRY_ENDPOINT` — not "send nowhere". Setting it to the
45 /// empty string is the way to say send nowhere: that resolves to no
46 /// endpoint, which appends batches to `dryrun.jsonl` and constructs no HTTP
47 /// client. Either way a persistent or run-scoped opt-out still prevents any
48 /// batch from being constructed.
49 ///
50 /// Kept as a scalar sibling of `telemetry` rather than folded into a
51 /// `[telemetry]` table. `telemetry` is already a scalar and every section
52 /// table is declared after it, so a table of that name would be a hard
53 /// `toml::from_str` failure — and one whose cause `ConfigStore::load`
54 /// deliberately hides, leaving the user with an unloadable config and no
55 /// explanation. It would also be a `ValueAfterTable` serialization hazard
56 /// against the scalars that follow.
57 pub telemetry_endpoint: Option<String>,
58 pub approval_policy: Option<String>,
59 pub sandbox_mode: Option<String>,
60 /// Native tool catalog controls shared with `codewhale-tui`.
61 #[serde(default)]
62 pub tools: Option<ToolsToml>,
63 #[serde(default, skip_serializing_if = "ProvidersToml::is_empty")]
64 pub providers: ProvidersToml,
65 /// Operator declarations for exact provider/endpoint/model tuples.
66 #[serde(
67 default,
68 skip_serializing_if = "Option::is_none",
69 deserialize_with = "catalog::configured::deserialize_configured_models"
70 )]
71 pub custom_models: Option<Vec<catalog::configured::ConfiguredModel>>,
72 /// Provider fallback chain (#2574). TUI runtime code may advance through
73 /// these providers after recoverable provider errors; config resolution
74 /// itself still reports the selected primary provider.
75 #[serde(default, skip_serializing_if = "Vec::is_empty")]
76 pub fallback_providers: Vec<ProviderKind>,
77 /// Per-domain network policy (#135). When absent, network tools fall back
78 /// to a permissive default that mirrors pre-v0.7.0 behavior.
79 #[serde(default)]
80 pub network: Option<NetworkPolicyToml>,
81 /// Verifier-preview behavior (#2093). When absent, verifier tools keep the
82 /// shipped defaults: disabled automatic preview and hunt verdict mapping.
83 #[serde(default)]
84 pub verifier: Option<VerifierConfigToml>,
85 /// Community skill installer settings (#140). Mirrors
86 /// [`SkillsToml`] from the TUI side; the dispatcher consults
87 /// `registry_url` when running `deepseek skill install`.
88 #[serde(default)]
89 pub skills: Option<SkillsToml>,
90 /// Workspace side-git snapshots (#137). The live TUI defaults this to
91 /// enabled with 7-day retention when absent.
92 #[serde(default)]
93 pub snapshots: Option<SnapshotsToml>,
94 /// Post-edit LSP diagnostics injection (#136). When absent, the engine
95 /// applies the defaults documented in [`LspConfigToml`].
96 #[serde(default)]
97 pub lsp: Option<LspConfigToml>,
98 /// Optional 1-8 hotbar slot bindings (#2064). When absent, the TUI falls
99 /// back to the built-in default slots.
100 #[serde(default, skip_serializing_if = "Option::is_none")]
101 pub hotbar: Option<Vec<HotbarBindingToml>>,
102 /// App-server hook sink configuration. Kept separate from the TUI
103 /// lifecycle `[hooks]` table so config rewrites preserve existing hooks.
104 #[serde(default)]
105 pub hook_sinks: Option<HookSinksToml>,
106 /// Lifecycle event outbox (`[lifecycle_outbox]`). Opt-in: an unset or
107 /// empty `path` disables the feature and leaves behavior unchanged.
108 #[serde(default)]
109 pub lifecycle_outbox: Option<LifecycleOutboxToml>,
110 /// Per-session control socket (`[control_socket]`). Opt-in: an absent
111 /// table or `enabled = false` (the default) leaves the feature off and
112 /// behavior unchanged.
113 #[serde(default)]
114 pub control_socket: Option<ControlSocketToml>,
115 /// Agent Fleet trust and security policy (#3165). When absent, fleet
116 /// workers inherit conservative Sandbox defaults.
117 #[serde(default)]
118 pub fleet: Option<FleetConfigToml>,
119 /// Workflow automatic-launch, approval, isolation, and activity
120 /// persistence knobs (#4128 / Section 2.11). When absent, consumers use
121 /// [`WorkflowConfigToml::default`].
122 #[serde(default)]
123 pub workflow: Option<WorkflowConfigToml>,
124 /// Model-bound credential redaction policy (`[redaction]`). When absent,
125 /// masking is enabled — the shipped security default.
126 #[serde(default, skip_serializing_if = "Option::is_none")]
127 pub redaction: Option<crate::redaction::RedactionToml>,
128 #[serde(flatten)]
129 pub extras: BTreeMap<String, toml::Value>,
130 }
131
132 impl ConfigToml {
133 /// The requested model-bound masking mode, defaulting to enabled.
134 ///
135 /// The request only takes effect once the interactive TUI has recorded a
136 /// confirmation on its startup gate; see
137 /// [`crate::redaction::effective_masking`].
138 #[must_use]
139 pub fn redaction_model_bound_masking(&self) -> crate::redaction::ModelBoundMasking {
140 self.redaction
141 .as_ref()
142 .map(crate::redaction::RedactionToml::model_bound_masking)
143 .unwrap_or_default()
144 }
145 }
146
146 lines RUST