Skip to main content

horto_os_ui_tui/
probe_job.rs

1//! Background remote surface probe for the TUI event loop.
2
3use horto_os_ui_shared::{
4    probe_surfaces, remote_box_snapshot, RemoteBoxSnapshot, RemoteOptions, SurfaceProbeReport,
5    SystemProcessRunner,
6};
7
8/// Successful remote probe payload (surfaces + optional setup snapshot).
9pub struct RemoteProbeOk {
10    /// SSH/CLI/API/MCP surface report.
11    pub report: SurfaceProbeReport,
12    /// Setup/doctor snapshot when the box CLI is current; `Err` if that fetch failed.
13    pub snapshot: Option<Result<RemoteBoxSnapshot, String>>,
14}
15
16/// Result of a background remote probe job.
17pub struct RemoteProbeOutcome {
18    /// OpenSSH Host that was probed.
19    pub host: String,
20    /// Surfaces + snapshot, or a probe-level error string.
21    pub result: Result<RemoteProbeOk, String>,
22}
23
24/// Run `probe_surfaces` then optional `remote_box_snapshot` (same work as the old blocking refresh).
25pub fn run_remote_probe(opts: &RemoteOptions, full: bool) -> RemoteProbeOutcome {
26    let host = opts.host.clone();
27    match probe_surfaces(&SystemProcessRunner, opts, false) {
28        Ok(report) => {
29            let snapshot = if report.cli.current {
30                Some(
31                    remote_box_snapshot(&SystemProcessRunner, opts, full)
32                        .map_err(|e| e.to_string()),
33                )
34            } else {
35                None
36            };
37            RemoteProbeOutcome {
38                host,
39                result: Ok(RemoteProbeOk { report, snapshot }),
40            }
41        }
42        Err(e) => RemoteProbeOutcome {
43            host,
44            result: Err(e.to_string()),
45        },
46    }
47}