Skip to main content

brainwires_system/
config.rs

1//! Configuration types for `brainwires-system`.
2
3use serde::{Deserialize, Serialize};
4
5/// File system reactor configuration.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ReactorConfig {
8    /// Maximum events per minute before rate limiting kicks in.
9    pub max_events_per_minute: u32,
10    /// Global debounce window in milliseconds.
11    pub global_debounce_ms: u64,
12    /// Maximum recursive watch depth.
13    pub max_watch_depth: u32,
14    /// Reactor rules.
15    #[serde(default)]
16    pub rules: Vec<ReactorRuleDef>,
17}
18
19impl Default for ReactorConfig {
20    fn default() -> Self {
21        Self {
22            max_events_per_minute: 60,
23            global_debounce_ms: 500,
24            max_watch_depth: 10,
25            rules: Vec::new(),
26        }
27    }
28}
29
30/// Definition of a reactor rule in configuration.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct ReactorRuleDef {
33    /// Unique rule identifier.
34    pub id: String,
35    /// Human-readable name.
36    pub name: String,
37    /// Paths to watch.
38    pub watch_paths: Vec<String>,
39    /// Glob patterns for file matching.
40    #[serde(default)]
41    pub patterns: Vec<String>,
42    /// Patterns to exclude.
43    #[serde(default)]
44    pub exclude_patterns: Vec<String>,
45    /// File system event types to react to.
46    #[serde(default)]
47    pub event_types: Vec<String>,
48    /// Per-rule debounce in milliseconds.
49    #[serde(default = "default_debounce")]
50    pub debounce_ms: u64,
51    /// Whether this rule is enabled.
52    #[serde(default = "default_true")]
53    pub enabled: bool,
54}
55
56fn default_debounce() -> u64 {
57    1000
58}
59
60fn default_true() -> bool {
61    true
62}
63
64/// System service management configuration.
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct ServiceConfig {
67    /// Explicit allow-list of service names (no wildcards).
68    #[serde(default)]
69    pub allowed_services: Vec<String>,
70    /// Additional forbidden services (supplements hardcoded deny-list).
71    #[serde(default)]
72    pub forbidden_services: Vec<String>,
73    /// If true, only status/list/logs are permitted (no start/stop/restart).
74    #[serde(default = "default_true")]
75    pub read_only: bool,
76    /// Docker socket path override.
77    #[serde(default)]
78    pub docker_socket_path: Option<String>,
79}
80
81impl Default for ServiceConfig {
82    fn default() -> Self {
83        Self {
84            allowed_services: Vec::new(),
85            forbidden_services: Vec::new(),
86            read_only: true,
87            docker_socket_path: None,
88        }
89    }
90}