Skip to main content

qualia_client_core/wellfair/
snapshot.rs

1//! Derive `WellfairHostSnapshot` from live host services (not Aether signals).
2
3use super::accessibility_prefs;
4use super::host_state::{NetworkExposure, SyncQueueState, VaultLifecycle, WellfairHostSnapshot};
5use qualia_core_db::key_vault::KeyVault;
6use std::path::Path;
7
8/// Build operating-state snapshot from KeyVault + Host API readiness.
9pub fn build_host_snapshot(
10    key_vault: &KeyVault,
11    host_api_ready: bool,
12    owner_label: &str,
13    demo_mode: bool,
14) -> WellfairHostSnapshot {
15    build_host_snapshot_with_storage(key_vault, host_api_ready, owner_label, demo_mode, None)
16}
17
18/// Builds host-snapshot-with-storage.
19pub fn build_host_snapshot_with_storage(
20    key_vault: &KeyVault,
21    host_api_ready: bool,
22    owner_label: &str,
23    demo_mode: bool,
24    storage_root: Option<&Path>,
25) -> WellfairHostSnapshot {
26    let vault = if demo_mode {
27        VaultLifecycle::Unlocked
28    } else if key_vault.is_locked() {
29        VaultLifecycle::Locked
30    } else if host_api_ready {
31        VaultLifecycle::Unlocked
32    } else {
33        VaultLifecycle::Unconfigured
34    };
35
36    WellfairHostSnapshot {
37        vault,
38        network: NetworkExposure::LocalOnly,
39        sync_state: SyncQueueState::Idle,
40        demo_mode,
41        owner_label: if owner_label.is_empty() {
42            "Owner vault".to_string()
43        } else {
44            owner_label.to_string()
45        },
46        accessibility: storage_root
47            .map(accessibility_prefs::load)
48            .unwrap_or_default(),
49        pending_jobs: 0,
50        health_record_count: 0,
51        graph_quin_count: 0,
52        last_checkpoint_prefix: None,
53        capabilities_ready: host_api_ready && !key_vault.is_locked(),
54        host_api_version: crate::qapp_install::SUPPORTED_HOST_API_VERSION.to_string(),
55    }
56}