Skip to main content

mur_common/config/
scratch.rs

1//! Per-agent scratch dir (`<mur_home>/tmp/<agent>`) tuning (`scratch:`).
2
3use super::*;
4
5/// Default age after which a top-level scratch entry is pruned at start.
6pub const SCRATCH_DEFAULT_RETENTION_DAYS: u32 = 7;
7/// Default per-agent size above which `mur agent doctor` warns.
8pub const SCRATCH_DEFAULT_WARN_SIZE_MB: u64 = 2048;
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct ScratchConfig {
12    /// Entries whose newest mtime is older than this many days are removed
13    /// by the supervisor before the sandbox seals.
14    #[serde(default = "scratch_default_retention_days")]
15    pub retention_days: u32,
16    /// `mur agent doctor` warns when an agent's scratch dir exceeds this.
17    #[serde(default = "scratch_default_warn_size_mb")]
18    pub warn_size_mb: u64,
19}
20
21fn scratch_default_retention_days() -> u32 {
22    SCRATCH_DEFAULT_RETENTION_DAYS
23}
24
25fn scratch_default_warn_size_mb() -> u64 {
26    SCRATCH_DEFAULT_WARN_SIZE_MB
27}
28
29impl Default for ScratchConfig {
30    fn default() -> Self {
31        Self {
32            retention_days: SCRATCH_DEFAULT_RETENTION_DAYS,
33            warn_size_mb: SCRATCH_DEFAULT_WARN_SIZE_MB,
34        }
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41
42    #[test]
43    fn config_without_scratch_block_uses_defaults() {
44        let c: Config = serde_yaml::from_str("llm: {}\n").unwrap();
45        assert_eq!(c.scratch.retention_days, 7);
46        assert_eq!(c.scratch.warn_size_mb, 2048);
47        let p: ScratchConfig = serde_yaml::from_str("retention_days: 3\n").unwrap();
48        assert_eq!((p.retention_days, p.warn_size_mb), (3, 2048));
49    }
50}