Skip to main content

mur_common/config/
ops.rs

1use super::*;
2
3/// Pre-dispatch triage settings (`triage:` in `~/.mur/config.yaml`).
4///
5/// Both knobs default to the passive posture, and `enforce` in particular is
6/// off for a reason that is not caution: `triage_calibration` cannot score a
7/// decision that prevented a run. Enforcing from the start produces only
8/// unfalsifiable `held_back` records, so there would never be evidence that
9/// enforcing was correct. Shadow mode records the same predictions AND lets
10/// the run happen, which is what makes `Calibration::shadow_precision`
11/// computable — turn `enforce` on once that number says triage is right often
12/// enough to be worth the refusals.
13#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
14pub struct TriageConfig {
15    /// Run triage before dispatch at all. Off = not even the free prefilter
16    /// runs, and no verdicts are recorded.
17    #[serde(default)]
18    pub enabled: bool,
19    /// Let a triage decision actually stop a dispatch. Requires `enabled`.
20    /// See the type docs before turning this on.
21    #[serde(default)]
22    pub enforce: bool,
23}
24
25impl TriageConfig {
26    /// Does triage actually bind here? `enforce` alone is inert — with
27    /// `enabled: false` nothing runs to enforce — so the two are resolved in
28    /// one place rather than at each call site, where the pair would
29    /// eventually be got wrong in one of them.
30    pub fn enforces(&self) -> bool {
31        self.enabled && self.enforce
32    }
33}
34
35/// Rotation for `~/.mur/queue/events.jsonl`, in the shape FreeBSD's
36/// `newsyslog(8)` uses: rotate past a size, keep a bounded number of
37/// generations, compress all but the newest, drop the oldest.
38///
39/// The point of generations is that nobody has to decide to delete anything.
40/// A 934 MB queue becomes `.0`, then `.1.gz`, and ages out on a policy the
41/// user set rather than on a judgement call someone makes once.
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
43pub struct CaptureConfig {
44    /// Rotate once the live file passes this. 64 MB keeps `mur hook stats`
45    /// responsive — parsing is O(file), and 934 MB took minutes.
46    #[serde(default = "default_rotate_at_mb")]
47    pub rotate_at_mb: u64,
48    /// How many rotated generations to keep. `.0` stays uncompressed like
49    /// newsyslog's, the rest are gzipped.
50    #[serde(default = "default_keep_generations")]
51    pub keep_generations: u32,
52}
53
54pub(super) fn default_rotate_at_mb() -> u64 {
55    64
56}
57
58fn default_keep_generations() -> u32 {
59    5
60}
61
62impl Default for CaptureConfig {
63    fn default() -> Self {
64        Self {
65            rotate_at_mb: default_rotate_at_mb(),
66            keep_generations: default_keep_generations(),
67        }
68    }
69}
70
71/// Post-upgrade settings for `mur update`. Stored under `update:` in
72/// `~/.mur/config.yaml`.
73#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
74pub struct UpdateConfig {
75    /// macOS code-signing identity used to re-sign installed binaries after an
76    /// upgrade. Keychain grants bind to the signing identity; fresh installs
77    /// are ad-hoc (new CDHash per build), so without a stable identity every
78    /// upgrade kills the grants and service-launched agents fail silently
79    /// (#849/#866). Fallback: the `MUR_CODESIGN_IDENTITY` env var.
80    #[serde(default, skip_serializing_if = "Option::is_none")]
81    pub codesign_identity: Option<String>,
82    /// Agent names `mur update --restart-agents` must never touch.
83    #[serde(default, skip_serializing_if = "Vec::is_empty")]
84    pub restart_exclude: Vec<String>,
85}
86
87/// Which notification channels the durable monitor may use. `log` is not
88/// listed: it is always on and cannot be disabled, because a notable event
89/// must leave a trace somewhere even when a user has turned everything off.
90#[derive(Debug, Clone, Default, Serialize, Deserialize)]
91pub struct NotificationsConfig {
92    /// OS desktop notification. Opt-in: a background daemon that starts
93    /// popping banners on upgrade is a hostile default.
94    #[serde(default)]
95    pub desktop: bool,
96}
97
98/// Whether the durable monitor may ask a model what to do about a terminal
99/// failure the structured rules did not settle.
100///
101/// Off by default, and not merely as a courtesy: enabling it lets a
102/// background daemon send monitor context to a model on its own schedule,
103/// with no one watching. Nobody watching is not permission, so this is a
104/// decision a user makes once, explicitly, rather than something an upgrade
105/// makes for them.
106///
107/// The bound on how often it may ask is NOT here: one proposal per
108/// observation cycle is an invariant of the design, not a knob (see
109/// `mur_core::monitor::resolver`). A tunable would let a user turn a bounded
110/// feature into an unbounded one.
111#[derive(Debug, Clone, Default, Serialize, Deserialize)]
112pub struct MonitorResolverConfig {
113    /// Opt-in. While false, nothing in the resolver path runs and no request
114    /// leaves the machine.
115    #[serde(default)]
116    pub enabled: bool,
117
118    /// Which model to ask. `None` uses the same backend `mur chat` resolves,
119    /// so a user who has already configured one does not configure it twice.
120    #[serde(default)]
121    pub model: Option<String>,
122}
123
124/// Run-status heartbeat tuning. Both values are config, never literals at a
125/// call site: the right interval depends on how long the machine's steps take.
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct RunsConfig {
128    /// How often `execute_dag` stamps `last_heartbeat_at`.
129    #[serde(default = "default_heartbeat_interval_secs")]
130    pub heartbeat_interval_secs: u64,
131    /// How many missed intervals before a live process counts as `stalled`.
132    /// Three tolerates one lost tick plus scheduling jitter without calling a
133    /// healthy run dead.
134    #[serde(default = "default_heartbeat_stale_after_intervals")]
135    pub heartbeat_stale_after_intervals: u32,
136}
137
138pub(super) fn default_heartbeat_interval_secs() -> u64 {
139    10
140}
141
142pub(super) fn default_heartbeat_stale_after_intervals() -> u32 {
143    3
144}
145
146impl Default for RunsConfig {
147    fn default() -> Self {
148        Self {
149            heartbeat_interval_secs: default_heartbeat_interval_secs(),
150            heartbeat_stale_after_intervals: default_heartbeat_stale_after_intervals(),
151        }
152    }
153}
154
155/// Authorization gate for the `parallel_jobs` MCP tool. Stored under `parallel_jobs:`
156/// in `~/.mur/config.yaml`. Deny-by-default: an empty `targets` list means the
157/// tool cannot delegate to ANY agent (inert until the user opts specific
158/// agents in). This is a deterministic, out-of-model gate that a
159/// prompt-injected concierge cannot widen (OWASP Agentic ASI02/03/04).
160#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
161pub struct ParallelJobsConfig {
162    /// Canonical agent names the `parallel_jobs` tool is allowed to delegate to.
163    /// Empty = deny all.
164    #[serde(default)]
165    pub targets: Vec<String>,
166}
167
168// --- memory-federation snapshot (spec 2026-08-04-unified-memory-federation) ---
169
170/// Daemon-side settings for the signed snapshot pull. Stored under
171/// `federation_snapshot:` in `~/.mur/config.yaml`; every field has a default
172/// so an absent block means "defaults", never "off".
173#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
174#[serde(default)]
175pub struct SnapshotConfig {
176    /// How often the daemon sweeps `inbox/snapshot-requests/`, in seconds.
177    pub poll_secs: u64,
178    /// Reject requests older than this (replay blunting), in seconds.
179    pub request_max_age_secs: u64,
180    /// Minimum lifecycle state a global skill needs to enter a snapshot.
181    pub min_lifecycle: crate::skill::stats::LifecycleState,
182}
183
184impl Default for SnapshotConfig {
185    fn default() -> Self {
186        Self {
187            poll_secs: 30,
188            request_max_age_secs: 600,
189            min_lifecycle: crate::skill::stats::LifecycleState::Stable,
190        }
191    }
192}
193
194/// Proactive memory capture (memory federation P2): gates the runtime's
195/// built-in `remember` tool and its system-prompt directive. Stored under
196/// `memory:` in `~/.mur/config.yaml`.
197#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
198#[serde(default)]
199pub struct MemoryConfig {
200    pub capture: CaptureMode,
201    /// How many memories may enter the system prompt per turn. Deliberately
202    /// NOT `skills.max_skills_in_prompt`: sharing that budget means saving a
203    /// memory silently evicts a skill, and five is a plausible number of
204    /// standing preferences for one user to have.
205    #[serde(default = "default_memory_in_prompt")]
206    pub max_in_prompt: usize,
207    /// Character ceiling for the whole memory block, spent before skills.
208    #[serde(default = "default_memory_chars")]
209    pub max_chars: usize,
210}
211
212fn default_memory_in_prompt() -> usize {
213    20
214}
215
216fn default_memory_chars() -> usize {
217    1500
218}
219
220impl Default for MemoryConfig {
221    fn default() -> Self {
222        Self {
223            capture: CaptureMode::AutoAnnounce,
224            max_in_prompt: default_memory_in_prompt(),
225            max_chars: default_memory_chars(),
226        }
227    }
228}
229
230/// How agents capture memories mid-conversation.
231#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
232#[serde(rename_all = "snake_case")]
233pub enum CaptureMode {
234    /// Agent asks for a one-line confirmation before saving.
235    Ask,
236    /// Agent saves immediately and announces in the same reply (default).
237    AutoAnnounce,
238    /// The `remember` tool is not registered at all.
239    Off,
240}
241
242/// Authorization gate for the runtime's built-in `fleet_run` tool. Stored under
243/// `fleet_run:` in `~/.mur/config.yaml`. Deny-by-default on BOTH axes: an agent
244/// not named in `agents` never even sees the tool, and a fleet not named in
245/// `fleets` cannot be run. Lives in the global config (not the agent profile)
246/// because the profile is writable by the concierge itself — this gate must be
247/// out of reach of a prompt-injected agent (same rationale as
248/// [`ParallelJobsConfig`]).
249#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
250pub struct FleetRunConfig {
251    /// Canonical agent names allowed to call `fleet_run`. Empty = deny all.
252    #[serde(default)]
253    pub agents: Vec<String>,
254    /// Fleet names those agents may run. Empty = deny all.
255    #[serde(default)]
256    pub fleets: Vec<String>,
257}
258
259/// Daemon-side settings for cross-router fleet dispatch (#2116). Stored under
260/// `fleet_dispatch:` in `~/.mur/config.yaml`; an absent block means defaults.
261/// WHO may dispatch WHAT is still [`FleetRunConfig`] — this only tunes timing.
262#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
263#[serde(default)]
264pub struct FleetDispatchConfig {
265    /// How often the daemon sweeps `inbox/fleet-dispatch-requests/`, in seconds.
266    /// Short by default: an agent is waiting on the run it just dispatched.
267    pub poll_secs: u64,
268    /// Reject requests older than this (replay blunting), in seconds.
269    pub request_max_age_secs: u64,
270    /// A daemon heartbeat older than this is treated as "daemon down" by the
271    /// requesting agent, which then refuses instead of queueing into nothing.
272    pub heartbeat_stale_secs: u64,
273}
274
275impl Default for FleetDispatchConfig {
276    fn default() -> Self {
277        Self {
278            poll_secs: 3,
279            request_max_age_secs: 300,
280            heartbeat_stale_secs: 60,
281        }
282    }
283}
284
285/// Gate for the git push broker (`git_push:` in `~/.mur/config.yaml`).
286/// Deny-by-default on BOTH axes, like [`FleetRunConfig`]: `enabled` is the
287/// broker-wide switch (off: the daemon sweeper does not run and no agent gets
288/// anything), and `agents` names the only agents that see `git_push_request` /
289/// `git_push_status` / `git_push_cancel` and get the Landlock read grant on the
290/// registry. An agent not named here — a deep-research worker, say — never sees
291/// the tools, so it neither learns the registry exists nor adds requests to the
292/// human approval queue. Global config, not the agent profile, for the same
293/// reason as [`FleetRunConfig`]: a prompt-injected agent must not widen it.
294#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
295pub struct GitPushConfig {
296    #[serde(default)]
297    pub enabled: bool,
298    /// Canonical agent names allowed the push tools. Empty = deny all.
299    #[serde(default)]
300    pub agents: Vec<String>,
301}
302
303/// Display policy for `mur open`.
304///
305/// Lives in `config.yaml` rather than in `open-items.jsonl` because that log
306/// is append-only and agent-writable via the `open_item` tool. A user's
307/// decision to stop looking at a source must not be overturnable by an agent
308/// appending a record. Same reasoning as `fleet_run.agents`.
309#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
310pub struct OpenItemsConfig {
311    /// Exact `origin` strings to collapse out of `mur open`. Exact match
312    /// only — `fleet` never matches `fleet:acme`.
313    #[serde(default)]
314    pub muted: Vec<String>,
315}
316
317/// Daemon-wide gate for unattended fleet auto-run (`mur-daemon`'s `fleet_tick`).
318/// Stored under `fleet:` in `~/.mur/config.yaml`. Either this flag OR the
319/// `MUR_FLEET_AUTORUN` env var satisfies the gate — both are equally explicit,
320/// off-by-default opt-ins; the env var remains for ops/CI use, this flag is
321/// what the Hub's Settings toggle controls. Per-fleet `budget_usd > 0` and the
322/// `.stopped` kill-switch are unaffected — see `mur-daemon/src/fleet_tick.rs`.
323#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
324pub struct FleetConfig {
325    /// Allow fleets with a trigger + budget configured to auto-run unattended.
326    #[serde(default)]
327    pub autorun: bool,
328}
329
330/// Routing for Anthropic subscription-OAuth (`sk-ant-oat*`) tokens through a
331/// local bridge — cc-proxy — that swaps `x-api-key` for the Bearer +
332/// claude-code betas disguise the upstream requires.
333///
334/// The Hub injects `ANTHROPIC_BASE_URL` pointing at [`url`](Self::url) when it
335/// spawns an agent runtime, but only when [`enabled`](Self::enabled) is set and
336/// the bridge is actually listening; otherwise it leaves the runtime on the
337/// direct `api.anthropic.com` path (where an oat token would 401). A runtime
338/// launched with `ANTHROPIC_BASE_URL` already in its environment is never
339/// overridden.
340#[derive(Debug, Clone, Serialize, Deserialize)]
341pub struct CcProxyConfig {
342    /// Bridge base URL. Defaults to cc-proxy's default bind.
343    #[serde(default = "default_cc_proxy_url")]
344    pub url: String,
345
346    /// Master switch. When false the Hub never routes runtimes through the
347    /// bridge, regardless of reachability.
348    #[serde(default = "default_true")]
349    pub enabled: bool,
350}
351
352fn default_cc_proxy_url() -> String {
353    "http://127.0.0.1:8088".to_string()
354}
355
356fn default_true() -> bool {
357    true
358}
359
360impl Default for CcProxyConfig {
361    fn default() -> Self {
362        Self {
363            url: default_cc_proxy_url(),
364            enabled: true,
365        }
366    }
367}
368
369/// Configuration for the agent CLI TUI.
370/// Stored in ~/.mur/config.yaml under the `cli:` key.
371#[derive(Debug, Clone, Serialize, Deserialize, Default)]
372pub struct CliConfig {
373    /// Default visual skin for `mur agent cli`. Overridable with --skin.
374    /// Valid values: "ansi" (default; "dark" is an alias), "light", "mur",
375    /// "clay", or the stem of a user skin file `<mur home>/skins/<name>.yaml`.
376    pub skin: Option<String>,
377
378    /// True once the one-time "permanent instructions" notice has been shown
379    /// (memories P1 §10).
380    ///
381    /// The notice is informational and must appear at most once — repeating a
382    /// feature announcement every session reads as a warning about something
383    /// wrong. Absent (false) in existing configs, which is correct: a user who
384    /// has never seen it should.
385    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
386    pub seen_permanent_instructions_notice: bool,
387}
388
389/// Configuration for the mobile relay (P4).
390/// Stored in ~/.mur/config.yaml under the `mobile_relay:` key.
391#[derive(Debug, Clone, Serialize, Deserialize, Default)]
392pub struct MobileRelayConfig {
393    /// Base URL of the mur-server relay, e.g. "wss://relay.mur.run".
394    /// Leave blank to disable relay forwarding on the Mac daemon side.
395    #[serde(default, skip_serializing_if = "Option::is_none")]
396    pub relay_url: Option<String>,
397
398    /// API key or JWT used by the Mac daemon to authenticate with the relay.
399    /// The value is typically a `mur_...` API key from app.mur.run.
400    #[serde(default, skip_serializing_if = "Option::is_none")]
401    pub api_key: Option<String>,
402}
403
404#[cfg(test)]
405mod fleet_config_tests {
406    use super::*;
407
408    #[test]
409    fn fleet_config_defaults_off_and_roundtrips() {
410        assert!(!FleetConfig::default().autorun);
411
412        let cfg: Config = serde_yaml_ng::from_str("fleet:\n  autorun: true\n").unwrap();
413        assert!(cfg.fleet.autorun);
414
415        // `fleet:` key entirely absent → defaults to off
416        let cfg2: Config = serde_yaml_ng::from_str("{}").unwrap();
417        assert!(!cfg2.fleet.autorun);
418    }
419
420    #[test]
421    fn fleet_run_config_defaults_deny_all_and_roundtrips() {
422        // Absent section → both allowlists empty → deny all.
423        let cfg: Config = serde_yaml_ng::from_str("{}").unwrap();
424        assert!(cfg.fleet_run.agents.is_empty());
425        assert!(cfg.fleet_run.fleets.is_empty());
426
427        let cfg2: Config =
428            serde_yaml_ng::from_str("fleet_run:\n  agents: [mur]\n  fleets: [deep-research]\n")
429                .unwrap();
430        assert_eq!(cfg2.fleet_run.agents, vec!["mur"]);
431        assert_eq!(cfg2.fleet_run.fleets, vec!["deep-research"]);
432    }
433
434    #[test]
435    fn git_push_config_defaults_off_and_roundtrips() {
436        let cfg: Config = serde_yaml_ng::from_str("{}").unwrap();
437        assert!(!cfg.git_push.enabled);
438        assert!(cfg.git_push.agents.is_empty());
439        let cfg2: Config =
440            serde_yaml_ng::from_str("git_push:\n  enabled: true\n  agents: [mur]\n").unwrap();
441        assert!(cfg2.git_push.enabled);
442        assert_eq!(cfg2.git_push.agents, vec!["mur"]);
443    }
444}
445
446#[cfg(test)]
447mod runs_config_tests {
448    use super::*;
449
450    /// A zero `heartbeat_interval_secs` is legal YAML but illegal at runtime:
451    /// it zeroes the stale threshold (every live run instantly reads STALLED)
452    /// and `tokio::time::interval(Duration::ZERO)` panics in the executor's
453    /// ticker. The loader must clamp zeroes to the defaults so one
454    /// user-edited line can neither lie nor crash.
455    #[test]
456    fn zero_heartbeat_values_clamp_to_defaults_at_load() {
457        let tmp = tempfile::tempdir().unwrap();
458        let path = tmp.path().join("config.yaml");
459        std::fs::write(
460            &path,
461            "runs:\n  heartbeat_interval_secs: 0\n  heartbeat_stale_after_intervals: 0\n",
462        )
463        .unwrap();
464
465        let cfg = Config::load_or_default(&path);
466        assert_eq!(
467            cfg.runs.heartbeat_interval_secs, 10,
468            "a zero interval must load as the default, not 0"
469        );
470        assert_eq!(
471            cfg.runs.heartbeat_stale_after_intervals, 3,
472            "a zero interval count must load as the default, not 0"
473        );
474    }
475
476    /// The clamp must not rewrite legitimate tuning: positive values survive.
477    #[test]
478    fn positive_heartbeat_values_survive_the_load() {
479        let tmp = tempfile::tempdir().unwrap();
480        let path = tmp.path().join("config.yaml");
481        std::fs::write(
482            &path,
483            "runs:\n  heartbeat_interval_secs: 60\n  heartbeat_stale_after_intervals: 2\n",
484        )
485        .unwrap();
486
487        let cfg = Config::load_or_default(&path);
488        assert_eq!(cfg.runs.heartbeat_interval_secs, 60);
489        assert_eq!(cfg.runs.heartbeat_stale_after_intervals, 2);
490    }
491}
492
493#[cfg(test)]
494mod ambient_capture_cfg_tests {
495    use super::*;
496
497    #[test]
498    fn session_and_harvest_defaults() {
499        let cfg: Config = serde_yaml::from_str("{}").unwrap();
500        assert_eq!(cfg.session.capture, "ambient");
501        assert_eq!(cfg.session.retention_days, 14);
502        assert!(cfg.harvest.auto_gate);
503        assert_eq!(cfg.harvest.llm, "local-first");
504        assert_eq!(cfg.harvest.min_events, 5);
505        assert_eq!(cfg.harvest.min_user_turns, 2);
506        assert_eq!(cfg.harvest.min_duration_secs, 120);
507        assert_eq!(cfg.harvest.idle_minutes, 30);
508        assert_eq!(cfg.harvest.max_llm_calls_per_day, 10);
509        assert_eq!(cfg.harvest.max_extract_input_tokens, 12000);
510        assert!(cfg.harvest.session_start_hint);
511        assert!((cfg.harvest.similarity_merge_threshold - 0.6).abs() < f32::EPSILON);
512    }
513
514    #[test]
515    fn session_capture_override_parses() {
516        let cfg: Config =
517            serde_yaml::from_str("session:\n  capture: off\n  retention_days: 3\n").unwrap();
518        assert_eq!(cfg.session.capture, "off");
519        assert_eq!(cfg.session.retention_days, 3);
520    }
521}
522
523#[cfg(test)]
524mod cc_proxy_cfg_tests {
525    use super::*;
526
527    #[test]
528    fn defaults_to_local_cc_proxy_enabled() {
529        let cfg: Config = serde_yaml_ng::from_str("{}").unwrap();
530        assert_eq!(cfg.cc_proxy.url, "http://127.0.0.1:8088");
531        assert!(cfg.cc_proxy.enabled);
532    }
533
534    #[test]
535    fn url_and_enabled_override_parse() {
536        let cfg: Config =
537            serde_yaml_ng::from_str("cc_proxy:\n  url: http://127.0.0.1:9999\n  enabled: false\n")
538                .unwrap();
539        assert_eq!(cfg.cc_proxy.url, "http://127.0.0.1:9999");
540        assert!(!cfg.cc_proxy.enabled);
541    }
542
543    #[test]
544    fn partial_section_keeps_other_default() {
545        // Only `enabled` given → url stays at the default.
546        let cfg: Config = serde_yaml_ng::from_str("cc_proxy:\n  enabled: false\n").unwrap();
547        assert_eq!(cfg.cc_proxy.url, "http://127.0.0.1:8088");
548        assert!(!cfg.cc_proxy.enabled);
549    }
550}
551
552#[cfg(test)]
553mod notifications_config_tests {
554    use super::*;
555
556    #[test]
557    fn notifications_default_to_log_only() {
558        let c: Config = serde_yaml::from_str("{}").unwrap();
559        assert!(!c.notifications.desktop, "desktop must be opt-in");
560    }
561
562    #[test]
563    fn an_existing_config_without_the_block_still_parses() {
564        // Every user upgrading has a config.yaml with no `notifications:` key.
565        let c: Config = serde_yaml::from_str("retrieval:\n  min_score: 0.42\n").unwrap();
566        assert!(!c.notifications.desktop);
567    }
568
569    /// The whole safety argument for the resolver rests on this one bit: an
570    /// upgrade must never start letting the daemon talk to a model. Asserted
571    /// from both an empty config and a realistic existing one, because the
572    /// failure that matters is an upgrade, not a fresh install.
573    #[test]
574    fn the_monitor_resolver_is_off_until_a_user_turns_it_on() {
575        let empty: Config = serde_yaml::from_str("{}").unwrap();
576        assert!(
577            !empty.monitor_resolver.enabled,
578            "asking a model must be opt-in"
579        );
580        assert!(empty.monitor_resolver.model.is_none());
581
582        let upgraded: Config = serde_yaml::from_str(
583            "retrieval:\n  min_score: 0.42\nnotifications:\n  desktop: true\n",
584        )
585        .unwrap();
586        assert!(
587            !upgraded.monitor_resolver.enabled,
588            "a config written before this feature existed must not enable it"
589        );
590    }
591
592    #[test]
593    fn the_monitor_resolver_reads_back_what_a_user_wrote() {
594        let c: Config =
595            serde_yaml::from_str("monitor_resolver:\n  enabled: true\n  model: claude_haiku\n")
596                .unwrap();
597        assert!(c.monitor_resolver.enabled);
598        assert_eq!(c.monitor_resolver.model.as_deref(), Some("claude_haiku"));
599    }
600
601    /// Triage must be inert for everyone who never asked for it — including
602    /// every config file written before it existed.
603    #[test]
604    fn triage_is_off_and_non_binding_by_default() {
605        let c: Config = serde_yaml::from_str("retrieval:\n  min_score: 0.42\n").unwrap();
606        assert!(!c.triage.enabled, "triage must not run unasked");
607        assert!(!c.triage.enforce);
608        assert!(!c.triage.enforces());
609    }
610
611    /// The trap this guards: `enforce: true` alone looks like it turned
612    /// something on, but there is nothing running to enforce.
613    #[test]
614    fn enforce_without_enabled_binds_nothing() {
615        let c: Config = serde_yaml::from_str("triage:\n  enforce: true\n").unwrap();
616        assert!(c.triage.enforce, "the user's word is kept verbatim");
617        assert!(
618            !c.triage.enforces(),
619            "but it binds nothing while triage does not run"
620        );
621    }
622
623    #[test]
624    fn triage_binds_only_when_both_knobs_are_set() {
625        let c: Config =
626            serde_yaml::from_str("triage:\n  enabled: true\n  enforce: true\n").unwrap();
627        assert!(c.triage.enforces());
628    }
629
630    /// Enabled without enforce is shadow mode: it runs, it records, it never
631    /// stops anything.
632    #[test]
633    fn enabled_alone_is_shadow_mode() {
634        let c: Config = serde_yaml::from_str("triage:\n  enabled: true\n").unwrap();
635        assert!(c.triage.enabled);
636        assert!(!c.triage.enforces());
637    }
638}