agent_hub_runtime/core/automation/
mod.rs1mod actions;
3#[cfg(any(target_os = "macos", test))]
4mod app_icons;
5pub mod backup;
6mod copy;
7pub use actions::{run as run_action, AutomationActionResult};
8#[cfg(any(unix, test))]
9mod cron;
10mod definition;
11pub use copy::copy_draft;
12pub use definition::prompt_variants::{prompt_variables, set_prompt_variable};
13mod events;
14mod hermes;
15mod history;
16pub mod libraries;
17pub(crate) use events::start as start_change_events;
18pub use history::{history, run_output, AutomationHistory, AutomationRun};
19mod output;
20pub use output::{output, AutomationRunOutput};
21#[cfg(target_os = "macos")]
22mod external_launchd;
23mod hermes_manage;
24#[cfg(any(target_os = "macos", test))]
25mod launchd;
26#[cfg(any(target_os = "macos", test))]
27mod launchd_names;
28#[cfg(any(target_os = "linux", test))]
29mod linux;
30mod local_data;
31mod managed;
32mod native;
33mod next_run;
34pub mod package;
35mod process;
36pub mod runtime_audit;
37mod script_sync;
38mod store;
39pub use script_sync::{sync_workspace_scripts, sync_workspace_scripts_for_read};
40mod templates;
41mod workspace;
42pub use backup::{shell as command_shell, AutomationBackup};
43pub use templates::{template, templates, AutomationCatalog};
44pub use workspace::open_root as open_workspace_root;
45pub(crate) fn watch_dir() -> std::path::PathBuf {
46 store::root()
47}
48pub(crate) fn has_pending_backup() -> bool {
49 backup::needs_export()
50}
51pub use definition::{
52 AutomationDraft, AutomationScriptFile, ManagedAutomation, Provider, Schedule,
53};
54pub use managed::{remove, remove_with_local_data, run, save};
55#[cfg(any(windows, test))]
56mod windows;
57
58use serde::Serialize;
59
60#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
61#[serde(rename_all = "snake_case")]
62pub enum TaskOrigin {
63 AgentHub,
64 External,
65 Unknown,
66}
67
68#[derive(Debug, Clone, Serialize)]
69pub struct AutomationTask {
70 pub id: String,
71 pub name: String,
72 pub identifier: Option<String>,
73 pub bundle_id: Option<String>,
74 pub icon: Option<String>,
75 pub source: String,
76 pub origin: TaskOrigin,
77 pub can_edit: bool,
78 pub can_run: bool,
79 pub requires_admin: bool,
81 pub definition: Option<AutomationDraft>,
82 pub revision: Option<u64>,
83 pub is_package: bool,
84 pub is_builtin: bool,
86 pub schedule: String,
87 pub project: Option<String>,
88 pub next_run: Option<String>,
89 pub last_run: Option<String>,
90 pub status: String,
91 pub last_result: Option<String>,
92 pub command: Option<String>,
93 pub prompt: Option<String>,
94 pub location: String,
95}
96
97impl AutomationTask {
98 fn new(id: String, name: String, source: &str, location: String) -> Self {
99 Self {
100 id,
101 name,
102 identifier: None,
103 bundle_id: None,
104 icon: None,
105 source: source.into(),
106 origin: TaskOrigin::External,
107 can_edit: source == "hermes",
108 can_run: source == "hermes",
109 requires_admin: false,
110 definition: None,
111 revision: None,
112 is_package: false,
113 is_builtin: false,
114 location,
115 schedule: String::new(),
116 project: None,
117 next_run: None,
118 last_run: None,
119 status: "unknown".into(),
120 last_result: None,
121 command: None,
122 prompt: None,
123 }
124 }
125}
126
127#[derive(Debug, Serialize)]
128pub struct SourceIssue {
129 pub source: String,
130 pub message: String,
131}
132
133#[derive(Default, Debug, Serialize)]
134pub struct AutomationOverview {
135 pub tasks: Vec<AutomationTask>,
136 pub issues: Vec<SourceIssue>,
137 pub hermes_installed: bool,
138}
139
140impl AutomationOverview {
141 fn collect(&mut self, source: &str, result: Result<Vec<AutomationTask>, String>) {
142 match result {
143 Ok(tasks) => self.tasks.extend(tasks),
144 Err(message) => self.issue(source, message),
145 }
146 }
147
148 fn issue(&mut self, source: &str, message: String) {
149 self.issues.push(SourceIssue {
150 source: source.into(),
151 message: super::log_sanitize::sanitize(&message),
152 });
153 }
154}
155
156pub fn overview(locale: Option<&str>) -> AutomationOverview {
158 #[cfg(not(target_os = "macos"))]
159 let _ = locale;
160 let mut report = AutomationOverview {
161 hermes_installed: super::tool_detection::is_installed("hermes"),
162 ..Default::default()
163 };
164 #[cfg(target_os = "macos")]
165 {
166 launchd::collect(&mut report, locale.unwrap_or("en"));
167 cron::collect(&mut report);
168 }
169 #[cfg(target_os = "linux")]
170 {
171 linux::collect(&mut report);
172 cron::collect(&mut report);
173 }
174 #[cfg(windows)]
175 windows::collect(&mut report);
176 if report.hermes_installed {
177 hermes::collect(&mut report);
178 }
179 managed::merge(&mut report, &store::root());
180 next_run::fill(&mut report, &chrono::Local::now());
181 report.tasks.sort_by_key(|task| task.name.to_lowercase());
182 report
183}
184
185#[cfg(test)]
186mod tests;