Skip to main content

theway_daemon/orchestration/
services.rs

1//! Process-scoped daemon services and their explicit ownership.
2
3use std::sync::{Arc, OnceLock};
4
5use crate::commands::CommandOutput;
6use crate::session_activation::SessionActivator;
7use crate::session_execution::SessionExecutionRegistry;
8use crate::tgrep_server::TgrepServerRegistry;
9use crate::tools::assembly::reload::ReloadRuntimeSlot;
10use crate::triggers::cron::CronRegistry;
11use crate::triggers::dynamic::DynamicTriggerRegistry;
12
13/// Shared services owned by one daemon application instance.
14#[derive(Clone)]
15pub struct DaemonServices {
16    pub(crate) command_output: CommandOutput,
17    pub(crate) dynamic_triggers: DynamicTriggerRegistry,
18    pub(crate) cron: CronRegistry,
19    pub(crate) reload: ReloadRuntimeSlot,
20    #[allow(dead_code)]
21    pub(crate) session_execution: SessionExecutionRegistry,
22    pub(crate) session_activator: Arc<OnceLock<Arc<SessionActivator>>>,
23    /// Process-scoped `tgrep serve` registry for the built-in grep tool
24    /// (issue #121): lazily spawned per project root, shared across sessions.
25    pub(crate) tgrep: TgrepServerRegistry,
26}
27
28impl Default for DaemonServices {
29    fn default() -> Self {
30        #[cfg(test)]
31        let dynamic_triggers = crate::triggers::global_registry().clone();
32        #[cfg(not(test))]
33        let dynamic_triggers = DynamicTriggerRegistry::default();
34
35        #[cfg(test)]
36        let cron = crate::triggers::global_cron_registry().clone();
37        #[cfg(not(test))]
38        let cron = CronRegistry::default();
39
40        Self {
41            command_output: CommandOutput::default(),
42            dynamic_triggers,
43            cron,
44            reload: ReloadRuntimeSlot::default(),
45            session_execution: SessionExecutionRegistry::default(),
46            session_activator: Arc::new(OnceLock::new()),
47            tgrep: TgrepServerRegistry::new(),
48        }
49    }
50}
51
52impl DaemonServices {
53    pub fn new() -> Self {
54        Self::default()
55    }
56
57    #[must_use]
58    pub(crate) fn with_command_output(mut self, command_output: CommandOutput) -> Self {
59        self.command_output = command_output;
60        self
61    }
62}