| 1 | use serde::{Deserialize, Serialize}; |
| 2 | use std::collections::BTreeMap; |
| 3 | |
| 4 | /// On-disk schema for the `[workflow]` table (#4128 / Section 2.11). |
| 5 | /// |
| 6 | /// Automatic Workflow launch, write/approval gates, child/isolation budgets, |
| 7 | /// and completed-activity persistence all read from this one model. When the |
| 8 | /// table is absent, consumers resolve [`WorkflowConfigToml::default`]. |
| 9 | /// See `config.example.toml` for documentation. |
| 10 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] |
| 11 | pub struct WorkflowConfigToml { |
| 12 | #[serde(default = "default_workflow_automatic")] |
| 13 | pub automatic: bool, |
| 14 | #[serde(default = "default_workflow_auto_start_read_only")] |
| 15 | pub auto_start_read_only: bool, |
| 16 | /// Require an operator approval card before launching plans that write, |
| 17 | /// elevate shell/network, or otherwise leave the read-only envelope. |
| 18 | #[serde(default = "default_workflow_require_approval_for_writes")] |
| 19 | pub require_approval_for_writes: bool, |
| 20 | /// Operator-selected total child limit. Zero leaves total work uncapped. |
| 21 | #[serde(default = "default_workflow_max_children")] |
| 22 | pub max_children: u32, |
| 23 | /// Maximum concurrently live agents inside one Workflow run (product: 64). |
| 24 | #[serde(default = "default_workflow_max_concurrent")] |
| 25 | pub max_concurrent: u32, |
| 26 | /// Maximum structural nesting depth accepted for Workflow IR. |
| 27 | /// |
| 28 | /// Zero leaves structural depth uncapped. Runtime delegation is separate. |
| 29 | #[serde(default = "default_workflow_max_depth")] |
| 30 | pub max_depth: u32, |
| 31 | } |
| 32 | |
| 33 | pub(crate) fn default_workflow_automatic() -> bool { |
| 34 | true |
| 35 | } |
| 36 | |
| 37 | pub(crate) fn default_workflow_auto_start_read_only() -> bool { |
| 38 | true |
| 39 | } |
| 40 | |
| 41 | pub(crate) fn default_workflow_require_approval_for_writes() -> bool { |
| 42 | true |
| 43 | } |
| 44 | |
| 45 | pub(crate) fn default_workflow_max_children() -> u32 { |
| 46 | 0 |
| 47 | } |
| 48 | |
| 49 | pub(crate) fn default_workflow_max_concurrent() -> u32 { |
| 50 | 64 |
| 51 | } |
| 52 | |
| 53 | pub(crate) fn default_workflow_max_depth() -> u32 { |
| 54 | 0 |
| 55 | } |
| 56 | |
| 57 | impl Default for WorkflowConfigToml { |
| 58 | fn default() -> Self { |
| 59 | Self { |
| 60 | automatic: default_workflow_automatic(), |
| 61 | auto_start_read_only: default_workflow_auto_start_read_only(), |
| 62 | require_approval_for_writes: default_workflow_require_approval_for_writes(), |
| 63 | max_children: default_workflow_max_children(), |
| 64 | max_concurrent: default_workflow_max_concurrent(), |
| 65 | max_depth: default_workflow_max_depth(), |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// On-disk schema for `[verifier]`. |
| 71 | #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] |
| 72 | pub struct VerifierConfigToml { |
| 73 | /// Enable automatic verifier preview when the runtime wires a |
| 74 | /// claim-of-done trigger. Manual `run_verifiers` remains available |
| 75 | /// regardless. |
| 76 | #[serde(default)] |
| 77 | pub enabled: bool, |
| 78 | } |
| 79 | |
| 80 | /// On-disk schema for `[advisor]` (#3982). |
| 81 | /// |
| 82 | /// Advisor mode is **off by default**. When enabled, the engine spawns a |
| 83 | /// short-lived background reviewer after each turn that contained tool calls. |
| 84 | /// The reviewer reads a bounded slice of recent tool calls, makes a concise |
| 85 | /// LLM advisory call, and emits the note as an `AdvisoryNote` event without |
| 86 | /// blocking the parent turn. |
| 87 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] |
| 88 | pub struct AdvisorConfigToml { |
| 89 | /// Master on/off switch. `false` by default — no background reviewer is |
| 90 | /// spawned until the user opts in via `[advisor] enabled = true` or |
| 91 | /// `/advisor on`. |
| 92 | #[serde(default)] |
| 93 | pub enabled: bool, |
| 94 | /// Maximum number of recent tool-call/result pairs to include in each |
| 95 | /// advisory review. Keeps the reviewer's context window bounded regardless |
| 96 | /// of turn length. Defaults to 10; clamped to 1–50. |
| 97 | #[serde(default = "advisor_default_max_tool_calls")] |
| 98 | pub max_tool_calls: u32, |
| 99 | /// Minimum wall-clock seconds between two consecutive advisor emissions. |
| 100 | /// Prevents noise on rapid multi-turn sequences. Defaults to 60 seconds; |
| 101 | /// clamped to 5–3600. |
| 102 | #[serde(default = "advisor_default_rate_limit_secs")] |
| 103 | pub rate_limit_secs: u64, |
| 104 | /// Deduplication window in seconds. An advisory note whose content hash |
| 105 | /// matches the previous note within this window is silently dropped. |
| 106 | /// Defaults to 300 seconds (5 minutes). |
| 107 | #[serde(default = "advisor_default_dedup_window_secs")] |
| 108 | pub dedup_window_secs: u64, |
| 109 | /// Optional model override for the advisor LLM call. When absent, the |
| 110 | /// advisor reuses the session's current model. |
| 111 | #[serde(default)] |
| 112 | pub model: Option<String>, |
| 113 | } |
| 114 | |
| 115 | pub(crate) fn advisor_default_max_tool_calls() -> u32 { |
| 116 | 10 |
| 117 | } |
| 118 | |
| 119 | pub(crate) fn advisor_default_rate_limit_secs() -> u64 { |
| 120 | 60 |
| 121 | } |
| 122 | |
| 123 | pub(crate) fn advisor_default_dedup_window_secs() -> u64 { |
| 124 | 300 |
| 125 | } |
| 126 | |
| 127 | impl Default for AdvisorConfigToml { |
| 128 | fn default() -> Self { |
| 129 | Self { |
| 130 | enabled: false, |
| 131 | max_tool_calls: advisor_default_max_tool_calls(), |
| 132 | rate_limit_secs: advisor_default_rate_limit_secs(), |
| 133 | dedup_window_secs: advisor_default_dedup_window_secs(), |
| 134 | model: None, |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// On-disk schema for the `[network]` table (#135). See `config.example.toml` |
| 140 | /// for documentation. |
| 141 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 142 | pub struct NetworkPolicyToml { |
| 143 | /// Decision for hosts that are not in `allow` or `deny`. One of |
| 144 | /// `"allow" | "deny" | "prompt"`. Defaults to `"prompt"`. |
| 145 | #[serde(default = "default_network_decision")] |
| 146 | pub default: String, |
| 147 | /// Hosts that are always allowed. Subdomain rules: a leading dot |
| 148 | /// (`.example.com`) matches subdomains but not the apex. |
| 149 | #[serde(default)] |
| 150 | pub allow: Vec<String>, |
| 151 | /// Hosts that are always denied. Deny entries win over allow entries. |
| 152 | #[serde(default)] |
| 153 | pub deny: Vec<String>, |
| 154 | /// Hostnames whose DNS may resolve to fake-IP/private proxy ranges in an |
| 155 | /// explicitly trusted proxy setup. Literal IP URLs remain blocked. |
| 156 | #[serde(default)] |
| 157 | pub proxy: Vec<String>, |
| 158 | /// Explicit fake-IP placeholder CIDRs for those proxy hosts. The runtime |
| 159 | /// accepts only subnets contained by `198.18.0.0/15`. |
| 160 | #[serde(default)] |
| 161 | pub proxy_fake_ip_cidrs: Vec<String>, |
| 162 | /// Whether to record one audit-log line per outbound network call. |
| 163 | #[serde(default = "default_network_audit")] |
| 164 | pub audit: bool, |
| 165 | /// Keys owned by the TUI runtime or added by newer releases must survive |
| 166 | /// dispatcher reads and typed saves. |
| 167 | #[serde(flatten)] |
| 168 | pub extras: BTreeMap<String, toml::Value>, |
| 169 | } |
| 170 | |
| 171 | pub(crate) fn default_network_decision() -> String { |
| 172 | "prompt".to_string() |
| 173 | } |
| 174 | |
| 175 | pub(crate) fn default_network_audit() -> bool { |
| 176 | true |
| 177 | } |
| 178 | |
| 179 | impl Default for NetworkPolicyToml { |
| 180 | fn default() -> Self { |
| 181 | Self { |
| 182 | default: default_network_decision(), |
| 183 | allow: Vec::new(), |
| 184 | deny: Vec::new(), |
| 185 | proxy: Vec::new(), |
| 186 | proxy_fake_ip_cidrs: Vec::new(), |
| 187 | audit: default_network_audit(), |
| 188 | extras: BTreeMap::new(), |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /// User-defined LSP server for one file extension (used inside |
| 194 | /// [`LspConfigToml::custom`]). |
| 195 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] |
| 196 | pub struct CustomLspDef { |
| 197 | /// LSP `languageId` value used in `textDocument/didOpen`. |
| 198 | pub language_id: String, |
| 199 | /// Executable to spawn. |
| 200 | pub command: String, |
| 201 | /// Arguments passed to the executable. |
| 202 | #[serde(default)] |
| 203 | pub args: Vec<String>, |
| 204 | } |
| 205 | |
| 206 | /// On-disk schema for the `[lsp]` table (#136). See `config.example.toml` |
| 207 | /// for documentation. All fields are optional so the TUI runtime can fall |
| 208 | /// back to its own defaults when keys are absent. |
| 209 | #[derive(Debug, Clone, Serialize, Deserialize, Default)] |
| 210 | pub struct LspConfigToml { |
| 211 | /// Master switch. |
| 212 | pub enabled: Option<bool>, |
| 213 | /// Maximum time to wait for diagnostics after an edit, in milliseconds. |
| 214 | pub poll_after_edit_ms: Option<u64>, |
| 215 | /// Cap on diagnostics surfaced per file. |
| 216 | pub max_diagnostics_per_file: Option<usize>, |
| 217 | /// When `true`, warnings (severity 2) are surfaced in addition to errors. |
| 218 | pub include_warnings: Option<bool>, |
| 219 | /// Optional override for the `language -> [cmd, ...args]` table. |
| 220 | pub servers: Option<BTreeMap<String, Vec<String>>>, |
| 221 | /// User-defined LSP servers for file extensions not in the built-in |
| 222 | /// registry. Keyed by extension (e.g. `"php"`, `"rb"`). |
| 223 | pub custom: Option<BTreeMap<String, CustomLspDef>>, |
| 224 | /// Keys owned by the TUI runtime or added by newer releases must survive |
| 225 | /// dispatcher reads and typed saves. |
| 226 | #[serde(flatten)] |
| 227 | pub extras: BTreeMap<String, toml::Value>, |
| 228 | } |
| 229 |